Change underflow system in Player.

Underflow is now possible before the playhead enters a gap in the
buffered ranges.  Some misbehaving live content freezes with as much
as 50ms of data still buffered, so going into an underflow/buffering
state with a positive amount of buffered data is desirable.

To keep this from causing trouble at EOF, there is a special check
against video.duration.

Change-Id: I5a350c543fe33910a55cd8e9ebd8fd1ab2d6408c
This commit is contained in:
Joey Parrish
2015-04-14 14:32:27 -07:00
parent bbf1f21a2d
commit e37dbce2f7
+20 -7
View File
@@ -844,18 +844,21 @@ shaka.player.Player.prototype.onWatchdogTimer_ = function() {
// buffering. |buffered| will show the intersection of buffered ranges for
// both audio and video, so this is an accurate way to sense that we are
// buffering. The 'stalled', 'waiting', and 'suspended' events do not work
// for this purpose as of Chrome 38.
// for this purpose as of Chrome 38. Nor will video.readyState.
var bufferEnd = buffered.length ? buffered.end(buffered.length - 1) : 0;
var underflow = this.video_.currentTime - bufferEnd;
var buffered = bufferEnd - this.video_.currentTime;
var threshold = shaka.player.Player.UNDERFLOW_THRESHOLD_;
var fudgedBufferEnd = bufferEnd + shaka.player.Player.BUFFERED_FUDGE_FACTOR_;
if (!this.buffering_) {
if (underflow > shaka.player.Player.UNDERFLOW_THRESHOLD_) {
// Don't go into a buffering state at the end of the video.
if (fudgedBufferEnd < this.video_.duration && buffered < threshold) {
this.enterBufferingState_();
}
} else {
var resumeThreshold = this.videoSource_.getResumeThreshold();
shaka.asserts.assert(resumeThreshold > 0);
if (underflow < -resumeThreshold) {
if (buffered > resumeThreshold) {
this.endBufferingState_();
this.video_.play();
}
@@ -864,13 +867,23 @@ shaka.player.Player.prototype.onWatchdogTimer_ = function() {
/**
* The threshold for underflow, in seconds. If the play head is outside the
* buffered range by this much, we will consider the player to be out of data.
* The threshold for underflow, in seconds. If there is less than this amount
* of data buffered, we will consider the player to be out of data.
*
* @private {number}
* @const
*/
shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.050;
shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.1;
/**
* A fudge factor applied to buffered ranges to determine if the end of the
* video is buffered.
*
* @private {number}
* @const
*/
shaka.player.Player.BUFFERED_FUDGE_FACTOR_ = 0.05;
/**