From: Mark Nauwelaerts Date: Tue, 22 Mar 2011 10:09:56 +0000 (+0100) Subject: baseaudioencoder: use buffer running time for granule calculation X-Git-Tag: 1.19.3~511^2~6555^2~572 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1f5c34fe77d4af98a9b74cf49542c69948477c7;p=platform%2Fupstream%2Fgstreamer.git baseaudioencoder: use buffer running time for granule calculation --- diff --git a/gst-libs/gst/audio/gstbaseaudioencoder.c b/gst-libs/gst/audio/gstbaseaudioencoder.c index e56e73a..76c0886 100644 --- a/gst-libs/gst/audio/gstbaseaudioencoder.c +++ b/gst-libs/gst/audio/gstbaseaudioencoder.c @@ -715,6 +715,34 @@ gst_base_audio_encoder_drain (GstBaseAudioEncoder * enc) return gst_base_audio_encoder_push_buffers (enc, TRUE); } +static void +gst_base_audio_encoder_set_base_gp (GstBaseAudioEncoder * enc) +{ + GstClockTime ts; + + if (!enc->granule) + return; + + /* use running time for granule */ + /* incoming data is clipped, so a valid input should yield a valid output */ + ts = gst_segment_to_running_time (&enc->segment, GST_FORMAT_TIME, + enc->priv->base_ts); + if (GST_CLOCK_TIME_IS_VALID (ts)) { + enc->priv->base_gp = + GST_CLOCK_TIME_TO_FRAMES (enc->priv->base_ts, enc->ctx->state.rate); + GST_DEBUG_OBJECT (enc, "new base gp %" G_GINT64_FORMAT, + GST_TIME_ARGS (enc->priv->base_gp)); + } else { + /* should reasonably have a valid base, + * otherwise start at 0 if we did not already start there earlier */ + if (enc->priv->base_gp < 0) { + enc->priv->base_gp = 0; + GST_DEBUG_OBJECT (enc, "new base gp %" G_GINT64_FORMAT, + GST_TIME_ARGS (enc->priv->base_gp)); + } + } +} + static GstFlowReturn gst_base_audio_encoder_chain (GstPad * pad, GstBuffer * buffer) { @@ -790,12 +818,7 @@ gst_base_audio_encoder_chain (GstPad * pad, GstBuffer * buffer) priv->base_ts = GST_BUFFER_TIMESTAMP (buffer); GST_DEBUG_OBJECT (enc, "new base ts %" GST_TIME_FORMAT, GST_TIME_ARGS (priv->base_ts)); - if (enc->granule) { - priv->base_gp = - GST_CLOCK_TIME_TO_FRAMES (priv->base_ts, enc->ctx->state.rate); - GST_DEBUG_OBJECT (enc, "new base gp %" G_GINT64_FORMAT, - GST_TIME_ARGS (priv->base_gp)); - } + gst_base_audio_encoder_set_base_gp (enc); } /* check for continuity; @@ -854,9 +877,7 @@ gst_base_audio_encoder_chain (GstPad * pad, GstBuffer * buffer) } /* now re-sync ts */ priv->base_ts += diff; - if (priv->base_gp >= 0) - priv->base_gp = - GST_CLOCK_TIME_TO_FRAMES (priv->base_ts, enc->ctx->state.rate); + gst_base_audio_encoder_set_base_gp (enc); priv->discont |= discont; }