[vlc-devel] [PATCH] add function libvlc_set_plugin_path

Костромин Дмитрий Андреевич kostromin at bolid.ru
Wed Dec 2 13:25:05 CET 2015


-- 
С уважением, Костромин Дмитрий Андреевич,
руководитель подразделения ЗАО НВП "Болид"
г.Орехово-Зуево

-------------- next part --------------
From b26e43f9f5184c3a7cd38436c972aefd6b3db033 Mon Sep 17 00:00:00 2001
From: kostromin <kostromin at bolid.ru>
Date: Wed, 2 Dec 2015 15:22:10 +0400
Subject: [PATCH] Added function libvlc_set_plugin_path (default plugins search
 path)

Using enviroment variable VLC_PLUGIN_PATH works only if you use runtime
similar to libvlc runtime. If runtime lib of your main project differs from
libvlc runtime lib(or your application is neither C++ nor C project)
setting of VLC_PLUGIN_PATH gives nothing, because function getenv used
inside of vlc core returns cached values of env variables. So developers
must have some mechanism of setting plugins search path.
---
 include/vlc/libvlc.h  | 11 +++++++++++
 lib/core.c            |  5 +++++
 lib/libvlc_internal.h |  2 ++
 src/libvlc.c          | 10 ++++++++++
 src/libvlccore.sym    |  1 +
 src/modules/bank.c    | 37 +++++++++++++++++++++++++++++--------
 src/modules/modules.h |  1 +
 7 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 68023ef..8f936e7 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -116,6 +116,17 @@ LIBVLC_API const char *libvlc_printerr (const char *fmt, ...);
 /**@} */
 
 /**
+ * Sets the LibVLC plugins search path 
+ * \note This function should be called before libvlc_new. Normally you can 
+ * use VLC_PLUGIN_PATH enviroment variable to set plugin search path, but 
+ * if your runtime differs from libvlc runtime, setting of VLC_PLUGIN_PATH won't 
+ * work
+ *
+ * \param path the search path
+ */
+LIBVLC_API void libvlc_set_plugin_path (const char *path);
+
+/**
  * Create and initialize a libvlc instance.
  * This functions accept a list of "command line" arguments similar to the
  * main(). These arguments affect the LibVLC instance default configuration.
diff --git a/lib/core.c b/lib/core.c
index fa5c4de..1a6329c 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -38,6 +38,11 @@
 
 #include "../src/revision.c"
 
+void libvlc_set_plugin_path ( const char *path )
+{
+	libvlc_InternalSetAltPath( path );
+}
+
 libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
 {
     libvlc_threads_init ();
diff --git a/lib/libvlc_internal.h b/lib/libvlc_internal.h
index b37b749..b6bc2c5 100644
--- a/lib/libvlc_internal.h
+++ b/lib/libvlc_internal.h
@@ -53,6 +53,8 @@ VLC_API void libvlc_InternalPlay( libvlc_int_t * );
 VLC_API void libvlc_InternalWait( libvlc_int_t * );
 VLC_API void libvlc_SetExitHandler( libvlc_int_t *, void (*) (void *), void * );
 
+VLC_API void libvlc_InternalSetAltPath( const char* );
+
 typedef void (*libvlc_vlm_release_func_t)( libvlc_instance_t * ) ;
 
 /***************************************************************************
diff --git a/src/libvlc.c b/src/libvlc.c
index a7d9a69..c571f4e 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -84,6 +84,16 @@
 static void GetFilenames  ( libvlc_int_t *, unsigned, const char *const [] );
 
 /**
+ * Set alternative search plugin path
+ *
+ * \param psz_path alternative plugin path
+ */
+void libvlc_InternalSetAltPath( const char* psz_path)
+{
+	module_SetAltPluginsPath( psz_path );
+}
+
+/**
  * Allocate a blank libvlc instance, also setting the exit handler.
  * Vlc's threading system must have been initialized first
  */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 95152e8..79f3a8d 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -234,6 +234,7 @@ libvlc_InternalCleanup
 libvlc_InternalCreate
 libvlc_InternalDestroy
 libvlc_InternalInit
+libvlc_InternalSetAltPath
 libvlc_Quit
 libvlc_SetExitHandler
 libvlc_MetaRequest
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 19292e6..198d1dc 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -56,6 +56,7 @@ static struct
  * Local prototypes
  *****************************************************************************/
 #ifdef HAVE_DYNAMIC_PLUGINS
+static char * psz_alt_plugins_search_path = NULL;
 static void AllocateAllPlugins (vlc_object_t *);
 #endif
 static module_t *module_InitStatic (vlc_plugin_cb);
@@ -164,6 +165,18 @@ void module_EndBank (bool b_plugins)
     }
 }
 
+/**
+ * Set alternative search plugin path
+ *
+ * \param psz_path alternative plugin path
+ */
+void module_SetAltPluginsPath(const char *psz_path)
+{
+#ifdef HAVE_DYNAMIC_PLUGINS
+	psz_alt_plugins_search_path = strdup(psz_path);
+#endif
+}
+
 #undef module_LoadPlugins
 /**
  * Loads module descriptions for all available plugins.
@@ -300,6 +313,7 @@ static void AllocatePluginPath (vlc_object_t *, const char *, cache_mode_t);
  *
  * This function will recursively browse the default plug-ins directory and any
  * directory listed in the VLC_PLUGIN_PATH environment variable.
+ * Additionaly you may override search path with libvlc_set_plugin_path function.
  * For performance reasons, a cache is normally used so that plug-in shared
  * objects do not need to loaded and linked into the process.
  */
@@ -321,16 +335,23 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
 #else
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/plugins. */
-    char *vlcpath = config_GetLibDir ();
-    if (likely(vlcpath != NULL)
-     && likely(asprintf (&paths, "%s" DIR_SEP "plugins", vlcpath) != -1))
-    {
-        AllocatePluginPath (p_this, paths, mode);
-        free( paths );
-    }
-    free (vlcpath);
+	if (psz_alt_plugins_search_path == NULL)
+	{
+		char *vlcpath = config_GetLibDir ();
+		if (likely(vlcpath != NULL)
+		 && likely(asprintf (&paths, "%s" DIR_SEP "plugins", vlcpath) != -1))
+		{
+			AllocatePluginPath (p_this, paths, mode);
+			free( paths );
+		}
+		free (vlcpath);
+	}
 #endif /* VLC_WINSTORE_APP */
 
+	/* Check alternative plugin path */
+	if (psz_alt_plugins_search_path != NULL)
+		AllocatePluginPath (p_this, psz_alt_plugins_search_path, mode);
+	
     /* If the user provided a plugin path, we add it to the list */
     paths = getenv( "VLC_PLUGIN_PATH" );
     if( paths == NULL )
diff --git a/src/modules/modules.h b/src/modules/modules.h
index e38e952..001f361 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -105,6 +105,7 @@ module_t *vlc_module_create (module_t *);
 void vlc_module_destroy (module_t *);
 
 void module_InitBank (void);
+void module_SetAltPluginsPath( const char * );
 size_t module_LoadPlugins( vlc_object_t * );
 #define module_LoadPlugins(a) module_LoadPlugins(VLC_OBJECT(a))
 void module_EndBank (bool);
-- 
2.6.1.windows.1



More information about the vlc-devel mailing list