[vlc-commits] [Git][videolan/vlc][master] 12 commits: input: add preparsing.subitems handling

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Oct 5 10:07:22 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
cdf5342b by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: add preparsing.subitems handling

This will replace input_item_ShouldPreparseSubItems() and i_preparse_depth

- - - - -
0f857d86 by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: parser: add an option to parse subitems

- - - - -
d971b177 by Thomas Guillem at 2024-10-05T09:54:40+00:00
preparser: add an option to parse subitems

- - - - -
55bebd41 by Thomas Guillem at 2024-10-05T09:54:40+00:00
playlist: handle recursive parsing

Read the "recursive" option and behave accordingly (expand, collapse,
none).

- - - - -
b1564955 by Thomas Guillem at 2024-10-05T09:54:40+00:00
media_tree: use META_REQUEST_OPTION_PARSE_SUBITEMS

Instead of i_preparse_depth

- - - - -
1bac5b67 by Thomas Guillem at 2024-10-05T09:54:40+00:00
lib: use META_REQUEST_OPTION_PARSE_SUBITEMS

Instead of i_preparse_depth

- - - - -
92d575f5 by Thomas Guillem at 2024-10-05T09:54:40+00:00
medialibrary: use subitems option in input_item_Parse()

Instead of i_preparse_depth.

- - - - -
1b3c08bd by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: remove i_preparse_depth

- - - - -
ba24b79a by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: add interact handling

This will replace input_item_t.b_preparse_interact

- - - - -
e1a6eec4 by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: parser: add an option to enable interaction

- - - - -
8a03232a by Thomas Guillem at 2024-10-05T09:54:40+00:00
preparser: use input_item_parser_cfg interact option

- - - - -
91bff6e2 by Thomas Guillem at 2024-10-05T09:54:40+00:00
input: item: remove b_preparse_interact

- - - - -


20 changed files:

- include/vlc_input_item.h
- include/vlc_playlist.h
- lib/media.c
- modules/gui/macosx/library/VLCInputItem.m
- modules/gui/qt/dialogs/dialogs_provider.cpp
- modules/misc/medialibrary/MetadataExtractor.cpp
- modules/misc/medialibrary/fs/directory.cpp
- src/input/input.c
- src/input/input_internal.h
- src/input/item.c
- src/input/item.h
- src/input/parse.c
- src/libvlc.c
- src/media_source/media_tree.c
- src/playlist/content.c
- src/playlist/playlist.c
- src/playlist/playlist.h
- src/playlist/preparse.c
- src/playlist/preparse.h
- src/preparser/preparser.c


Changes:

=====================================
include/vlc_input_item.h
=====================================
@@ -130,12 +130,6 @@ struct input_item_t
     bool        b_net;               /**< Net: always true for TYPE_STREAM, it
                                           depends for others types */
 
-    int         i_preparse_depth;    /**< How many level of sub items can be preparsed:
-                                          -1: recursive, 0: none, >0: n levels */
-
-    bool        b_preparse_interact; /**< Force interaction with the user when
-                                          preparsing.*/
-
     void        *libvlc_owner;       /**< LibVLC private data, can only be set
                                           before events are registered. */
 };
@@ -472,6 +466,10 @@ struct input_item_parser_cfg {
     const input_item_parser_cbs_t *cbs;
     /** Opaque data used by parser callbacks */
     void *cbs_data;
+    /** true to parse subitems (from a folder or a playlist file) */
+    bool subitems;
+    /** true to trigger dialog interactions when needed */
+    bool interact;
 };
 
 /**
@@ -525,6 +523,7 @@ typedef enum input_item_meta_request_option_t
     META_REQUEST_OPTION_FETCH_ANY     =
         META_REQUEST_OPTION_FETCH_LOCAL|META_REQUEST_OPTION_FETCH_NETWORK,
     META_REQUEST_OPTION_DO_INTERACT   = 0x20,
+    META_REQUEST_OPTION_PARSE_SUBITEMS = 0x40,
 } input_item_meta_request_option_t;
 
 /* status of the on_preparse_ended() callback */


=====================================
include/vlc_playlist.h
=====================================
@@ -901,9 +901,11 @@ vlc_playlist_PlayAt(vlc_playlist_t *playlist, size_t index)
  *
  * \param playlist the playlist (not necessarily locked)
  * \param media the media to preparse
+ * \param parse_subitems true to parse subitems (from a folder or a playlist file)
  */
 VLC_API void
-vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *media);
+vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *media,
+                      bool parse_subitems);
 
 /**
  * Export the playlist to a file.


=====================================
lib/media.c
=====================================
@@ -767,6 +767,7 @@ int libvlc_media_parse_request(libvlc_instance_t *inst, libvlc_media_t *media,
         parse_scope |= META_REQUEST_OPTION_FETCH_NETWORK;
     if (parse_flag & libvlc_media_do_interact)
         parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
+    parse_scope |= META_REQUEST_OPTION_PARSE_SUBITEMS;
 
     ret = libvlc_MetadataRequest(libvlc, item, parse_scope,
                                  &preparser_callbacks, media,


=====================================
modules/gui/macosx/library/VLCInputItem.m
=====================================
@@ -592,7 +592,8 @@ static const struct vlc_metadata_cbs preparseCallbacks = {
     return libvlc_MetadataRequest(vlc_object_instance(getIntf()),
                                   _vlcInputItem,
                                   META_REQUEST_OPTION_SCOPE_ANY |
-                                  META_REQUEST_OPTION_FETCH_LOCAL,
+                                  META_REQUEST_OPTION_FETCH_LOCAL |
+                                  META_REQUEST_OPTION_PARSE_SUBITEMS,
                                   &preparseCallbacks,
                                   (__bridge void *)self,
                                   -1, NULL);


=====================================
modules/gui/qt/dialogs/dialogs_provider.cpp
=====================================
@@ -387,7 +387,7 @@ void DialogsProvider::mediaInfoDialog( const MLItemId& itemId )
 
         const int result = libvlc_MetadataRequest( vlc_object_instance( p_intf ),
                                                    inputItem,
-                                                   static_cast<input_item_meta_request_option_t>(META_REQUEST_OPTION_SCOPE_ANY | META_REQUEST_OPTION_SCOPE_FORCED),
+                                                   static_cast<input_item_meta_request_option_t>(META_REQUEST_OPTION_SCOPE_ANY | META_REQUEST_OPTION_SCOPE_FORCED | META_REQUEST_OPTION_PARSE_SUBITEMS),
                                                    &cbs,
                                                    this,
                                                    0,


=====================================
modules/misc/medialibrary/MetadataExtractor.cpp
=====================================
@@ -236,9 +236,10 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
     const struct input_item_parser_cfg cfg= {
         .cbs = &cbs,
         .cbs_data = std::addressof( ctx ),
+        .subitems = true,
+        .interact = false,
     };
     m_currentCtx = &ctx;
-    ctx.inputItem->i_preparse_depth = 1;
     ctx.inputParser = {
         input_item_Parse( m_obj, ctx.inputItem.get(), &cfg ),
         &input_item_parser_id_Release


=====================================
modules/misc/medialibrary/fs/directory.cpp
=====================================
@@ -162,8 +162,6 @@ static bool request_metadata_sync( libvlc_int_t *libvlc, input_item_t *media,
     req.probe = false;
     auto deadline = vlc_tick_now() + VLC_TICK_FROM_SEC( 15 );
 
-    media->i_preparse_depth = 1;
-
     static const input_item_parser_cbs_t cbs = {
         onParserEnded,
         onParserSubtreeAdded,
@@ -173,6 +171,8 @@ static bool request_metadata_sync( libvlc_int_t *libvlc, input_item_t *media,
     const struct input_item_parser_cfg cfg= {
         .cbs = &cbs,
         .cbs_data = &req,
+        .subitems = true,
+        .interact = false,
     };
 
     auto inputParser = vlc::wrap_cptr( input_item_Parse( VLC_OBJECT( libvlc ), media, &cfg ),


=====================================
src/input/input.c
=====================================
@@ -252,6 +252,7 @@ input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *p_item,
     priv->cbs = cfg->cbs;
     priv->cbs_data = cfg->cbs_data;
     priv->type = cfg->type;
+    priv->preparse_subitems = cfg->preparsing.subitems;
     priv->i_start = 0;
     priv->i_stop  = 0;
     priv->i_title_offset = input_priv(p_input)->i_seekpoint_offset = 0;
@@ -283,34 +284,16 @@ input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *p_item,
     if( !p_item->p_stats )
         p_item->p_stats = calloc( 1, sizeof(*p_item->p_stats) );
 
-    /* setup the preparse depth of the item
-     * if we are preparsing, use the i_preparse_depth of the parent item */
     if( priv->type != INPUT_TYPE_PLAYBACK )
     {
         p_input->obj.logger = NULL;
         p_input->obj.no_interact = true;
     }
