[vlc-commits] input: split time and time-offset callbacks

Rémi Denis-Courmont git at videolan.org
Fri May 22 21:15:54 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri May 22 21:47:37 2015 +0300| [72ab20782b8eb8665023f8b9f01bc70883af0df5] | committer: Rémi Denis-Courmont

input: split time and time-offset callbacks

There was no common code.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=72ab20782b8eb8665023f8b9f01bc70883af0df5
---

 src/input/var.c |   53 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/src/input/var.c b/src/input/var.c
index c478609..24dd8cd 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -47,6 +47,8 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval, void * );
 static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval, void * );
+static int TimeOffsetCallback( vlc_object_t *p_this, char const *psz_cmd,
+                             vlc_value_t oldval, vlc_value_t newval, void * );
 static int ProgramCallback ( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval, void * );
 static int TitleCallback   ( vlc_object_t *p_this, char const *psz_cmd,
@@ -91,7 +93,7 @@ static const vlc_input_callback_t p_input_callbacks[] =
     CALLBACK( "position", PositionCallback ),
     CALLBACK( "position-offset", PositionCallback ),
     CALLBACK( "time", TimeCallback ),
-    CALLBACK( "time-offset", TimeCallback ),
+    CALLBACK( "time-offset", TimeOffsetCallback ),
     CALLBACK( "bookmark", BookmarkCallback ),
     CALLBACK( "program", ProgramCallback ),
     CALLBACK( "title", TitleCallback ),
@@ -611,35 +613,36 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     input_thread_t *p_input = (input_thread_t*)p_this;
-    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
+    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
 
-    if( !strcmp( psz_cmd, "time-offset" ) )
+    /* Update "position" for better intf behavour */
+    const mtime_t i_length = var_GetTime( p_input, "length" );
+    if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length )
     {
-        mtime_t i_time = var_GetTime( p_input, "time" ) + newval.i_time;
-        if( i_time < 0 )
-            i_time = 0;
-        var_SetTime( p_this, "time", i_time );
+        vlc_value_t val;
+
+        val.f_float = (double)newval.i_time/(double)i_length;
+        var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
+        /*
+         * Notify the intf that a new event has been occurred.
+         * XXX this is a bit hackish but it's the only way to do it now.
+         */
+        var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
     }
-    else
-    {
-        /* Update "position" for better intf behavour */
-        const mtime_t i_length = var_GetTime( p_input, "length" );
-        if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length )
-        {
-            vlc_value_t val;
 
-            val.f_float = (double)newval.i_time/(double)i_length;
-            var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
-            /*
-             * Notify the intf that a new event has been occurred.
-             * XXX this is a bit hackish but it's the only way to do it now.
-             */
-            var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
-        }
+    input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
+    return VLC_SUCCESS;
+}
 
-        /* */
-        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
-    }
+static int TimeOffsetCallback( vlc_object_t *obj, char const *varname,
+                               vlc_value_t prev, vlc_value_t cur, void *data )
+{
+    VLC_UNUSED(varname); VLC_UNUSED(prev); VLC_UNUSED(data);
+
+    mtime_t i_time = var_GetTime( obj, "time" ) + cur.i_time;
+    if( i_time < 0 )
+        i_time = 0;
+    var_SetTime( obj, "time", i_time );
     return VLC_SUCCESS;
 }
 



More information about the vlc-commits mailing list