[vlc-commits] input_clock: change rate argument

Thomas Guillem git at videolan.org
Fri Feb 15 16:38:02 CET 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Feb 15 12:52:59 2019 +0100| [e94cc7fe638540fbff5f2645e40116b41a3cb4a5] | committer: Thomas Guillem

input_clock: change rate argument

Use a float and inverse it.

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=e94cc7fe638540fbff5f2645e40116b41a3cb4a5
---

 src/clock/input_clock.c | 36 ++++++++++++++++--------------------
 src/clock/input_clock.h | 10 +++++-----
 src/input/decoder.c     |  9 +++++----
 src/input/es_out.c      | 12 ++++++------
 4 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/src/clock/input_clock.c b/src/clock/input_clock.c
index cf490622f3..3729c74e03 100644
--- a/src/clock/input_clock.c
+++ b/src/clock/input_clock.c
@@ -139,7 +139,7 @@ struct input_clock_t
 
     /* Current modifiers */
     bool    b_paused;
-    int     i_rate;
+    float   rate;
     vlc_tick_t i_pts_delay;
     vlc_tick_t i_pause_date;
 };
@@ -152,7 +152,7 @@ static vlc_tick_t ClockGetTsOffset( input_clock_t * );
 /*****************************************************************************
  * input_clock_New: create a new clock
  *****************************************************************************/
