From 15b6ea50d6c59fb56cff8010b76ef0a4ee4d3a4b Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 25 Aug 2006 09:54:56 +0000 Subject: [PATCH] ext/vorbis/vorbisenc.c: Allow very small discontinuities in the timestamps. These we can't do anything useful with an... Original commit message from CVS: * ext/vorbis/vorbisenc.c: (gst_vorbis_enc_buffer_check_discontinuous): Allow very small discontinuities in the timestamps. These we can't do anything useful with anyway (because vorbis's timestamps have only sample granularity), and are commonly produced by elements with minor bugs. Allow up to 1/2 a sample out. Fixes #351742. --- ChangeLog | 10 ++++++++++ ext/vorbis/vorbisenc.c | 25 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b71443a9e9..b0869a7bb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-08-25 Michael Smith + + * ext/vorbis/vorbisenc.c: + (gst_vorbis_enc_buffer_check_discontinuous): + Allow very small discontinuities in the timestamps. These we can't + do anything useful with anyway (because vorbis's timestamps have + only sample granularity), and are commonly produced by elements with + minor bugs. Allow up to 1/2 a sample out. + Fixes #351742. + 2006-08-24 Wim Taymans * tests/examples/seek/seek.c: (seek_cb), (start_seek), (stop_seek), diff --git a/ext/vorbis/vorbisenc.c b/ext/vorbis/vorbisenc.c index 83c8949bd0..088bcb7417 100644 --- a/ext/vorbis/vorbisenc.c +++ b/ext/vorbis/vorbisenc.c @@ -1003,16 +1003,27 @@ gst_vorbis_enc_buffer_check_discontinuous (GstVorbisEnc * vorbisenc, if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { GST_DEBUG_OBJECT (vorbisenc, "Discont set on incoming buffer"); ret = TRUE; - } else if (vorbisenc->expected_ts != GST_CLOCK_TIME_NONE && + } else if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE && + vorbisenc->expected_ts != GST_CLOCK_TIME_NONE && GST_BUFFER_TIMESTAMP (buffer) != vorbisenc->expected_ts) { - GST_DEBUG_OBJECT (vorbisenc, "Expected TS % " GST_TIME_FORMAT - ", buffer TS % " GST_TIME_FORMAT, - GST_TIME_ARGS (vorbisenc->expected_ts), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); - ret = TRUE; + /* It turns out that a lot of elements don't generate perfect streams due + * to rounding errors. So, we permit small errors (< 1/2 a sample) without + * causing a discont. + */ + int halfsample = GST_SECOND / vorbisenc->frequency / 2; + + if ((GstClockTimeDiff) (GST_BUFFER_TIMESTAMP (buffer) - + vorbisenc->expected_ts) > halfsample) { + GST_DEBUG_OBJECT (vorbisenc, "Expected TS % " GST_TIME_FORMAT + ", buffer TS % " GST_TIME_FORMAT, + GST_TIME_ARGS (vorbisenc->expected_ts), + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); + ret = TRUE; + } } - if (vorbisenc->expected_ts != GST_CLOCK_TIME_NONE) { + if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE && + GST_BUFFER_DURATION (buffer) != GST_CLOCK_TIME_NONE) { vorbisenc->expected_ts = GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer); } else