Merge branch 'alsa_input_buffer' of https://github.com/borine/MPD

This commit is contained in:
Max Kellermann 2023-11-26 08:24:27 +01:00
commit 634b38169a
2 changed files with 10 additions and 4 deletions

1
NEWS
View File

@ -21,6 +21,7 @@ ver 0.24 (not yet released)
* storage * storage
- curl: optimize database update - curl: optimize database update
* input * input
- alsa: limit ALSA buffer time to 2 seconds
- curl: add "connect_timeout" configuration - curl: add "connect_timeout" configuration
* decoder * decoder
- ffmpeg: require FFmpeg 4.0 or later - ffmpeg: require FFmpeg 4.0 or later

View File

@ -353,9 +353,14 @@ AlsaInputStream::ConfigureCapture(AudioFormat audio_format)
period_size_min, period_size_max, period_size_min, period_size_max,
period_time_min, period_time_max); period_time_min, period_time_max);
/* choose the maximum possible buffer_size ... */ /* choose the maximum buffer_time up to limit of 2 seconds ... */
snd_pcm_hw_params_set_buffer_size(capture_handle, hw_params, unsigned buffer_time = buffer_time_max;
buffer_size_max); if (buffer_time > 2000000U)
buffer_time = 2000000U;
int direction = -1;
if ((err = snd_pcm_hw_params_set_buffer_time_near(capture_handle,
hw_params, &buffer_time, &direction)) < 0)
throw Alsa::MakeError(err, "Cannot set buffer time");
/* ... and calculate the period_size to have four periods in /* ... and calculate the period_size to have four periods in
one buffer; this way, we get woken up often enough to avoid one buffer; this way, we get woken up often enough to avoid
@ -363,7 +368,7 @@ AlsaInputStream::ConfigureCapture(AudioFormat audio_format)
snd_pcm_uframes_t buffer_size; snd_pcm_uframes_t buffer_size;
if (snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size) == 0) { if (snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size) == 0) {
snd_pcm_uframes_t period_size = buffer_size / 4; snd_pcm_uframes_t period_size = buffer_size / 4;
int direction = -1; direction = -1;
if ((err = snd_pcm_hw_params_set_period_size_near(capture_handle, if ((err = snd_pcm_hw_params_set_period_size_near(capture_handle,
hw_params, &period_size, &direction)) < 0) hw_params, &period_size, &direction)) < 0)
throw Alsa::MakeError(err, "Cannot set period size"); throw Alsa::MakeError(err, "Cannot set period size");