[vlc-devel] [PATCH 1/2] input: add input_SetTime and input_SetPosition

Zhao Zhili quinkblack at foxmail.com
Tue Jun 19 14:58:30 CEST 2018


---
 include/vlc_input.h        |  4 ++
 src/input/input.c          | 93 +++++++++++++++++++++++++++++++++++-----------
 src/input/input_internal.h |  1 -
 src/input/var.c            |  8 ++--
 src/libvlccore.sym         |  2 +
 5 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index 16c566a..1d24fd1 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 int input_SetTime( input_thread_t *, mtime_t i_time, bool b_fast );
+
+VLC_API int 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 a413683..a8ae021 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -227,6 +227,46 @@ void input_Close( input_thread_t *p_input )
     vlc_object_release( p_input );
 }
 
+typedef struct input_seek_params_t {
+    bool b_fast;
+    union {
+        mtime_t i_time;
+        float f_position;
+    };
+} input_seek_params_t;
+
+int input_SetTime( input_thread_t *p_input, mtime_t i_time, bool b_fast )
+{
+    vlc_value_t val;
+    input_seek_params_t *param;
+
+    param = malloc( sizeof(*param) );
+    if( unlikely(param == NULL) )
+        return VLC_ENOMEM;
+
+    param->b_fast = b_fast;
+    param->i_time = i_time;
+    val.p_address = param;
+    input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
+    return VLC_SUCCESS;
+}
+
+int input_SetPosition( input_thread_t *p_input, float f_position, bool b_fast )
+{
+    vlc_value_t val;
+    input_seek_params_t *param;
+
+    param = malloc( sizeof(*param) );
+    if( unlikely(param == NULL) )
+        return VLC_ENOMEM;
+
+    param->b_fast = b_fast;
+    param->f_position = f_position;
+    val.p_address = param;
+    input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
+    return VLC_SUCCESS;
+}
+
 /**
  * Input destructor (called when the object's refcount reaches 0).
  */
@@ -616,30 +656,28 @@ 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_ControlPush( 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_ControlPush( p_input,
                            INPUT_CONTROL_SET_SEEKPOINT, &val );
 
     /* Seek to start position */
-    if( input_priv(p_input)->i_start > 0 )
+    if( priv->i_start > 0 )
     {
-        val.i_int = input_priv(p_input)->i_start;
-        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
+        input_SetTime( p_input, priv->i_start, false );
     }
     else
     {
-        val.f_float = 0.f;
-        input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
+        input_SetPosition( p_input, 0.0f, false );
     }
 
     return VLC_SUCCESS;
@@ -916,20 +954,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_ControlPush( 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)
@@ -1627,6 +1661,8 @@ static void ControlRelease( int i_type, vlc_value_t val )
     case INPUT_CONTROL_SET_VIEWPOINT:
     case INPUT_CONTROL_SET_INITIAL_VIEWPOINT:
     case INPUT_CONTROL_UPDATE_VIEWPOINT:
+    case INPUT_CONTROL_SET_TIME:
+    case INPUT_CONTROL_SET_POSITION:
         free( val.p_address );
         break;
     case INPUT_CONTROL_SET_RENDERER:
@@ -1849,7 +1885,8 @@ static bool Control( input_thread_t *p_input,
                 break;
             }
 
-            float f_pos = val.f_float;
+            input_seek_params_t *param = val.p_address;
+            float f_pos = param->f_position;
             if( f_pos < 0.f )
                 f_pos = 0.f;
             else if( f_pos > 1.f )
@@ -1857,7 +1894,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->b_fast ) )
             {
                 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "
                          "%2.1f%% failed", (double)(f_pos * 100.f) );
@@ -1877,6 +1914,7 @@ static bool Control( input_thread_t *p_input,
         {
             int64_t i_time;
             int i_ret;
+            input_seek_params_t *param;
 
             if( input_priv(p_input)->b_recording )
             {
@@ -1884,7 +1922,8 @@ static bool Control( input_thread_t *p_input,
                 break;
             }
 
-            i_time = val.i_int;
+            param = val.p_address;
+            i_time = param->i_time;
             if( i_time < 0 )
                 i_time = 0;
 
@@ -1893,7 +1932,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->b_fast );
             if( i_ret )
             {
                 int64_t i_length;
@@ -1905,7 +1944,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->b_fast );
                 }
             }
             if( i_ret )
@@ -2236,8 +2275,18 @@ static bool Control( input_thread_t *p_input,
                 break;
             }
 
-            val.i_int = time_offset;
-            b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
+            vlc_value_t seek_val;
+            input_seek_params_t *param;
+
+            param = malloc( sizeof(*param) );
+            if( unlikely(param == NULL) )
+                break;
+
+            param->b_fast = false;
+            param->i_time = time_offset;
+            seek_val.p_address = param;
+
+            b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, seek_val );
             break;
         }
         case INPUT_CONTROL_SET_RENDERER:
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index c0b8ae4..bc38a09 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -106,7 +106,6 @@ typedef struct input_thread_private_t
     mtime_t     i_start;    /* :start-time,0 by default */
     mtime_t     i_stop;     /* :stop-time, 0 if none */
     mtime_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 04c8cb0..717ae74 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -593,8 +593,8 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
         var_Change( p_input, "time", VLC_VAR_SETVALUE, val );
     }
 
-    input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
-    return VLC_SUCCESS;
+    return input_SetPosition( p_input, newval.f_float,
+                              var_GetBool( p_input, "input-fast-seek" ) );
 }
 
 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
@@ -618,8 +618,8 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
         var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
     }
 
-    input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
-    return VLC_SUCCESS;
+    return input_SetTime( p_input, newval.i_int,
+                          var_GetBool( p_input, "input-fast-seek" ) );
 }
 
 static int TimeOffsetCallback( vlc_object_t *obj, char const *varname,
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index e32a686..15a8af2 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