/** * Run the main control thread itself */ static void *Thread ( void *data ) { playlist_t *p_playlist = data; playlist_private_t *p_sys = pl_priv(p_playlist); PL_LOCK; for( ;; ) { while( p_sys->p_input != NULL ) LoopInput( p_playlist ); if( p_sys->killed ) break; /* THE END */ const int status = p_sys->request.b_request ? p_sys->request.i_status : p_sys->status.i_status; /* Destroy any video display if the playlist is supposed to stop */ if( status == PLAYLIST_STOPPED && input_resource_HasVout( p_sys->p_input_resource ) ) { PL_UNLOCK; /* Mind: NO LOCKS while manipulating input resources! */ input_resource_TerminateVout( p_sys->p_input_resource ); PL_LOCK; continue; /* lost lock = lost state */ } LoopRequest( p_playlist, status ); } p_sys->status.i_status = PLAYLIST_STOPPED; PL_UNLOCK; input_resource_Terminate( p_sys->p_input_resource ); return NULL; }
/************************************************************************** * Destroy a Media Instance object (libvlc internal) * * Warning: No lock held here, but hey, this is internal. Caller must lock. **************************************************************************/ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi ) { assert( p_mi ); /* Detach Callback from the main libvlc object */ var_DelCallback( p_mi->p_libvlc, "snapshot-file", snapshot_was_taken, p_mi ); /* No need for lock_input() because no other threads knows us anymore */ if( p_mi->input.p_thread ) release_input_thread(p_mi, true); if( p_mi->input.p_resource ) { input_resource_Terminate( p_mi->input.p_resource ); input_resource_Release( p_mi->input.p_resource ); p_mi->input.p_resource = NULL; } vlc_mutex_destroy( &p_mi->input.lock ); libvlc_event_manager_release( p_mi->p_event_manager ); libvlc_media_release( p_mi->p_md ); vlc_mutex_destroy( &p_mi->object_lock ); libvlc_instance_t *instance = p_mi->p_libvlc_instance; vlc_object_release( p_mi ); libvlc_release(instance); }
/** * Run the main control thread itself */ static void *Thread ( void *data ) { playlist_t *p_playlist = data; playlist_private_t *p_sys = pl_priv(p_playlist); PL_LOCK; while( !p_sys->killed ) { /* Playlist in stopped state */ assert(p_sys->p_input == NULL); if( !p_sys->request.b_request ) { vlc_cond_wait( &p_sys->signal, &p_sys->lock ); continue; } while( !p_sys->killed && Next( p_playlist ) ) { /* Playlist in running state */ assert(p_sys->p_input != NULL); do LoopInput( p_playlist ); while( p_sys->p_input != NULL ); } msg_Dbg( p_playlist, "nothing to play" ); if( var_InheritBool( p_playlist, "play-and-exit" ) ) { msg_Info( p_playlist, "end of playlist, exiting" ); libvlc_Quit( p_playlist->p_libvlc ); } /* Destroy any video display now (XXX: ugly hack) */ if( input_resource_HasVout( p_sys->p_input_resource ) ) { PL_UNLOCK; /* Mind: NO LOCKS while manipulating input resources! */ input_resource_TerminateVout( p_sys->p_input_resource ); PL_LOCK; } } PL_UNLOCK; input_resource_Terminate( p_sys->p_input_resource ); return NULL; }
/************************************************************************** * Stop playing. **************************************************************************/ void libvlc_media_player_stop( libvlc_media_player_t *p_mi ) { libvlc_state_t state = libvlc_media_player_get_state( p_mi ); lock_input(p_mi); release_input_thread( p_mi, true ); /* This will stop the input thread */ /* Force to go to stopped state, in case we were in Ended, or Error * state. */ if( state != libvlc_Stopped ) { set_state( p_mi, libvlc_Stopped, false ); /* Construct and send the event */ libvlc_event_t event; event.type = libvlc_MediaPlayerStopped; libvlc_event_send( p_mi->p_event_manager, &event ); } input_resource_Terminate( p_mi->input.p_resource ); unlock_input(p_mi); }
void playlist_Deactivate( playlist_t *p_playlist ) { /* */ playlist_private_t *p_sys = pl_priv(p_playlist); msg_Dbg( p_playlist, "deactivating the playlist" ); PL_LOCK; vlc_object_kill( p_playlist ); vlc_cond_signal( &p_sys->signal ); PL_UNLOCK; vlc_join( p_sys->thread, NULL ); assert( !p_sys->p_input ); /* release input resources */ if( p_sys->p_input_resource ) { input_resource_Terminate( p_sys->p_input_resource ); input_resource_Release( p_sys->p_input_resource ); } p_sys->p_input_resource = NULL; if( var_InheritBool( p_playlist, "media-library" ) ) playlist_MLDump( p_playlist ); PL_LOCK; /* Release the current node */ set_current_status_node( p_playlist, NULL ); /* Release the current item */ set_current_status_item( p_playlist, NULL ); PL_UNLOCK; msg_Dbg( p_playlist, "playlist correctly deactivated" ); }