]> git.sesse.net Git - vlc/commitdiff
stream_filter/httplive.c: Use first HLS stream in .m3u8 as starting point.
authorJean-Paul Saman <jean-paul.saman@m2x.nl>
Tue, 14 Dec 2010 11:05:00 +0000 (12:05 +0100)
committerJean-Paul Saman <jean-paul.saman@m2x.nl>
Tue, 14 Dec 2010 11:05:00 +0000 (12:05 +0100)
Determine which HLS stream can be served best by this server. If found, then download
the first two segments and start playback.

modules/stream_filter/httplive.c

index 89ed7d063536865f1b7c5f4cd801bef98e35029f..9ceb8e160b7fd7c6960cee706960640f7801534b 100644 (file)
@@ -965,35 +965,29 @@ static void* hls_Thread(vlc_object_t *p_this)
 static int Prefetch(stream_t *s, int *current)
 {
     stream_sys_t *p_sys = s->p_sys;
-    int i_segment = p_sys->segment;
+    int stream;
 
     /* Try to pick best matching stream */
-    int count = vlc_array_count(p_sys->hls_stream);
-    for (int stream = 0; stream < count; stream++)
-    {
-        hls_stream_t *hls = hls_Get(p_sys->hls_stream, stream);
-        if (hls == NULL)
-            return VLC_EGENERIC;
-
-        segment_t *segment = segment_GetSegment(hls,i_segment);
-        if (segment == NULL )
-            return VLC_EGENERIC;
+again:
+    stream = *current;
 
-        if (Download(s, hls, segment, &stream) != VLC_SUCCESS)
-            return VLC_EGENERIC;
+    hls_stream_t *hls = hls_Get(p_sys->hls_stream, *current);
+    if (hls == NULL)
+        return VLC_EGENERIC;
 
-        i_segment++;
+    segment_t *segment = segment_GetSegment(hls,  p_sys->segment);
+    if (segment == NULL )
+        return VLC_EGENERIC;
 
-        /* */
-        *current = stream;
-    }
+    if (Download(s, hls, segment, current) != VLC_SUCCESS)
+        return VLC_EGENERIC;
 
-    /* Download first 3 segments of this HLS stream */
-    hls_stream_t *hls = hls_Get(p_sys->hls_stream, *current);
-    if (hls == NULL)
-        return VLC_EGENERIC; /* FIXME: */
+    /* Found better bandwidth match, try again */
+    if (*current != stream)
+        goto again;
 
-    for (int i = 0; i < 3; i++)
+    /* Download first 2 segments of this HLS stream */
+    for (int i = 0; i < 2; i++)
     {
         segment_t *segment = segment_GetSegment(hls, p_sys->segment);
         if (segment == NULL )
@@ -1210,8 +1204,8 @@ static int Open(vlc_object_t *p_this)
         goto fail;
     }
 
-    /* */
-    int current = p_sys->current = hls_LowestBandwidthStream(p_sys->hls_stream);
+    /* Choose first HLS stream to start with */
+    int current = p_sys->current = 0;
     p_sys->segment = 0;
 
     if (Prefetch(s, &current) != VLC_SUCCESS)