[vlc-commits] playlist: receive events from input thread

Romain Vimont git at videolan.org
Mon Aug 20 13:59:15 CEST 2018


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Fri Aug 10 16:00:56 2018 +0200| [e355ca914a3bc2774c00f647ecf51aad008286f2] | committer: Romain Vimont

playlist: receive events from input thread

Replace listeners on the input item by preparser callbacks (for
preparsing) and input thread callbacks (for normal playback).

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

 src/playlist/item.c              | 27 +++++++++++++++++----------
 src/playlist/playlist_internal.h |  2 ++
 src/playlist/thread.c            | 14 +++++++++++++-
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/playlist/item.c b/src/playlist/item.c
index 9e3d0fac43..a6d375f66e 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -51,13 +51,19 @@ static int RecursiveInsertCopy (
  * An input item has gained subitems (Event Callback)
  *****************************************************************************/
 
-static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
-                                          void * user_data )
+static void input_item_subtree_added(input_item_t *p_input,
+                                     input_item_node_t *subtree,
+                                     void *user_data)
+{
+    playlist_t *playlist = user_data;
+    playlist_AddSubtree(playlist, p_input, subtree);
+}
+
+void playlist_AddSubtree(playlist_t *p_playlist,
+                         input_item_t *p_input, input_item_node_t *subtree)
 {
-    input_item_t *p_input = p_event->p_obj;
-    playlist_t *p_playlist = user_data;
     playlist_private_t *p_sys = pl_priv( p_playlist );
-    input_item_node_t *p_new_root = p_event->u.input_item_subitem_tree_added.p_root;
+    input_item_node_t *p_new_root = subtree;
 
     PL_LOCK;
 
@@ -309,8 +315,6 @@ playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,
 
     vlc_event_manager_t *p_em = &p_item->p_input->event_manager;
 
-    vlc_event_attach( p_em, vlc_InputItemSubItemTreeAdded,
-                      input_item_add_subitem_tree, p_playlist );
     vlc_event_attach( p_em, vlc_InputItemDurationChanged,
                       input_item_changed, p_playlist );
     vlc_event_attach( p_em, vlc_InputItemMetaChanged,
@@ -346,8 +350,6 @@ void playlist_ItemRelease( playlist_t *p_playlist, playlist_item_t *p_item )
 
     vlc_event_manager_t *p_em = &p_item->p_input->event_manager;
 
-    vlc_event_detach( p_em, vlc_InputItemSubItemTreeAdded,
-                      input_item_add_subitem_tree, p_playlist );
     vlc_event_detach( p_em, vlc_InputItemMetaChanged,
                       input_item_changed, p_playlist );
     vlc_event_detach( p_em, vlc_InputItemDurationChanged,
@@ -724,6 +726,10 @@ vlc_tick_t playlist_GetNodeDuration( playlist_item_t* node )
     return duration;
 }
 
+static const input_preparser_callbacks_t input_preparser_callbacks = {
+    .on_subtree_added = input_item_subtree_added,
+};
+
 /***************************************************************************
  * The following functions are local
  ***************************************************************************/
@@ -745,7 +751,8 @@ static void playlist_Preparse( playlist_t *p_playlist,
     if( sys->b_preparse && !input_item_IsPreparsed( input )
      && (EMPTY_STR(psz_artist) || EMPTY_STR(psz_album)) )
         vlc_MetadataRequest( p_playlist->obj.libvlc, input, 0,
-                             NULL, NULL, -1, p_item );
+                             &input_preparser_callbacks, p_playlist,
+                             -1, p_item );
     free( psz_artist );
     free( psz_album );
 }
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 3ed57c2a53..793ed6a514 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -118,6 +118,8 @@ void playlist_SendAddNotify( playlist_t *p_playlist, playlist_item_t *item );
 int playlist_InsertInputItemTree ( playlist_t *,
         playlist_item_t *, input_item_node_t *, int, bool );
 
+void playlist_AddSubtree(playlist_t *, input_item_t *, input_item_node_t *);
+
 /* Tree walking */
 int playlist_NodeInsert(playlist_item_t*, playlist_item_t *, int);
 
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 0823ed54a9..bc53135d1a 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -185,6 +185,18 @@ void ResetCurrentlyPlaying( playlist_t *p_playlist,
     p_sys->b_reset_currently_playing = false;
 }
 
+static void on_input_event(input_thread_t *input, void *userdata,
+                           const struct vlc_input_event *event)
+{
+    if (event->type == INPUT_EVENT_SUBITEMS)
+    {
+        playlist_t *playlist = userdata;
+        input_item_t *item = input_GetItem(input);
+        playlist_AddSubtree(playlist, item, event->subitems);
+    }
+
+    input_LegacyEvents(input, userdata, event);
+}
 
 /**
  * Start the input for an item
@@ -216,7 +228,7 @@ static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
     libvlc_MetadataCancel( p_playlist->obj.libvlc, p_item );
 
     input_thread_t *p_input_thread = input_Create( p_playlist,
-                                                   input_LegacyEvents, NULL,
+                                                   on_input_event, p_playlist,
                                                    p_input, NULL,
                                                    p_sys->p_input_resource,
                                                    p_renderer );



More information about the vlc-commits mailing list