[vlc-devel] [PATCH 04/14] lib: add new libvlc_MediaDiscoverer events
Thomas Guillem
thomas at gllm.fr
Fri Dec 5 14:42:55 CET 2014
Notify event listener when new items are added or removed.
---
include/vlc/libvlc_events.h | 13 +++++++++++++
lib/media_discoverer.c | 25 ++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 963163a..9b0cc81 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -94,6 +94,9 @@ enum libvlc_event_e {
libvlc_MediaDiscovererStarted=0x500,
libvlc_MediaDiscovererEnded,
+ libvlc_MediaDiscovererItemAdded,
+ libvlc_MediaDiscovererItemRemoved,
+ libvlc_MediaDiscovererItemRemoveAll,
libvlc_VlmMediaAdded=0x600,
libvlc_VlmMediaRemoved,
@@ -209,6 +212,16 @@ typedef struct libvlc_event_t
libvlc_media_t * item;
} media_list_player_next_item_set;
+ /* media discoverer */
+ struct
+ {
+ libvlc_media_t * item;
+ } media_discoverer_item_added;
+ struct
+ {
+ libvlc_media_t * item;
+ } media_discoverer_item_removed;
+
/* snapshot taken */
struct
{
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index 8eb76ac..8200efe 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -65,6 +65,7 @@ static void services_discovery_item_added( const vlc_event_t * p_event,
libvlc_media_t * p_md;
libvlc_media_discoverer_t * p_mdis = user_data;
libvlc_media_list_t * p_mlist = p_mdis->p_mlist;
+ libvlc_event_t event;
p_md = libvlc_media_new_from_input_item( p_mdis->p_libvlc_instance,
p_item );
@@ -100,6 +101,10 @@ static void services_discovery_item_added( const vlc_event_t * p_event,
_libvlc_media_list_add_media( p_mlist, p_md );
libvlc_media_list_unlock( p_mlist );
+ event.type = libvlc_MediaDiscovererItemAdded;
+ event.u.media_discoverer_item_added.item = p_md;
+ libvlc_event_send( p_mdis->p_event_manager, &event );
+
libvlc_media_release( p_md );
}
@@ -111,7 +116,7 @@ static void services_discovery_item_removed( const vlc_event_t * p_event,
void * user_data )
{
input_item_t * p_item = p_event->u.services_discovery_item_added.p_new_item;
- libvlc_media_t * p_md;
+ libvlc_media_t * p_md = NULL;
libvlc_media_discoverer_t * p_mdis = user_data;
int i, count = libvlc_media_list_count( p_mdis->p_mlist );
@@ -126,6 +131,14 @@ static void services_discovery_item_removed( const vlc_event_t * p_event,
}
}
libvlc_media_list_unlock( p_mdis->p_mlist );
+
+ if( p_md ) {
+ libvlc_event_t event;
+
+ event.type = libvlc_MediaDiscovererItemRemoved;
+ event.u.media_discoverer_item_removed.item = p_md;
+ libvlc_event_send( p_mdis->p_event_manager, &event );
+ }
}
/**************************************************************************
@@ -136,6 +149,7 @@ static void services_discovery_removeall( const vlc_event_t * p_event,
{
VLC_UNUSED(p_event);
libvlc_media_discoverer_t * p_mdis = user_data;
+ libvlc_event_t event;
libvlc_media_list_lock( p_mdis->p_mlist );
for( int i = 0; i < libvlc_media_list_count( p_mdis->p_mlist ); i++ )
@@ -143,6 +157,9 @@ static void services_discovery_removeall( const vlc_event_t * p_event,
_libvlc_media_list_remove_index( p_mdis->p_mlist, i );
}
libvlc_media_list_unlock( p_mdis->p_mlist );
+
+ event.type = libvlc_MediaDiscovererItemRemoveAll;
+ libvlc_event_send( p_mdis->p_event_manager, &event );
}
/**************************************************************************
@@ -229,6 +246,12 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
libvlc_MediaDiscovererStarted );
libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
libvlc_MediaDiscovererEnded );
+ libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
+ libvlc_MediaDiscovererItemAdded );
+ libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
+ libvlc_MediaDiscovererItemRemoved );
+ libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
+ libvlc_MediaDiscovererItemRemoveAll );
p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int,
psz_name );
--
2.1.3
More information about the vlc-devel
mailing list