[vlc-commits] sout: transcode: add mutex on cross id ressource
Francois Cartegnie
git at videolan.org
Tue Aug 27 14:50:54 CEST 2019
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Aug 26 16:10:56 2019 +0200| [6a63336a0b01a1b4c3ac9e8aff10473c5c9ee474] | committer: Francois Cartegnie
sout: transcode: add mutex on cross id ressource
not thread safe on deletion
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6a63336a0b01a1b4c3ac9e8aff10473c5c9ee474
---
modules/stream_out/transcode/transcode.c | 35 ++++++++++++++++++++++++--------
modules/stream_out/transcode/transcode.h | 6 ++++--
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
index 9dfb4a2c05..4b5fc230e5 100644
--- a/modules/stream_out/transcode/transcode.c
+++ b/modules/stream_out/transcode/transcode.c
@@ -463,6 +463,7 @@ static int Open( vlc_object_t *p_this )
/* Set default size for TEXT spu non overlay conversion / updater */
p_sys->senc_cfg.spu.i_width = (p_sys->venc_cfg.video.i_width) ? p_sys->venc_cfg.video.i_width : 1280;
p_sys->senc_cfg.spu.i_height = (p_sys->venc_cfg.video.i_height) ? p_sys->venc_cfg.video.i_height : 720;
+ vlc_mutex_init( &p_sys->lock );
p_stream->pf_add = Add;
p_stream->pf_del = Del;
@@ -489,6 +490,8 @@ static void Close( vlc_object_t * p_this )
transcode_encoder_config_clean( &p_sys->senc_cfg );
+ vlc_mutex_destroy( &p_sys->lock );
+
free( p_sys );
}
@@ -505,32 +508,38 @@ static void SendSpuToVideoCallback( void *cbdata, subpicture_t *p_subpicture )
{
sout_stream_t *p_stream = cbdata;
sout_stream_sys_t *p_sys = p_stream->p_sys;
+ vlc_mutex_lock( &p_sys->lock );
if( !p_sys->id_video )
subpicture_Delete( p_subpicture );
else
transcode_video_push_spu( p_stream,
p_sys->id_video, p_subpicture );
+ vlc_mutex_unlock( &p_sys->lock );
}
static int GetVideoDimensions( void *cbdata, unsigned *w, unsigned *h )
{
sout_stream_t *p_stream = cbdata;
sout_stream_sys_t *p_sys = p_stream->p_sys;
- if( !p_sys->id_video )
- return VLC_EGENERIC;
- return transcode_video_get_output_dimensions( p_stream,
- p_sys->id_video, w, h );
+ int i_ret = VLC_EGENERIC;
+ vlc_mutex_lock( &p_sys->lock );
+ if( p_sys->id_video )
+ i_ret = transcode_video_get_output_dimensions( p_stream,
+ p_sys->id_video, w, h );
+ vlc_mutex_unlock( &p_sys->lock );
+ return i_ret;
}
static vlc_tick_t GetMasterDrift( void *cbdata )
{
sout_stream_t *p_stream = cbdata;
sout_stream_sys_t *p_sys = p_stream->p_sys;
+ vlc_mutex_lock( &p_sys->lock );
+ vlc_tick_t drift = 0;
if( p_sys->id_master_sync )
- {
- return p_sys->id_master_sync->i_drift;
- }
- return 0;
+ drift = p_sys->id_master_sync->i_drift;
+ vlc_mutex_unlock( &p_sys->lock );
+ return drift;
}
static int ValidateDrift( void *cbdata, vlc_tick_t i_drift )
@@ -630,14 +639,18 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
if( p_fmt->i_cat == AUDIO_ES && id->p_enccfg->i_codec )
{
success = !transcode_audio_init(p_stream, p_fmt, id);
+ vlc_mutex_lock( &p_sys->lock );
if( success && p_sys->b_master_sync && !p_sys->id_master_sync )
p_sys->id_master_sync = id;
+ vlc_mutex_unlock( &p_sys->lock );
}
else if( p_fmt->i_cat == VIDEO_ES && id->p_enccfg->i_codec )
{
success = !transcode_video_init(p_stream, p_fmt, id);
+ vlc_mutex_lock( &p_sys->lock );
if( success && !p_sys->id_video )
p_sys->id_video = id;
+ vlc_mutex_unlock( &p_sys->lock );
}
else if( ( p_fmt->i_cat == SPU_ES ) &&
( id->p_enccfg->i_codec || p_sys->b_soverlay ) )
@@ -676,15 +689,19 @@ static void Del( sout_stream_t *p_stream, void *_id )
case AUDIO_ES:
Send( p_stream, id, NULL );
decoder_Destroy( id->p_decoder );
- transcode_audio_clean( p_stream, id );
+ vlc_mutex_lock( &p_sys->lock );
if( id == p_sys->id_master_sync )
p_sys->id_master_sync = NULL;
+ vlc_mutex_unlock( &p_sys->lock );
+ transcode_audio_clean( p_stream, id );
break;
case VIDEO_ES:
Send( p_stream, id, NULL );
decoder_Destroy( id->p_decoder );
+ vlc_mutex_lock( &p_sys->lock );
if( id == p_sys->id_video )
p_sys->id_video = NULL;
+ vlc_mutex_unlock( &p_sys->lock );
transcode_video_clean( p_stream, id );
break;
case SPU_ES:
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index adb2b635f8..0cce7eea97 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -42,8 +42,6 @@ typedef struct sout_stream_id_sys_t sout_stream_id_sys_t;
typedef struct
{
- sout_stream_id_sys_t *id_video;
-
bool b_soverlay;
/* Audio */
@@ -57,9 +55,13 @@ typedef struct
/* SPU */
transcode_encoder_config_t senc_cfg;
+ /* Shared betweeen streams */
+ vlc_mutex_t lock;
/* Sync */
bool b_master_sync;
sout_stream_id_sys_t *id_master_sync;
+ /* Spu's video */
+ sout_stream_id_sys_t *id_video;
} sout_stream_sys_t;
More information about the vlc-commits
mailing list