[vlc-commits] cli: notify item change immediately

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 18 17:03:47 2020 +0300| [437538aa58a4e5f0f3328e6499a3e196e2058ffe] | committer: Rémi Denis-Courmont

cli: notify item change immediately

Use the dedicated player callback. Don't wait for user input.

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

 modules/control/cli/cli.c    | 15 +--------------
 modules/control/cli/player.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index e13aa29b28..bf0506b841 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -471,7 +471,6 @@ static void *Run( void *data )
 
     /* Register commands that will be cleaned up upon object destruction */
     vlc_player_t *player = vlc_playlist_GetPlayer(p_sys->playlist);
-    input_item_t *item = NULL;
 
     /* status callbacks */
 
@@ -493,19 +492,7 @@ static void *Run( void *data )
 
         vlc_player_Lock(player);
         /* Manage the input part */
-        if( item == NULL )
-        {
-            item = vlc_player_GetCurrentMedia(player);
-            /* New input has been registered */
-            if( item )
-            {
-                char *psz_uri = input_item_GetURI( item );
-                msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
-                free( psz_uri );
-            }
-        }
-
-        if( item && b_showpos )
+        if( b_showpos )
         {
             i_newpos = 100 * vlc_player_GetPosition( player );
             if( i_oldpos != i_newpos )
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index 02f9760811..f19602ef3a 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -46,6 +46,23 @@ struct player_cli {
 /********************************************************************
  * Status callback routines
  ********************************************************************/
+
+static void
+player_on_media_changed(vlc_player_t *player, input_item_t *item, void *data)
+{
+    struct player_cli *pc = data;
+    intf_thread_t *p_intf = pc->intf;
+
+    (void) player;
+
+    if (item != NULL)
+    {
+        vlc_mutex_lock(&item->lock);
+        msg_rc(STATUS_CHANGE "( new input: %s )", item->psz_uri);
+        vlc_mutex_unlock(&item->lock);
+    }
+}
+
 static void
 player_on_state_changed(vlc_player_t *player,
                         enum vlc_player_state state, void *data)
@@ -108,6 +125,7 @@ player_on_position_changed(vlc_player_t *player,
 
 static const struct vlc_player_cbs player_cbs =
 {
+    .on_current_media_changed = player_on_media_changed,
     .on_state_changed = player_on_state_changed,
     .on_buffering_changed = player_on_buffering_changed,
     .on_rate_changed = player_on_rate_changed,



More information about the vlc-commits mailing list