From aa5999a0c036d1ccd52f51845e61bde56344566b Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 7 Jun 2003 00:34:51 +0000 Subject: [PATCH] Another duration patch from Joshua (slightly modified by me) Original commit message from CVS: Another duration patch from Joshua (slightly modified by me) --- ext/lame/gstlame.c | 20 ++++++++++++++++++-- ext/lame/gstlame.h | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ext/lame/gstlame.c b/ext/lame/gstlame.c index 3b29698..0c0ab52 100644 --- a/ext/lame/gstlame.c +++ b/ext/lame/gstlame.c @@ -653,6 +653,8 @@ gst_lame_chain (GstPad *pad, GstBuffer *buf) } } else { + gint64 duration; + if (!lame->initialized) { gst_buffer_unref (buf); gst_element_error (GST_ELEMENT (lame), "encoder not initialized (input is not audio?)"); @@ -681,9 +683,22 @@ gst_lame_chain (GstPad *pad, GstBuffer *buf) "encoded %d bytes of audio to %d bytes of mp3", GST_BUFFER_SIZE (buf), mp3_size); + duration = (GST_SECOND * GST_BUFFER_SIZE (buf) / + (2 * lame->samplerate * lame->num_channels)); + + if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE && + GST_BUFFER_DURATION (buf) != duration) + GST_DEBUG (GST_CAT_PLUGIN_INFO, + "mad: incoming buffer had incorrect duration %lld, " + "outgoing buffer will have correct duration %lld", + GST_BUFFER_DURATION (buf), duration); + if (lame->last_ts == GST_CLOCK_TIME_NONE) { - lame->last_ts = GST_BUFFER_TIMESTAMP (buf); - lame->last_offs = GST_BUFFER_OFFSET (buf); + lame->last_ts = GST_BUFFER_TIMESTAMP (buf); + lame->last_offs = GST_BUFFER_OFFSET (buf); + lame->last_duration = duration; + } else { + lame->last_duration += duration; } gst_buffer_unref (buf); @@ -695,6 +710,7 @@ gst_lame_chain (GstPad *pad, GstBuffer *buf) GST_BUFFER_SIZE (outbuf) = mp3_size; GST_BUFFER_TIMESTAMP (outbuf) = lame->last_ts; GST_BUFFER_OFFSET (outbuf) = lame->last_offs; + GST_BUFFER_DURATION (outbuf) = lame->last_duration; gst_pad_push (lame->srcpad,outbuf); diff --git a/ext/lame/gstlame.h b/ext/lame/gstlame.h index 220d61b..d1055a7 100644 --- a/ext/lame/gstlame.h +++ b/ext/lame/gstlame.h @@ -95,7 +95,7 @@ struct _GstLame { lame_global_flags *lgf; /* time tracker */ - guint64 last_ts, last_offs; + guint64 last_ts, last_offs, last_duration; }; struct _GstLameClass { -- 2.7.4