- if( p_playlist->b_reset_currently_playing &&
- mdate() - p_playlist->last_rebuild_date > 30000 ) // 30 ms
- {
- ResetCurrentlyPlaying( p_playlist, var_GetBool( p_playlist, "random" ),
- p_playlist->status.p_item );
- p_playlist->last_rebuild_date = mdate();
- }
-
-check_input:
- /* If there is an input, check that it doesn't need to die. */
- if( p_playlist->p_input )
- {
- if( p_playlist->request.b_request && !p_playlist->p_input->b_die )
- {
- PL_DEBUG( "incoming request - stopping current input" );
- input_StopThread( p_playlist->p_input );
- }
-
- /* This input is dead. Remove it ! */
- if( p_playlist->p_input->b_dead )
- {
- int i_activity;
- input_thread_t *p_input;
- sout_instance_t **pp_sout =
- &libvlc_priv(p_playlist->p_libvlc)->p_sout;
-
- PL_DEBUG( "dead input" );
-
- p_input = p_playlist->p_input;
-
- assert( *pp_sout == NULL );
- if( var_CreateGetBool( p_input, "sout-keep" ) )
- *pp_sout = input_DetachSout( p_input );
-
- /* Destroy input */
- playlist_release_current_input( p_playlist );
-
- p_playlist->gc_date = mdate();
- p_playlist->b_cant_sleep = true;
-
- if( p_playlist->status.p_item->i_flags
- & PLAYLIST_REMOVE_FLAG )
- {
- PL_DEBUG( "%s was marked for deletion, deleting",
- PLI_NAME( p_playlist->status.p_item ) );
- playlist_ItemDelete( p_playlist->status.p_item );
- if( p_playlist->request.p_item == p_playlist->status.p_item )
- p_playlist->request.p_item = NULL;
- p_playlist->status.p_item = NULL;
- }
-
- i_activity= var_GetInteger( p_playlist, "activity" );
- var_SetInteger( p_playlist, "activity", i_activity -
- DEFAULT_INPUT_ACTIVITY );
-
- goto check_input;
- }
- /* This input is dying, let it do */
- else if( p_playlist->p_input->b_die )
- {
- PL_DEBUG( "dying input" );
- PL_UNLOCK;
- msleep( INTF_IDLE_SLEEP );
- PL_LOCK;
- goto check_input;
- }
- /* This input has finished, ask it to die ! */
- else if( p_playlist->p_input->b_error
- || p_playlist->p_input->b_eof )
- {
- PL_DEBUG( "finished input" );
- input_StopThread( p_playlist->p_input );
- /* No need to wait here, we'll wait in the p_input->b_die case */
- goto check_input;
- }
- else if( p_playlist->p_input->i_state != INIT_S )
- {
- PL_UNLOCK;
- ObjectGarbageCollector( p_playlist, false );
- PL_LOCK;
- }
- }
- else
- {
- /* 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
- */
- int i_status = p_playlist->request.b_request ?
- p_playlist->request.i_status : p_playlist->status.i_status;
- if( i_status != PLAYLIST_STOPPED )
- {
- msg_Dbg( p_playlist, "starting new item" );
- p_item = playlist_NextItem( p_playlist );
-
- if( p_item == NULL )
- {
- msg_Dbg( p_playlist, "nothing to play" );
- p_playlist->status.i_status = PLAYLIST_STOPPED;
- PL_UNLOCK;
-
- if( b_playexit == true )
- {
- msg_Info( p_playlist, "end of playlist, exiting" );
- vlc_object_kill( p_playlist->p_libvlc );
- }
- ObjectGarbageCollector( p_playlist, true );
- return;
- }
- playlist_PlayItem( p_playlist, p_item );
- }
- else
- {
- const bool b_gc_forced = p_playlist->status.i_status != PLAYLIST_STOPPED;
-
- p_playlist->status.i_status = PLAYLIST_STOPPED;
- if( p_playlist->status.p_item &&
- p_playlist->status.p_item->i_flags & PLAYLIST_REMOVE_FLAG )
- {
- PL_DEBUG( "deleting item marked for deletion" );
- playlist_ItemDelete( p_playlist->status.p_item );
- p_playlist->status.p_item = NULL;
- }
-
- /* Collect garbage */
- PL_UNLOCK;
- ObjectGarbageCollector( p_playlist, b_gc_forced );
- PL_LOCK;
- }
- }
- PL_UNLOCK;