[vlc-commits] ALSA: remove hack. Do not fail 10 times to open the same device.

Rémi Denis-Courmont git at videolan.org
Wed Apr 13 19:36:04 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 13 18:38:14 2011 +0300| [b00308ebf20530988c46f5e1471d4121160b54fa] | committer: Rémi Denis-Courmont

ALSA: remove hack. Do not fail 10 times to open the same device.

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

 modules/audio_output/alsa.c |   46 ++++++++++--------------------------------
 1 files changed, 11 insertions(+), 35 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index a67d971..0d5dd78 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -435,41 +435,18 @@ static int Open( vlc_object_t *p_this )
 
     /* Open the device */
     msg_Dbg( p_aout, "opening ALSA device `%s'", psz_device );
-    for( unsigned i = 10; i; i-- )
+    int val = snd_pcm_open (&p_sys->p_snd_pcm, psz_device,
+                            SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+    if (val != 0)
     {
-        int val = snd_pcm_open( &p_sys->p_snd_pcm, psz_device,
-                                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
-        if( val == 0 )
-            break; /* success! */
-
-        if( val != -EBUSY )
-        {
-            msg_Err( p_aout, "cannot open ALSA device `%s' (%s)",
-                     psz_device, snd_strerror( val ) );
-            dialog_Fatal( p_aout, _("Audio output failed"),
-                          _("VLC could not open the ALSA device \"%s\" (%s)."),
-                          psz_device, snd_strerror( val ) );
-            free( psz_device );
-            free( p_sys );
-            return VLC_EGENERIC;
-        }
-
-        /* Since it seems snd_pcm_close hasn't really released the device at
-          the time it returns, probe if the device is available in loop for 1s.
-          We cannot use blocking mode since the we would wait indefinitely when
-          switching from a dmx device to surround51. */
-        if( i == 1 )
-        {
-            msg_Err( p_aout, "audio device %s is already in use",
-                     psz_device );
-            dialog_Fatal( p_aout, _("Audio output failed"),
-                          _("The audio device \"%s\" is already in use."),
-                          psz_device );
-            free( psz_device );
-            free( p_sys );
-            return VLC_EGENERIC;
-        }
-        msleep( CLOCK_FREQ / 10 );
+        msg_Err (p_aout, "cannot open ALSA device `%s' (%s)",
+                 psz_device, snd_strerror (val));
+        dialog_Fatal (p_aout, _("Audio output failed"),
+                      _("The audio device \"%s\" could not be used:\n%s."),
+                      psz_device, snd_strerror (val));
+        free (psz_device);
+        free (p_sys);
+        return VLC_EGENERIC;
     }
     free( psz_device );
 
@@ -512,7 +489,6 @@ static int Open( vlc_object_t *p_this )
 
     /* Due to some bugs in alsa with some drivers, we need to retry in s16l
        if snd_pcm_hw_params fails in fl32 */
-    int val;
 retry:
     /* Get Initial hardware parameters */
     val = snd_pcm_hw_params_any( p_sys->p_snd_pcm, p_hw );



More information about the vlc-commits mailing list