From: <th...@ke...> - 2009-03-13 22:55:38
|
Module: gst-plugins-ugly Branch: master Commit: d2c6f0b2b69f484ff82578e82d97090317be35bf URL: http://cgit.freedesktop.org/gstreamer/gst-plugins-ugly/commit/?id=d2c6f0b2b69f484ff82578e82d97090317be35bf Author: Jan Schmidt <th...@no...> Date: Fri Mar 13 19:23:12 2009 +0000 mp3parse: Fix glitches in the output when playing (for e.g.) AVI Don't introduce glitches in the output by a) relaxing the threshold for taking upstream timestamps in preference to our calculated timestamps and b) only set the discont flag on outgoing buffers in response to an incoming discont buffer. Fixes: #575046 --- gst/mpegaudioparse/gstmpegaudioparse.c | 23 ++++++++++++++--------- gst/mpegaudioparse/gstmpegaudioparse.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gst/mpegaudioparse/gstmpegaudioparse.c b/gst/mpegaudioparse/gstmpegaudioparse.c index b26ba93..1d5d1fa 100644 --- a/gst/mpegaudioparse/gstmpegaudioparse.c +++ b/gst/mpegaudioparse/gstmpegaudioparse.c @@ -623,24 +623,20 @@ gst_mp3parse_emit_frame (GstMPEGAudioParse * mp3parse, guint size, * here */ if (GST_CLOCK_TIME_IS_VALID (mp3parse->pending_ts)) { if (mp3parse->tracked_offset >= mp3parse->pending_offset) { - /* If the incoming timestamp differs from our expected by more than 2 - * 90khz MPEG ticks, then take it and, if needed, set the discont flag. + /* If the incoming timestamp differs from our expected by more than + * half a frame, then take it instead of our calculated timestamp. * This avoids creating imperfect streams just because of - * quantization in the MPEG clock sampling */ + * quantization in the container timestamping */ GstClockTimeDiff diff = mp3parse->next_ts - mp3parse->pending_ts; + GstClockTimeDiff thresh = GST_BUFFER_DURATION (outbuf) / 2; - if (diff < -2 * (GST_SECOND / 90000) || diff > 2 * (GST_SECOND / 90000)) { + if (diff < -thresh || diff > thresh) { GST_DEBUG_OBJECT (mp3parse, "Updating next_ts from %" GST_TIME_FORMAT " to pending ts %" GST_TIME_FORMAT " at offset %lld (pending offset was %lld)", GST_TIME_ARGS (mp3parse->next_ts), GST_TIME_ARGS (mp3parse->pending_ts), mp3parse->tracked_offset, mp3parse->pending_offset); - - /* Only set discont if we sent out some timestamps already and we're - * adjusting */ - if (GST_CLOCK_TIME_IS_VALID (mp3parse->next_ts)) - GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); mp3parse->next_ts = mp3parse->pending_ts; } mp3parse->pending_ts = GST_CLOCK_TIME_NONE; @@ -829,6 +825,13 @@ gst_mp3parse_emit_frame (GstMPEGAudioParse * mp3parse, guint size, g_list_free (mp3parse->pending_events); mp3parse->pending_events = NULL; } + + /* set discont if needed */ + if (mp3parse->discont) { + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); + mp3parse->discont = FALSE; + } + ret = gst_pad_push (mp3parse->srcpad, outbuf); } @@ -1174,6 +1177,8 @@ gst_mp3parse_chain (GstPad * pad, GstBuffer * buf) timestamp = GST_BUFFER_TIMESTAMP (buf); + mp3parse->discont |= GST_BUFFER_IS_DISCONT (buf); + /* If we don't yet have a next timestamp, save it and the incoming offset * so we can apply it to the right outgoing buffer */ if (GST_CLOCK_TIME_IS_VALID (timestamp)) { diff --git a/gst/mpegaudioparse/gstmpegaudioparse.h b/gst/mpegaudioparse/gstmpegaudioparse.h index b95436b..d5f193a 100644 --- a/gst/mpegaudioparse/gstmpegaudioparse.h +++ b/gst/mpegaudioparse/gstmpegaudioparse.h @@ -62,6 +62,7 @@ struct _GstMPEGAudioParse { GstSegment segment; GstClockTime next_ts; + gboolean discont; /* Offset as supplied by incoming buffers */ gint64 cur_offset; |