]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
macosx: Fix crash log and remove some unneeded NSLog.
[vlc] / src / playlist / engine.c
index 6a378fe7b797a304a4e925b03763461b81f5b634..ce92f756cf53940b27ad1f25d8bc3847975e9329 100644 (file)
@@ -76,7 +76,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     VariablesInit( p_playlist );
 
     /* Initialise data structures */
-    vlc_mutex_init( &p_playlist->gc_lock );
     p_playlist->i_last_playlist_id = 0;
     p_playlist->p_input = NULL;
 
@@ -85,6 +84,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 
     ARRAY_INIT( p_playlist->items );
     ARRAY_INIT( p_playlist->all_items );
+    ARRAY_INIT( p_playlist->items_to_delete );
     ARRAY_INIT( p_playlist->current );
 
     p_playlist->i_current_index = 0;
@@ -198,9 +198,7 @@ static void ObjectGarbageCollector( playlist_t *p_playlist, bool b_force )
             return;
     }
 
-    vlc_mutex_lock( &p_playlist->gc_lock );
     p_playlist->b_cant_sleep = false;
-    vlc_mutex_unlock( &p_playlist->gc_lock );
 }
 
 /* Input Callback */
@@ -305,9 +303,8 @@ void set_current_status_item( playlist_t * p_playlist,
         p_playlist->status.p_item->i_flags & PLAYLIST_REMOVE_FLAG &&
         p_playlist->status.p_item != p_item )
     {
-         PL_DEBUG( "%s was marked for deletion, deleting",
-                         PLI_NAME( p_playlist->status.p_item  ) );
-         playlist_ItemDelete( p_playlist->status.p_item );
+        /* It's unsafe given current design to delete a playlist item :(
+        playlist_ItemDelete( p_playlist->status.p_item ); */
     }
     p_playlist->status.p_item = p_item;
 }
@@ -321,9 +318,8 @@ void set_current_status_node( playlist_t * p_playlist,
         p_playlist->status.p_node->i_flags & PLAYLIST_REMOVE_FLAG &&
         p_playlist->status.p_node != p_node )
     {
-         PL_DEBUG( "%s was marked for deletion, deleting",
-                         PLI_NAME( p_playlist->status.p_node  ) );
-         playlist_ItemDelete( p_playlist->status.p_node );
+        /* It's unsafe given current design to delete a playlist item :(
+        playlist_ItemDelete( p_playlist->status.p_node ); */
     }
     p_playlist->status.p_node = p_node;
 }
@@ -331,7 +327,8 @@ void set_current_status_node( playlist_t * p_playlist,
 /**
  * Main loop
  *
- * Main loop for the playlist
+ * Main loop for the playlist. It should be entered with the
+ * playlist lock (otherwise input event may be lost)
  * \param p_playlist the playlist object
  * \return nothing
  */
@@ -339,7 +336,8 @@ void playlist_MainLoop( playlist_t *p_playlist )
 {
     playlist_item_t *p_item = NULL;
     bool b_playexit = var_GetBool( p_playlist, "play-and-exit" );
-    PL_LOCK;
+
+    PL_ASSERT_LOCKED;
 
     if( p_playlist->b_reset_currently_playing &&
         mdate() - p_playlist->last_rebuild_date > 30000 ) // 30 ms
@@ -381,8 +379,6 @@ check_input:
             p_playlist->gc_date = mdate();
             p_playlist->b_cant_sleep = true;
 
-            set_current_status_item( p_playlist, NULL );
-
             i_activity= var_GetInteger( p_playlist, "activity" );
             var_SetInteger( p_playlist, "activity", i_activity -
                             DEFAULT_INPUT_ACTIVITY );
@@ -409,9 +405,7 @@ check_input:
         }
         else if( p_playlist->p_input->i_state != INIT_S )
         {
-            PL_UNLOCK;
             ObjectGarbageCollector( p_playlist, false );
-            PL_LOCK;
         }
     }
     else
@@ -433,7 +427,6 @@ check_input:
             {
                 msg_Dbg( p_playlist, "nothing to play" );
                 p_playlist->status.i_status = PLAYLIST_STOPPED;
-                PL_UNLOCK;
 
                 if( b_playexit == true )
                 {
@@ -442,23 +435,21 @@ check_input:
                 }
                 ObjectGarbageCollector( p_playlist, true );
                 return;
-             }
-             playlist_PlayItem( p_playlist, p_item );
-         }
-         else
-         {
+            }
+            playlist_PlayItem( p_playlist, p_item );
+            /* playlist_PlayItem loose input event, we need to recheck */
+            goto check_input;
+        }
+        else
+        {
             const bool b_gc_forced = p_playlist->status.i_status != PLAYLIST_STOPPED;
 
             p_playlist->status.i_status = PLAYLIST_STOPPED;
-            set_current_status_item( p_playlist, NULL );
 
             /* Collect garbage */
-            PL_UNLOCK;
             ObjectGarbageCollector( p_playlist, b_gc_forced );
-            PL_LOCK;
         }
     }
-    PL_UNLOCK;
 }
 
 /**
@@ -542,6 +533,12 @@ void playlist_LastLoop( playlist_t *p_playlist )
         free( p_del );
     FOREACH_END();
     ARRAY_RESET( p_playlist->all_items );
+    FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->items_to_delete )
+        free( p_del->pp_children );
+        vlc_gc_decref( p_del->p_input );
+        free( p_del );
+    FOREACH_END();
+    ARRAY_RESET( p_playlist->items_to_delete );
 
     ARRAY_RESET( p_playlist->items );
     ARRAY_RESET( p_playlist->current );