]> git.sesse.net Git - vlc/blobdiff - src/playlist/thread.c
Check the return value of malloc.
[vlc] / src / playlist / thread.c
index 01544c73d4b990bf10deee663d3a0ca023d3f652..8d66901f1c37f5c2f2360f89f15fd700c0288b73 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_es.h>
 #include <vlc_input.h>
@@ -36,10 +40,6 @@ static void RunControlThread ( playlist_t * );
 static void RunPreparse( playlist_preparse_t * );
 static void RunFetcher( playlist_fetcher_t * );
 
-static playlist_t * CreatePlaylist( vlc_object_t *p_parent );
-static void EndPlaylist( playlist_t * );
-static void DestroyPlaylist( playlist_t * );
-
 static void DestroyInteraction( playlist_t * );
 
 /*****************************************************************************
@@ -57,26 +57,26 @@ static void DestroyInteraction( playlist_t * );
  */
 void __playlist_ThreadCreate( vlc_object_t *p_parent )
 {
-    playlist_t *p_playlist;
-    p_playlist = CreatePlaylist( p_parent );
-
+    playlist_t *p_playlist = playlist_Create( p_parent );
     if( !p_playlist ) return;
 
     // Stats
     p_playlist->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
+    if( !p_playlist->p_stats )
+    {
+        vlc_object_release( p_playlist );
+        return;
+    }
     vlc_mutex_init( p_playlist, &p_playlist->p_stats->lock );
     p_playlist->p_stats_computer = NULL;
 
-    // Interaction
-    p_playlist->p_interaction = NULL;
-
     // Preparse
     p_playlist->p_preparse = vlc_object_create( p_playlist,
                                   sizeof( playlist_preparse_t ) );
     if( !p_playlist->p_preparse )
     {
         msg_Err( p_playlist, "unable to create preparser" );
-        vlc_object_destroy( p_playlist );
+        vlc_object_release( p_playlist );
         return;
     }
     p_playlist->p_preparse->i_waiting = 0;
@@ -88,7 +88,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     {
         msg_Err( p_playlist, "cannot spawn preparse thread" );
         vlc_object_detach( p_playlist->p_preparse );
-        vlc_object_destroy( p_playlist->p_preparse );
+        vlc_object_release( p_playlist->p_preparse );
         return;
     }
 
@@ -98,11 +98,13 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     if( !p_playlist->p_fetcher )
     {
         msg_Err( p_playlist, "unable to create secondary preparser" );
-        vlc_object_destroy( p_playlist );
+        vlc_object_release( p_playlist );
         return;
     }
     p_playlist->p_fetcher->i_waiting = 0;
     p_playlist->p_fetcher->p_waiting = NULL;
+    p_playlist->p_fetcher->b_fetch_meta = var_CreateGetInteger( p_playlist,
+                                                                 "fetch-meta" );
     p_playlist->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist,
                                                                 "album-art" );
 
@@ -114,7 +116,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     {
         msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
         vlc_object_detach( p_playlist->p_fetcher );
-        vlc_object_destroy( p_playlist->p_fetcher );
+        vlc_object_release( p_playlist->p_fetcher );
         return;
     }
 
@@ -123,7 +125,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
                            VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
     {
         msg_Err( p_playlist, "cannot spawn playlist thread" );
-        vlc_object_destroy( p_playlist );
+        vlc_object_release( p_playlist );
         return;
     }
 
@@ -142,21 +144,40 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
  */
 int playlist_ThreadDestroy( playlist_t * p_playlist )
 {
-    p_playlist->b_die = VLC_TRUE;
-    playlist_Signal( p_playlist );
+    // Tell playlist to go to last loop
+    vlc_object_kill( p_playlist );
+
+    // Kill preparser
     if( p_playlist->p_preparse )
     {
-        vlc_cond_signal( &p_playlist->p_preparse->object_wait );
+        vlc_object_kill( p_playlist->p_preparse );
+        vlc_thread_join( p_playlist->p_preparse );
         free( p_playlist->p_preparse->pp_waiting );
+        vlc_object_detach( p_playlist->p_preparse );
+        vlc_object_release( p_playlist->p_preparse );
     }
+
+    // Kill meta fetcher
     if( p_playlist->p_fetcher )
     {
-        vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
+        vlc_object_kill( p_playlist->p_fetcher );
+        vlc_thread_join( p_playlist->p_fetcher );
         free( p_playlist->p_fetcher->p_waiting );
+        vlc_object_detach( p_playlist->p_fetcher );
+        vlc_object_release( p_playlist->p_fetcher );
     }
 
+    // Wait for thread to complete
+    vlc_thread_join( p_playlist );
+
+    // Stats
+    vlc_mutex_destroy( &p_playlist->p_stats->lock );
+    if( p_playlist->p_stats )
+        free( p_playlist->p_stats );
+
     DestroyInteraction( p_playlist );
-    DestroyPlaylist( p_playlist );
+
+    playlist_Destroy( p_playlist );
 
     return VLC_SUCCESS;
 }
@@ -166,11 +187,10 @@ int playlist_ThreadDestroy( playlist_t * p_playlist )
  */
 static void RunControlThread ( playlist_t *p_playlist )
 {
-   int i_loops = 0;
-
-   /* Tell above that we're ready */
-   vlc_thread_ready( p_playlist );
+    int i_loops = 0;
 
+    /* Tell above that we're ready */
+    vlc_thread_ready( p_playlist );
     while( !p_playlist->b_die )
     {
         i_loops++;
@@ -191,26 +211,6 @@ static void RunControlThread ( playlist_t *p_playlist )
             PL_UNLOCK;
         }
     }
-
-    EndPlaylist( p_playlist );
-}
-
-
-/*****************************************************************************
- * Playlist-specific functions
- *****************************************************************************/
-static playlist_t * CreatePlaylist( vlc_object_t *p_parent )
-{
-    return playlist_Create( p_parent );
-}
-
-static void DestroyPlaylist( playlist_t *p_playlist )
-{
-    playlist_Destroy( p_playlist );
-}
-
-static void EndPlaylist( playlist_t *p_playlist )
-{
     playlist_LastLoop( p_playlist );
 }