From 96daac8ac7d19ccd8ee5ec4eb06cb770191350bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 10 Jul 2023 14:44:05 +0200 Subject: [PATCH] vkvideoutils: add GstVulkanVideoOperation enum To differentiate a video/x-h264 caps use with a decoder or an encoder and get the correct video profile, the API expects an enum GstVulkanVideoOperation to handle this difference. Part-of: --- .../gst/vulkan/gstvkimagebufferpool.c | 3 ++- .../gst-libs/gst/vulkan/gstvkvideoutils.c | 17 +++++++++++------ .../gst-libs/gst/vulkan/gstvkvideoutils.h | 19 ++++++++++++++++++- .../tests/check/libs/vkimagebufferpool.c | 3 ++- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c index e7edca3e8f..eb5070db32 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c @@ -169,7 +169,8 @@ gst_vulkan_image_buffer_pool_set_config (GstBufferPool * pool, & (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) != 0)) { priv->has_profile = - gst_vulkan_video_profile_from_caps (&priv->profile, decode_caps); + gst_vulkan_video_profile_from_caps (&priv->profile, decode_caps, + GST_VULKAN_VIDEO_OPERATION_DECODE); } #endif gst_clear_caps (&decode_caps); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.c index 2d11301a98..b00405d934 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.c @@ -27,13 +27,14 @@ #if GST_VULKAN_HAVE_VIDEO_EXTENSIONS /* *INDENT-OFF* */ static const struct { + GstVulkanVideoOperation video_operation; VkVideoCodecOperationFlagBitsKHR codec; const char *mime; VkStructureType stype; } video_codecs_map[] = { - { VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR, "video/x-h264", + { GST_VULKAN_VIDEO_OPERATION_DECODE, VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR, "video/x-h264", VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_PROFILE_INFO_KHR }, - { VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR, "video/x-h265", + { GST_VULKAN_VIDEO_OPERATION_DECODE, VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR, "video/x-h265", VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_PROFILE_INFO_KHR }, }; @@ -201,6 +202,7 @@ gst_vulkan_video_profile_to_caps (const GstVulkanVideoProfile * profile) * gst_vulkan_video_profile_from_caps: (skip) * @profile: (out): the output profile * @caps: a #GstCaps to parse + * @video_operation: a supported video operation * * Returns: %TRUE if @caps was parsed correctly, otherwise %FALSE * @@ -208,15 +210,17 @@ gst_vulkan_video_profile_to_caps (const GstVulkanVideoProfile * profile) */ gboolean gst_vulkan_video_profile_from_caps (GstVulkanVideoProfile * profile, - GstCaps * caps) + GstCaps * caps, GstVulkanVideoOperation video_operation) { #if GST_VULKAN_HAVE_VIDEO_EXTENSIONS const GstStructure *structure; - const char *mime, *chroma_sub, *profile_str = NULL, *layout = NULL; - int i, luma, chroma; + const gchar *mime, *chroma_sub, *profile_str = NULL, *layout = NULL; + gint i, luma, chroma; g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); g_return_val_if_fail (profile, FALSE); + g_return_val_if_fail (video_operation < GST_VULKAN_VIDEO_OPERATION_UNKNOWN, + FALSE); structure = gst_caps_get_structure (caps, 0); @@ -228,7 +232,8 @@ gst_vulkan_video_profile_from_caps (GstVulkanVideoProfile * profile, mime = gst_structure_get_name (structure); for (i = 0; i < G_N_ELEMENTS (video_codecs_map); i++) { - if (g_strcmp0 (video_codecs_map[i].mime, mime) == 0) { + if ((video_codecs_map[i].video_operation == video_operation) + && (g_strcmp0 (video_codecs_map[i].mime, mime) == 0)) { profile->profile.videoCodecOperation = video_codecs_map[i].codec; switch (profile->profile.videoCodecOperation) { diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.h index 8e97fa2dd6..1e8c0d7a0d 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkvideoutils.h @@ -67,11 +67,28 @@ struct _GstVulkanVideoCapabilities gpointer _reserved[GST_PADDING]; }; +/** + * GstVulkanVideoOperation: + * @GST_VULKAN_VIDEO_OPERATION_DECODE: decode operation + * @GST_VULKAN_VIDEO_OPERATION_ENCODE: encode operation + * @GST_VULKAN_VIDEO_OPERATION_UNKNOWN: unknown + * + * The type of video operation. + * + * Since: 1.24 + */ +typedef enum { + GST_VULKAN_VIDEO_OPERATION_DECODE = 0, + GST_VULKAN_VIDEO_OPERATION_ENCODE, + GST_VULKAN_VIDEO_OPERATION_UNKNOWN, +} GstVulkanVideoOperation; + GST_VULKAN_API GstCaps * gst_vulkan_video_profile_to_caps (const GstVulkanVideoProfile * profile); GST_VULKAN_API gboolean gst_vulkan_video_profile_from_caps (GstVulkanVideoProfile * profile, - GstCaps * caps); + GstCaps * caps, + GstVulkanVideoOperation video_operation); GST_VULKAN_API gboolean gst_vulkan_video_profile_is_valid (GstVulkanVideoProfile * profile, guint codec); diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkimagebufferpool.c b/subprojects/gst-plugins-bad/tests/check/libs/vkimagebufferpool.c index 25a289f84d..1d1ce28cb5 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkimagebufferpool.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkimagebufferpool.c @@ -144,7 +144,8 @@ GST_START_TEST (test_vulkan_profiles) caps = gst_vulkan_video_profile_to_caps (&profile); fail_unless (caps); - fail_unless (gst_vulkan_video_profile_from_caps (&profile2, caps)); + fail_unless (gst_vulkan_video_profile_from_caps (&profile2, caps, + GST_VULKAN_VIDEO_OPERATION_DECODE)); gst_caps_unref (caps); fail_unless (profile2.profile.sType == VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR);