[vlc-devel] [V3 2/3] input: add input_SetTime and input_SetPosition

Zhao Zhili quinkblack at foxmail.com
Mon Jun 25 10:03:49 CEST 2018


---
 include/vlc_input.h        |  4 ++++
 src/input/input.c          | 59 ++++++++++++++++++++++++++--------------------
 src/input/input_internal.h |  9 ++++++-
 src/input/var.c            |  6 +++--
 src/libvlccore.sym         |  2 ++
 5 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index f892a10..7c758eb 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -514,6 +514,10 @@ VLC_API int input_Control( input_thread_t *, int i_query, ...  );
 
 VLC_API void input_Close( input_thread_t * );
 
+VLC_API void input_SetTime( input_thread_t *, vlc_tick_t i_time, bool b_fast );
+
+VLC_API void input_SetPosition( input_thread_t *, float f_position, bool b_fast );
+
 /**
  * Create a new input_thread_t and start it.
  *
diff --git a/src/input/input.c b/src/input/input.c
index 7861934..802d486 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -227,6 +227,24 @@ void input_Close( input_thread_t *p_input )
     vlc_object_release( p_input );
 }
 
+void input_SetTime( input_thread_t *p_input, vlc_tick_t i_time, bool b_fast )
+{
+    input_control_param_t param;
+
+    param.time.i_val = i_time;
+    param.time.b_fast_seek = b_fast;
+    input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &param );
+}
+
+void input_SetPosition( input_thread_t *p_input, float f_position, bool b_fast )
+{
+    input_control_param_t param;
+
+    param.pos.f_val = f_position;
+    param.pos.b_fast_seek = b_fast;
+    input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &param );
+}
+
 /**
  * Input destructor (called when the object's refcount reaches 0).
  */
@@ -616,31 +634,25 @@ static int MainLoopTryRepeat( input_thread_t *p_input )
         var_SetInteger( p_input, "input-repeat", i_repeat );
     }
 
+    input_thread_private_t *priv = input_priv(p_input);
     /* Seek to start title/seekpoint */
-    val.i_int = input_priv(p_input)->master->i_title_start -
-        input_priv(p_input)->master->i_title_offset;
-    if( val.i_int < 0 || val.i_int >= input_priv(p_input)->master->i_title )
+    val.i_int = priv->master->i_title_start - priv->master->i_title_offset;
+    if( val.i_int < 0 || val.i_int >= priv->master->i_title )
         val.i_int = 0;
     input_ControlPushHelper( p_input,
                        INPUT_CONTROL_SET_TITLE, &val );
 
-    val.i_int = input_priv(p_input)->master->i_seekpoint_start -
-        input_priv(p_input)->master->i_seekpoint_offset;
+    val.i_int = priv->master->i_seekpoint_start -
+                priv->master->i_seekpoint_offset;
     if( val.i_int > 0 /* TODO: check upper boundary */ )
         input_ControlPushHelper( p_input,
                            INPUT_CONTROL_SET_SEEKPOINT, &val );
 
     /* Seek to start position */
-    if( input_priv(p_input)->i_start > 0 )
-    {
-        val.i_int = input_priv(p_input)->i_start;
-        input_ControlPushHelper( p_input, INPUT_CONTROL_SET_TIME, &val );
-    }
+    if( priv->i_start > 0 )
+        input_SetTime( p_input, priv->i_start, false );
     else
-    {
-        val.f_float = 0.f;
-        input_ControlPushHelper( p_input, INPUT_CONTROL_SET_POSITION, &val );
-    }
+        input_SetPosition( p_input, 0.0f, false );
 
     return VLC_SUCCESS;
 }
@@ -917,20 +929,16 @@ static void StartTitle( input_thread_t * p_input )
 
     if( priv->i_start > 0 )
     {
-        vlc_value_t s;
-
         msg_Dbg( p_input, "starting at time: %"PRId64"s",
                  priv->i_start / CLOCK_FREQ );
 
-        s.i_int = priv->i_start;
-        input_ControlPushHelper( p_input, INPUT_CONTROL_SET_TIME, &s );
+        input_SetTime( p_input, priv->i_start, false );
     }
     if( priv->i_stop > 0 && priv->i_stop <= priv->i_start )
     {
         msg_Warn( p_input, "invalid stop-time ignored" );
         priv->i_stop = 0;
     }
