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
This commit is contained in:
Seungha Yang 2019-11-07 22:00:03 +09:00 committed by GStreamer Merge Bot
parent b6bdff0c84
commit fab2d6d60c

View file

@ -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 */