]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
* Do not take and release the structure lock for each element of the list while
[vlc] / src / playlist / engine.c
index 9840a3f61c6cd9574a2788e7cb7172158992e03e..f83409d3b86d94889639215d8be43a807a7ba540 100644 (file)
  *****************************************************************************/
 
 #include <vlc/vlc.h>
-#include <vlc/vout.h>
-#include <vlc/sout.h>
-#include <vlc/input.h>
-#include "vlc_playlist.h"
-#include "vlc_interaction.h"
+#include <vlc_vout.h>
+#include <vlc_sout.h>
+#include <vlc_playlist.h>
+#include <vlc_interface.h>
 #include "playlist_internal.h"
+#include "stream_output/stream_output.h" /* sout_DeleteInstance */
 
 /*****************************************************************************
  * Local prototypes
@@ -94,17 +94,27 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist->b_auto_preparse =
                         var_CreateGetBool( p_playlist, "auto-preparse") ;
 
-    p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL);
-    p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL);
+    p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL,
+                                                       0 );
+    p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL,
+                                                       0 );
+
+    if( !p_playlist->p_root_category || !p_playlist->p_root_onelevel )
+        return NULL;
 
     /* Create playlist and media library */
     p_playlist->p_local_category = playlist_NodeCreate( p_playlist,
-                                 _( "Playlist" ),p_playlist->p_root_category );
+                              _( "Playlist" ),p_playlist->p_root_category, 0 );
     p_playlist->p_local_onelevel =  playlist_NodeCreate( p_playlist,
-                                _( "Playlist" ), p_playlist->p_root_onelevel );
+                              _( "Playlist" ), p_playlist->p_root_onelevel, 0 );
     p_playlist->p_local_category->i_flags |= PLAYLIST_RO_FLAG;
     p_playlist->p_local_onelevel->i_flags |= PLAYLIST_RO_FLAG;
 
+    if( !p_playlist->p_local_category || !p_playlist->p_local_onelevel ||
+        !p_playlist->p_local_category->p_input ||
+        !p_playlist->p_local_onelevel->p_input )
+        return NULL;
+
     /* Link the nodes together. Todo: actually create them from the same input*/
     p_playlist->p_local_onelevel->p_input->i_id =
         p_playlist->p_local_category->p_input->i_id;
@@ -112,9 +122,13 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     if( config_GetInt( p_playlist, "media-library") )
     {
         p_playlist->p_ml_category =   playlist_NodeCreate( p_playlist,
-                           _( "Media Library" ), p_playlist->p_root_category );
+                         _( "Media Library" ), p_playlist->p_root_category, 0 );
         p_playlist->p_ml_onelevel =  playlist_NodeCreate( p_playlist,
-                           _( "Media Library" ), p_playlist->p_root_onelevel );
+                         _( "Media Library" ), p_playlist->p_root_onelevel, 0 );
+
+        if(!p_playlist->p_ml_category || !p_playlist->p_ml_onelevel)
+            return NULL;
+
         p_playlist->p_ml_category->i_flags |= PLAYLIST_RO_FLAG;
         p_playlist->p_ml_onelevel->i_flags |= PLAYLIST_RO_FLAG;
         p_playlist->p_ml_onelevel->p_input->i_id =
@@ -193,6 +207,7 @@ void playlist_Destroy( playlist_t *p_playlist )
 
     PL_UNLOCK;
 
+    vlc_mutex_destroy( &p_playlist->p_stats->lock );
     if( p_playlist->p_stats )
         free( p_playlist->p_stats );
 
@@ -201,7 +216,6 @@ void playlist_Destroy( playlist_t *p_playlist )
     vlc_object_destroy( p_playlist->p_fetcher );
     vlc_object_detach( p_playlist );
     vlc_object_destroy( p_playlist );
-
 }
 
 /* Destroy remaining objects */
@@ -522,7 +536,8 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
              * This only checks for meta, not for art
              * \todo don't do this for things we won't get meta for, like vids
              */
-            if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o ) )
+            if( p_current->p_meta &&
+                !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o ) )
             {
                 preparse_item_t p;
                 PL_DEBUG("need to fetch meta for %s", p_current->psz_name );
@@ -531,13 +546,13 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
                 vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
                 INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
                              p_playlist->p_fetcher->i_waiting,
-                             p_playlist->p_fetcher->i_waiting,
-                             p );
+                             p_playlist->p_fetcher->i_waiting, p);
                 vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
                 vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
             }
             /* We already have all needed meta, but we need art right now */
-            else if( p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL &&
+            else if( p_current->p_meta &&
+                     p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL &&
                      EMPTY_STR( p_current->p_meta->psz_arturl ) )
             {
                 preparse_item_t p;
@@ -548,15 +563,16 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
                 vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
                 INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
                              p_playlist->p_fetcher->i_waiting,
-                             p_playlist->p_fetcher->i_waiting,
-                             p );
+                             p_playlist->p_fetcher->i_waiting, p);
                 vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
                 vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
             }
             else
             {
                 PL_DEBUG( "no fetch required for %s (art currently %s)",
-                          p_current->psz_name, p_current->p_meta->psz_arturl );
+                          p_current->psz_name,
+                          p_current->p_meta ? p_current->p_meta->psz_arturl:
+                                              "null" );
                 vlc_gc_decref( p_current );
             }
             PL_UNLOCK;
@@ -600,6 +616,7 @@ void playlist_FetcherLoop( playlist_fetcher_t *p_obj )
         vlc_mutex_unlock( &p_obj->object_lock );
         if( p_item )
         {
+            assert( p_item->p_meta );
             if( !b_fetch_art )
             {
                 input_MetaFetch( p_playlist, p_item );
@@ -628,15 +645,19 @@ void playlist_FetcherLoop( playlist_fetcher_t *p_obj )
                 if( i_ret == 1 )
                 {
                     PL_DEBUG("downloading art for %s", p_item->psz_name );
-                    if( !input_DownloadAndCacheArt( p_playlist, p_item ) )
+                    if( input_DownloadAndCacheArt( p_playlist, p_item ) )
                         p_item->p_meta->i_status |= ITEM_ART_NOTFOUND;
-                    else
+                    else {
                         p_item->p_meta->i_status |= ITEM_ART_FETCHED;
+                        var_SetInteger( p_playlist, "item-change",
+                                        p_item->i_id );
+                    }
                 }
                 else if( i_ret == 0 ) /* Was in cache */
                 {
                     PL_DEBUG("found art for %s in cache", p_item->psz_name );
                     p_item->p_meta->i_status |= ITEM_ART_FETCHED;
+                    var_SetInteger( p_playlist, "item-change", p_item->i_id );
                 }
                 else
                 {