diff options
author | wm4 <wm4@nowhere> | 2015-11-02 23:58:55 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-11-03 00:23:28 +0100 |
commit | d634394da6f71b93d61afbcc1c9d8c0eb4904d49 (patch) | |
tree | 02656b57349b55bcb14c41611e8308880eaeb7fa | |
parent | 609de236a9e2bf64407fa447c32d2cc1262d1727 (diff) | |
download | mpv-d634394da6f71b93d61afbcc1c9d8c0eb4904d49.tar.bz2 mpv-d634394da6f71b93d61afbcc1c9d8c0eb4904d49.tar.xz |
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.
-rw-r--r-- | audio/out/ao_alsa.c | 16 |
1 files changed, 12 insertions, 4 deletions
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); |