From 39716cdd440edc4fd1f610b45db20741dd92af6f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 11 Jan 2022 16:33:19 +0100 Subject: [PATCH] alsa: limit batch period size to default We take half of the current quantum as the period size for batch devices. Limit this to the default quantum to ensure we don't end up with too much headroom. --- spa/plugins/alsa/alsa-pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 650a0dc9a..1d7ea762b 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1420,8 +1420,10 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ if (period_size == 0) period_size = state->position ? state->position->clock.duration : DEFAULT_PERIOD; /* batch devices get their hw pointers updated every period. Make - * the period smaller and add one period of headroom */ - period_size /= 2; + * the period smaller and add one period of headroom. Limit the + * period size to our default so that we don't create too much + * headroom. */ + period_size = SPA_MIN(period_size, DEFAULT_PERIOD) / 2; spa_log_info(state->log, "%s: batch mode, period_size:%ld", state->props.device, period_size); } else {