-    priv->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
 }
 
 static int SlaveCompare(const void *a, const void *b)
@@ -1849,7 +1857,7 @@ static bool Control( input_thread_t *p_input,
                 break;
             }
 
-            float f_pos = param.val.f_float;
+            float f_pos = param.pos.f_val;
             if( f_pos < 0.f )
                 f_pos = 0.f;
             else if( f_pos > 1.f )
@@ -1857,7 +1865,7 @@ static bool Control( input_thread_t *p_input,
             /* Reset the decoders states and clock sync (before calling the demuxer */
             es_out_Control( input_priv(p_input)->p_es_out, ES_OUT_RESET_PCR );
             if( demux_Control( input_priv(p_input)->master->p_demux, DEMUX_SET_POSITION,
-                               (double) f_pos, !input_priv(p_input)->b_fast_seek ) )
+                               (double) f_pos, !param.pos.b_fast_seek ) )
             {
                 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "
                          "%2.1f%% failed", (double)(f_pos * 100.f) );
@@ -1884,7 +1892,7 @@ static bool Control( input_thread_t *p_input,
                 break;
             }
 
-            i_time = param.val.i_int;
+            i_time = param.time.i_val;
             if( i_time < 0 )
                 i_time = 0;
 
@@ -1893,7 +1901,7 @@ static bool Control( input_thread_t *p_input,
 
             i_ret = demux_Control( input_priv(p_input)->master->p_demux,
                                    DEMUX_SET_TIME, i_time,
-                                   !input_priv(p_input)->b_fast_seek );
+                                   !param.time.b_fast_seek );
             if( i_ret )
             {
                 int64_t i_length;
@@ -1905,7 +1913,7 @@ static bool Control( input_thread_t *p_input,
                     double f_pos = (double)i_time / (double)i_length;
                     i_ret = demux_Control( input_priv(p_input)->master->p_demux,
                                             DEMUX_SET_POSITION, f_pos,
-                                            !input_priv(p_input)->b_fast_seek );
+                                            !param.time.b_fast_seek );
                 }
             }
             if( i_ret )
@@ -2239,7 +2247,8 @@ static bool Control( input_thread_t *p_input,
             }
 
             input_control_param_t param;
-            param.val.i_int = time_offset;
+            param.time.i_val = time_offset;
+            param.time.b_fast_seek = false;
             b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, param );
             break;
         }
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 540e100..15526db 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -82,6 +82,14 @@ typedef union
 {
     vlc_value_t val;
     vlc_viewpoint_t viewpoint;
+    struct {
+        bool b_fast_seek;
+        vlc_tick_t i_val;
+    } time;
+    struct {
+        bool b_fast_seek;
+        float f_val;
+    } pos;
 } input_control_param_t;
 
 typedef struct
@@ -112,7 +120,6 @@ typedef struct input_thread_private_t
     vlc_tick_t  i_start;    /* :start-time,0 by default */
     vlc_tick_t  i_stop;     /* :stop-time, 0 if none */
     vlc_tick_t  i_time;     /* Current time */
-    bool        b_fast_seek;/* :input-fast-seek */
 
     /* Output */
     bool            b_out_pace_control; /* XXX Move it ot es_sout ? */
diff --git a/src/input/var.c b/src/input/var.c
index 410deb1..3013b5f 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -593,7 +593,8 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
         var_Change( p_input, "time", VLC_VAR_SETVALUE, val );
     }
 
-    input_ControlPushHelper( p_input, INPUT_CONTROL_SET_POSITION, &newval );
+    input_SetPosition( p_input, newval.f_float,
+                       var_GetBool( p_input, "input-fast-seek" ) );
     return VLC_SUCCESS;
 }
 
@@ -618,7 +619,8 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
         var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
     }
 
-    input_ControlPushHelper( p_input, INPUT_CONTROL_SET_TIME, &newval );
+    input_SetTime( p_input, newval.i_int,
+                   var_GetBool( p_input, "input-fast-seek" ) );
     return VLC_SUCCESS;
 }
 
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 0378c96..31e4ece 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -205,6 +205,8 @@ input_resource_ResetAout
 input_Start
 input_Stop
 input_vaControl
+input_SetTime
+input_SetPosition
 vlc_readdir_helper_init
 vlc_readdir_helper_finish
 vlc_readdir_helper_additem
-- 
2.9.5





More information about the vlc-devel mailing list