584b2b99 by David LaPalomento

Make a constant for the live edge

Don't use the literal "3" for the number of segments required for stable live playback.
1 parent 25033e31
...@@ -4,6 +4,16 @@ ...@@ -4,6 +4,16 @@
4 (function(window, videojs) { 4 (function(window, videojs) {
5 'use strict'; 5 'use strict';
6 6
7 var Playlist = {
8 /**
9 * The number of segments that are unsafe to start playback at in
10 * a live stream. Changing this value can cause playback stalls.
11 * See HTTP Live Streaming, "Playing the Media Playlist File"
12 * https://tools.ietf.org/html/draft-pantos-http-live-streaming-18#section-6.3.3
13 */
14 UNSAFE_LIVE_SEGMENTS: 3
15 };
16
7 var duration, intervalDuration, backwardDuration, forwardDuration, seekable; 17 var duration, intervalDuration, backwardDuration, forwardDuration, seekable;
8 18
9 backwardDuration = function(playlist, endSequence) { 19 backwardDuration = function(playlist, endSequence) {
...@@ -186,13 +196,14 @@ ...@@ -186,13 +196,14 @@
186 // https://tools.ietf.org/html/draft-pantos-http-live-streaming-16#section-6.3.3 196 // https://tools.ietf.org/html/draft-pantos-http-live-streaming-16#section-6.3.3
187 start = intervalDuration(playlist, playlist.mediaSequence); 197 start = intervalDuration(playlist, playlist.mediaSequence);
188 end = intervalDuration(playlist, 198 end = intervalDuration(playlist,
189 playlist.mediaSequence + Math.max(0, playlist.segments.length - 3)); 199 playlist.mediaSequence +
200 Math.max(0, playlist.segments.length - Playlist.UNSAFE_LIVE_SEGMENTS));
190 return videojs.createTimeRange(start, end); 201 return videojs.createTimeRange(start, end);
191 }; 202 };
192 203
193 // exports 204 // exports
194 videojs.Hls.Playlist = { 205 Playlist.duration = duration;
195 duration: duration, 206 Playlist.seekable = seekable;
196 seekable: seekable 207 videojs.Hls.Playlist = Playlist;
197 }; 208
198 })(window, window.videojs); 209 })(window, window.videojs);
......