[vlc-commits] playlist: create the playlist when needed (refs #5460)

Rémi Denis-Courmont git at videolan.org
Mon Nov 26 23:19:52 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Nov 26 23:53:36 2012 +0200| [f2b9c723187fcdb1b24285771cc6f7d580be2ba1] | committer: Rémi Denis-Courmont

playlist: create the playlist when needed (refs #5460)

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

 src/libvlc.c                     |   24 +++++++++---------------
 src/libvlc.h                     |    2 --
 src/playlist/engine.c            |   22 ++++++++++++++--------
 src/playlist/playlist_internal.h |    3 ---
 src/playlist/thread.c            |   18 ++----------------
 5 files changed, 25 insertions(+), 44 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index bf5ae78..9a3d03c 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -145,7 +145,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     char *       psz_modules = NULL;
     char *       psz_parser = NULL;
     char *       psz_control = NULL;
-    playlist_t  *p_playlist = NULL;
     char        *psz_val;
 
     /* System specific initialization code */
@@ -433,15 +432,6 @@ dbus_out:
     var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
     var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
 
-    /* Initialize playlist and get commandline files */
-    p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
-    if( !p_playlist )
-    {
-        msg_Err( p_libvlc, "playlist initialization failed" );
-        module_EndBank (true);
-        return VLC_EGENERIC;
-    }
-
     /* System specific configuration */
     system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
 
@@ -468,7 +458,7 @@ dbus_out:
     {
         char *p = psz_modules, *m;
         while( ( m = strsep( &p, " :," ) ) != NULL )
-            playlist_ServicesDiscoveryAdd( p_playlist, m );
+            playlist_ServicesDiscoveryAdd( pl_Get(p_libvlc), m );
         free( psz_modules );
     }
 
@@ -582,7 +572,7 @@ dbus_out:
     psz_val = var_InheritString( p_libvlc, "open" );
     if ( psz_val != NULL )
     {
-        playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
+        playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
                          -1, 0, NULL, 0, true, pl_Unlocked );
         free( psz_val );
     }
@@ -600,8 +590,11 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     playlist_t    *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
 
     /* Remove all services discovery */
-    msg_Dbg( p_libvlc, "removing all services discovery tasks" );
-    playlist_ServicesDiscoveryKillAll( p_playlist );
+    if( p_playlist != NULL )
+    {
+        msg_Dbg( p_libvlc, "removing all services discovery tasks" );
+        playlist_ServicesDiscoveryKillAll( p_playlist );
+    }
 
     /* Ask the interfaces to stop and destroy them */
     msg_Dbg( p_libvlc, "removing all interfaces" );
@@ -627,7 +620,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
 #endif
 
     /* Free playlist now, all threads are gone */
-    playlist_Destroy( p_playlist );
+    if( p_playlist != NULL )
+        playlist_Destroy( p_playlist );
 
     msg_Dbg( p_libvlc, "removing stats" );
 
diff --git a/src/libvlc.h b/src/libvlc.h
index 4392f48..ebc68c9 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -141,8 +141,6 @@ typedef struct libvlc_priv_t
 {
     libvlc_int_t       public_data;
 
-    bool               playlist_active;
-
     /* Messages */
     signed char        i_verbose;   ///< info messages
     bool               b_color;     ///< color messages?
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 3a72621..dc5b0e9 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -195,7 +195,7 @@ static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd,
  * \param p_parent the vlc object that is to be the parent of this playlist
  * \return a pointer to the created playlist, or NULL on error
  */
-playlist_t * playlist_Create( vlc_object_t *p_parent )
+static playlist_t *playlist_Create( vlc_object_t *p_parent )
 {
     playlist_t *p_playlist;
     playlist_private_t *p;
@@ -209,8 +209,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist = &p->public_data;
     TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
 
-    libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
-
     VariablesInit( p_playlist );
     vlc_mutex_init( &p->lock );
     vlc_cond_init( &p->signal );
@@ -298,6 +296,14 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
         pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
     }
 
+    /* Input resources */
+    p->p_input_resource = input_resource_New( VLC_OBJECT( p_playlist ) );
+    if( unlikely(p->p_input_resource == NULL) )
+        abort();
+
+    /* Thread */
+    playlist_Activate (p_playlist);
+
     return p_playlist;
 }
 
@@ -366,12 +372,12 @@ playlist_t *pl_Get (vlc_object_t *obj)
 
     vlc_mutex_lock (&lock);
     pl = libvlc_priv (p_libvlc)->p_playlist;
-    assert (pl != NULL);
-
-    if (!libvlc_priv (p_libvlc)->playlist_active)
+    if (unlikely(pl == NULL))
     {
-         playlist_Activate (pl);
-         libvlc_priv (p_libvlc)->playlist_active = true;
+        pl = playlist_Create (VLC_OBJECT(p_libvlc));
+        if (unlikely(pl == NULL))
+            abort();
+        libvlc_priv (p_libvlc)->p_playlist = pl;
     }
     vlc_mutex_unlock (&lock);
     return pl;
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 7e6bede..9b6c000 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -99,10 +99,7 @@ typedef struct playlist_private_t
  *****************************************************************************/
 
 /* Creation/Deletion */
-playlist_t *playlist_Create( vlc_object_t * );
 void playlist_Destroy( playlist_t * );
-
-/* */
 void playlist_Activate( playlist_t * );
 
 /* */
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 5f22924..9bfbc3c 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -46,29 +46,18 @@ static void *Thread   ( void * );
  *****************************************************************************/
 
 /**
- * Create the main playlist threads.
- * Additionally to the playlist, this thread controls :
- *    - Statistics
- *    - VLM
- * \param p_parent
- * \return an object with a started thread
+ * Creates the main playlist thread.
  */
 void playlist_Activate( playlist_t *p_playlist )
 {
-    /* */
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
-    p_sys->p_input_resource = input_resource_New( VLC_OBJECT( p_playlist ) );
-    if( unlikely(p_sys->p_input_resource == NULL) )
-        abort();
-
-    /* Start the playlist thread */
     if( vlc_clone( &p_sys->thread, Thread, p_playlist,
                    VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_playlist, "cannot spawn playlist thread" );
+        abort();
     }
-    msg_Dbg( p_playlist, "playlist threads correctly activated" );
 }
 
 /**
@@ -80,9 +69,6 @@ void playlist_Deactivate( playlist_t *p_playlist )
 {
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
-    if( p_sys->p_input_resource == NULL )
-        return; /* playlist was never activated... */
-
     PL_LOCK;
     /* WARNING: There is a latent bug. It is assumed that only one thread will
      * be waiting for playlist deactivation at a time. So far, that works



More information about the vlc-commits mailing list