audio: attempt to gracefully handle disconnected/reconnected devices

Currently only ALSA is supported/tested, and only if the mixer
device is not on the audio device being disconnected (software
mixer).

This patch allows me to disconnect my Headroom Total Airhead USB
sound card, and resume playback (skips to the next song, which
should be fixed) when the device is plugged back in.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4364 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2006-07-16 16:52:29 +00:00
parent 8224e837ef
commit 6b2167a444
2 changed files with 13 additions and 5 deletions

View File

@ -274,7 +274,7 @@ static void syncAudioDevicesEnabledArrays(void) {
static int flushAudioBuffer() {
int ret = -1;
int i;
int i, err;
if(audioBufferPos == 0) return 0;
@ -286,11 +286,14 @@ static int flushAudioBuffer() {
for(i = 0; i < audioOutputArraySize; i++) {
if(!myAudioDevicesEnabled[i]) continue;
if(0 == playAudioOutput(audioOutputArray[i], audioBuffer,
audioBufferPos))
{
err = playAudioOutput(audioOutputArray[i], audioBuffer,
audioBufferPos);
if (!err)
ret = 0;
}
else if (err < 0)
/* device should already be closed if the play func
* returned an error */
myAudioDevicesEnabled[i] = 0;
}
audioBufferPos = 0;

View File

@ -315,6 +315,11 @@ static int alsa_errorRecovery(AlsaData * ad, int err) {
case SND_PCM_STATE_XRUN:
err = snd_pcm_prepare(ad->pcmHandle);
break;
case SND_PCM_STATE_DISCONNECTED:
/* so alsa_closeDevice won't try to drain: */
snd_pcm_close(ad->pcmHandle);
ad->pcmHandle = NULL;
break;
default:
/* unknown state, do nothing */
break;