Skip to content

Commit

Permalink
Fix handling of internal-error key status.
Browse files Browse the repository at this point in the history
Closes #539.

Change-Id: I3ff30167034b4aed2bd390fc901e9466f6dd12c6
  • Loading branch information
ismena committed Oct 6, 2016
1 parent 91da191 commit fade7d2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 65 deletions.
8 changes: 1 addition & 7 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ shaka.media.DrmEngine.prototype.onKeyStatusesChange_ = function(event) {
status = 'usable';
}

if (status != 'status-pending' && status != 'internal-error') {
if (status != 'status-pending') {
this.activeSessions_[i].loaded = true;
if (this.activeSessions_.every(function(s) { return s.loaded; }))
this.allSessionsLoaded_.resolve();
Expand All @@ -1115,12 +1115,6 @@ shaka.media.DrmEngine.prototype.onKeyStatusesChange_ = function(event) {

var keyIdHex = shaka.util.Uint8ArrayUtils.toHex(new Uint8Array(keyId));

if (status == 'internal-error') {
this.onError_(new shaka.util.Error(
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.INTERNAL_ERROR_KEY_STATUS, keyIdHex));
}

this.keyStatusByKeyId_[keyIdHex] = status;
}.bind(this));

Expand Down
7 changes: 3 additions & 4 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1752,9 +1752,8 @@ shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) {
goog.asserts.assert(this.streamingEngine_, 'Should have been initialized.');
// 'usable', 'released', 'output-downscaled', 'status-pending' are statuses
// of the usable keys.
// 'expired' and 'internal-error' are error statuses which are being handled
// separately in DrmEngine.
var restrictedStatus = 'output-restricted';
// 'expired' status is being handled separately in DrmEngine.
var restrictedStatuses = ['output-restricted', 'internal-error'];

var period = this.streamingEngine_.getCurrentPeriod();
var tracksChanged = false;
Expand All @@ -1766,7 +1765,7 @@ shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) {
// Only update the status if it is in the map.
if (stream.keyId && stream.keyId in keyStatusMap) {
var keyStatus = keyStatusMap[stream.keyId];
stream.allowedByKeySystem = keyStatus != restrictedStatus;
stream.allowedByKeySystem = restrictedStatuses.indexOf(keyStatus) < 0;
}

if (originalAllowed != stream.allowedByKeySystem) {
Expand Down
7 changes: 0 additions & 7 deletions lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,6 @@ shaka.util.Error.Code = {
*/
'RESTRICTIONS_CANNOT_BE_MET': 4012,

/**
* A key has a status of 'internal-error'. Must be a problem on the
* application side.
* <br> error.data[0] is an id of the key.
*/
'INTERNAL_ERROR_KEY_STATUS': 4013,


/**
* The StreamingEngine called onChooseStreams() but the callback receiver
Expand Down
45 changes: 0 additions & 45 deletions test/media/drm_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,51 +920,6 @@ describe('DrmEngine', function() {
}).catch(fail);
});

it('internal-error key status causes an INTERNAL_ERROR_KEY_STATUS error',
function(done) {
onErrorSpy.and.stub();

initAndAttach().then(function() {
expect(onErrorSpy).not.toHaveBeenCalled();

var initData = new Uint8Array(0);
mockVideo.on['encrypted'](
{ initDataType: 'webm', initData: initData });

var keyId1 = (new Uint8Array(1)).buffer;
var keyId2 = (new Uint8Array(2)).buffer;
var keyId3 = (new Uint8Array(3)).buffer;

session1.keyStatuses.forEach.and.callFake(function(callback) {
callback(keyId1, 'internal-error');
callback(keyId2, 'internal-error');
callback(keyId3, 'usable');
});

onKeyStatusSpy.and.callFake(function(statusMap) {
expect(onErrorSpy).toHaveBeenCalled();
// There should be as many errors as the key ids
// with 'internal-error' status. Two in this case
expect(onErrorSpy.calls.count()).toEqual(2);
var errorKey1 = onErrorSpy.calls.argsFor(0)[0];
shaka.test.Util.expectToEqualError(
errorKey1, new shaka.util.Error(
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.INTERNAL_ERROR_KEY_STATUS,
shaka.util.Uint8ArrayUtils.toHex(new Uint8Array(keyId1))));
var errorKey2 = onErrorSpy.calls.argsFor(1)[0];
shaka.test.Util.expectToEqualError(
errorKey2, new shaka.util.Error(
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.INTERNAL_ERROR_KEY_STATUS,
shaka.util.Uint8ArrayUtils.toHex(new Uint8Array(keyId2))));
done();
});

session1.on['keystatuseschange']({ target: session1 });
}).catch(fail);
});

it('causes only one error when two keys expire at once', function(done) {
onErrorSpy.and.stub();

Expand Down
32 changes: 30 additions & 2 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ describe('Player', function() {
expect(activeVideo.id).toBe(5);
});

it('switches if active is restricted by key status', function() {
it('switches if active key status is "output-restricted"', function() {
var activeVideo = getActiveTrack('video');
expect(activeVideo.id).toBe(4);

Expand All @@ -1214,7 +1214,25 @@ describe('Player', function() {
expect(activeVideo.id).toBe(5);
});

it('removes based on key status', function() {
it('switches if active key status is "internal-error"', function() {
var activeVideo = getActiveTrack('video');
expect(activeVideo.id).toBe(4);

// AbrManager should choose the second track since the first is
// restricted.
abrManager.chooseIndex = 1;
abrManager.chooseStreams.calls.reset();
onKeyStatus({'abc': 'internal-error'});
expect(abrManager.chooseStreams).toHaveBeenCalled();
expect(manifest.periods[0].streamSets[1].streams[0].id).toBe(4);
expect(manifest.periods[0].streamSets[1].streams[0].allowedByKeySystem)
.toBe(false);

activeVideo = getActiveTrack('video');
expect(activeVideo.id).toBe(5);
});

it('removes if key status is "output-restricted"', function() {
expect(player.getTracks().length).toBe(9);

onKeyStatus({'abc': 'output-restricted'});
Expand All @@ -1224,6 +1242,16 @@ describe('Player', function() {
expectDoesNotInclude(tracks, 4);
});

it('removes if key status is "internal-error"', function() {
expect(player.getTracks().length).toBe(9);

onKeyStatus({'abc': 'internal-error'});

var tracks = player.getTracks();
expect(tracks.length).toBe(8);
expectDoesNotInclude(tracks, 4);
});

it('removes if key system does not support codec', function() {
// Should already be removed from filterPeriod_
var tracks = player.getTracks();
Expand Down

0 comments on commit fade7d2

Please sign in to comment.