[vlc-commits] libvlc: receive events from input thread
Romain Vimont
git at videolan.org
Mon Aug 20 13:59:14 CEST 2018
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Thu Aug 16 09:51:10 2018 +0200| [d56e796169f93472b725c58f745c0daa86946277] | committer: Romain Vimont
libvlc: receive events from input thread
Replace listeners on the input item by preparser callbacks (for
preparsing) and input thread callbacks (for normal playback).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d56e796169f93472b725c58f745c0daa86946277
---
lib/media.c | 44 ++++++++++++++++++++------------------------
lib/media_internal.h | 1 +
lib/media_player.c | 15 ++++++++++++++-
test/libvlc/media.c | 14 ++++++++------
4 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/lib/media.c b/lib/media.c
index 81c39436cb..17deae436e 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -200,13 +200,17 @@ static void input_item_add_subnode( libvlc_media_t *md,
/**************************************************************************
* input_item_subitemtree_added (Private) (vlc event Callback)
**************************************************************************/
-static void input_item_subitemtree_added( const vlc_event_t * p_event,
- void * user_data )
+static void input_item_subtree_added(input_item_t *item,
+ input_item_node_t *node,
+ void *user_data)
{
+ VLC_UNUSED(item);
libvlc_media_t * p_md = user_data;
- libvlc_event_t event;
- input_item_node_t *node = p_event->u.input_item_subitem_tree_added.p_root;
+ libvlc_media_add_subtree(p_md, node);
+}
+void libvlc_media_add_subtree(libvlc_media_t *p_md, input_item_node_t *node)
+{
/* FIXME FIXME FIXME
* Recursive function calls seem much simpler for this. But playlists are
* untrusted and can be arbitrarily deep (e.g. with XSPF). So recursion can
@@ -214,6 +218,7 @@ static void input_item_subitemtree_added( const vlc_event_t * p_event,
input_item_add_subnode( p_md, node );
/* Construct the event */
+ libvlc_event_t event;
event.type = libvlc_MediaSubItemTreeAdded;
event.u.media_subitemtree_added.item = p_md;
@@ -305,13 +310,15 @@ static void send_parsed_changed( libvlc_media_t *p_md,
/**************************************************************************
* input_item_preparse_ended (Private) (vlc event Callback)
**************************************************************************/
-static void input_item_preparse_ended( const vlc_event_t * p_event,
- void * user_data )
+static void input_item_preparse_ended(input_item_t *item,
+ enum input_item_preparse_status status,
+ void *user_data)
{
+ VLC_UNUSED(item);
libvlc_media_t * p_md = user_data;
libvlc_media_parsed_status_t new_status;
- switch( p_event->u.input_item_preparse_ended.new_status )
+ switch( status )
{
case ITEM_PREPARSE_SKIPPED:
new_status = libvlc_media_parsed_status_skipped;
@@ -344,14 +351,6 @@ static void install_input_item_observer( libvlc_media_t *p_md )
vlc_InputItemDurationChanged,
input_item_duration_changed,
p_md );
- vlc_event_attach( &p_md->p_input_item->event_manager,
- 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 );
}
/**************************************************************************
@@ -367,14 +366,6 @@ static void uninstall_input_item_observer( libvlc_media_t *p_md )
vlc_InputItemDurationChanged,
input_item_duration_changed,
p_md );
- vlc_event_detach( &p_md->p_input_item->event_manager,
- 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 );
}
/**************************************************************************
@@ -778,6 +769,11 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
return from_mtime(input_item_GetDuration( p_md->p_input_item ));
}
+static const input_preparser_callbacks_t input_preparser_callbacks = {
+ .on_preparse_ended = input_item_preparse_ended,
+ .on_subtree_added = input_item_subtree_added,
+};
+
static int media_parse(libvlc_media_t *media, bool b_async,
libvlc_media_parse_flag_t parse_flag, int timeout)
{
@@ -812,7 +808,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
if (parse_flag & libvlc_media_do_interact)
parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
- ret = libvlc_MetadataRequest(libvlc, item, parse_scope, NULL, NULL, timeout, media);
+ ret = libvlc_MetadataRequest(libvlc, item, parse_scope, &input_preparser_callbacks, media, timeout, media);
if (ret != VLC_SUCCESS)
return ret;
}
diff --git a/lib/media_internal.h b/lib/media_internal.h
index 5a67e9ff60..0b5c18d712 100644
--- a/lib/media_internal.h
+++ b/lib/media_internal.h
@@ -55,5 +55,6 @@ libvlc_media_t * libvlc_media_new_from_input_item(
libvlc_instance_t *, input_item_t * );
void libvlc_media_set_state( libvlc_media_t *, libvlc_state_t );
+void libvlc_media_add_subtree(libvlc_media_t *, input_item_node_t *);
#endif
diff --git a/lib/media_player.c b/lib/media_player.c
index 30374d4ee9..72955bc3dd 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -952,6 +952,19 @@ static void del_es_callbacks( input_thread_t *p_input_thread, libvlc_media_playe
var_DelListCallback( p_input_thread, "spu-es", input_es_changed, p_mi );
}
+static void on_input_event(input_thread_t *input, void *userdata,
+ const struct vlc_input_event *event)
+{
+ if (event->type == INPUT_EVENT_SUBITEMS)
+ {
+ libvlc_media_player_t *media_player = userdata;
+ libvlc_media_t *media = media_player->p_md;
+ libvlc_media_add_subtree(media, event->subitems);
+ }
+
+ input_LegacyEvents(input, userdata, event);
+}
+
/**************************************************************************
* Tell media player to start playing.
**************************************************************************/
@@ -984,7 +997,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
media_attach_preparsed_event( p_mi->p_md );
- p_input_thread = input_Create( p_mi, input_LegacyEvents, NULL,
+ p_input_thread = input_Create( p_mi, on_input_event, p_mi,
p_mi->p_md->p_input_item, NULL,
p_mi->input.p_resource,
p_mi->input.p_renderer );
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index 933ca41f70..5e20177a6a 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -127,12 +127,14 @@ static void test_media_preparsed(libvlc_instance_t *vlc, const char *path,
libvlc_media_release (media);
}
-static void input_item_preparse_timeout( const vlc_event_t *p_event,
+static void input_item_preparse_timeout( input_item_t *item,
+ enum input_item_preparse_status status,
void *user_data )
{
+ VLC_UNUSED(item);
vlc_sem_t *p_sem = user_data;
- assert( p_event->u.input_item_preparse_ended.new_status == ITEM_PREPARSE_TIMEOUT );
+ assert( status == ITEM_PREPARSE_TIMEOUT );
vlc_sem_post(p_sem);
}
@@ -154,12 +156,12 @@ static void test_input_metadata_timeout(libvlc_instance_t *vlc, int timeout,
vlc_sem_t sem;
vlc_sem_init (&sem, 0);
- i_ret = vlc_event_attach(&p_item->event_manager, vlc_InputItemPreparseEnded,
- input_item_preparse_timeout, &sem);
- assert(i_ret == 0);
+ const struct input_preparser_callbacks_t cbs = {
+ .on_preparse_ended = input_item_preparse_timeout,
+ };
i_ret = libvlc_MetadataRequest(vlc->p_libvlc_int, p_item,
META_REQUEST_OPTION_SCOPE_LOCAL,
- NULL, NULL, timeout, vlc);
+ &cbs, &sem, timeout, vlc);
assert(i_ret == 0);
if (wait_and_cancel > 0)
More information about the vlc-commits
mailing list