[vlc-commits] Export playlist_Deactivate() and simplify it

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:11:05 2012 +0200| [d32dc564a1639b2750100020421f9cb38032978b] | committer: Rémi Denis-Courmont

Export playlist_Deactivate() and simplify it

Those interfaces that need playlist deactivation can now call it
explicitly.

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

 include/vlc_playlist.h           |    1 +
 src/libvlccore.sym               |    1 +
 src/playlist/engine.c            |   16 ++++++++++++++--
 src/playlist/playlist_internal.h |    1 -
 src/playlist/thread.c            |   39 ++++++++++++++++++--------------------
 5 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index d837e7d..5f58bfd 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -265,6 +265,7 @@ VLC_API playlist_t * pl_Get( vlc_object_t * ) VLC_USED;
 VLC_API void playlist_Lock( playlist_t * );
 VLC_API void playlist_Unlock( playlist_t * );
 VLC_API void playlist_AssertLocked( playlist_t * );
+VLC_API void playlist_Deactivate( playlist_t * );
 
 /**
  * Do a playlist action.
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 04dfbc8..346dad1 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -324,6 +324,7 @@ playlist_Clear
 playlist_Control
 playlist_CurrentInput
 playlist_CurrentPlayingItem
+playlist_Deactivate
 playlist_DeleteFromInput
 playlist_Export
 playlist_GetNextLeaf
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 4443388..466215f 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -313,13 +313,25 @@ void playlist_Destroy( playlist_t *p_playlist )
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
     msg_Dbg( p_playlist, "destroying" );
+
     if( p_sys->p_preparser )
         playlist_preparser_Delete( p_sys->p_preparser );
     if( p_sys->p_fetcher )
         playlist_fetcher_Delete( p_sys->p_fetcher );
 
-    /* Already cleared when deactivating (if activated anyway) */
-    assert( !p_sys->p_input );
+    /* Release input resources */
+    assert( p_sys->p_input == NULL );
+    input_resource_Release( p_sys->p_input_resource );
+
+    if( p_playlist->p_media_library != NULL )
+        playlist_MLDump( p_playlist );
+
+    PL_LOCK;
+    /* Release the current node */
+    set_current_status_node( p_playlist, NULL );
+    /* Release the current item */
+    set_current_status_item( p_playlist, NULL );
+    PL_UNLOCK;
 
     vlc_cond_destroy( &p_sys->signal );
     vlc_mutex_destroy( &p_sys->lock );
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index fedecea..fa2469e 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -104,7 +104,6 @@ void playlist_Destroy( playlist_t * );
 
 /* */
 void playlist_Activate( playlist_t * );
-void playlist_Deactivate( playlist_t * );
 void pl_Deactivate (libvlc_int_t *);
 
 /* */
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 053a09a..5f22924 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -71,38 +71,35 @@ void playlist_Activate( playlist_t *p_playlist )
     msg_Dbg( p_playlist, "playlist threads correctly activated" );
 }
 
+/**
+ * Stops the playlist forever (but do not destroy it yet).
+ * Any input is stopped.
+ * \return Nothing but waits for the playlist to be deactivated.
+ */
 void playlist_Deactivate( playlist_t *p_playlist )
 {
-    /* */
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
-    msg_Dbg( p_playlist, "deactivating the 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
+     * as playlist_Deactivate() is only ever called while closing an
+     * interface and interfaces are shut down serially by intf_DestroyAll(). */
+    if( p_sys->killed )
+    {
+        PL_UNLOCK;
+        return;
+    }
+
+    msg_Dbg( p_playlist, "deactivating the playlist" );
     p_sys->killed = true;
     vlc_cond_signal( &p_sys->signal );
     PL_UNLOCK;
 
     vlc_join( p_sys->thread, NULL );
-    assert( !p_sys->p_input );
-
-    /* release input resources */
-    input_resource_Release( p_sys->p_input_resource );
-
-    if( var_InheritBool( p_playlist, "media-library" ) )
-        playlist_MLDump( p_playlist );
-
-    PL_LOCK;
-
-    /* Release the current node */
-    set_current_status_node( p_playlist, NULL );
-
-    /* Release the current item */
-    set_current_status_item( p_playlist, NULL );
-
-    PL_UNLOCK;
-
-    msg_Dbg( p_playlist, "playlist correctly deactivated" );
 }
 
 /* */



More information about the vlc-commits mailing list