]> git.alsa-project.org Git - alsa-plugins.git/commitdiff
a52: limit the number of periods for ioplug from slave PCM
authorJaroslav Kysela <perex@perex.cz>
Tue, 15 Jun 2021 13:25:47 +0000 (15:25 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 16 Jun 2021 06:53:46 +0000 (08:53 +0200)
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 <perex@perex.cz>
a52/pcm_a52.c

index 14e444d2cbea763a784a42a2f2793032b1055ab5..76511bf0584ca77dff5f19f0719f50b9d0e92b44 100644 (file)
@@ -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 ||