Commit 06996317 authored by Christophe Massiot's avatar Christophe Massiot

aout3 API change :

pf_setformat disappears (it was never called independantly of Open). If
the format needs to be changed, we will have Close/Open. This is much
simpler than before. Please check that I didn't break some plug-ins.
parent 0b88e775
......@@ -2,7 +2,7 @@
* aout_internal.h : internal defines for audio output
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: aout_internal.h,v 1.13 2002/08/30 22:22:24 massiot Exp $
* $Id: aout_internal.h,v 1.14 2002/08/30 23:27:05 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -158,7 +158,6 @@ typedef struct aout_output_t
struct module_t * p_module;
struct aout_sys_t * p_sys;
int (* pf_setformat)( aout_instance_t * );
void (* pf_play)( aout_instance_t * );
int i_nb_samples;
} aout_output_t;
......
......@@ -2,7 +2,7 @@
* alsa.c : alsa plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: alsa.c,v 1.9 2002/08/29 23:53:22 massiot Exp $
* $Id: alsa.c,v 1.10 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Henri Fallon <henri@videolan.org> - Original Author
* Jeffrey Baker <jwbaker@acm.org> - Port to ALSA 1.0 API
......@@ -52,8 +52,6 @@ struct aout_sys_t
snd_pcm_sframes_t i_buffer_size;
int i_period_time;
volatile vlc_bool_t b_initialized;
volatile vlc_bool_t b_can_sleek;
#ifdef DEBUG
......@@ -77,10 +75,7 @@ struct aout_sys_t
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static int ALSAThread ( aout_instance_t * );
static void ALSAFill ( aout_instance_t * );
......@@ -105,6 +100,18 @@ static int Open( vlc_object_t *p_this )
aout_instance_t * p_aout = (aout_instance_t *)p_this;
struct aout_sys_t * p_sys;
int i_snd_rc;
char * psz_device;
char psz_alsadev[128];
char * psz_userdev;
int i_format;
int i_channels;
snd_pcm_hw_params_t *p_hw;
snd_pcm_sw_params_t *p_sw;
/* Allocate structures */
p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) );
if( p_sys == NULL )
......@@ -113,48 +120,12 @@ static int Open( vlc_object_t *p_this )
return -1;
}
/* Create ALSA thread and wait for its readiness. */
p_sys->b_initialized = VLC_FALSE;
if( vlc_thread_create( p_aout, "aout", ALSAThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create ALSA thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
#ifdef DEBUG
snd_output_stdio_attach( &p_sys->p_snd_stderr, stderr, 0 );
#endif
return 0;
}
/*****************************************************************************
* 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.
*****************************************************************************/
static int SetFormat( aout_instance_t * p_aout )
{
struct aout_sys_t * p_sys = p_aout->output.p_sys;
int i_snd_rc;
char * psz_device;
char psz_alsadev[128];
char * psz_userdev;
int i_format;
int i_channels;
snd_pcm_hw_params_t *p_hw;
snd_pcm_sw_params_t *p_sw;
/* Read in ALSA device preferences from configuration */
psz_userdev = config_GetPsz( p_aout, "alsa-device" );
......@@ -334,13 +305,20 @@ static int SetFormat( aout_instance_t * p_aout )
snd_output_printf( p_sys->p_snd_stderr, "\n" );
#endif
p_sys->b_initialized = VLC_TRUE;
/* Create ALSA thread and wait for its readiness. */
if( vlc_thread_create( p_aout, "aout", ALSAThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create ALSA thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
return 0;
}
/*****************************************************************************
* Play: queue a buffer for playing by ALSAThread
* Play: nothing to do
*****************************************************************************/
static void Play( aout_instance_t *p_aout )
{
......@@ -383,9 +361,6 @@ static int ALSAThread( aout_instance_t * p_aout )
{
struct aout_sys_t * p_sys = p_aout->output.p_sys;
while ( !p_aout->b_die && !p_sys->b_initialized )
msleep( THREAD_SLEEP );
while ( !p_aout->b_die )
{
ALSAFill( p_aout );
......
......@@ -2,6 +2,7 @@
* arts.c : aRts module
*****************************************************************************
* Copyright (C) 2001-2002 VideoLAN
* $Id: arts.c,v 1.10 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Emmanuel Blindauer <manu@agat.net>
* Samuel Hocevar <sam@zoy.org>
......@@ -46,7 +47,6 @@
struct aout_sys_t
{
arts_stream_t stream;
vlc_bool_t b_initialized;
mtime_t latency;
int i_size;
......@@ -57,8 +57,6 @@ struct aout_sys_t
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static int aRtsThread ( aout_instance_t * );
......@@ -87,6 +85,7 @@ static int Open( vlc_object_t *p_this )
msg_Err( p_aout, "out of memory" );
return -1;
}
p_aout->output.p_sys = p_sys;
i_err = arts_init();
......@@ -97,35 +96,10 @@ static int Open( vlc_object_t *p_this )
return -1;
}
p_aout->output.p_sys = p_sys;
/* Create aRts thread and wait for its readiness. */
p_sys->b_initialized = VLC_FALSE;
if( vlc_thread_create( p_aout, "aout", aRtsThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create aRts thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
p_sys->stream = NULL;
return 0;
}
/*****************************************************************************
* SetFormat: set the output format
*****************************************************************************/
static int SetFormat( aout_instance_t *p_aout )
{
struct aout_sys_t * p_sys = p_aout->output.p_sys;
p_sys->b_initialized = VLC_FALSE;
if( p_sys->stream )
{
arts_close_stream( p_sys->stream );
......@@ -152,13 +126,20 @@ static int SetFormat( aout_instance_t *p_aout )
p_aout->output.output.i_format = AOUT_FMT_S16_NE;
p_aout->output.i_nb_samples = p_sys->i_size;
p_sys->b_initialized = VLC_TRUE;
/* Create aRts thread and wait for its readiness. */
if( vlc_thread_create( p_aout, "aout", aRtsThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create aRts thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
return 0;
}
/*****************************************************************************
* Play: queue a buffer for playing by aRtsThread
* Play: nothing to do
*****************************************************************************/
static void Play( aout_instance_t *p_aout )
{
......@@ -198,12 +179,6 @@ static int aRtsThread( aout_instance_t * p_aout )
int i_tmp, i_size;
byte_t * p_bytes;
if( !p_sys->b_initialized )
{
msleep( THREAD_SLEEP );
continue;
}
/* Get the presentation date of the next write() operation. It
* is equal to the current date + latency */
p_buffer = aout_OutputNextBuffer( p_aout, mdate() + p_sys->latency,
......
......@@ -2,7 +2,7 @@
* esd.c : EsounD module
*****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN
* $Id: esd.c,v 1.11 2002/08/29 23:53:22 massiot Exp $
* $Id: esd.c,v 1.12 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -46,7 +46,6 @@ struct aout_sys_t
{
esd_format_t esd_format;
int i_fd;
vlc_bool_t b_initialized;
mtime_t latency;
};
......@@ -56,8 +55,6 @@ struct aout_sys_t
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static int ESDThread ( aout_instance_t * );
......@@ -89,31 +86,8 @@ static int Open( vlc_object_t *p_this )
p_aout->output.p_sys = p_sys;
/* Create ESD thread and wait for its readiness. */
p_sys->b_initialized = VLC_FALSE;
if( vlc_thread_create( p_aout, "aout", ESDThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create ESD thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
return( 0 );
}
/*****************************************************************************
* SetFormat: set the output format
*****************************************************************************/
static int SetFormat( aout_instance_t *p_aout )
{
struct aout_sys_t * p_sys = p_aout->output.p_sys;
p_sys->b_initialized = VLC_FALSE;
/* Initialize some variables */
p_sys->esd_format = ESD_BITS16 | ESD_STREAM | ESD_PLAY;
p_sys->esd_format &= ~ESD_MASK_CHAN;
......@@ -155,13 +129,20 @@ static int SetFormat( aout_instance_t *p_aout )
/ p_aout->output.output.i_bytes_per_frame
/ p_aout->output.output.i_rate;
p_sys->b_initialized = VLC_TRUE;
/* Create ESD thread and wait for its readiness. */
if( vlc_thread_create( p_aout, "aout", ESDThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create ESD thread (%s)", strerror(errno) );
free( p_sys );
return -1;
}
return 0;
}
/*****************************************************************************
* Play: queue a buffer for playing by ESDThread
* Play: nothing to do
*****************************************************************************/
static void Play( aout_instance_t *p_aout )
{
......@@ -195,12 +176,6 @@ static int ESDThread( aout_instance_t * p_aout )
int i_tmp, i_size;
byte_t * p_bytes;
if( !p_sys->b_initialized )
{
msleep( THREAD_SLEEP );
continue;
}
/* Get the presentation date of the next write() operation. It
* is equal to the current date + buffered samples + esd latency */
p_buffer = aout_OutputNextBuffer( p_aout, mdate() + p_sys->latency,
......
......@@ -2,7 +2,7 @@
* file.c : audio output which writes the samples to a file
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: file.c,v 1.9 2002/08/30 22:22:24 massiot Exp $
* $Id: file.c,v 1.10 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -41,7 +41,6 @@
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
/*****************************************************************************
......@@ -82,37 +81,18 @@ static int Open( vlc_object_t * p_this )
aout_instance_t * p_aout = (aout_instance_t *)p_this;
FILE * p_file;
char * psz_name = config_GetPsz( p_this, "path" );
char * psz_format = config_GetPsz( p_aout, "format" );
char ** ppsz_compare = format_list;
int i = 0;
p_file = fopen( psz_name, "wb" );
p_aout->output.p_sys = (void *)p_file;
free( psz_name );
if ( p_file == NULL ) return -1;
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: close our file
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
aout_instance_t * p_aout = (aout_instance_t *)p_this;
fclose( (FILE *)p_aout->output.p_sys );
}
/*****************************************************************************
* SetFormat: pretend to set the dsp output format
*****************************************************************************/
static int SetFormat( aout_instance_t * p_aout )
{
char * psz_format = config_GetPsz( p_aout, "format" );
char ** ppsz_compare = format_list;
int i = 0;
while ( *ppsz_compare != NULL )
{
if ( !strncmp( *ppsz_compare, psz_format, strlen(*ppsz_compare) ) )
......@@ -143,6 +123,16 @@ static int SetFormat( aout_instance_t * p_aout )
return 0;
}
/*****************************************************************************
* Close: close our file
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
aout_instance_t * p_aout = (aout_instance_t *)p_this;
fclose( (FILE *)p_aout->output.p_sys );
}
/*****************************************************************************
* Play: pretend to play a sound
*****************************************************************************/
......
......@@ -2,7 +2,7 @@
* oss.c : OSS /dev/dsp module for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
* $Id: oss.c,v 1.20 2002/08/29 23:53:22 massiot Exp $
* $Id: oss.c,v 1.21 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -62,7 +62,6 @@
struct aout_sys_t
{
int i_fd;
volatile vlc_bool_t b_initialized;
};
#define FRAME_SIZE 1024
......@@ -75,7 +74,6 @@ struct aout_sys_t
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static int OSSThread ( aout_instance_t * );
......@@ -102,6 +100,10 @@ static int Open( vlc_object_t *p_this )
aout_instance_t * p_aout = (aout_instance_t *)p_this;
struct aout_sys_t * p_sys;
char * psz_device;
int i_format;
int i_rate;
int i_fragments;
vlc_bool_t b_stereo;
/* Allocate structure */
p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) );
......@@ -129,42 +131,8 @@ static int Open( vlc_object_t *p_this )
}
free( psz_device );
/* Create OSS thread and wait for its readiness. */
p_sys->b_initialized = VLC_FALSE;
if( vlc_thread_create( p_aout, "aout", OSSThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create OSS thread (%s)", strerror(errno) );
close( p_sys->i_fd );
free( psz_device );
free( p_sys );
return VLC_ETHREAD;
}
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
return VLC_SUCCESS;
}
/*****************************************************************************
* SetFormat: reset the dsp and set its format
*****************************************************************************
* 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.
*****************************************************************************/
static int SetFormat( aout_instance_t *p_aout )
{
struct aout_sys_t * p_sys = p_aout->output.p_sys;
int i_format;
int i_rate;
int i_fragments;
vlc_bool_t b_stereo;
p_sys->b_initialized = VLC_FALSE;
/* Reset the DSP device */
if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
{
......@@ -246,13 +214,22 @@ static int SetFormat( aout_instance_t *p_aout )
}
}
p_sys->b_initialized = VLC_TRUE;
/* Create OSS thread and wait for its readiness. */
if( vlc_thread_create( p_aout, "aout", OSSThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
{
msg_Err( p_aout, "cannot create OSS thread (%s)", strerror(errno) );
close( p_sys->i_fd );
free( psz_device );
free( p_sys );
return VLC_ETHREAD;
}
return VLC_SUCCESS;
}
/*****************************************************************************
* Play: queue a buffer for playing by OSSThread
* Play: nothing to do
*****************************************************************************/
static void Play( aout_instance_t *p_aout )
{
......@@ -319,12 +296,6 @@ static int OSSThread( aout_instance_t * p_aout )
int i_tmp, i_size;
byte_t * p_bytes;
if( !p_sys->b_initialized )
{
msleep( THREAD_SLEEP );
continue;
}
if ( p_aout->output.output.i_format != AOUT_FMT_SPDIF )
{
mtime_t buffered = BufferDuration( p_aout );
......
......@@ -2,7 +2,7 @@
* sdl.c : SDL audio output plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
* $Id: sdl.c,v 1.8 2002/08/30 22:22:24 massiot Exp $
* $Id: sdl.c,v 1.9 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -57,10 +57,7 @@ struct aout_sys_t
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static void SDLCallback ( void *, Uint8 *, int );
/*****************************************************************************
......@@ -78,6 +75,7 @@ vlc_module_end();
static int Open ( vlc_object_t *p_this )
{
aout_instance_t *p_aout = (aout_instance_t *)p_this;
SDL_AudioSpec desired;
Uint32 i_flags = SDL_INIT_AUDIO;
......@@ -106,16 +104,7 @@ static int Open ( vlc_object_t *p_this )
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
/*****************************************************************************
* SetFormat: reset the audio device and sets its format
*****************************************************************************/
static int SetFormat( aout_instance_t *p_aout )
{
/* TODO: finish and clean this */
SDL_AudioSpec desired;
desired.freq = p_aout->output.output.i_rate;
desired.format = AUDIO_S16SYS;
......
......@@ -2,7 +2,7 @@
* waveout.c : Windows waveOut plugin for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: waveout.c,v 1.5 2002/08/25 09:40:00 sam Exp $
* $Id: waveout.c,v 1.6 2002/08/30 23:27:06 massiot Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -43,8 +43,6 @@
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
/* local functions */
......@@ -102,7 +100,6 @@ static int Open( vlc_object_t *p_this )
return 1;
}
p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
/* calculate the frame size in bytes */
......@@ -119,57 +116,17 @@ static int Open( vlc_object_t *p_this )
/* We need to open the device with default values to be sure it is
* available */
return OpenWaveOut( p_aout, WAVE_FORMAT_PCM, 2, 44100 );
}
/*****************************************************************************
* SetFormat: reset the audio device and sets its format
*****************************************************************************
* This functions set a new audio format.
* For this we need to close the current device and create another
* one with the desired format.
*****************************************************************************/
static int SetFormat( aout_instance_t *p_aout )
{
msg_Dbg( p_aout, "SetFormat" );
if ( OpenWaveOut( p_aout, WAVE_FORMAT_PCM, 2, 44100 ) )
{
msg_Err( p_aout, "cannot open waveout" );
return 1;
}
waveOutReset( p_aout->output.p_sys->h_waveout );
p_aout->output.output.i_format = AOUT_FMT_S16_NE;
p_aout->output.i_nb_samples = FRAME_SIZE;
/* Check if the format has changed */
if( (p_aout->output.p_sys->waveformat.nChannels !=
p_aout->output.output.i_channels) ||
(p_aout->output.p_sys->waveformat.nSamplesPerSec !=
p_aout->output.output.i_rate) )
{
if( waveOutClose( p_aout->output.p_sys->h_waveout ) !=
MMSYSERR_NOERROR )
{