vkencoder-private: remove width, height and fps from GstVulkanEncoderPicture
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 4 Sep 2024 12:14:04 +0000 (14:14 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 4 Dec 2024 02:17:44 +0000 (02:17 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8007>

subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c
subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h
subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c
subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c

index 388a9bbb8bce6b9dd9c9afdf0b0fad4264238d0e..a2dbb1ef080497ada0d39c289e5cf03ee943f323 100644 (file)
@@ -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,
index 311518bb59bfef5d11a6011dc71d6a1237c30180..e165601ee8fef92c03142f80893b61dee45bacb7 100644 (file)
@@ -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);
index 87c03dd3076192fd87d610fcc4f1dfeb207c3073..7ba21d4488f41b8f742eb6d75c18d231e3a161e2 100644 (file)
@@ -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));
 }
 
index 5574199fe554756bd7d3dd2fbd0188489a1c8ea7..c793fbef7e5da8e1ea855cc7b44411339c00e12d 100644 (file)
@@ -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));
 }