-    else
-    {
-        char *psz_rec = var_InheritString( p_parent, "recursive" );
-
-        if( psz_rec != NULL )
-        {
-            if ( !strcasecmp( psz_rec, "none" ) )
-                p_item->i_preparse_depth = 0;
-            else if ( !strcasecmp( psz_rec, "collapse" ) )
-                p_item->i_preparse_depth = 1;
-            else
-                p_item->i_preparse_depth = -1; /* default is expand */
-            free (psz_rec);
-        } else
-            p_item->i_preparse_depth = -1;
-    }
 
     /* Make sure the interaction option is honored */
     if( !var_InheritBool( p_input, "interact" ) )
         p_input->obj.no_interact = true;
-    else if( p_item->b_preparse_interact )
+    else if( cfg->interact )
     {
         /* If true, this item was asked explicitly to interact with the user
          * (via libvlc_MetadataRequest). Sub items created from this input won't
@@ -437,7 +420,7 @@ static void *Preparse( void *data )
     if( !Init( p_input ) )
     {   /* if the demux is a playlist, call Mainloop that will call
          * demux_Demux in order to fetch sub items */
-        if ( input_item_ShouldPreparseSubItems( priv->p_item )
+        if( priv->preparse_subitems
          && priv->master->p_demux->pf_readdir != NULL )
             MainLoop( p_input, false );
         End( p_input );


=====================================
src/input/input_internal.h
=====================================
@@ -334,6 +334,11 @@ struct vlc_input_thread_cfg
     vlc_renderer_item_t *renderer;
     const struct vlc_input_thread_callbacks *cbs;
     void *cbs_data;
+
+    struct {
+        bool subitems;
+    } preparsing;
+    bool interact;
 };
 /**
  * Create a new input_thread_t.
@@ -441,6 +446,7 @@ typedef struct input_thread_private_t
     void *cbs_data;
 
     enum input_type type;
+    bool preparse_subitems;
 
     /* Current state */
     int         i_state;


=====================================
src/input/item.c
=====================================
@@ -398,17 +398,6 @@ bool input_item_IsArtFetched( input_item_t *p_item )
     return b_fetched;
 }
 
-bool input_item_ShouldPreparseSubItems( input_item_t *p_item )
-{
-    bool b_ret;
-
-    vlc_mutex_lock( &p_item->lock );
-    b_ret = p_item->i_preparse_depth == -1 ? true : p_item->i_preparse_depth > 0;
-    vlc_mutex_unlock( &p_item->lock );
-
-    return b_ret;
-}
-
 input_item_t *input_item_Hold( input_item_t *p_item )
 {
     input_item_owner_t *owner = item_owner(p_item);
@@ -1206,20 +1195,9 @@ void input_item_node_Delete( input_item_node_t *p_node )
 
 input_item_node_t *input_item_node_AppendItem( input_item_node_t *p_node, input_item_t *p_item )
 {
-    int i_preparse_depth;
     input_item_node_t *p_new_child = input_item_node_Create( p_item );
     if( !p_new_child ) return NULL;
 
-    vlc_mutex_lock( &p_node->p_item->lock );
-    i_preparse_depth = p_node->p_item->i_preparse_depth;
-    vlc_mutex_unlock( &p_node->p_item->lock );
-
-    vlc_mutex_lock( &p_item->lock );
-    p_item->i_preparse_depth = i_preparse_depth > 0 ?
-                               i_preparse_depth -1 :
-                               i_preparse_depth;
-    vlc_mutex_unlock( &p_item->lock );
-
     input_item_node_AppendNode( p_node, p_new_child );
     return p_new_child;
 }


=====================================
src/input/item.h
=====================================
@@ -28,7 +28,6 @@
 
 void input_item_UpdateTracksInfo( input_item_t *item, const es_format_t *fmt,
                                   const char *es_id, bool stable );
-bool input_item_ShouldPreparseSubItems( input_item_t *p_i );
 
 typedef struct input_item_owner
 {


=====================================
src/input/parse.c
=====================================
@@ -108,6 +108,8 @@ input_item_Parse(vlc_object_t *obj, input_item_t *item,
         .type = INPUT_TYPE_PREPARSING,
         .cbs = &input_cbs,
         .cbs_data = parser,
+        .preparsing.subitems = cfg->subitems,
+        .interact = cfg->interact,
     };
     parser->input = input_Create(obj, item, &input_cfg );
     if (!parser->input || input_Start(parser->input))


=====================================
src/libvlc.c
=====================================
@@ -487,11 +487,6 @@ int libvlc_MetadataRequest(libvlc_int_t *libvlc, input_item_t *item,
     if (unlikely(priv->parser == NULL))
         return VLC_ENOMEM;
 
-    vlc_mutex_lock( &item->lock );
-    if( item->i_preparse_depth == 0 )
-        item->i_preparse_depth = 1;
-    vlc_mutex_unlock( &item->lock );
-
     return vlc_MetadataRequest(libvlc, item, i_options, cbs, cbs_userdata, timeout, id);
 }
 


=====================================
src/media_source/media_tree.c
=====================================
@@ -350,9 +350,9 @@ vlc_media_tree_Preparse(vlc_media_tree_t *tree, libvlc_int_t *libvlc,
     VLC_UNUSED(id);
     VLC_UNUSED(preparser_callbacks);
 #else
-    media->i_preparse_depth = 1;
     vlc_MetadataRequest(libvlc, media, META_REQUEST_OPTION_SCOPE_ANY |
-                        META_REQUEST_OPTION_DO_INTERACT,
+                        META_REQUEST_OPTION_DO_INTERACT |
+                        META_REQUEST_OPTION_PARSE_SUBITEMS,
                         &preparser_callbacks, tree, 0, id);
 #endif
 }


=====================================
src/playlist/content.c
=====================================
@@ -58,7 +58,8 @@ vlc_playlist_ItemsReset(vlc_playlist_t *playlist)
 }
 
 static void
-vlc_playlist_ItemsInserted(vlc_playlist_t *playlist, size_t index, size_t count)
+vlc_playlist_ItemsInserted(vlc_playlist_t *playlist, size_t index, size_t count,
+                           bool subitems)
 {
     if (playlist->order == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM)
         randomizer_Add(&playlist->randomizer,
@@ -79,7 +80,7 @@ vlc_playlist_ItemsInserted(vlc_playlist_t *playlist, size_t index, size_t count)
     for (size_t i = index; i < index + count; ++i)
     {
         vlc_playlist_item_t *item = playlist->items.data[i];
-        vlc_playlist_AutoPreparse(playlist, item->media);
+        vlc_playlist_AutoPreparse(playlist, item->media, subitems);
     }
 }
 
@@ -175,7 +176,8 @@ vlc_playlist_ItemReplaced(vlc_playlist_t *playlist, size_t index)
                         &playlist->items.data[index], 1);
     vlc_playlist_state_NotifyChanges(playlist, &state);
 
-    vlc_playlist_AutoPreparse(playlist, playlist->items.data[index]->media);
+    vlc_playlist_AutoPreparse(playlist, playlist->items.data[index]->media,
+                              false);
 }
 
 size_t
