]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
Beginning of implementation of art fetch when played
[vlc] / src / playlist / engine.c
index 9840a3f61c6cd9574a2788e7cb7172158992e03e..cca6fdaaffd7983a437d5470a62b0f3bf01941a9 100644 (file)
@@ -97,6 +97,9 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL);
     p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL);
 
+    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 );
@@ -105,6 +108,11 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     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;
@@ -115,6 +123,10 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
                            _( "Media Library" ), p_playlist->p_root_category );
         p_playlist->p_ml_onelevel =  playlist_NodeCreate( p_playlist,
                            _( "Media Library" ), p_playlist->p_root_onelevel );
+
+        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 =
@@ -201,7 +213,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 +533,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 +543,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 +560,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 +613,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 +642,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
                 {