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--;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mixer.c : audio output mixing operations * mixer.c : audio output mixing operations
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: mixer.c,v 1.7 2002/08/19 21:54:37 massiot Exp $ * $Id: mixer.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>
* *
...@@ -59,19 +59,17 @@ void aout_MixerDelete( aout_instance_t * p_aout ) ...@@ -59,19 +59,17 @@ void aout_MixerDelete( aout_instance_t * p_aout )
} }
/***************************************************************************** /*****************************************************************************
* aout_MixerRun: entry point for the mixer & post-filters processing * MixBuffer: try to prepare one output buffer
*****************************************************************************/ *****************************************************************************/
void aout_MixerRun( aout_instance_t * p_aout ) static int MixBuffer( aout_instance_t * p_aout )
{ {
int i; int i;
aout_buffer_t * p_output_buffer; aout_buffer_t * p_output_buffer;
mtime_t start_date, end_date; mtime_t start_date, end_date;
/* Retrieve the date of the next buffer. We don't use aout_FifoNextStart /* Retrieve the date of the next buffer. */
* because we need to keep the lock on the FIFO, to prevent the aout vlc_mutex_lock( &p_aout->mixer_lock );
* thread from triggering resampling while we are running. */ start_date = aout_FifoNextStart( p_aout, &p_aout->output.fifo );
vlc_mutex_lock( &p_aout->output.fifo.lock );
start_date = p_aout->output.fifo.end_date;
if ( start_date != 0 && start_date < mdate() ) if ( start_date != 0 && start_date < mdate() )
{ {
/* The output is _very_ late. This can only happen if the user /* The output is _very_ late. This can only happen if the user
...@@ -81,11 +79,42 @@ void aout_MixerRun( aout_instance_t * p_aout ) ...@@ -81,11 +79,42 @@ void aout_MixerRun( aout_instance_t * p_aout )
start_date ); start_date );
start_date = p_aout->output.fifo.end_date = 0; start_date = p_aout->output.fifo.end_date = 0;
} }
/* See if we have enough data to prepare a new buffer for the audio
* output. First : start date. */
if ( !start_date )
{
/* Find the latest start date available. */
for ( i = 0; i < p_aout->i_nb_inputs; i++ )
{
aout_input_t * p_input = p_aout->pp_inputs[i];
aout_fifo_t * p_fifo = &p_input->fifo;
aout_buffer_t * p_buffer;
p_buffer = p_fifo->p_first;
if ( p_buffer == NULL )
{
break;
}
if ( !start_date || start_date < p_buffer->start_date )
{
start_date = p_buffer->start_date;
}
}
if ( i < p_aout->i_nb_inputs )
{
/* Interrupted before the end... We can't run. */
vlc_mutex_unlock( &p_aout->mixer_lock );
return -1;
}
}
end_date = start_date + (mtime_t)p_aout->output.i_nb_samples * 1000000 end_date = start_date + (mtime_t)p_aout->output.i_nb_samples * 1000000
/ p_aout->output.output.i_rate; / p_aout->output.output.i_rate;
/* See if we have enough data to prepare a new buffer for the audio /* Check that start_date and end_date are available for all input
* output. */ * streams. */
for ( i = 0; i < p_aout->i_nb_inputs; i++ ) for ( i = 0; i < p_aout->i_nb_inputs; i++ )
{ {
aout_input_t * p_input = p_aout->pp_inputs[i]; aout_input_t * p_input = p_aout->pp_inputs[i];
...@@ -94,73 +123,60 @@ void aout_MixerRun( aout_instance_t * p_aout ) ...@@ -94,73 +123,60 @@ void aout_MixerRun( aout_instance_t * p_aout )
mtime_t prev_date; mtime_t prev_date;
vlc_bool_t b_drop_buffers; vlc_bool_t b_drop_buffers;
vlc_mutex_lock( &p_fifo->lock );
p_buffer = p_fifo->p_first; p_buffer = p_fifo->p_first;
if ( p_buffer == NULL ) if ( p_buffer == NULL )
{ {
vlc_mutex_unlock( &p_fifo->lock );
break; break;
} }
if ( !start_date ) /* Check for the continuity of start_date */
while ( p_buffer != NULL && p_buffer->end_date < start_date )
{ {
start_date = p_buffer->start_date; aout_buffer_t * p_next = p_buffer->p_next;
end_date += p_buffer->start_date; msg_Err( p_aout, "the mixer got a packet in the past (%lld)",
p_input->p_first_byte_to_mix = p_buffer->p_buffer; start_date - p_buffer->end_date );
aout_BufferFree( p_buffer );
p_fifo->p_first = p_buffer = p_next;
p_input->p_first_byte_to_mix = NULL;
} }
else if ( p_buffer == NULL )
{ {
/* Check for the continuity of start_date */ p_fifo->pp_last = &p_fifo->p_first;
while ( p_buffer != NULL && p_buffer->end_date < start_date ) break;
{ }
aout_buffer_t * p_next = p_buffer->p_next;
msg_Err( p_aout, "the mixer got a packet in the past (%lld)", if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer.mixer ) )
start_date - p_buffer->end_date ); {
aout_BufferFree( p_buffer ); /* Additionally check that p_first_byte_to_mix is well
p_fifo->p_first = p_buffer = p_next; * located. */
p_input->p_first_byte_to_mix = NULL; unsigned long i_nb_bytes = (start_date - p_buffer->start_date)
} * p_aout->mixer.mixer.i_bytes_per_frame
if ( p_buffer == NULL ) * p_aout->mixer.mixer.i_rate
/ p_aout->mixer.mixer.i_frame_length
/ 1000000;
ptrdiff_t mixer_nb_bytes;
if ( p_input->p_first_byte_to_mix == NULL )
{ {
p_fifo->pp_last = &p_fifo->p_first; p_input->p_first_byte_to_mix = p_buffer->p_buffer;
vlc_mutex_unlock( &p_fifo->lock );
break;
} }
mixer_nb_bytes = p_input->p_first_byte_to_mix
- p_buffer->p_buffer;
if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer.mixer ) ) if ( i_nb_bytes + p_aout->mixer.mixer.i_bytes_per_frame
< mixer_nb_bytes ||
i_nb_bytes - p_aout->mixer.mixer.i_bytes_per_frame
> mixer_nb_bytes )
{ {
/* Additionally check that p_first_byte_to_mix is well msg_Warn( p_aout,
* located. */ "mixer start isn't output start (%ld)",
unsigned long i_nb_bytes = (start_date - p_buffer->start_date) i_nb_bytes - mixer_nb_bytes );
* p_aout->mixer.mixer.i_bytes_per_frame
* p_aout->mixer.mixer.i_rate
/ p_aout->mixer.mixer.i_frame_length
/ 1000000;
ptrdiff_t mixer_nb_bytes;
if ( p_input->p_first_byte_to_mix == NULL )
{
p_input->p_first_byte_to_mix = p_buffer->p_buffer;
}
mixer_nb_bytes = p_input->p_first_byte_to_mix
- p_buffer->p_buffer;
if ( i_nb_bytes + p_aout->mixer.mixer.i_bytes_per_frame /* Round to the nearest multiple */
< mixer_nb_bytes || i_nb_bytes /= p_aout->mixer.mixer.i_bytes_per_frame;
i_nb_bytes - p_aout->mixer.mixer.i_bytes_per_frame i_nb_bytes *= p_aout->mixer.mixer.i_bytes_per_frame;
> mixer_nb_bytes ) p_input->p_first_byte_to_mix = p_buffer->p_buffer
{ + i_nb_bytes;
msg_Warn( p_aout,
"mixer start isn't output start (%ld)",
i_nb_bytes - mixer_nb_bytes );
/* Round to the nearest multiple */
i_nb_bytes /= p_aout->mixer.mixer.i_bytes_per_frame;
i_nb_bytes *= p_aout->mixer.mixer.i_bytes_per_frame;
p_input->p_first_byte_to_mix = p_buffer->p_buffer
+ i_nb_bytes;
}
} }
} }
...@@ -180,7 +196,7 @@ void aout_MixerRun( aout_instance_t * p_aout ) ...@@ -180,7 +196,7 @@ void aout_MixerRun( aout_instance_t * p_aout )
if ( prev_date != p_buffer->start_date ) if ( prev_date != p_buffer->start_date )
{ {
msg_Warn( p_aout, msg_Warn( p_aout,
"buffer discontinuity, dropping packets (%lld)", "buffer hole, dropping packets (%lld)",
p_buffer->start_date - prev_date ); p_buffer->start_date - prev_date );
b_drop_buffers = 1; b_drop_buffers = 1;
break; break;
...@@ -201,20 +217,16 @@ void aout_MixerRun( aout_instance_t * p_aout ) ...@@ -201,20 +217,16 @@ void aout_MixerRun( aout_instance_t * p_aout )
} }
else break; else break;
} }
vlc_mutex_unlock( &p_fifo->lock );
if ( p_buffer == NULL ) break; if ( p_buffer == NULL ) break;
} }
if ( i < p_aout->i_nb_inputs ) if ( i < p_aout->i_nb_inputs )
{ {
/* Interrupted before the end... We can't run. */ /* Interrupted before the end... We can't run. */
vlc_mutex_unlock( &p_aout->output.fifo.lock ); vlc_mutex_unlock( &p_aout->mixer_lock );
return; return -1;
} }
p_aout->b_mixer_active = 1;
vlc_mutex_unlock( &p_aout->output.fifo.lock );
/* Run the mixer. */ /* Run the mixer. */
aout_BufferAlloc( &p_aout->mixer.output_alloc, aout_BufferAlloc( &p_aout->mixer.output_alloc,
((u64)p_aout->output.i_nb_samples * 1000000) ((u64)p_aout->output.i_nb_samples * 1000000)
...@@ -226,22 +238,29 @@ void aout_MixerRun( aout_instance_t * p_aout ) ...@@ -226,22 +238,29 @@ void aout_MixerRun( aout_instance_t * p_aout )
if ( p_output_buffer == NULL ) if ( p_output_buffer == NULL )
{ {
msg_Err( p_aout, "out of memory" ); msg_Err( p_aout, "out of memory" );
return; vlc_mutex_unlock( &p_aout->mixer_lock );
return -1;
} }
p_output_buffer->i_nb_samples = p_aout->output.i_nb_samples; p_output_buffer->i_nb_samples = p_aout->output.i_nb_samples;
p_output_buffer->i_nb_bytes = p_aout->output.i_nb_samples p_output_buffer->i_nb_bytes = p_aout->output.i_nb_samples
* p_aout->output.output.i_bytes_per_frame * p_aout->mixer.mixer.i_bytes_per_frame
/ p_aout->output.output.i_frame_length; / p_aout->mixer.mixer.i_frame_length;
p_output_buffer->start_date = start_date; p_output_buffer->start_date = start_date;
p_output_buffer->end_date = end_date; p_output_buffer->end_date = end_date;
p_aout->mixer.pf_do_work( p_aout, p_output_buffer ); p_aout->mixer.pf_do_work( p_aout, p_output_buffer );
vlc_mutex_unlock( &p_aout->mixer_lock );
aout_OutputPlay( p_aout, p_output_buffer ); aout_OutputPlay( p_aout, p_output_buffer );
vlc_mutex_lock( &p_aout->output.fifo.lock ); return 0;
p_aout->b_mixer_active = 0;
vlc_cond_signal( &p_aout->mixer_signal );
vlc_mutex_unlock( &p_aout->output.fifo.lock );
} }
/*****************************************************************************
* aout_MixerRun: entry point for the mixer & post-filters processing
*****************************************************************************/
void aout_MixerRun( aout_instance_t * p_aout )
{
while( MixBuffer( p_aout ) != -1 );
}
...@@ -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