From f4779f1fabbdb638369cdfae320079c6b20832d6 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Sun, 11 Jun 2023 20:17:19 +0800 Subject: [PATCH] va: baseenc: Extend the create_output_buffer() to accept prefix data Part-of: --- subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c | 11 +++++++++-- subprojects/gst-plugins-bad/sys/va/gstvabaseenc.h | 4 +++- subprojects/gst-plugins-bad/sys/va/gstvah264enc.c | 3 ++- subprojects/gst-plugins-bad/sys/va/gstvah265enc.c | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c index 8188a8e951..4652caa0ea 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c @@ -271,7 +271,8 @@ gst_va_base_enc_import_input_buffer (GstVaBaseEnc * base, GstBuffer * gst_va_base_enc_create_output_buffer (GstVaBaseEnc * base, - GstVaEncodePicture * picture) + GstVaEncodePicture * picture, const guint8 * prefix_data, + guint prefix_data_len) { guint coded_size; goffset offset; @@ -300,7 +301,7 @@ gst_va_base_enc_create_output_buffer (GstVaBaseEnc * base, coded_size += seg->size; buf = gst_video_encoder_allocate_output_buffer (GST_VIDEO_ENCODER_CAST (base), - coded_size); + coded_size + prefix_data_len); if (!buf) { va_unmap_buffer (base->display, picture->coded_buffer); GST_ERROR_OBJECT (base, "Failed to allocate output buffer, size %d", @@ -309,6 +310,12 @@ gst_va_base_enc_create_output_buffer (GstVaBaseEnc * base, } offset = 0; + if (prefix_data) { + g_assert (prefix_data_len > 0); + gst_buffer_fill (buf, offset, prefix_data, prefix_data_len); + offset += prefix_data_len; + } + for (seg = seg_list; seg; seg = seg->next) { gsize write_size; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.h b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.h index bb6491d095..da4162a3f0 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.h +++ b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.h @@ -138,7 +138,9 @@ void gst_va_base_enc_add_codec_tag (GstVaBaseEnc * base, const gchar * codec_name); void gst_va_base_enc_reset_state (GstVaBaseEnc * base); GstBuffer * gst_va_base_enc_create_output_buffer (GstVaBaseEnc * base, - GstVaEncodePicture * picture); + GstVaEncodePicture * picture, + const guint8 * prefix_data, + guint prefix_data_len); gint gst_va_base_enc_copy_output_data (GstVaBaseEnc * base, GstVaEncodePicture * picture, guint8 * data, diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c index 650af1f6e6..81faec3d36 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c @@ -3057,7 +3057,8 @@ gst_va_h264_enc_prepare_output (GstVaBaseEnc * base, base->output_frame_count++; frame->duration = base->frame_duration; - buf = gst_va_base_enc_create_output_buffer (base, frame_enc->picture); + buf = gst_va_base_enc_create_output_buffer (base, + frame_enc->picture, NULL, 0); if (!buf) { GST_ERROR_OBJECT (base, "Failed to create output buffer"); return FALSE; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c index e26bea7882..8cb0f66e78 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c @@ -4630,7 +4630,8 @@ gst_va_h265_enc_prepare_output (GstVaBaseEnc * base, base->output_frame_count++; frame->duration = base->frame_duration; - buf = gst_va_base_enc_create_output_buffer (base, frame_enc->picture); + buf = gst_va_base_enc_create_output_buffer (base, + frame_enc->picture, NULL, 0); if (!buf) { GST_ERROR_OBJECT (base, "Failed to create output buffer"); return FALSE;