*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
- * Authors:
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ * Samuel Hocevar <sam@zoy.org>
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
+#define MODULE_NAME dsp
+#include "modules_inner.h"
+
/* TODO:
*
- * - an aout_DspGetFormats() function
+ * - an aout_GetFormats() function
* - dsp inline/static
* - make this library portable (see mpg123)
- * - macroify aout_DspPlaySamples &/| aout_DspGetBufInfo ?
*
*/
#include "common.h" /* boolean_t, byte_t */
#include "threads.h"
#include "mtime.h"
-#include "plugins.h"
+#include "tests.h"
#include "audio_output.h" /* aout_thread_t */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
#include "main.h"
+#include "modules.h"
+
/*****************************************************************************
- * vout_dsp_t: dsp audio output method descriptor
+ * aout_sys_t: dsp audio output method descriptor
*****************************************************************************
* This structure is part of the audio output thread descriptor.
* It describes the dsp specific properties of an audio device.
} aout_sys_t;
/*****************************************************************************
- * aout_DspOpen: opens the audio device (the digital sound processor)
+ * 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 _M( aout_getfunctions )( function_list_t * p_function_list )
+{
+ p_function_list->pf_probe = aout_Probe;
+ p_function_list->functions.aout.pf_open = aout_Open;
+ p_function_list->functions.aout.pf_setformat = aout_SetFormat;
+ p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
+ p_function_list->functions.aout.pf_play = aout_Play;
+ p_function_list->functions.aout.pf_close = aout_Close;
+}
+
+/*****************************************************************************
+ * aout_Probe: probe the audio device and return a score
*****************************************************************************
- * - This function opens the dsp as an usual non-blocking write-only file, and
- * modifies the p_aout->p_sys->i_fd with the file's descriptor.
+ * This function tries to open the DSP and returns a score to the plugin
+ * manager so that it can choose the most appropriate one.
*****************************************************************************/
-int aout_DspOpen( aout_thread_t *p_aout )
+static int aout_Probe( probedata_t *p_data )
{
- /* Allocate structure */
- p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
- if( p_aout->p_sys == NULL )
+ char * psz_device = main_GetPszVariable( AOUT_DSP_VAR, AOUT_DSP_DEFAULT );
+ int i_fd = open( psz_device, O_WRONLY|O_NONBLOCK );
+
+ /* If we were unable to open the device, there is no way we can use
+ * the plugin. Return a score of 0. */
+ if( i_fd < 0 )
{
- intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
- return( 1 );
+ return( 0 );
}
- /* Initialize some variables */
- p_aout->i_format = AOUT_FORMAT_DEFAULT;
- p_aout->psz_device = main_GetPszVariable( AOUT_DSP_VAR, AOUT_DSP_DEFAULT );
- p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
- p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
+ /* Otherwise, there are good chances we can use this plugin, return 100. */
+ close( i_fd );
- /* Open the sound device */
- if ( (p_aout->i_fd = open( p_aout->psz_device, O_WRONLY|O_NONBLOCK )) < 0 )
+ if( TestMethod( AOUT_METHOD_VAR, "dsp" ) )
{
- intf_ErrMsg( "aout error: can't open audio device (%s)\n", p_aout->psz_device );
- return( -1 );
+ return( 999 );
}
- return( 0 );
+ return( 100 );
}
/*****************************************************************************
- * aout_DspReset: resets the dsp
+ * aout_Open: opens the audio device (the digital sound processor)
+ *****************************************************************************
+ * This function opens the dsp as a usual non-blocking write-only file, and
+ * modifies the p_aout->i_fd with the file's descriptor.
*****************************************************************************/
-int aout_DspReset( aout_thread_t *p_aout )
+static int aout_Open( aout_thread_t *p_aout )
{
- if ( ioctl( p_aout->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
+ /* Allocate structure */
+ p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
+ if( p_aout->p_sys == NULL )
{
- intf_ErrMsg( "aout error: can't reset audio device (%s)\n", p_aout->psz_device );
- return( -1 );
+ intf_ErrMsg("aout error: %s", strerror(ENOMEM) );
+ return( 1 );
+ }
+
+ /* Initialize some variables */
+ p_aout->psz_device = main_GetPszVariable( AOUT_DSP_VAR, AOUT_DSP_DEFAULT );
+ p_aout->i_format = AOUT_FORMAT_DEFAULT;
+ p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
+ AOUT_STEREO_DEFAULT );
+ p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR,
+ AOUT_RATE_DEFAULT );
+
+ /* Open the sound device */
+ if( (p_aout->i_fd = open( p_aout->psz_device, O_WRONLY|O_NONBLOCK )) < 0 )
+ {
+ intf_ErrMsg( "aout error: can't open audio device (%s)",
+ p_aout->psz_device );
+ return( -1 );
}
return( 0 );
}
/*****************************************************************************
- * aout_DspSetFormat: sets the dsp output format
+ * aout_SetFormat: resets the dsp and sets its format
*****************************************************************************
- * This functions tries to initialize the dsp output format with the value
- * contained in the dsp structure, and if this value could not be set, the
- * default value returned by ioctl is set.
+ * This functions resets the DSP device, tries to initialize the output
+ * format with the value contained in the dsp structure, and if this value
+ * could not be set, the default value returned by ioctl is set. It then
+ * does the same for the stereo mode, and for the output rate.
*****************************************************************************/
-int aout_DspSetFormat( aout_thread_t *p_aout )
+static int aout_SetFormat( aout_thread_t *p_aout )
{
int i_format;
+ long l_rate;
+ boolean_t b_stereo = p_aout->b_stereo;
+
+ /* Reset the DSP device */
+ if( ioctl( p_aout->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
+ {
+ intf_ErrMsg( "aout error: can't reset audio device (%s)",
+ p_aout->psz_device );
+ return( -1 );
+ }
+ /* Set the output format */
i_format = p_aout->i_format;
- if ( ioctl( p_aout->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
+ if( ioctl( p_aout->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
{
- intf_ErrMsg( "aout error: can't set audio output format (%i)\n", p_aout->i_format );
+ intf_ErrMsg( "aout error: can't set audio output format (%i)",
+ p_aout->i_format );
return( -1 );
}
- if ( i_format != p_aout->i_format )
+ if( i_format != p_aout->i_format )
{
- intf_DbgMsg( "aout debug: audio output format not supported (%i)\n", p_aout->i_format );
+ intf_DbgMsg( "aout debug: audio output format not supported (%i)",
+ p_aout->i_format );
p_aout->i_format = i_format;
}
- return( 0 );
-}
-
-/*****************************************************************************
- * aout_DspSetChannels: sets the dsp's stereo or mono mode
- *****************************************************************************
- * This function acts just like the previous one...
- *****************************************************************************/
-int aout_DspSetChannels( aout_thread_t *p_aout )
-{
- boolean_t b_stereo = p_aout->b_stereo;
-
- if ( ioctl( p_aout->i_fd, SNDCTL_DSP_STEREO, &b_stereo ) < 0 )
+ /* Set the number of channels */
+ if( ioctl( p_aout->i_fd, SNDCTL_DSP_STEREO, &b_stereo ) < 0 )
{
- intf_ErrMsg( "aout error: can't set number of audio channels (%i)\n", p_aout->i_channels );
+ intf_ErrMsg( "aout error: can't set number of audio channels (%i)",
+ p_aout->i_channels );
return( -1 );
}
- if ( b_stereo != p_aout->b_stereo )
+ if( b_stereo != p_aout->b_stereo )
{
- intf_DbgMsg( "aout debug: number of audio channels not supported (%i)\n", p_aout->i_channels );
+ intf_DbgMsg( "aout debug: number of audio channels not supported (%i)",
+ p_aout->i_channels );
p_aout->b_stereo = b_stereo;
p_aout->i_channels = 1 + b_stereo;
}
- return( 0 );
-}
-
-/*****************************************************************************
- * aout_DspSetRate: sets the dsp's audio output rate
- *****************************************************************************
- * This function tries to initialize the dsp with the rate contained in the
- * dsp structure, but if the dsp doesn't support this value, the function uses
- * the value returned by ioctl...
- *****************************************************************************/
-int aout_DspSetRate( aout_thread_t *p_aout )
-{
- long l_rate;
-
+ /* Set the output rate */
l_rate = p_aout->l_rate;
- if ( ioctl( p_aout->i_fd, SNDCTL_DSP_SPEED, &l_rate ) < 0 )
+ if( ioctl( p_aout->i_fd, SNDCTL_DSP_SPEED, &l_rate ) < 0 )
{
- intf_ErrMsg( "aout error: can't set audio output rate (%li)\n", p_aout->l_rate );
+ intf_ErrMsg( "aout error: can't set audio output rate (%li)",
+ p_aout->l_rate );
return( -1 );
}
- if ( l_rate != p_aout->l_rate )
+ if( l_rate != p_aout->l_rate )
{
- intf_DbgMsg( "aout debug: audio output rate not supported (%li)\n", p_aout->l_rate );
+ intf_DbgMsg( "aout debug: audio output rate not supported (%li)",
+ p_aout->l_rate );
p_aout->l_rate = l_rate;
}
}
/*****************************************************************************
- * aout_DspGetBufInfo: buffer status query
+ * aout_GetBufInfo: buffer status query
*****************************************************************************
* This function fills in the audio_buf_info structure :
* - int fragments : number of available fragments (partially usend ones not
* - int bytes : available space in bytes (includes partially used fragments)
* Note! 'bytes' could be more than fragments*fragsize
*****************************************************************************/
-long aout_DspGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
{
ioctl( p_aout->i_fd, SNDCTL_DSP_GETOSPACE, &p_aout->p_sys->audio_buf );
}
/*****************************************************************************
- * aout_DspPlaySamples: plays a sound samples buffer
+ * aout_Play: plays a sound samples buffer
*****************************************************************************
* This function writes a buffer of i_length bytes in the dsp
*****************************************************************************/
-void aout_DspPlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
+static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
{
if( p_aout->b_active )
{
}
/*****************************************************************************
- * aout_DspClose: closes the dsp audio device
+ * aout_Close: closes the dsp audio device
*****************************************************************************/
-void aout_DspClose( aout_thread_t *p_aout )
+static void aout_Close( aout_thread_t *p_aout )
{
close( p_aout->i_fd );
}