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)
$(CC) $(PCFLAGS) -shared -o $@ $^
lib/alsa.so: $(PLUGIN_ALSA)
$(CC) $(PCFLAGS) -shared -o $@ $^
$(CC) $(PCFLAGS) -shared -o $@ $^ -lasound
lib/null.so: $(PLUGIN_NULL)
$(CC) $(PCFLAGS) -shared -o $@ $^
......
/*****************************************************************************
* dsp.c : OSS /dev/dsp plugin for vlc
* alsa.c : alsa plugin for vlc
*****************************************************************************
* Copyright (C) 2000 VideoLAN
*
......@@ -21,81 +21,99 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define MODULE_NAME alsa
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/asoundlib.h> /* for alsa :) */
#include <linux/asound.h>
#include <fcntl.h>
#include <stdlib.h> /* malloc(), free() */
// #include <unistd.h> /* close() */
#include "config.h"
#include "common.h" /* boolean_t, byte_t */
#include "threads.h"
#include "mtime.h"
#include "tests.h"
#include "plugins.h"
#include "interface.h"
#include "audio_output.h"
#include "video.h"
#include "video_output.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 );
int aout_AlsaSetFormat ( aout_thread_t *p_aout );
long aout_AlsaGetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
void aout_AlsaPlay ( aout_thread_t *p_aout, byte_t *buffer,
int i_size );
void aout_AlsaClose ( aout_thread_t *p_aout );
/*****************************************************************************
* Capabilities defined in the other files.
*****************************************************************************/
extern void aout_getfunctions( function_list_t * p_function_list );
/*****************************************************************************
* 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_info->psz_name = "Alsa plugin";
p_info->psz_version = VERSION;
p_info->psz_author = "the VideoLAN team <vlc@videolan.org>";
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;
p_module->psz_name = MODULE_STRING;
p_module->psz_longname = "Alsa audio module";
p_module->psz_version = VERSION;
p_module->i_capabilities = MODULE_CAPABILITY_NULL
| MODULE_CAPABILITY_AOUT;
return( 0 );
}
/* 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.
*****************************************************************************/
static void aout_GetPlugin( p_aout_thread_t p_aout )
int DeactivateModule( module_t * p_module )
{
p_aout->p_open = aout_AlsaOpen;
p_aout->p_setformat = aout_AlsaSetFormat;
p_aout->p_getbufinfo = aout_AlsaGetBufInfo;
p_aout->p_play = aout_AlsaPlay;
p_aout->p_close = aout_AlsaClose;
free( p_module->p_functions );
return( 0 );
}
......@@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define MODULE_NAME alsa
/*****************************************************************************
* Preamble
*****************************************************************************/
......@@ -39,13 +41,14 @@
#include "common.h" /* boolean_t, byte_t */
#include "threads.h"
#include "mtime.h"
#include "plugins.h"
#include "audio_output.h" /* aout_thread_t */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
#include "main.h"
#include "modules.h"
#include "modules_inner.h"
......@@ -70,13 +73,83 @@ typedef struct aout_sys_s
snd_pcm_format_t s_alsa_format;
} 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 );
/*****************************************************************************
* 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;
}
/*****************************************************************************
* 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_AlsaOpen : creates a handle and opens an alsa device
* aout_Open : creates a handle and opens an alsa device
*****************************************************************************
* This function opens an alsa device, through the alsa API
*****************************************************************************/
int aout_AlsaOpen( aout_thread_t *p_aout )
static int aout_Open( aout_thread_t *p_aout )
{
int i_open_returns;
......@@ -100,27 +173,30 @@ int aout_AlsaOpen( aout_thread_t *p_aout )
p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
/* 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_device.i_num,
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 );
intf_ErrMsg ( "This means : %s", snd_strerror(i_open_returns) );
return ( 1 );
intf_ErrMsg( "This means : %s", snd_strerror(i_open_returns) );
return( -1 );
}
intf_DbgMsg("Alsa plugin : Alsa device successfully opened");
return ( 0 );
intf_DbgMsg( "Alsa plugin : Alsa device successfully opened" );
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;
......@@ -128,8 +204,8 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
int i_playback_go_returns;
/* Fill with zeros */
memset(&p_aout->p_sys->s_alsa_channel_params,0,
sizeof(p_aout->p_sys->s_alsa_channel_params));
memset( &p_aout->p_sys->s_alsa_channel_params,0,
sizeof( p_aout->p_sys->s_alsa_channel_params ) );
/* Fill the s_alsa_channel_params structure */
......@@ -139,7 +215,7 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
/* Format and rate */
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 =
SND_PCM_SFMT_S16_LE;
else
......@@ -163,106 +239,108 @@ int aout_AlsaSetFormat ( aout_thread_t *p_aout )
p_aout->p_sys->s_alsa_channel_params.buf.stream.max_fill = 0 ;
/* 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->s_alsa_channel_params) );
if ( i_set_param_returns )
if( i_set_param_returns )
{
intf_ErrMsg ( "ALSA_PLUGIN : Unable to set parameters; exit = %i",
i_set_param_returns );
intf_ErrMsg( "ALSA_PLUGIN : Unable to set parameters; exit = %i",
i_set_param_returns );
intf_ErrMsg( "This means : %s",
snd_strerror( i_set_param_returns ) );
return ( 1 );
snd_strerror( i_set_param_returns ) );
return( -1 );
}
/* we shall now prepare the channel */
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",
i_prepare_playback_returns );
intf_ErrMsg( "ALSA_PLUGIN : Unable to prepare channel : exit = %i",
i_prepare_playback_returns );
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 */
i_playback_go_returns =
snd_pcm_playback_go ( p_aout->p_sys->p_alsa_handle );
if ( i_playback_go_returns )
snd_pcm_playback_go( p_aout->p_sys->p_alsa_handle );
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 );
intf_ErrMsg( "This means : %s",
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;
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 );
if ( i_alsa_get_status_returns )
if( i_alsa_get_status_returns )
{
intf_ErrMsg ( "Error getting alsa buffer info; exit=%i",
i_alsa_get_status_returns );
i_alsa_get_status_returns );
intf_ErrMsg ( "This means : %s",
snd_strerror ( i_alsa_get_status_returns ) );
return ( 1 );
snd_strerror ( i_alsa_get_status_returns ) );
return ( -1 );
}
switch( alsa_channel_status.status )
{
case SND_PCM_STATUS_NOTREADY : intf_ErrMsg("Status NOT READY");
break;
case SND_PCM_STATUS_UNDERRUN : {
int i_prepare_returns;
intf_ErrMsg(
"Status UNDERRUN ... reseting queue");
i_prepare_returns =
snd_pcm_playback_prepare(
p_aout->p_sys->p_alsa_handle );
if ( i_prepare_returns )
{
intf_ErrMsg(
"Error : could not flush : %i",
i_prepare_returns);
intf_ErrMsg(
"This means : %s",
snd_strerror(i_prepare_returns));
}
break;
}
case SND_PCM_STATUS_NOTREADY : intf_ErrMsg("Status NOT READY");
break;
case SND_PCM_STATUS_UNDERRUN : {
int i_prepare_returns;
intf_ErrMsg( "Status UNDERRUN ... reseting queue ");
i_prepare_returns = snd_pcm_playback_prepare(
p_aout->p_sys->p_alsa_handle );
if ( i_prepare_returns )
{
intf_ErrMsg( "Error : could not flush : %i", i_prepare_returns );
intf_ErrMsg( "This means : %s", snd_strerror(i_prepare_returns) );
}
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;
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 ( "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 )
}
/*****************************************************************************
* 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;
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( "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");
}
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