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 a2dbb1ef08..3ee3e189d9 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 @@ -372,31 +372,29 @@ gst_vulkan_encoder_new_video_session_parameters (GstVulkanEncoder * self, } /** - * gst_vulkan_encoder_picture_new: + * gst_vulkan_encode_picture_init: + * @pic: the #GstVulkanEncoderPicture to initialize * @self: the #GstVulkanEncoder with the pool's configuration. * @in_buffer: (transfer none): the input #GstBuffer. * @size: size of the output buffer * - * Create a new vulkan encode picture from the input buffer. - * - * Returns: a new #GstVulkanEncoderPicture. + * Initialize @pic structure. * + * Returns: %TRUE if @pic was initialized correctly; otherwise %FALSE */ -GstVulkanEncoderPicture * -gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, - gsize size) +gboolean +gst_vulkan_encoder_picture_init (GstVulkanEncoderPicture * pic, + GstVulkanEncoder * self, GstBuffer * in_buffer, gsize size) { - GstVulkanEncoderPicture *pic; GstVulkanEncoderPrivate *priv; gsize size_aligned; - g_return_val_if_fail (GST_IS_VULKAN_ENCODER (self), NULL); - g_return_val_if_fail (GST_IS_BUFFER (in_buffer), NULL); + g_return_val_if_fail (pic != NULL, FALSE); + g_return_val_if_fail (GST_IS_VULKAN_ENCODER (self), FALSE); + g_return_val_if_fail (GST_IS_BUFFER (in_buffer), FALSE); priv = gst_vulkan_encoder_get_instance_private (self); - pic = g_new0 (GstVulkanEncoderPicture, 1); - size_aligned = GST_ROUND_UP_N (size, priv->caps.caps.minBitstreamBufferSizeAlignment); @@ -409,10 +407,8 @@ gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, g_assert (GST_IS_BUFFER_POOL (priv->dpb_pool)); ret = gst_buffer_pool_acquire_buffer (priv->dpb_pool, &pic->dpb_buffer, NULL); - if (ret != GST_FLOW_OK) { - gst_vulkan_encoder_picture_free (pic); - return NULL; - } + if (ret != GST_FLOW_OK) + return FALSE; } pic->in_buffer = gst_buffer_ref (in_buffer); pic->out_buffer = @@ -431,18 +427,17 @@ gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, GstBuffer * in_buffer, priv->layered_dpb, FALSE, NULL); } - return pic; + return TRUE; } /** - * gst_vulkan_encoder_picture_free: + * gst_vulkan_encoder_picture_clear: * @pic: the #GstVulkanEncoderPicture to free. * - * Free the #GstVulkanEncoderPicture. - * + * Release data of @pic. */ void -gst_vulkan_encoder_picture_free (GstVulkanEncoderPicture * pic) +gst_vulkan_encoder_picture_clear (GstVulkanEncoderPicture * pic) { g_return_if_fail (pic != NULL); @@ -455,8 +450,6 @@ gst_vulkan_encoder_picture_free (GstVulkanEncoderPicture * pic) gst_vulkan_image_view_unref (pic->dpb_view); pic->dpb_view = NULL; - - g_free (pic); } /** 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 e165601ee8..cbed184baa 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 @@ -164,8 +164,9 @@ gboolean gst_vulkan_encoder_caps (GstVulkanEncode GST_VULKAN_API GstCaps * gst_vulkan_encoder_profile_caps (GstVulkanEncoder * self); GST_VULKAN_API -GstVulkanEncoderPicture* gst_vulkan_encoder_picture_new (GstVulkanEncoder * self, +gboolean gst_vulkan_encoder_picture_init (GstVulkanEncoderPicture * pic, + GstVulkanEncoder * self, GstBuffer * in_buffer, gsize size); GST_VULKAN_API -void gst_vulkan_encoder_picture_free (GstVulkanEncoderPicture * pic); +void gst_vulkan_encoder_picture_clear (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 7ba21d4488..e256779fb1 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c @@ -45,7 +45,7 @@ static GstVideoInfo out_info; typedef struct { - GstVulkanEncoderPicture *picture; + GstVulkanEncoderPicture picture; gboolean is_ref; gint pic_num; @@ -65,13 +65,14 @@ typedef struct } GstVulkanH264EncodeFrame; static GstVulkanH264EncodeFrame * -_h264_encode_frame_new (GstVulkanEncoderPicture * picture, gboolean is_ref) +_h264_encode_frame_new (GstVulkanEncoder * enc, GstBuffer * img_buffer, + gsize size, gboolean is_ref) { GstVulkanH264EncodeFrame *frame; - g_return_val_if_fail (picture, NULL); frame = g_new (GstVulkanH264EncodeFrame, 1); - frame->picture = picture; + fail_unless (gst_vulkan_encoder_picture_init (&frame->picture, enc, + img_buffer, size)); frame->is_ref = is_ref; return frame; @@ -81,7 +82,8 @@ static void _h264_encode_frame_free (gpointer pframe) { GstVulkanH264EncodeFrame *frame = pframe; - g_clear_pointer (&frame->picture, gst_vulkan_encoder_picture_free); + + gst_vulkan_encoder_picture_clear (&frame->picture); g_free (frame); } @@ -361,10 +363,8 @@ 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 * 3), is_ref); + frame = _h264_encode_frame_new (enc, img_buffer, width * height * 3, is_ref); fail_unless (frame); - fail_unless (frame->picture); gst_buffer_unref (in_buffer); gst_buffer_unref (img_buffer); @@ -387,7 +387,7 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH264EncodeFrame * frame, guint qp_i = 26; guint qp_p = 26; guint qp_b = 26; - GstVulkanEncoderPicture *picture = frame->picture; + GstVulkanEncoderPicture *picture = &frame->picture; GST_DEBUG ("Encoding frame num:%d", frame_num); @@ -544,12 +544,12 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH264EncodeFrame * frame, picture->codec_dpb_slot_info = &frame->dpb_slot_info; for (i = 0; i < list0_num; i++) { - ref_pics[i] = list0[i]->picture; - frame->ref_list_info.RefPicList0[0] = list0[i]->picture->slotIndex; + ref_pics[i] = &list0[i]->picture; + frame->ref_list_info.RefPicList0[0] = list0[i]->picture.slotIndex; } for (i = 0; i < list1_num; i++) { - ref_pics[i + list0_num] = list1[i]->picture; - frame->ref_list_info.RefPicList1[i] = list1[i]->picture->slotIndex; + ref_pics[i + list0_num] = &list1[i]->picture; + frame->ref_list_info.RefPicList1[i] = list1[i]->picture.slotIndex; } fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num, @@ -762,12 +762,12 @@ check_encoded_frame (GstVulkanH264EncodeFrame * frame, GstH264NalUnitType nal_type) { GstMapInfo info; - fail_unless (frame->picture->out_buffer != NULL); - gst_buffer_map (frame->picture->out_buffer, &info, GST_MAP_READ); + fail_unless (frame->picture.out_buffer != NULL); + gst_buffer_map (frame->picture.out_buffer, &info, GST_MAP_READ); fail_unless (info.size); GST_MEMDUMP ("out buffer", info.data, info.size); check_h264_nalu (info.data, info.size, nal_type); - gst_buffer_unmap (frame->picture->out_buffer, &info); + gst_buffer_unmap (frame->picture.out_buffer, &info); } /* Greater than the maxDpbSlots == 16*/ @@ -905,7 +905,6 @@ GST_START_TEST (test_encoder_h264_i_p_b) /* Encode 1st picture as an IDR-Frame */ frame = allocate_frame (enc, width, height, TRUE); - fail_unless (frame->picture != NULL); encode_frame (enc, frame, STD_VIDEO_H264_SLICE_TYPE_I, frame_num, NULL, 0, NULL, 0, sps_id, pps_id); check_encoded_frame (frame, GST_H264_NAL_SLICE_IDR); diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c index c793fbef7e..ec41e512a6 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c @@ -47,7 +47,7 @@ static GstVideoInfo in_info; static GstVideoInfo out_info; typedef struct { - GstVulkanEncoderPicture *picture; + GstVulkanEncoderPicture picture; gboolean is_ref; gint pic_num; @@ -70,13 +70,14 @@ typedef struct static GstVulkanH265EncodeFrame * -_h265_encode_frame_new (GstVulkanEncoderPicture * picture, gboolean is_ref) +_h265_encode_frame_new (GstVulkanEncoder * enc, GstBuffer * img_buffer, + gsize size, gboolean is_ref) { GstVulkanH265EncodeFrame *frame; - g_return_val_if_fail (picture, NULL); frame = g_new (GstVulkanH265EncodeFrame, 1); - frame->picture = picture; + fail_unless (gst_vulkan_encoder_picture_init (&frame->picture, enc, + img_buffer, size)); frame->is_ref = is_ref; return frame; @@ -86,7 +87,8 @@ static void _h265_encode_frame_free (gpointer pframe) { GstVulkanH265EncodeFrame *frame = pframe; - g_clear_pointer (&frame->picture, gst_vulkan_encoder_picture_free); + + gst_vulkan_encoder_picture_clear (&frame->picture); g_free (frame); } @@ -368,10 +370,8 @@ allocate_frame (GstVulkanEncoder * enc, int width, /* get a Vulkan image buffer out of the input buffer */ 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 * 3), is_ref); + frame = _h265_encode_frame_new (enc, img_buffer, width * height * 3, is_ref); fail_unless (frame); - fail_unless (frame->picture); gst_buffer_unref (in_buffer); gst_buffer_unref (img_buffer); @@ -398,7 +398,7 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH265EncodeFrame * frame, guint qp_i = 26; guint qp_p = 26; guint qp_b = 26; - GstVulkanEncoderPicture *picture = frame->picture; + GstVulkanEncoderPicture *picture = &frame->picture; gint picture_type = PICTURE_TYPE(slice_type, frame->is_ref); GST_DEBUG ("Encoding frame num: %d", frame_num); @@ -610,12 +610,12 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH265EncodeFrame * frame, picture->codec_dpb_slot_info = &frame->dpb_slot_info; for (i = 0; i < list0_num; i++) { - ref_pics[i] = list0[i]->picture; - frame->ref_list_info.RefPicList0[0] = list0[i]->picture->slotIndex; + ref_pics[i] = &list0[i]->picture; + frame->ref_list_info.RefPicList0[0] = list0[i]->picture.slotIndex; } for (i = 0; i < list1_num; i++) { - ref_pics[i + list0_num] = list1[i]->picture; - frame->ref_list_info.RefPicList1[i] = list1[i]->picture->slotIndex; + ref_pics[i + list0_num] = &list1[i]->picture; + frame->ref_list_info.RefPicList1[i] = list1[i]->picture.slotIndex; } fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num, @@ -933,12 +933,12 @@ check_encoded_frame (GstVulkanH265EncodeFrame * frame, GstH265NalUnitType nal_type) { GstMapInfo info; - fail_unless (frame->picture->out_buffer != NULL); - gst_buffer_map (frame->picture->out_buffer, &info, GST_MAP_READ); + fail_unless (frame->picture.out_buffer != NULL); + gst_buffer_map (frame->picture.out_buffer, &info, GST_MAP_READ); fail_unless (info.size); GST_MEMDUMP ("out buffer", info.data, info.size); check_h265_nalu (info.data, info.size, nal_type); - gst_buffer_unmap (frame->picture->out_buffer, &info); + gst_buffer_unmap (frame->picture.out_buffer, &info); } /* Greater than the maxDpbSlots == 16*/