From c12a6ae73e10673901ff9fc7da236e6f68f74aef Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 15 Jun 2021 15:25:47 +0200 Subject: [PATCH] a52: limit the number of periods for ioplug from slave PCM Intel HDMI: PERIOD_SIZE: [32 4272000] PERIOD_BYTES: [128 17088000] PERIODS: [2 32] BUFFER_SIZE: [64 8544000] BUFFER_BYTES: [256 34176000] Selected: PERIOD_SIZE: 768 PERIOD_BYTES: 3072 PERIODS: 32 BUFFER_SIZE: 24576 BUFFER_BYTES: 98304 The a52_hw_params() tries to set the big 4271616 buffer size (frames) for speaker-test which is beyond the maximal slave buffer. BugLink: https://github.com/alsa-project/alsa-plugins/pull/23 Signed-off-by: Jaroslav Kysela --- a52/pcm_a52.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 14e444d..76511bf 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -839,7 +839,7 @@ static int a52_set_hw_constraint(struct a52_ctx *rec) SND_PCM_ACCESS_RW_NONINTERLEAVED }; unsigned int formats[] = { SND_PCM_FORMAT_S16 }; - int err; + int err, dir; snd_pcm_uframes_t buffer_max; unsigned int period_bytes, max_periods; @@ -868,8 +868,11 @@ static int a52_set_hw_constraint(struct a52_ctx *rec) return err; snd_pcm_hw_params_get_buffer_size_max(rec->hw_params, &buffer_max); + dir = -1; + snd_pcm_hw_params_get_periods_max(rec->hw_params, &max_periods, &dir); period_bytes = A52_FRAME_SIZE * 2 * rec->channels; - max_periods = buffer_max / A52_FRAME_SIZE; + if (buffer_max / A52_FRAME_SIZE < max_periods) + max_periods = buffer_max / A52_FRAME_SIZE; if ((err = snd_pcm_ioplug_set_param_minmax(&rec->io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, period_bytes, period_bytes)) < 0 || -- 2.47.1