]> git.sesse.net Git - vlc/commitdiff
interface: create the playlist first and use it as parent
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 1 Jan 2014 17:08:21 +0000 (19:08 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 7 Jan 2014 22:07:50 +0000 (00:07 +0200)
include/vlc_interface.h
modules/control/ntservice.c
modules/control/rc.c
src/interface/interface.c
src/libvlc.c
src/libvlc.h
src/playlist/playlist_internal.h

index 50b745e7a746c1eba5696bbc35e7c96f5f819dba..8799e471d6b2e9a37616173f2570b94ae3e1c8a1 100644 (file)
@@ -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 * );
 
index c0602aeed53067782de566ec7823a7356559f248..3eda3ecdc2f7a8ba134e8eb34c5020a6b248fa89 100644 (file)
@@ -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 );
index 1da54400cabf9df7f0f94e218f957d690ec1e167..3d3f7afa0a501bab94d9767330d77b3793b54bf1 100644 (file)
@@ -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,
index b24cd697ffb97f839eaab3686624f0369c2248cd..b380ba49340b15f3e7a10ae818b925e5b42f0028 100644 (file)
@@ -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;
 }
index d6c63ade9e8ea31bb213a80a313647307cc512f9..cc68b120f63559af29f1cd343655e759ac7df98b 100644 (file)
@@ -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 )
index d32976afc81c9686ce24a896af170fcb0af6530a..3fd00ead53916c459c1ae78f047db484d29f70d8 100644 (file)
@@ -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;
 
index 2fbaaacdba6765701176086f44d4341e22f4e29f..8141c40d92318b358c0e8d58d54eee452bbe32db 100644 (file)
@@ -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. */