From 685aed1de2ba5a966b5bb733c175aeadf047a3a3 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 2e3427526..fad4e0852 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -3386,6 +3386,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); }