[vlc-devel] [PATCH 9/9] libvlc: add a timeout in libvlc_media_parse_with_options()

Thomas Guillem thomas at gllm.fr
Sun Jun 5 11:41:50 CEST 2016


---
 include/vlc/libvlc_media.h |  7 ++++++-
 lib/media.c                | 16 ++++++++++------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index a392368..09de265 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -268,6 +268,7 @@ typedef enum libvlc_media_parsed_status_t
     libvlc_media_parsed_status_init,
     libvlc_media_parsed_status_skipped,
     libvlc_media_parsed_status_failed,
+    libvlc_media_parsed_status_timeout,
     libvlc_media_parsed_status_done,
 } libvlc_media_parsed_status_t;
 
@@ -671,12 +672,16 @@ libvlc_media_parse( libvlc_media_t *p_md );
  *
  * \param p_md media descriptor object
  * \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.
  * \return -1 in case of error, 0 otherwise
  * \version LibVLC 3.0.0 or later
  */
 LIBVLC_API int
 libvlc_media_parse_with_options( libvlc_media_t *p_md,
-                                 libvlc_media_parse_flag_t parse_flag );
+                                 libvlc_media_parse_flag_t parse_flag,
+                                 int64_t timeout );
 
 /**
  * Get Parsed status for media descriptor object.
diff --git a/lib/media.c b/lib/media.c
index b68111c..04062ef 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -275,6 +275,9 @@ static void input_item_preparse_ended( const vlc_event_t * p_event,
         case ITEM_PREPARSE_FAILED:
             new_status = libvlc_media_parsed_status_failed;
             break;
+        case ITEM_PREPARSE_TIMEOUT:
+            new_status = libvlc_media_parsed_status_timeout;
+            break;
         case ITEM_PREPARSE_DONE:
             new_status = libvlc_media_parsed_status_done;
             break;
@@ -735,7 +738,7 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
 }
 
 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, int64_t timeout)
 {
     bool needed;
 
@@ -768,7 +771,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, -1, media);
+        ret = libvlc_MetadataRequest(libvlc, item, parse_scope, timeout, media);
         if (ret != VLC_SUCCESS)
             return ret;
     }
@@ -791,7 +794,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
 void
 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)
 void
 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)
  **************************************************************************/
 int
 libvlc_media_parse_with_options( libvlc_media_t *media,
-                                 libvlc_media_parse_flag_t parse_flag )
+                                 libvlc_media_parse_flag_t parse_flag,
+                                 int64_t timeout )
 {
-    return media_parse( media, true, parse_flag ) == VLC_SUCCESS ? 0 : -1;
+    return media_parse( media, true, parse_flag, timeout ) == VLC_SUCCESS ? 0 : -1;
 }
 
 /**************************************************************************
-- 
2.8.1



More information about the vlc-devel mailing list