[vlc-commits] [Git][videolan/vlc][master] decoder: fix aout_stream_NotifyLatency data-races
Thomas Guillem (@tguillem)
gitlab at videolan.org
Fri Aug 12 06:04:22 UTC 2022
Thomas Guillem pushed to branch master at VideoLAN / VLC
Commits:
839dee68 by Thomas Guillem at 2022-08-12T05:44:30+00:00
decoder: fix aout_stream_NotifyLatency data-races
Fixes #27204
- - - - -
1 changed file:
- src/input/decoder.c
Changes:
=====================================
src/input/decoder.c
=====================================
@@ -132,6 +132,7 @@ struct vlc_input_decoder_t
/* If p_aout is valid, then p_astream is valid too */
audio_output_t *p_aout;
vlc_aout_stream *p_astream;
+ bool b_astream_update_latency;
vout_thread_t *p_vout;
bool vout_started;
@@ -270,6 +271,7 @@ static int DecoderThread_Reload( vlc_input_decoder_t *p_owner,
// no need to lock, the decoder and ModuleThread are dead
p_owner->p_aout = NULL;
p_owner->p_astream = NULL;
+ p_owner->b_astream_update_latency = false;
if( p_aout )
{
assert( p_astream );
@@ -343,7 +345,12 @@ static void aout_stream_NotifyLatency(void *data)
{
/* Wake the DecoderThread in order to update the audio latency via
* vlc_aout_stream_UpdateLatency() */
- vlc_fifo_Signal(data);
+ vlc_input_decoder_t *owner = data;
+
+ vlc_fifo_Lock(owner->p_fifo);
+ owner->b_astream_update_latency = true;
+ vlc_fifo_Signal(owner->p_fifo);
+ vlc_fifo_Unlock(owner->p_fifo);
}
static int ModuleThread_UpdateAudioFormat( decoder_t *p_dec )
@@ -362,6 +369,7 @@ static int ModuleThread_UpdateAudioFormat( decoder_t *p_dec )
vlc_mutex_lock( &p_owner->lock );
p_owner->p_astream = NULL;
p_owner->p_aout = NULL; // the DecoderThread should not use the old aout anymore
+ p_owner->b_astream_update_latency = false;
vlc_mutex_unlock( &p_owner->lock );
vlc_aout_stream_Delete( p_astream );
@@ -410,7 +418,7 @@ static int ModuleThread_UpdateAudioFormat( decoder_t *p_dec )
.str_id = p_owner->psz_id,
.replay_gain = &p_dec->fmt_out.audio_replay_gain,
.notify_latency_cb = aout_stream_NotifyLatency,
- .notify_latency_data = p_owner->p_fifo,
+ .notify_latency_data = p_owner,
};
p_astream = vlc_aout_stream_New( p_aout, &cfg );
if( p_astream == NULL )
@@ -1620,6 +1628,20 @@ static void DecoderThread_ChangeRate( vlc_input_decoder_t *p_owner, float rate )
vlc_mutex_unlock( &p_owner->lock );
}
+static void DecoderThread_UpdateAudioLatency( vlc_input_decoder_t *p_owner )
+{
+ decoder_t *p_dec = &p_owner->dec;
+
+ /* Update the audio latency after a possible long wait in order to update
+ * the audio clock as soon as possible. */
+ assert( p_dec->fmt_in.i_cat == AUDIO_ES );
+
+ vlc_mutex_lock( &p_owner->lock );
+ if( p_owner->p_astream != NULL )
+ vlc_aout_stream_UpdateLatency( p_owner->p_astream );
+ vlc_mutex_unlock( &p_owner->lock );
+}
+
static void DecoderThread_ChangeDelay( vlc_input_decoder_t *p_owner, vlc_tick_t delay )
{
decoder_t *p_dec = &p_owner->dec;
@@ -1726,6 +1748,16 @@ static void *DecoderThread( void *p_data )
continue;
}
+ if( p_owner->b_astream_update_latency )
+ {
+ vlc_fifo_Unlock( p_owner->p_fifo );
+
+ DecoderThread_UpdateAudioLatency( p_owner );
+
+ vlc_fifo_Lock( p_owner->p_fifo );
+ p_owner->b_astream_update_latency = false;
+ }
+
if( rate != p_owner->request_rate )
{
rate = p_owner->request_rate;
@@ -1767,13 +1799,6 @@ static void *DecoderThread( void *p_data )
p_owner->b_idle = true;
vlc_cond_signal( &p_owner->wait_acknowledge );
vlc_fifo_Wait( p_owner->p_fifo );
-
- /* Update the audio latency after a possible long wait in order
- * to update the audio clock as soon as possible. */
- if( p_owner->dec.fmt_in.i_cat == AUDIO_ES &&
- p_owner->p_astream != NULL )
- vlc_aout_stream_UpdateLatency( p_owner->p_astream );
-
p_owner->b_idle = false;
continue;
}
@@ -1877,6 +1902,7 @@ CreateDecoder( vlc_object_t *p_parent, const struct vlc_input_decoder_cfg *cfg )
p_owner->cbs_userdata = cfg->cbs_data;
p_owner->p_aout = NULL;
p_owner->p_astream = NULL;
+ p_owner->b_astream_update_latency = false;
p_owner->p_vout = NULL;
p_owner->vout_started = false;
p_owner->i_spu_channel = VOUT_SPU_CHANNEL_INVALID;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/839dee68cacef9bf6af57b71af40e415f98362ce
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/839dee68cacef9bf6af57b71af40e415f98362ce
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list