Skip to content

Commit

Permalink
Merge pull request video-dev#466 from JHartman5/abr-playback-rate
Browse files Browse the repository at this point in the history
Make the ABR controller take the playback rate into account
  • Loading branch information
mangui committed Jun 9, 2016
2 parents 99f909e + 12448fe commit 60dbea9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,22 @@ class AbrController extends EventHandler {
}
/* only monitor frag retrieval time if
(video not paused OR first fragment being loaded(ready state === HAVE_NOTHING = 0)) AND autoswitching enabled AND not lowest level (=> means that we have several levels) */
if (v && (!v.paused || !v.readyState) && frag.autoLevel && frag.level) {
let requestDelay = performance.now() - frag.trequest;
if (v && ((!v.paused && (v.playbackRate !== 0)) || !v.readyState) && frag.autoLevel && frag.level) {
let requestDelay = performance.now() - frag.trequest,
playbackRate = Math.abs(v.playbackRate);
// monitor fragment load progress after half of expected fragment duration,to stabilize bitrate
if (requestDelay > (500 * frag.duration)) {
if (requestDelay > (500 * frag.duration / playbackRate)) {
let loadRate = Math.max(1,frag.loaded * 1000 / requestDelay); // byte/s; at least 1 byte/s to avoid division by zero
if (frag.expectedLen < frag.loaded) {
frag.expectedLen = frag.loaded;
}
let pos = v.currentTime;
let fragLoadedDelay = (frag.expectedLen - frag.loaded) / loadRate;
let bufferStarvationDelay = BufferHelper.bufferInfo(v,pos,hls.config.maxBufferHole).end - pos;
let bufferStarvationDelay = (BufferHelper.bufferInfo(v,pos,hls.config.maxBufferHole).end - pos) / playbackRate;
// consider emergency switch down only if we have less than 2 frag buffered AND
// time to finish loading current fragment is bigger than buffer starvation delay
// ie if we risk buffer starvation if bw does not increase quickly
if (bufferStarvationDelay < 2*frag.duration && fragLoadedDelay > bufferStarvationDelay) {
if ((bufferStarvationDelay < (2 * frag.duration / playbackRate)) && (fragLoadedDelay > bufferStarvationDelay)) {
let fragLevelNextLoadedDelay, nextLoadLevel;
// lets iterate through lower level and try to find the biggest one that could avoid rebuffering
// we start from current level - 1 and we step down , until we find a matching level
Expand Down Expand Up @@ -151,7 +152,11 @@ class AbrController extends EventHandler {
}

get nextAutoLevel() {
var lastbw = this.lastbw, hls = this.hls,adjustedbw, i, maxAutoLevel;
let hls = this.hls,
v = hls.media,
playbackRate = ((v && v.playbackRate !== 0) ? Math.abs(v.playbackRate) : 1.0),
lastbw = this.lastbw / playbackRate;
var adjustedbw, i, maxAutoLevel;
if (this._autoLevelCapping === -1 && hls.levels && hls.levels.length) {
maxAutoLevel = hls.levels.length - 1;
} else {
Expand Down

0 comments on commit 60dbea9

Please sign in to comment.