-input_clock_t *input_clock_New( int i_rate )
+input_clock_t *input_clock_New( float rate )
 {
     input_clock_t *cl = malloc( sizeof(*cl) );
     if( !cl )
@@ -176,7 +176,7 @@ input_clock_t *input_clock_New( int i_rate )
     for( int i = 0; i < INPUT_CLOCK_LATE_COUNT; i++ )
         cl->late.pi_value[i] = 0;
 
-    cl->i_rate = i_rate;
+    cl->rate = rate;
     cl->i_pts_delay = 0;
     cl->b_paused = false;
     cl->i_pause_date = VLC_TICK_INVALID;
@@ -308,7 +308,7 @@ void input_clock_Reset( input_clock_t *cl )
 /*****************************************************************************
  * input_clock_ChangeRate:
  *****************************************************************************/
-void input_clock_ChangeRate( input_clock_t *cl, int i_rate )
+void input_clock_ChangeRate( input_clock_t *cl, float rate )
 {
     vlc_mutex_lock( &cl->lock );
 
@@ -316,9 +316,9 @@ void input_clock_ChangeRate( input_clock_t *cl, int i_rate )
     {
         /* Move the reference point (as if we were playing at the new rate
          * from the start */
-        cl->ref.i_system = cl->last.i_system - (cl->last.i_system - cl->ref.i_system) * i_rate / cl->i_rate;
+        cl->ref.i_system = cl->last.i_system - (cl->last.i_system - cl->ref.i_system) / rate * cl->rate;
     }
-    cl->i_rate = i_rate;
+    cl->rate = rate;
 
     vlc_mutex_unlock( &cl->lock );
 }
@@ -369,14 +369,14 @@ vlc_tick_t input_clock_GetWakeup( input_clock_t *cl )
  * input_clock_ConvertTS
  *****************************************************************************/
 int input_clock_ConvertTS( vlc_object_t *p_object, input_clock_t *cl,
-                           int *pi_rate, vlc_tick_t *pi_ts0, vlc_tick_t *pi_ts1,
+                           float *p_rate, vlc_tick_t *pi_ts0, vlc_tick_t *pi_ts1,
                            vlc_tick_t i_ts_bound )
 {
     assert( pi_ts0 );
     vlc_mutex_lock( &cl->lock );
 
-    if( pi_rate )
-        *pi_rate = cl->i_rate;
+    if( p_rate )
+        *p_rate = cl->rate;
 
     if( !cl->b_has_reference )
     {
@@ -390,7 +390,7 @@ int input_clock_ConvertTS( vlc_object_t *p_object, input_clock_t *cl,
     }
 
     /* */
-    const vlc_tick_t i_ts_buffering = cl->i_buffering_duration * cl->i_rate / INPUT_RATE_DEFAULT;
+    const vlc_tick_t i_ts_buffering = cl->i_buffering_duration / cl->rate;
     const vlc_tick_t i_ts_delay = cl->i_pts_delay + ClockGetTsOffset( cl );
 
     /* */
@@ -427,15 +427,13 @@ int input_clock_ConvertTS( vlc_object_t *p_object, input_clock_t *cl,
 /*****************************************************************************
  * input_clock_GetRate: Return current rate
  *****************************************************************************/
-int input_clock_GetRate( input_clock_t *cl )
+float input_clock_GetRate( input_clock_t *cl )
 {
-    int i_rate;
-
     vlc_mutex_lock( &cl->lock );
-    i_rate = cl->i_rate;
+    float rate = cl->rate;
     vlc_mutex_unlock( &cl->lock );
 
-    return i_rate;
+    return rate;
 }
 
 int input_clock_GetState( input_clock_t *cl,
@@ -570,8 +568,7 @@ static vlc_tick_t ClockStreamToSystem( input_clock_t *cl, vlc_tick_t i_stream )
     if( !cl->b_has_reference )
         return VLC_TICK_INVALID;
 
-    return ( i_stream - cl->ref.i_stream ) * cl->i_rate / INPUT_RATE_DEFAULT +
-           cl->ref.i_system;
+    return ( i_stream - cl->ref.i_stream ) / cl->rate + cl->ref.i_system;
 }
 
 /*****************************************************************************
@@ -582,8 +579,7 @@ static vlc_tick_t ClockStreamToSystem( input_clock_t *cl, vlc_tick_t i_stream )
 static vlc_tick_t ClockSystemToStream( input_clock_t *cl, vlc_tick_t i_system )
 {
     assert( cl->b_has_reference );
-    return ( i_system - cl->ref.i_system ) * INPUT_RATE_DEFAULT / cl->i_rate +
-            cl->ref.i_stream;
+    return ( i_system - cl->ref.i_system ) * cl->rate + cl->ref.i_stream;
 }
 
 /**
@@ -592,6 +588,6 @@ static vlc_tick_t ClockSystemToStream( input_clock_t *cl, vlc_tick_t i_system )
  */
 static vlc_tick_t ClockGetTsOffset( input_clock_t *cl )
 {
-    return cl->i_pts_delay * ( cl->i_rate - INPUT_RATE_DEFAULT ) / INPUT_RATE_DEFAULT;
+    return cl->i_pts_delay * ( 1.0f / cl->rate - 1.0f );
 }
 
diff --git a/src/clock/input_clock.h b/src/clock/input_clock.h
index b9b508c968..1ec2a45895 100644
--- a/src/clock/input_clock.h
+++ b/src/clock/input_clock.h
@@ -39,7 +39,7 @@ typedef struct input_clock_t input_clock_t;
  * This function creates a new input_clock_t.
  * You must use input_clock_Delete to delete it once unused.
  */
-input_clock_t *input_clock_New( int i_rate );
+input_clock_t *input_clock_New( float rate );
 
 /**
  * This function destroys a input_clock_t created by input_clock_New.
@@ -72,7 +72,7 @@ vlc_tick_t input_clock_GetWakeup( input_clock_t * );
 /**
  * This functions allows changing the actual reading speed.
  */
-void    input_clock_ChangeRate( input_clock_t *, int i_rate );
+void    input_clock_ChangeRate( input_clock_t *, float rate );
 
 /**
  * This function allows changing the pause status.
@@ -96,7 +96,7 @@ void    input_clock_ChangeSystemOrigin( input_clock_t *, bool b_absolute, vlc_ti
 /**
  * This function converts a pair of timestamp from stream clock to system clock.
  *
- * If pi_rate is provided it will be filled with the rate value used for
+ * If p_rate is provided it will be filled with the rate value used for
  * the conversion.
  * p_ts0 is a pointer to a timestamp to be converted (in place) and must be non NULL.
  * p_ts1 is a pointer to a timestamp to be converted (in place) and can be NULL.
@@ -107,13 +107,13 @@ void    input_clock_ChangeSystemOrigin( input_clock_t *, bool b_absolute, vlc_ti
  * this case, *p_ts0 and *p_ts1 will hold an invalid timestamp.
  * Otherwise it will return VLC_SUCCESS.
  */
-int input_clock_ConvertTS( vlc_object_t *, input_clock_t *, int *pi_rate,
+int input_clock_ConvertTS( vlc_object_t *, input_clock_t *, float *p_rate,
                            vlc_tick_t *pi_ts0, vlc_tick_t *pi_ts1, vlc_tick_t i_ts_bound );
 
 /**
  * This function returns the current rate.
  */
-int input_clock_GetRate( input_clock_t * );
+float input_clock_GetRate( input_clock_t * );
 
 /**
  * This function returns current clock state or VLC_EGENERIC if there is not a
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 51b509dbad..bd32275df0 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -711,7 +711,7 @@ static float DecoderGetDisplayRate( decoder_t *p_dec )
 
     if( !p_owner->p_clock )
         return 1.f;
-    return input_clock_GetRate( p_owner->p_clock ) / (float) INPUT_RATE_DEFAULT;
+    return input_clock_GetRate( p_owner->p_clock );
 }
 
 /*****************************************************************************
@@ -811,7 +811,7 @@ static void DecoderFixTs( decoder_t *p_dec, vlc_tick_t *pi_ts0, vlc_tick_t *pi_t
         return;
 
     const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
-    int i_rate;
+    float rate;
 
     if( *pi_ts0 != VLC_TICK_INVALID )
     {
@@ -820,7 +820,7 @@ static void DecoderFixTs( decoder_t *p_dec, vlc_tick_t *pi_ts0, vlc_tick_t *pi_t
             *pi_ts1 += i_es_delay;
         if( i_ts_bound != INT64_MAX )
             i_ts_bound += i_es_delay;
-        if( input_clock_ConvertTS( VLC_OBJECT(p_dec), p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound ) ) {
+        if( input_clock_ConvertTS( VLC_OBJECT(p_dec), p_clock, &rate, pi_ts0, pi_ts1, i_ts_bound ) ) {
             const char *psz_name = module_get_name( p_dec->p_module, false );
             if( pi_ts1 != NULL )
                 msg_Err(p_dec, "Could not convert timestamps %"PRId64
@@ -832,8 +832,9 @@ static void DecoderFixTs( decoder_t *p_dec, vlc_tick_t *pi_ts0, vlc_tick_t *pi_t
     }
     else
     {
-        i_rate = input_clock_GetRate( p_clock );
+        rate = input_clock_GetRate( p_clock );
     }
+    const int i_rate = INPUT_RATE_DEFAULT / rate;
 
     /* Do not create ephemere data because of rounding errors */
     if( !b_ephemere && pi_ts1 && *pi_ts1 != VLC_TICK_INVALID && *pi_ts0 == *pi_ts1 )
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 4767003747..4a3f8c6e75 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -679,7 +679,7 @@ static void EsOutChangePause( es_out_t *out, bool b_paused, vlc_tick_t i_date )
 static void EsOutChangeRate( es_out_t *out, int i_rate )
 {
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
-    float rate = (float)i_rate / (float)INPUT_RATE_DEFAULT;
+    const float rate = (float)i_rate / (float)INPUT_RATE_DEFAULT;
     es_out_id_t *es;
 
     p_sys->i_rate = i_rate;
@@ -879,9 +879,10 @@ 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, p_sys->i_rate);
+        input_clock_ChangeRate(pgrm->p_input_clock, rate);
 }
 
 static void EsOutFrameNext( es_out_t *out )
@@ -938,13 +939,12 @@ static void EsOutFrameNext( es_out_t *out )
         p_sys->i_buffering_extra_stream = p_sys->i_buffering_extra_initial;
     }
 
-    const int i_rate = input_clock_GetRate( p_sys->p_pgrm->p_input_clock );
+    const float rate = input_clock_GetRate( p_sys->p_pgrm->p_input_clock );
 
     p_sys->b_buffering = true;
     p_sys->i_buffering_extra_system += i_duration;
     p_sys->i_buffering_extra_stream = p_sys->i_buffering_extra_initial +
-                                      ( p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial ) *
-                                                INPUT_RATE_DEFAULT / i_rate;
+        ( p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial ) * rate;
 
     p_sys->i_preroll_end = -1;
     p_sys->i_prev_stream_level = -1;
@@ -1113,7 +1113,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( p_sys->i_rate );
+    p_pgrm->p_input_clock = input_clock_New( INPUT_RATE_DEFAULT / p_sys->i_rate );
     if( !p_pgrm->p_input_clock )
     {
         free( p_pgrm );



More information about the vlc-commits mailing list