alsa/oss: Remove fd transfer handlers before closing oss/alsa fd/handle

Signed-off-by: malc <av1474@comtv.ru>
This commit is contained in:
malc 2009-09-14 03:51:48 +04:00
parent 9332f6a2e2
commit 6ebfda13a6
2 changed files with 32 additions and 27 deletions

View File

@ -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)

View File

@ -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;
}