[vlc-commits] transcode: video: use local master condition instead of global boolean
Francois Cartegnie
git at videolan.org
Mon Jul 9 16:15:55 CEST 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Jul 6 13:18:40 2018 +0200| [80027c016d1de666b0199c9daeaafea7ec958d79] | committer: Francois Cartegnie
transcode: video: use local master condition instead of global boolean
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=80027c016d1de666b0199c9daeaafea7ec958d79
---
modules/stream_out/transcode/audio.c | 18 +++++-------
modules/stream_out/transcode/spu.c | 22 ++++++++++----
modules/stream_out/transcode/transcode.c | 49 +++++++++++++++++++++++++++++++-
modules/stream_out/transcode/transcode.h | 20 +++++++++----
modules/stream_out/transcode/video.c | 23 +++++++++++----
5 files changed, 105 insertions(+), 27 deletions(-)
diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index e12ac8033e..2f7f22777b 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -365,7 +365,6 @@ int transcode_audio_process( sout_stream_t *p_stream,
sout_stream_id_sys_t *id,
block_t *in, block_t **out )
{
- sout_stream_sys_t *p_sys = p_stream->p_sys;
*out = NULL;
int ret = id->p_decoder->pf_decode( id->p_decoder, in );
@@ -433,25 +432,22 @@ int transcode_audio_process( sout_stream_t *p_stream,
vlc_mutex_unlock(&id->fifo.lock);
- if( p_sys->b_master_sync )
+ if( id->pf_drift_validate )
{
vlc_tick_t i_pts = date_Get( &id->next_input_pts );
vlc_tick_t i_drift = 0;
if( likely( p_audio_buf->i_pts != VLC_TICK_INVALID ) )
i_drift = p_audio_buf->i_pts - i_pts;
-
- if ( unlikely(i_drift > MASTER_SYNC_MAX_DRIFT
- || i_drift < -MASTER_SYNC_MAX_DRIFT) )
+ if( id->pf_drift_validate( id->callback_data, i_drift ) != VLC_SUCCESS )
{
- msg_Dbg( p_stream,
- "audio drift is too high (%"PRId64"), resetting master sync",
- i_drift );
date_Set( &id->next_input_pts, p_audio_buf->i_pts );
- if( likely(p_audio_buf->i_pts != VLC_TICK_INVALID ) )
- i_drift = 0;
+ i_drift = 0;
}
- p_sys->i_master_drift = i_drift;
+
+ vlc_mutex_lock(&id->fifo.lock);
+ id->i_drift = i_drift;
+ vlc_mutex_unlock(&id->fifo.lock);
date_Increment( &id->next_input_pts, p_audio_buf->i_nb_samples );
}
diff --git a/modules/stream_out/transcode/spu.c b/modules/stream_out/transcode/spu.c
index f13789cc7c..9bd09e18c4 100644
--- a/modules/stream_out/transcode/spu.c
+++ b/modules/stream_out/transcode/spu.c
@@ -181,10 +181,13 @@ int transcode_spu_process( sout_stream_t *p_stream,
continue;
}
- if( p_sys->b_master_sync && p_sys->i_master_drift )
+ vlc_tick_t drift;
+ if( id->pf_get_master_drift &&
+ (drift = id->pf_get_master_drift( id->callback_data )) )
{
- p_subpic->i_start -= p_sys->i_master_drift;
- if( p_subpic->i_stop ) p_subpic->i_stop -= p_sys->i_master_drift;
+ p_subpic->i_start -= drift;
+ if( p_subpic->i_stop )
+ p_subpic->i_stop -= drift;
}
if( p_sys->b_soverlay )
@@ -203,13 +206,22 @@ int transcode_spu_process( sout_stream_t *p_stream,
es_format_t fmt;
es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_TEXT );
+ unsigned w, h;
+ if( id->pf_get_output_dimensions == NULL ||
+ id->pf_get_output_dimensions( id->callback_data,
+ &w, &h ) != VLC_SUCCESS )
+ {
+ w = id->p_enccfg->spu.i_width;
+ h = id->p_enccfg->spu.i_height;
+ }
+
fmt.video.i_sar_num =
fmt.video.i_visible_width =
- fmt.video.i_width = id->p_enccfg->spu.i_width;
+ fmt.video.i_width = w;
fmt.video.i_sar_den =
fmt.video.i_visible_height =
- fmt.video.i_height =id->p_enccfg->spu.i_height;
+ fmt.video.i_height = h;
subpicture_Update( p_subpic, &fmt.video, &fmt.video, p_subpic->i_start );
es_format_Clean( &fmt );
diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
index 58de27486c..2f45bc4b07 100644
--- a/modules/stream_out/transcode/transcode.c
+++ b/modules/stream_out/transcode/transcode.c
@@ -372,7 +372,6 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
p_sys = calloc( 1, sizeof( *p_sys ) );
- p_sys->i_master_drift = 0;
config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
p_stream->p_cfg );
@@ -504,6 +503,40 @@ static void SendSpuToVideoCallback( void *cbdata, subpicture_t *p_subpicture )
p_sys->id_video, p_subpicture );
}
+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 );
+}
+
+static vlc_tick_t GetMasterDrift( void *cbdata )
+{
+ sout_stream_t *p_stream = cbdata;
+ sout_stream_sys_t *p_sys = p_stream->p_sys;
+ if( p_sys->id_master_sync )
+ {
+ return p_sys->id_master_sync->i_drift;
+ }
+ return 0;
+}
+
+static int ValidateDrift( void *cbdata, vlc_tick_t i_drift )
+{
+ sout_stream_t *p_stream = cbdata;
+ if( unlikely(i_drift > MASTER_SYNC_MAX_DRIFT ||
+ i_drift < -MASTER_SYNC_MAX_DRIFT) )
+ {
+ msg_Dbg( p_stream, "drift is too high (%"PRId64"), resetting master sync",
+ i_drift );
+ return VLC_EGENERIC;
+ }
+ return VLC_SUCCESS;
+}
+
static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
@@ -535,6 +568,11 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
case AUDIO_ES:
id->p_filterscfg = &p_sys->afilters_cfg;
id->p_enccfg = &p_sys->aenc_cfg;
+ if( p_sys->b_master_sync )
+ {
+ id->pf_drift_validate = ValidateDrift;
+ id->callback_data = p_sys;
+ }
break;
case VIDEO_ES:
id->p_filterscfg = &p_sys->vfilters_cfg;
@@ -544,6 +582,9 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
id->p_filterscfg = NULL;
id->p_enccfg = &p_sys->senc_cfg;
id->pf_send_subpicture = SendSpuToVideoCallback;
+ id->pf_get_output_dimensions = GetVideoDimensions;
+ if( p_sys->b_master_sync )
+ id->pf_get_master_drift = GetMasterDrift;
id->callback_data = p_stream;
break;
default:
@@ -570,7 +611,11 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
bool success;
if( p_fmt->i_cat == AUDIO_ES && id->p_enccfg->i_codec )
+ {
success = transcode_audio_add(p_stream, p_fmt, id);
+ if( success && p_sys->b_master_sync && !p_sys->id_master_sync )
+ p_sys->id_master_sync = id;
+ }
else if( p_fmt->i_cat == VIDEO_ES && id->p_enccfg->i_codec )
{
success = transcode_video_add(p_stream, p_fmt, id);
@@ -611,6 +656,8 @@ static void Del( sout_stream_t *p_stream, void *_id )
case AUDIO_ES:
Send( p_stream, id, NULL );
transcode_audio_close( id );
+ if( id == p_sys->id_master_sync )
+ p_sys->id_master_sync = NULL;
break;
case VIDEO_ES:
Send( p_stream, id, NULL );
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index d63aeccb75..aa57356d30 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -110,8 +110,8 @@ typedef struct
/* Sync */
bool b_master_sync;
- /* i_master drift is how much audio buffer is ahead of calculated pts */
- vlc_tick_t i_master_drift;
+ sout_stream_id_sys_t *id_master_sync;
+
} sout_stream_sys_t;
struct aout_filters;
@@ -149,7 +149,16 @@ struct sout_stream_id_sys_t
union
{
- void (*pf_send_subpicture)(void *cbdata, subpicture_t *);
+ struct
+ {
+ int (*pf_drift_validate)(void *cbdata, vlc_tick_t);
+ };
+ struct
+ {
+ void (*pf_send_subpicture)(void *cbdata, subpicture_t *);
+ int (*pf_get_output_dimensions)(void *cbdata, unsigned *, unsigned *);
+ vlc_tick_t (*pf_get_master_drift)(void *cbdata);
+ };
};
void *callback_data;
@@ -189,8 +198,7 @@ struct sout_stream_id_sys_t
/* Sync */
date_t next_input_pts; /**< Incoming calculated PTS */
- date_t next_output_pts; /**< output calculated PTS */
-
+ vlc_tick_t i_drift; /** how much buffer is ahead of calculated PTS */
};
struct decoder_owner
@@ -225,6 +233,8 @@ bool transcode_audio_add ( sout_stream_t *, const es_format_t *,
void transcode_video_close ( sout_stream_t *, sout_stream_id_sys_t * );
int transcode_video_process( sout_stream_t *, sout_stream_id_sys_t *,
block_t *, block_t ** );
+int transcode_video_get_output_dimensions( sout_stream_t *, sout_stream_id_sys_t *,
+ unsigned *w, unsigned *h );
void transcode_video_push_spu( sout_stream_t *, sout_stream_id_sys_t *, subpicture_t * );
bool transcode_video_add ( sout_stream_t *, const es_format_t *,
sout_stream_id_sys_t *);
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 442c3fab0c..d20223d51d 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -745,6 +745,22 @@ void transcode_video_push_spu( sout_stream_t *p_stream, sout_stream_id_sys_t *id
spu_PutSubpicture( id->p_spu, p_subpicture );
}
+int transcode_video_get_output_dimensions( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
+ unsigned *w, unsigned *h )
+{
+ VLC_UNUSED(p_stream);
+ vlc_mutex_lock( &id->fifo.lock );
+ *w = id->fmt_input_video.i_visible_width;
+ *h = id->fmt_input_video.i_visible_height;
+ if( !*w || !*h )
+ {
+ *w = id->video_dec_out.i_visible_width;
+ *h = id->video_dec_out.i_visible_height;
+ }
+ vlc_mutex_unlock( &id->fifo.lock );
+ return (*w && *h) ? VLC_SUCCESS : VLC_EGENERIC;
+}
+
static picture_t * RenderSubpictures( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
picture_t *p_pic )
{
@@ -822,7 +838,6 @@ static block_t * EncodeFrame( sout_stream_t *p_stream, picture_t *p_pic, sout_st
int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
block_t *in, block_t **out )
{
- sout_stream_sys_t *p_sys = p_stream->p_sys;
*out = NULL;
int ret = id->p_decoder->pf_decode( id->p_decoder, in );
@@ -880,13 +895,11 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
video_format_Copy( &id->fmt_input_video, &p_pic->format );
- transcode_video_filter_init( p_stream, id->p_filterscfg, p_sys->b_master_sync, id );
+ transcode_video_filter_init( p_stream, id->p_filterscfg,
+ (id->p_enccfg->video.fps.num > 0), id );
if( conversion_video_filter_append( id, p_pic ) != VLC_SUCCESS )
goto error;
- p_sys->senc_cfg.spu.i_width = p_pic->format.i_visible_width;
- p_sys->senc_cfg.spu.i_height = p_pic->format.i_visible_height;
-
/* Start missing encoder */
if( id->p_encoder->p_module == NULL &&
transcode_video_encoder_open( p_stream, id ) != VLC_SUCCESS )
More information about the vlc-commits
mailing list