X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmedia_list.c;h=c379db9497d8e4241f8d5ae284585266a05f18ef;hb=32b31e87d90967549e5cc8bef18d5aae7e3b98c6;hp=8a10874b7dcb86fe5c675eaf0ce099e6f757b344;hpb=8299af702c1c6c0566b518413d115a01318755c6;p=vlc diff --git a/src/control/media_list.c b/src/control/media_list.c index 8a10874b7d..c379db9497 100644 --- a/src/control/media_list.c +++ b/src/control/media_list.c @@ -31,6 +31,14 @@ typedef enum EventPlaceInTime { EventDidHappen } EventPlaceInTime; +//#define DEBUG_MEDIA_LIST + +#ifdef DEBUG_MEDIA_LIST +# define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ ) +#else +# define trace( ... ) +#endif + /* * Private functions */ @@ -44,7 +52,7 @@ typedef enum EventPlaceInTime { **************************************************************************/ static void notify_item_addition( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, int index, EventPlaceInTime event_status ) { @@ -53,6 +61,7 @@ notify_item_addition( libvlc_media_list_t * p_mlist, /* Construct the event */ if( event_status == EventDidHappen ) { + trace("item was added at index %d\n", index); event.type = libvlc_MediaListItemAdded; event.u.media_list_item_added.item = p_md; event.u.media_list_item_added.index = index; @@ -75,7 +84,7 @@ notify_item_addition( libvlc_media_list_t * p_mlist, **************************************************************************/ static void notify_item_deletion( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, int index, EventPlaceInTime event_status ) { @@ -84,6 +93,7 @@ notify_item_deletion( libvlc_media_list_t * p_mlist, /* Construct the event */ if( event_status == EventDidHappen ) { + trace("item at index %d was deleted\n", index); event.type = libvlc_MediaListItemDeleted; event.u.media_list_item_deleted.item = p_md; event.u.media_list_item_deleted.index = index; @@ -124,7 +134,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst, /* Code for that one should be handled in flat_media_list.c */ p_mlist->p_flat_mlist = NULL; - p_mlist->b_read_only = VLC_FALSE; + p_mlist->b_read_only = false; libvlc_event_manager_register_event_type( p_mlist->p_event_manager, libvlc_MediaListItemAdded, p_e ); @@ -142,7 +152,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst, return NULL; } - vlc_mutex_init( p_inst->p_libvlc_int, &p_mlist->object_lock ); + vlc_mutex_init( &p_mlist->object_lock ); vlc_array_init( &p_mlist->items ); p_mlist->i_refcount = 1; @@ -158,7 +168,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst, **************************************************************************/ void libvlc_media_list_release( libvlc_media_list_t * p_mlist ) { - libvlc_media_descriptor_t * p_md; + libvlc_media_t * p_md; int i; vlc_mutex_lock( &p_mlist->object_lock ); @@ -175,12 +185,12 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist ) libvlc_event_manager_release( p_mlist->p_event_manager ); if( p_mlist->p_md ) - libvlc_media_descriptor_release( p_mlist->p_md ); + libvlc_media_release( p_mlist->p_md ); for ( i = 0; i < vlc_array_count( &p_mlist->items ); i++ ) { p_md = vlc_array_item_at_index( &p_mlist->items, i ); - libvlc_media_descriptor_release( p_md ); + libvlc_media_release( p_md ); } vlc_mutex_destroy( &p_mlist->object_lock ); @@ -211,7 +221,7 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, libvlc_exception_t * p_e ) { input_item_t * p_input_item; - libvlc_media_descriptor_t * p_md; + libvlc_media_t * p_md; p_input_item = input_ItemNewExt( p_mlist->p_libvlc_instance->p_libvlc_int, psz_uri, _("Media Library"), 0, NULL, -1 ); @@ -222,7 +232,7 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, return; } - p_md = libvlc_media_descriptor_new_from_input_item( + p_md = libvlc_media_new_from_input_item( p_mlist->p_libvlc_instance, p_input_item, p_e ); @@ -232,52 +242,52 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, return; } - libvlc_media_list_add_media_descriptor( p_mlist, p_md, p_e ); + libvlc_media_list_add_media( p_mlist, p_md, p_e ); if( libvlc_exception_raised( p_e ) ) return; - input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item, VLC_TRUE ); + input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item, true ); return; } /************************************************************************** - * set_media_descriptor (Public) + * set_media (Public) **************************************************************************/ -void libvlc_media_list_set_media_descriptor( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, +void libvlc_media_list_set_media( libvlc_media_list_t * p_mlist, + libvlc_media_t * p_md, libvlc_exception_t * p_e) { (void)p_e; vlc_mutex_lock( &p_mlist->object_lock ); if( p_mlist->p_md ) - libvlc_media_descriptor_release( p_mlist->p_md ); - libvlc_media_descriptor_retain( p_md ); + libvlc_media_release( p_mlist->p_md ); + libvlc_media_retain( p_md ); p_mlist->p_md = p_md; vlc_mutex_unlock( &p_mlist->object_lock ); } /************************************************************************** - * media_descriptor (Public) + * media (Public) * - * If this media_list comes is a media_descriptor's subitems, - * This holds the corresponding media_descriptor. + * If this media_list comes is a media's subitems, + * This holds the corresponding media. * This md is also seen as the information holder for the media_list. * Indeed a media_list can have meta information through this - * media_descriptor. + * media. **************************************************************************/ -libvlc_media_descriptor_t * -libvlc_media_list_media_descriptor( libvlc_media_list_t * p_mlist, +libvlc_media_t * +libvlc_media_list_media( libvlc_media_list_t * p_mlist, libvlc_exception_t * p_e) { - libvlc_media_descriptor_t *p_md; + libvlc_media_t *p_md; (void)p_e; vlc_mutex_lock( &p_mlist->object_lock ); p_md = p_mlist->p_md; if( p_md ) - libvlc_media_descriptor_retain( p_md ); + libvlc_media_retain( p_md ); vlc_mutex_unlock( &p_mlist->object_lock ); return p_md; @@ -296,13 +306,13 @@ int libvlc_media_list_count( libvlc_media_list_t * p_mlist, } /************************************************************************** - * libvlc_media_list_add_media_descriptor (Public) + * libvlc_media_list_add_media (Public) * * Lock should be hold when entering. **************************************************************************/ -void libvlc_media_list_add_media_descriptor( +void libvlc_media_list_add_media( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, libvlc_exception_t * p_e ) { if( p_mlist->b_read_only ) @@ -312,17 +322,17 @@ void libvlc_media_list_add_media_descriptor( return; } - _libvlc_media_list_add_media_descriptor( p_mlist, p_md, p_e ); + _libvlc_media_list_add_media( p_mlist, p_md, p_e ); } /* LibVLC internal version */ -void _libvlc_media_list_add_media_descriptor( +void _libvlc_media_list_add_media( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, libvlc_exception_t * p_e ) { (void)p_e; - libvlc_media_descriptor_retain( p_md ); + libvlc_media_retain( p_md ); notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items ), EventWillHappen ); vlc_array_append( &p_mlist->items, p_md ); @@ -330,13 +340,13 @@ void _libvlc_media_list_add_media_descriptor( } /************************************************************************** - * libvlc_media_list_insert_media_descriptor (Public) + * libvlc_media_list_insert_media (Public) * * Lock should be hold when entering. **************************************************************************/ -void libvlc_media_list_insert_media_descriptor( +void libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, int index, libvlc_exception_t * p_e ) { @@ -346,18 +356,18 @@ void libvlc_media_list_insert_media_descriptor( libvlc_exception_raise( p_e, "Trying to write into a read-only media list." ); return; } - _libvlc_media_list_insert_media_descriptor( p_mlist, p_md, index, p_e ); + _libvlc_media_list_insert_media( p_mlist, p_md, index, p_e ); } /* LibVLC internal version */ -void _libvlc_media_list_insert_media_descriptor( +void _libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_md, + libvlc_media_t * p_md, int index, libvlc_exception_t * p_e ) { (void)p_e; - libvlc_media_descriptor_retain( p_md ); + libvlc_media_retain( p_md ); notify_item_addition( p_mlist, p_md, index, EventWillHappen ); vlc_array_insert( &p_mlist->items, p_md, index ); @@ -387,15 +397,22 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, int index, libvlc_exception_t * p_e ) { - libvlc_media_descriptor_t * p_md; + libvlc_media_t * p_md; + + if( index < 0 || index >= vlc_array_count( &p_mlist->items )) + { + libvlc_exception_raise( p_e, "Index out of bounds exception"); + return; + } + p_md = vlc_array_item_at_index( &p_mlist->items, index ); notify_item_deletion( p_mlist, p_md, index, EventWillHappen ); vlc_array_remove( &p_mlist->items, index ); notify_item_deletion( p_mlist, p_md, index, EventDidHappen ); - libvlc_media_descriptor_release( p_md ); + libvlc_media_release( p_md ); } /************************************************************************** @@ -403,14 +420,22 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist, * * Lock should be hold when entering. **************************************************************************/ -libvlc_media_descriptor_t * +libvlc_media_t * libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist, int index, libvlc_exception_t * p_e ) { - libvlc_media_descriptor_t * p_md; + VLC_UNUSED(p_e); + + if( index < 0 || index >= vlc_array_count( &p_mlist->items )) + { + libvlc_exception_raise( p_e, "Index out of bounds exception"); + return NULL; + } + + libvlc_media_t * p_md; p_md = vlc_array_item_at_index( &p_mlist->items, index ); - libvlc_media_descriptor_retain( p_md ); + libvlc_media_retain( p_md ); return p_md; } @@ -421,10 +446,12 @@ libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist, * Warning: this function would return the first matching item **************************************************************************/ int libvlc_media_list_index_of_item( libvlc_media_list_t * p_mlist, - libvlc_media_descriptor_t * p_searched_md, + libvlc_media_t * p_searched_md, libvlc_exception_t * p_e ) { - libvlc_media_descriptor_t * p_md; + VLC_UNUSED(p_e); + + libvlc_media_t * p_md; int i; for ( i = 0; i < vlc_array_count( &p_mlist->items ); i++ ) { @@ -440,7 +467,7 @@ int libvlc_media_list_index_of_item( libvlc_media_list_t * p_mlist, * * This indicates if this media list is read-only from a user point of view **************************************************************************/ -vlc_bool_t libvlc_media_list_is_readonly( libvlc_media_list_t * p_mlist ) +int libvlc_media_list_is_readonly( libvlc_media_list_t * p_mlist ) { return p_mlist->b_read_only; }