Skip to content

Commit

Permalink
Merge branch 'main' into bug-fix/moving-average-bandwidth-selector-up…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
gkatsev authored Jun 22, 2021
2 parents 04c1f43 + 55726af commit fd3bd54
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 2 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"devDependencies": {
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-strip": "^2.0.1",
"@videojs/generator-helpers": "~2.0.1",
"d3": "^3.4.8",
"es5-shim": "^4.5.13",
Expand Down
7 changes: 7 additions & 0 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const worker = require('rollup-plugin-worker-factory');
const {terser} = require('rollup-plugin-terser');
const createTestData = require('./create-test-data.js');
const replace = require('@rollup/plugin-replace');
const strip = require('@rollup/plugin-strip');

const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';

Expand Down Expand Up @@ -57,6 +58,9 @@ const options = {
}
defaults.module.unshift('replace');

defaults.module.unshift('strip');
defaults.browser.unshift('strip');

return defaults;
},
primedPlugins(defaults) {
Expand All @@ -71,6 +75,9 @@ const options = {
output: {comments: 'some'},
compress: {passes: 2}
}),
strip: strip({
functions: ['TEST_ONLY_*']
}),
createTestData: createTestData()
});

Expand Down
7 changes: 6 additions & 1 deletion src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export class MasterPlaylistController extends videojs.EventTarget {
bandwidth,
externVhs,
useCueTags,
maxPlaylistRetries,
blacklistDuration,
enableLowInitialPlaylist,
sourceType,
Expand All @@ -152,6 +151,12 @@ export class MasterPlaylistController extends videojs.EventTarget {
throw new Error('A non-empty playlist URL or JSON manifest string is required');
}

let { maxPlaylistRetries } = options;

if (maxPlaylistRetries === null || typeof maxPlaylistRetries === 'undefined') {
maxPlaylistRetries = Infinity;
}

Vhs = externVhs;

this.experimentalBufferBasedABR = Boolean(experimentalBufferBasedABR);
Expand Down
12 changes: 11 additions & 1 deletion src/playlist-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const comparePlaylistResolution = function(left, right) {
* currently detected bandwidth, accounting for some amount of
* bandwidth variance
*/
export const simpleSelector = function(
export let simpleSelector = function(
master,
playerBandwidth,
playerWidth,
Expand Down Expand Up @@ -313,6 +313,16 @@ export const simpleSelector = function(
return null;
};

export const TEST_ONLY_SIMPLE_SELECTOR = (newSimpleSelector) => {
const oldSimpleSelector = simpleSelector;

simpleSelector = newSimpleSelector;

return function resetSimpleSelector() {
simpleSelector = oldSimpleSelector;
};
};

// Playlist Selectors

/**
Expand Down
64 changes: 64 additions & 0 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5796,6 +5796,70 @@ QUnit.test('true if duration < 30', function(assert) {
assert.ok(mpc.shouldSwitchToMedia_(nextPlaylist), 'should switch');
});

QUnit.test('maxPlaylistRetries defaults to Infinity when no value or null/undefined is provided', function(assert) {
const playerNull = createPlayer({
html5: {
vhs: {
maxPlaylistRetries: null
}
}
});

const playerUndefined = createPlayer({
html5: {
vhs: {
maxPlaylistRetries: undefined
}
}
});

const playerNoValue = createPlayer();

playerNull.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

playerUndefined.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

playerNoValue.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

assert.equal(playerNull.tech_.vhs.masterPlaylistController_.maxPlaylistRetries, Infinity, 'maxPlaylistRetries defaults to Infinity when null is provided as the option value');
assert.equal(playerUndefined.tech_.vhs.masterPlaylistController_.maxPlaylistRetries, Infinity, 'maxPlaylistRetries defaults to Infinity when undefined is provided as the option value');
assert.equal(playerNoValue.tech_.vhs.masterPlaylistController_.maxPlaylistRetries, Infinity, 'maxPlaylistRetries defaults to Infinity when no value is provided');
});

QUnit.test('maxPlaylistRetries is set when zero is passed as the option\'s value', function(assert) {
const player = createPlayer({
html5: {
vhs: {
maxPlaylistRetries: 0
}
}
});

player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

assert.equal(player.tech_.vhs.masterPlaylistController_.maxPlaylistRetries, 0, 'maxPlaylistRetries was set to zero');
});

QUnit.test('true duration < 16 with experimentalBufferBasedABR', function(assert) {
const mpc = this.masterPlaylistController;
const nextPlaylist = {id: 'foo', endList: true};
Expand Down
45 changes: 45 additions & 0 deletions test/playlist-selectors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import document from 'global/document';
import {
TEST_ONLY_SIMPLE_SELECTOR,
simpleSelector,
movingAverageBandwidthSelector,
minRebufferMaxBandwidthSelector,
Expand Down Expand Up @@ -64,6 +65,50 @@ test('Exponential moving average has a configurable decay parameter', function(a
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');
});

test('Calling exponential moving average wont decay average unless new bandwidth data was provided', function(assert) {
let playlist;
const simSel = simpleSelector;
const bandwidthAverages = [];

const resetSimpleSelector = TEST_ONLY_SIMPLE_SELECTOR((...args) => {
// second argument to simpleSelector is the average
bandwidthAverages.push(args[1]);
return simSel(...args);
});

this.vhs.playlists.master.playlists = [
{ attributes: { BANDWIDTH: 1 } },
{ attributes: { BANDWIDTH: 50 } },
{ attributes: { BANDWIDTH: 100 } }
];

const fiftyPercentDecay = movingAverageBandwidthSelector(0.50);

this.vhs.systemBandwidth = 50 * Config.BANDWIDTH_VARIANCE + 1;
playlist = fiftyPercentDecay.call(this.vhs);
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');

this.vhs.systemBandwidth = 1000 * Config.BANDWIDTH_VARIANCE + 1;
playlist = fiftyPercentDecay.call(this.vhs);
assert.equal(playlist.attributes.BANDWIDTH, 100, 'selected the top playlist');

// using the systemBandwidth values above, 50->1000
// we decay into 1000 after 50 iterations
let i = 50;

while (i--) {
playlist = fiftyPercentDecay.call(this.vhs);
}

assert.equal(
bandwidthAverages[bandwidthAverages.length - 1],
bandwidthAverages[1],
'bandwidth should only change when we get new bandwidth data'
);

resetSimpleSelector();
});

test(
'minRebufferMaxBandwidthSelector picks highest rendition without rebuffering',
function(assert) {
Expand Down

0 comments on commit fd3bd54

Please sign in to comment.