[vlc-commits] modules: add --no-plugins-scan option to turn off directory scanning

Rémi Denis-Courmont git at videolan.org
Fri Oct 28 10:01:09 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Oct 28 10:55:19 2016 +0300| [851257809ce616fa5614b86e614eb5c1f82898cf] | committer: Rémi Denis-Courmont

modules: add --no-plugins-scan option to turn off directory scanning

With that options, plugins are *only* loaded from the cache. This
reduces the run time of libvlc_new() (about 2.5x on my system).

But new plugins won´t be picked up until the cache is regenerated.

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

 src/libvlc-module.c |  7 +++++++
 src/modules/bank.c  | 47 +++++++++++++++++++++++++++++------------------
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index ea13769..3b95d5c 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1034,6 +1034,11 @@ static const char *const ppsz_prefres[] = {
 #define PLUGINS_CACHE_LONGTEXT N_( \
     "Use a plugins cache which will greatly improve the startup time of VLC.")
 
+#define PLUGINS_SCAN_TEXT N_("Scan for new plugins")
+#define PLUGINS_SCAN_LONGTEXT N_( \
+    "Scan plugin directories for new plugins at startup. " \
+    "This increases the startup time of VLC.")
+
 #define KEYSTORE_TEXT N_("Preferred keystore list")
 #define KEYSTORE_LONGTEXT N_( \
     "List of keystores that VLC will use in " \
@@ -1968,6 +1973,8 @@ vlc_module_begin ()
     set_section( N_("Plugins" ), NULL )
     add_bool( "plugins-cache", true, PLUGINS_CACHE_TEXT,
               PLUGINS_CACHE_LONGTEXT, true )
+    add_bool( "plugins-scan", true, PLUGINS_SCAN_TEXT,
+              PLUGINS_SCAN_LONGTEXT, true )
     add_obsolete_string( "plugin-path" ) /* since 2.0.0 */
     add_obsolete_string( "data-path" ) /* since 2.1.0 */
     add_string( "keystore", NULL, KEYSTORE_TEXT,
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 3867337..62ee779 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -148,7 +148,12 @@ error:
     return NULL;
 }
 
-typedef enum { CACHE_USE, CACHE_RESET, CACHE_IGNORE } cache_mode_t;
+typedef enum
+{
+    CACHE_READ_FILE  = 0x1,
+    CACHE_SCAN_DIR   = 0x2,
+    CACHE_WRITE_FILE = 0x4,
+} cache_mode_t;
 
 typedef struct module_bank
 {
@@ -170,7 +175,7 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
     vlc_plugin_t *plugin = NULL;
 
     /* Check our plugins cache first then load plugin if needed */
-    if (bank->mode == CACHE_USE)
+    if (bank->mode & CACHE_READ_FILE)
     {
         plugin = vlc_cache_lookup(&bank->cache, relpath);
 
@@ -202,7 +207,7 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
 
     module_StoreBank(plugin);
 
-    if (bank->mode == CACHE_RESET) /* Add entry to to-be-saved cache */
+    if (bank->mode & CACHE_WRITE_FILE) /* Add entry to to-be-saved cache */
     {
         bank->plugins = xrealloc(bank->plugins,
                                  (bank->size + 1) * sizeof (vlc_plugin_t *));
@@ -305,26 +310,32 @@ static void AllocatePluginPath(vlc_object_t *obj, const char *path,
         .mode = mode,
     };
 
-    if (mode == CACHE_USE)
+    if (mode & CACHE_READ_FILE)
         bank.cache = vlc_cache_load(obj, path, &modules.caches);
     else
         msg_Dbg(bank.obj, "ignoring plugins cache file");
 
-    msg_Dbg(obj, "recursively browsing `%s'", bank.base);
+    if (mode & CACHE_SCAN_DIR)
+    {
+        msg_Dbg(obj, "recursively browsing `%s'", bank.base);
 
-    /* Don't go deeper than 5 subdirectories */
-    AllocatePluginDir (&bank, 5, path, NULL);
+        /* Don't go deeper than 5 subdirectories */
+        AllocatePluginDir(&bank, 5, path, NULL);
+    }
 
-    /* Discard unmatched cache entries */
+    /* Deal with unmatched cache entries from cache file */
     while (bank.cache != NULL)
     {
         vlc_plugin_t *plugin = bank.cache;
 
         bank.cache = plugin->next;
-        vlc_plugin_destroy(plugin);
+        if (mode & CACHE_SCAN_DIR)
+            vlc_plugin_destroy(plugin);
+        else
+            module_StoreBank(plugin);
     }
 
-    if (mode == CACHE_RESET)
+    if (mode & CACHE_WRITE_FILE)
         CacheSave(obj, path, bank.plugins, bank.size);
 
     free(bank.plugins);
@@ -341,14 +352,14 @@ static void AllocatePluginPath(vlc_object_t *obj, const char *path,
 static void AllocateAllPlugins (vlc_object_t *p_this)
 {
     char *paths;
-    cache_mode_t mode;
-
-    if( !var_InheritBool( p_this, "plugins-cache" ) )
-        mode = CACHE_IGNORE;
-    else if( var_InheritBool( p_this, "reset-plugins-cache" ) )
-        mode = CACHE_RESET;
-    else
-        mode = CACHE_USE;
+    cache_mode_t mode = 0;
+
+    if (var_InheritBool(p_this, "plugins-cache"))
+        mode |= CACHE_READ_FILE;
+    if (var_InheritBool(p_this, "plugins-scan"))
+        mode |= CACHE_SCAN_DIR;
+    if (var_InheritBool(p_this, "reset-plugins-cache"))
+        mode = (mode | CACHE_WRITE_FILE) & ~CACHE_READ_FILE;
 
 #if VLC_WINSTORE_APP
     /* Windows Store Apps can not load external plugins with absolute paths. */



More information about the vlc-commits mailing list