58b7c472 by jrivera

Minor fixes to the fetcher

Increased the bandwidthVariance based on similar constraints in other projects
Added a fudge factor of half a frame to account for TimeRanges rounding
Don't try to cancel a fetch in the middle of an append operation
1 parent 958f2b8c
...@@ -9,14 +9,15 @@ ...@@ -9,14 +9,15 @@
9 var 9 var
10 // a fudge factor to apply to advertised playlist bitrates to account for 10 // a fudge factor to apply to advertised playlist bitrates to account for
11 // temporary flucations in client bandwidth 11 // temporary flucations in client bandwidth
12 bandwidthVariance = 1.1, 12 bandwidthVariance = 1.2,
13 Component = videojs.getComponent('Component'), 13 Component = videojs.getComponent('Component'),
14 14
15 // the amount of time to wait between checking the state of the buffer 15 // the amount of time to wait between checking the state of the buffer
16 bufferCheckInterval = 500, 16 bufferCheckInterval = 500,
17 17
18 keyFailed, 18 keyFailed,
19 resolveUrl; 19 resolveUrl,
20 TIME_FUDGE_FACTOR = 1 / 60;
20 21
21 // returns true if a key has failed to download within a certain amount of retries 22 // returns true if a key has failed to download within a certain amount of retries
22 keyFailed = function(key) { 23 keyFailed = function(key) {
...@@ -396,7 +397,7 @@ videojs.HlsHandler.prototype.setupSourceBuffer_ = function() { ...@@ -396,7 +397,7 @@ videojs.HlsHandler.prototype.setupSourceBuffer_ = function() {
396 397
397 // transition the sourcebuffer to the ended state if we've hit the end of 398 // transition the sourcebuffer to the ended state if we've hit the end of
398 // the playlist 399 // the playlist
399 this.sourceBuffer.addEventListener('updateend', function() { 400 this.sourceBuffer.addEventListener('updateend', function updateEndHandler() {
400 var 401 var
401 segmentInfo = this.pendingSegment_, 402 segmentInfo = this.pendingSegment_,
402 segment, 403 segment,
...@@ -448,7 +449,8 @@ videojs.HlsHandler.prototype.setupSourceBuffer_ = function() { ...@@ -448,7 +449,8 @@ videojs.HlsHandler.prototype.setupSourceBuffer_ = function() {
448 return; 449 return;
449 } 450 }
450 451
451 if (timelineUpdates.length) { 452 if (timelineUpdates.length ||
453 segmentInfo.buffered.length !== this.tech_.buffered().length) {
452 this.updateDuration(playlist); 454 this.updateDuration(playlist);
453 // check if it's time to download the next segment 455 // check if it's time to download the next segment
454 this.fillBuffer(); 456 this.fillBuffer();
...@@ -540,6 +542,11 @@ videojs.HlsHandler.prototype.setCurrentTime = function(currentTime) { ...@@ -540,6 +542,11 @@ videojs.HlsHandler.prototype.setCurrentTime = function(currentTime) {
540 return currentTime; 542 return currentTime;
541 } 543 }
542 544
545 // if we are in the middle of appending a segment, let it finish up
546 if (this.pendingSegment_ && this.pendingSegment_.buffered) {
547 return currentTime;
548 }
549
543 this.lastSegmentLoaded_ = null; 550 this.lastSegmentLoaded_ = null;
544 551
545 // cancel outstanding requests and buffer appends 552 // cancel outstanding requests and buffer appends
...@@ -640,6 +647,7 @@ videojs.HlsHandler.prototype.cancelSegmentXhr = function() { ...@@ -640,6 +647,7 @@ videojs.HlsHandler.prototype.cancelSegmentXhr = function() {
640 this.segmentXhr_.abort(); 647 this.segmentXhr_.abort();
641 this.segmentXhr_ = null; 648 this.segmentXhr_ = null;
642 } 649 }
650
643 // clear out the segment being processed 651 // clear out the segment being processed
644 this.pendingSegment_ = null; 652 this.pendingSegment_ = null;
645 }; 653 };
...@@ -828,8 +836,8 @@ videojs.HlsHandler.prototype.findCurrentBuffered_ = function() { ...@@ -828,8 +836,8 @@ videojs.HlsHandler.prototype.findCurrentBuffered_ = function() {
828 if (buffered && buffered.length) { 836 if (buffered && buffered.length) {
829 // Search for a range containing the play-head 837 // Search for a range containing the play-head
830 for (i = 0; i < buffered.length; i++) { 838 for (i = 0; i < buffered.length; i++) {
831 if (buffered.start(i) <= currentTime && 839 if (buffered.start(i) - TIME_FUDGE_FACTOR <= currentTime &&
832 buffered.end(i) >= currentTime) { 840 buffered.end(i) + TIME_FUDGE_FACTOR >= currentTime) {
833 ranges = videojs.createTimeRanges(buffered.start(i), buffered.end(i)); 841 ranges = videojs.createTimeRanges(buffered.start(i), buffered.end(i));
834 ranges.indexOf = i; 842 ranges.indexOf = i;
835 return ranges; 843 return ranges;
......