[vlc-devel] [PATCH 3/7] Create services_advertisement VLC object

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


---
 include/vlc_services_advertisement.h | 87 ++++++++++++++++++++++++++++++++++++
 src/Makefile.am                      |  2 +
 src/misc/services_advertisement.c    | 84 ++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
 create mode 100644 include/vlc_services_advertisement.h
 create mode 100644 src/misc/services_advertisement.c

diff --git a/include/vlc_services_advertisement.h b/include/vlc_services_advertisement.h
new file mode 100644
index 0000000000..444c3d5c4e
--- /dev/null
+++ b/include/vlc_services_advertisement.h
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * vlc_services_advertisement.h : Services Advertisement functions
+ *****************************************************************************
+ * Copyright (C) 1999-2019 VLC authors and VideoLAN
+ *
+ * Authors:
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_SERVICES_ADVERTISEMENT_H_
+#define VLC_SERVICES_ADVERTISEMENT_H_
+
+#include <vlc_input.h>
+
+/**
+ * \file
+ * This file lists functions and structures for service advertisement (SA) in vlc
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/**
+ * @{
+ */
+
+/**
+ * Main service advertisement structure to build a SA module
+ */
+typedef struct services_advertisement_t
+{
+    struct vlc_object_t obj;
+
+    struct services_advertisement_t *p_next;  /** Points to the next SA element */
+
+    module_t *          p_module;             /**< Loaded module */
+
+    char *psz_name;                           /**< Main name of the SA */
+    config_chain_t *p_cfg;                    /**< Configuration for the SA */
+
+    const char *description;                  /**< Human-readable name */
+
+    void *p_sys;                              /**< Custom private data */
+} services_advertisement_t;
+
+
+/***********************************************************************
+ * Service Advertisement
+ ***********************************************************************/
+
+/**
+ * Loads a service advertisement (SA) module for the given configuration
+ * and adds it to the VLC's list of SA modules.
+ * 
+ * @param chain configuration chain string
+ * @return VLC_SUCCESS or an error code
+ */
+int sa_Create( libvlc_int_t *libvlc, const char *chain );
+
+/**
+ * Stops and unloads all services advertisement modules.
+ * 
+ * @param libvlc the LibVLC instance
+ */
+void sa_DestroyAll( libvlc_int_t *libvlc );
+
+
+/** @} */
+# ifdef __cplusplus
+}
+# endif
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c56c0e165..42bb39ebaf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,6 +85,7 @@ pluginsinclude_HEADERS = \
 	../include/vlc_probe.h \
 	../include/vlc_rand.h \
 	../include/vlc_services_discovery.h \
+	../include/vlc_services_advertisement.h \
 	../include/vlc_fingerprinter.h \
 	../include/vlc_interrupt.h \
 	../include/vlc_renderer_discovery.h \
@@ -358,6 +359,7 @@ libvlccore_la_SOURCES = \
 	misc/interrupt.c \
 	misc/keystore.c \
 	misc/renderer_discovery.c \
+    misc/services_advertisement.c \
 	misc/threads.c \
 	misc/cpu.c \
 	misc/epg.c \
diff --git a/src/misc/services_advertisement.c b/src/misc/services_advertisement.c
new file mode 100644
index 0000000000..344b512007
--- /dev/null
+++ b/src/misc/services_advertisement.c
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * services_advertisement.c : Manage services advertisement modules
+ *****************************************************************************
+ * Copyright (C) 1999-2019 VLC authors and VideoLAN
+ *
+ * Authors:
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <assert.h>
+
+#include <vlc_common.h>
+#include <vlc_services_advertisement.h>
+#include <vlc_modules.h>
+#include "../libvlc.h"
+
+int sa_Create( libvlc_int_t *libvlc, const char *chain )
+{
+    assert( libvlc );
+    libvlc_priv_t *priv = libvlc_priv( libvlc );
+
+    services_advertisement_t *sa = vlc_custom_create( libvlc, sizeof( *sa ),
+                                                 "services advertisement" );
+    if( unlikely( sa == NULL ) )
+        return VLC_ENOMEM;
+
+    free( config_ChainCreate( &sa->psz_name, &sa->p_cfg, chain ) );
+    
+    sa->description = NULL;
+
+    sa->p_module = module_need( sa, "services_advertisement",
+                                sa->psz_name, true );
+    if ( sa->p_module == NULL )
+    {
+        msg_Err( sa, "no suitable services advertisement module" );
+        return VLC_EGENERIC;
+    }
+
+    vlc_mutex_lock( &priv->lock );
+    sa->p_next = priv->services_advertisements;
+    priv->services_advertisements = sa;
+    vlc_mutex_unlock( &priv->lock );
+
+    return VLC_SUCCESS;
+}
+
+void sa_DestroyAll( libvlc_int_t *libvlc )
+{
+    libvlc_priv_t *priv = libvlc_priv( libvlc );
+
+    vlc_mutex_lock( &priv->lock );
+    services_advertisement_t *sa, **pp = &priv->services_advertisements;
+
+    while( ( sa = *pp ) != NULL )
+    {
+        *pp = sa->p_next;
+        vlc_mutex_unlock( &priv->lock );
+
+        if( sa->p_module )
+            module_unneed( sa, sa->p_module );
+
+        config_ChainDestroy( sa->p_cfg );
+        free( sa->psz_name );
+        vlc_object_delete( sa );
+
+        vlc_mutex_lock( &priv->lock );
+    }
+    vlc_mutex_unlock( &priv->lock );
+}
\ No newline at end of file
-- 
2.11.0



More information about the vlc-devel mailing list