[vlc-devel] [PATCH 4/7] Add services-advertisement to libvlc

Roland Bewick roland.bewick at gmail.com
Wed Jul 24 17:43:47 CEST 2019


- Parse --services-advertisement option and load modules on VLC startup
- unload services advertisement modules on VLC shutdown
---
 src/libvlc.c | 32 ++++++++++++++++++++++++++++++++
 src/libvlc.h |  2 ++
 2 files changed, 34 insertions(+)

diff --git a/src/libvlc.c b/src/libvlc.c
index 018987f0bf..f404876f38 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -63,6 +63,7 @@
 #include <vlc_modules.h>
 #include <vlc_media_library.h>
 #include <vlc_thumbnailer.h>
+#include <vlc_services_advertisement.h>
 
 #include "libvlc.h"
 
@@ -92,6 +93,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     priv = libvlc_priv (p_libvlc);
     vlc_mutex_init(&priv->lock);
     priv->interfaces = NULL;
+    priv->services_advertisements = NULL;
     priv->main_playlist = NULL;
     priv->p_vlm = NULL;
     priv->media_source_provider = NULL;
@@ -116,6 +118,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     char *       psz_modules = NULL;
     char *       psz_parser = NULL;
     char *       psz_control = NULL;
+    char *       psz_services_advertisement = NULL;
     char        *psz_val;
     int          i_ret = VLC_EGENERIC;
 
@@ -330,6 +333,32 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     if( var_InheritBool( p_libvlc, "network-synchronisation") )
         libvlc_InternalAddIntf( p_libvlc, "netsync,none" );
 
+    /*
+     * Load service advertisement modules
+     */
+    psz_services_advertisement = var_InheritString( p_libvlc,
+                                                    "services-advertisement" );
+    psz_parser = psz_services_advertisement;
+
+    while( psz_parser && *psz_parser )
+    {
+        char *psz_module, *psz_temp;
+        psz_module = psz_parser;
+        psz_parser = strchr( psz_module, ':' );
+        if( psz_parser )
+        {
+            *psz_parser = '\0';
+            psz_parser++;
+        }
+        if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
+        {
+            sa_Create( p_libvlc, psz_temp );
+            free( psz_temp );
+        }
+    }
+
+    free( psz_services_advertisement );
+
 #ifdef __APPLE__
     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
     var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
@@ -395,6 +424,9 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     msg_Dbg( p_libvlc, "removing all interfaces" );
     intf_DestroyAll( p_libvlc );
 
+    /* Ask the service announcement modules to stop and destroy them */
+    sa_DestroyAll( p_libvlc );
+
     if ( priv->p_thumbnailer )
         vlc_thumbnailer_Release( priv->p_thumbnailer );
 
diff --git a/src/libvlc.h b/src/libvlc.h
index ff50bd9218..8f97b456f5 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -193,6 +193,7 @@ typedef struct vlc_actions_t vlc_actions_t;
 typedef struct vlc_playlist vlc_playlist_t;
 typedef struct vlc_media_source_provider_t vlc_media_source_provider_t;
 typedef struct intf_thread_t intf_thread_t;
+typedef struct services_advertisement_t services_advertisement_t;
 
 typedef struct libvlc_priv_t
 {
@@ -210,6 +211,7 @@ typedef struct libvlc_priv_t
     vlc_actions_t *actions; ///< Hotkeys handler
     struct vlc_medialibrary_t *p_media_library; ///< Media library instance
     struct vlc_thumbnailer_t *p_thumbnailer; ///< Lazily instantiated media thumbnailer
+    services_advertisement_t * services_advertisements; // Linked-list of SA modules
 
     /* Exit callback */
     vlc_exit_t       exit;
-- 
2.11.0



More information about the vlc-devel mailing list