Commit f7da3d84 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

lib/media: fix MediaListEndReached not sent when media doesn't have sub items

MediaListEndReached event should not be sent only when a new sub item tree is
added, otherwise it won't be sent if media doesn't have any sub items.

To fix this issue, send the MediaListEndReached event when preparse function
terminates (only if the media_list was created either by user or by sub items
callbacks).
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 4935cbe1
......@@ -104,12 +104,13 @@ static const libvlc_meta_t vlc_to_libvlc_meta[] =
[vlc_meta_DiscNumber] = libvlc_meta_DiscNumber
};
static libvlc_media_list_t *media_get_subitems( libvlc_media_t * p_md )
static libvlc_media_list_t *media_get_subitems( libvlc_media_t * p_md,
bool b_create )
{
libvlc_media_list_t *p_subitems = NULL;
vlc_mutex_lock( &p_md->subitems_lock );
if( p_md->p_subitems == NULL )
if( p_md->p_subitems == NULL && b_create )
{
p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance );
if( p_md->p_subitems != NULL )
......@@ -139,7 +140,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event,
p_event->u.input_item_subitem_added.p_new_child );
/* Add this to our media list */
p_subitems = media_get_subitems( p_md );
p_subitems = media_get_subitems( p_md, true );
if( p_subitems != NULL )
{
libvlc_media_list_lock( p_subitems );
......@@ -164,18 +165,8 @@ static void input_item_subitemtree_added( const vlc_event_t * p_event,
{
VLC_UNUSED( p_event );
libvlc_media_t * p_md = user_data;
libvlc_media_list_t *p_subitems;
libvlc_event_t event;
/* notify the media list */
p_subitems = media_get_subitems( p_md );
if( p_subitems != NULL )
{
libvlc_media_list_lock( p_subitems );
libvlc_media_list_internal_end_reached( p_subitems );
libvlc_media_list_unlock( p_subitems );
}
/* Construct the event */
event.type = libvlc_MediaSubItemTreeAdded;
event.u.media_subitemtree_added.item = p_md;
......@@ -245,6 +236,25 @@ static void input_item_preparsed_changed(const vlc_event_t *p_event,
libvlc_event_send(media->p_event_manager, &event);
}
/**************************************************************************
* input_item_preparse_ended (Private) (vlc event Callback)
**************************************************************************/
static void input_item_preparse_ended( const vlc_event_t * p_event,
void * user_data )
{
VLC_UNUSED( p_event );
libvlc_media_t * p_md = user_data;
libvlc_media_list_t *p_subitems = media_get_subitems( p_md, false );
if( p_subitems != NULL )
{
/* notify the media list */
libvlc_media_list_lock( p_subitems );
libvlc_media_list_internal_end_reached( p_subitems );
libvlc_media_list_unlock( p_subitems );
}
}
/**************************************************************************
* Install event handler (Private)
**************************************************************************/
......@@ -270,6 +280,10 @@ static void install_input_item_observer( libvlc_media_t *p_md )
vlc_InputItemSubItemTreeAdded,
input_item_subitemtree_added,
p_md );
vlc_event_attach( &p_md->p_input_item->event_manager,
vlc_InputItemPreparseEnded,
input_item_preparse_ended,
p_md );
}
/**************************************************************************
......@@ -297,6 +311,10 @@ static void uninstall_input_item_observer( libvlc_media_t *p_md )
vlc_InputItemSubItemTreeAdded,
input_item_subitemtree_added,
p_md );
vlc_event_detach( &p_md->p_input_item->event_manager,
vlc_InputItemPreparseEnded,
input_item_preparse_ended,
p_md );
}
/**************************************************************************
......@@ -428,7 +446,7 @@ libvlc_media_t * libvlc_media_new_as_node( libvlc_instance_t *p_instance,
p_md = libvlc_media_new_from_input_item( p_instance, p_input_item );
p_subitems = media_get_subitems( p_md );
p_subitems = media_get_subitems( p_md, true );
if( p_subitems == NULL) {
libvlc_media_release( p_md );
return NULL;
......@@ -606,7 +624,7 @@ libvlc_media_set_state( libvlc_media_t *p_md,
libvlc_media_list_t *
libvlc_media_subitems( libvlc_media_t * p_md )
{
libvlc_media_list_t *p_subitems = media_get_subitems( p_md );
libvlc_media_list_t *p_subitems = media_get_subitems( p_md, true );
if( p_subitems )
libvlc_media_list_retain( p_subitems );
return p_subitems;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment