# HG changeset patch
# User Matthias Kretz <[EMAIL PROTECTED]>
# Date 1180992616 -7200
# Node ID 956dd4cfadac32e0ee510c1b4d460ad9a23ea16e
# Parent  eaa6f0249cf88687077dedf3fbcecb083e358ef1
handle unplugged devices in audio_alsa_out (return -1) and in audio_out close 
the driver on a return value <0

diff -r 956dd4cfadac32e0ee510c1b4d460ad9a23ea16e -r 
eaa6f0249cf88687077dedf3fbcecb083e358ef1 src/audio_out/audio_alsa_out.c
--- a/src/audio_out/audio_alsa_out.c    Mon Jun 04 23:30:16 2007 +0200
+++ b/src/audio_out/audio_alsa_out.c    Sun Jun 03 18:06:50 2007 +0100
@@ -752,6 +752,9 @@ static int ao_alsa_write(ao_driver_t *th
     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 *th
 #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 *th
          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 -r 956dd4cfadac32e0ee510c1b4d460ad9a23ea16e -r 
eaa6f0249cf88687077dedf3fbcecb083e358ef1 src/xine-engine/audio_out.c
--- a/src/xine-engine/audio_out.c       Mon Jun 04 23:30:16 2007 +0200
+++ b/src/xine-engine/audio_out.c       Sun Jun 03 18:06:50 2007 +0100
@@ -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");

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Xine-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-cvslog

Reply via email to