Skip to content

Commit 7eecf48

Browse files
committed
Add a limitBitrateByPortalMinimum setting to prevent limiting too much
1 parent e47eff9 commit 7eecf48

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,7 @@ export class MediaPlayerSettingClass {
18391839
abr?: {
18401840
limitBitrateByPortal?: boolean;
18411841
usePixelRatioInLimitBitrateByPortal?: boolean;
1842+
limitBitrateByPortalMinimum?: number,
18421843
enableSupplementalPropertyAdaptationSetSwitching?: boolean,
18431844
rules?: {
18441845
throughputRule?: {

src/core/Settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ import SwitchRequest from '../streaming/rules/SwitchRequest.js';
746746
* If true, the size of the video portal will limit the max chosen video resolution.
747747
* @property {boolean} [usePixelRatioInLimitBitrateByPortal=false]
748748
* Sets whether to take into account the device's pixel ratio when defining the portal dimensions.
749+
* @property {number} [limitBitrateByPortalMinimum=0]
750+
* Sets a minimum bitrate in kbps for limitBitrateByPortal. Representations at this bitrate or below it will not be limited by the portal size. Useful if the player can be resized.
749751
*
750752
* Useful on, for example, retina displays.
751753
* @property {module:Settings~AbrRules} [rules]
@@ -1324,6 +1326,7 @@ function Settings() {
13241326
abr: {
13251327
limitBitrateByPortal: false,
13261328
usePixelRatioInLimitBitrateByPortal: false,
1329+
limitBitrateByPortalMinimum: 0,
13271330
enableSupplementalPropertyAdaptationSetSwitching: true,
13281331
rules: {
13291332
throughputRule: {

src/streaming/controllers/AbrController.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,13 @@ function AbrController() {
400400
if (!settings.get().streaming.abr.limitBitrateByPortal) {
401401
return voRepresentations;
402402
}
403+
const minimum = (settings.get().streaming.abr.limitBitrateByPortalMinimum * 1000) || 0;
403404

404405
const { elementWidth } = videoModel.getVideoElementSize();
405406

406407
const filteredArray = voRepresentations.filter((voRepresentation) => {
407-
return voRepresentation.mediaInfo.type !== Constants.VIDEO || voRepresentation.width <= elementWidth;
408-
})
408+
return voRepresentation.mediaInfo.type !== Constants.VIDEO || voRepresentation.width <= elementWidth || voRepresentation.bandwidth <= minimum;
409+
});
409410

410411
if (filteredArray.length > 0) {
411412
return filteredArray

test/unit/test/streaming/streaming.controllers.AbrController.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,5 +936,61 @@ describe('AbrController', function () {
936936
let possibleVoRepresentations = abrCtrl.getPossibleVoRepresentationsFilteredBySettings(mediaInfo);
937937
expect(possibleVoRepresentations.length).to.be.equal(2);
938938
});
939-
})
939+
940+
it('should allow representations with a bandwidth below limitBitrateByPortalMinimum', function () {
941+
videoModelMock.getVideoElementSize = () => {
942+
return { elementWidth: 200 }
943+
};
944+
const s = {
945+
streaming: {
946+
abr: {
947+
limitBitrateByPortal: true,
948+
limitBitrateByPortalMinimum: 2100
949+
}
950+
}
951+
};
952+
settings.update(s);
953+
954+
const mediaInfo = streamProcessor.getMediaInfo();
955+
const bitrateList = mediaInfo.bitrateList;
956+
957+
adapterMock.getVoRepresentations = () => {
958+
return [
959+
{
960+
bitrateInKbit: bitrateList[0].bandwidth / 1000,
961+
bandwidth: 1000000,
962+
mediaInfo,
963+
id: 1,
964+
width: 640
965+
},
966+
{
967+
bitrateInKbit: bitrateList[1].bandwidth / 1000,
968+
bandwidth: 2000000,
969+
mediaInfo,
970+
id: 2,
971+
width: 720
972+
},
973+
{
974+
bitrateInKbit: bitrateList[2].bandwidth / 1000,
975+
bandwidth: 3000000,
976+
mediaInfo,
977+
id: 3,
978+
width: 1920
979+
}
980+
]
981+
}
982+
983+
adapterMock.areMediaInfosEqual = () => {
984+
return true
985+
}
986+
987+
mediaInfo.streamInfo = streamProcessor.getStreamInfo();
988+
mediaInfo.type = Constants.VIDEO;
989+
990+
let possibleVoRepresentations = abrCtrl.getPossibleVoRepresentationsFilteredBySettings(mediaInfo);
991+
expect(possibleVoRepresentations.length).to.be.equal(2);
992+
expect(possibleVoRepresentations[0].id).to.be.equal(1);
993+
expect(possibleVoRepresentations[1].id).to.be.equal(2);
994+
});
995+
});
940996
});

0 commit comments

Comments
 (0)