-
-/*****************************************************************************
- * ProbeFormat: probe the audio device for available formats
- *****************************************************************************/
-int ProbeFormat( aout_instance_t * p_aout, const char * psz_device,
- int *pi_snd_pcm_format )
-{
- int i_ret, i;
- struct aout_sys_t * p_sys = p_aout->output.p_sys;
- struct timeval tval;
-
- /* We'll open the audio device in non blocking mode so we can just exit
- * when it is already in use, but for the real stuff we'll still use
- * the blocking mode */
-
- /* Now test linear PCM capabilities */
-
- /* Since it seems snd_pcm_close hasen'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_ret = snd_pcm_open( &p_sys->p_snd_pcm, psz_device,
- SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) ) )
- {
- snd_pcm_hw_params_t * p_hw;
- snd_pcm_hw_params_alloca (&p_hw);
-
- if ( snd_pcm_hw_params_any( p_sys->p_snd_pcm, p_hw ) < 0 )
- {
- msg_Warn( p_aout, "unable to retrieve initial hardware"
- "parameters, disabling linear PCM audio" );
- snd_pcm_close( p_sys->p_snd_pcm );
- var_Destroy( p_aout, "audio-device" );
- return -1;
- }
-
- if ( snd_pcm_hw_params_set_format( p_sys->p_snd_pcm, p_hw,
- *pi_snd_pcm_format ) < 0 )
- {
- if( *pi_snd_pcm_format != SND_PCM_FORMAT_S16 )
- {
- *pi_snd_pcm_format = SND_PCM_FORMAT_S16;
- if ( snd_pcm_hw_params_set_format( p_sys->p_snd_pcm, p_hw,
- *pi_snd_pcm_format ) < 0 )
- {
- msg_Warn( p_aout, "unable to set stream sample size"
- "and word order, disabling linear PCM audio" );
- snd_pcm_close( p_sys->p_snd_pcm );
- var_Destroy( p_aout, "audio-device" );
- return -1;
- }
- }
- }
- snd_pcm_close( p_sys->p_snd_pcm );
- return 0;
- }
- else if ( i_ret == -EBUSY && i == 0 )
- {
- msg_Err( p_aout, "audio device: %s is already in use", psz_device );
- }
- else if ( i_ret == -EBUSY )
- {
- msleep( SLEEP_TIME );
- }
- }
- return -1;
-}
-