f4e07878 by Dylan Dove Committed by David LaPalomento

Fixed up changes to byte-range support

- Addressed internal function issues as well as removed a potential fillBuffer bug
- Added tests for byte-range requests
1 parent d8ff8610
...@@ -894,7 +894,7 @@ videojs.HlsHandler.prototype.fillBuffer = function(mediaIndex) { ...@@ -894,7 +894,7 @@ videojs.HlsHandler.prototype.fillBuffer = function(mediaIndex) {
894 // we have entered a state where we are fetching the same segment, 894 // we have entered a state where we are fetching the same segment,
895 // try to walk forward 895 // try to walk forward
896 if (this.lastSegmentLoaded_ && 896 if (this.lastSegmentLoaded_ &&
897 this.lastSegmentLoaded_ === segment) { 897 this.lastSegmentLoaded_ === this.playlistUriToUrl(segment.uri)) {
898 return this.fillBuffer(mediaIndex + 1); 898 return this.fillBuffer(mediaIndex + 1);
899 } 899 }
900 900
...@@ -964,7 +964,7 @@ videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) { ...@@ -964,7 +964,7 @@ videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) {
964 /* Turns segment byterange into a string suitable for use in 964 /* Turns segment byterange into a string suitable for use in
965 * HTTP Range requests 965 * HTTP Range requests
966 */ 966 */
967 videojs.HlsHandler.prototype.byterangeStr = function(byterange) { 967 videojs.HlsHandler.prototype.byterangeStr_ = function(byterange) {
968 var byterangeStart, byterangeEnd; 968 var byterangeStart, byterangeEnd;
969 969
970 // `byterangeEnd` is one less than `offset + length` because the HTTP range 970 // `byterangeEnd` is one less than `offset + length` because the HTTP range
...@@ -976,10 +976,10 @@ videojs.HlsHandler.prototype.byterangeStr = function(byterange) { ...@@ -976,10 +976,10 @@ videojs.HlsHandler.prototype.byterangeStr = function(byterange) {
976 976
977 /* Defines headers for use in the xhr request for a particular segment. 977 /* Defines headers for use in the xhr request for a particular segment.
978 */ 978 */
979 videojs.HlsHandler.prototype.segmentXhrHeaders = function(segment) { 979 videojs.HlsHandler.prototype.segmentXhrHeaders_ = function(segment) {
980 var headers = {}; 980 var headers = {};
981 if ('byterange' in segment) { 981 if ('byterange' in segment) {
982 headers['Range'] = this.byterangeStr(segment.byterange); 982 headers['Range'] = this.byterangeStr_(segment.byterange);
983 } 983 }
984 return headers; 984 return headers;
985 }; 985 };
...@@ -1078,7 +1078,7 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { ...@@ -1078,7 +1078,7 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) {
1078 // some time to switch renditions in the event of a catastrophic 1078 // some time to switch renditions in the event of a catastrophic
1079 // decrease in network performance or a server issue. 1079 // decrease in network performance or a server issue.
1080 timeout: (segment.duration * 1.5) * 1000, 1080 timeout: (segment.duration * 1.5) * 1000,
1081 headers: this.segmentXhrHeaders(segment) 1081 headers: this.segmentXhrHeaders_(segment)
1082 }, function(error, request) { 1082 }, function(error, request) {
1083 // This is a timeout of a previously aborted segment request 1083 // This is a timeout of a previously aborted segment request
1084 // so simply ignore it 1084 // so simply ignore it
......
...@@ -324,6 +324,56 @@ test('starts playing if autoplay is specified', function() { ...@@ -324,6 +324,56 @@ test('starts playing if autoplay is specified', function() {
324 strictEqual(1, plays, 'play was called'); 324 strictEqual(1, plays, 'play was called');
325 }); 325 });
326 326
327 test('XHR requests first byte range on play', function() {
328 player.src({
329 src: 'manifest/playlist.m3u8',
330 type: 'application/vnd.apple.mpegurl'
331 });
332 player.tech_.triggerReady();
333 clock.tick(1);
334 player.tech_.trigger('play');
335 openMediaSource(player);
336 standardXHRResponse(requests[0]);
337 equal(requests[1].headers.Range, "bytes=0-522827");
338 });
339
340 test('Seeking requests correct byte range', function() {
341 player.src({
342 src: 'manifest/playlist.m3u8',
343 type: 'application/vnd.apple.mpegurl'
344 });
345 player.tech_.triggerReady();
346 clock.tick(1);
347 player.tech_.trigger('play');
348 openMediaSource(player);
349 standardXHRResponse(requests[0]);
350 player.tech_.hls.sourceBuffer.trigger('updateend');
351 clock.tick(1);
352 player.currentTime(40);
353 clock.tick(1);
354 equal(requests[2].headers.Range, "bytes=2299992-2835603");
355 });
356
357 test('if buffered, will request second segment byte range', function() {
358 player.src({
359 src: 'manifest/playlist.m3u8',
360 type: 'application/vnd.apple.mpegurl'
361 });
362 player.tech_.triggerReady();
363 clock.tick(1);
364 player.tech_.trigger('play');
365 openMediaSource(player);
366 player.tech_.buffered = function() {
367 return videojs.createTimeRange(0, 20);
368 };
369 standardXHRResponse(requests[0]);
370 standardXHRResponse(requests[1]);
371 player.tech_.hls.sourceBuffer.trigger('updateend');
372 player.tech_.hls.checkBuffer_();
373 clock.tick(100);
374 equal(requests[2].headers.Range, "bytes=1823412-2299991");
375 });
376
327 test('autoplay seeks to the live point after playlist load', function() { 377 test('autoplay seeks to the live point after playlist load', function() {
328 var currentTime = 0; 378 var currentTime = 0;
329 player.autoplay(true); 379 player.autoplay(true);
......