summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha.yang@navercorp.com>2019-11-07 22:00:03 +0900
committerTim-Philipp Müller <tim@centricular.com>2019-11-18 12:02:18 +0000
commit3997224eb440c60d41852bb5cfe6e7ab879992df (patch)
tree43534cb5d65d1147c5f51f2f0aba47f186728f8b
parent492415abcc743a6b44560a5d3445a23e119d9b12 (diff)
downloadgstreamer-plugins-base-3997224eb440c60d41852bb5cfe6e7ab879992df.tar.gz
audiorate: Update next_offset per rate change
To support runtime audio samplerate change, re-calculate next target offset per caps. Calculating the next buffer offset using the previous offset seems to be tricky and rounding error prone. Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/693
-rw-r--r--gst/audiorate/gstaudiorate.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gst/audiorate/gstaudiorate.c b/gst/audiorate/gstaudiorate.c
index eceeed2ad..30a5d6ffd 100644
--- a/gst/audiorate/gstaudiorate.c
+++ b/gst/audiorate/gstaudiorate.c
@@ -216,12 +216,24 @@ static gboolean
gst_audio_rate_setcaps (GstAudioRate * audiorate, GstCaps * caps)
{
GstAudioInfo info;
+ gint prev_rate = 0;
if (!gst_audio_info_from_caps (&info, caps))
goto wrong_caps;
+ prev_rate = audiorate->info.rate;
audiorate->info = info;
+ if (audiorate->next_offset >= 0 && prev_rate > 0 && prev_rate != info.rate) {
+ GST_DEBUG_OBJECT (audiorate,
+ "rate changed from %d to %d", prev_rate, info.rate);
+
+ /* calculate next_offset based on new rate value */
+ audiorate->next_offset =
+ gst_util_uint64_scale_int_round (audiorate->next_ts,
+ info.rate, GST_SECOND);
+ }
+
return TRUE;
/* ERRORS */