From 667f20974248cd497df9f794b9cabc37f58c3ed1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Jan 2017 20:49:59 +0100 Subject: [PATCH] input/alsa: check snd_pcm_state() in Recover() Copy some good code from the ALSA output plugin. --- src/input/plugins/AlsaInputPlugin.cxx | 37 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 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 -ESTRPIPE: - case -EINTR: - err = snd_pcm_recover(capture_handle, err, 1); + 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 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; }