+ playlist_private_t *p_sys = pl_priv(p_playlist);
+ assert( !p_sys->p_input );
+
+ /* No input. Several cases
+ * - No request, running status -> start new item
+ * - No request, stopped status -> collect garbage
+ * - Request, running requested -> start new item
+ * - Request, stopped requested -> collect garbage
+ */
+ const int i_status = p_sys->request.b_request ?
+ p_sys->request.i_status : p_sys->status.i_status;
+
+ if( i_status == PLAYLIST_STOPPED || !vlc_object_alive( p_playlist ) )
+ {
+ p_sys->status.i_status = PLAYLIST_STOPPED;
+
+ if( p_sys->p_input_resource &&
+ input_resource_HasVout( p_sys->p_input_resource ) )
+ {
+ /* XXX We can unlock if we don't issue the wait as we will be
+ * call again without anything else done between the calls */
+ PL_UNLOCK;
+
+ /* input_resource_t must be manipulated without playlist lock */
+ input_resource_TerminateVout( p_sys->p_input_resource );
+
+ PL_LOCK;
+ }
+ else
+ {
+ if( vlc_object_alive( p_playlist ) )
+ vlc_cond_wait( &p_sys->signal, &p_sys->lock );
+ }
+ return;
+ }
+
+ playlist_item_t *p_item = NextItem( p_playlist );
+ if( p_item )
+ {
+ msg_Dbg( p_playlist, "starting new item" );
+ PlayItem( p_playlist, p_item );
+ return;
+ }
+
+ msg_Dbg( p_playlist, "nothing to play" );
+ p_sys->status.i_status = PLAYLIST_STOPPED;
+
+ if( var_GetBool( p_playlist, "play-and-exit" ) )
+ {
+ msg_Info( p_playlist, "end of playlist, exiting" );
+ libvlc_Quit( p_playlist->p_libvlc );
+ }