[vlc-commits] playlist: create instance only when needed

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> | Thu Jan  2 23:36:35 2014 +0200| [a87ad3c76d203df5a89e1a5a3f25f890f94805ab] | committer: Rémi Denis-Courmont

playlist: create instance only when needed

This avoids checking that the playlist exists over and over again. The
playlist always exists when an interface is running.

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

 src/interface/interface.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 src/libvlc.c              |   39 ---------------------------------------
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/interface/interface.c b/src/interface/interface.c
index 35446c0..e044021 100644
--- a/src/interface/interface.c
+++ b/src/interface/interface.c
@@ -188,8 +188,42 @@ void libvlc_InternalPlay(libvlc_int_t *libvlc)
 }
 
 /**
- * Stops and destroys all interfaces
- * @param p_libvlc the LibVLC instance
+ * Starts an interface plugin.
+ */
+int libvlc_InternalAddIntf(libvlc_int_t *libvlc, const char *name)
+{
+    playlist_t *playlist = intf_GetPlaylist(libvlc);
+    int ret;
+
+    if (unlikely(playlist == NULL))
+        ret = VLC_ENOMEM;
+    else
+    if (name != NULL)
+        ret = intf_Create(playlist, name);
+    else
+    {   /* Default interface */
+        char *intf = var_InheritString(libvlc, "intf");
+        if (intf == NULL) /* "intf" has not been set */
+        {
+            char *pidfile = var_InheritString(libvlc, "pidfile");
+            if (pidfile != NULL)
+                free(pidfile);
+            else
+                msg_Info(libvlc, _("Running vlc with the default interface. "
+                         "Use 'cvlc' to use vlc without interface."));
+        }
+        ret = intf_Create(playlist, intf);
+        name = "default";
+    }
+    if (ret != VLC_SUCCESS)
+        msg_Err(libvlc, "interface \"%s\" initialization failed", name);
+    return ret;
+}
+
+/**
+ * Stops and destroys all interfaces, then the playlist.
+ * @warning FIXME
+ * @param libvlc the LibVLC instance
  */
 void intf_DestroyAll(libvlc_int_t *libvlc)
 {
@@ -213,8 +247,13 @@ void intf_DestroyAll(libvlc_int_t *libvlc)
 
             vlc_mutex_lock(&lock);
         }
+
+        libvlc_priv(libvlc)->playlist = NULL;
     }
     vlc_mutex_unlock(&lock);
+
+    if (playlist != NULL)
+        playlist_Destroy(playlist);
 }
 
 /* Following functions are local */
diff --git a/src/libvlc.c b/src/libvlc.c
index 8fe3fe1..21f9d4a 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -532,11 +532,6 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     }
 #endif
 
-    /* Free playlist now, all threads are gone */
-    playlist_t *p_playlist = libvlc_priv (p_libvlc)->playlist;
-    if( p_playlist != NULL )
-        playlist_Destroy( p_playlist );
-
 #if !defined( _WIN32 ) && !defined( __OS2__ )
     char *pidfile = var_InheritString( p_libvlc, "pidfile" );
     if( pidfile != NULL )
@@ -583,40 +578,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
     vlc_object_release( p_libvlc );
 }
 
-/**
- * Add an interface plugin and run it
- */
-int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, const char *name )
-{
-    if( !p_libvlc )
-        return VLC_EGENERIC;
-
-    playlist_t *playlist = pl_Get(p_libvlc);
-    int ret;
-
-    if( name != NULL )
-        ret = intf_Create( playlist, name );
-    else
-    {   /* Default interface */
-        char *intf = var_InheritString( p_libvlc, "intf" );
-        if( intf == NULL ) /* "intf" has not been set */
-        {
-            char *pidfile = var_InheritString( p_libvlc, "pidfile" );
-            if( pidfile != NULL )
-                free( pidfile );
-            else
-                msg_Info( p_libvlc, "%s",
-                          _("Running vlc with the default interface. "
-                            "Use 'cvlc' to use vlc without interface.") );
-        }
-        ret = intf_Create( playlist, intf );
-        name = "default";
-    }
-    if( ret )
-        msg_Err( p_libvlc, "interface \"%s\" initialization failed", name );
-    return ret;
-}
-
 /*****************************************************************************
  * GetFilenames: parse command line options which are not flags
  *****************************************************************************



More information about the vlc-commits mailing list