[vlc-commits] libvlc: add libvlc_MediaListEndReached event

Thomas Guillem git at videolan.org
Tue Jan 20 11:20:54 CET 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jan 20 10:46:31 2015 +0100| [1723d7e97f421c27ed4c99159e70c3fafb8fdaee] | committer: Jean-Baptiste Kempf

libvlc: add libvlc_MediaListEndReached event

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.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1723d7e97f421c27ed4c99159e70c3fafb8fdaee
---

 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 b8b7620..6f3440b 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 74218b0..28479e1 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 47d2fbf..40b34da 100644
--- a/lib/media_list_internal.h
+++ b/lib/media_list_internal.h
@@ -64,4 +64,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



More information about the vlc-commits mailing list