From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MWQJq-0002eW-Mk for qemu-devel@nongnu.org; Thu, 30 Jul 2009 03:44:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MWQJm-0002eK-6t for qemu-devel@nongnu.org; Thu, 30 Jul 2009 03:44:54 -0400 Received: from [199.232.76.173] (port=55414 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWQJm-0002eH-1Q for qemu-devel@nongnu.org; Thu, 30 Jul 2009 03:44:50 -0400 Received: from mx20.gnu.org ([199.232.41.8]:13123) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MWQJl-0006Ac-Eg for qemu-devel@nongnu.org; Thu, 30 Jul 2009 03:44:49 -0400 Received: from canardo.mork.no ([148.122.252.1]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MWQJk-0007Pj-DY for qemu-devel@nongnu.org; Thu, 30 Jul 2009 03:44:48 -0400 From: =?utf-8?q?Bj=C3=B8rn=20Mork?= Date: Thu, 30 Jul 2009 09:44:26 +0200 Message-Id: <1248939866-21541-1-git-send-email-bjorn@mork.no> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] alsa: add host suspend/resume support List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?utf-8?q?Bj=C3=B8rn=20Mork?= Both input and output streams may be in SND_PCM_STATE_SUSPENDED after the host is suspended and resumed, meaning "Hardware is suspended". snd_pcm_readi() and snd_pcm_writei() will return -ESTRPIPE if called while the stream is in this state. Call snd_pcm_resume() to enable audio output and capture after host resume. Signed-off-by: Bj=C3=B8rn Mork --- audio/alsaaudio.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-) diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index d0b7cd0..c970afb 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -503,6 +503,16 @@ static int alsa_recover (snd_pcm_t *handle) return 0; } =20 +static int alsa_resume (snd_pcm_t *handle) +{ + int err =3D snd_pcm_resume (handle); + if (err < 0) { + alsa_logerr (err, "Failed to resume handle %p\n", handle); + return -1; + } + return 0; +} + static snd_pcm_sframes_t alsa_get_avail (snd_pcm_t *handle) { snd_pcm_sframes_t avail; @@ -580,6 +590,19 @@ static int alsa_run_out (HWVoiceOut *hw) } continue; =20 + case -ESTRPIPE: + /* stream is suspended and waiting for an + application recovery */ + if (alsa_resume (alsa->handle)) { + alsa_logerr (written, "Failed to write %d frames= \n", + len); + goto exit; + } + if (conf.verbose) { + dolog ("Resuming suspended output stream\n"); + } + continue; + case -EAGAIN: goto exit; =20 @@ -779,8 +802,21 @@ static int alsa_run_in (HWVoiceIn *hw) return 0; } =20 - if (!avail && (snd_pcm_state (alsa->handle) =3D=3D SND_PCM_STATE_PRE= PARED)) { - avail =3D hw->samples; + if (!avail) { + switch (snd_pcm_state (alsa->handle)) { + case SND_PCM_STATE_PREPARED: + avail =3D hw->samples; + break; + case SND_PCM_STATE_SUSPENDED: + /* stream is suspended and waiting for an application recove= ry */ + if (alsa_resume (alsa->handle)) { + dolog ("Failed to resume suspended input stream\n"); + return 0; + } + if (conf.verbose) { + dolog ("Resuming suspended input stream\n"); + } + } } =20 decr =3D audio_MIN (dead, avail); --=20 1.5.6.5