From d634394da6f71b93d61afbcc1c9d8c0eb4904d49 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 2 Nov 2015 23:58:55 +0100 Subject: ao_alsa: make failure of buffer parameter setting non-fatal These calls actually can leave the ALSA configuration space empty (how very useful), which is why snd_pcm_hw_params() can fail. An earlier change intended to make this non-fatal, but it didn't work for this reason. Backup the old parameters, so we can retry with the non-empty configuration space. (It has to be non-empty, because the previous setters didn't fail.) Note that the buffer settings are not very important to us. They're a leftover from MPlayer, which needed to write enough data to the audio device to not underrun while decoding and displaying a video frame. In mpv, most of these things happen asynchronously, _and_ there is a dedicated thread just for feeding the audio device, so we should be pretty imune even against extreme buffer settings. But I suppose it's still useful to prevent PulseAudio from making the buffer too large, so still keep this code. --- audio/out/ao_alsa.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index 9f297bbade..b6066bd0d4 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -548,13 +548,21 @@ static int init_device(struct ao *ao, bool second_try) (p->alsa, alsa_hwparams, &ao->samplerate, NULL); CHECK_ALSA_ERROR("Unable to set samplerate-2"); + snd_pcm_hw_params_t *hwparams_backup; + snd_pcm_hw_params_alloca(&hwparams_backup); + snd_pcm_hw_params_copy(hwparams_backup, alsa_hwparams); + + // Cargo-culted buffer settings; might still be useful for PulseAudio. err = snd_pcm_hw_params_set_buffer_time_near (p->alsa, alsa_hwparams, &(unsigned int){BUFFER_TIME}, NULL); CHECK_ALSA_WARN("Unable to set buffer time near"); - - err = snd_pcm_hw_params_set_periods_near - (p->alsa, alsa_hwparams, &(unsigned int){FRAGCOUNT}, NULL); - CHECK_ALSA_WARN("Unable to set periods"); + if (err >= 0) { + err = snd_pcm_hw_params_set_periods_near + (p->alsa, alsa_hwparams, &(unsigned int){FRAGCOUNT}, NULL); + CHECK_ALSA_WARN("Unable to set periods"); + } + if (err < 0) + snd_pcm_hw_params_copy(alsa_hwparams, hwparams_backup); /* finally install hardware parameters */ err = snd_pcm_hw_params(p->alsa, alsa_hwparams); -- cgit v1.2.3