[vlc-devel] [PATCH 5/6] libvlc: use vlc_vector for interfaces

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Tue Nov 27 13:28:57 CET 2018


---
 include/vlc_interface.h   |  2 --
 src/interface/interface.c | 22 +++++++++-------------
 src/libvlc.c              |  1 +
 src/libvlc.h              |  6 +++++-
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index 632759060b..558ac1099d 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -49,8 +49,6 @@ typedef struct intf_thread_t
 {
     struct vlc_common_members obj;
 
-    struct intf_thread_t *p_next; /** LibVLC interfaces book keeping */
-
     /* Specific interfaces */
     intf_sys_t *        p_sys;                          /** system interface */
 
diff --git a/src/interface/interface.c b/src/interface/interface.c
index 0f47e06fd8..7e0fed8412 100644
--- a/src/interface/interface.c
+++ b/src/interface/interface.c
@@ -111,8 +111,7 @@ int intf_Create( playlist_t *playlist, const char *chain )
     }
 
     vlc_mutex_lock( &lock );
-    p_intf->p_next = pl_priv( playlist )->interface;
-    pl_priv( playlist )->interface = p_intf;
+    vlc_vector_push(&libvlc_priv(libvlc)->interfaces, p_intf);
     vlc_mutex_unlock( &lock );
 
     return VLC_SUCCESS;
@@ -240,14 +239,13 @@ void intf_DestroyAll(libvlc_int_t *libvlc)
     playlist_t *playlist;
 
     vlc_mutex_lock(&lock);
-    playlist = libvlc_priv(libvlc)->playlist;
+    libvlc_priv_t *libvlc_p = livlc_priv(libvlc);
+    playlist = libvlc_p->playlist;
     if (playlist != NULL)
     {
-        intf_thread_t *intf, **pp = &(pl_priv(playlist)->interface);
-
-        while ((intf = *pp) != NULL)
+        intf_thread_t *intf;
+        vlc_vector_foreach(intf, &libvlc_p->interfaces)
         {
-            *pp = intf->p_next;
             vlc_mutex_unlock(&lock);
 
             module_unneed(intf, intf->p_module);
@@ -257,8 +255,8 @@ void intf_DestroyAll(libvlc_int_t *libvlc)
 
             vlc_mutex_lock(&lock);
         }
-
-        libvlc_priv(libvlc)->playlist = NULL;
+        vlc_vector_clear(&libvlc_p->interfaces);
+        libvlc_p->playlist = NULL;
     }
     vlc_mutex_unlock(&lock);
 
@@ -271,13 +269,11 @@ void intf_DestroyAll(libvlc_int_t *libvlc)
 static int AddIntfCallback( vlc_object_t *obj, char const *var,
                             vlc_value_t old, vlc_value_t cur, void *data )
 {
-    playlist_t *playlist = data;
-
-    int ret = intf_Create( playlist, cur.psz_string );
+    int ret = intf_Create( obj->obj.libvlc, cur.psz_string );
     if( ret )
         msg_Err( obj, "interface \"%s\" initialization failed",
                  cur.psz_string );
 
-    (void) var; (void) old;
+    (void) var; (void) old; (void) data;
     return ret;
 }
diff --git a/src/libvlc.c b/src/libvlc.c
index cf35bcfed3..003a606373 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -96,6 +96,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
         return NULL;
 
     priv = libvlc_priv (p_libvlc);
+    vlc_vector_init(&priv->interfaces);
     priv->playlist = NULL;
     priv->main_playlist = NULL;
     priv->p_vlm = NULL;
diff --git a/src/libvlc.h b/src/libvlc.h
index a0adeeb26a..8fb96017eb 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -25,7 +25,9 @@
 #ifndef LIBVLC_LIBVLC_H
 # define LIBVLC_LIBVLC_H 1
 
+#include <vlc_vector.h>
 #include <vlc_input_item.h>
+#include <vlc_interface.h>
 
 extern const char psz_vlc_changeset[];
 
@@ -185,6 +187,7 @@ typedef struct vlc_keystore vlc_keystore;
 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 VLC_VECTOR(intf_thread_t *) intf_vector;
 
 typedef struct libvlc_priv_t
 {
@@ -195,7 +198,8 @@ typedef struct libvlc_priv_t
     vlm_t             *p_vlm;  ///< the VLM singleton (or NULL)
     vlc_dialog_provider *p_dialog_provider; ///< dialog provider
     vlc_keystore      *p_memory_keystore; ///< memory keystore
-    struct playlist_t *playlist; ///< Playlist for interfaces
+    intf_vector interfaces; ///< LibVLC interfaces book keeping
+    struct playlist_t *playlist;
     vlc_playlist_t *main_playlist;
     struct input_preparser_t *parser; ///< Input item meta data handler
     vlc_media_source_provider_t *media_source_provider;
-- 
2.19.1



More information about the vlc-devel mailing list