[FFmpeg-devel] [PATCH 2/3] avcodec/vulkan: Make FFVkCodecMap decoder-only

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sun Mar 3 13:37:17 EET 2024


All the fields of FFVkCodecMap are either decoder-only
or encoder-only (with the latter being unused and unset for now).
This commit therefore makes this struct decoder-only and
moves it to vulkan_decode.c.

Also use designated initializers while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/vulkan_decode.c | 38 +++++++++++++++++++++++++++++++-------
 libavcodec/vulkan_video.c  | 26 --------------------------
 libavcodec/vulkan_video.h  | 11 -----------
 3 files changed, 31 insertions(+), 44 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 5def908a21..b80415a019 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -22,6 +22,30 @@
 #include "config_components.h"
 #include "libavutil/avassert.h"
 
+typedef struct VkCodecMap {
+    enum AVCodecID                   codec_id;
+    FFVulkanExtensions               decode_extension;
+    VkVideoCodecOperationFlagBitsKHR decode_op;
+} VkCodecMap;
+
+static const VkCodecMap vk_codec_map[] = {
+    {
+        .codec_id         = AV_CODEC_ID_H264,
+        .decode_extension = FF_VK_EXT_VIDEO_DECODE_H264,
+        .decode_op        = VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR,
+    },
+    {
+        .codec_id         = AV_CODEC_ID_HEVC,
+        .decode_extension = FF_VK_EXT_VIDEO_DECODE_H265,
+        .decode_op        = VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR,
+    },
+    {
+        .codec_id         = AV_CODEC_ID_AV1,
+        .decode_extension = FF_VK_EXT_VIDEO_DECODE_AV1,
+        .decode_op        = 0x01000000, /* TODO fix this */
+    },
+};
+
 #if CONFIG_H264_VULKAN_HWACCEL
 extern const VkExtensionProperties ff_vk_dec_h264_ext;
 #endif
@@ -44,11 +68,11 @@ static const VkExtensionProperties *dec_ext[] = {
 #endif
 };
 
-static const FFVkCodecMap *get_codecmap(enum AVCodecID codec_id)
+static const VkCodecMap *get_codecmap(enum AVCodecID codec_id)
 {
-    for (size_t i = 0; i < FF_ARRAY_ELEMS(ff_vk_codec_map); i++)
-        if (ff_vk_codec_map[i].codec_id == codec_id)
-            return &ff_vk_codec_map[i];
+    for (size_t i = 0; i < FF_ARRAY_ELEMS(vk_codec_map); i++)
+        if (vk_codec_map[i].codec_id == codec_id)
+            return &vk_codec_map[i];
     av_assert1(!"unreachable");
     return NULL;
 }
@@ -670,7 +694,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
                                      FFVulkanDecodeProfileData *prof,
                                      AVVulkanDeviceContext *hwctx,
                                      FFVulkanFunctions *vk,
-                                     const struct FFVkCodecMap *vk_codec,
+                                     const VkCodecMap *vk_codec,
                                      VkVideoDecodeH264CapabilitiesKHR *h264_caps,
                                      VkVideoDecodeH265CapabilitiesKHR *h265_caps,
                                      VkVideoDecodeAV1CapabilitiesMESA *av1_caps,
@@ -747,7 +771,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
 {
     VkResult ret;
     int max_level, base_profile, cur_profile;
-    const FFVkCodecMap *vk_codec = get_codecmap(avctx->codec_id);
+    const VkCodecMap *vk_codec = get_codecmap(avctx->codec_id);
     AVHWFramesContext *frames = (AVHWFramesContext *)frames_ref->data;
     AVHWDeviceContext *device = (AVHWDeviceContext *)frames->device_ref->data;
     AVVulkanDeviceContext *hwctx = device->hwctx;
@@ -1121,7 +1145,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
     FFVulkanContext *s;
     FFVulkanFunctions *vk;
     const VkVideoProfileInfoKHR *profile;
-    const FFVkCodecMap *vk_codec;
+    const VkCodecMap *vk_codec;
 
     VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = {
         .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR,
diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c
index a87df52871..799ac7ee7c 100644
--- a/libavcodec/vulkan_video.c
+++ b/libavcodec/vulkan_video.c
@@ -16,34 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "codec_id.h"
-
 #include "vulkan_video.h"
 
-const FFVkCodecMap ff_vk_codec_map[3] = {
-    {
-        .codec_id = AV_CODEC_ID_H264,
-                           0,
-                           0,
-                           FF_VK_EXT_VIDEO_DECODE_H264,
-                           VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR,
-    },
-    {
-        .codec_id = AV_CODEC_ID_HEVC,
-                           0,
-                           0,
-                           FF_VK_EXT_VIDEO_DECODE_H265,
-                           VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR
-    },
-    {
-        .codec_id = AV_CODEC_ID_AV1,
-                           0,
-                           0,
-                           FF_VK_EXT_VIDEO_DECODE_AV1,
-                           0x01000000 /* TODO fix this */
-    },
-};
-
 #define ASPECT_2PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)
 #define ASPECT_3PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT)
 
diff --git a/libavcodec/vulkan_video.h b/libavcodec/vulkan_video.h
index b06e369abd..bb69e920bb 100644
--- a/libavcodec/vulkan_video.h
+++ b/libavcodec/vulkan_video.h
@@ -19,7 +19,6 @@
 #ifndef AVCODEC_VULKAN_VIDEO_H
 #define AVCODEC_VULKAN_VIDEO_H
 
-#include "codec_id.h"
 #include "vulkan.h"
 
 #include <vk_video/vulkan_video_codecs_common.h>
@@ -31,14 +30,6 @@
 #define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
 #define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
 
-typedef struct FFVkCodecMap {
-    enum AVCodecID                   codec_id;
-    FFVulkanExtensions               encode_extension;
-    VkVideoCodecOperationFlagBitsKHR encode_op;
-    FFVulkanExtensions               decode_extension;
-    VkVideoCodecOperationFlagBitsKHR decode_op;
-} FFVkCodecMap;
-
 typedef struct FFVkVideoSession {
     VkVideoSessionKHR session;
     VkDeviceMemory *mem;
@@ -47,8 +38,6 @@ typedef struct FFVkVideoSession {
     AVBufferPool *buf_pool;
 } FFVkVideoCommon;
 
-extern const FFVkCodecMap ff_vk_codec_map[3];
-
 /**
  * Get pixfmt from a Vulkan format.
  */
-- 
2.40.1



More information about the ffmpeg-devel mailing list