[vlc-commits] cli: use player callback to show position

Rémi Denis-Courmont git at videolan.org
Sun Oct 18 18:11:45 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 18 17:11:59 2020 +0300| [27461a11372ad957ebffad2360ac8ef8b14fec70] | committer: Rémi Denis-Courmont

cli: use player callback to show position

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

 modules/control/cli/cli.c    | 21 ---------------------
 modules/control/cli/player.c | 16 +++++++++++++++-
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index bf0506b841..406b0e988a 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -450,11 +450,8 @@ static void *Run( void *data )
     intf_sys_t *p_sys = p_intf->p_sys;
 
     char p_buffer[ MAX_LINE_LENGTH + 1 ];
-    bool b_showpos = var_InheritBool( p_intf, "rc-show-pos" );
 
     int  i_size = 0;
-    int  i_oldpos = 0;
-    int  i_newpos;
     int  canc = vlc_savecancel( );
 
     p_buffer[0] = 0;
@@ -469,11 +466,6 @@ static void *Run( void *data )
     }
 #endif
 
-    /* Register commands that will be cleaned up upon object destruction */
-    vlc_player_t *player = vlc_playlist_GetPlayer(p_sys->playlist);
-
-    /* status callbacks */
-
     for( ;; )
     {
         bool b_complete;
@@ -490,19 +482,6 @@ static void *Run( void *data )
         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
         canc = vlc_savecancel( );
 
-        vlc_player_Lock(player);
-        /* Manage the input part */
-        if( b_showpos )
-        {
-            i_newpos = 100 * vlc_player_GetPosition( player );
-            if( i_oldpos != i_newpos )
-            {
-                i_oldpos = i_newpos;
-                msg_rc( "pos: %d%%", i_newpos );
-            }
-        }
-        vlc_player_Unlock(player);
-
         /* Is there something to do? */
         if( !b_complete ) continue;
 
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index f19602ef3a..9850c22025 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <assert.h>
+#include <math.h>
 
 #include <vlc_common.h>
 #include <vlc_interface.h>
@@ -40,7 +41,9 @@ struct player_cli {
     intf_thread_t *intf;
     vlc_player_listener_id *player_listener;
     vlc_player_aout_listener_id *player_aout_listener;
+    long position;
     bool input_buffering;
+    bool show_position;
 };
 
 /********************************************************************
@@ -117,10 +120,19 @@ player_on_position_changed(vlc_player_t *player,
     intf_thread_t *p_intf = pc->intf;
 
     if (pc->input_buffering)
+    {
         msg_rc(STATUS_CHANGE "( time: %"PRId64"s )",
                SEC_FROM_VLC_TICK(new_time));
+        pc->input_buffering = false;
+    }
 
-    pc->input_buffering = false;
+    long position = lroundf(new_pos * 100.f);
+
+    if (pc->show_position && position != pc->position)
+    {
+        pc->position = position;
+        msg_rc("pos: %ld%%", pc->position);
+    }
 }
 
 static const struct vlc_player_cbs player_cbs =
@@ -931,7 +943,9 @@ void *RegisterPlayer(intf_thread_t *intf)
         return NULL;
 
     pc->intf = intf;
+    pc->position = -1.;
     pc->input_buffering = false;
+    pc->show_position = var_InheritBool(intf, "rc-show-pos");
 
     RegisterHandlers(intf, cmds, ARRAY_SIZE(cmds));
 



More information about the vlc-commits mailing list