diff options
author | Max Kellermann <max@musicpd.org> | 2017-01-14 20:49:59 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-01-14 20:51:51 +0100 |
commit | 667f20974248cd497df9f794b9cabc37f58c3ed1 (patch) | |
tree | a9c0640889c271f6c5bcbae9225046755de2c650 | |
parent | 4ad0747c785ebe48e80cf265db595cf8d17f5066 (diff) |
input/alsa: check snd_pcm_state() in Recover()
Copy some good code from the ALSA output plugin.
-rw-r--r-- | src/input/plugins/AlsaInputPlugin.cxx | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/input/plugins/AlsaInputPlugin.cxx b/src/input/plugins/AlsaInputPlugin.cxx index 23b4188eb..62519aed8 100644 --- a/src/input/plugins/AlsaInputPlugin.cxx +++ b/src/input/plugins/AlsaInputPlugin.cxx @@ -231,19 +231,40 @@ AlsaInputStream::Recover(int err) switch(err) { case -EPIPE: LogDebug(alsa_input_domain, "Buffer Overrun"); - // drop through + break; + } + + switch (snd_pcm_state(capture_handle)) { + case SND_PCM_STATE_PAUSED: + err = snd_pcm_pause(capture_handle, /* disable */ 0); + break; + + case SND_PCM_STATE_SUSPENDED: + err = snd_pcm_resume(capture_handle); + if (err == -EAGAIN) + return 0; + /* fall-through to snd_pcm_prepare: */ #if GCC_CHECK_VERSION(7,0) [[fallthrough]]; #endif + case SND_PCM_STATE_OPEN: + case SND_PCM_STATE_SETUP: + case SND_PCM_STATE_XRUN: + err = snd_pcm_prepare(capture_handle); + break; + + case SND_PCM_STATE_DISCONNECTED: + break; - case -ESTRPIPE: - case -EINTR: - err = snd_pcm_recover(capture_handle, err, 1); + case SND_PCM_STATE_PREPARED: + case SND_PCM_STATE_RUNNING: + case SND_PCM_STATE_DRAINING: + /* this is no error, so just keep running */ + err = 0; break; - default: - // something broken somewhere, give up - err = -1; } + + return err; } |