[vlc-devel] [PATCH 1/3] prepaser: change options handling

Thomas Guillem thomas at gllm.fr
Thu Aug 22 14:22:52 CEST 2019


Reminder of the current behavior: the meta fetcher is either always triggered
after the preparser is finished or manually.

This commit aims to give more controls so that the meta fetcher is not
necessarily triggered after a preparsng.

The current behavior of macOS/playlist/mediatree is unchanged (the components
touching the preparser).

Here are the API changes for

libvlc_MetadataRequest():

 - Can't be called without a valid META_REQUEST_OPTION_SCOPE_* flag

 - The flag META_REQUEST_OPTION_SCOPE_* is not fetching meta anymore. Use
   (META_REQUEST_OPTION_SCOPE_*|META_REQUEST_OPTION_FETCH_*) to fetch meta when
   the preparsing ends.

libvlc_ArtRequest():

 - Can't be called without a valid META_REQUEST_OPTION_FETCH_* flag.

 - The META_REQUEST_OPTION_FETCH_NETWORK flag will now only fetch meta via
   network.

libvlc_media_parse_with_options():

 - The flag libvlc_media_parse_* is not fetching meta anymore. Use
   libvlc_media_fetch_* to fetch meta when the preparsing ends.
 - The libvlc_media_fetch_network flag will now only fetch meta via network.
---
 include/vlc_input_item.h                        |  5 ++++-
 lib/media.c                                     |  7 ++++++-
 modules/gui/macosx/library/VLCInputItem.m       |  3 ++-
 modules/gui/qt/components/player_controller.cpp |  4 ++--
 src/libvlc.c                                    |  5 ++++-
 src/media_source/media_tree.c                   |  3 +--
 src/playlist/preparse.c                         |  4 +++-
 src/preparser/fetcher.c                         |  7 +++++--
 src/preparser/preparser.c                       | 13 +++++++++----
 test/libvlc/media.c                             |  3 ++-
 10 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 492a442036..1c99f6c012 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -462,7 +462,10 @@ typedef enum input_item_meta_request_option_t
     META_REQUEST_OPTION_SCOPE_LOCAL   = 0x01,
     META_REQUEST_OPTION_SCOPE_NETWORK = 0x02,
     META_REQUEST_OPTION_SCOPE_ANY     = 0x03,
-    META_REQUEST_OPTION_DO_INTERACT   = 0x04
+    META_REQUEST_OPTION_FETCH_LOCAL   = 0x04,
+    META_REQUEST_OPTION_FETCH_NETWORK = 0x08,
+    META_REQUEST_OPTION_FETCH_ANY     = 0x0C,
+    META_REQUEST_OPTION_DO_INTERACT   = 0x10,
 } input_item_meta_request_option_t;
 
 /* status of the on_preparse_ended() callback */
diff --git a/lib/media.c b/lib/media.c
index 06d02bad8d..b190d0e268 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -806,9 +806,14 @@ static int media_parse(libvlc_media_t *media, bool b_async,
 
         if (parse_flag & libvlc_media_parse_network)
             parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
+        if (parse_flag & libvlc_media_fetch_local)
+            parse_scope |= META_REQUEST_OPTION_FETCH_LOCAL;
         if (parse_flag & libvlc_media_do_interact)
             parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
-        ret = libvlc_MetadataRequest(libvlc, item, parse_scope, &input_preparser_callbacks, media, timeout, media);
+
+        ret = libvlc_MetadataRequest(libvlc, item, parse_scope,
+                                     &input_preparser_callbacks, media,
+                                     timeout, media);
         if (ret != VLC_SUCCESS)
             return ret;
     }
