[vlc-devel] [PATCH] HttpLive stream_filter: alternative version of ChooseSegment function
Łukasz Korbel
korbel85 at gmail.com
Mon Mar 12 18:53:27 CET 2012
You are completely right. Here is version with existing start-time:
>From 75f06911df5735716c547c186267b0791069176c Mon Sep 17 00:00:00 2001
From: Lukasz Korbel <korbel85 at gmail.com>
Date: Mon, 12 Mar 2012 17:17:53 +0100
Subject: [PATCH] HLS: implementation of start-time option
User can specify how long, after playlist beginning, to start playback.
Accuracy depends on segments length.
---
modules/stream_filter/httplive.c | 56 +++++++++++++++++--------------------
1 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index b4ed58d..666eef3 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -125,6 +125,8 @@ struct stream_sys_t
int stream; /* current hls_stream */
int segment; /* current segment for playback */
} playback;
+ /* Settings for playback */
+ int i_start_time; /* seconds after playlist first segment*/
/* Playlist */
struct hls_playlist_s
@@ -430,43 +432,34 @@ static int ChooseSegment(stream_t *s, const int current)
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 index = 0;
int count = vlc_array_count(hls->segments);
- int i = p_sys->b_live ? count - 1 : 0;
+ segment_t *segment;
- while((i >= 0) && (i < count))
+ /* Use start-time value to determine first segment */
+ if (p_sys->i_start_time > 0)
{
- segment_t *segment = segment_GetSegment(hls, i);
- assert(segment);
-
- if (segment->duration > hls->duration)
+ int duration = 0;
+ /* Must start no later than from last but two segment:
+ http://tools.ietf.org/html/draft-pantos-http-live-streaming-00#section-6.2.2
*/
+ while (index < count - 2)
{
- 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;
+ segment = segment_GetSegment(hls, index);
+ duration += segment->duration;
+ if (duration >= p_sys->i_start_time)
+ break; /* segment found */
+ else
+ index++;
}
-
- if (p_sys->b_live)
- i-- ;
- else
- i++;
}
+ else
+ segment = segment_GetSegment(hls, index);
+
+ /* query for starting segment sequence number */
+ int sequence = segment->sequence;
- msg_Info(s, "Choose segment %d/%d (sequence=%d)", wanted, count, sequence);
- return wanted;
+ msg_Info(s, "Choose segment %d/%d (sequence=%d)", index+1, count,
sequence);
+ return index;
}
/* Parsing */
@@ -1908,6 +1901,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 );
+ /* Read playlist settings from config, implicit cast to int */
+ p_sys->i_start_time = var_InheritFloat(s, "start-time");
+
/* Choose first HLS stream to start with */
int current = p_sys->playback.stream = 0;
p_sys->playback.segment = p_sys->download.segment =
ChooseSegment(s, current);
--
1.7.5.4
Regards,
Łukasz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-HLS-implementation-of-start-time-option.patch
Type: text/x-patch
Size: 3614 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120312/5ff4ea1e/attachment.bin>
More information about the vlc-devel
mailing list