- int i;
-
- msg_Dbg( p_aout, "opening ALSA device `%s'", psz_device );
-
- /* 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. */
-
- for( i = 10; i >= 0; i-- )
- {
- if ( ( i_snd_rc = snd_pcm_open( &p_sys->p_snd_pcm, psz_device,
- SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ) ) == -EBUSY )
- {
- if( i ) msleep( 100000 /* 100ms */ );
- else
- {
- 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 );
- }
- continue;
- }
- break;
- }
- if( i_snd_rc < 0 )
- {
- msg_Err( p_aout, "cannot open ALSA device `%s' (%s)",
- psz_device, snd_strerror( i_snd_rc ) );
- dialog_Fatal( p_aout, _("Audio output failed"),
- _("VLC could not open the ALSA device \"%s\" (%s)."),
- psz_device, snd_strerror( i_snd_rc ) );
- free( p_sys );
- free( psz_device );
- return VLC_EGENERIC;
- }
-
- /* We want blocking mode */
- snd_pcm_nonblock( p_sys->p_snd_pcm, 0 );
-