Skip to content

Commit

Permalink
Merge pull request #2039 from streamroot/expose-average-throughput
Browse files Browse the repository at this point in the history
Add getter for average throughput on MediaPlayer's API
  • Loading branch information
Dan Sparacio authored Jul 7, 2017
2 parents 9a5a35d + 6a3973c commit bc0ed6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,19 @@ function MediaPlayer() {
return mediaPlayerModel.getBandwidthSafetyFactor();
}

/**
* Returns the average throughput computed in the ABR logic
*
* @param {string} type
* @return {number} value
* @memberof module:MediaPlayer
* @instance
*/
function getAverageThroughput(type) {
const throughputHistory = abrController.getThroughputHistory();
return throughputHistory ? throughputHistory.getAverageThroughput(type) : 0;
}

/**
* A timeout value in seconds, which during the ABRController will block switch-up events.
* This will only take effect after an abandoned fragment event occurs.
Expand Down Expand Up @@ -2455,6 +2468,7 @@ function MediaPlayer() {
removeAllABRCustomRule: removeAllABRCustomRule,
setBandwidthSafetyFactor: setBandwidthSafetyFactor,
getBandwidthSafetyFactor: getBandwidthSafetyFactor,
getAverageThroughput: getAverageThroughput,
setAbandonLoadTimeout: setAbandonLoadTimeout,
retrieveManifest: retrieveManifest,
addUTCTimingSource: addUTCTimingSource,
Expand Down
11 changes: 7 additions & 4 deletions test/unit/mocks/AbrControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ class AbrControllerMock{
this.limitBitrateByPortal = false;
this.usePixelRatioInLimitBitrateByPortal = false;
this.autoSwitchBitrate = {video: true, audio: true};
this.throughputHistory = undefined;
}

initialize() {}

createAbrRulesCollection() {}

reset() {}
reset() {
this.setup();
}

setConfig() {}

Expand Down Expand Up @@ -162,9 +165,9 @@ class AbrControllerMock{

}

setAverageThroughput() {}

getAverageThroughput() {}
getThroughputHistory() {
return this.throughputHistory;
}

updateTopQualityIndex() {}

Expand Down
20 changes: 18 additions & 2 deletions test/unit/streaming.MediaPlayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("MediaPlayer", function () {
beforeEach(function () {
player.initialize(videoElementMock, dummyUrl, false);
});
it("Method isReady should return false", function () {
it("Method isReady should return true", function () {
let isReady = player.isReady();
expect(isReady).to.be.true;
});
Expand Down Expand Up @@ -327,7 +327,7 @@ describe("MediaPlayer", function () {

});

describe("AutoBitrate Functions", function () {
describe("AbrController Functions", function () {
afterEach(function () {
abrControllerMock.reset();
})
Expand Down Expand Up @@ -457,6 +457,22 @@ describe("MediaPlayer", function () {
expect(AutoSwitchBitrateFor).to.be.false;
});

it("Method getAverageThroughput should return 0 when throughputHistory is not set up", function() {
const averageThroughput = player.getAverageThroughput('video');
expect(averageThroughput).to.equal(0);
});

it("Method getAverageThroughput should value computed from ThroughputHistory", function() {
const AVERAGE_THROUGHPUT = 2000;
abrControllerMock.throughputHistory = {
getAverageThroughput: function() {
return AVERAGE_THROUGHPUT;
}
};
const averageThroughput = player.getAverageThroughput('video');
expect(averageThroughput).to.equal(AVERAGE_THROUGHPUT);
});

describe("When it is not initialized", function () {
it("Method getQualityFor should throw an exception", function () {
expect(player.getQualityFor).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
Expand Down

0 comments on commit bc0ed6e

Please sign in to comment.