[vlc-devel] [PATCH] HttpLive stream_filter: alternative version of ChooseSegment function
Łukasz Korbel
korbel85 at gmail.com
Mon Mar 12 18:25:32 CET 2012
I made modification as we talked:
Subject: [PATCH] HLS: start-time option
User can specify how long, after playlist beginning, to start playback.
---
modules/stream_filter/httplive.c | 66 ++++++++++++++++++++-----------------
1 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index b4ed58d..e64a07a 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -48,11 +48,21 @@
static int Open (vlc_object_t *);
static void Close(vlc_object_t *);
+#define HLS_STARTTIME_TEXT N_("Start no earlier than given time from begining")
+#define HLS_STARTTIME_LONGTEXT N_("Start playback from segment, that is at "\
+ "least given number of seconds after "\
+ "playlist beginning (accuracy depends on "\
+ "segments length). Please note that "\
+ "playback will not start later than from "\
+ "last but two segment in playlist.")
+
vlc_module_begin()
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_STREAM_FILTER)
set_description(N_("Http Live Streaming stream filter"))
set_capability("stream_filter", 20)
+ add_integer( "hls-start-time", 0, HLS_STARTTIME_TEXT,
HLS_STARTTIME_LONGTEXT, true )
+ change_integer_range (0, 65535)
set_callbacks(Open, Close)
vlc_module_end()
@@ -125,6 +135,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 +442,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))
+ /* If playing live stream use start-time value to determine first
segment */
+ if (p_sys->b_live && 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 at least before last two segments.
+ 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 +1911,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 */
+ p_sys->i_start_time = var_InheritInteger(s, "hls-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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-HLS-start-time-option.patch
Type: text/x-patch
Size: 4650 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120312/9efa6781/attachment.bin>
More information about the vlc-devel
mailing list