amlv4l2dec: CB2 codec_data post rule [1/1]
PD#SWPL-187335
Problem:
some codec needs to posted codec_data to decoder.
some coded do not need codec_data.
Solution:
need post codec_data
H264,HEVC,MPEG4,MPEG2,MJPED,VC1,H266,MPEG1
do not post codec_data to decoder
AP9,AV1,AVS,AVS2,AVS3
Verify:
ap222
Change-Id: Icd723c61f82463a3caf50ff6fb22b5e693f81ed9
Signed-off-by: fei.deng <fei.deng@amlogic.com>
diff --git a/src/gstamlv4l2videodec.c b/src/gstamlv4l2videodec.c
index 5814746..0bcfbb0 100644
--- a/src/gstamlv4l2videodec.c
+++ b/src/gstamlv4l2videodec.c
@@ -1374,6 +1374,52 @@
gst_pad_pause_task (decoder->srcpad);
}
+static combining_codec_data(GstAmlVideoDecoder * decoder, GstAmlVideoCodecFrame * frame)
+{
+ GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
+ gboolean need_codec_data = FALSE;
+
+ /*check if post codec_data to decoder.*/
+ if (self->input_state->codec_data && !self->codec_data_inject)
+ {
+ guint32 pixelformat = self->v4l2output->format.fmt.pix.pixelformat;
+ switch (pixelformat)
+ {
+ case V4L2_PIX_FMT_VP9:
+ case V4L2_PIX_FMT_AV1:
+ need_codec_data = FALSE;
+ self->codec_data_inject = TRUE;
+ GST_DEBUG_OBJECT (self, "not inject code_data,pixelformat:%" GST_FOURCC_FORMAT ,GST_FOURCC_ARGS (pixelformat));
+ break;
+ case V4L2_PIX_FMT_H264:
+ case V4L2_PIX_FMT_HEVC:
+ case V4L2_PIX_FMT_MPEG1:
+ case V4L2_PIX_FMT_MPEG2:
+ case V4L2_PIX_FMT_MPEG4:
+ need_codec_data = TRUE;
+ GST_DEBUG_OBJECT (self, "must inject code_data,pixelformat:%" GST_FOURCC_FORMAT ,GST_FOURCC_ARGS (pixelformat));
+ break;
+ default:
+ need_codec_data = FALSE;
+ self->codec_data_inject = TRUE;
+ GST_DEBUG_OBJECT (self, "default, not inject code_data,pixelformat:%" GST_FOURCC_FORMAT ,GST_FOURCC_ARGS (pixelformat));
+ break;
+ }
+ //should inject codec data to es buffer
+ if (need_codec_data && !self->v4l2output->secure_es) {
+ GstBuffer *buffer_input = gst_buffer_new();
+ gst_buffer_copy_into (buffer_input, self->input_state->codec_data,
+ GST_BUFFER_COPY_MEMORY, 0, -1);
+ gst_buffer_copy_into (buffer_input, frame->input_buffer,
+ GST_BUFFER_COPY_MEMORY, 0, -1);
+ gst_buffer_unref(frame->input_buffer);
+ frame->input_buffer = buffer_input;
+ GST_BUFFER_PTS(frame->input_buffer) = frame->pts;
+ self->codec_data_inject = TRUE;
+ }
+ }
+}
+
static GstFlowReturn
gst_aml_v4l2_video_dec_handle_frame (GstAmlVideoDecoder * decoder,
GstAmlVideoCodecFrame * frame)
@@ -1417,21 +1463,7 @@
GST_DEBUG_OBJECT (self, "Sending header");
- codec_data = self->input_state->codec_data;
-
- /* We are running in byte-stream mode, so we don't know the headers, but
- * we need to send something, otherwise the decoder will refuse to
- * initialize.
- */
- if (codec_data)
- {
- gst_buffer_ref (codec_data);
- }
- else
- {
- codec_data = gst_buffer_ref (frame->input_buffer);
- processed = TRUE;
- }
+ combining_codec_data(decoder, frame);
/* Ensure input internal pool is active */
if (!gst_buffer_pool_is_active (pool))
@@ -1453,12 +1485,10 @@
}
GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder);
- ret =
- gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &codec_data);
- self->codec_data_inject = TRUE;
- GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder);
+ processed = TRUE;
+ ret = gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &frame->input_buffer);
- gst_buffer_unref (codec_data);
+ GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder);
/* For decoders G_FMT returns coded size, G_SELECTION returns visible size
* in the compose rectangle. gst_aml_v4l2_object_acquire_format() checks both
@@ -1494,29 +1524,7 @@
if (!processed)
{
GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder);
- if (!self->codec_data_inject && self->input_state->codec_data)
- {
- if (!self->v4l2output->secure_es)
- {
- GstBuffer *buffer_input = gst_buffer_new();
- gst_buffer_copy_into (buffer_input, self->input_state->codec_data,
- GST_BUFFER_COPY_MEMORY, 0, -1);
- gst_buffer_copy_into (buffer_input, frame->input_buffer,
- GST_BUFFER_COPY_MEMORY, 0, -1);
- gst_buffer_unref(frame->input_buffer);
- frame->input_buffer = buffer_input;
- GST_BUFFER_PTS(frame->input_buffer) = frame->pts;
- self->codec_data_inject = TRUE;
- }
- else
- {
- ret = gst_aml_v4l2_buffer_pool_process
- (GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &self->input_state->codec_data);
- self->codec_data_inject = TRUE;
- if (ret != GST_FLOW_OK)
- goto send_codec_failed;
- }
- }
+ combining_codec_data(decoder, frame);
ret =
gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &frame->input_buffer);
GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder);