From 4021ce949b4ae20720e15709757344c5ec3be62d Mon Sep 17 00:00:00 2001 From: Ilkka Ollakka Date: Sat, 1 Feb 2014 14:01:38 +0200 Subject: [PATCH] httplive: use longest segment to calculate reload wait instead of given max duration tag This way if playlist contains way shorter segments than max-duration, we have better estimate on how ofter we should reload playlist. --- modules/stream_filter/httplive.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c index 12304d3578bd..725a538cfe42 100644 --- a/modules/stream_filter/httplive.c +++ b/modules/stream_filter/httplive.c @@ -83,6 +83,7 @@ typedef struct hls_stream_s int version; /* protocol version should be 1 */ int sequence; /* media sequence number */ int duration; /* maximum duration per segment (s) */ + int max_segment_length; /* maximum duration segments */ uint64_t bandwidth; /* bandwidth usage of segments (bits per second)*/ uint64_t size; /* stream length is calculated by taking the sum foreach segment of (segment->duration * hls->bandwidth/8) */ @@ -240,6 +241,7 @@ static hls_stream_t *hls_New(vlc_array_t *hls_stream, const int id, const uint64 hls->id = id; hls->bandwidth = bw; hls->duration = -1;/* unknown */ + hls->max_segment_length = -1;/* unknown */ hls->size = 0; hls->sequence = 0; /* default is 0 */ hls->version = 1; /* default protocol version */ @@ -652,6 +654,8 @@ static int parse_SegmentInformation(hls_stream_t *hls, char *p_read, int *durati value = ((int)d); *duration = value; } + if( *duration > hls->max_segment_length) + hls->max_segment_length = *duration; /* Ignore the rest of the line */ return VLC_SUCCESS; @@ -1369,6 +1373,7 @@ static int hls_UpdatePlaylist(stream_t *s, hls_stream_t *hls_new, hls_stream_t * hls_new->id, hls_new->bandwidth, count); vlc_mutex_lock(&hls_old->lock); + hls_old->max_segment_length=-1; for (int n = 0; n < count; n++) { segment_t *p = segment_GetSegment(hls_new, n); @@ -1438,6 +1443,8 @@ static int hls_UpdatePlaylist(stream_t *s, hls_stream_t *hls_new, hls_stream_t * } vlc_array_append(hls_old->segments, p); msg_Dbg(s, "- segment %d appended", p->sequence); + hls_old->max_segment_length = __MAX(hls_old->max_segment_length, l->duration); + msg_Dbg(s, " playlists new max duration %d", hls_old->max_segment_length); // Signal download thread otherwise the segment will not get downloaded *stream_appended = true; @@ -1746,7 +1753,7 @@ static void* hls_Reload(void *p_this) /* determine next time to update playlist */ p_sys->playlist.last = now; - p_sys->playlist.wakeup = now + ((mtime_t)(hls->duration * wait) + p_sys->playlist.wakeup = now + ((mtime_t)(hls->max_segment_length * wait) * (mtime_t)1000000); }