- /* First, check if we have something to do */
- /* FIXME : this can be called several times */
- if( p_playlist->request.b_request )
- {
- /* Stop the existing input */
- if( p_playlist->p_input && !p_playlist->p_input->b_die )
- {
- PL_DEBUG( "incoming request - stopping current input" );
- input_StopThread( p_playlist->p_input );
- }
- }
-
- /* If there is an input, check that it doesn't need to die. */
- if( 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;
- PL_DEBUG( "dead input" );
-
- p_input = p_playlist->p_input;
- p_playlist->p_input = NULL;
-
- /* Release the playlist lock, because we may get stuck
- * in input_DestroyThread() for some time. */
- PL_UNLOCK
-
- /* 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 );
-
- p_playlist->i_vout_destroyed_date = 0;
- p_playlist->i_sout_destroyed_date = 0;
-
- 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 );
-
- return;
- }
- /* This input is dying, let it do */
- else if( p_playlist->p_input->b_die )
- {
- PL_DEBUG( "dying 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 );
- /* Select the next playlist item */
- PL_UNLOCK
- return;
- }
- else if( p_playlist->p_input->i_state != INIT_S )
- {
- PL_UNLOCK;
- p_playlist->i_vout_destroyed_date =
- ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
- p_playlist->i_vout_destroyed_date );
- p_playlist->i_sout_destroyed_date =
- ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
- p_playlist->i_sout_destroyed_date );
- 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
- */
- if( (!p_playlist->request.b_request &&
- p_playlist->status.i_status != PLAYLIST_STOPPED) ||
- ( p_playlist->request.b_request &&
- p_playlist->request.i_status != PLAYLIST_STOPPED ) )
- {
- msg_Dbg( p_playlist, "starting new item" );
- stats_TimerStart( p_playlist, "Playlist walk",
- STATS_TIMER_PLAYLIST_WALK );
- p_item = playlist_NextItem( p_playlist );
- stats_TimerStop( p_playlist, STATS_TIMER_PLAYLIST_WALK );
-
- if( p_item == NULL )
- {
- msg_Dbg( p_playlist, "nothing to play" );
- if( b_playexit == VLC_TRUE )
- {
- msg_Info( p_playlist, "end of playlist, exiting" );
- p_playlist->p_libvlc->b_die = VLC_TRUE;
- }
- p_playlist->status.i_status = PLAYLIST_STOPPED;
- PL_UNLOCK
- return;
- }
- playlist_PlayItem( p_playlist, p_item );
- }
- else
- {
- 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
- p_playlist->i_sout_destroyed_date =
- ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, mdate() );
- p_playlist->i_vout_destroyed_date =
- ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, mdate() );
- PL_LOCK
- }
- }
- PL_UNLOCK