Commit 922ab4d4 authored by Christophe Massiot's avatar Christophe Massiot

More changes in the date handling. Should be more tolerant with

pause/play and change of audio channel.
parent 9a1fd919
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* aout_internal.h : internal defines for audio output * aout_internal.h : internal defines for audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: aout_internal.h,v 1.6 2002/08/19 21:31:11 massiot Exp $ * $Id: aout_internal.h,v 1.7 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -82,7 +82,6 @@ typedef struct aout_alloc_t ...@@ -82,7 +82,6 @@ typedef struct aout_alloc_t
*****************************************************************************/ *****************************************************************************/
typedef struct aout_fifo_t typedef struct aout_fifo_t
{ {
vlc_mutex_t lock;
struct aout_buffer_t * p_first; struct aout_buffer_t * p_first;
struct aout_buffer_t ** pp_last; struct aout_buffer_t ** pp_last;
mtime_t end_date; mtime_t end_date;
...@@ -91,7 +90,6 @@ typedef struct aout_fifo_t ...@@ -91,7 +90,6 @@ typedef struct aout_fifo_t
static inline void aout_FifoInit( struct aout_instance_t * p_aout, static inline void aout_FifoInit( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo ) aout_fifo_t * p_fifo )
{ {
vlc_mutex_init( (vlc_object_t *)p_aout, &p_fifo->lock );
p_fifo->p_first = NULL; p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first; p_fifo->pp_last = &p_fifo->p_first;
p_fifo->end_date = 0; p_fifo->end_date = 0;
...@@ -101,7 +99,6 @@ static inline void aout_FifoPush( struct aout_instance_t * p_aout, ...@@ -101,7 +99,6 @@ static inline void aout_FifoPush( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo, aout_fifo_t * p_fifo,
aout_buffer_t * p_buffer ) aout_buffer_t * p_buffer )
{ {
vlc_mutex_lock( &p_fifo->lock );
*p_fifo->pp_last = p_buffer; *p_fifo->pp_last = p_buffer;
p_fifo->pp_last = &p_buffer->p_next; p_fifo->pp_last = &p_buffer->p_next;
*p_fifo->pp_last = NULL; *p_fifo->pp_last = NULL;
...@@ -118,26 +115,31 @@ static inline void aout_FifoPush( struct aout_instance_t * p_aout, ...@@ -118,26 +115,31 @@ static inline void aout_FifoPush( struct aout_instance_t * p_aout,
{ {
p_fifo->end_date = p_buffer->end_date; p_fifo->end_date = p_buffer->end_date;
} }
vlc_mutex_unlock( &p_fifo->lock );
} }
static inline mtime_t aout_FifoNextStart( struct aout_instance_t * p_aout, static inline mtime_t aout_FifoNextStart( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo ) aout_fifo_t * p_fifo )
{ {
mtime_t end_date; return p_fifo->end_date;
vlc_mutex_lock( &p_fifo->lock );
end_date = p_fifo->end_date;
vlc_mutex_unlock( &p_fifo->lock );
return end_date;
} }
/* Reinit the end_date (for instance after a pause). */ /* Reinit the end_date (for instance after a pause). */
static inline void aout_FifoSet( struct aout_instance_t * p_aout, static inline void aout_FifoSet( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo, mtime_t date ) aout_fifo_t * p_fifo, mtime_t date )
{ {
vlc_mutex_lock( &p_fifo->lock ); aout_buffer_t * p_buffer;
p_fifo->end_date = date; p_fifo->end_date = date;
vlc_mutex_unlock( &p_fifo->lock );
/* Remove all buffers. */
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
aout_buffer_t * p_next = p_buffer->p_next;
aout_BufferFree( p_buffer );
p_buffer = p_next;
}
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
} }
/* This function supposes there is at least one buffer in p_fifo. */ /* This function supposes there is at least one buffer in p_fifo. */
...@@ -145,14 +147,12 @@ static inline aout_buffer_t * aout_FifoPop( struct aout_instance_t * p_aout, ...@@ -145,14 +147,12 @@ static inline aout_buffer_t * aout_FifoPop( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo ) aout_fifo_t * p_fifo )
{ {
aout_buffer_t * p_buffer; aout_buffer_t * p_buffer;
vlc_mutex_lock( &p_fifo->lock );
p_buffer = p_fifo->p_first; p_buffer = p_fifo->p_first;
p_fifo->p_first = p_buffer->p_next; p_fifo->p_first = p_buffer->p_next;
if ( p_fifo->p_first == NULL ) if ( p_fifo->p_first == NULL )
{ {
p_fifo->pp_last = &p_fifo->p_first; p_fifo->pp_last = &p_fifo->p_first;
} }
vlc_mutex_unlock( &p_fifo->lock );
return p_buffer; return p_buffer;
} }
...@@ -162,7 +162,6 @@ static inline void aout_FifoDestroy( struct aout_instance_t * p_aout, ...@@ -162,7 +162,6 @@ static inline void aout_FifoDestroy( struct aout_instance_t * p_aout,
{ {
aout_buffer_t * p_buffer; aout_buffer_t * p_buffer;
vlc_mutex_destroy( &p_fifo->lock );
p_buffer = p_fifo->p_first; p_buffer = p_fifo->p_first;
while ( p_buffer != NULL ) while ( p_buffer != NULL )
{ {
...@@ -260,9 +259,7 @@ struct aout_instance_t ...@@ -260,9 +259,7 @@ struct aout_instance_t
int i_nb_inputs; int i_nb_inputs;
/* Mixer */ /* Mixer */
vlc_cond_t mixer_signal; /* the associated mutex is vlc_mutex_t mixer_lock;
* p_aout->output.fifo.lock */
vlc_bool_t b_mixer_active;
aout_mixer_t mixer; aout_mixer_t mixer;
/* Output plug-in */ /* Output plug-in */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* file.c : audio output which writes the samples to a file * file.c : audio output which writes the samples to a file
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: file.c,v 1.7 2002/08/19 23:07:30 sam Exp $ * $Id: file.c,v 1.8 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -148,7 +148,12 @@ static int SetFormat( aout_instance_t * p_aout ) ...@@ -148,7 +148,12 @@ static int SetFormat( aout_instance_t * p_aout )
*****************************************************************************/ *****************************************************************************/
static void Play( aout_instance_t * p_aout ) static void Play( aout_instance_t * p_aout )
{ {
aout_buffer_t * p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); aout_buffer_t * p_buffer;
/* We don't need the mixer lock, since Play is entered _with_ the
* mixer lock. */
p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
if( fwrite( p_buffer->p_buffer, p_buffer->i_nb_bytes, 1, if( fwrite( p_buffer->p_buffer, p_buffer->i_nb_bytes, 1,
(FILE *)p_aout->output.p_sys ) != 1 ) (FILE *)p_aout->output.p_sys ) != 1 )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* aout_dummy.c : dummy audio output plugin * aout_dummy.c : dummy audio output plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: aout.c,v 1.5 2002/08/19 21:31:11 massiot Exp $ * $Id: aout.c,v 1.6 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -77,6 +77,8 @@ static int SetFormat( aout_instance_t * p_aout ) ...@@ -77,6 +77,8 @@ static int SetFormat( aout_instance_t * p_aout )
*****************************************************************************/ *****************************************************************************/
static void Play( aout_instance_t * p_aout ) static void Play( aout_instance_t * p_aout )
{ {
/* We don't need the mixer lock, since Play is entered _with_ the
* mixer lock. */
aout_buffer_t * p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); aout_buffer_t * p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* audio_output.c : audio output instance * audio_output.c : audio output instance
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: audio_output.c,v 1.97 2002/08/19 21:31:11 massiot Exp $ * $Id: audio_output.c,v 1.98 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -57,8 +57,7 @@ aout_instance_t * __aout_NewInstance( vlc_object_t * p_parent ) ...@@ -57,8 +57,7 @@ aout_instance_t * __aout_NewInstance( vlc_object_t * p_parent )
p_aout->b_change_requested = 0; p_aout->b_change_requested = 0;
p_aout->i_nb_inputs = 0; p_aout->i_nb_inputs = 0;
vlc_cond_init( p_parent, &p_aout->mixer_signal ); vlc_mutex_init( p_parent, &p_aout->mixer_lock );
p_aout->b_mixer_active = 0;
vlc_object_attach( p_aout, p_parent->p_vlc ); vlc_object_attach( p_aout, p_parent->p_vlc );
...@@ -72,7 +71,7 @@ void aout_DeleteInstance( aout_instance_t * p_aout ) ...@@ -72,7 +71,7 @@ void aout_DeleteInstance( aout_instance_t * p_aout )
{ {
vlc_mutex_destroy( &p_aout->input_lock ); vlc_mutex_destroy( &p_aout->input_lock );
vlc_cond_destroy( &p_aout->input_signal ); vlc_cond_destroy( &p_aout->input_signal );
vlc_cond_destroy( &p_aout->mixer_signal ); vlc_mutex_destroy( &p_aout->mixer_lock );
/* Free structure. */ /* Free structure. */
vlc_object_destroy( p_aout ); vlc_object_destroy( p_aout );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input.c : internal management of input streams for the audio output * input.c : internal management of input streams for the audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: input.c,v 1.5 2002/08/19 21:31:11 massiot Exp $ * $Id: input.c,v 1.6 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -42,13 +42,7 @@ static aout_input_t * InputNew( aout_instance_t * p_aout, ...@@ -42,13 +42,7 @@ static aout_input_t * InputNew( aout_instance_t * p_aout,
if ( p_input == NULL ) return NULL; if ( p_input == NULL ) return NULL;
vlc_mutex_lock( &p_aout->output.fifo.lock ); vlc_mutex_lock( &p_aout->mixer_lock );
while ( p_aout->b_mixer_active )
{
vlc_cond_wait( &p_aout->mixer_signal, &p_aout->output.fifo.lock );
}
p_aout->b_mixer_active = 1;
vlc_mutex_unlock( &p_aout->output.fifo.lock );
if ( p_aout->i_nb_inputs == 0 ) if ( p_aout->i_nb_inputs == 0 )
{ {
...@@ -110,18 +104,12 @@ static aout_input_t * InputNew( aout_instance_t * p_aout, ...@@ -110,18 +104,12 @@ static aout_input_t * InputNew( aout_instance_t * p_aout,
{ {
aout_MixerNew( p_aout ); aout_MixerNew( p_aout );
} }
vlc_mutex_lock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
p_aout->b_mixer_active = 0;
vlc_cond_signal( &p_aout->mixer_signal );
vlc_mutex_unlock( &p_aout->output.fifo.lock );
return NULL; return NULL;
} }
vlc_mutex_lock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
p_aout->b_mixer_active = 0;
vlc_cond_signal( &p_aout->mixer_signal );
vlc_mutex_unlock( &p_aout->output.fifo.lock );
/* Prepare hints for the buffer allocator. */ /* Prepare hints for the buffer allocator. */
p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP; p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
...@@ -177,15 +165,7 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -177,15 +165,7 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
{ {
int i_input; int i_input;
msg_Dbg( p_aout, "input 0x%x destroyed", p_input ); vlc_mutex_lock( &p_aout->mixer_lock );
vlc_mutex_lock( &p_aout->output.fifo.lock );
while ( p_aout->b_mixer_active )
{
vlc_cond_wait( &p_aout->mixer_signal, &p_aout->output.fifo.lock );
}
p_aout->b_mixer_active = 1;
vlc_mutex_unlock( &p_aout->output.fifo.lock );
for ( i_input = 0; i_input < p_aout->i_nb_inputs; i_input++ ) for ( i_input = 0; i_input < p_aout->i_nb_inputs; i_input++ )
{ {
...@@ -206,10 +186,7 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -206,10 +186,7 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
(AOUT_MAX_INPUTS - i_input - 1) * sizeof(aout_input_t *) ); (AOUT_MAX_INPUTS - i_input - 1) * sizeof(aout_input_t *) );
p_aout->i_nb_inputs--; p_aout->i_nb_inputs--;
vlc_mutex_lock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
p_aout->b_mixer_active = 0;
vlc_cond_signal( &p_aout->mixer_signal );
vlc_mutex_unlock( &p_aout->output.fifo.lock );
aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters, aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
p_input->i_nb_filters ); p_input->i_nb_filters );
...@@ -222,6 +199,8 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -222,6 +199,8 @@ void aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
aout_OutputDelete( p_aout ); aout_OutputDelete( p_aout );
aout_MixerDelete( p_aout ); aout_MixerDelete( p_aout );
} }
msg_Dbg( p_aout, "input 0x%x destroyed", p_input );
} }
/***************************************************************************** /*****************************************************************************
...@@ -252,7 +231,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -252,7 +231,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
* happen :). */ * happen :). */
msg_Warn( p_aout, "Computed PTS is out of range (%lld), clearing out", msg_Warn( p_aout, "Computed PTS is out of range (%lld), clearing out",
start_date ); start_date );
vlc_mutex_lock( &p_aout->mixer_lock );
aout_FifoSet( p_aout, &p_input->fifo, 0 ); aout_FifoSet( p_aout, &p_input->fifo, 0 );
vlc_mutex_unlock( &p_aout->mixer_lock );
start_date = 0; start_date = 0;
} }
...@@ -314,7 +295,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -314,7 +295,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
&new_output ) < 0 ) &new_output ) < 0 )
{ {
msg_Err( p_aout, "couldn't set an input pipeline for resampling" ); msg_Err( p_aout, "couldn't set an input pipeline for resampling" );
vlc_mutex_lock( &p_aout->mixer_lock );
aout_FifoSet( p_aout, &p_input->fifo, 0 ); aout_FifoSet( p_aout, &p_input->fifo, 0 );
vlc_mutex_unlock( &p_aout->mixer_lock );
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
vlc_mutex_lock( &p_aout->input_lock ); vlc_mutex_lock( &p_aout->input_lock );
...@@ -347,7 +330,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -347,7 +330,9 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* Adding the start date will be managed by aout_FifoPush(). */ /* Adding the start date will be managed by aout_FifoPush(). */
p_buffer->start_date = start_date; p_buffer->start_date = start_date;
p_buffer->end_date = start_date + duration; p_buffer->end_date = start_date + duration;
vlc_mutex_lock( &p_aout->mixer_lock );
aout_FifoPush( p_aout, &p_input->fifo, p_buffer ); aout_FifoPush( p_aout, &p_input->fifo, p_buffer );
vlc_mutex_unlock( &p_aout->mixer_lock );
vlc_mutex_lock( &p_aout->input_lock ); vlc_mutex_lock( &p_aout->input_lock );
p_aout->i_inputs_active--; p_aout->i_inputs_active--;
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* output.c : internal management of output streams for the audio output * output.c : internal management of output streams for the audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: output.c,v 1.7 2002/08/19 21:31:11 massiot Exp $ * $Id: output.c,v 1.8 2002/08/19 23:12:57 massiot Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -43,9 +43,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -43,9 +43,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
int i_channels = config_GetInt( p_aout, "aout-channels" ); int i_channels = config_GetInt( p_aout, "aout-channels" );
/* Prepare FIFO. */ /* Prepare FIFO. */
vlc_mutex_init( p_aout, &p_aout->output.fifo.lock ); aout_FifoInit( p_aout, &p_aout->output.fifo );
p_aout->output.fifo.p_first = NULL;
p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first;
p_aout->output.p_module = module_Need( p_aout, "audio output", p_aout->output.p_module = module_Need( p_aout, "audio output",
psz_name ); psz_name );
...@@ -151,6 +149,7 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer ) ...@@ -151,6 +149,7 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
p_aout->output.i_nb_filters, p_aout->output.i_nb_filters,
&p_buffer ); &p_buffer );
/* Please remember that we have the mixer_lock in this function. */
aout_FifoPush( p_aout, &p_aout->output.fifo, p_buffer ); aout_FifoPush( p_aout, &p_aout->output.fifo, p_buffer );
p_aout->output.pf_play( p_aout ); p_aout->output.pf_play( p_aout );
...@@ -169,7 +168,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -169,7 +168,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
{ {
aout_buffer_t * p_buffer; aout_buffer_t * p_buffer;
vlc_mutex_lock( &p_aout->output.fifo.lock ); vlc_mutex_lock( &p_aout->mixer_lock );
p_buffer = p_aout->output.fifo.p_first; p_buffer = p_aout->output.fifo.p_first;
while ( p_buffer != NULL && p_buffer->end_date < start_date ) while ( p_buffer != NULL && p_buffer->end_date < start_date )
...@@ -183,7 +182,9 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -183,7 +182,9 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
if ( p_buffer == NULL ) if ( p_buffer == NULL )
{ {
p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first; p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first;
vlc_mutex_unlock( &p_aout->output.fifo.lock ); /* Set date to 0, to allow the mixer to send a new buffer ASAP */
p_aout->output.fifo.end_date = 0;
vlc_mutex_unlock( &p_aout->mixer_lock );
msg_Dbg( p_aout, "audio output is starving" ); msg_Dbg( p_aout, "audio output is starving" );
return NULL; return NULL;
} }
...@@ -193,7 +194,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -193,7 +194,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
if ( p_buffer->start_date > start_date if ( p_buffer->start_date > start_date
+ (p_buffer->end_date - p_buffer->start_date) ) + (p_buffer->end_date - p_buffer->start_date) )
{ {
vlc_mutex_unlock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
msg_Dbg( p_aout, "audio output is starving (%lld)", msg_Dbg( p_aout, "audio output is starving (%lld)",
p_buffer->start_date - start_date ); p_buffer->start_date - start_date );
return NULL; return NULL;
...@@ -222,6 +223,6 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -222,6 +223,6 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first; p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first;
} }
vlc_mutex_unlock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
return p_buffer; return p_buffer;
} }
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