Skip to content

Commit

Permalink
Fix custom ABR demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Jan 13, 2025
1 parent a6f9f21 commit e3e7c3a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
13 changes: 6 additions & 7 deletions samples/abr/LowestBitrateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function LowestBitrateRuleClass() {
let factory = dashjs.FactoryMaker;
let SwitchRequest = factory.getClassFactoryByName('SwitchRequest');
let MetricsModel = factory.getSingletonFactoryByName('MetricsModel');
let StreamController = factory.getSingletonFactoryByName('StreamController');
let context = this.context;
let instance;

Expand All @@ -56,18 +55,18 @@ function LowestBitrateRuleClass() {
console.log(metrics);

// Get current bitrate
let streamController = StreamController(context).getInstance();
let abrController = rulesContext.getAbrController();
let current = abrController.getQualityFor(mediaType, streamController.getActiveStreamInfo().id);

const abrController = rulesContext.getAbrController();
const representation = rulesContext.getRepresentation();
// If already in lowest bitrate, don't do anything
if (current === 0) {
if (abrController.isPlayingAtLowestQuality(representation)) {
return SwitchRequest(context).create();
}

// Ask to switch to the lowest bitrate
const mediaInfo = rulesContext.getMediaInfo();
const newRepresentation = abrController.getOptimalRepresentationForBitrate(mediaInfo, 0, true);
let switchRequest = SwitchRequest(context).create();
switchRequest.quality = 0;
switchRequest.representation = newRepresentation;
switchRequest.reason = 'Always switching to the lowest bitrate';
switchRequest.priority = SwitchRequest.PRIORITY.STRONG;
return switchRequest;
Expand Down
44 changes: 23 additions & 21 deletions samples/abr/custom-abr-rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@
function init() {
var video,
player,
url = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
url = 'https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd';

video = document.querySelector("video");
video = document.querySelector('video');
player = dashjs.MediaPlayer().create();

/* don't use dash.js default rules */
player.updateSettings({
abr: {
activeRules: {
throughputRule: {
active: false
},
bolaRule: {
active: false
},
insufficientBufferRule: {
active: false
},
switchHistoryRule: {
active: false
},
droppedFramesRule: {
active: false
},
abandonRequestsRule: {
active: false
streaming: {
abr: {
rules: {
throughputRule: {
active: false
},
bolaRule: {
active: false
},
insufficientBufferRule: {
active: false
},
switchHistoryRule: {
active: false
},
droppedFramesRule: {
active: false
},
abandonRequestsRule: {
active: false
}
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions test/unit/mocks/AbrControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,6 @@ function AbrControllerMock () {

this.isPlayingAtTopQuality = function () {};

this.getQualityFor = function (type) {
var quality;

if (!this.currentStreamId || !this.qualityDict.hasOwnProperty(this.currentStreamId)) {
return QUALITY_DEFAULT;
}

if (!this.qualityDict[this.currentStreamId].hasOwnProperty(type)) {
return QUALITY_DEFAULT;
}

quality = this.qualityDict[this.currentStreamId][type];
return quality;
};

this.setQualityFor = function (type, id, value) {
this.currentStreamId = id;
this.qualityDict[id] = this.qualityDict[id] || {};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test/streaming/streaming.MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ describe('MediaPlayer', function () {
});

describe('When it is not initialized', function () {
it('Method getQualityFor should throw an exception', function () {
it('Method getCurrentRepresentationForType should throw an exception', function () {
expect(player.getCurrentRepresentationForType).to.throw(STREAMING_NOT_INITIALIZED_ERROR);
});

Expand Down

0 comments on commit e3e7c3a

Please sign in to comment.