/************************************************************************** * 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); }
/************************************************************************** * Set the Media descriptor associated with the instance. * * Enter without lock -- function will lock the object. **************************************************************************/ void libvlc_media_player_set_media( libvlc_media_player_t *p_mi, libvlc_media_t *p_md ) { lock_input(p_mi); /* FIXME I am not sure if it is a user request or on die(eof/error) * request here */ release_input_thread( p_mi, p_mi->input.p_thread && !p_mi->input.p_thread->b_eof && !p_mi->input.p_thread->b_error ); lock( p_mi ); set_state( p_mi, libvlc_NothingSpecial, true ); unlock_input( p_mi ); libvlc_media_release( p_mi->p_md ); if( !p_md ) { p_mi->p_md = NULL; unlock(p_mi); return; /* It is ok to pass a NULL md */ } libvlc_media_retain( p_md ); p_mi->p_md = p_md; /* The policy here is to ignore that we were created using a different * libvlc_instance, because we don't really care */ p_mi->p_libvlc_instance = p_md->p_libvlc_instance; unlock(p_mi); /* Send an event for the newly available media */ libvlc_event_t event; event.type = libvlc_MediaPlayerMediaChanged; event.u.media_player_media_changed.new_media = p_md; libvlc_event_send( p_mi->p_event_manager, &event ); }
/************************************************************************** * 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); }