[vlc-devel] [PATCH 11/12] libvlc: add libvlc_MediaListEndReached event

Thomas Guillem thomas at gllm.fr
Mon Jan 19 11:22:53 CET 2015


Expose an event to libvlc users which allows them to get notified when a media
list reached the end. That is, when the media list is attached to a media
(subitems) that completed a parsing. Or when the media list is attached to a
media discovery that stopped.
---
 include/vlc/libvlc_events.h |  1 +
 lib/media.c                 | 10 ++++++++++
 lib/media_discoverer.c      |  7 +++++++
 lib/media_list.c            | 13 +++++++++++++
 lib/media_list_internal.h   |  2 ++
 5 files changed, 33 insertions(+)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 963163a..c99e25c 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -82,6 +82,7 @@ enum libvlc_event_e {
     libvlc_MediaListWillAddItem,
     libvlc_MediaListItemDeleted,
     libvlc_MediaListWillDeleteItem,
+    libvlc_MediaListEndReached,
 
     libvlc_MediaListViewItemAdded=0x300,
     libvlc_MediaListViewWillAddItem,
diff --git a/lib/media.c b/lib/media.c
index cee1190..abf409f 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -164,8 +164,18 @@ 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;
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index c914e3a..4e11c80 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -169,8 +169,15 @@ static void services_discovery_ended( const vlc_event_t * p_event,
 {
     VLC_UNUSED(p_event);
     libvlc_media_discoverer_t * p_mdis = user_data;
+    libvlc_media_list_t * p_mlist = p_mdis->p_mlist;
     libvlc_event_t event;
+
     p_mdis->running = false;
+
+    libvlc_media_list_lock( p_mlist );
+    libvlc_media_list_internal_end_reached( p_mlist );
+    libvlc_media_list_unlock( p_mlist );
+
     event.type = libvlc_MediaDiscovererEnded;
     libvlc_event_send( p_mdis->p_event_manager, &event );
 }
diff --git a/lib/media_list.c b/lib/media_list.c
index 07864d1..88b4fb1 100644
--- a/lib/media_list.c
+++ b/lib/media_list.c
@@ -122,6 +122,17 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
     libvlc_event_send( p_mlist->p_event_manager, &event );
 }
 
+/* LibVLC internal */
+void libvlc_media_list_internal_end_reached( libvlc_media_list_t * p_mlist )
+{
+    libvlc_event_t event;
+
+    event.type = libvlc_MediaListEndReached;
+
+    /* Send the event */
+    libvlc_event_send( p_mlist->p_event_manager, &event );
+}
+
 /**************************************************************************
  *       static mlist_is_writable (private)
  **************************************************************************/
@@ -176,6 +187,8 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
             libvlc_MediaListItemDeleted );
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListWillDeleteItem );
+    libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
+            libvlc_MediaListEndReached );
 
     vlc_mutex_init( &p_mlist->object_lock );
     vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
diff --git a/lib/media_list_internal.h b/lib/media_list_internal.h
index 832ae13..1175b91 100644
--- a/lib/media_list_internal.h
+++ b/lib/media_list_internal.h
@@ -68,4 +68,6 @@ void libvlc_media_list_internal_insert_media(
 int libvlc_media_list_internal_remove_index(
         libvlc_media_list_t * p_mlist, int index );
 
+void libvlc_media_list_internal_end_reached(
+        libvlc_media_list_t * p_mlist );
 #endif
-- 
2.1.3




More information about the vlc-devel mailing list