Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for average throughput on MediaPlayer's API #2039

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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