From e37dbce2f7d22c8cbc4d576c55b41e73aec28fd4 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 14 Apr 2015 14:32:27 -0700 Subject: [PATCH] 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 --- lib/player/player.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/player/player.js b/lib/player/player.js index 3ff08769d..b794e7765 100644 --- a/lib/player/player.js +++ b/lib/player/player.js @@ -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; /**