amlv4l2: CB1 support v4l2 stream mode [1/1]
PD#SWPL-118049
Problem:
videodeocder frame list design for v4l2 frame mode
frame list will keep growing when in stream mode
Solution:
Release all expired frames when pop frame in stream mode
Verify:
(detail info)
Change-Id: I8e940eceb2e4ab40b9bc80574c521e08f12c8a11
Signed-off-by: xuesong.jiang <xuesong.jiang@amlogic.com>
diff --git a/src/gstamlv4l2videodec.c b/src/gstamlv4l2videodec.c
index c0aa48c..70d3ba6 100644
--- a/src/gstamlv4l2videodec.c
+++ b/src/gstamlv4l2videodec.c
@@ -636,12 +636,14 @@
}
static GstVideoCodecFrame *
-gst_aml_v4l2_video_dec_get_right_frame(GstVideoDecoder *decoder, GstClockTime pts)
+gst_aml_v4l2_video_dec_get_right_frame_for_frame_mode(GstVideoDecoder *decoder, GstClockTime pts)
{
GstVideoCodecFrame *frame = NULL;
GList *frames, *l;
gint count = 0;
+ GST_LOG_OBJECT (decoder, "trace in with pts: %" GST_TIME_FORMAT, GST_TIME_ARGS(pts));
+
frames = gst_video_decoder_get_frames(decoder);
for (l = frames; l != NULL; l = l->next)
@@ -668,9 +670,81 @@
g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
+ GST_LOG_OBJECT (decoder, "trace out ret:%p", frame);
return frame;
}
+static GstVideoCodecFrame *
+gst_aml_v4l2_video_dec_get_right_frame_for_stream_mode(GstVideoDecoder *decoder, GstClockTime pts)
+{
+ GstVideoCodecFrame *frame = NULL;
+ GList *frames, *l;
+ gint count = 0;
+
+ GST_LOG_OBJECT (decoder, "trace in with pts: %" GST_TIME_FORMAT, GST_TIME_ARGS(pts));
+
+ frames = gst_video_decoder_get_frames(decoder);
+ guint frames_len = 0;
+ frames_len = g_list_length(frames);
+ GST_LOG_OBJECT (decoder, "got frames list len:%d", frames_len);
+
+ frame = frames->data;
+
+ for (l = frames; l != NULL; l = l->next)
+ {
+ GstVideoCodecFrame *f = l->data;
+
+ if (GST_CLOCK_TIME_IS_VALID(pts) && (ABSDIFF(f->pts, pts)) < 1000)
+ {
+ /* found the right frame */
+ frame = f;
+ break;
+ }
+ else if(GST_CLOCK_TIME_IS_VALID(pts) && (f->pts < pts))
+ {
+ GST_LOG_OBJECT(decoder,
+ "stream mode drop frame %d %" GST_TIME_FORMAT,
+ frame->system_frame_number, GST_TIME_ARGS(frame->pts));
+
+ gst_video_codec_frame_ref(f);
+ // gst_video_decoder_drop_frame(decoder, f);
+ gst_video_decoder_release_frame(decoder, f);
+ }
+ else
+ {
+ GST_LOG_OBJECT (decoder, "dbg");
+ }
+ }
+
+ if (frame)
+ {
+ guint l_len = 0;
+ l = gst_video_decoder_get_frames(decoder);
+ l_len = g_list_length(l);
+ g_list_free_full(l, (GDestroyNotify)gst_video_codec_frame_unref);
+
+ GST_LOG_OBJECT(decoder,
+ "frame is %d %" GST_TIME_FORMAT " and %d frames left",
+ frame->system_frame_number, GST_TIME_ARGS(frame->pts), l_len);
+ gst_video_codec_frame_ref(frame);
+ }
+
+ g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
+
+ GST_LOG_OBJECT (decoder, "trace out ret:%p", frame);
+ return frame;
+}
+
+static GstVideoCodecFrame *
+gst_aml_v4l2_video_dec_get_right_frame(GstVideoDecoder *decoder, GstClockTime pts)
+{
+ GstAmlV4l2VideoDec *self = (GstAmlV4l2VideoDec *)decoder;
+ if (self->v4l2output->stream_mode)
+ return gst_aml_v4l2_video_dec_get_right_frame_for_stream_mode(decoder, pts);
+ else
+ return gst_aml_v4l2_video_dec_get_right_frame_for_frame_mode(decoder, pts);
+}
+
static gboolean
gst_aml_v4l2_video_remove_padding(GstCapsFeatures *features,
GstStructure *structure, gpointer user_data)