[vlc-devel] [PATCH 4/5] input: handle "sub-fps" with a new control
Thomas Guillem
thomas at gllm.fr
Wed Oct 17 15:32:58 CEST 2018
We now change the slave demux rate according to the requested subtitle fps and
the main demuxer fps.
Example: Video is 24fps but the subtitle is 26fps. In that case, we want to
slow down the subtitle demuxer. Setting "sub-fps" to 26 will change the rate
of the subtitle demuxer to 0.92.
---
src/input/input.c | 32 ++++++++++++++++++++++++++++++++
src/input/input_internal.h | 3 +++
2 files changed, 35 insertions(+)
diff --git a/src/input/input.c b/src/input/input.c
index 0595b8e73a..995287c56f 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -996,6 +996,16 @@ static bool SlaveExists( input_item_slave_t **pp_slaves, int i_slaves,
return false;
}
+static void SlaveRequestNewRate( input_thread_t *p_input, float f_slave_fps )
+{
+ input_thread_private_t *priv = input_priv(p_input);
+ const float f_fps = input_priv(p_input)->master->f_fps;
+ if( f_fps > 1.f && f_slave_fps > 1.f )
+ priv->i_slaves_requested_rate = INPUT_RATE_DEFAULT / ( f_fps / f_slave_fps );
+ else if ( priv->i_slaves_rate != 0 )
+ priv->i_slaves_requested_rate = INPUT_RATE_DEFAULT;
+}
+
static void SetSubtitlesOptions( input_thread_t *p_input )
{
input_thread_private_t *priv = input_priv(p_input);
@@ -1005,6 +1015,7 @@ static void SetSubtitlesOptions( input_thread_t *p_input )
if( f_fps > 1.f )
{
var_SetFloat( p_input, "sub-original-fps", f_fps );
+ SlaveRequestNewRate( p_input, var_InheritFloat( p_input, "sub-fps" ) );
}
int64_t sub_delay = var_InheritInteger( p_input, "sub-delay" );
@@ -2229,6 +2240,9 @@ static bool Control( input_thread_t *p_input,
}
}
break;
+ case INPUT_CONTROL_SET_SLAVE_FPS:
+ SlaveRequestNewRate( p_input, param.val.f_float );
+ break;
case INPUT_CONTROL_SET_RECORD_STATE:
val = param.val;
@@ -2846,6 +2860,7 @@ static void InputSourceMeta( input_thread_t *p_input,
static void SlaveDemux( input_thread_t *p_input )
{
+ input_thread_private_t *priv = input_priv(p_input);
vlc_tick_t i_time;
int i;
@@ -2863,6 +2878,17 @@ static void SlaveDemux( input_thread_t *p_input )
if( in->b_eof )
continue;
+ if( priv->i_slaves_requested_rate != 0
+ && priv->i_slaves_requested_rate != priv->i_slaves_rate
+ && in->b_can_rate_control )
+ {
+ if( priv->i_slaves_rate != 0 ) /* Don't reset when it's the first time */
+ es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
+ int i_new_rate = priv->i_slaves_requested_rate;
+ demux_Control( in->p_demux, DEMUX_SET_RATE, &i_new_rate );
+
+ }
+
/* Call demux_Demux until we have read enough data */
if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
{
@@ -2898,6 +2924,12 @@ static void SlaveDemux( input_thread_t *p_input )
in->b_eof = true;
}
}
+
+ if( priv->i_slaves_requested_rate != 0 )
+ {
+ priv->i_slaves_rate = priv->i_slaves_requested_rate;
+ priv->i_slaves_requested_rate = 0;
+ }
}
static void SlaveSeek( input_thread_t *p_input )
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index bcc8f06a91..a5b536f152 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -175,6 +175,8 @@ typedef struct input_thread_private_t
/* Slave sources (subs, and others) */
int i_slave;
input_source_t **slave;
+ unsigned i_slaves_rate;
+ unsigned i_slaves_requested_rate;
/* Last ES added */
enum es_format_category_e i_last_es_cat;
@@ -252,6 +254,7 @@ enum input_control_e
INPUT_CONTROL_SET_SPU_DELAY,
INPUT_CONTROL_ADD_SLAVE,
+ INPUT_CONTROL_SET_SLAVE_FPS,
INPUT_CONTROL_SET_RECORD_STATE,
--
2.19.1
More information about the vlc-devel
mailing list