From aea2a1113650abcfbd6830b7f8d7fb3641e42bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 22 Aug 2008 07:24:13 +0000 Subject: [PATCH] ext/vorbis/vorbisenc.c: If a buffer arrives with a timestamp before the timestamp+duration of the previous buffer cli... Original commit message from CVS: * ext/vorbis/vorbisenc.c: (gst_vorbis_enc_chain): If a buffer arrives with a timestamp before the timestamp+duration of the previous buffer clip it instead of dropping it completely. Slight improvement for the unfixable bug #548913. --- ChangeLog | 7 +++++++ ext/vorbis/vorbisenc.c | 23 ++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3c2525242..7685854f33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-08-22 Sebastian Dröge + + * ext/vorbis/vorbisenc.c: (gst_vorbis_enc_chain): + If a buffer arrives with a timestamp before the timestamp+duration + of the previous buffer clip it instead of dropping it completely. + Slight improvement for the unfixable bug #548913. + 2008-08-21 Sebastian Dröge * ext/vorbis/vorbisdec.c: (vorbis_handle_data_packet): diff --git a/ext/vorbis/vorbisenc.c b/ext/vorbis/vorbisenc.c index e562eb15d5..08089fc03b 100644 --- a/ext/vorbis/vorbisenc.c +++ b/ext/vorbis/vorbisenc.c @@ -284,6 +284,7 @@ static const GstAudioChannelPosition vorbischannelpositions[][8] = { GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT, }, }; + static GstCaps * gst_vorbis_enc_generate_sink_caps (void) { @@ -1161,13 +1162,29 @@ gst_vorbis_enc_chain (GstPad * pad, GstBuffer * buffer) if (vorbisenc->expected_ts != GST_CLOCK_TIME_NONE && GST_BUFFER_TIMESTAMP (buffer) < vorbisenc->expected_ts) { + guint64 diff = vorbisenc->expected_ts - GST_BUFFER_TIMESTAMP (buffer); + guint64 diff_bytes; + GST_WARNING_OBJECT (vorbisenc, "Buffer is older than previous " "timestamp + duration (%" GST_TIME_FORMAT "< %" GST_TIME_FORMAT - "), cannot handle. Dropping buffer.", + "), cannot handle. Clipping buffer.", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), GST_TIME_ARGS (vorbisenc->expected_ts)); - gst_buffer_unref (buffer); - return GST_FLOW_OK; + + diff_bytes = + GST_CLOCK_TIME_TO_FRAMES (diff, + vorbisenc->frequency) * vorbisenc->channels * sizeof (gfloat); + if (diff_bytes >= GST_BUFFER_SIZE (buffer)) { + gst_buffer_unref (buffer); + return GST_FLOW_OK; + } + buffer = gst_buffer_make_metadata_writable (buffer); + GST_BUFFER_DATA (buffer) += diff_bytes; + GST_BUFFER_SIZE (buffer) -= diff_bytes; + + GST_BUFFER_TIMESTAMP (buffer) += diff; + if (GST_BUFFER_DURATION_IS_VALID (buffer)) + GST_BUFFER_DURATION (buffer) -= diff; } if (gst_vorbis_enc_buffer_check_discontinuous (vorbisenc, buffer) && !first) {