Skip to content

Commit

Permalink
Only change streams if restricted on keystatuschange
Browse files Browse the repository at this point in the history
b/36094412

Change-Id: I423089f00c0619d43dbc8ce647b2410cf3b15f92
  • Loading branch information
TheModMaker committed Mar 9, 2017
1 parent 2356e55 commit 21c6420
Show file tree
Hide file tree
Showing 2 changed files with 41 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 @@ -2291,6 +2291,7 @@ shaka.Player.prototype.onVideoError_ = function(event) {
* @private
*/
shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) {
var ContentType = shaka.util.ManifestParserUtils.ContentType;
goog.asserts.assert(this.streamingEngine_, 'Should have been initialized.');
// 'usable', 'released', 'output-downscaled', 'status-pending' are statuses
// of the usable keys.
Expand Down Expand Up @@ -2320,8 +2321,14 @@ shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) {
});
});

shaka.log.debug('Choosing new streams after key status changed');
this.chooseStreamsAndSwitch_(period);
var activeStreams = this.streamingEngine_.getActiveStreams();
var activeVariant = shaka.util.StreamUtils.getVariantByStreams(
activeStreams[ContentType.AUDIO], activeStreams[ContentType.VIDEO],
period.variants);
if (activeVariant && !activeVariant.allowedByKeySystem) {
shaka.log.debug('Choosing new streams after key status changed');
this.chooseStreamsAndSwitch_(period);
}

if (tracksChanged)
this.onTracksChanged_();
Expand Down
32 changes: 32 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,38 @@ describe('Player', function() {
}).then(done);
});

it('doesn\'t switch if the active stream isn\'t restricted',
function(done) {
manifest = new shaka.test.ManifestGenerator()
.addPeriod(0)
.addVariant(0)
.addVideo(1).keyId('abc')
.addVariant(1)
.addVideo(2)
.build();

parser = new shaka.test.FakeManifestParser(manifest);
factory = function() { return parser; };
player.load('', 0, factory)
.then(function() {
// "initialize" the current period.
chooseStreams();
canSwitch();
abrManager.chooseStreams.calls.reset();

var activeVariant = getActiveTrack('variant');
expect(activeVariant.id).toBe(0);

onKeyStatus({'abc': 'usable'});
expect(abrManager.chooseStreams).not.toHaveBeenCalled();

activeVariant = getActiveTrack('variant');
expect(activeVariant.id).toBe(0);
})
.catch(fail)
.then(done);
});

it('removes if key status is "output-restricted"', function(done) {
manifest = new shaka.test.ManifestGenerator()
.addPeriod(0)
Expand Down

0 comments on commit 21c6420

Please sign in to comment.