[vlc-commits] commit: stream_filter/httplive.c: Start playback of live HLS streams near the end of the playlist. ( Jean-Paul Saman )

git at videolan.org git at videolan.org
Tue Jan 4 16:46:57 CET 2011


vlc | branch: master | Jean-Paul Saman <jean-paul.saman at m2x.nl> | Tue Jan  4 13:26:52 2011 +0100| [7b9b81d93cd4b47532dd79ea744f0dce028d4698] | committer: Jean-Paul Saman 

stream_filter/httplive.c: Start playback of live HLS streams near the end of the playlist.

Playback of live streams with HLS started at index 0 from the downloaded playlists. For
live streams it is more natural to be closer to the end of the playlist, but not within
the last 3 segments of the stream.

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

 modules/stream_filter/httplive.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index a50817c..dca216d 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -343,6 +343,15 @@ static segment_t *segment_Find(hls_stream_t *hls, int sequence)
     return NULL;
 }
 
+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;
+}
+
 /* Parsing */
 static char *parse_Attributes(const char *line, const char *attr)
 {
@@ -1261,10 +1270,10 @@ static void* hls_Thread(vlc_object_t *p_this)
 
         vlc_mutex_lock(&hls->lock);
         segment_t *segment = segment_GetSegment(hls, p_sys->download.segment);
-        assert(segment);
         vlc_mutex_unlock(&hls->lock);
 
-        if (Download(s, hls, segment, &p_sys->download.current) != VLC_SUCCESS)
+        if ((segment != NULL) &&
+            (Download(s, hls, segment, &p_sys->download.current) != VLC_SUCCESS))
         {
             if (!vlc_object_alive(p_this)) break;
 
@@ -1306,7 +1315,7 @@ again:
     if (hls == NULL)
         return VLC_EGENERIC;
 
-    segment_t *segment = segment_GetSegment(hls, p_sys->playback.segment);
+    segment_t *segment = segment_GetSegment(hls, p_sys->download.segment);
     if (segment == NULL )
         return VLC_EGENERIC;
 
@@ -1321,20 +1330,20 @@ again:
     stream = *current;
     for (int i = 0; i < 2; i++)
     {
-        segment_t *segment = segment_GetSegment(hls, i);
+        segment_t *segment = segment_GetSegment(hls, p_sys->download.segment);
         if (segment == NULL )
             return VLC_EGENERIC;
 
         if (segment->data)
         {
-            p_sys->playback.segment++;
+            p_sys->download.segment++;
             continue;
         }
 
         if (Download(s, hls, segment, current) != VLC_SUCCESS)
             return VLC_EGENERIC;
 
-        p_sys->playback.segment++;
+        p_sys->download.segment++;
 
         /* adapt bandwidth? */
         if (*current != stream)
@@ -1558,7 +1567,8 @@ static int Open(vlc_object_t *p_this)
 
     /* Choose first HLS stream to start with */
     int current = p_sys->playback.current = 0;
-    p_sys->playback.segment = 0;
+    p_sys->playback.segment = p_sys->download.segment =
+            p_sys->b_live ? live_ChooseSegment(s, current) : 0;
 
     if (Prefetch(s, &current) != VLC_SUCCESS)
     {
@@ -1584,9 +1594,7 @@ static int Open(vlc_object_t *p_this)
 
     p_sys->download.current = current;
     p_sys->playback.current = current;
-    p_sys->download.segment = p_sys->playback.segment;
     p_sys->download.seek = -1;
-    p_sys->playback.segment = 0; /* reset to first segment */
     p_sys->thread->s = s;
 
     vlc_mutex_init(&p_sys->download.lock_wait);



More information about the vlc-commits mailing list