Commit 4af9ab12 authored by Henri Fallon's avatar Henri Fallon

Done :
- ported the alsa plugin to the news vlc module API
- cosmetic changes

To do :
- check if it works with the latest alsa release
- add features ... prepare for 4 or more speakers
parent a85534e5
...@@ -506,7 +506,7 @@ lib/dsp.so: $(PLUGIN_DSP) ...@@ -506,7 +506,7 @@ lib/dsp.so: $(PLUGIN_DSP)
$(CC) $(PCFLAGS) -shared -o $@ $^ $(CC) $(PCFLAGS) -shared -o $@ $^
lib/alsa.so: $(PLUGIN_ALSA) lib/alsa.so: $(PLUGIN_ALSA)
$(CC) $(PCFLAGS) -shared -o $@ $^ $(CC) $(PCFLAGS) -shared -o $@ $^ -lasound
lib/null.so: $(PLUGIN_NULL) lib/null.so: $(PLUGIN_NULL)
$(CC) $(PCFLAGS) -shared -o $@ $^ $(CC) $(PCFLAGS) -shared -o $@ $^
......
/***************************************************************************** /*****************************************************************************
* dsp.c : OSS /dev/dsp plugin for vlc * alsa.c : alsa plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000 VideoLAN * Copyright (C) 2000 VideoLAN
* *
...@@ -21,81 +21,99 @@ ...@@ -21,81 +21,99 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#define MODULE_NAME alsa
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h" #include "defs.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/asoundlib.h> /* for alsa :) */ #include <sys/asoundlib.h> /* for alsa :) */
#include <linux/asound.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> /* malloc(), free() */ #include <stdlib.h> /* malloc(), free() */
// #include <unistd.h> /* close() */
#include "config.h" #include "config.h"
#include "common.h" /* boolean_t, byte_t */ #include "common.h" /* boolean_t, byte_t */
#include "threads.h" #include "threads.h"
#include "mtime.h" #include "mtime.h"
#include "tests.h" #include "tests.h"
#include "plugins.h"
#include "interface.h" #include "interface.h"
#include "audio_output.h"
#include "video.h"
#include "video_output.h"
#include "main.h" #include "main.h"
#include "modules.h"
#include "modules_inner.h"
/***************************************************************************** /*****************************************************************************
* Exported prototypes * Build configuration tree.
*****************************************************************************/ *****************************************************************************/
static void aout_GetPlugin( p_aout_thread_t p_aout ); MODULE_CONFIG_START
ADD_COMMENT( "Yeah, alsa rocks !" )
MODULE_CONFIG_END
/* Audio output */ /*****************************************************************************
int aout_AlsaOpen ( aout_thread_t *p_aout ); * Capabilities defined in the other files.
int aout_AlsaSetFormat ( aout_thread_t *p_aout ); *****************************************************************************/
long aout_AlsaGetBufInfo ( aout_thread_t *p_aout, long l_buffer_info ); extern void aout_getfunctions( function_list_t * p_function_list );
void aout_AlsaPlay ( aout_thread_t *p_aout, byte_t *buffer,
int i_size );
void aout_AlsaClose ( aout_thread_t *p_aout );
/***************************************************************************** /*****************************************************************************
* GetConfig: get the plugin structure and configuration * InitModule: get the module structure and configuration.
*****************************************************************************
* We have to fill psz_name, psz_longname and psz_version. These variables
* will be strdup()ed later by the main application because the module can
* be unloaded later to save memory, and we want to be able to access this
* data even after the module has been unloaded.
*****************************************************************************/ *****************************************************************************/
plugin_info_t * GetConfig( void ) int InitModule( module_t * p_module )
{ {
plugin_info_t * p_info = (plugin_info_t *) malloc( sizeof(plugin_info_t) ); p_module->psz_name = MODULE_STRING;
p_module->psz_longname = "Alsa audio module";
p_info->psz_name = "Alsa plugin"; p_module->psz_version = VERSION;
p_info->psz_version = VERSION; p_module->i_capabilities = MODULE_CAPABILITY_NULL
p_info->psz_author = "the VideoLAN team <vlc@videolan.org>"; | MODULE_CAPABILITY_AOUT;
return( 0 );
p_info->aout_GetPlugin = aout_GetPlugin; }
p_info->vout_GetPlugin = NULL;
p_info->intf_GetPlugin = NULL;
p_info->yuv_GetPlugin = NULL;
/* TODO : test if alsa is available */
p_info->i_score = 0x100;
/* If this plugin was requested, score it higher */ /*****************************************************************************
if( TestMethod( AOUT_METHOD_VAR, "alsa" ) ) * ActivateModule: set the module to an usable state.
*****************************************************************************
* This function fills the capability functions and the configuration
* structure. Once ActivateModule() has been called, the i_usage can
* be set to 0 and calls to NeedModule() be made to increment it. To unload
* the module, one has to wait until i_usage == 0 and call DeactivateModule().
*****************************************************************************/
int ActivateModule( module_t * p_module )
{
p_module->p_functions = malloc( sizeof( module_functions_t ) );
if( p_module->p_functions == NULL )
{ {
p_info->i_score += 0x200; return( -1 );
} }
return( p_info ); aout_getfunctions( &p_module->p_functions->aout );
p_module->p_config = p_config;
return( 0 );
} }
/***************************************************************************** /*****************************************************************************
* Following functions are only called through the p_info structure * DeactivateModule: make sure the module can be unloaded.
*****************************************************************************
* This function must only be called when i_usage == 0. If it successfully
* returns, i_usage can be set to -1 and the module unloaded. Be careful to
* lock usage_lock during the whole process.
*****************************************************************************/ *****************************************************************************/
int DeactivateModule( module_t * p_module )
static void aout_GetPlugin( p_aout_thread_t p_aout )
{ {
p_aout->p_open = aout_AlsaOpen; free( p_module->p_functions );
p_aout->p_setformat = aout_AlsaSetFormat;
p_aout->p_getbufinfo = aout_AlsaGetBufInfo; return( 0 );
p_aout->p_play = aout_AlsaPlay;
p_aout->p_close = aout_AlsaClose;
} }
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#define MODULE_NAME alsa
/***************************************************************************** /*****************************************************************************
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
...@@ -39,13 +41,14 @@ ...@@ -39,13 +41,14 @@
#include "common.h" /* boolean_t, byte_t */ #include "common.h" /* boolean_t, byte_t */
#include "threads.h" #include "threads.h"
#include "mtime.h" #include "mtime.h"
#include "plugins.h"
#include "audio_output.h" /* aout_thread_t */ #include "audio_output.h" /* aout_thread_t */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */ #include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
#include "main.h" #include "main.h"
#include "modules.h"
#include "modules_inner.h"
...@@ -70,13 +73,83 @@ typedef struct aout_sys_s ...@@ -70,13 +73,83 @@ typedef struct aout_sys_s
snd_pcm_format_t s_alsa_format; snd_pcm_format_t s_alsa_format;
} aout_sys_t; } aout_sys_t;
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int aout_Probe ( probedata_t *p_data );
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
/***************************************************************************** /*****************************************************************************
* aout_AlsaOpen : creates a handle and opens an alsa device * Functions exported as capabilities. They are declared as static so that
* we don't pollute the namespace too much.
*****************************************************************************/ *****************************************************************************/
void aout_getfunctions( function_list_t * p_function_list )
{
p_function_list->p_probe = aout_Probe;
p_function_list->functions.aout.p_open = aout_Open;
p_function_list->functions.aout.p_setformat = aout_SetFormat;
p_function_list->functions.aout.p_getbufinfo = aout_GetBufInfo;
p_function_list->functions.aout.p_play = aout_Play;
p_function_list->functions.aout.p_close = aout_Close;
}
int aout_AlsaOpen( aout_thread_t *p_aout )
/*****************************************************************************
* aout_Probe: probes the audio device and return a score
*****************************************************************************
* This function tries to open the dps and returns a score to the plugin
* manager so that it can make its choice.
*****************************************************************************/
static int aout_Probe( probedata_t *p_data )
{
int i_open_return,i_close_return;
aout_sys_t local_sys;
/* This is the same as the beginning of the aout_Open */
/* Initialize */
local_sys.s_alsa_device.i_num = 0;
local_sys.s_alsa_card.i_num = 0;
/* Open device */
i_open_return = snd_pcm_open( &(local_sys.p_alsa_handle),
local_sys.s_alsa_card.i_num,
local_sys.s_alsa_device.i_num,
SND_PCM_OPEN_PLAYBACK );
if( i_open_return )
{
/* Score is zero */
return ( 0 );
}
/* Otherwise, we may think it'll work */
/* Close */
i_close_return = snd_pcm_close ( local_sys.p_alsa_handle );
if( i_close_return )
{
intf_ErrMsg( "Error closing alsa device in aout_probe; exit=%i",
i_close_return );
intf_ErrMsg( "This means : %s",snd_strerror( i_close_return ) );
}
/* And return score */
return( 100 );
}
/*****************************************************************************
* aout_Open : creates a handle and opens an alsa device
*****************************************************************************
* This function opens an alsa device, through the alsa API
*****************************************************************************/
static int aout_Open( aout_thread_t *p_aout )
{ {
int i_open_returns; int i_open_returns;
...@@ -100,27 +173,30 @@ int aout_AlsaOpen( aout_thread_t *p_aout ) ...@@ -100,27 +173,30 @@ int aout_AlsaOpen( aout_thread_t *p_aout )
p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT ); p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
/* Open device */ /* Open device */
if ( ( i_open_returns = snd_pcm_open( &(p_aout->p_sys->p_alsa_handle), if( ( i_open_returns = snd_pcm_open( &(p_aout->p_sys->p_alsa_handle),
p_aout->p_sys->s_alsa_card.i_num, p_aout->p_sys->s_alsa_card.i_num,
p_aout->p_sys->s_alsa_device.i_num, p_aout->p_sys->s_alsa_device.i_num,
SND_PCM_OPEN_PLAYBACK ) ) ) SND_PCM_OPEN_PLAYBACK ) ) )
{ {
intf_ErrMsg ( "Could not open alsa device; exit = %i", intf_ErrMsg( "Could not open alsa device; exit = %i",
i_open_returns ); i_open_returns );
intf_ErrMsg ( "This means : %s", snd_strerror(i_open_returns) ); intf_ErrMsg( "This means : %s", snd_strerror(i_open_returns) );
return ( 1 ); return( -1 );
} }
intf_DbgMsg("Alsa plugin : Alsa device successfully opened"); intf_DbgMsg( "Alsa plugin : Alsa device successfully opened" );
return ( 0 ); return( 0 );
} }
/***************************************************************************** /*****************************************************************************
* aout_AlsaSetFormat : sets the alsa output format * aout_SetFormat : sets the alsa output format
*****************************************************************************
* This function prepares the device, sets the rate, format, the mode
* ("play as soon as you have data"), and buffer information.
*****************************************************************************/ *****************************************************************************/
int aout_AlsaSetFormat ( aout_thread_t *p_aout ) int aout_SetFormat( aout_thread_t *p_aout )
{ {
int i_set_param_returns; int i_set_param_returns;
...@@ -128,8 +204,8 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout ) ...@@ -128,8 +204,8 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
int i_playback_go_returns; int i_playback_go_returns;
/* Fill with zeros */ /* Fill with zeros */
memset(&p_aout->p_sys->s_alsa_channel_params,0, memset( &p_aout->p_sys->s_alsa_channel_params,0,
sizeof(p_aout->p_sys->s_alsa_channel_params)); sizeof( p_aout->p_sys->s_alsa_channel_params ) );
/* Fill the s_alsa_channel_params structure */ /* Fill the s_alsa_channel_params structure */
...@@ -139,7 +215,7 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout ) ...@@ -139,7 +215,7 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
/* Format and rate */ /* Format and rate */
p_aout->p_sys->s_alsa_channel_params.format.interleave = 1; p_aout->p_sys->s_alsa_channel_params.format.interleave = 1;
if ( p_aout->i_format == AOUT_FMT_S16_LE ) if( p_aout->i_format == AOUT_FMT_S16_LE )
p_aout->p_sys->s_alsa_channel_params.format.format = p_aout->p_sys->s_alsa_channel_params.format.format =
SND_PCM_SFMT_S16_LE; SND_PCM_SFMT_S16_LE;
else else
...@@ -163,67 +239,72 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout ) ...@@ -163,67 +239,72 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
p_aout->p_sys->s_alsa_channel_params.buf.stream.max_fill = 0 ; p_aout->p_sys->s_alsa_channel_params.buf.stream.max_fill = 0 ;
/* Now we pass this to the driver */ /* Now we pass this to the driver */
i_set_param_returns = snd_pcm_channel_params ( i_set_param_returns = snd_pcm_channel_params(
p_aout->p_sys->p_alsa_handle, p_aout->p_sys->p_alsa_handle,
&(p_aout->p_sys->s_alsa_channel_params) ); &(p_aout->p_sys->s_alsa_channel_params) );
if ( i_set_param_returns ) if( i_set_param_returns )
{ {
intf_ErrMsg ( "ALSA_PLUGIN : Unable to set parameters; exit = %i", intf_ErrMsg( "ALSA_PLUGIN : Unable to set parameters; exit = %i",
i_set_param_returns ); i_set_param_returns );
intf_ErrMsg( "This means : %s", intf_ErrMsg( "This means : %s",
snd_strerror( i_set_param_returns ) ); snd_strerror( i_set_param_returns ) );
return ( 1 ); return( -1 );
} }
/* we shall now prepare the channel */ /* we shall now prepare the channel */
i_prepare_playback_returns = i_prepare_playback_returns =
snd_pcm_playback_prepare ( p_aout->p_sys->p_alsa_handle ); snd_pcm_playback_prepare( p_aout->p_sys->p_alsa_handle );
if ( i_prepare_playback_returns ) if( i_prepare_playback_returns )
{ {
intf_ErrMsg ( "ALSA_PLUGIN : Unable to prepare channel : exit = %i", intf_ErrMsg( "ALSA_PLUGIN : Unable to prepare channel : exit = %i",
i_prepare_playback_returns ); i_prepare_playback_returns );
intf_ErrMsg( "This means : %s", intf_ErrMsg( "This means : %s",
snd_strerror( i_set_param_returns ) ); snd_strerror( i_set_param_returns ) );
return ( 1 ); return( -1 );
} }
/* then we may go */ /* then we may go */
i_playback_go_returns = i_playback_go_returns =
snd_pcm_playback_go ( p_aout->p_sys->p_alsa_handle ); snd_pcm_playback_go( p_aout->p_sys->p_alsa_handle );
if ( i_playback_go_returns ) if( i_playback_go_returns )
{ {
intf_ErrMsg ( "ALSA_PLUGIN : Unable to prepare channel (bis) : intf_ErrMsg( "ALSA_PLUGIN : Unable to prepare channel (bis) :
exit = %i", i_playback_go_returns ); exit = %i", i_playback_go_returns );
intf_ErrMsg( "This means : %s", intf_ErrMsg( "This means : %s",
snd_strerror( i_set_param_returns ) ); snd_strerror( i_set_param_returns ) );
return ( 1 ); return( -1 );
} }
return ( 0 ); return( 0 );
} }
/***************************************************************************** /*****************************************************************************
* aout_AlsaGetBufInfo: buffer status query * aout_BufInfo: buffer status query
*****************************************************************************
* This function returns the number of used byte in the queue.
* It also deals with errors : indeed if the device comes to run out
* of data to play, it switches to the "underrun" status. It has to
* be flushed and re-prepared
*****************************************************************************/ *****************************************************************************/
long aout_AlsaGetBufInfo ( aout_thread_t *p_aout, long l_buffer_limit ) long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
{ {
snd_pcm_channel_status_t alsa_channel_status; snd_pcm_channel_status_t alsa_channel_status;
int i_alsa_get_status_returns; int i_alsa_get_status_returns;
memset (&alsa_channel_status, 0, sizeof(alsa_channel_status)); memset(&alsa_channel_status, 0, sizeof( alsa_channel_status ) );
i_alsa_get_status_returns = snd_pcm_channel_status ( i_alsa_get_status_returns = snd_pcm_channel_status(
p_aout->p_sys->p_alsa_handle, &alsa_channel_status ); p_aout->p_sys->p_alsa_handle, &alsa_channel_status );
if ( i_alsa_get_status_returns ) if( i_alsa_get_status_returns )
{ {
intf_ErrMsg ( "Error getting alsa buffer info; exit=%i", intf_ErrMsg ( "Error getting alsa buffer info; exit=%i",
i_alsa_get_status_returns ); i_alsa_get_status_returns );
intf_ErrMsg ( "This means : %s", intf_ErrMsg ( "This means : %s",
snd_strerror ( i_alsa_get_status_returns ) ); snd_strerror ( i_alsa_get_status_returns ) );
return ( 1 ); return ( -1 );
} }
switch( alsa_channel_status.status ) switch( alsa_channel_status.status )
...@@ -231,38 +312,35 @@ long aout_AlsaGetBufInfo ( aout_thread_t *p_aout, long l_buffer_limit ) ...@@ -231,38 +312,35 @@ long aout_AlsaGetBufInfo ( aout_thread_t *p_aout, long l_buffer_limit )
case SND_PCM_STATUS_NOTREADY : intf_ErrMsg("Status NOT READY"); case SND_PCM_STATUS_NOTREADY : intf_ErrMsg("Status NOT READY");
break; break;
case SND_PCM_STATUS_UNDERRUN : { case SND_PCM_STATUS_UNDERRUN : {
int i_prepare_returns; int i_prepare_returns;
intf_ErrMsg( intf_ErrMsg( "Status UNDERRUN ... reseting queue ");
"Status UNDERRUN ... reseting queue"); i_prepare_returns = snd_pcm_playback_prepare(
i_prepare_returns =
snd_pcm_playback_prepare(
p_aout->p_sys->p_alsa_handle ); p_aout->p_sys->p_alsa_handle );
if ( i_prepare_returns ) if ( i_prepare_returns )
{ {
intf_ErrMsg( intf_ErrMsg( "Error : could not flush : %i", i_prepare_returns );
"Error : could not flush : %i", intf_ErrMsg( "This means : %s", snd_strerror(i_prepare_returns) );
i_prepare_returns);
intf_ErrMsg(
"This means : %s",
snd_strerror(i_prepare_returns));
} }
break; break;
} }
} }
return ( alsa_channel_status.count ); return( alsa_channel_status.count );
} }
/***************************************************************************** /*****************************************************************************
* aout_AlsaPlay * aout_Play : plays a sample
*****************************************************************************
* Plays a sample using the snd_pcm_write function from the alsa API
*****************************************************************************/ *****************************************************************************/
void aout_AlsaPlay ( aout_thread_t *p_aout, byte_t *buffer, int i_size ) void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
{ {
int i_write_returns; int i_write_returns;
i_write_returns = (int) snd_pcm_write ( i_write_returns = (int) snd_pcm_write (
p_aout->p_sys->p_alsa_handle, (void *)buffer, (size_t) i_size ); p_aout->p_sys->p_alsa_handle, (void *) buffer, (size_t) i_size );
if ( i_write_returns <= 0 ) if( i_write_returns <= 0 )
{ {
intf_ErrMsg ( "Error writing blocks; exit=%i", i_write_returns ); intf_ErrMsg ( "Error writing blocks; exit=%i", i_write_returns );
intf_ErrMsg ( "This means : %s", snd_strerror( i_write_returns ) ); intf_ErrMsg ( "This means : %s", snd_strerror( i_write_returns ) );
...@@ -270,20 +348,20 @@ void aout_AlsaPlay ( aout_thread_t *p_aout, byte_t *buffer, int i_size ) ...@@ -270,20 +348,20 @@ void aout_AlsaPlay ( aout_thread_t *p_aout, byte_t *buffer, int i_size )
} }
/***************************************************************************** /*****************************************************************************
* aout_AlsaClose : close the Alsa device * aout_Close : close the Alsa device
*****************************************************************************/ *****************************************************************************/
void aout_AlsaClose ( aout_thread_t *p_aout ) void aout_Close( aout_thread_t *p_aout )
{ {
int i_close_returns; int i_close_returns;
i_close_returns = snd_pcm_close ( p_aout->p_sys->p_alsa_handle ); i_close_returns = snd_pcm_close( p_aout->p_sys->p_alsa_handle );
if ( i_close_returns ) if( i_close_returns )
{ {
intf_ErrMsg( "Error closing alsa device; exit=%i",i_close_returns ); intf_ErrMsg( "Error closing alsa device; exit=%i",i_close_returns );
intf_ErrMsg( "This means : %s",snd_strerror( i_close_returns ) ); intf_ErrMsg( "This means : %s",snd_strerror( i_close_returns ) );
} }
free(p_aout->p_sys); free( p_aout->p_sys );
intf_DbgMsg( "Alsa plugin : Alsa device closed"); intf_DbgMsg( "Alsa plugin : Alsa device closed");
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment