From d299d1c06384c0098286939c9a25102bed1cb87c Mon Sep 17 00:00:00 2001 From: Julien Moutte Date: Fri, 27 Apr 2007 15:33:46 +0000 Subject: [PATCH] ext/theora/theoradec.c: Calculate buffer duration correctly to generate a perfect stream (#433888). Original commit message from CVS: 2007-04-27 Julien MOUTTE * ext/theora/theoradec.c: (_theora_granule_time), (theora_dec_push_forward), (theora_handle_data_packet), (theora_dec_decode_buffer): Calculate buffer duration correctly to generate a perfect stream (#433888). * gst/audioresample/gstaudioresample.c: (audioresample_check_discont): Glib provides ABS. --- ChangeLog | 9 +++++++++ ext/theora/theoradec.c | 24 ++++++++++++++++++------ gst/audioresample/gstaudioresample.c | 4 +--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cdc374..2b247a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-04-27 Julien MOUTTE + + * ext/theora/theoradec.c: (_theora_granule_time), + (theora_dec_push_forward), (theora_handle_data_packet), + (theora_dec_decode_buffer): Calculate buffer duration correctly + to generate a perfect stream (#433888). + * gst/audioresample/gstaudioresample.c: + (audioresample_check_discont): Glib provides ABS. + 2007-04-27 Wim Taymans * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_get_rb), diff --git a/ext/theora/theoradec.c b/ext/theora/theoradec.c index c10ce69..aa96536 100644 --- a/ext/theora/theoradec.c +++ b/ext/theora/theoradec.c @@ -230,7 +230,7 @@ _theora_granule_frame (GstTheoraDec * dec, gint64 granulepos) static GstClockTime _theora_granule_time (GstTheoraDec * dec, gint64 granulepos) { - gint framecount; + gint64 framecount; /* invalid granule results in invalid time */ if (granulepos == -1) @@ -936,6 +936,10 @@ theora_dec_push_forward (GstTheoraDec * dec, GstBuffer * buf) GST_DEBUG_OBJECT (dec, "patch buffer %lld %lld", size, time); GST_BUFFER_TIMESTAMP (buffer) = time; + /* Next timestamp - this one is duration */ + GST_BUFFER_DURATION (buffer) = + (outtime - gst_util_uint64_scale_int ((size - 1) * GST_SECOND, + dec->info.fps_denominator, dec->info.fps_numerator)) - time; if (dec->discont) { GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT); @@ -1103,9 +1107,16 @@ theora_handle_data_packet (GstTheoraDec * dec, ogg_packet * packet, if (dec->frame_nr != -1) dec->frame_nr++; GST_BUFFER_OFFSET_END (out) = dec->frame_nr; - GST_BUFFER_DURATION (out) = - gst_util_uint64_scale_int (GST_SECOND, dec->info.fps_denominator, - dec->info.fps_numerator); + if (dec->granulepos != -1) { + gint64 cf = _theora_granule_frame (dec, dec->granulepos) + 1; + + GST_BUFFER_DURATION (out) = gst_util_uint64_scale_int (cf * GST_SECOND, + dec->info.fps_denominator, dec->info.fps_numerator) - outtime; + } else { + GST_BUFFER_DURATION (out) = + gst_util_uint64_scale_int (GST_SECOND, dec->info.fps_denominator, + dec->info.fps_numerator); + } GST_BUFFER_TIMESTAMP (out) = outtime; if (dec->segment.rate >= 0.0) @@ -1190,8 +1201,9 @@ theora_dec_decode_buffer (GstTheoraDec * dec, GstBuffer * buf) dec->last_timestamp = -1; } - GST_DEBUG_OBJECT (dec, "header=%02x packetno=%lld, outtime=%" GST_TIME_FORMAT, - packet.bytes ? packet.packet[0] : -1, packet.packetno, + GST_DEBUG_OBJECT (dec, "header=%02x packetno=%lld, granule pos=%" + G_GINT64_FORMAT ", outtime=%" GST_TIME_FORMAT, + packet.bytes ? packet.packet[0] : -1, packet.packetno, packet.granulepos, GST_TIME_ARGS (dec->last_timestamp)); /* switch depending on packet type. A zero byte packet is always a data diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index fb5ebab..a475baf 100644 --- a/gst/audioresample/gstaudioresample.c +++ b/gst/audioresample/gstaudioresample.c @@ -575,8 +575,6 @@ audioresample_do_output (GstAudioresample * audioresample, GstBuffer * outbuf) return GST_FLOW_OK; } -/* llabs() is C99, so we might not have it; just use a simple macro... */ -#define LLABS(x) ((x>0)?x:-x) static gboolean audioresample_check_discont (GstAudioresample * audioresample, GstClockTime timestamp) @@ -592,7 +590,7 @@ audioresample_check_discont (GstAudioresample * audioresample, GstClockTimeDiff diff = timestamp - (audioresample->prev_ts + audioresample->prev_duration); - if (LLABS (diff) > GST_SECOND / audioresample->i_rate) { + if (ABS (diff) > GST_SECOND / audioresample->i_rate) { GST_WARNING_OBJECT (audioresample, "encountered timestamp discontinuity of %" G_GINT64_FORMAT, diff); return TRUE; -- 2.7.4