From 1e6dad14d3cd970dbd8f8c899c2f961df4e6b9ad Mon Sep 17 00:00:00 2001 From: Martin Geier Date: Wed, 27 Mar 2024 11:56:12 +0100 Subject: [PATCH] alsa-pcm: use headroom to calculate minimum available frames for non time scheduling Alsa needs to call handler soon enough to have headroom plus threshold frames in the buffer and not only threshold left. Signed-off-by: Martin Geier --- spa/plugins/alsa/alsa-pcm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 20f0fcd51..e164b91d1 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -2336,14 +2336,15 @@ static int set_swparams(struct state *state) CHECK(snd_pcm_sw_params_set_start_threshold(hndl, params, LONG_MAX), "set_start_threshold"); if (state->disable_tsched) { - snd_pcm_uframes_t avail_min; + snd_pcm_uframes_t avail_min = 0; if (state->stream == SND_PCM_STREAM_PLAYBACK) { /* wake up when buffer has target frames or less data (will underrun soon) */ - avail_min = state->buffer_frames - state->threshold; + if (state->buffer_frames >= (state->threshold + state->headroom)) + avail_min = state->buffer_frames - (state->threshold + state->headroom); } else { /* wake up when there's target frames or more (enough for us to read and push a buffer) */ - avail_min = state->threshold; + avail_min = SPA_MIN(state->threshold + state->headroom, state->buffer_frames); } CHECK(snd_pcm_sw_params_set_avail_min(hndl, params, avail_min), "set_avail_min");