@@ -282,7 +284,7 @@ vlc_playlist_Insert(vlc_playlist_t *playlist, size_t index,
         return ret;
     }
 
-    vlc_playlist_ItemsInserted(playlist, index, count);
+    vlc_playlist_ItemsInserted(playlist, index, count, true);
     vlc_playlist_UpdateNextMedia(playlist);
 
     return VLC_SUCCESS;
@@ -379,7 +381,7 @@ vlc_playlist_Expand(vlc_playlist_t *playlist, size_t index,
                 vlc_vector_remove_slice(&playlist->items, index + 1, count - 1);
                 return ret;
             }
-            vlc_playlist_ItemsInserted(playlist, index + 1, count - 1);
+            vlc_playlist_ItemsInserted(playlist, index + 1, count - 1, false);
         }
 
         if ((ssize_t) index == playlist->current)


=====================================
src/playlist/playlist.c
=====================================
@@ -54,6 +54,7 @@ vlc_playlist_New(vlc_object_t *parent)
     playlist->repeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
     playlist->order = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
     playlist->idgen = 0;
+    playlist->recursive = VLC_PLAYLIST_RECURSIVE_COLLAPSE;
 #ifdef TEST_PLAYLIST
     playlist->libvlc = NULL;
     playlist->auto_preparse = false;
@@ -61,6 +62,16 @@ vlc_playlist_New(vlc_object_t *parent)
     assert(parent);
     playlist->libvlc = vlc_object_instance(parent);
     playlist->auto_preparse = var_InheritBool(parent, "auto-preparse");
+
+    char *rec = var_InheritString(parent, "recursive");
+    if (rec != NULL)
+    {
+        if (!strcasecmp(rec, "none"))
+            playlist->recursive = VLC_PLAYLIST_RECURSIVE_NONE;
+        else if (!strcasecmp(rec, "expand"))
+            playlist->recursive = VLC_PLAYLIST_RECURSIVE_EXPAND;
+        free(rec);
+    }
 #endif
 
     return playlist;


=====================================
src/playlist/playlist.h
=====================================
@@ -44,12 +44,20 @@ typedef struct input_item_t input_item_t;
 
 typedef struct VLC_VECTOR(vlc_playlist_item_t *) playlist_item_vector_t;
 
