From ec48b24291e4587145d012034e76d69761126d43 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 12 Dec 2010 12:38:55 +0100 Subject: [PATCH] dec: scale the estimated duration by number of frames When estimating the frame duration, the diff between two incomming timestamps should be scaled by the amount of frames in the interval. Improves duration estimation and DTS interpolation. --- ext/ffmpeg/gstffmpegdec.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c index 20f87511f1..dd8d41dec3 100644 --- a/ext/ffmpeg/gstffmpegdec.c +++ b/ext/ffmpeg/gstffmpegdec.c @@ -97,6 +97,7 @@ struct _GstFFMpegDec gboolean reordered_in; GstClockTime last_in; GstClockTime last_diff; + guint last_frames; gboolean reordered_out; GstClockTime last_out; GstClockTime next_out; @@ -499,6 +500,7 @@ gst_ffmpegdec_reset_ts (GstFFMpegDec * ffmpegdec) { ffmpegdec->last_in = GST_CLOCK_TIME_NONE; ffmpegdec->last_diff = GST_CLOCK_TIME_NONE; + ffmpegdec->last_frames = 0; ffmpegdec->last_out = GST_CLOCK_TIME_NONE; ffmpegdec->next_out = GST_CLOCK_TIME_NONE; ffmpegdec->reordered_in = FALSE; @@ -2491,12 +2493,22 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf) ffmpegdec->reordered_in = TRUE; ffmpegdec->last_diff = GST_CLOCK_TIME_NONE; } else if (in_timestamp > ffmpegdec->last_in) { + GstClockTime diff; /* keep track of timestamp diff to estimate duration */ - ffmpegdec->last_diff = in_timestamp - ffmpegdec->last_in; + diff = in_timestamp - ffmpegdec->last_in; + /* need to scale with amount of frames in the interval */ + if (ffmpegdec->last_frames) + diff /= ffmpegdec->last_frames; + + GST_LOG_OBJECT (ffmpegdec, "estimated duration %" GST_TIME_FORMAT " %u", + GST_TIME_ARGS (diff), ffmpegdec->last_frames); + + ffmpegdec->last_diff = diff; } } ffmpegdec->last_in = in_timestamp; } + ffmpegdec->last_frames = 0; GST_LOG_OBJECT (ffmpegdec, "Received new data of size %u, offset:%" G_GUINT64_FORMAT ", ts:%" @@ -2634,6 +2646,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf) } else { ffmpegdec->clear_ts = TRUE; } + ffmpegdec->last_frames++; GST_LOG_OBJECT (ffmpegdec, "Before (while bsize>0). bsize:%d , bdata:%p", bsize, bdata);