summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio_out/audio_alsa_out.c12
-rw-r--r--src/xine-engine/audio_out.c16
2 files changed, 18 insertions, 10 deletions
diff --git a/src/audio_out/audio_alsa_out.c b/src/audio_out/audio_alsa_out.c
index 6ad78da2a..ce3e7fb2b 100644
--- a/src/audio_out/audio_alsa_out.c
+++ b/src/audio_out/audio_alsa_out.c
@@ -752,6 +752,9 @@ static int ao_alsa_write(ao_driver_t *this_gen, int16_t *data, uint32_t count) {
if (res < 0)
return 0;
state = snd_pcm_state(this->audio_fd);
+ } else if (state == SND_PCM_STATE_DISCONNECTED) {
+ /* the device is gone. audio_out.c handles it if we return something < 0 */
+ return -1;
}
if (state == SND_PCM_STATE_XRUN) {
#ifdef LOG_DEBUG
@@ -784,11 +787,11 @@ static int ao_alsa_write(ao_driver_t *this_gen, int16_t *data, uint32_t count) {
#endif
snd_pcm_status(this->audio_fd, pcm_stat);
if ( snd_pcm_status_get_avail(pcm_stat) < number_of_frames) {
- wait_result = snd_pcm_wait(this->audio_fd, 1000000);
+ wait_result = snd_pcm_wait(this->audio_fd, 1000);
#ifdef LOG_DEBUG
printf("audio_alsa_out:write:loop:wait_result=%d\n",wait_result);
#endif
- if (wait_result < 0) return 0;
+ if (wait_result <= 0) return 0;
}
}
if (this->mmap != 0) {
@@ -808,7 +811,10 @@ static int ao_alsa_write(ao_driver_t *this_gen, int16_t *data, uint32_t count) {
return 0;
continue;
}
- if ( (state != SND_PCM_STATE_PREPARED) &&
+ if (state == SND_PCM_STATE_DISCONNECTED) {
+ /* the device is gone. audio_out.c handles it if we return something < 0 */
+ return -1;
+ } else if ( (state != SND_PCM_STATE_PREPARED) &&
(state != SND_PCM_STATE_RUNNING) &&
(state != SND_PCM_STATE_DRAINING) ) {
xprintf(this->class->xine, XINE_VERBOSITY_DEBUG,
diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c
index 66e28d80d..2655d495a 100644
--- a/src/xine-engine/audio_out.c
+++ b/src/xine-engine/audio_out.c
@@ -1211,13 +1211,15 @@ static void *ao_loop (void *this_gen) {
}
if( result < 0 ) {
- /* FIXME: USB device unplugged.
- * We should get the card into a closed state here, that involves closing
- * the PCM as well as the MIXER.
- * Maybe we should pause the stream until the USB device is plugged in again.
- * Return values 0 happen even if usb not unplugged, so needs further investigation.
- */
- xprintf(this->xine, XINE_VERBOSITY_LOG, _("write to sound card failed. Was a USB device unplugged ?\n"));
+ /* device unplugged. */
+ xprintf(this->xine, XINE_VERBOSITY_LOG, _("write to sound card failed. Assuming the device was unplugged.\n"));
+
+ pthread_mutex_lock( &this->driver_lock );
+ if(this->driver_open)
+ this->driver->close(this->driver);
+ this->driver_open = 0;
+ pthread_mutex_unlock( &this->driver_lock );
+ /* closing the driver will result in XINE_MSG_AUDIO_OUT_UNAVAILABLE to be emitted */
}
lprintf ("loop: next buf from fifo\n");