Commit d56e7961 authored by Romain Vimont's avatar Romain Vimont
Browse files

libvlc: receive events from input thread

Replace listeners on the input item by preparser callbacks (for
preparsing) and input thread callbacks (for normal playback).
parent 5fe63eb3
......@@ -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;
}
......
......@@ -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
......@@ -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 );
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment