]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
Reworked/improved the way sout-keep works. (VLM sout-keep does not
[vlc] / src / playlist / engine.c
index 4e510eb9186c63301cf2670e142ba2c9cede3a21..d405e41107bdc98fb12d077e229b6560ff7a8d59 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,19 @@ 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;
 
@@ -120,9 +122,9 @@ 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;
@@ -147,7 +149,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist->i_sort = SORT_ID;
     p_playlist->i_order = ORDER_NORMAL;
 
-    vlc_object_attach( p_playlist, p_parent );
     b_save = p_playlist->b_auto_preparse;
     p_playlist->b_auto_preparse = VLC_FALSE;
     playlist_MLLoad( p_playlist );
@@ -157,21 +158,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 
 void playlist_Destroy( playlist_t *p_playlist )
 {
-    while( p_playlist->i_sds )
-    {
-        playlist_ServicesDiscoveryRemove( p_playlist,
-                                          p_playlist->pp_sds[0]->psz_module );
-    }
-
-    playlist_MLDump( p_playlist );
-
-    vlc_thread_join( p_playlist->p_preparse );
-    vlc_thread_join( p_playlist->p_fetcher );
-    vlc_thread_join( p_playlist );
-
-    vlc_object_detach( p_playlist->p_preparse );
-    vlc_object_detach( p_playlist->p_fetcher );
-
     var_Destroy( p_playlist, "intf-change" );
     var_Destroy( p_playlist, "item-change" );
     var_Destroy( p_playlist, "playlist-current" );
@@ -184,33 +170,7 @@ void playlist_Destroy( playlist_t *p_playlist )
     var_Destroy( p_playlist, "loop" );
     var_Destroy( p_playlist, "activity" );
 
-    PL_LOCK;
-    /* Go through all items, and simply free everything without caring
-     * about the tree structure. Do not decref, it will be done by doing
-     * the same thing on the input items array */
-    FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->all_items )
-        free( p_del->pp_children );
-        free( p_del );
-    FOREACH_END();
-    ARRAY_RESET( p_playlist->all_items );
-
-    FOREACH_ARRAY( input_item_t *p_del, p_playlist->input_items )
-        input_ItemClean( p_del );
-        free( p_del );
-    FOREACH_END();
-    ARRAY_RESET( p_playlist->input_items );
-
-    ARRAY_RESET( p_playlist->items );
-    ARRAY_RESET( p_playlist->current );
-
-    PL_UNLOCK;
-
-    if( p_playlist->p_stats )
-        free( p_playlist->p_stats );
-
     vlc_mutex_destroy( &p_playlist->gc_lock );
-    vlc_object_destroy( p_playlist->p_preparse );
-    vlc_object_destroy( p_playlist->p_fetcher );
     vlc_object_detach( p_playlist );
     vlc_object_destroy( p_playlist );
 }
@@ -250,6 +210,8 @@ static void ObjectGarbageCollector( playlist_t *p_playlist )
             vlc_object_release( p_obj );
             break;
         }
+        msg_Dbg( p_playlist, "garbage collector destroying 1 sout" );
+        vlc_object_detach( p_obj );
         vlc_object_release( p_obj );
         sout_DeleteInstance( (sout_instance_t*)p_obj );
     }
@@ -299,13 +261,6 @@ check_input:
             /* Destroy input */
             input_DestroyThread( p_input );
 
-            /* Unlink current input
-             * (_after_ input_DestroyThread for vout garbage collector) */
-            vlc_object_detach( p_input );
-
-            /* Destroy object */
-            vlc_object_destroy( p_input );
-
             PL_LOCK;
 
             p_playlist->gc_date = mdate();
@@ -331,7 +286,9 @@ check_input:
         else if( p_playlist->p_input->b_die )
         {
             PL_DEBUG( "dying input" );
+            PL_UNLOCK;
             msleep( 25000 ); // 25 ms
+            PL_LOCK;
             goto check_input;
         }
         /* This input has finished, ask it to die ! */
@@ -427,12 +384,6 @@ void playlist_LastLoop( playlist_t *p_playlist )
 
             /* Destroy input */
             input_DestroyThread( p_input );
-            /* Unlink current input (_after_ input_DestroyThread for vout
-             * garbage collector)*/
-            vlc_object_detach( p_input );
-
-            /* Destroy object */
-            vlc_object_destroy( p_input );
             continue;
         }
         else if( p_playlist->p_input->b_die )
@@ -460,6 +411,7 @@ void playlist_LastLoop( playlist_t *p_playlist )
     while( ( p_obj = vlc_object_find( p_playlist,
                                       VLC_OBJECT_SOUT, FIND_CHILD ) ) )
     {
+        vlc_object_detach( p_obj );
         vlc_object_release( p_obj );
         sout_DeleteInstance( (sout_instance_t*)p_obj );
     }
@@ -472,6 +424,35 @@ void playlist_LastLoop( playlist_t *p_playlist )
         vlc_object_release( p_obj );
         vout_Destroy( (vout_thread_t *)p_obj );
     }
+
+    while( p_playlist->i_sds )
+    {
+        playlist_ServicesDiscoveryRemove( p_playlist,
+                                          p_playlist->pp_sds[0]->psz_module );
+    }
+
+    playlist_MLDump( p_playlist );
+
+    PL_LOCK;
+    /* Go through all items, and simply free everything without caring
+     * about the tree structure. Do not decref, it will be done by doing
+     * the same thing on the input items array */
+    FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->all_items )
+        free( p_del->pp_children );
+        free( p_del );
+    FOREACH_END();
+    ARRAY_RESET( p_playlist->all_items );
+
+    FOREACH_ARRAY( input_item_t *p_del, p_playlist->input_items )
+        input_ItemClean( p_del );
+        free( p_del );
+    FOREACH_END();
+    ARRAY_RESET( p_playlist->input_items );
+
+    ARRAY_RESET( p_playlist->items );
+    ARRAY_RESET( p_playlist->current );
+
+    PL_UNLOCK;
 }
 
 /** Main loop for preparser queue */
@@ -558,9 +539,9 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
                 p.p_item = p_current;
                 p.b_fetch_art = VLC_TRUE;
                 vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
-                TAB_APPEND( p_playlist->p_fetcher->i_waiting,
-                            p_playlist->p_fetcher->p_waiting,
-                            );
+                INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
+                             p_playlist->p_fetcher->i_waiting,
+                             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 );
             }
@@ -642,15 +623,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
                 {