* aout_alsa.c : Alsa functions library
*****************************************************************************
* Copyright (C) 2000 VideoLAN
- * $Id: aout_alsa.c,v 1.16 2001/05/30 17:03:11 sam Exp $
+ * $Id: aout_alsa.c,v 1.17 2001/07/11 02:01:03 sam Exp $
*
* Authors: Henri Fallon <henri@videolan.org> - Original Author
* Jeffrey Baker <jwbaker@acm.org> - Port to ALSA 1.0 API
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
{
int i_open_return, i_close_return;
aout_sys_t local_sys;
-
+
/* Open device */
- i_open_return = snd_pcm_open( &(local_sys.p_alsa_handle), "plug:0,0",
+ i_open_return = snd_pcm_open( &(local_sys.p_alsa_handle), "plug:0,0",
SND_PCM_STREAM_PLAYBACK, 0 );
if( i_open_return )
{
- intf_ErrMsg( "Aout_alsa: error opening alsa device in aout_probe(%d)"
- " : %s", i_open_return, snd_strerror( i_open_return ) );
- intf_WarnMsg( 1, "Aout_alsa : module scored 0" );
+ intf_WarnMsg( 2, "aout info: could not probe ALSA device (%s)",
+ snd_strerror( i_open_return ) );
return ( 0 );
}
/* Close it */
i_close_return = snd_pcm_close( local_sys.p_alsa_handle );
-
+
if( i_close_return )
{
- intf_ErrMsg( "Aout_alsa: error closing alsa device in aout_probe(%d)"
- " : %s", i_close_return, snd_strerror( i_close_return ) );
- intf_WarnMsg( 1, "Aout_alsa : module scored 0" );
+ intf_ErrMsg( "aout error: could not close ALSA device (%s)",
+ snd_strerror( i_close_return ) );
return( 0 );
}
-
+
if( TestMethod( AOUT_METHOD_VAR, "alsa" ) )
{
- intf_WarnMsg( 1, "Aout_alsa : module scored 999" );
return( 999 );
}
/* And return score */
return( 100 );
-}
+}
/*****************************************************************************
* aout_Open : creates a handle and opens an alsa device
{
int i_open_returns;
-
+
/* Allocate structures */
p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
if( p_aout->p_sys == NULL )
{
- intf_ErrMsg( "Aout_alsa : Could not allocate memory : %s",
+ intf_ErrMsg( "aout error: failed allocating memory for ALSA (%s)",
strerror(ENOMEM) );
return( 1 );
}
AOUT_RATE_DEFAULT );
/* Open device */
- if( ( i_open_returns = snd_pcm_open(&(p_aout->p_sys->p_alsa_handle),
- "plug:0,0",
+ if( ( i_open_returns = snd_pcm_open(&(p_aout->p_sys->p_alsa_handle),
+ "plug:0,0",
SND_PCM_STREAM_PLAYBACK, 0) ) )
{
- intf_ErrMsg( "Could not open alsa device; exit = %i",
- i_open_returns );
- intf_ErrMsg( "This means : %s", snd_strerror(i_open_returns) );
+ intf_ErrMsg( "aout error: could not open ALSA device (%s)",
+ snd_strerror(i_open_returns) );
return( -1 );
}
- intf_DbgMsg( "Aout_alsa : Alsa device successfully opened" );
+ intf_DbgMsg( "aout info: ALSA device successfully opened" );
return( 0 );
}
*****************************************************************************/
static int aout_SetFormat( aout_thread_t *p_aout )
{
-
+
int i_rv;
int i_format;
-
+
snd_pcm_hw_params_t *p_hw;
snd_pcm_sw_params_t *p_sw;
-
+
snd_pcm_hw_params_alloca(&p_hw);
snd_pcm_sw_params_alloca(&p_sw);
- switch (p_aout->i_format) {
+ switch (p_aout->i_format)
+ {
case AOUT_FMT_S16_LE:
i_format = SND_PCM_FORMAT_S16_LE;
p_aout->p_sys->bytes_per_sample = 2;
break;
-
+
default:
i_format = SND_PCM_FORMAT_S16_BE;
p_aout->p_sys->bytes_per_sample = 2;
}
p_aout->p_sys->samples_per_frame = p_aout->i_channels;
- p_aout->p_sys->bytes_per_frame = p_aout->p_sys->samples_per_frame *
+ p_aout->p_sys->bytes_per_frame = p_aout->p_sys->samples_per_frame *
p_aout->p_sys->bytes_per_sample;
i_rv = snd_pcm_hw_params_any( p_aout->p_sys->p_alsa_handle, p_hw );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to retrieve initial parameters." );
+ intf_ErrMsg( "aout error: unable to retrieve initial parameters" );
return( -1 );
}
-
- i_rv = snd_pcm_hw_params_set_access( p_aout->p_sys->p_alsa_handle, p_hw,
+
+ i_rv = snd_pcm_hw_params_set_access( p_aout->p_sys->p_alsa_handle, p_hw,
SND_PCM_ACCESS_RW_INTERLEAVED );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set interleaved stream format." );
+ intf_ErrMsg( "aout error: unable to set interleaved stream format" );
return( -1 );
}
-
- i_rv = snd_pcm_hw_params_set_format( p_aout->p_sys->p_alsa_handle,
+
+ i_rv = snd_pcm_hw_params_set_format( p_aout->p_sys->p_alsa_handle,
p_hw, i_format );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set stream sample size and word"
- " order." );
+ intf_ErrMsg( "aout error: unable to set stream sample size and word"
+ " order" );
return( -1 );
}
- i_rv = snd_pcm_hw_params_set_channels( p_aout->p_sys->p_alsa_handle, p_hw,
+ i_rv = snd_pcm_hw_params_set_channels( p_aout->p_sys->p_alsa_handle, p_hw,
p_aout->i_channels );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set number of output channels." );
+ intf_ErrMsg( "aout error: unable to set number of output channels" );
return( -1 );
}
-
- i_rv = snd_pcm_hw_params_set_rate_near( p_aout->p_sys->p_alsa_handle, p_hw,
+
+ i_rv = snd_pcm_hw_params_set_rate_near( p_aout->p_sys->p_alsa_handle, p_hw,
p_aout->l_rate, 0 );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set sample rate." );
+ intf_ErrMsg( "aout error: unable to set sample rate" );
return( -1 );
}
- else
- p_aout->p_sys->rate = i_rv;
-
+ p_aout->p_sys->rate = i_rv;
+
i_rv = snd_pcm_hw_params_set_buffer_time_near( p_aout->p_sys->p_alsa_handle,
- p_hw, AOUT_BUFFER_DURATION,
+ p_hw, AOUT_BUFFER_DURATION,
0 );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set buffer time." );
+ intf_ErrMsg( "aout error: unable to set buffer time" );
return( -1 );
}
- else
- p_aout->p_sys->buffer_time = i_rv;
-
+ p_aout->p_sys->buffer_time = i_rv;
+
i_rv = snd_pcm_hw_params_set_period_time_near( p_aout->p_sys->p_alsa_handle,
p_hw, p_aout->p_sys->buffer_time / p_aout->p_sys->bytes_per_frame, 0 );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set period time." );
+ intf_ErrMsg( "aout error: unable to set period time" );
return( -1 );
}
- else
- p_aout->p_sys->period_time = i_rv;
-
+ p_aout->p_sys->period_time = i_rv;
+
i_rv = snd_pcm_hw_params(p_aout->p_sys->p_alsa_handle, p_hw);
if (i_rv < 0)
{
- intf_ErrMsg( "Aout_alsa: Unable to set hardware configuration." );
+ intf_ErrMsg( "aout error: unable to set hardware configuration" );
return( -1 );
}
-
+
p_aout->p_sys->chunk_size = snd_pcm_hw_params_get_period_size( p_hw, 0 );
- p_aout->p_sys->buffer_size = snd_pcm_hw_params_get_buffer_size( p_hw );
+ p_aout->p_sys->buffer_size = snd_pcm_hw_params_get_buffer_size( p_hw );
- snd_pcm_sw_params_current( p_aout->p_sys->p_alsa_handle, p_sw );
- i_rv = snd_pcm_sw_params_set_sleep_min( p_aout->p_sys->p_alsa_handle, p_sw,
+ snd_pcm_sw_params_current( p_aout->p_sys->p_alsa_handle, p_sw );
+ i_rv = snd_pcm_sw_params_set_sleep_min( p_aout->p_sys->p_alsa_handle, p_sw,
0 );
- i_rv = snd_pcm_sw_params_set_avail_min( p_aout->p_sys->p_alsa_handle, p_sw,
+ i_rv = snd_pcm_sw_params_set_avail_min( p_aout->p_sys->p_alsa_handle, p_sw,
p_aout->p_sys->chunk_size );
/* Worked with the CVS version but not with 0.9beta3
- i_rv = snd_pcm_sw_params_set_start_threshold( p_aout->p_sys->p_alsa_handle,
+ i_rv = snd_pcm_sw_params_set_start_threshold( p_aout->p_sys->p_alsa_handle,
p_sw, p_aout->p_sys->buffer_size );
-
- i_rv = snd_pcm_sw_params_set_stop_threshold( p_aout->p_sys->p_alsa_handle,
+
+ i_rv = snd_pcm_sw_params_set_stop_threshold( p_aout->p_sys->p_alsa_handle,
p_sw, p_aout->p_sys->buffer_size);
*/
- i_rv = snd_pcm_sw_params( p_aout->p_sys->p_alsa_handle, p_sw );
+ i_rv = snd_pcm_sw_params( p_aout->p_sys->p_alsa_handle, p_sw );
if( i_rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: Unable to set software configuration." );
+ intf_ErrMsg( "aout error: unable to set software configuration" );
return( -1 );
- }
-
+ }
return( 0 );
}
/*****************************************************************************
- * static void aout_HandleXrun : reprepare the output
+ * aout_HandleXrun : reprepare the output
*****************************************************************************
* When buffer gets empty, the driver goes in "Xrun" state, where it needs
* to be reprepared before playing again
{
int i_rv;
- intf_ErrMsg( "Aout_alsa: resetting output after buffer underrun." );
-
+ intf_ErrMsg( "aout error: resetting output after buffer underrun" );
+
i_rv = snd_pcm_reset( p_aout->p_sys->p_alsa_handle );
i_rv = snd_pcm_prepare( p_aout->p_sys->p_alsa_handle );
if( i_rv < 0 )
- intf_ErrMsg( "Aout_alsa: Unable to recover from buffer underrun: %s",
+ {
+ intf_ErrMsg( "aout error: unable to recover from buffer underrun (%s)",
snd_strerror( i_rv ) );
+ }
}
{
snd_pcm_status_t *p_status;
int i_alsa_get_status_returns;
-
+
snd_pcm_status_alloca( &p_status );
- i_alsa_get_status_returns = snd_pcm_status( p_aout->p_sys->p_alsa_handle,
+ i_alsa_get_status_returns = snd_pcm_status( p_aout->p_sys->p_alsa_handle,
p_status );
if( i_alsa_get_status_returns )
{
- intf_ErrMsg ( "Aout_alsa: Error getting alsa buffer info (%d) : %s",
- i_alsa_get_status_returns,
+ intf_ErrMsg ( "aout error: failed getting alsa buffer info (%s)",
snd_strerror ( i_alsa_get_status_returns ) );
return ( -1 );
}
case SND_PCM_STATE_PREPARED:
case SND_PCM_STATE_RUNNING:
break;
-
+
default:
- intf_ErrMsg( "Aout_alsa: Encountered unhandled condition %i!",
+ intf_ErrMsg( "aout error: unhandled condition %i",
snd_pcm_status_get_state( p_status ) );
break;
- }
+ }
- return( snd_pcm_status_get_avail(p_status) *
+ return( snd_pcm_status_get_avail(p_status) *
p_aout->p_sys->bytes_per_frame );
}
snd_pcm_uframes_t tot_frames;
snd_pcm_uframes_t frames_left;
snd_pcm_uframes_t rv;
-
+
tot_frames = i_size / p_aout->p_sys->bytes_per_frame;
frames_left = tot_frames;
while( frames_left > 0 )
- {
- rv = snd_pcm_writei( p_aout->p_sys->p_alsa_handle, buffer +
- (tot_frames - frames_left) *
+ {
+ rv = snd_pcm_writei( p_aout->p_sys->p_alsa_handle, buffer +
+ (tot_frames - frames_left) *
p_aout->p_sys->bytes_per_frame, frames_left );
if( (signed int) rv < 0 )
{
- intf_ErrMsg( "Aout_alsa: error writing to output: %s",
+ intf_ErrMsg( "aout error: failed writing to output (%s)",
snd_strerror( rv ) );
return;
}
if( i_close_returns )
{
- intf_ErrMsg( "Aout_alsa: error closing alsa device (%d): %s",
+ intf_ErrMsg( "aout error: failed closing ALSA device (%s)",
i_close_returns, snd_strerror( i_close_returns ) );
}
free( p_aout->p_sys );
-
- intf_DbgMsg( "Aout_alsa : Alsa device closed" );
+
+ intf_DbgMsg( "aout: ALSA device closed" );
}
/*****************************************************************************
p_function_list->functions.aout.pf_play = aout_Play;
p_function_list->functions.aout.pf_close = aout_Close;
}
+