Skip to content

Commit

Permalink
Fix reload interval computation
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bartos committed Feb 12, 2019
1 parent 4dd1ae7 commit 8654222
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/controller/level-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ export function adjustSliding (oldPlaylist, newPlaylist) {

export function computeReloadInterval (currentPlaylist, newPlaylist, lastRequestTime) {
let reloadInterval = 1000 * (newPlaylist.averagetargetduration ? newPlaylist.averagetargetduration : newPlaylist.targetduration);
const minReloadInterval = reloadInterval / 2;
if (currentPlaylist && newPlaylist.endSN === currentPlaylist.endSN) {
// follow HLS Spec, If the client reloads a Playlist file and finds that it has not
// changed then it MUST wait for a period of one-half the target
// duration before retrying.
reloadInterval /= 2;
reloadInterval = minReloadInterval;
}
// decrement reloadInterval with level loading delay

if (lastRequestTime) {
reloadInterval -= (window.performance.now() - lastRequestTime);
reloadInterval = Math.max(minReloadInterval, reloadInterval - (window.performance.now() - lastRequestTime));
}
// in any case, don't reload more than half of target duration
reloadInterval = Math.max(reloadInterval / 2, Math.round(reloadInterval), 0);
return reloadInterval;
return Math.round(reloadInterval);
}
4 changes: 2 additions & 2 deletions tests/unit/controller/level-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ describe('LevelHelper Tests', function () {
expect(actual).to.equal(4000);
});

it('returns 0 if request time causes the interval to be negative', function () {
it('returns a minimum of half the target duration', function () {
const oldPlaylist = generatePlaylist([1, 2]);
const newPlaylist = generatePlaylist([3, 4]);
newPlaylist.averagetargetduration = 5;

const clock = sandbox.useFakeTimers();
clock.tick(9000);
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, 1000);
expect(actual).to.equal(0);
expect(actual).to.equal(2500);
});
});
});

0 comments on commit 8654222

Please sign in to comment.