diff options
-rw-r--r-- | audio/alsaaudio.c | 53 | ||||
-rw-r--r-- | audio/ossaudio.c | 6 |
2 files changed, 32 insertions, 27 deletions
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index 28c245dc70..b7031518f0 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -123,7 +123,23 @@ static void GCC_FMT_ATTR (3, 4) alsa_logerr2 ( AUD_log (AUDIO_CAP, "Reason: %s\n", snd_strerror (err)); } -static void alsa_anal_close (snd_pcm_t **handlep) +static void alsa_fini_poll (struct pollhlp *hlp) +{ + int i; + struct pollfd *pfds = hlp->pfds; + + if (pfds) { + for (i = 0; i < hlp->count; ++i) { + qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL); + } + qemu_free (pfds); + } + hlp->pfds = NULL; + hlp->count = 0; + hlp->handle = NULL; +} + +static void alsa_anal_close1 (snd_pcm_t **handlep) { int err = snd_pcm_close (*handlep); if (err) { @@ -132,6 +148,12 @@ static void alsa_anal_close (snd_pcm_t **handlep) *handlep = NULL; } +static void alsa_anal_close (snd_pcm_t **handlep, struct pollhlp *hlp) +{ + alsa_fini_poll (hlp); + alsa_anal_close1 (handlep); +} + static int alsa_recover (snd_pcm_t *handle) { int err = snd_pcm_prepare (handle); @@ -648,7 +670,7 @@ static int alsa_open (int in, struct alsa_params_req *req, return 0; err: - alsa_anal_close (&handle); + alsa_anal_close1 (&handle); return -1; } @@ -765,35 +787,17 @@ static int alsa_run_out (HWVoiceOut *hw) return decr; } -static void alsa_fini_poll (struct pollhlp *hlp) -{ - int i; - struct pollfd *pfds = hlp->pfds; - - if (pfds) { - for (i = 0; i < hlp->count; ++i) { - qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL); - } - qemu_free (pfds); - } - hlp->pfds = NULL; - hlp->count = 0; - hlp->handle = NULL; -} - static void alsa_fini_out (HWVoiceOut *hw) { ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; ldebug ("alsa_fini\n"); - alsa_anal_close (&alsa->handle); + alsa_anal_close (&alsa->handle, &alsa->pollhlp); if (alsa->pcm_buf) { qemu_free (alsa->pcm_buf); alsa->pcm_buf = NULL; } - - alsa_fini_poll (&alsa->pollhlp); } static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as) @@ -830,7 +834,7 @@ static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as) if (!alsa->pcm_buf) { dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n", hw->samples, 1 << hw->info.shift); - alsa_anal_close (&handle); + alsa_anal_close1 (&handle); return -1; } @@ -921,7 +925,7 @@ static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as) if (!alsa->pcm_buf) { dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n", hw->samples, 1 << hw->info.shift); - alsa_anal_close (&handle); + alsa_anal_close1 (&handle); return -1; } @@ -933,13 +937,12 @@ static void alsa_fini_in (HWVoiceIn *hw) { ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; - alsa_anal_close (&alsa->handle); + alsa_anal_close (&alsa->handle, &alsa->pollhlp); if (alsa->pcm_buf) { qemu_free (alsa->pcm_buf); alsa->pcm_buf = NULL; } - alsa_fini_poll (&alsa->pollhlp); } static int alsa_run_in (HWVoiceIn *hw) diff --git a/audio/ossaudio.c b/audio/ossaudio.c index ecb88395b7..0b391e422c 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -114,11 +114,13 @@ static void GCC_FMT_ATTR (3, 4) oss_logerr2 ( static void oss_anal_close (int *fdp) { - int err = close (*fdp); + int err; + + qemu_set_fd_handler (*fdp, NULL, NULL, NULL); + err = close (*fdp); if (err) { oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp); } - qemu_set_fd_handler (*fdp, NULL, NULL, NULL); *fdp = -1; } |