[vlc-devel] [PATCH 2/7] media_tree: send notification when preparse is complete

Pierre Lamot pierre at videolabs.io
Mon Oct 21 18:08:54 CEST 2019


---
 include/vlc_media_source.h    | 13 +++++++++++++
 src/media_source/media_tree.c | 22 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/vlc_media_source.h b/include/vlc_media_source.h
index 02c94eb5d5..36e1f9a0b8 100644
--- a/include/vlc_media_source.h
+++ b/include/vlc_media_source.h
@@ -111,6 +111,19 @@ struct vlc_media_tree_callbacks
     (*on_children_removed)(vlc_media_tree_t *tree, input_item_node_t *node,
                            input_item_node_t *const children[], size_t count,
                            void *userdata);
+
+    /**
+     * Called when the preparsing of a node is complete
+     *
+     * \param tree     the media tree
+     * \param node     the node being parsed
+     * \param status   the reason for the preparsing termination
+     * \param userdata userdata provided to AddListener()
+     */
+    void
+    (*on_preparse_end)(vlc_media_tree_t *tree, input_item_node_t * node,
+                       enum input_item_preparse_status status,
+                       void *userdata);
 };
 
 /**
diff --git a/src/media_source/media_tree.c b/src/media_source/media_tree.c
index 031bd21515..a3c63b3d1f 100644
--- a/src/media_source/media_tree.c
+++ b/src/media_source/media_tree.c
@@ -168,6 +168,27 @@ media_subtree_changed(input_item_t *media, input_item_node_t *node,
     vlc_media_tree_Unlock(tree);
 }
 
+static void
+media_subtree_preparse_ended(input_item_t *media,
+                             enum input_item_preparse_status status,
+                             void *user_data)
+{
+    vlc_media_tree_t *tree = user_data;
+
+    vlc_media_tree_Lock(tree);
+    input_item_node_t *subtree_root;
+    /* TODO retrieve the node without traversing the tree */
+    bool found = vlc_media_tree_FindNodeByMedia(&tree->root, media,
+                                                &subtree_root, NULL);
+    if (!found) {
+        /* the node probably failed to be allocated */
+        vlc_media_tree_Unlock(tree);
+        return;
+    }
+    vlc_media_tree_Notify(tree, on_preparse_end, subtree_root, status);
+    vlc_media_tree_Unlock(tree);
+}
+
 static inline void
 vlc_media_tree_DestroyRootNode(vlc_media_tree_t *tree)
 {
@@ -316,6 +337,7 @@ vlc_media_tree_Remove(vlc_media_tree_t *tree, input_item_t *media)
 
 static const input_preparser_callbacks_t input_preparser_callbacks = {
     .on_subtree_added = media_subtree_changed,
+    .on_preparse_ended = media_subtree_preparse_ended
 };
 
 void
-- 
2.17.1



More information about the vlc-devel mailing list