diff options
author | Mark Nauwelaerts <mnauw@users.sourceforge.net> | 2017-08-08 20:35:25 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-08-11 10:59:12 +0300 |
commit | 035d1d48f11855404073758eebe4e72e2dd38bb7 (patch) | |
tree | d0114dddb638b4b8793dd978232570667a3fa947 | |
parent | 556141ea5387459225bf26bb97f914c99ea5ea37 (diff) | |
download | gstreamer-plugins-base-035d1d48f11855404073758eebe4e72e2dd38bb7.tar.gz |
audioencoder: also adjust sample count upon discont to avoid ts overflow
Only adjusting the base_ts might lead to a negative ts and as such integer
overflow into a huge timestamp which then propagates into the granulepos
and so on. Instead, resync to incoming buffer timestamp using both base_ts
and sample count rather than only base_ts.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=785948
-rw-r--r-- | gst-libs/gst/audio/gstaudioencoder.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/gst-libs/gst/audio/gstaudioencoder.c b/gst-libs/gst/audio/gstaudioencoder.c index 5c3b97bae..182d6a549 100644 --- a/gst-libs/gst/audio/gstaudioencoder.c +++ b/gst-libs/gst/audio/gstaudioencoder.c @@ -1325,7 +1325,18 @@ gst_audio_encoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) } if (discont) { /* now re-sync ts */ - priv->base_ts += diff; + GstClockTime shift = + gst_util_uint64_scale (gst_adapter_available (priv->adapter), + GST_SECOND, ctx->info.rate * ctx->info.bpf); + + if (G_UNLIKELY (shift > GST_BUFFER_TIMESTAMP (buffer))) { + /* ERROR */ + goto wrong_time; + } + /* arrange for newly added samples to come out with the ts + * of the incoming buffer that adds these */ + priv->base_ts = GST_BUFFER_TIMESTAMP (buffer) - shift; + priv->samples = 0; gst_audio_encoder_set_base_gp (enc); priv->discont |= discont; } @@ -1362,6 +1373,14 @@ wrong_buffer: ret = GST_FLOW_ERROR; goto done; } +wrong_time: + { + GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL), + ("buffer going too far back in time")); + gst_buffer_unref (buffer); + ret = GST_FLOW_ERROR; + goto done; + } } static gboolean |