From 3bcc59120a776b1ad9698aab7603f8b8cec5fbc6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 3 Mar 2021 16:55:40 +0100 Subject: [PATCH] alsa: fix timeout adjustment Only adjust the timeout when the quantum increases so that we end u with exactly the number of samples of the new quantum. Suppose we are handling a quantum of 1024, we wake up with 1024 samples in the device, we now notice a quantum of 8192 and will pull in the 8192 samples, we then have 1024 + 8192 samples in the buffer. Schedule a timeout for 1024 samples so that we end up in the timout with 8192 samples in the device. --- spa/plugins/alsa/alsa-pcm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index b78be86b7..d7a5b4101 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -874,7 +874,8 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del int32_t diff = (int32_t) (state->last_threshold - state->threshold); spa_log_trace(state->log, NAME" %p: follower:%d quantum change %d -> %d (%d)", state, follower, state->last_threshold, state->threshold, diff); - state->next_time += diff / corr * 1e9 / state->rate; + if (diff < 0) + state->next_time += diff / corr * 1e9 / state->rate; state->last_threshold = state->threshold; }