ao_alsa: handle -EPIPE XRUNs from snd_pcm_status

Set pcm state to SND_PCM_STATE_XRUN in case -EPIPE is received,
and handle this state as per the usual logic.

This way snd_pcm_prepare gets called, and the loop continued.

Inspired by a patch posted by malc_ on #mpv.
This commit is contained in:
Jan Ekström 2020-11-04 23:43:27 +02:00 committed by sfan5
parent 976fcf57c1
commit 8ddd4547fc
1 changed files with 11 additions and 2 deletions

View File

@ -933,9 +933,18 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state)
// (where things were retried in a loop).
for (int n = 0; n < 10; n++) {
err = snd_pcm_status(p->alsa, st);
CHECK_ALSA_ERROR("snd_pcm_status");
if (err == -EPIPE) {
// ALSA APIs can return -EPIPE when an XRUN happens,
// we skip right to handling it by setting pcmst
// manually.
pcmst = SND_PCM_STATE_XRUN;
} else {
// Otherwise do error checking and query the PCM state properly.
CHECK_ALSA_ERROR("snd_pcm_status");
pcmst = snd_pcm_status_get_state(st);
}
pcmst = snd_pcm_status_get_state(st);
if (pcmst == SND_PCM_STATE_PREPARED ||
pcmst == SND_PCM_STATE_RUNNING ||
pcmst == SND_PCM_STATE_PAUSED)