From c9c98312cb3dffba9f96f914b12ab666ad6c6309 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 18 Oct 2023 15:44:07 +0200 Subject: [PATCH] alsa: don't limit reads to avail The ringbuffer can warp around and then there is really more available. --- spa/plugins/alsa/alsa-pcm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index cfaa9032e..356778e90 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1483,6 +1483,10 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num, static void recalc_headroom(struct state *state) { uint32_t latency; + uint32_t rate = 0; + + if (state->position != NULL) + rate = state->position->clock.target_rate.denom; state->headroom = state->default_headroom; if (!state->disable_tsched || state->resample) { @@ -1500,8 +1504,8 @@ static void recalc_headroom(struct state *state) state->headroom = SPA_MIN(state->headroom, state->buffer_frames); latency = SPA_MAX(state->min_delay, SPA_MIN(state->max_delay, state->headroom)); - if (state->position != NULL && state->rate != 0) - latency = SPA_SCALE32_UP(latency, state->position->clock.target_rate.denom, state->rate); + if (rate != 0 && state->rate != 0) + latency = SPA_SCALE32_UP(latency, rate, state->rate); state->latency[state->port_direction].min_rate = state->latency[state->port_direction].max_rate = latency; @@ -2744,8 +2748,6 @@ static int alsa_read_frames(struct state *state) alsa_recover(state, res); return res; } - if (avail < frames) - frames = avail; spa_log_trace_fp(state->log, "%p: begin offs:%ld frames:%ld avail:%ld thres:%d", state, offset, frames, avail, state->threshold); } else {