Skip to content

Commit

Permalink
Apply restrictions to AbrManager in configure().
Browse files Browse the repository at this point in the history
Closes #1533

Change-Id: I58de78bdcee4d3b049b5f2db53fce38ad72e1ded
  • Loading branch information
TheModMaker committed Sep 10, 2018
1 parent ea9702b commit d133f86
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,15 @@ shaka.Player.prototype.applyConfig_ = function() {
let period = this.streamingEngine_.getCurrentPeriod();
let activeVariant = shaka.util.StreamUtils.getVariantByStreams(
activeAudio, activeVideo, period.variants);
if (!activeVariant || !activeVariant.allowedByApplication ||
!activeVariant.allowedByKeySystem) {
if (this.abrManager_ && activeVariant &&
activeVariant.allowedByApplication &&
activeVariant.allowedByKeySystem) {
// Update AbrManager variants to match these new settings.
const variants = shaka.util.StreamUtils.filterVariantsByPreference(
period.variants, this.currentAudioLanguage_, this.currentVariantRole_,
this.currentAudioChannelCount_);
this.abrManager_.setVariants(variants);
} else {
shaka.log.debug('Choosing new streams after changing configuration');
this.chooseStreamsAndSwitch_(period);
}
Expand Down
30 changes: 30 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,36 @@ describe('Player', function() {
expect(activeVariant.id).toBe(1);
});

it('updates AbrManager for restriction changes', async () => {
manifest = new shaka.test.ManifestGenerator()
.addPeriod(0)
.addVariant(1).bandwidth(500)
.addVideo(10)
.addVariant(2).bandwidth(100)
.addVideo(20)
.build();

await setupPlayer();
abrManager.setVariants.calls.reset();

player.configure({restrictions: {maxBandwidth: 200}});

// AbrManager should have been updated with the restricted tracks.
// The first variant is disallowed.
expect(abrManager.setVariants).toHaveBeenCalledTimes(1);
const variants = abrManager.setVariants.calls.argsFor(0)[0];
expect(variants.length).toBe(1);
expect(variants[0].id).toBe(2);

// Now increase the restriction, AbrManager should still be updated.
// https://github.com/google/shaka-player/issues/1533
abrManager.setVariants.calls.reset();
player.configure({restrictions: {maxBandwidth: Infinity}});
expect(abrManager.setVariants).toHaveBeenCalledTimes(1);
const newVariants = abrManager.setVariants.calls.argsFor(0)[0];
expect(newVariants.length).toBe(2);
});

it('switches if active key status is "output-restricted"', async () => {
manifest = new shaka.test.ManifestGenerator()
.addPeriod(0)
Expand Down

0 comments on commit d133f86

Please sign in to comment.