Commit 855054fe authored by Max Kellermann's avatar Max Kellermann

alsa: don't close PCM handle in alsa_recover()

If the PCM handle gets disconnected, don't close and clear it in alsa_recover(). The MPD core will call alsa_close() anyway. This way, we can always assume that alsa_data.pcm is always valid.
parent 538701e7
...@@ -94,7 +94,6 @@ alsa_data_new(void) ...@@ -94,7 +94,6 @@ alsa_data_new(void)
struct alsa_data *ret = g_new(struct alsa_data, 1); struct alsa_data *ret = g_new(struct alsa_data, 1);
ret->mode = 0; ret->mode = 0;
ret->pcm = NULL;
ret->writei = snd_pcm_writei; ret->writei = snd_pcm_writei;
return ret; return ret;
...@@ -413,8 +412,6 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error) ...@@ -413,8 +412,6 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error)
err = snd_pcm_open(&ad->pcm, alsa_device(ad), err = snd_pcm_open(&ad->pcm, alsa_device(ad),
SND_PCM_STREAM_PLAYBACK, ad->mode); SND_PCM_STREAM_PLAYBACK, ad->mode);
if (err < 0) { if (err < 0) {
ad->pcm = NULL;
g_set_error(error, alsa_output_quark(), err, g_set_error(error, alsa_output_quark(), err,
"Failed to open ALSA device \"%s\": %s", "Failed to open ALSA device \"%s\": %s",
alsa_device(ad), snd_strerror(err)); alsa_device(ad), snd_strerror(err));
...@@ -424,7 +421,6 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error) ...@@ -424,7 +421,6 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error)
success = alsa_setup(ad, audio_format, bitformat, error); success = alsa_setup(ad, audio_format, bitformat, error);
if (!success) { if (!success) {
snd_pcm_close(ad->pcm); snd_pcm_close(ad->pcm);
ad->pcm = NULL;
return false; return false;
} }
...@@ -456,9 +452,6 @@ alsa_recover(struct alsa_data *ad, int err) ...@@ -456,9 +452,6 @@ alsa_recover(struct alsa_data *ad, int err)
err = snd_pcm_prepare(ad->pcm); err = snd_pcm_prepare(ad->pcm);
break; break;
case SND_PCM_STATE_DISCONNECTED: case SND_PCM_STATE_DISCONNECTED:
/* so alsa_closeDevice won't try to drain: */
snd_pcm_close(ad->pcm);
ad->pcm = NULL;
break; break;
/* this is no error, so just keep running */ /* this is no error, so just keep running */
case SND_PCM_STATE_RUNNING: case SND_PCM_STATE_RUNNING:
...@@ -485,13 +478,10 @@ alsa_close(void *data) ...@@ -485,13 +478,10 @@ alsa_close(void *data)
{ {
struct alsa_data *ad = data; struct alsa_data *ad = data;
if (ad->pcm != NULL) { if (snd_pcm_state(ad->pcm) == SND_PCM_STATE_RUNNING)
if (snd_pcm_state(ad->pcm) == SND_PCM_STATE_RUNNING) snd_pcm_drain(ad->pcm);
snd_pcm_drain(ad->pcm);
snd_pcm_close(ad->pcm); snd_pcm_close(ad->pcm);
ad->pcm = NULL;
}
mixer_close(ad->mixer); mixer_close(ad->mixer);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment