alsa-pcm: do not allow headroom plus threshold be bigger then the alsa buffer

Headroom are extra samples available in alsa buffer on top of a threshold.
Its use to prefill alsa buffer with silence before the playback starts
and later its use to calculate target number of a frames in the alsa buffer
when get_status is called. Target is calculated as headroom plus
threshold, which should be smaller then buffer size to make sense.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Martin Geier 2024-03-27 11:48:10 +01:00 committed by Wim Taymans
parent 695f236f5f
commit b4ed8dcf14

View file

@ -1939,7 +1939,10 @@ static void recalc_headroom(struct state *state)
if (state->stream == SND_PCM_STREAM_CAPTURE)
state->headroom = SPA_MAX(state->headroom, 32u);
}
state->headroom = SPA_MIN(state->headroom, state->buffer_frames);
if (SPA_LIKELY(state->buffer_frames >= state->threshold))
state->headroom = SPA_MIN(state->headroom, state->buffer_frames - state->threshold);
else
state->headroom = 0;
latency = SPA_MAX(state->min_delay, SPA_MIN(state->max_delay, state->headroom));
if (rate != 0 && state->rate != 0)