X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmedia_list_player.c;h=1ed1af0b324b10fb3d79127718a99877066d19ef;hb=c5c06b64c806052086e5772d64e540a8db7e4a9b;hp=40b45dba0b70e8cec0662d770da64d24b3e1f080;hpb=cd4c4f1dadf2a9b595948da6d70ac2eaad93c990;p=vlc diff --git a/src/control/media_list_player.c b/src/control/media_list_player.c index 40b45dba0b..1ed1af0b32 100644 --- a/src/control/media_list_player.c +++ b/src/control/media_list_player.c @@ -20,10 +20,32 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "libvlc_internal.h" + #include +#include +#include +#include +#include +#include + +#include "libvlc_internal.h" + +#include "media_internal.h" // Abuse, could and should be removed #include "media_list_path.h" + +struct libvlc_media_list_player_t +{ + libvlc_event_manager_t * p_event_manager; + libvlc_instance_t * p_libvlc_instance; + int i_refcount; + vlc_mutex_t object_lock; + libvlc_media_list_path_t current_playing_item_path; + libvlc_media_t * p_current_playing_item; + libvlc_media_list_t * p_mlist; + libvlc_media_player_t * p_mi; +}; + /* * Private functions */ @@ -43,7 +65,9 @@ get_next_path( libvlc_media_list_player_t * p_mlp ) if ( !p_mlp->current_playing_item_path ) { - p_mlp->current_playing_item_path = libvlc_media_list_path_empty(); + if( !libvlc_media_list_count( p_mlp->p_mlist, NULL ) ) + return NULL; + return libvlc_media_list_path_with_root_index(0); } p_sublist_of_playing_item = libvlc_media_list_sublist_at_path( @@ -62,23 +86,23 @@ get_next_path( libvlc_media_list_player_t * p_mlp ) p_mlp->p_mlist, p_mlp->current_playing_item_path ); - int deepness = libvlc_media_list_path_deepness( p_mlp->current_playing_item_path ); - if( deepness < 1 || !p_parent_of_playing_item ) + int depth = libvlc_media_list_path_depth( p_mlp->current_playing_item_path ); + if( depth < 1 || !p_parent_of_playing_item ) return NULL; ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path ); - while( ret[deepness-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) ) + while( ret[depth-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) ) { - deepness--; - if( deepness <= 0 ) + depth--; + if( depth <= 0 ) { free( ret ); libvlc_media_list_release( p_parent_of_playing_item ); return NULL; } - ret[deepness] = -1; - ret[deepness-1]++; + ret[depth] = -1; + ret[depth-1]++; p_parent_of_playing_item = libvlc_media_list_parentlist_at_path( p_mlp->p_mlist, ret ); @@ -204,12 +228,15 @@ set_current_playing_item( libvlc_media_list_player_t * p_mlp, VLC_UNUSED(p_e); libvlc_media_t * p_md; - - p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path ); + + p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path ); vlc_mutex_lock( &p_mlp->object_lock ); - - free( p_mlp->current_playing_item_path ); - p_mlp->current_playing_item_path = path; + + if( p_mlp->current_playing_item_path != path ) + { + free( p_mlp->current_playing_item_path ); + p_mlp->current_playing_item_path = path; + } if( !p_md ) { @@ -256,10 +283,16 @@ libvlc_media_list_player_new( libvlc_instance_t * p_instance, (void)p_e; libvlc_media_list_player_t * p_mlp; p_mlp = malloc(sizeof(libvlc_media_list_player_t)); + if( !p_mlp ) + return NULL; + + libvlc_retain( p_instance ); + p_mlp->p_libvlc_instance = p_instance; + p_mlp->i_refcount = 0; + vlc_mutex_init( &p_mlp->object_lock ); p_mlp->current_playing_item_path = NULL; - p_mlp->p_mi = NULL; p_mlp->p_mlist = NULL; - vlc_mutex_init( &p_mlp->object_lock ); + p_mlp->p_mi = NULL; p_mlp->p_event_manager = libvlc_event_manager_new( p_mlp, p_instance, p_e ); @@ -274,7 +307,32 @@ libvlc_media_list_player_new( libvlc_instance_t * p_instance, **************************************************************************/ void libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp ) { - free(p_mlp); + if( !p_mlp ) + return; + + vlc_mutex_lock( &p_mlp->object_lock ); + + p_mlp->i_refcount--; + if( p_mlp->i_refcount > 0 ) + { + vlc_mutex_unlock( &p_mlp->object_lock ); + return; + } + vlc_mutex_unlock( &p_mlp->object_lock ); + vlc_mutex_destroy( &p_mlp->object_lock ); + + libvlc_event_manager_release( p_mlp->p_event_manager ); + libvlc_media_player_release( p_mlp->p_mi ); + + if( p_mlp->p_mlist ) + { + uninstall_playlist_observer( p_mlp ); + libvlc_media_list_release( p_mlp->p_mlist ); + } + + free( p_mlp->current_playing_item_path ); + libvlc_release( p_mlp->p_libvlc_instance ); + free( p_mlp ); } /************************************************************************** @@ -311,7 +369,7 @@ void libvlc_media_list_player_set_media_list( libvlc_exception_t * p_e ) { vlc_mutex_lock( &p_mlp->object_lock ); - + if( libvlc_media_list_player_is_playing( p_mlp, p_e ) ) { libvlc_media_player_stop( p_mlp->p_mi, p_e ); @@ -368,7 +426,6 @@ libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp, { libvlc_state_t state = libvlc_media_player_get_state( p_mlp->p_mi, p_e ); return (state == libvlc_Opening) || (state == libvlc_Buffering) || - (state == libvlc_Forward) || (state == libvlc_Backward) || (state == libvlc_Playing); }