From a95d6dd55359a9d20c99ad9218a29ac880c47df9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 22 Jul 2025 16:48:43 +0200 Subject: [PATCH] alsa: update resampler requested size before reading spa_alsa_read is called from the source process function when we are a follower and no buffer is ready yet. Part of the rate correction was performed by the ALSA driver when it woke up but now, the resampler has updated the requested size and we need to requery it before we can start reading samples. Otherwise, we end up with requested samples from before the rate update and we might not give enough samples to the resampler. In that case, the adapter will call us again and we will again try to produce a buffer worth of the requested samples, which will xrun. --- spa/plugins/alsa/alsa-pcm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 5ba9f82c4..cb8f04c56 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -3384,6 +3384,10 @@ int spa_alsa_read(struct state *state) uint64_t current_time = state->position->clock.nsec; alsa_read_sync(state, current_time); } + else if (state->resample && state->rate_match) { + state->read_size = state->rate_match->size; + state->max_read = SPA_MIN(state->buffer_frames, state->read_size); + } return alsa_read_frames(state); }