+enum vlc_playlist_recursive_parsing
+{
+    VLC_PLAYLIST_RECURSIVE_NONE,
+    VLC_PLAYLIST_RECURSIVE_COLLAPSE,
+    VLC_PLAYLIST_RECURSIVE_EXPAND,
+};
+
 struct vlc_playlist
 {
     vlc_player_t *player;
     libvlc_int_t *libvlc;
     enum vlc_playlist_media_stopped_action stopped_action;
     bool auto_preparse;
+    enum vlc_playlist_recursive_parsing recursive;
     /* all remaining fields are protected by the lock of the player */
     struct vlc_player_listener_id *player_listener;
     playlist_item_vector_t items;


=====================================
src/playlist/preparse.c
=====================================
@@ -112,7 +112,8 @@ static const struct vlc_metadata_cbs preparser_callbacks = {
 };
 
 void
-vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *input)
+vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *input,
+                      bool parse_subitems)
 {
 #ifdef TEST_PLAYLIST
     VLC_UNUSED(playlist);
@@ -120,16 +121,34 @@ vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *input)
     VLC_UNUSED(preparser_callbacks);
 #else
     /* vlc_MetadataRequest is not exported */
-    vlc_MetadataRequest(playlist->libvlc, input,
-                        META_REQUEST_OPTION_SCOPE_LOCAL |
-                        META_REQUEST_OPTION_FETCH_LOCAL,
+    input_item_meta_request_option_t options =
+        META_REQUEST_OPTION_SCOPE_LOCAL | META_REQUEST_OPTION_FETCH_LOCAL;
+    if (parse_subitems)
+        options |= META_REQUEST_OPTION_PARSE_SUBITEMS;
+
+    vlc_MetadataRequest(playlist->libvlc, input, options,
                         &preparser_callbacks, playlist, -1, NULL);
 #endif
 }
 
 void
-vlc_playlist_AutoPreparse(vlc_playlist_t *playlist, input_item_t *input)
+vlc_playlist_AutoPreparse(vlc_playlist_t *playlist, input_item_t *input,
+                          bool parse_subitems)
 {
     if (playlist->auto_preparse && !input_item_IsPreparsed(input))
-        vlc_playlist_Preparse(playlist, input);
+    {
+        switch (playlist->recursive)
+        {
+            case VLC_PLAYLIST_RECURSIVE_NONE:
+                parse_subitems = false;
+                break;
+            case VLC_PLAYLIST_RECURSIVE_COLLAPSE:
+                break;
+            case VLC_PLAYLIST_RECURSIVE_EXPAND:
+                parse_subitems = true;
+                break;
+            default: vlc_assert_unreachable();
+        }
+        vlc_playlist_Preparse(playlist, input, parse_subitems);
+    }
 }


=====================================
src/playlist/preparse.h
=====================================
@@ -27,7 +27,8 @@ typedef struct vlc_playlist vlc_playlist_t;
 typedef struct input_item_node_t input_item_node_t;
 
 void
-vlc_playlist_AutoPreparse(vlc_playlist_t *playlist, input_item_t *input);
+vlc_playlist_AutoPreparse(vlc_playlist_t *playlist, input_item_t *input,
+                          bool parse_subitems);
 
 int
 vlc_playlist_ExpandItem(vlc_playlist_t *playlist, size_t index,


=====================================
src/preparser/preparser.c
=====================================
@@ -224,6 +224,8 @@ Parse(struct task *task, vlc_tick_t deadline)
     const struct input_item_parser_cfg cfg = {
         .cbs = &cbs,
         .cbs_data = task,
+        .subitems = task->options & META_REQUEST_OPTION_PARSE_SUBITEMS,
+        .interact = task->options & META_REQUEST_OPTION_DO_INTERACT,
     };
     task->parser = input_item_Parse(obj, task->item, &cfg);
     if (!task->parser)
@@ -358,8 +360,6 @@ int vlc_preparser_Push( vlc_preparser_t *preparser,
     vlc_mutex_lock( &item->lock );
     enum input_item_type_e i_type = item->i_type;
     int b_net = item->b_net;
-    if( i_options & META_REQUEST_OPTION_DO_INTERACT )
-        item->b_preparse_interact = true;
     vlc_mutex_unlock( &item->lock );
 
     if (!(i_options & META_REQUEST_OPTION_SCOPE_FORCED))



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6efacdce54cba4655e2d76976bd82257b90cd9f0...91bff6e2b2ab0cbb021ce57207c583bdd8ba87f9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6efacdce54cba4655e2d76976bd82257b90cd9f0...91bff6e2b2ab0cbb021ce57207c583bdd8ba87f9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list