[vlc-devel] [PATCH] HttpLive stream_filter: alternative version of ChooseSegment function

Łukasz Korbel korbel85 at gmail.com
Tue Mar 13 16:27:46 CET 2012


I guess the best solution is to start playback from first segment in
playlist. If someone want to start from later segment this can be
achieved with seeking. In that case there is no need to keep
ChooseSegment function no more (which was not very optimal btw.)

>From 17b9125a6b9d780e8a8449ebcdcce59d394102ac Mon Sep 17 00:00:00 2001
From: Lukasz Korbel <korbel85 at gmail.com>
Date: Tue, 13 Mar 2012 16:04:14 +0100
Subject: [PATCH] HLS: allways start from first segment in playlist

---
 modules/stream_filter/httplive.c |   49 +------------------------------------
 1 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 6748ad2..5c0a08e 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -425,51 +425,6 @@ static segment_t *segment_Find(hls_stream_t *hls,
const int sequence)
     return NULL;
 }

-static int ChooseSegment(stream_t *s, const 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;
-
-    /* Choose a segment to start which is no closer than
-     * 3 times the target duration from the end of the playlist.
-     */
-    int wanted = 0;
-    int duration = 0;
-    int sequence = 0;
-    int count = vlc_array_count(hls->segments);
-    int i = p_sys->b_live ? count - 1 : 0;
-
-    while((i >= 0) && (i < count))
-    {
-        segment_t *segment = segment_GetSegment(hls, i);
-        assert(segment);
-
-        if (segment->duration > hls->duration)
-        {
-            msg_Err(s, "EXTINF:%d duration is larger than
EXT-X-TARGETDURATION:%d",
-                    segment->duration, hls->duration);
-        }
-
-        duration += segment->duration;
-        if (duration >= 3 * hls->duration)
-        {
-            /* Start point found */
-            wanted = p_sys->b_live ? i : 0;
-            sequence = segment->sequence;
-            break;
-        }
-
-        if (p_sys->b_live)
-            i-- ;
-        else
-            i++;
-    }
-
-    msg_Info(s, "Choose segment %d/%d (sequence=%d)", wanted, count, sequence);
-    return wanted;
-}
-
 /* Parsing */
 static char *parse_Attributes(const char *line, const char *attr)
 {
@@ -1911,9 +1866,9 @@ static int Open(vlc_object_t *p_this)
     qsort( p_sys->hls_stream->pp_elems, p_sys->hls_stream->i_count,
            sizeof( hls_stream_t* ), &hls_CompareStreams );

-    /* Choose first HLS stream to start with */
+    /* Start always from first segment in playlist */
     int current = p_sys->playback.stream = 0;
-    p_sys->playback.segment = p_sys->download.segment =
ChooseSegment(s, current);
+    p_sys->playback.segment = p_sys->download.segment = 0;

     /* manage encryption key if needed */
     hls_ManageSegmentKeys(s, hls_Get(p_sys->hls_stream, current));
-- 
1.7.5.4

Kind regards,
Łukasz Korbel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-HLS-allways-start-from-first-segment-in-playlist.patch
Type: text/x-patch
Size: 2647 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120313/115b3a1e/attachment.bin>


More information about the vlc-devel mailing list