* sdl.c : SDL audio output plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
- * $Id: sdl.c,v 1.3 2002/08/19 21:31:11 massiot Exp $
+ * $Id: sdl.c,v 1.12 2002/09/18 21:21:23 massiot Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
#include SDL_INCLUDE_FILE
-#define FRAME_SIZE 2048*2
+#define FRAME_SIZE 2048
+
+/*****************************************************************************
+ * aout_sys_t: SDL audio output method descriptor
+ *****************************************************************************
+ * This structure is part of the audio output thread descriptor.
+ * It describes the specific properties of an audio device.
+ *****************************************************************************/
+struct aout_sys_t
+{
+ mtime_t next_date;
+ mtime_t buffer_time;
+};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
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 );
/*****************************************************************************
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;
if( SDL_WasInit( i_flags ) )
{
- return 1;
+ return VLC_EGENERIC;
}
- p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
+ aout_VolumeSoftInit( p_aout );
#ifndef WIN32
/* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
i_flags |= SDL_INIT_EVENTTHREAD;
if( SDL_Init( i_flags ) < 0 )
{
msg_Err( p_aout, "cannot initialize SDL (%s)", SDL_GetError() );
- return 1;
+ return VLC_EGENERIC;
}
- return 0;
-}
+ if ( p_aout->output.output.i_channels > 2 )
+ p_aout->output.output.i_channels = 2;
+ p_aout->output.output.i_format = AOUT_FMT_S16_NE;
+ p_aout->output.i_nb_samples = FRAME_SIZE;
-/*****************************************************************************
- * 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;
/* Open the sound device - FIXME : get the "natural" parameters */
if( SDL_OpenAudio( &desired, NULL ) < 0 )
{
- return -1;
+ return VLC_EGENERIC;
}
- p_aout->output.output.i_format = AOUT_FMT_S16_NE;
- p_aout->output.i_nb_samples = FRAME_SIZE;
-
SDL_PauseAudio( 0 );
- return 0;
+ return VLC_SUCCESS;
}
/*****************************************************************************
static void SDLCallback( void * _p_aout, byte_t * p_stream, int i_len )
{
aout_instance_t * p_aout = (aout_instance_t *)_p_aout;
- /* FIXME : take into account SDL latency instead of mdate() */
- aout_buffer_t * p_buffer = aout_OutputNextBuffer( p_aout, mdate(), 0 );
+ aout_buffer_t * p_buffer;
- if ( i_len != FRAME_SIZE * sizeof(s16)
- * p_aout->output.output.i_channels )
- {
- msg_Err( p_aout, "SDL doesn't know its buffer size (%d)", i_len );
- }
+ /* SDL is unable to call us at regular times, or tell us its current
+ * hardware latency, or the buffer state. So we just pop data and throw
+ * it at SDL's face. Nah. */
+
+ vlc_mutex_lock( &p_aout->output_fifo_lock );
+ p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
+ vlc_mutex_unlock( &p_aout->output_fifo_lock );
if ( p_buffer != NULL )
{