[vlc-commits] interface: create the playlist first and use it as parent

Rémi Denis-Courmont git at videolan.org
Tue Jan 7 23:07:58 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jan  1 19:08:21 2014 +0200| [11405d4de49c252c69e168346d8911b119ea8a4a] | committer: Rémi Denis-Courmont

interface: create the playlist first and use it as parent

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

 include/vlc_interface.h          |    3 +-
 modules/control/ntservice.c      |    2 +-
 modules/control/rc.c             |    5 +--
 src/interface/interface.c        |   68 ++++++++++++++++++++------------------
 src/libvlc.c                     |   19 +++++------
 src/libvlc.h                     |    3 --
 src/playlist/playlist_internal.h |    1 +
 7 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index 50b745e..8799e47 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -90,8 +90,7 @@ struct intf_dialog_args_t
     struct interaction_dialog_t *p_dialog;
 };
 
-VLC_API int intf_Create( vlc_object_t *, const char * );
-#define intf_Create(a,b) intf_Create(VLC_OBJECT(a),b)
+VLC_API int intf_Create( playlist_t *, const char * );
 
 VLC_API void libvlc_Quit( libvlc_int_t * );
 
diff --git a/modules/control/ntservice.c b/modules/control/ntservice.c
index c0602ae..3eda3ec 100644
--- a/modules/control/ntservice.c
+++ b/modules/control/ntservice.c
@@ -322,7 +322,7 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 )
         {
             /* Try to create the interface */
-            if( intf_Create( p_intf, psz_temp ) )
+            if( intf_Create( pl_Get(p_intf), psz_temp ) )
             {
                 msg_Err( p_intf, "interface \"%s\" initialization failed",
                          psz_temp );
diff --git a/modules/control/rc.c b/modules/control/rc.c
index 1da5440..3d3f7af 100644
--- a/modules/control/rc.c
+++ b/modules/control/rc.c
@@ -1420,9 +1420,10 @@ static int Quit( vlc_object_t *p_this, char const *psz_cmd,
 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
+    intf_thread_t *intf = (intf_thread_t *)p_this;
 
-    return intf_Create( p_this->p_libvlc, newval.psz_string );
+    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
+    return intf_Create(pl_Get(intf), newval.psz_string );
 }
 
 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
diff --git a/src/interface/interface.c b/src/interface/interface.c
index b24cd69..b380ba4 100644
--- a/src/interface/interface.c
+++ b/src/interface/interface.c
@@ -61,22 +61,19 @@ static int AddIntfCallback( vlc_object_t *, char const *,
  */
 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
 
-#undef intf_Create
 /**
  * Create and start an interface.
  *
- * @param p_this the calling vlc_object_t
+ * @param playlist playlist and parent object for the interface
  * @param chain configuration chain string
  * @return VLC_SUCCESS or an error code
  */
-int intf_Create( vlc_object_t *p_this, const char *chain )
+int intf_Create( playlist_t *playlist, const char *chain )
 {
-    libvlc_int_t *p_libvlc = p_this->p_libvlc;
-    intf_thread_t * p_intf;
-
     /* Allocate structure */
-    p_intf = vlc_custom_create( p_libvlc, sizeof( *p_intf ), "interface" );
-    if( !p_intf )
+    intf_thread_t *p_intf = vlc_custom_create( playlist, sizeof( *p_intf ),
+                                               "interface" );
+    if( unlikely(p_intf == NULL) )
         return VLC_ENOMEM;
 
     /* Variable used for interface spawning */
@@ -106,7 +103,7 @@ int intf_Create( vlc_object_t *p_this, const char *chain )
     text.psz_string = (char *)_("Mouse Gestures");
     var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text );
 
-    var_AddCallback( p_intf, "intf-add", AddIntfCallback, NULL );
+    var_AddCallback( p_intf, "intf-add", AddIntfCallback, playlist );
 
     /* Choose the best module */
     char *module;
@@ -122,8 +119,8 @@ int intf_Create( vlc_object_t *p_this, const char *chain )
     }
 
     vlc_mutex_lock( &lock );
-    p_intf->p_next = libvlc_priv( p_libvlc )->p_intf;
-    libvlc_priv( p_libvlc )->p_intf = p_intf;
+    p_intf->p_next = pl_priv( playlist )->interface;
+    pl_priv( playlist )->interface = p_intf;
     vlc_mutex_unlock( &lock );
 
     return VLC_SUCCESS;
@@ -169,39 +166,44 @@ playlist_t *(pl_Get)(vlc_object_t *obj)
  * Stops and destroys all interfaces
  * @param p_libvlc the LibVLC instance
  */
-void intf_DestroyAll( libvlc_int_t *p_libvlc )
+void intf_DestroyAll(libvlc_int_t *libvlc)
 {
-    intf_thread_t *p_intf;
-
-    vlc_mutex_lock( &lock );
-    p_intf = libvlc_priv( p_libvlc )->p_intf;
-#ifndef NDEBUG
-    libvlc_priv( p_libvlc )->p_intf = NULL;
-#endif
-    vlc_mutex_unlock( &lock );
+    playlist_t *playlist;
 
-    /* Cleanup the interfaces */
-    while( p_intf != NULL )
+    vlc_mutex_lock(&lock);
+    playlist = libvlc_priv(libvlc)->playlist;
+    if (playlist != NULL)
     {
-        intf_thread_t *p_next = p_intf->p_next;
+        intf_thread_t *intf, **pp = &(pl_priv(playlist)->interface);
 
-        module_unneed( p_intf, p_intf->p_module );
-        config_ChainDestroy( p_intf->p_cfg );
-        vlc_object_release( p_intf );
-        p_intf = p_next;
+        while ((intf = *pp) != NULL)
+        {
+            *pp = intf->p_next;
+            vlc_mutex_unlock(&lock);
+
+            module_unneed(intf, intf->p_module);
+            config_ChainDestroy(intf->p_cfg);
+            var_DelCallback(intf, "intf-add", AddIntfCallback, playlist);
+            vlc_object_release(intf);
+
+            vlc_mutex_lock(&lock);
+        }
     }
+    vlc_mutex_unlock(&lock);
 }
 
 /* Following functions are local */
 
-static int AddIntfCallback( vlc_object_t *p_this, char const *psz_cmd,
-                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
+static int AddIntfCallback( vlc_object_t *obj, char const *var,
+                            vlc_value_t old, vlc_value_t cur, void *data )
 {
-    (void)psz_cmd; (void)oldval; (void)p_data;
+    playlist_t *playlist = data;
 
-    int ret = intf_Create( VLC_OBJECT(p_this->p_libvlc), newval.psz_string );
+    int ret = intf_Create( playlist, cur.psz_string );
     if( ret )
-        msg_Err( p_this, "interface \"%s\" initialization failed",
-                 newval.psz_string );
+        msg_Err( obj, "interface \"%s\" initialization failed",
+                 cur.psz_string );
+
+    (void) var; (void) old;
     return ret;
 }
diff --git a/src/libvlc.c b/src/libvlc.c
index d6c63ad..cc68b12 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -447,7 +447,7 @@ dbus_out:
         }
         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
         {
-            intf_Create( p_libvlc, psz_temp );
+            libvlc_InternalAddIntf( p_libvlc, psz_temp );
             free( psz_temp );
         }
     }
@@ -459,7 +459,7 @@ dbus_out:
     {
         char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
         var_SetString( p_libvlc, "logmode", "syslog" );
-        intf_Create( p_libvlc, "logger,none" );
+        libvlc_InternalAddIntf( p_libvlc, "logger,none" );
 
         if( logmode )
         {
@@ -471,12 +471,10 @@ dbus_out:
     else
 #endif
     if( var_InheritBool( p_libvlc, "file-logging" ) )
-        intf_Create( p_libvlc, "logger,none" );
+        libvlc_InternalAddIntf( p_libvlc, "logger,none" );
 
     if( var_InheritBool( p_libvlc, "network-synchronisation") )
-    {
-        intf_Create( p_libvlc, "netsync,none" );
-    }
+        libvlc_InternalAddIntf( p_libvlc, "netsync,none" );
 
 #ifdef __APPLE__
     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
@@ -591,13 +589,14 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
  */
 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, const char *name )
 {
-    int ret;
-
     if( !p_libvlc )
         return VLC_EGENERIC;
 
+    playlist_t *playlist = pl_Get(p_libvlc);
+    int ret;
+
     if( name != NULL )
-        ret = intf_Create( p_libvlc, name );
+        ret = intf_Create( playlist, name );
     else
     {   /* Default interface */
         char *intf = var_InheritString( p_libvlc, "intf" );
@@ -611,7 +610,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, const char *name )
                           _("Running vlc with the default interface. "
                             "Use 'cvlc' to use vlc without interface.") );
         }
-        ret = intf_Create( p_libvlc, intf );
+        ret = intf_Create( playlist, intf );
         name = "default";
     }
     if( ret )
diff --git a/src/libvlc.h b/src/libvlc.h
index d32976a..3fd00ea 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -166,9 +166,6 @@ typedef struct libvlc_priv_t
     struct playlist_preparser_t *parser; ///< Input item meta data handler
     struct vlc_actions *actions; ///< Hotkeys handler
 
-    /* Interfaces */
-    struct intf_thread_t *p_intf; ///< Interfaces linked-list
-
     /* Objects tree */
     vlc_mutex_t        structure_lock;
 
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 2fbaaac..8141c40 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -48,6 +48,7 @@ typedef struct playlist_private_t
 {
     playlist_t           public_data;
     playlist_preparser_t *p_preparser;  /**< Preparser data */
+    struct intf_thread_t *interface; /**< Linked-list of interfaces */
 
     playlist_item_array_t items_to_delete; /**< Array of items and nodes to
             delete... At the very end. This sucks. */



More information about the vlc-commits mailing list