From e3e7c3a8fed1a50c11a0f287871dd66ec6fca898 Mon Sep 17 00:00:00 2001 From: Daniel Silhavy Date: Mon, 13 Jan 2025 09:37:31 +0100 Subject: [PATCH] Fix custom ABR demo --- samples/abr/LowestBitrateRule.js | 13 +++--- samples/abr/custom-abr-rules.html | 44 ++++++++++--------- test/unit/mocks/AbrControllerMock.js | 15 ------- .../test/streaming/streaming.MediaPlayer.js | 2 +- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/samples/abr/LowestBitrateRule.js b/samples/abr/LowestBitrateRule.js index 64c51c4969..f88019aefd 100644 --- a/samples/abr/LowestBitrateRule.js +++ b/samples/abr/LowestBitrateRule.js @@ -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; @@ -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; diff --git a/samples/abr/custom-abr-rules.html b/samples/abr/custom-abr-rules.html index c2642f8802..bf3d0ddeed 100644 --- a/samples/abr/custom-abr-rules.html +++ b/samples/abr/custom-abr-rules.html @@ -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 + } } } } diff --git a/test/unit/mocks/AbrControllerMock.js b/test/unit/mocks/AbrControllerMock.js index 3b8122d622..580e739cf9 100644 --- a/test/unit/mocks/AbrControllerMock.js +++ b/test/unit/mocks/AbrControllerMock.js @@ -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] || {}; diff --git a/test/unit/test/streaming/streaming.MediaPlayer.js b/test/unit/test/streaming/streaming.MediaPlayer.js index 3b8a09493b..5fe5e84de8 100644 --- a/test/unit/test/streaming/streaming.MediaPlayer.js +++ b/test/unit/test/streaming/streaming.MediaPlayer.js @@ -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); });