From: "Bjørn Mork" <bjorn@mork.no>
To: qemu-devel@nongnu.org
Cc: "Bjørn Mork" <bjorn@mork.no>
Subject: [Qemu-devel] [PATCH] alsa: add host suspend/resume support
Date: Thu, 30 Jul 2009 09:44:26 +0200 [thread overview]
Message-ID: <1248939866-21541-1-git-send-email-bjorn@mork.no> (raw)
In-Reply-To: <Pine.LNX.4.64.0907291751280.4082@linmac.oyster.ru>
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ørn Mork <bjorn@mork.no>
---
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;
}
+static int alsa_resume (snd_pcm_t *handle)
+{
+ int err = 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;
+ 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;
@@ -779,8 +802,21 @@ static int alsa_run_in (HWVoiceIn *hw)
return 0;
}
- if (!avail && (snd_pcm_state (alsa->handle) == SND_PCM_STATE_PREPARED)) {
- avail = hw->samples;
+ if (!avail) {
+ switch (snd_pcm_state (alsa->handle)) {
+ case SND_PCM_STATE_PREPARED:
+ avail = hw->samples;
+ break;
+ case SND_PCM_STATE_SUSPENDED:
+ /* stream is suspended and waiting for an application recovery */
+ if (alsa_resume (alsa->handle)) {
+ dolog ("Failed to resume suspended input stream\n");
+ return 0;
+ }
+ if (conf.verbose) {
+ dolog ("Resuming suspended input stream\n");
+ }
+ }
}
decr = audio_MIN (dead, avail);
--
1.5.6.5
next prev parent reply other threads:[~2009-07-30 7:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 10:51 [Qemu-devel] [PATCH] alsa broken when the host is suspended (or hibernated) Bjørn Mork
2009-07-29 11:57 ` malc
2009-07-29 12:36 ` Bjørn Mork
2009-07-29 13:45 ` malc
2009-07-29 13:46 ` Bjørn Mork
2009-07-29 13:51 ` malc
2009-07-30 7:44 ` Bjørn Mork [this message]
2009-07-30 10:47 ` [Qemu-devel] Re: [PATCH] alsa: add host suspend/resume support malc
2009-07-30 7:47 ` [Qemu-devel] [PATCH] alsa broken when the host is suspended (or hibernated) Bjørn Mork
2009-07-29 16:58 ` Rob Landley
2009-07-29 18:57 ` malc
2009-07-30 10:29 ` malc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1248939866-21541-1-git-send-email-bjorn@mork.no \
--to=bjorn@mork.no \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).