[vlc-commits] access/alsa.c: simplify error recovery when capturing

Jean-Paul Saman git at videolan.org
Sat Sep 3 10:34:26 CEST 2011


vlc | branch: master | Jean-Paul Saman <jean-paul.saman at m2x.nl> | Fri Sep  2 16:43:34 2011 +0200| [171bdb145813b9fda1770d66ff93a1e83b73e9dc] | committer: Jean-Paul Saman

access/alsa.c: simplify error recovery when capturing

Use highlevel function snd_pcm_recover() the recover from error states.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=171bdb145813b9fda1770d66ff93a1e83b73e9dc
---

 modules/access/alsa.c |   27 ++++++++++-----------------
 1 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/modules/access/alsa.c b/modules/access/alsa.c
index 19dbd01..44777da 100644
--- a/modules/access/alsa.c
+++ b/modules/access/alsa.c
@@ -377,33 +377,26 @@ static block_t* GrabAudio( demux_t *p_demux )
         return NULL;
     }
 
+    if( i_read < 0 )
+        i_read = snd_pcm_recover( p_sys->p_alsa_pcm, i_read, 0 );
+
     if( i_read <= 0 )
     {
         switch( i_read )
         {
-            case -EPIPE:
-                /* xrun */
-                snd_pcm_prepare( p_sys->p_alsa_pcm );
-                break;
-            case -ESTRPIPE:
-            {
-                /* suspend */
-                int i_resume = snd_pcm_resume( p_sys->p_alsa_pcm );
-                if( i_resume < 0 && i_resume != -EAGAIN ) snd_pcm_prepare( p_sys->p_alsa_pcm );
-                break;
-            }
+            case 0: /* state recovered or no data */
+                return NULL;
+            case -EAGAIN:
+                snd_pcm_wait( p_sys->p_alsa_pcm, 10 ); /* See poll() comment in oss.c */
+                return NULL;
             default:
                 msg_Err( p_demux, "Failed to read alsa frame (%s)", snd_strerror( i_read ) );
                 return 0;
         }
     }
-    else
-    {
-        /* convert from frames to bytes */
-        i_read *= p_sys->i_alsa_frame_size;
-    }
 
-    if( i_read <= 0 ) return 0;
+    /* convert from frames to bytes */
+    i_read *= p_sys->i_alsa_frame_size;
 
     p_block->i_buffer = i_read;
     p_sys->p_block = 0;



More information about the vlc-commits mailing list