[vlc-commits] libvlc: add a timeout in libvlc_media_parse_with_options()

Thomas Guillem git at videolan.org
Sun Jun 5 13:02:14 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Sun Jun  5 11:36:19 2016 +0200| [99c8288760d2183c1e22a433c6cd3d836b7c53a5] | committer: Thomas Guillem

libvlc: add a timeout in libvlc_media_parse_with_options()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=99c8288760d2183c1e22a433c6cd3d836b7c53a5
---

 include/vlc/libvlc_media.h |    7 ++++++-
 lib/media.c                |   16 ++++++++++------
 test/libvlc/media.c        |    4 ++--
 test/libvlc/slaves.c       |    2 +-
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index a392368..4c02b04 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 (in milliseconds).
  * \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,
+                                 int timeout );
 
 /**
  * Get Parsed status for media descriptor object.
diff --git a/lib/media.c b/lib/media.c
index 45ad99a..9088369 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, int 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, 0, 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,
+                                 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;
 }
 
 /**************************************************************************
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index 2f47ccb..59f2cd4 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -64,7 +64,7 @@ static void test_media_preparsed(int argc, const char** argv,
     libvlc_event_attach (em, libvlc_MediaParsedChanged, media_parse_ended, &sem);
 
     // 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);
 
     // Wait for preparsed event
@@ -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);
 
-        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);
         vlc_sem_wait (&sem);
     }
diff --git a/test/libvlc/slaves.c b/test/libvlc/slaves.c
index b9c9d46..d8225d2 100644
--- a/test/libvlc/slaves.c
+++ b/test/libvlc/slaves.c
@@ -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_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);
 
     vlc_sem_wait (&sem);



More information about the vlc-commits mailing list