[vlc-devel] [PATCH] lua: add option to allow loading extension at startup

Pierre Lamot pierre at videolabs.io
Tue Oct 17 16:30:48 CEST 2017


---
 modules/lua/extension.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 modules/lua/vlc.c       |  4 ++++
 2 files changed, 51 insertions(+)

diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index 342ce21827..6f2818d5ee 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -96,6 +96,8 @@ static void inputItemMetaChanged( const vlc_event_t *p_event,
  **/
 int Open_Extension( vlc_object_t *p_this )
 {
+    char *psz_ext_parser, *psz_ext;
+
     if( lua_Disabled( p_this ) )
         return VLC_EGENERIC;
 
@@ -115,6 +117,51 @@ int Open_Extension( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+    //load extensions at startup
+    psz_ext_parser =  psz_ext = var_CreateGetString( p_mgr, "lua-extension-list" );
+    while ( psz_ext_parser && *psz_ext_parser != '\0' )
+    {
+        for ( int i = 0; i < p_mgr->extensions.i_size; i++ )
+        {
+            extension_t *p_ext = p_mgr->extensions.p_elems[i];
+            size_t i_ext_name_len = strlen( p_ext->psz_shortdescription );
+            if ( strncmp( p_ext->psz_shortdescription, psz_ext_parser, i_ext_name_len ) == 0 )
+            {
+                //don't activate the same extension twice, b_thread_running is used rather
+                //than querying EXTENSION_IS_ACTIVATED due to potential race condition
+                bool b_is_ext_running = false;
+                vlc_mutex_lock( &p_ext->p_sys->command_lock );
+                b_is_ext_running = p_ext->p_sys->b_thread_running;
+                vlc_mutex_unlock( &p_ext->p_sys->command_lock );
+
+                if ( b_is_ext_running )
+                {
+                    msg_Warn( p_mgr, "extension %s can't be loaded twices", p_ext->psz_shortdescription );
+                }
+                else
+                {
+                    extension_Control( p_mgr, EXTENSION_ACTIVATE, p_ext );
+                }
+                psz_ext_parser += i_ext_name_len;
+                break;
+            }
+        }
+
+        if( strchr( psz_ext_parser, ',' ) )
+        {
+            psz_ext_parser = strchr( psz_ext_parser, ',' ) + 1;
+        }
+        else if( strchr( psz_ext_parser, ':' ) )
+        {
+            psz_ext_parser = strchr( psz_ext_parser, ':' ) + 1;
+        }
+        else
+        {
+            break;
+        }
+    }
+    free( psz_ext );
+
     // Create the dialog-event variable
     var_Create( p_this, "dialog-event", VLC_VAR_ADDRESS );
     var_AddCallback( p_this, "dialog-event",
diff --git a/modules/lua/vlc.c b/modules/lua/vlc.c
index 73c92d26b6..53c2d320fb 100644
--- a/modules/lua/vlc.c
+++ b/modules/lua/vlc.c
@@ -79,6 +79,9 @@
     "plain TCP socket (\"localhost:4212\") or use the telnet protocol " \
     "(\"telnet://0.0.0.0:4212\")" )
 
+#define ELIST_TEXT N_("Lua extension list")
+#define ELIST_LONGTEXT N_("A list of lua extensions to load, separated by commas.\n")
+
 static int vlc_sd_probe_Open( vlc_object_t * );
 
 vlc_module_begin ()
@@ -161,6 +164,7 @@ vlc_module_begin ()
         set_description( N_("Lua Extension") )
         add_shortcut( "luaextension" )
         set_capability( "extension", 1 )
+        add_string( "lua-extension-list", "", ELIST_TEXT, ELIST_LONGTEXT, true )
         set_callbacks( Open_Extension, Close_Extension )
 
     add_submodule ()
-- 
2.14.2



More information about the vlc-devel mailing list