Commit 99c82887 authored by Thomas Guillem's avatar Thomas Guillem

libvlc: add a timeout in libvlc_media_parse_with_options()

parent 6cf2720e
...@@ -268,6 +268,7 @@ typedef enum libvlc_media_parsed_status_t ...@@ -268,6 +268,7 @@ typedef enum libvlc_media_parsed_status_t
libvlc_media_parsed_status_init, libvlc_media_parsed_status_init,
libvlc_media_parsed_status_skipped, libvlc_media_parsed_status_skipped,
libvlc_media_parsed_status_failed, libvlc_media_parsed_status_failed,
libvlc_media_parsed_status_timeout,
libvlc_media_parsed_status_done, libvlc_media_parsed_status_done,
} libvlc_media_parsed_status_t; } libvlc_media_parsed_status_t;
...@@ -671,12 +672,16 @@ libvlc_media_parse( libvlc_media_t *p_md ); ...@@ -671,12 +672,16 @@ libvlc_media_parse( libvlc_media_t *p_md );
* *
* \param p_md media descriptor object * \param p_md media descriptor object
* \param parse_flag parse options: * \param parse_flag parse options:
* \param timeout maximum time allowed to preparse the media. If -1, the
* default "preparse-timeout" option will be used as a timeout. If 0, it will
* wait indefinitely. If > 0, the timeout will be used (in milliseconds).
* \return -1 in case of error, 0 otherwise * \return -1 in case of error, 0 otherwise
* \version LibVLC 3.0.0 or later * \version LibVLC 3.0.0 or later
*/ */
LIBVLC_API int LIBVLC_API int
libvlc_media_parse_with_options( libvlc_media_t *p_md, libvlc_media_parse_with_options( libvlc_media_t *p_md,
libvlc_media_parse_flag_t parse_flag ); libvlc_media_parse_flag_t parse_flag,
int timeout );
/** /**
* Get Parsed status for media descriptor object. * Get Parsed status for media descriptor object.
......
...@@ -275,6 +275,9 @@ static void input_item_preparse_ended( const vlc_event_t * p_event, ...@@ -275,6 +275,9 @@ static void input_item_preparse_ended( const vlc_event_t * p_event,
case ITEM_PREPARSE_FAILED: case ITEM_PREPARSE_FAILED:
new_status = libvlc_media_parsed_status_failed; new_status = libvlc_media_parsed_status_failed;
break; break;
case ITEM_PREPARSE_TIMEOUT:
new_status = libvlc_media_parsed_status_timeout;
break;
case ITEM_PREPARSE_DONE: case ITEM_PREPARSE_DONE:
new_status = libvlc_media_parsed_status_done; new_status = libvlc_media_parsed_status_done;
break; break;
...@@ -735,7 +738,7 @@ libvlc_media_get_duration( libvlc_media_t * p_md ) ...@@ -735,7 +738,7 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
} }
static int media_parse(libvlc_media_t *media, bool b_async, static int media_parse(libvlc_media_t *media, bool b_async,
libvlc_media_parse_flag_t parse_flag) libvlc_media_parse_flag_t parse_flag, int timeout)
{ {
bool needed; bool needed;
...@@ -768,7 +771,7 @@ static int media_parse(libvlc_media_t *media, bool b_async, ...@@ -768,7 +771,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK; parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
if (parse_flag & libvlc_media_do_interact) if (parse_flag & libvlc_media_do_interact)
parse_scope |= META_REQUEST_OPTION_DO_INTERACT; parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
ret = libvlc_MetadataRequest(libvlc, item, parse_scope, 0, media); ret = libvlc_MetadataRequest(libvlc, item, parse_scope, timeout, media);
if (ret != VLC_SUCCESS) if (ret != VLC_SUCCESS)
return ret; return ret;
} }
...@@ -791,7 +794,7 @@ static int media_parse(libvlc_media_t *media, bool b_async, ...@@ -791,7 +794,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
void void
libvlc_media_parse(libvlc_media_t *media) libvlc_media_parse(libvlc_media_t *media)
{ {
media_parse( media, false, libvlc_media_fetch_local ); media_parse( media, false, -1, libvlc_media_fetch_local );
} }
/************************************************************************** /**************************************************************************
...@@ -800,7 +803,7 @@ libvlc_media_parse(libvlc_media_t *media) ...@@ -800,7 +803,7 @@ libvlc_media_parse(libvlc_media_t *media)
void void
libvlc_media_parse_async(libvlc_media_t *media) libvlc_media_parse_async(libvlc_media_t *media)
{ {
media_parse( media, true, libvlc_media_fetch_local ); media_parse( media, true, -1, libvlc_media_fetch_local );
} }
/************************************************************************** /**************************************************************************
...@@ -808,9 +811,10 @@ libvlc_media_parse_async(libvlc_media_t *media) ...@@ -808,9 +811,10 @@ libvlc_media_parse_async(libvlc_media_t *media)
**************************************************************************/ **************************************************************************/
int int
libvlc_media_parse_with_options( libvlc_media_t *media, libvlc_media_parse_with_options( libvlc_media_t *media,
libvlc_media_parse_flag_t parse_flag ) libvlc_media_parse_flag_t parse_flag,
int timeout )
{ {
return media_parse( media, true, parse_flag ) == VLC_SUCCESS ? 0 : -1; return media_parse( media, true, parse_flag, timeout ) == VLC_SUCCESS ? 0 : -1;
} }
/************************************************************************** /**************************************************************************
......
...@@ -64,7 +64,7 @@ static void test_media_preparsed(int argc, const char** argv, ...@@ -64,7 +64,7 @@ static void test_media_preparsed(int argc, const char** argv,
libvlc_event_attach (em, libvlc_MediaParsedChanged, media_parse_ended, &sem); libvlc_event_attach (em, libvlc_MediaParsedChanged, media_parse_ended, &sem);
// Parse the media. This is synchronous. // Parse the media. This is synchronous.
int i_ret = libvlc_media_parse_with_options(media, libvlc_media_parse_local); int i_ret = libvlc_media_parse_with_options(media, libvlc_media_parse_local, -1);
assert(i_ret == 0); assert(i_ret == 0);
// Wait for preparsed event // Wait for preparsed event
...@@ -161,7 +161,7 @@ static void test_media_subitems_media(libvlc_media_t *media, bool play, ...@@ -161,7 +161,7 @@ static void test_media_subitems_media(libvlc_media_t *media, bool play,
{ {
libvlc_event_attach (em, libvlc_MediaParsedChanged, subitem_parse_ended, &sem); libvlc_event_attach (em, libvlc_MediaParsedChanged, subitem_parse_ended, &sem);
int i_ret = libvlc_media_parse_with_options(media, libvlc_media_parse_local); int i_ret = libvlc_media_parse_with_options(media, libvlc_media_parse_local, -1);
assert(i_ret == 0); assert(i_ret == 0);
vlc_sem_wait (&sem); vlc_sem_wait (&sem);
} }
......
...@@ -43,7 +43,7 @@ media_parse_sync(libvlc_media_t *p_m) ...@@ -43,7 +43,7 @@ media_parse_sync(libvlc_media_t *p_m)
libvlc_event_manager_t *p_em = libvlc_media_event_manager(p_m); libvlc_event_manager_t *p_em = libvlc_media_event_manager(p_m);
libvlc_event_attach(p_em, libvlc_MediaParsedChanged, finished_event, &sem); libvlc_event_attach(p_em, libvlc_MediaParsedChanged, finished_event, &sem);
int i_ret = libvlc_media_parse_with_options(p_m, libvlc_media_parse_local); int i_ret = libvlc_media_parse_with_options(p_m, libvlc_media_parse_local, -1);
assert(i_ret == 0); assert(i_ret == 0);
vlc_sem_wait (&sem); vlc_sem_wait (&sem);
......
Markdown is supported
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