From c1e364ecdcd778bfb72dbfb802dcc8aa8ab6944e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 4 Sep 2024 14:14:04 +0200 Subject: [PATCH] vkencoder-private: remove width, height and fps from GstVulkanEncoderPicture In GStreamer that buffer information is decoupled, holding other structures to describe the stream: GstCaps. So, to keep the GStreamer design this patch removes these information from GstVulkanEncoderPicture and pass to gst_vulkan_encoder_encode() a pointer to GstVideoInfo. Part-of: --- .../gst/vulkan/gstvkencoder-private.c | 24 +++++++++---------- .../gst/vulkan/gstvkencoder-private.h | 13 +--------- .../tests/check/libs/vkvideoencodeh264.c | 4 ++-- .../tests/check/libs/vkvideoencodeh265.c | 4 ++-- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c index 388a9bbb8b..a2dbb1ef08 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c @@ -375,8 +375,7 @@ gst_vulkan_encoder_new_video_session_parameters (GstVulkanEncoder * self, * gst_vulkan_encoder_picture_new: * @self: the #GstVulkanEncoder with the pool's configuration. * @in_buffer: (transfer none): the input #GstBuffer. - * @width: the picture width - * @height: the picture height + * @size: size of the output buffer * * Create a new vulkan encode picture from the input buffer. * @@ -385,7 +384,7 @@ gst_vulkan_encoder_new_video_session_parameters (GstVulkanEncoder * self, */ GstVulkanEncoderPicture * gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, - int width, int height, gsize size) + gsize size) { GstVulkanEncoderPicture *pic; GstVulkanEncoderPrivate *priv; @@ -419,8 +418,6 @@ gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, pic->out_buffer = gst_vulkan_video_codec_buffer_new (self->queue->device, &priv->profile, VK_BUFFER_USAGE_VIDEO_ENCODE_DST_BIT_KHR, size_aligned); - pic->width = width; - pic->height = height; pic->slotIndex = -1; pic->offset = 0; @@ -1057,6 +1054,7 @@ bail: /** * gst_vulkan_encoder_encode: * @self: a #GstVulkanEncoder + * @info: the #GstVideoInfo of the @pic to process * @pic: a #GstVulkanEncoderPicture * @nb_refs: number of @ref_pics * @ref_pics: an array of #GstVulkanEncoderPicture @@ -1067,7 +1065,7 @@ bail: * */ gboolean -gst_vulkan_encoder_encode (GstVulkanEncoder * self, +gst_vulkan_encoder_encode (GstVulkanEncoder * self, GstVideoInfo * info, GstVulkanEncoderPicture * pic, guint nb_refs, GstVulkanEncoderPicture ** ref_pics) { @@ -1090,7 +1088,7 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, GArray *barriers; g_return_val_if_fail (GST_IS_VULKAN_ENCODER (self), FALSE); - g_return_val_if_fail (pic != NULL, FALSE); + g_return_val_if_fail (info != NULL && pic != NULL, FALSE); priv = gst_vulkan_encoder_get_instance_private (self); @@ -1123,8 +1121,8 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, .pNext = pic->codec_rc_layer_info, .averageBitrate = priv->prop.average_bitrate, .maxBitrate = priv->caps.encoder.caps.maxBitrate, - .frameRateNumerator = pic->fps_n, - .frameRateDenominator = pic->fps_d, + .frameRateNumerator = GST_VIDEO_INFO_FPS_N (info), + .frameRateDenominator = GST_VIDEO_INFO_FPS_D (info), }; priv->rate_control_info = (VkVideoEncodeRateControlInfoKHR) { .sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_RATE_CONTROL_INFO_KHR, @@ -1166,8 +1164,8 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, .pNext = NULL, .codedOffset = { 0, 0 }, .codedExtent = { - .width = pic->width, - .height = pic->height + .width = GST_VIDEO_INFO_WIDTH (info), + .height = GST_VIDEO_INFO_HEIGHT (info), }, .baseArrayLayer = 0, .imageViewBinding = pic->dpb_view->view, @@ -1269,8 +1267,8 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, .pNext = NULL, .codedOffset = { 0, 0 }, .codedExtent = { - .width = pic->width, - .height = pic->height + .width = GST_VIDEO_INFO_WIDTH (info), + .height = GST_VIDEO_INFO_HEIGHT (info), }, .baseArrayLayer = 0, .imageViewBinding = pic->img_view->view, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h index 311518bb59..e165601ee8 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h @@ -42,10 +42,6 @@ typedef struct _GstVulkanEncoderPicture GstVulkanEncoderPicture; * GstVulkanEncoderPicture: * @slotIndex: slot index * @offset: headers offset - * @width: picture width - * @height: picture height - * @fps_n: fps numerator - * @fps_d: fps denominator * @in_buffer: input buffer * @out_buffer: output buffer * @@ -59,12 +55,6 @@ struct _GstVulkanEncoderPicture guint64 offset; - gint width; - gint height; - - gint fps_n; - gint fps_d; - GstBuffer *in_buffer; GstBuffer *dpb_buffer; GstBuffer *out_buffer; @@ -164,6 +154,7 @@ gboolean gst_vulkan_encoder_create_dpb_pool (GstVulkanEncode GstCaps * caps); GST_VULKAN_API gboolean gst_vulkan_encoder_encode (GstVulkanEncoder * self, + GstVideoInfo * info, GstVulkanEncoderPicture * pic, guint nb_refs, GstVulkanEncoderPicture ** ref_pics); @@ -175,8 +166,6 @@ GstCaps * gst_vulkan_encoder_profile_caps (GstVulkanEncode GST_VULKAN_API GstVulkanEncoderPicture* gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, - gint width, - gint height, gsize size); GST_VULKAN_API void gst_vulkan_encoder_picture_free (GstVulkanEncoderPicture * pic); diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c index 87c03dd307..7ba21d4488 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c @@ -362,7 +362,7 @@ allocate_frame (GstVulkanEncoder * enc, int width, upload_buffer_to_image(img_pool, in_buffer, &img_buffer); frame = _h264_encode_frame_new (gst_vulkan_encoder_picture_new (enc, - img_buffer, width, height, width * height * 3), is_ref); + img_buffer, width * height * 3), is_ref); fail_unless (frame); fail_unless (frame->picture); gst_buffer_unref (in_buffer); @@ -552,7 +552,7 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH264EncodeFrame * frame, frame->ref_list_info.RefPicList1[i] = list1[i]->picture->slotIndex; } - fail_unless (gst_vulkan_encoder_encode (enc, picture, ref_pics_num, + fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num, ref_pics)); } diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c index 5574199fe5..c793fbef7e 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c @@ -369,7 +369,7 @@ allocate_frame (GstVulkanEncoder * enc, int width, upload_buffer_to_image(img_pool, in_buffer, &img_buffer); frame = _h265_encode_frame_new (gst_vulkan_encoder_picture_new (enc, - img_buffer, width, height, width * height * 3), is_ref); + img_buffer, width * height * 3), is_ref); fail_unless (frame); fail_unless (frame->picture); gst_buffer_unref (in_buffer); @@ -618,7 +618,7 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH265EncodeFrame * frame, frame->ref_list_info.RefPicList1[i] = list1[i]->picture->slotIndex; } - fail_unless (gst_vulkan_encoder_encode (enc, picture, ref_pics_num, + fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num, ref_pics)); }