From 00fa39befae4076277c9a046f72c9fe8a4275048 Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Tue, 8 Aug 2017 20:35:25 +0200 Subject: [PATCH] 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 --- gst-libs/gst/audio/gstaudioencoder.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/audio/gstaudioencoder.c b/gst-libs/gst/audio/gstaudioencoder.c index 5c3b97bae2..182d6a5496 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