diff --git a/modules/gui/macosx/library/VLCInputItem.m b/modules/gui/macosx/library/VLCInputItem.m
index 656874ddc8..556aae74f6 100644
--- a/modules/gui/macosx/library/VLCInputItem.m
+++ b/modules/gui/macosx/library/VLCInputItem.m
@@ -542,7 +542,8 @@ static const struct input_preparser_callbacks_t preparseCallbacks = {
 
     return libvlc_MetadataRequest(vlc_object_instance(getIntf()),
                                   _vlcInputItem,
-                                  META_REQUEST_OPTION_SCOPE_ANY,
+                                  META_REQUEST_OPTION_SCOPE_ANY |
+                                  META_REQUEST_OPTION_FETCH_LOCAL,
                                   &preparseCallbacks,
                                   (__bridge void *)self,
                                   -1, NULL);
diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index e73fc7e8ab..5b3de57421 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -1436,8 +1436,8 @@ void PlayerController::requestArtUpdate( input_item_t *p_item, bool b_forced )
                 return;
         }
         libvlc_ArtRequest( vlc_object_instance(d->p_intf), p_item,
-                           (b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
-                                      : META_REQUEST_OPTION_NONE,
+                           (b_forced) ? META_REQUEST_OPTION_FETCH_ANY
+                                      : META_REQUEST_OPTION_FETCH_LOCAL,
                            &input_fetcher_cbs, this );
     }
 }
