[vlc-devel] [RFC PATCH 2/2] lib/media: fix MediaListEndReached not sent when media doesn't have sub items

Thomas Guillem thomas at gllm.fr
Tue Feb 3 19:04:12 CET 2015


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

To fix this issue, send the MediaListEndReached event when media is parsed
(only if the media_list was created either by user or by sub item callbacks)
---
 lib/media.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/lib/media.c b/lib/media.c
index 00e1e8a..4c29142 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -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;
@@ -227,6 +218,7 @@ static void input_item_preparsed_changed(const vlc_event_t *p_event,
                                          void * user_data)
 {
     libvlc_media_t *media = user_data;
+    libvlc_media_list_t *p_subitems;
     libvlc_event_t event;
 
     /* Eventually notify libvlc_media_parse() */
@@ -235,6 +227,14 @@ static void input_item_preparsed_changed(const vlc_event_t *p_event,
     vlc_cond_broadcast(&media->parsed_cond);
     vlc_mutex_unlock(&media->parsed_lock);
 
+    /* notify the media list */
+    p_subitems = media_get_subitems( media, false );
+    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_MediaParsedChanged;
@@ -428,7 +428,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 +606,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;
-- 
2.1.3




More information about the vlc-devel mailing list