}
/**
- * 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);
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 =
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);
gst_vulkan_image_view_unref (pic->dpb_view);
pic->dpb_view = NULL;
-
- g_free (pic);
}
/**
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);
typedef struct
{
- GstVulkanEncoderPicture *picture;
+ GstVulkanEncoderPicture picture;
gboolean is_ref;
gint pic_num;
} 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;
_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);
}
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);
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);
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,
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*/
/* 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);
static GstVideoInfo out_info;
typedef struct
{
- GstVulkanEncoderPicture *picture;
+ GstVulkanEncoderPicture picture;
gboolean is_ref;
gint pic_num;
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;
_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);
}
/* 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);
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);
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,
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*/