Skip to content

Commit

Permalink
Merge pull request #4 from gesinger/ewma-selector-minor-changes
Browse files Browse the repository at this point in the history
Change binds in moving average test to calls
  • Loading branch information
dmlap authored May 30, 2017
2 parents a626249 + 3efc64c commit f9fe1c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/playlist-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ const simpleSelector = function(master, bandwidth, width, height) {
* Chooses the appropriate media playlist based on the most recent
* bandwidth estimate and the player size.
*
* Expects to be called within the context of an instance of HlsHandler
*
* @return {Playlist} the highest bitrate playlist less than the
* currently detected bandwidth, accounting for some amount of
* bandwidth variance
Expand All @@ -212,6 +214,8 @@ export const lastBandwidthSelector = function() {
* exponential-weighted moving average of the bandwidth after
* filtering for player size.
*
* Expects to be called within the context of an instance of HlsHandler
*
* @param {Number} decay - a number between 0 and 1. Higher values of
* this parameter will cause previous bandwidth estimates to lose
* significance more quickly.
Expand Down
9 changes: 5 additions & 4 deletions test/playlist-selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,26 @@ test('Exponential moving average has a configurable decay parameter', function(a
{ attributes: { BANDWIDTH: 100 } }
];
hls.systemBandwidth = 50 * Config.BANDWIDTH_VARIANCE + 1;
playlist = instantAverage.bind(hls)();
playlist = instantAverage.call(hls);
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');

hls.systemBandwidth = 100 * Config.BANDWIDTH_VARIANCE + 1;
playlist = instantAverage.bind(hls)();
playlist = instantAverage.call(hls);
assert.equal(playlist.attributes.BANDWIDTH, 100, 'selected the top playlist');

const fiftyPercentDecay = movingAverageBandwidthSelector(0.5);

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

// average = decay * systemBandwidth + (1 - decay) * average
// bandwidth = 0.5 * systemBandwidth + 0.5 * (100 * variance + 1)
// 50 * variance + 1 = 0.5 * (systemBandwidth + (100 * variance + 1))
// 2 * 50 * variance + 2 = systemBandwidth + (100 * variance + 1)
// 100 * variance + 2 - (100 * variance + 1) = systemBandwidth
// 1 = systemBandwidth
hls.systemBandwidth = 1;
playlist = fiftyPercentDecay.bind(hls)();
playlist = fiftyPercentDecay.call(hls);
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');
});

0 comments on commit f9fe1c0

Please sign in to comment.