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) {
// we have entered a state where we are fetching the same segment,
// try to walk forward
if (this.lastSegmentLoaded_ &&
this.lastSegmentLoaded_ === segment) {
this.lastSegmentLoaded_ === this.playlistUriToUrl(segment.uri)) {
return this.fillBuffer(mediaIndex + 1);
}
......@@ -964,7 +964,7 @@ videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) {
/* Turns segment byterange into a string suitable for use in
* HTTP Range requests
*/
videojs.HlsHandler.prototype.byterangeStr = function(byterange) {
videojs.HlsHandler.prototype.byterangeStr_ = function(byterange) {
var byterangeStart, byterangeEnd;
// `byterangeEnd` is one less than `offset + length` because the HTTP range
......@@ -976,10 +976,10 @@ videojs.HlsHandler.prototype.byterangeStr = function(byterange) {
/* Defines headers for use in the xhr request for a particular segment.
*/
videojs.HlsHandler.prototype.segmentXhrHeaders = function(segment) {
videojs.HlsHandler.prototype.segmentXhrHeaders_ = function(segment) {
var headers = {};
if ('byterange' in segment) {
headers['Range'] = this.byterangeStr(segment.byterange);
headers['Range'] = this.byterangeStr_(segment.byterange);
}
return headers;
};
......@@ -1078,7 +1078,7 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) {
// some time to switch renditions in the event of a catastrophic
// decrease in network performance or a server issue.
timeout: (segment.duration * 1.5) * 1000,
headers: this.segmentXhrHeaders(segment)
headers: this.segmentXhrHeaders_(segment)
}, function(error, request) {
// This is a timeout of a previously aborted segment request
// so simply ignore it
......
......@@ -324,6 +324,56 @@ test('starts playing if autoplay is specified', function() {
strictEqual(1, plays, 'play was called');
});
test('XHR requests first byte range on play', function() {
player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.tech_.triggerReady();
clock.tick(1);
player.tech_.trigger('play');
openMediaSource(player);
standardXHRResponse(requests[0]);
equal(requests[1].headers.Range, "bytes=0-522827");
});
test('Seeking requests correct byte range', function() {
player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.tech_.triggerReady();
clock.tick(1);
player.tech_.trigger('play');
openMediaSource(player);
standardXHRResponse(requests[0]);
player.tech_.hls.sourceBuffer.trigger('updateend');
clock.tick(1);
player.currentTime(40);
clock.tick(1);
equal(requests[2].headers.Range, "bytes=2299992-2835603");
});
test('if buffered, will request second segment byte range', function() {
player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.tech_.triggerReady();
clock.tick(1);
player.tech_.trigger('play');
openMediaSource(player);
player.tech_.buffered = function() {
return videojs.createTimeRange(0, 20);
};
standardXHRResponse(requests[0]);
standardXHRResponse(requests[1]);
player.tech_.hls.sourceBuffer.trigger('updateend');
player.tech_.hls.checkBuffer_();
clock.tick(100);
equal(requests[2].headers.Range, "bytes=1823412-2299991");
});
test('autoplay seeks to the live point after playlist load', function() {
var currentTime = 0;
player.autoplay(true);
......