[vlc-commits] stream_filter/httplive.c: Do not start live playback when there is not enough data available.

Jean-Paul Saman git at videolan.org
Fri Jan 21 17:21:36 CET 2011


vlc | branch: master | Jean-Paul Saman <jean-paul.saman at m2x.nl> | Fri Jan 21 17:14:54 2011 +0100| [18b1e6cb26e04609013c121c85f1164a3e49b274] | committer: Jean-Paul Saman

stream_filter/httplive.c: Do not start live playback when there is not enough data available.

Do not start live playback when there is not enough data available. There
should at least be 3 times the target duration of data segments.

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

 modules/stream_filter/httplive.c |   51 ++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 2b815cf..0df42a0 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -339,8 +339,29 @@ static int live_ChooseSegment(stream_t *s, int current)
     stream_sys_t *p_sys = (stream_sys_t *)s->p_sys;
     hls_stream_t *hls = hls_Get(p_sys->hls_stream, current);
     if (hls == NULL) return 0;
-    int wanted = vlc_array_count(hls->segments) - 4;
-    return (wanted < 0) ? 0 : wanted;
+
+    /* Choose a segment to start which is no closer then
+     * 3 times the target duration from the end of the playlist.
+     */
+    int wanted = -1;
+    int duration = 0;
+    int count = vlc_array_count(hls->segments);
+    for (int i = count; i >= 0; i--)
+    {
+        segment_t *segment = segment_GetSegment(hls, i);
+        if (segment)
+        {
+            duration += segment->duration;
+            if (duration >= 3 * hls->duration)
+            {
+                /* Start point found */
+                wanted = i;
+                break;
+            }
+        }
+    }
+
+    return wanted;
 }
 
 /* Parsing */
@@ -961,25 +982,7 @@ static int parse_HTTPLiveStreaming(stream_t *s)
         }
 
         vlc_mutex_lock(&hls->lock);
-        if (p_sys->b_live)
-        {
-            /* There should at least be 3 segments of hls->duration */
-            int ok = 0;
-            int num = vlc_array_count(hls->segments);
-            for (int i = 0; i < num; i++)
-            {
-                segment_t *segment = segment_GetSegment(hls, i);
-                if (segment && segment->duration >= hls->duration)
-                    ok++;
-            }
-            if (ok < 3)
-            {
-                msg_Err(s, "cannot start live playback at this time, try again later.");
-                vlc_mutex_unlock(&hls->lock);
-                return VLC_EGENERIC;
-            }
-        }
-        else
+        if (!p_sys->b_live)
         {
             /* Stream size (approximate) */
             hls->size = hls_GetStreamSize(hls);
@@ -1577,6 +1580,12 @@ static int Open(vlc_object_t *p_this)
     p_sys->playback.segment = p_sys->download.segment =
             p_sys->b_live ? live_ChooseSegment(s, current) : 0;
 
+    if (p_sys->b_live && (p_sys->playback.segment < 0))
+    {
+        msg_Err(s, "not enough data available for live playback, try again later");
+        goto fail;
+    }
+
     if (Prefetch(s, &current) != VLC_SUCCESS)
     {
         msg_Err(s, "fetching first segment.");



More information about the vlc-commits mailing list