Commit a56b8f9c authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

audio_output: Use help to lock and unlock so we can hopefully track bad locking scheme.

The audio output locking rule seems very vague. Moreover there could be some cross lock issues.
parent 2a6de932
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#ifndef __LIBVLC_AOUT_INTERNAL_H #ifndef __LIBVLC_AOUT_INTERNAL_H
# define __LIBVLC_AOUT_INTERNAL_H 1 # define __LIBVLC_AOUT_INTERNAL_H 1
#include <assert.h>
#if defined( __APPLE__ ) || defined( SYS_BSD ) #if defined( __APPLE__ ) || defined( SYS_BSD )
#undef HAVE_ALLOCA #undef HAVE_ALLOCA
#endif #endif
...@@ -140,16 +142,59 @@ int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_inpu ...@@ -140,16 +142,59 @@ int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_inpu
/* Helpers */ /* Helpers */
static inline void aout_lock_mixer( aout_instance_t *p_aout )
{
vlc_mutex_lock( &p_aout->mixer_lock );
}
static inline void aout_unlock_mixer( aout_instance_t *p_aout )
{
vlc_mutex_unlock( &p_aout->mixer_lock );
}
static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
{
vlc_mutex_lock( &p_aout->input_fifos_lock );
}
static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
{
vlc_mutex_unlock( &p_aout->input_fifos_lock );
}
static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
{
vlc_mutex_lock( &p_aout->output_fifo_lock );
}
static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
{
vlc_mutex_unlock( &p_aout->output_fifo_lock );
}
static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
{
(void)p_aout;
vlc_mutex_lock( &p_input->lock );
}
static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
{
(void)p_aout;
vlc_mutex_unlock( &p_input->lock );
}
/** /**
* This function will safely mark aout input to be restarted as soon as * This function will safely mark aout input to be restarted as soon as
* possible to take configuration changes into account */ * possible to take configuration changes into account */
static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout ) static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
{ {
int i; int i;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
for( i = 0; i < p_aout->i_nb_inputs; i++ ) for( i = 0; i < p_aout->i_nb_inputs; i++ )
p_aout->pp_inputs[i]->b_restart = true; p_aout->pp_inputs[i]->b_restart = true;
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
} }
/* This function will add or remove a a module from a string list (comma /* This function will add or remove a a module from a string list (comma
......
...@@ -80,7 +80,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, ...@@ -80,7 +80,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
/* We can only be called by the decoder, so no need to lock /* We can only be called by the decoder, so no need to lock
* p_input->lock. */ * p_input->lock. */
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( p_aout->i_nb_inputs >= AOUT_MAX_INPUTS ) if ( p_aout->i_nb_inputs >= AOUT_MAX_INPUTS )
{ {
...@@ -105,7 +105,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, ...@@ -105,7 +105,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
if( p_replay_gain ) if( p_replay_gain )
p_input->replay_gain = *p_replay_gain; p_input->replay_gain = *p_replay_gain;
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
p_aout->pp_inputs[p_aout->i_nb_inputs] = p_input; p_aout->pp_inputs[p_aout->i_nb_inputs] = p_input;
p_aout->i_nb_inputs++; p_aout->i_nb_inputs++;
...@@ -121,22 +121,22 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, ...@@ -121,22 +121,22 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
{ {
for ( i = 0; i < p_aout->i_nb_inputs - 1; i++ ) for ( i = 0; i < p_aout->i_nb_inputs - 1; i++ )
{ {
vlc_mutex_lock( &p_aout->pp_inputs[i]->lock ); aout_lock_input( p_aout, p_aout->pp_inputs[i] );
aout_InputDelete( p_aout, p_aout->pp_inputs[i] ); aout_InputDelete( p_aout, p_aout->pp_inputs[i] );
vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock ); aout_unlock_input( p_aout, p_aout->pp_inputs[i] );
} }
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return p_input; return p_input;
} }
/* Create other input streams. */ /* Create other input streams. */
for ( i = 0; i < p_aout->i_nb_inputs - 1; i++ ) for ( i = 0; i < p_aout->i_nb_inputs - 1; i++ )
{ {
vlc_mutex_lock( &p_aout->pp_inputs[i]->lock ); aout_lock_input( p_aout, p_aout->pp_inputs[i] );
aout_InputDelete( p_aout, p_aout->pp_inputs[i] ); aout_InputDelete( p_aout, p_aout->pp_inputs[i] );
aout_InputNew( p_aout, p_aout->pp_inputs[i] ); aout_InputNew( p_aout, p_aout->pp_inputs[i] );
vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock ); aout_unlock_input( p_aout, p_aout->pp_inputs[i] );
} }
} }
else else
...@@ -147,14 +147,14 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, ...@@ -147,14 +147,14 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
if ( aout_MixerNew( p_aout ) == -1 ) if ( aout_MixerNew( p_aout ) == -1 )
{ {
aout_OutputDelete( p_aout ); aout_OutputDelete( p_aout );
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
goto error; goto error;
} }
aout_InputNew( p_aout, p_input ); aout_InputNew( p_aout, p_input );
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
p_input->i_desync = var_CreateGetInteger( p_this, "audio-desync" ) * 1000; p_input->i_desync = var_CreateGetInteger( p_this, "audio-desync" ) * 1000;
p_input_thread = (input_thread_t *)vlc_object_find( p_this, p_input_thread = (input_thread_t *)vlc_object_find( p_this,
...@@ -176,7 +176,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, ...@@ -176,7 +176,7 @@ static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout,
return p_input; return p_input;
error: error:
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return NULL; return NULL;
} }
...@@ -211,7 +211,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -211,7 +211,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input )
/* This function can only be called by the decoder itself, so no need /* This function can only be called by the decoder itself, so no need
* to lock p_input->lock. */ * to lock p_input->lock. */
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
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++ )
{ {
...@@ -224,7 +224,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -224,7 +224,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input )
if ( i_input == p_aout->i_nb_inputs ) if ( i_input == p_aout->i_nb_inputs )
{ {
msg_Err( p_aout, "cannot find an input to delete" ); msg_Err( p_aout, "cannot find an input to delete" );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return -1; return -1;
} }
...@@ -252,7 +252,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -252,7 +252,7 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input )
} }
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return 0; return 0;
} }
...@@ -271,11 +271,11 @@ aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input, ...@@ -271,11 +271,11 @@ aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input,
aout_buffer_t * p_buffer; aout_buffer_t * p_buffer;
mtime_t duration; mtime_t duration;
vlc_mutex_lock( &p_input->lock ); aout_lock_input( NULL, p_input );
if ( p_input->b_error ) if ( p_input->b_error )
{ {
vlc_mutex_unlock( &p_input->lock ); aout_unlock_input( NULL, p_input );
return NULL; return NULL;
} }
...@@ -290,7 +290,7 @@ aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input, ...@@ -290,7 +290,7 @@ aout_buffer_t * aout_DecNewBuffer( aout_input_t * p_input,
/* Suppose the decoder doesn't have more than one buffered buffer */ /* Suppose the decoder doesn't have more than one buffered buffer */
p_input->b_changed = 0; p_input->b_changed = 0;
vlc_mutex_unlock( &p_input->lock ); aout_unlock_input( NULL, p_input );
if( p_buffer == NULL ) if( p_buffer == NULL )
return NULL; return NULL;
...@@ -360,11 +360,11 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -360,11 +360,11 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
+ (mtime_t)p_buffer->i_nb_samples * 1000000 + (mtime_t)p_buffer->i_nb_samples * 1000000
/ p_input->input.i_rate; / p_input->input.i_rate;
vlc_mutex_lock( &p_input->lock ); aout_lock_input( p_aout, p_input );
if ( p_input->b_error ) if ( p_input->b_error )
{ {
vlc_mutex_unlock( &p_input->lock ); aout_unlock_input( p_aout, p_input );
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
return -1; return -1;
} }
...@@ -391,16 +391,14 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -391,16 +391,14 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* If the buffer is too early, wait a while. */ /* If the buffer is too early, wait a while. */
mwait( p_buffer->start_date - AOUT_MAX_PREPARE_TIME ); mwait( p_buffer->start_date - AOUT_MAX_PREPARE_TIME );
if ( aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate ) == -1 ) int ret = aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
{
vlc_mutex_unlock( &p_input->lock ); aout_unlock_input( p_aout, p_input );
return -1;
}
vlc_mutex_unlock( &p_input->lock ); if ( ret == -1 ) return -1;
/* Run the mixer if it is able to run. */ /* Run the mixer if it is able to run. */
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
aout_MixerRun( p_aout ); aout_MixerRun( p_aout );
if( p_input->p_input_thread ) if( p_input->p_input_thread )
{ {
...@@ -410,7 +408,7 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -410,7 +408,7 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
1, NULL ); 1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock); vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock);
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return 0; return 0;
} }
...@@ -483,8 +483,8 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -483,8 +483,8 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_fifo_t fifo, dummy_fifo; aout_fifo_t fifo, dummy_fifo;
uint8_t *p_first_byte_to_mix; uint8_t *p_first_byte_to_mix;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
/* A little trick to avoid loosing our input fifo */ /* A little trick to avoid loosing our input fifo */
aout_FifoInit( p_aout, &dummy_fifo, p_aout->mixer.mixer.i_rate ); aout_FifoInit( p_aout, &dummy_fifo, p_aout->mixer.mixer.i_rate );
...@@ -496,8 +496,8 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -496,8 +496,8 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
p_input->p_first_byte_to_mix = p_first_byte_to_mix; p_input->p_first_byte_to_mix = p_first_byte_to_mix;
p_input->fifo = fifo; p_input->fifo = fifo;
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
} }
if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL ) if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
...@@ -541,9 +541,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -541,9 +541,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* We don't care if someone changes the start date behind our back after /* We don't care if someone changes the start date behind our back after
* this. We'll deal with that when pushing the buffer, and compensate * this. We'll deal with that when pushing the buffer, and compensate
* with the next incoming buffer. */ * with the next incoming buffer. */
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
start_date = aout_FifoNextStart( p_aout, &p_input->fifo ); start_date = aout_FifoNextStart( p_aout, &p_input->fifo );
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
if ( start_date != 0 && start_date < mdate() ) if ( start_date != 0 && start_date < mdate() )
{ {
...@@ -552,10 +552,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -552,10 +552,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
* happen :). */ * happen :). */
msg_Warn( p_aout, "computed PTS is out of range (%"PRId64"), " msg_Warn( p_aout, "computed PTS is out of range (%"PRId64"), "
"clearing out", mdate() - start_date ); "clearing out", mdate() - start_date );
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
aout_FifoSet( p_aout, &p_input->fifo, 0 ); aout_FifoSet( p_aout, &p_input->fifo, 0 );
p_input->p_first_byte_to_mix = NULL; p_input->p_first_byte_to_mix = NULL;
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE ) if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
msg_Warn( p_aout, "timing screwed, stopping resampling" ); msg_Warn( p_aout, "timing screwed, stopping resampling" );
inputResamplingStop( p_input ); inputResamplingStop( p_input );
...@@ -582,10 +582,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -582,10 +582,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
{ {
msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out", msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out",
start_date - p_buffer->start_date ); start_date - p_buffer->start_date );
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
aout_FifoSet( p_aout, &p_input->fifo, 0 ); aout_FifoSet( p_aout, &p_input->fifo, 0 );
p_input->p_first_byte_to_mix = NULL; p_input->p_first_byte_to_mix = NULL;
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE ) if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
msg_Warn( p_aout, "timing screwed, stopping resampling" ); msg_Warn( p_aout, "timing screwed, stopping resampling" );
inputResamplingStop( p_input ); inputResamplingStop( p_input );
...@@ -710,9 +710,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, ...@@ -710,9 +710,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
(p_buffer->end_date - p_buffer->start_date); (p_buffer->end_date - p_buffer->start_date);
p_buffer->start_date = start_date; p_buffer->start_date = start_date;
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
aout_FifoPush( p_aout, &p_input->fifo, p_buffer ); aout_FifoPush( p_aout, &p_input->fifo, p_buffer );
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
return 0; return 0;
} }
...@@ -862,13 +862,13 @@ static int ReplayGainCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -862,13 +862,13 @@ static int ReplayGainCallback( vlc_object_t *p_this, char const *psz_cmd,
aout_instance_t *p_aout = (aout_instance_t *)p_this; aout_instance_t *p_aout = (aout_instance_t *)p_this;
int i; int i;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
for( i = 0; i < p_aout->i_nb_inputs; i++ ) for( i = 0; i < p_aout->i_nb_inputs; i++ )
ReplayGainSelect( p_aout, p_aout->pp_inputs[i] ); ReplayGainSelect( p_aout, p_aout->pp_inputs[i] );
/* Restart the mixer (a trivial mixer may be in use) */ /* Restart the mixer (a trivial mixer may be in use) */
aout_MixerMultiplierSet( p_aout, p_aout->mixer.f_multiplier ); aout_MixerMultiplierSet( p_aout, p_aout->mixer.f_multiplier );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -78,7 +78,7 @@ int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume ) ...@@ -78,7 +78,7 @@ int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume )
return 0; return 0;
} }
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( !p_aout->mixer.b_error ) if ( !p_aout->mixer.b_error )
{ {
i_result = p_aout->output.pf_volume_get( p_aout, pi_volume ); i_result = p_aout->output.pf_volume_get( p_aout, pi_volume );
...@@ -87,7 +87,7 @@ int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume ) ...@@ -87,7 +87,7 @@ int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume )
{ {
*pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" ); *pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" );
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
vlc_object_release( p_aout ); vlc_object_release( p_aout );
return i_result; return i_result;
...@@ -109,12 +109,12 @@ int __aout_VolumeSet( vlc_object_t * p_object, audio_volume_t i_volume ) ...@@ -109,12 +109,12 @@ int __aout_VolumeSet( vlc_object_t * p_object, audio_volume_t i_volume )
if ( p_aout == NULL ) return 0; if ( p_aout == NULL ) return 0;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( !p_aout->mixer.b_error ) if ( !p_aout->mixer.b_error )
{ {
i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); i_result = p_aout->output.pf_volume_set( p_aout, i_volume );
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
var_Set( p_aout, "intf-change", val ); var_Set( p_aout, "intf-change", val );
vlc_object_release( p_aout ); vlc_object_release( p_aout );
...@@ -132,7 +132,7 @@ int __aout_VolumeInfos( vlc_object_t * p_object, audio_volume_t * pi_soft ) ...@@ -132,7 +132,7 @@ int __aout_VolumeInfos( vlc_object_t * p_object, audio_volume_t * pi_soft )
if ( p_aout == NULL ) return 0; if ( p_aout == NULL ) return 0;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( p_aout->mixer.b_error ) if ( p_aout->mixer.b_error )
{ {
/* The output module is destroyed. */ /* The output module is destroyed. */
...@@ -142,7 +142,7 @@ int __aout_VolumeInfos( vlc_object_t * p_object, audio_volume_t * pi_soft ) ...@@ -142,7 +142,7 @@ int __aout_VolumeInfos( vlc_object_t * p_object, audio_volume_t * pi_soft )
{ {
i_result = p_aout->output.pf_volume_infos( p_aout, pi_soft ); i_result = p_aout->output.pf_volume_infos( p_aout, pi_soft );
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
vlc_object_release( p_aout ); vlc_object_release( p_aout );
return i_result; return i_result;
...@@ -180,13 +180,13 @@ int __aout_VolumeUp( vlc_object_t * p_object, int i_nb_steps, ...@@ -180,13 +180,13 @@ int __aout_VolumeUp( vlc_object_t * p_object, int i_nb_steps,
if ( p_aout == NULL ) return 0; if ( p_aout == NULL ) return 0;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( !p_aout->mixer.b_error ) if ( !p_aout->mixer.b_error )
{ {
i_result = p_aout->output.pf_volume_set( p_aout, i_result = p_aout->output.pf_volume_set( p_aout,
(audio_volume_t) i_volume ); (audio_volume_t) i_volume );
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
vlc_object_release( p_aout ); vlc_object_release( p_aout );
return i_result; return i_result;
...@@ -223,12 +223,12 @@ int __aout_VolumeDown( vlc_object_t * p_object, int i_nb_steps, ...@@ -223,12 +223,12 @@ int __aout_VolumeDown( vlc_object_t * p_object, int i_nb_steps,
if ( p_aout == NULL ) return 0; if ( p_aout == NULL ) return 0;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( !p_aout->mixer.b_error ) if ( !p_aout->mixer.b_error )
{ {
i_result = p_aout->output.pf_volume_set( p_aout, (audio_volume_t) i_volume ); i_result = p_aout->output.pf_volume_set( p_aout, (audio_volume_t) i_volume );
} }
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
vlc_object_release( p_aout ); vlc_object_release( p_aout );
return i_result; return i_result;
...@@ -369,21 +369,21 @@ static int aout_Restart( aout_instance_t * p_aout ) ...@@ -369,21 +369,21 @@ static int aout_Restart( aout_instance_t * p_aout )
int i; int i;
bool b_error = 0; bool b_error = 0;
vlc_mutex_lock( &p_aout->mixer_lock ); aout_lock_mixer( p_aout );
if ( p_aout->i_nb_inputs == 0 ) if ( p_aout->i_nb_inputs == 0 )
{ {
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
msg_Err( p_aout, "no decoder thread" ); msg_Err( p_aout, "no decoder thread" );
return -1; return -1;
} }
/* Lock all inputs. */ /* Lock all inputs. */
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
for ( i = 0; i < p_aout->i_nb_inputs; i++ ) for ( i = 0; i < p_aout->i_nb_inputs; i++ )
{ {
vlc_mutex_lock( &p_aout->pp_inputs[i]->lock ); aout_lock_input( p_aout, p_aout->pp_inputs[i] );
aout_InputDelete( p_aout, p_aout->pp_inputs[i] ); aout_InputDelete( p_aout, p_aout->pp_inputs[i] );
} }
...@@ -399,8 +399,8 @@ static int aout_Restart( aout_instance_t * p_aout ) ...@@ -399,8 +399,8 @@ static int aout_Restart( aout_instance_t * p_aout )
{ {
vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock ); vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock );
} }
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return -1; return -1;
} }
...@@ -411,8 +411,8 @@ static int aout_Restart( aout_instance_t * p_aout ) ...@@ -411,8 +411,8 @@ static int aout_Restart( aout_instance_t * p_aout )
{ {
vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock ); vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock );
} }
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return -1; return -1;
} }
...@@ -420,14 +420,13 @@ static int aout_Restart( aout_instance_t * p_aout ) ...@@ -420,14 +420,13 @@ static int aout_Restart( aout_instance_t * p_aout )
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];
b_error |= aout_InputNew( p_aout, p_input ); b_error |= aout_InputNew( p_aout, p_input );
p_input->b_changed = 1; p_input->b_changed = 1;
vlc_mutex_unlock( &p_input->lock ); aout_unlock_input( p_aout, p_input );
} }
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock ); aout_unlock_mixer( p_aout );
return b_error; return b_error;
} }
......
...@@ -80,7 +80,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -80,7 +80,7 @@ static int MixBuffer( aout_instance_t * p_aout )
if ( p_aout->mixer.b_error ) if ( p_aout->mixer.b_error )
{ {
/* Free all incoming buffers. */ /* Free all incoming buffers. */
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
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];
...@@ -93,13 +93,13 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -93,13 +93,13 @@ static int MixBuffer( aout_instance_t * p_aout )
p_buffer = p_next; p_buffer = p_next;
} }
} }
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
return -1; return -1;
} }
vlc_mutex_lock( &p_aout->output_fifo_lock ); aout_lock_output_fifo( p_aout );
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
/* Retrieve the date of the next buffer. */ /* Retrieve the date of the next buffer. */
memcpy( &exact_start_date, &p_aout->output.fifo.end_date, memcpy( &exact_start_date, &p_aout->output.fifo.end_date,
...@@ -118,7 +118,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -118,7 +118,7 @@ static int MixBuffer( aout_instance_t * p_aout )
start_date = 0; start_date = 0;
} }
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
/* See if we have enough data to prepare a new buffer for the audio /* See if we have enough data to prepare a new buffer for the audio
* output. First : start date. */ * output. First : start date. */
...@@ -164,7 +164,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -164,7 +164,7 @@ static int MixBuffer( aout_instance_t * p_aout )
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->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
return -1; return -1;
} }
} }
...@@ -287,10 +287,10 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -287,10 +287,10 @@ static int MixBuffer( aout_instance_t * p_aout )
if( i_nb_bytes < 0 ) if( i_nb_bytes < 0 )
{ {
/* Is it really the best way to do it ? */ /* Is it really the best way to do it ? */
vlc_mutex_lock( &p_aout->output_fifo_lock ); aout_lock_output_fifo( p_aout );
aout_FifoSet( p_aout, &p_aout->output.fifo, 0 ); aout_FifoSet( p_aout, &p_aout->output.fifo, 0 );
aout_DateSet( &exact_start_date, 0 ); aout_DateSet( &exact_start_date, 0 );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
break; break;
} }
...@@ -302,7 +302,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -302,7 +302,7 @@ static int MixBuffer( aout_instance_t * p_aout )
if ( i < p_aout->i_nb_inputs || i_first_input == p_aout->i_nb_inputs ) if ( i < p_aout->i_nb_inputs || i_first_input == 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->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
return -1; return -1;
} }
...@@ -316,7 +316,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -316,7 +316,7 @@ static int MixBuffer( aout_instance_t * p_aout )
p_output_buffer ); p_output_buffer );
if ( p_output_buffer == NULL ) if ( p_output_buffer == NULL )
{ {
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
return -1; return -1;
} }
/* This is again a bit kludgy - for the S/PDIF mixer. */ /* This is again a bit kludgy - for the S/PDIF mixer. */
...@@ -332,7 +332,7 @@ static int MixBuffer( aout_instance_t * p_aout ) ...@@ -332,7 +332,7 @@ static int MixBuffer( aout_instance_t * p_aout )
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->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
aout_OutputPlay( p_aout, p_output_buffer ); aout_OutputPlay( p_aout, p_output_buffer );
......
...@@ -51,14 +51,14 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -51,14 +51,14 @@ int aout_OutputNew( aout_instance_t * p_aout,
p_aout->output.output.i_rate = i_rate; p_aout->output.output.i_rate = i_rate;
aout_FormatPrepare( &p_aout->output.output ); aout_FormatPrepare( &p_aout->output.output );
vlc_mutex_lock( &p_aout->output_fifo_lock ); aout_lock_output_fifo( p_aout );
/* Find the best output plug-in. */ /* Find the best output plug-in. */
p_aout->output.p_module = module_Need( p_aout, "audio output", "$aout", 0); p_aout->output.p_module = module_Need( p_aout, "audio output", "$aout", 0);
if ( p_aout->output.p_module == NULL ) if ( p_aout->output.p_module == NULL )
{ {
msg_Err( p_aout, "no suitable audio output module" ); msg_Err( p_aout, "no suitable audio output module" );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
return -1; return -1;
} }
...@@ -165,7 +165,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -165,7 +165,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
aout_FifoInit( p_aout, &p_aout->output.fifo, aout_FifoInit( p_aout, &p_aout->output.fifo,
p_aout->output.output.i_rate ); p_aout->output.output.i_rate );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
aout_FormatPrint( p_aout, "output", &p_aout->output.output ); aout_FormatPrint( p_aout, "output", &p_aout->output.output );
...@@ -232,9 +232,9 @@ void aout_OutputDelete( aout_instance_t * p_aout ) ...@@ -232,9 +232,9 @@ void aout_OutputDelete( aout_instance_t * p_aout )
aout_FiltersDestroyPipeline( p_aout, p_aout->output.pp_filters, aout_FiltersDestroyPipeline( p_aout, p_aout->output.pp_filters,
p_aout->output.i_nb_filters ); p_aout->output.i_nb_filters );
vlc_mutex_lock( &p_aout->output_fifo_lock ); aout_lock_output_fifo( p_aout );
aout_FifoDestroy( p_aout, &p_aout->output.fifo ); aout_FifoDestroy( p_aout, &p_aout->output.fifo );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
p_aout->output.b_error = true; p_aout->output.b_error = true;
} }
...@@ -256,10 +256,10 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer ) ...@@ -256,10 +256,10 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
return; return;
} }
vlc_mutex_lock( &p_aout->output_fifo_lock ); aout_lock_output_fifo( p_aout );
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 );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
} }
/***************************************************************************** /*****************************************************************************
...@@ -276,7 +276,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -276,7 +276,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 ); aout_lock_output_fifo( p_aout );
p_buffer = p_aout->output.fifo.p_first; p_buffer = p_aout->output.fifo.p_first;
...@@ -310,7 +310,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -310,7 +310,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
p_aout->output.b_starving = 1; p_aout->output.b_starving = 1;
#endif #endif
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
return NULL; return NULL;
} }
...@@ -327,7 +327,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -327,7 +327,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
*/ */
{ {
const mtime_t i_delta = p_buffer->start_date - start_date; const mtime_t i_delta = p_buffer->start_date - start_date;
vlc_mutex_unlock( &p_aout->output_fifo_lock ); aout_unlock_output_fifo( p_aout );
if ( !p_aout->output.b_starving ) if ( !p_aout->output.b_starving )
msg_Dbg( p_aout, "audio output is starving (%"PRId64"), " msg_Dbg( p_aout, "audio output is starving (%"PRId64"), "
...@@ -348,7 +348,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -348,7 +348,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
msg_Warn( p_aout, "output date isn't PTS date, requesting " msg_Warn( p_aout, "output date isn't PTS date, requesting "
"resampling (%"PRId64")", difference ); "resampling (%"PRId64")", difference );
vlc_mutex_lock( &p_aout->input_fifos_lock ); aout_lock_input_fifos( p_aout );
for ( i = 0; i < p_aout->i_nb_inputs; i++ ) for ( i = 0; i < p_aout->i_nb_inputs; i++ )
{ {
aout_fifo_t * p_fifo = &p_aout->pp_inputs[i]->fifo; aout_fifo_t * p_fifo = &p_aout->pp_inputs[i]->fifo;
...@@ -357,7 +357,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -357,7 +357,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
} }
aout_FifoMoveDates( p_aout, &p_aout->output.fifo, difference ); aout_FifoMoveDates( p_aout, &p_aout->output.fifo, difference );
vlc_mutex_unlock( &p_aout->input_fifos_lock ); aout_unlock_input_fifos( p_aout );
} }
p_aout->output.fifo.p_first = p_buffer->p_next; p_aout->output.fifo.p_first = p_buffer->p_next;
...@@ -366,6 +366,6 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout, ...@@ -366,6 +366,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 ); aout_unlock_output_fifo( p_aout );
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