[vlc-commits] es_out: change rate argument
Thomas Guillem
git at videolan.org
Fri Feb 15 16:38:04 CET 2019
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Feb 15 14:09:09 2019 +0100| [1bd4f9869e00c1818ed85c03fbe306058ba8bca7] | committer: Thomas Guillem
es_out: change rate argument
Inverse and use a float.
Before, the int rate value for a 4x speed was 250 (INPUT_RATE_DEFAULT / 250 =
4.f). Now, for a 4x speed, the float value will be 4.f.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1bd4f9869e00c1818ed85c03fbe306058ba8bca7
---
src/input/es_out.c | 32 ++++++++++-------------
src/input/es_out.h | 10 +++----
src/input/es_out_timeshift.c | 62 ++++++++++++++++++++++----------------------
src/input/input.c | 8 +++---
4 files changed, 55 insertions(+), 57 deletions(-)
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 4a3f8c6e75..d6aaa8fda1 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -181,7 +181,7 @@ typedef struct
vlc_tick_t i_pts_delay;
vlc_tick_t i_pts_jitter;
int i_cr_average;
- int i_rate;
+ float rate;
/* */
bool b_paused;
@@ -314,7 +314,7 @@ static const struct es_out_callbacks es_out_cbs;
/*****************************************************************************
* input_EsOutNew:
*****************************************************************************/
-es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
+es_out_t *input_EsOutNew( input_thread_t *p_input, float rate )
{
es_out_sys_t *p_sys = calloc( 1, sizeof( *p_sys ) );
if( !p_sys )
@@ -344,7 +344,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
p_sys->i_pause_date = -1;
- p_sys->i_rate = i_rate;
+ p_sys->rate = rate;
p_sys->b_buffering = true;
p_sys->i_preroll_end = -1;
@@ -676,18 +676,17 @@ static void EsOutChangePause( es_out_t *out, bool b_paused, vlc_tick_t i_date )
p_sys->i_pause_date = i_date;
}
-static void EsOutChangeRate( es_out_t *out, int i_rate )
+static void EsOutChangeRate( es_out_t *out, float rate )
{
es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
- const float rate = (float)i_rate / (float)INPUT_RATE_DEFAULT;
es_out_id_t *es;
- p_sys->i_rate = i_rate;
+ p_sys->rate = rate;
EsOutProgramsChangeRate( out );
foreach_es_then_es_slaves(es)
if( es->p_dec != NULL )
- input_DecoderChangeRate( es->p_dec, rate );
+ input_DecoderChangeRate( es->p_dec, 1.f / rate );
}
static void EsOutChangePosition( es_out_t *out )
@@ -879,10 +878,9 @@ static void EsOutProgramsChangeRate( es_out_t *out )
{
es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
es_out_pgrm_t *pgrm;
- float rate = INPUT_RATE_DEFAULT / (float) p_sys->i_rate;
vlc_list_foreach(pgrm, &p_sys->programs, node)
- input_clock_ChangeRate(pgrm->p_input_clock, rate);
+ input_clock_ChangeRate(pgrm->p_input_clock, p_sys->rate);
}
static void EsOutFrameNext( es_out_t *out )
@@ -987,7 +985,7 @@ static vlc_tick_t EsOutGetBuffering( es_out_t *out )
i_system_duration = vlc_tick_now() - i_system_start;
}
- const vlc_tick_t i_consumed = i_system_duration * INPUT_RATE_DEFAULT / p_sys->i_rate - i_stream_duration;
+ const vlc_tick_t i_consumed = i_system_duration * p_sys->rate - i_stream_duration;
i_delay = p_sys->i_pts_delay - i_consumed;
}
if( i_delay < 0 )
@@ -1113,7 +1111,7 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
p_pgrm->b_selected = false;
p_pgrm->b_scrambled = false;
p_pgrm->p_meta = NULL;
- p_pgrm->p_input_clock = input_clock_New( INPUT_RATE_DEFAULT / p_sys->i_rate );
+ p_pgrm->p_input_clock = input_clock_New( p_sys->rate );
if( !p_pgrm->p_input_clock )
{
free( p_pgrm );
@@ -1775,9 +1773,7 @@ static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
input_priv(p_input)->p_sout );
if( dec != NULL )
{
- float rate = (float)p_sys->i_rate / (float)INPUT_RATE_DEFAULT;
-
- input_DecoderChangeRate( dec, rate );
+ input_DecoderChangeRate( dec, 1 / p_sys->rate );
if( p_sys->b_buffering )
input_DecoderStartWait( dec );
@@ -2951,11 +2947,11 @@ static int EsOutVaControlLocked( es_out_t *out, int i_query, va_list args )
case ES_OUT_SET_RATE:
{
- const int i_src_rate = va_arg( args, int );
- const int i_rate = va_arg( args, int );
+ const float src_rate = va_arg( args, double );
+ const float rate = va_arg( args, double );
- assert( i_src_rate == i_rate );
- EsOutChangeRate( out, i_rate );
+ assert( src_rate == rate );
+ EsOutChangeRate( out, rate );
return VLC_SUCCESS;
}
diff --git a/src/input/es_out.h b/src/input/es_out.h
index 29007bf707..6760752ddd 100644
--- a/src/input/es_out.h
+++ b/src/input/es_out.h
@@ -68,7 +68,7 @@ enum es_out_query_private_e
ES_OUT_SET_PAUSE_STATE, /* arg1=bool b_source_paused, bool b_paused arg2=vlc_tick_t res=can fail */
/* Set rate */
- ES_OUT_SET_RATE, /* arg1=int i_source_rate arg2=int i_rate res=can fail */
+ ES_OUT_SET_RATE, /* arg1=double source_rate arg2=double rate res=can fail */
/* Set next frame */
ES_OUT_SET_FRAME_NEXT, /* res=can fail */
@@ -134,9 +134,9 @@ static inline int es_out_SetPauseState( es_out_t *p_out, bool b_source_paused, b
{
return es_out_Control( p_out, ES_OUT_SET_PAUSE_STATE, b_source_paused, b_paused, i_date );
}
-static inline int es_out_SetRate( es_out_t *p_out, int i_source_rate, int i_rate )
+static inline int es_out_SetRate( es_out_t *p_out, float source_rate, float rate )
{
- return es_out_Control( p_out, ES_OUT_SET_RATE, i_source_rate, i_rate );
+ return es_out_Control( p_out, ES_OUT_SET_RATE, source_rate, rate );
}
static inline int es_out_SetFrameNext( es_out_t *p_out )
{
@@ -172,7 +172,7 @@ static inline void es_out_Eos( es_out_t *p_out )
assert( !i_ret );
}
-es_out_t *input_EsOutNew( input_thread_t *, int i_rate );
-es_out_t *input_EsOutTimeshiftNew( input_thread_t *, es_out_t *, int i_rate );
+es_out_t *input_EsOutNew( input_thread_t *, float rate );
+es_out_t *input_EsOutTimeshiftNew( input_thread_t *, es_out_t *, float i_rate );
#endif
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index 8e6de78b87..3e5b07c8f2 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -198,8 +198,8 @@ typedef struct
vlc_tick_t i_pause_date;
/* */
- int i_rate;
- int i_rate_source;
+ float rate;
+ float rate_source;
vlc_tick_t i_rate_date;
vlc_tick_t i_rate_delay;
@@ -238,8 +238,8 @@ typedef struct
/* */
bool b_input_paused;
bool b_input_paused_source;
- int i_input_rate;
- int i_input_rate_source;
+ float input_rate;
+ float input_rate_source;
/* */
int i_es;
@@ -259,7 +259,7 @@ static int TsPopCmdLocked( ts_thread_t *, ts_cmd_t *, bool b_flush );
static bool TsHasCmd( ts_thread_t * );
static bool TsIsUnused( ts_thread_t * );
static int TsChangePause( ts_thread_t *, bool b_source_paused, bool b_paused, vlc_tick_t i_date );
-static int TsChangeRate( ts_thread_t *, int i_src_rate, int i_rate );
+static int TsChangeRate( ts_thread_t *, float src_rate, float rate );
static void *TsRun( void * );
@@ -298,7 +298,7 @@ static const struct es_out_callbacks es_out_timeshift_cbs;
/*****************************************************************************
* input_EsOutTimeshiftNew:
*****************************************************************************/
-es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out, int i_rate )
+es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out, float rate )
{
es_out_sys_t *p_sys = malloc( sizeof(*p_sys) );
if( !p_sys )
@@ -310,8 +310,8 @@ es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out
p_sys->b_input_paused = false;
p_sys->b_input_paused_source = false;
p_sys->p_input = p_input;
- p_sys->i_input_rate = i_rate;
- p_sys->i_input_rate_source = i_rate;
+ p_sys->input_rate = rate;
+ p_sys->input_rate_source = rate;
p_sys->p_out = p_next_out;
vlc_mutex_init_recursive( &p_sys->lock );
@@ -553,14 +553,14 @@ static int ControlLockedSetPauseState( es_out_t *p_out, bool b_source_paused, bo
}
return i_ret;
}
-static int ControlLockedSetRate( es_out_t *p_out, int i_src_rate, int i_rate )
+static int ControlLockedSetRate( es_out_t *p_out, float src_rate, float rate )
{
es_out_sys_t *p_sys = container_of(p_out, es_out_sys_t, out);
int i_ret;
- if( !p_sys->b_delayed && i_src_rate == i_rate )
+ if( !p_sys->b_delayed && src_rate == rate )
{
- i_ret = es_out_SetRate( p_sys->p_out, i_src_rate, i_rate );
+ i_ret = es_out_SetRate( p_sys->p_out, src_rate, rate );
}
else
{
@@ -570,7 +570,7 @@ static int ControlLockedSetRate( es_out_t *p_out, int i_src_rate, int i_rate )
if( !p_sys->b_delayed )
TsStart( p_out );
if( p_sys->b_delayed )
- i_ret = TsChangeRate( p_sys->p_ts, i_src_rate, i_rate );
+ i_ret = TsChangeRate( p_sys->p_ts, src_rate, rate );
}
else
{
@@ -584,8 +584,8 @@ static int ControlLockedSetRate( es_out_t *p_out, int i_src_rate, int i_rate )
if( !i_ret )
{
- p_sys->i_input_rate_source = i_src_rate;
- p_sys->i_input_rate = i_rate;
+ p_sys->input_rate_source = src_rate;
+ p_sys->input_rate = rate;
}
return i_ret;
}
@@ -707,10 +707,10 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
}
case ES_OUT_SET_RATE:
{
- const int i_src_rate = va_arg( args, int );
- const int i_rate = va_arg( args, int );
+ const float src_rate = va_arg( args, double );
+ const float rate = va_arg( args, double );
- return ControlLockedSetRate( p_out, i_src_rate, i_rate );
+ return ControlLockedSetRate( p_out, src_rate, rate );
}
case ES_OUT_SET_FRAME_NEXT:
{
@@ -805,8 +805,8 @@ static int TsStart( es_out_t *p_out )
vlc_cond_init( &p_ts->wait );
p_ts->b_paused = p_sys->b_input_paused && !p_sys->b_input_paused_source;
p_ts->i_pause_date = p_ts->b_paused ? vlc_tick_now() : -1;
- p_ts->i_rate_source = p_sys->i_input_rate_source;
- p_ts->i_rate = p_sys->i_input_rate;
+ p_ts->rate_source = p_sys->input_rate_source;
+ p_ts->rate = p_sys->input_rate;
p_ts->i_rate_date = -1;
p_ts->i_rate_delay = 0;
p_ts->i_buffering_delay = 0;
@@ -933,7 +933,7 @@ static bool TsIsUnused( ts_thread_t *p_ts )
vlc_mutex_lock( &p_ts->lock );
b_unused = !p_ts->b_paused &&
- p_ts->i_rate == p_ts->i_rate_source &&
+ p_ts->rate == p_ts->rate_source &&
TsStorageIsEmpty( p_ts->p_storage_r );
vlc_mutex_unlock( &p_ts->lock );
@@ -971,7 +971,7 @@ static int TsChangePause( ts_thread_t *p_ts, bool b_source_paused, bool b_paused
vlc_mutex_unlock( &p_ts->lock );
return i_ret;
}
-static int TsChangeRate( ts_thread_t *p_ts, int i_src_rate, int i_rate )
+static int TsChangeRate( ts_thread_t *p_ts, float src_rate, float rate )
{
int i_ret;
@@ -980,10 +980,10 @@ static int TsChangeRate( ts_thread_t *p_ts, int i_src_rate, int i_rate )
p_ts->i_rate_date = -1;
p_ts->i_rate_delay = 0;
- p_ts->i_rate = i_rate;
- p_ts->i_rate_source = i_src_rate;
+ p_ts->rate = rate;
+ p_ts->rate_source = src_rate;
- i_ret = es_out_SetRate( p_ts->p_out, i_rate, i_rate );
+ i_ret = es_out_SetRate( p_ts->p_out, rate, rate );
vlc_mutex_unlock( &p_ts->lock );
return i_ret;
@@ -1036,28 +1036,28 @@ static void *TsRun( void *p_data )
p_ts->i_rate_date = cmd.i_date;
p_ts->i_rate_delay = 0;
- if( p_ts->i_rate_source != p_ts->i_rate )
+ if( p_ts->rate_source != p_ts->rate )
{
const vlc_tick_t i_duration = cmd.i_date - p_ts->i_rate_date;
- p_ts->i_rate_delay = i_duration * p_ts->i_rate / p_ts->i_rate_source - i_duration;
+ p_ts->i_rate_delay = i_duration * p_ts->rate_source / p_ts->rate - i_duration;
}
- if( p_ts->i_cmd_delay + p_ts->i_rate_delay + p_ts->i_buffering_delay < 0 && p_ts->i_rate != p_ts->i_rate_source )
+ if( p_ts->i_cmd_delay + p_ts->i_rate_delay + p_ts->i_buffering_delay < 0 && p_ts->rate != p_ts->rate_source )
{
const int canc = vlc_savecancel();
/* Auto reset to rate 1.0 */
- msg_Warn( p_ts->p_input, "es out timeshift: auto reset rate to %d", p_ts->i_rate_source );
+ msg_Warn( p_ts->p_input, "es out timeshift: auto reset rate to %f", p_ts->rate_source );
p_ts->i_cmd_delay = 0;
p_ts->i_buffering_delay = 0;
p_ts->i_rate_delay = 0;
p_ts->i_rate_date = -1;
- p_ts->i_rate = p_ts->i_rate_source;
+ p_ts->rate = p_ts->rate_source;
- if( !es_out_SetRate( p_ts->p_out, p_ts->i_rate_source, p_ts->i_rate ) )
+ if( !es_out_SetRate( p_ts->p_out, p_ts->rate_source, p_ts->rate ) )
{
- vlc_value_t val = { .i_int = p_ts->i_rate };
+ vlc_value_t val = { .i_int = INPUT_RATE_DEFAULT / p_ts->rate };
/* Warn back input
* FIXME it is perfectly safe BUT it is ugly as it may hide a
* rate change requested by user */
diff --git a/src/input/input.c b/src/input/input.c
index 677a830339..cf4f179b03 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -508,7 +508,7 @@ static input_thread_t *Create( vlc_object_t *p_parent,
else
priv->stats = NULL;
- priv->p_es_out_display = input_EsOutNew( p_input, priv->i_rate );
+ priv->p_es_out_display = input_EsOutNew( p_input, INPUT_RATE_DEFAULT / (float) priv->i_rate );
priv->p_es_out = NULL;
/* Set the destructor when we are sure we are initialized */
@@ -1355,7 +1355,7 @@ static int Init( input_thread_t * p_input )
/* Create es out */
priv->p_es_out = input_EsOutTimeshiftNew( p_input, priv->p_es_out_display,
- priv->i_rate );
+ INPUT_RATE_DEFAULT / (float) priv->i_rate );
if( priv->p_es_out == NULL )
goto error;
@@ -2058,7 +2058,9 @@ static bool Control( input_thread_t *p_input,
if( priv->master->b_rescale_ts )
{
const int i_rate_source = (priv->b_can_pace_control || priv->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
- es_out_SetRate( priv->p_es_out, i_rate_source, i_rate );
+ es_out_SetRate( priv->p_es_out,
+ INPUT_RATE_DEFAULT / (float) i_rate_source,
+ INPUT_RATE_DEFAULT / (float) i_rate );
}
b_force_update = true;
More information about the vlc-commits
mailing list