From 1f080391edfbb3294f2cf95027c4d5fea3a40454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 25 Apr 2024 14:13:30 +0200 Subject: [PATCH] vulkan: replace gst_vulkan_queue_create_decoder() with gst_vulkan_decoder_new_from_queue() The purpose of this refactor is to hide decoding code from public API. Part-of: --- girs/GstVulkan-1.0.gir | 24 ------ .../gst-docs/symbols/symbol_index.json | 1 - .../gst-plugins-bad/ext/vulkan/vkh264dec.c | 2 +- .../gst-plugins-bad/ext/vulkan/vkh265dec.c | 2 +- .../gst/vulkan/gstvkdecoder-private.c | 69 +++++++++++++++++ .../gst/vulkan/gstvkdecoder-private.h | 5 ++ .../gst-libs/gst/vulkan/gstvkqueue.c | 75 ------------------- .../gst-libs/gst/vulkan/gstvkqueue.h | 5 +- .../gst-libs/gst/vulkan/vulkan_fwd.h | 3 - .../tests/check/libs/vkvideodecode.c | 4 +- 10 files changed, 79 insertions(+), 111 deletions(-) diff --git a/girs/GstVulkan-1.0.gir b/girs/GstVulkan-1.0.gir index 56fcfb2bf4..97b5903981 100644 --- a/girs/GstVulkan-1.0.gir +++ b/girs/GstVulkan-1.0.gir @@ -1314,12 +1314,6 @@ need to use this function. - - - - - - @@ -5169,24 +5163,6 @@ surrounding elements of @element. - - Creates a #GstVulkanDecoder object if @codec decoding is supported by @queue - - - the #GstVulkanDecoder object - - - - - a #GstVulkanQueue - - - - the VkVideoCodecOperationFlagBitsKHR to decode - - - - diff --git a/subprojects/gst-docs/symbols/symbol_index.json b/subprojects/gst-docs/symbols/symbol_index.json index 362e40a7e2..466357b913 100644 --- a/subprojects/gst-docs/symbols/symbol_index.json +++ b/subprojects/gst-docs/symbols/symbol_index.json @@ -44932,7 +44932,6 @@ "gst_vulkan_physical_device_type_to_string", "gst_vulkan_present_mode_to_string", "gst_vulkan_queue_create_command_pool", - "gst_vulkan_queue_create_decoder", "gst_vulkan_queue_flags_to_string", "gst_vulkan_queue_get_device", "gst_vulkan_queue_handle_context_query", diff --git a/subprojects/gst-plugins-bad/ext/vulkan/vkh264dec.c b/subprojects/gst-plugins-bad/ext/vulkan/vkh264dec.c index 92d4988009..c966521cc2 100644 --- a/subprojects/gst-plugins-bad/ext/vulkan/vkh264dec.c +++ b/subprojects/gst-plugins-bad/ext/vulkan/vkh264dec.c @@ -162,7 +162,7 @@ gst_vulkan_h264_decoder_open (GstVideoDecoder * decoder) return FALSE; } - self->decoder = gst_vulkan_queue_create_decoder (self->decode_queue, + self->decoder = gst_vulkan_decoder_new_from_queue (self->decode_queue, VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR); if (!self->decoder) { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, diff --git a/subprojects/gst-plugins-bad/ext/vulkan/vkh265dec.c b/subprojects/gst-plugins-bad/ext/vulkan/vkh265dec.c index b73fab01d4..f9da891ca6 100644 --- a/subprojects/gst-plugins-bad/ext/vulkan/vkh265dec.c +++ b/subprojects/gst-plugins-bad/ext/vulkan/vkh265dec.c @@ -220,7 +220,7 @@ gst_vulkan_h265_decoder_open (GstVideoDecoder * decoder) return FALSE; } - self->decoder = gst_vulkan_queue_create_decoder (self->decode_queue, + self->decoder = gst_vulkan_decoder_new_from_queue (self->decode_queue, VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR); if (!self->decoder) { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c index b7c2b7593f..77709fc04a 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c @@ -1310,3 +1310,72 @@ gst_vulkan_decoder_wait (GstVulkanDecoder * self) return TRUE; } + +/** + * gst_vulkan_decoder_new_from_queue: + * @queue: a #GstVulkanQueue + * @codec: (type guint): the VkVideoCodecOperationFlagBitsKHR to decode + * + * Creates a #GstVulkanDecoder object if @codec decoding is supported by @queue + * + * Returns: (transfer full) (nullable): the #GstVulkanDecoder object + */ +GstVulkanDecoder * +gst_vulkan_decoder_new_from_queue (GstVulkanQueue * queue, guint codec) +{ + GstVulkanPhysicalDevice *device; + GstVulkanDecoder *decoder; + guint flags, expected_flag, supported_video_ops; + const char *extension; + + g_return_val_if_fail (GST_IS_VULKAN_QUEUE (queue), NULL); + + device = queue->device->physical_device; + expected_flag = VK_QUEUE_VIDEO_DECODE_BIT_KHR; + flags = device->queue_family_props[queue->family].queueFlags; + supported_video_ops = device->queue_family_ops[queue->family].video; + + if (device->properties.apiVersion < VK_MAKE_VERSION (1, 3, 238)) { + GST_WARNING_OBJECT (queue, + "Driver API version [%d.%d.%d] doesn't support Video extensions", + VK_VERSION_MAJOR (device->properties.apiVersion), + VK_VERSION_MINOR (device->properties.apiVersion), + VK_VERSION_PATCH (device->properties.apiVersion)); + return NULL; + } + + switch (codec) { + case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR: + extension = VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME; + break; + case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR: + extension = VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME; + break; + default: + GST_WARNING_OBJECT (queue, "Unsupported codec %u", codec); + return NULL; + } + if ((flags & expected_flag) != expected_flag) { + GST_WARNING_OBJECT (queue, "Queue doesn't support decoding"); + return NULL; + } + if ((supported_video_ops & codec) != codec) { + GST_WARNING_OBJECT (queue, "Queue doesn't support codec %u decoding", + codec); + return NULL; + } + + if (!(gst_vulkan_device_is_extension_enabled (queue->device, + VK_KHR_VIDEO_QUEUE_EXTENSION_NAME) + && gst_vulkan_device_is_extension_enabled (queue->device, + VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME) + && gst_vulkan_device_is_extension_enabled (queue->device, extension))) + return NULL; + + decoder = g_object_new (GST_TYPE_VULKAN_DECODER, NULL); + gst_object_ref_sink (decoder); + decoder->queue = gst_object_ref (queue); + decoder->codec = codec; + + return decoder; +} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.h index 9d5dfddc88..ba240af214 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.h @@ -33,6 +33,8 @@ G_BEGIN_DECLS GST_VULKAN_API GType gst_vulkan_decoder_get_type (void); +typedef struct _GstVulkanDecoder GstVulkanDecoder; +typedef struct _GstVulkanDecoderClass GstVulkanDecoderClass; typedef struct _GstVulkanDecoderPicture GstVulkanDecoderPicture; typedef union _GstVulkanDecoderParameters GstVulkanDecoderParameters; @@ -134,6 +136,9 @@ union _GstVulkanDecoderParameters G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstVulkanDecoder, gst_object_unref) +GST_VULKAN_API +GstVulkanDecoder * gst_vulkan_decoder_new_from_queue (GstVulkanQueue * queue, + guint codec); GST_VULKAN_API gboolean gst_vulkan_decoder_start (GstVulkanDecoder * self, GstVulkanVideoProfile * profile, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.c index 31a818dd9f..2db911af00 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.c @@ -157,81 +157,6 @@ error: return NULL; } -/** - * gst_vulkan_queue_create_decoder: - * @queue: a #GstVulkanQueue - * @codec: (type guint): the VkVideoCodecOperationFlagBitsKHR to decode - * - * Creates a #GstVulkanDecoder object if @codec decoding is supported by @queue - * - * Returns: (transfer full) (nullable): the #GstVulkanDecoder object - * - * Since: 1.24 - */ -GstVulkanDecoder * -gst_vulkan_queue_create_decoder (GstVulkanQueue * queue, guint codec) -{ -#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS - GstVulkanPhysicalDevice *device; - GstVulkanDecoder *decoder; - guint flags, expected_flag, supported_video_ops; - const char *extension; - - g_return_val_if_fail (GST_IS_VULKAN_QUEUE (queue), NULL); - - device = queue->device->physical_device; - expected_flag = VK_QUEUE_VIDEO_DECODE_BIT_KHR; - flags = device->queue_family_props[queue->family].queueFlags; - supported_video_ops = device->queue_family_ops[queue->family].video; - - if (device->properties.apiVersion < VK_MAKE_VERSION (1, 3, 238)) { - GST_WARNING_OBJECT (queue, - "Driver API version [%d.%d.%d] doesn't support Video extensions", - VK_VERSION_MAJOR (device->properties.apiVersion), - VK_VERSION_MINOR (device->properties.apiVersion), - VK_VERSION_PATCH (device->properties.apiVersion)); - return NULL; - } - - switch (codec) { - case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR: - extension = VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME; - break; - case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR: - extension = VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME; - break; - default: - GST_WARNING_OBJECT (queue, "Unsupported codec %u", codec); - return NULL; - } - if ((flags & expected_flag) != expected_flag) { - GST_WARNING_OBJECT (queue, "Queue doesn't support decoding"); - return NULL; - } - if ((supported_video_ops & codec) != codec) { - GST_WARNING_OBJECT (queue, "Queue doesn't support codec %u decoding", - codec); - return NULL; - } - - if (!(gst_vulkan_device_is_extension_enabled (queue->device, - VK_KHR_VIDEO_QUEUE_EXTENSION_NAME) - && gst_vulkan_device_is_extension_enabled (queue->device, - VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME) - && gst_vulkan_device_is_extension_enabled (queue->device, extension))) - return NULL; - - decoder = g_object_new (GST_TYPE_VULKAN_DECODER, NULL); - gst_object_ref_sink (decoder); - decoder->queue = gst_object_ref (queue); - decoder->codec = codec; - - return decoder; -#else - return NULL; -#endif -} - /** * gst_context_set_vulkan_queue: * @context: a #GstContext diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.h index e8aee04ab2..a74be299eb 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkqueue.h @@ -80,15 +80,12 @@ struct _GstVulkanQueueClass G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstVulkanQueue, gst_object_unref) - GST_VULKAN_API +GST_VULKAN_API GstVulkanDevice * gst_vulkan_queue_get_device (GstVulkanQueue * queue); GST_VULKAN_API GstVulkanCommandPool * gst_vulkan_queue_create_command_pool (GstVulkanQueue * queue, GError ** error); -GST_VULKAN_API -GstVulkanDecoder * gst_vulkan_queue_create_decoder (GstVulkanQueue * queue, - guint codec); GST_VULKAN_API void gst_vulkan_queue_submit_lock (GstVulkanQueue * queue); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/vulkan_fwd.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/vulkan_fwd.h index dda4c4ad77..26eb70aae5 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/vulkan_fwd.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/vulkan_fwd.h @@ -119,9 +119,6 @@ typedef struct _GstVulkanOperation GstVulkanOperation; typedef struct _GstVulkanOperationClass GstVulkanOperationClass; typedef struct _GstVulkanOperationPrivate GstVulkanOperationPrivate; -typedef struct _GstVulkanDecoder GstVulkanDecoder; -typedef struct _GstVulkanDecoderClass GstVulkanDecoderClass; - G_END_DECLS #endif /* __GST_VULKAN_FWD_H__ */ diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c index e71f92a261..3bcf097c9f 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c @@ -329,7 +329,7 @@ GST_START_TEST (test_h264_decoder) return; } - dec = gst_vulkan_queue_create_decoder (video_queue, + dec = gst_vulkan_decoder_new_from_queue (video_queue, VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR); if (!dec) { GST_WARNING ("Unable to create a vulkan decoder"); @@ -497,7 +497,7 @@ GST_START_TEST (test_h265_decoder) return; } - dec = gst_vulkan_queue_create_decoder (video_queue, + dec = gst_vulkan_decoder_new_from_queue (video_queue, VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR); if (!dec) { GST_WARNING ("Unable to create a vulkan decoder");