[vlc-commits] libvlc: add an option to disable lua

Thomas Guillem git at videolan.org
Thu Oct 5 11:20:07 CEST 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Oct  5 10:00:33 2017 +0200| [c972cfd0f142d52ea1bf0afd87117036b5244839] | committer: Thomas Guillem

libvlc: add an option to disable lua

Playlist lua modules are probed for each opened input. This can take a lot of
time, it can double the time of a local parsing where no lua module are needed.
This time is negligible when playing a file.

Playlist lua probe can take 5ms on desktop (in comparison of 5ms for parsing),
or 50ms on some android devices.

This new option can be used by VLC ports to disable lua when using VLC for
parsing.

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

 modules/lua/demux.c              | 4 +++-
 modules/lua/extension.c          | 3 +++
 modules/lua/intf.c               | 3 +++
 modules/lua/meta.c               | 9 +++++++++
 modules/lua/services_discovery.c | 3 +++
 modules/lua/vlc.c                | 3 +++
 modules/lua/vlc.h                | 6 ++++++
 src/libvlc-module.c              | 5 +++++
 8 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/modules/lua/demux.c b/modules/lua/demux.c
index 70c5fe56be..a4ea3af1aa 100644
--- a/modules/lua/demux.c
+++ b/modules/lua/demux.c
@@ -275,8 +275,10 @@ static int ReadDir(stream_t *s, input_item_node_t *node)
  *****************************************************************************/
 int Import_LuaPlaylist(vlc_object_t *obj)
 {
-    stream_t *s = (stream_t *)obj;
+    if( lua_Disabled( obj ) )
+        return VLC_EGENERIC;
 
+    stream_t *s = (stream_t *)obj;
     if( !vlc_stream_Control( s->p_source, STREAM_IS_DIRECTORY ) )
         return VLC_EGENERIC;
 
diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index fbfccbc670..342ce21827 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -96,6 +96,9 @@ static void inputItemMetaChanged( const vlc_event_t *p_event,
  **/
 int Open_Extension( vlc_object_t *p_this )
 {
+    if( lua_Disabled( p_this ) )
+        return VLC_EGENERIC;
+
     msg_Dbg( p_this, "Opening Lua Extension module" );
 
     extensions_manager_t *p_mgr = ( extensions_manager_t* ) p_this;
diff --git a/modules/lua/intf.c b/modules/lua/intf.c
index a9f27e563a..7218a99380 100644
--- a/modules/lua/intf.c
+++ b/modules/lua/intf.c
@@ -201,6 +201,9 @@ static const luaL_Reg p_reg[] = { { NULL, NULL } };
 
 static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
 {
+    if( lua_Disabled( p_this ) )
+        return VLC_EGENERIC;
+
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
     lua_State *L;
 
diff --git a/modules/lua/meta.c b/modules/lua/meta.c
index 2dfba88403..be672f2a23 100644
--- a/modules/lua/meta.c
+++ b/modules/lua/meta.c
@@ -241,6 +241,9 @@ static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
 
 int ReadMeta( demux_meta_t *p_this )
 {
+    if( lua_Disabled( p_this ) )
+        return VLC_EGENERIC;
+
     return vlclua_scripts_batch_execute( VLC_OBJECT(p_this), "meta"DIR_SEP"reader",
                                          (void*) &read_meta, NULL );
 }
@@ -252,6 +255,9 @@ int ReadMeta( demux_meta_t *p_this )
 
 int FetchMeta( meta_fetcher_t *p_finder )
 {
+    if( lua_Disabled( p_finder ) )
+        return VLC_EGENERIC;
+
     luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
 
     return vlclua_scripts_batch_execute( VLC_OBJECT(p_finder), "meta"DIR_SEP"fetcher",
@@ -264,6 +270,9 @@ int FetchMeta( meta_fetcher_t *p_finder )
  *****************************************************************************/
 int FindArt( meta_fetcher_t *p_finder )
 {
+    if( lua_Disabled( p_finder ) )
+        return VLC_EGENERIC;
+
     luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
 
     return vlclua_scripts_batch_execute( VLC_OBJECT(p_finder), "meta"DIR_SEP"art",
diff --git a/modules/lua/services_discovery.c b/modules/lua/services_discovery.c
index f5581c7f9a..6d847dc212 100644
--- a/modules/lua/services_discovery.c
+++ b/modules/lua/services_discovery.c
@@ -154,6 +154,9 @@ static const luaL_Reg p_reg[] = { { NULL, NULL } };
  *****************************************************************************/
 int Open_LuaSD( vlc_object_t *p_this )
 {
+    if( lua_Disabled( p_this ) )
+        return VLC_EGENERIC;
+
     services_discovery_t *p_sd = ( services_discovery_t * )p_this;
     services_discovery_sys_t *p_sys;
     lua_State *L = NULL;
diff --git a/modules/lua/vlc.c b/modules/lua/vlc.c
index 512d9e505c..73c92d26b6 100644
--- a/modules/lua/vlc.c
+++ b/modules/lua/vlc.c
@@ -526,6 +526,9 @@ out:
 
 static int vlc_sd_probe_Open( vlc_object_t *obj )
 {
+    if( lua_Disabled( obj ) )
+        return VLC_EGENERIC;
+
     vlc_dictionary_t name_d;
 
     char **ppsz_dir_list;
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index 141f331329..71f381d334 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -105,6 +105,12 @@ static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
     va_end( ap );
 }
 
+static inline bool lua_Disabled( vlc_object_t *p_this )
+{
+    return !var_InheritBool( p_this, "lua" );
+}
+#define lua_Disabled( x ) lua_Disabled( VLC_OBJECT( x ) )
+
 /*****************************************************************************
  * Functions that should be in lua ... but aren't for some obscure reason
  *****************************************************************************/
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index ae6825fa12..6fe8e92ff6 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -690,6 +690,9 @@ static const char *const ppsz_prefres[] = {
     "$n: Track num<br>$p: Now playing<br>$A: Date<br>$D: Duration<br>"  \
     "$Z: \"Now playing\" (Fall back on Title - Artist)" )
 
+#define INPUT_LUA_TEXT N_( "Disable lua" )
+#define INPUT_LUA_LONGTEXT N_( "Disable all lua plugins" )
+
 // DEPRECATED
 #define SUB_CAT_LONGTEXT N_( \
     "These options allow you to modify the behavior of the subpictures " \
@@ -1900,6 +1903,8 @@ vlc_module_begin ()
 
     add_string( "input-title-format", "$Z", INPUT_TITLE_FORMAT_TEXT, INPUT_TITLE_FORMAT_LONGTEXT, false );
 
+    add_bool( "lua", true, INPUT_LUA_TEXT, INPUT_LUA_LONGTEXT, true );
+
 /* Decoder options */
     set_subcategory( SUBCAT_INPUT_VCODEC )
     add_category_hint( N_("Decoders"), CODEC_CAT_LONGTEXT , true )



More information about the vlc-commits mailing list