diff --git a/src/libvlc.c b/src/libvlc.c
index 018987f0bf..76dc15885c 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -537,6 +537,7 @@ int libvlc_MetadataRequest(libvlc_int_t *libvlc, input_item_t *item,
                            int timeout, void *id)
 {
     libvlc_priv_t *priv = libvlc_priv(libvlc);
+    assert(i_options & META_REQUEST_OPTION_SCOPE_ANY);
 
     if (unlikely(priv->parser == NULL))
         return VLC_ENOMEM;
@@ -559,11 +560,13 @@ int libvlc_ArtRequest(libvlc_int_t *libvlc, input_item_t *item,
                       void *cbs_userdata)
 {
     libvlc_priv_t *priv = libvlc_priv(libvlc);
+    assert(i_options & META_REQUEST_OPTION_FETCH_ANY);
 
     if (unlikely(priv->parser == NULL))
         return VLC_ENOMEM;
 
-    input_preparser_fetcher_Push(priv->parser, item, i_options, cbs, cbs_userdata);
+    input_preparser_fetcher_Push(priv->parser, item, i_options,
+                                 cbs, cbs_userdata);
     return VLC_SUCCESS;
 }
 
diff --git a/src/media_source/media_tree.c b/src/media_source/media_tree.c
index 4fa79c1716..e83fc0afe4 100644
--- a/src/media_source/media_tree.c
+++ b/src/media_source/media_tree.c
@@ -329,8 +329,7 @@ vlc_media_tree_Preparse(vlc_media_tree_t *tree, libvlc_int_t *libvlc,
     VLC_UNUSED(input_preparser_callbacks);
 #else
     media->i_preparse_depth = 1;
-    vlc_MetadataRequest(libvlc, media, META_REQUEST_OPTION_SCOPE_LOCAL |
-                        META_REQUEST_OPTION_SCOPE_NETWORK,
+    vlc_MetadataRequest(libvlc, media, META_REQUEST_OPTION_SCOPE_ANY,
                         &input_preparser_callbacks, tree, -1, NULL);
 #endif
 }
diff --git a/src/playlist/preparse.c b/src/playlist/preparse.c
index 9955aec7ff..11f6faff41 100644
--- a/src/playlist/preparse.c
+++ b/src/playlist/preparse.c
@@ -120,7 +120,9 @@ vlc_playlist_Preparse(vlc_playlist_t *playlist, input_item_t *input)
     VLC_UNUSED(input_preparser_callbacks);
 #else
     /* vlc_MetadataRequest is not exported */
-    vlc_MetadataRequest(playlist->libvlc, input, META_REQUEST_OPTION_NONE,
+    vlc_MetadataRequest(playlist->libvlc, input,
+                        META_REQUEST_OPTION_SCOPE_LOCAL |
+                        META_REQUEST_OPTION_FETCH_LOCAL,
                         &input_preparser_callbacks, playlist, -1, NULL);
 #endif
 }
diff --git a/src/preparser/fetcher.c b/src/preparser/fetcher.c
index a49090c2fe..ac5c3eba21 100644
--- a/src/preparser/fetcher.c
+++ b/src/preparser/fetcher.c
@@ -294,7 +294,7 @@ static void SearchLocal( input_fetcher_t* fetcher, struct fetcher_request* req )
         return; /* done */
 
     if( var_InheritBool( fetcher->owner, "metadata-network-access" ) ||
-        req->options & META_REQUEST_OPTION_SCOPE_NETWORK )
+        req->options & META_REQUEST_OPTION_FETCH_NETWORK )
     {
         if( background_worker_Push( fetcher->network, req, NULL, 0 ) )
             NotifyArtFetchEnded(req, false);
@@ -451,6 +451,7 @@ int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
     input_item_meta_request_option_t options,
     const input_fetcher_callbacks_t *cbs, void *cbs_userdata )
 {
+    assert(options & META_REQUEST_OPTION_FETCH_ANY);
     struct fetcher_request* req = malloc( sizeof *req );
 
     if( unlikely( !req ) )
@@ -464,7 +465,9 @@ int input_fetcher_Push( input_fetcher_t* fetcher, input_item_t* item,
     vlc_atomic_rc_init( &req->rc );
     input_item_Hold( item );
 
-    if( background_worker_Push( fetcher->local, req, NULL, 0 ) )
+    struct background_worker* worker =
+        options & META_REQUEST_OPTION_FETCH_LOCAL ? fetcher->local : fetcher->network;
+    if( background_worker_Push( worker, req, NULL, 0 ) )
         NotifyArtFetchEnded(req, false);
 
     RequestRelease( req );
diff --git a/src/preparser/preparser.c b/src/preparser/preparser.c
index f59519aef1..f3f678a2e1 100644
--- a/src/preparser/preparser.c
+++ b/src/preparser/preparser.c
@@ -42,6 +42,7 @@ struct input_preparser_t
 typedef struct input_preparser_req_t
 {
     input_item_t *item;
+    input_item_meta_request_option_t options;
     const input_preparser_callbacks_t *cbs;
     void *userdata;
     vlc_atomic_rc_t rc;
@@ -58,6 +59,7 @@ typedef struct input_preparser_task_t
 } input_preparser_task_t;
 
 static input_preparser_req_t *ReqCreate(input_item_t *item,
+                                        input_item_meta_request_option_t options,
                                         const input_preparser_callbacks_t *cbs,
                                         void *userdata)
 {
@@ -66,6 +68,7 @@ static input_preparser_req_t *ReqCreate(input_item_t *item,
         return NULL;
 
     req->item = item;
+    req->options = options;
     req->cbs = cbs;
     req->userdata = userdata;
     vlc_atomic_rc_init(&req->rc);
@@ -197,11 +200,12 @@ static void PreparserCloseInput( void* preparser_, void* task_ )
 
     input_item_parser_id_Release( task->parser );
 
-    if( preparser->fetcher )
+    if( preparser->fetcher && (req->options & META_REQUEST_OPTION_FETCH_ANY) )
     {
         task->preparse_status = status;
-        if (!input_fetcher_Push(preparser->fetcher, item, 0,
-                               &input_fetcher_callbacks, task))
+        if (!input_fetcher_Push(preparser->fetcher, item,
+                                req->options & META_REQUEST_OPTION_FETCH_ANY,
+                                &input_fetcher_callbacks, task))
         {
             ReqHold(task->req);
             return;
@@ -280,7 +284,8 @@ void input_preparser_Push( input_preparser_t *preparser,
             return;
     }
 
-    struct input_preparser_req_t *req = ReqCreate(item, cbs, cbs_userdata);
+    struct input_preparser_req_t *req = ReqCreate(item, i_options,
+                                                  cbs, cbs_userdata);
 
     if (background_worker_Push(preparser->worker, req, id, timeout))
         if (req->cbs && cbs->on_preparse_ended)
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index d6e2484357..285fed32bc 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -159,7 +159,8 @@ static void test_input_metadata_timeout(libvlc_instance_t *vlc, int timeout,
         .on_preparse_ended = input_item_preparse_timeout,
     };
     i_ret = libvlc_MetadataRequest(vlc->p_libvlc_int, p_item,
-                                   META_REQUEST_OPTION_SCOPE_LOCAL,
+                                   META_REQUEST_OPTION_SCOPE_LOCAL |
+                                   META_REQUEST_OPTION_FETCH_LOCAL,
                                    &cbs, &sem, timeout, vlc);
     assert(i_ret == 0);
 
-- 
2.20.1



More information about the vlc-devel mailing list