Skip to content

Commit

Permalink
feat(FEC-8700): add config option to specify DRM system (#70)
Browse files Browse the repository at this point in the history
Consider `drm.keySystem` config which specify the drm system to run with. 
Depends on kaltura/playkit-js#330
  • Loading branch information
yairans authored Dec 20, 2018
1 parent d6fa901 commit 5a7e528
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"access": "public"
},
"devDependencies": {
"@playkit-js/playkit-js": "^0.37.0",
"@playkit-js/playkit-js": "^0.44.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
Expand Down Expand Up @@ -77,7 +77,7 @@
"webpack-dev-server": "latest"
},
"peerDependencies": {
"@playkit-js/playkit-js": "^0.37.0",
"@playkit-js/playkit-js": "^0.44.0",
"shaka-player": "https://github.com/kaltura/shaka-player.git#v2.3.3-k-3"
},
"keywords": [
Expand Down
14 changes: 12 additions & 2 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,28 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
/**
* Checks if dash adapter can play a given drm data.
* @param {Array<Object>} drmData - The drm data to check.
* @param {PKDrmConfigObject} drmConfig - The drm config.
* @returns {boolean} - Whether the dash adapter can play a specific drm data.
* @static
*/
static canPlayDrm(drmData: Array<Object>): boolean {
static canPlayDrm(drmData: Array<Object>, drmConfig: PKDrmConfigObject): boolean {
let canPlayDrm = false;
for (let drmProtocol of DashAdapter._drmProtocols) {
if (drmProtocol.canPlayDrm(drmData)) {
if (drmProtocol.isConfigured(drmData, drmConfig)) {
DashAdapter._drmProtocol = drmProtocol;
canPlayDrm = true;
break;
}
}
if (!canPlayDrm) {
for (let drmProtocol of DashAdapter._drmProtocols) {
if (drmProtocol.canPlayDrm(drmData)) {
DashAdapter._drmProtocol = drmProtocol;
canPlayDrm = true;
break;
}
}
}
DashAdapter._logger.debug('canPlayDrm result is ' + canPlayDrm.toString(), drmData);
return canPlayDrm;
}
Expand Down
12 changes: 11 additions & 1 deletion src/drm/playready.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ const DrmScheme = BaseDrmProtocol.DrmScheme;
export default class PlayReady extends BaseDrmProtocol {
static _logger = BaseDrmProtocol.getLogger('PlayReady');

/**
* PLAYREADY is the configure key system.
* @param {Array<Object>} drmData - The drm data.
* @param {PKDrmConfigObject} drmConfig - The drm config.
* @return {boolean} - Whether PLAYREADY is the configure key system.
*/
static isConfigured(drmData: Array<Object>, drmConfig: PKDrmConfigObject): boolean {
return DrmScheme.PLAYREADY === drmConfig.keySystem && !!drmData.find(drmEntry => drmEntry.scheme === drmConfig.keySystem);
}

/**
* PlayReady playback supports in case 2 conditions are met:
* 1. The environment supports PlayReady playback.
* 2. The drm data of the source object contains entry with PlayReady scheme.
* @param {Array<Object>} drmData - The drm data to check.
* @return {boolean} - Whether FairPlay can be play on the current environment.
* @return {boolean} - Whether PlayReady can be play on the current environment.
*/
static canPlayDrm(drmData: Array<Object>): boolean {
PlayReady._logger.debug('Can play DRM scheme of: ' + DrmScheme.PLAYREADY);
Expand Down
12 changes: 11 additions & 1 deletion src/drm/widevine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ const DrmScheme = BaseDrmProtocol.DrmScheme;
export default class Widevine extends BaseDrmProtocol {
static _logger = BaseDrmProtocol.getLogger('Widevine');

/**
* Widevine is the configure key system.
* @param {Array<Object>} drmData - The drm data.
* @param {PKDrmConfigObject} drmConfig - The drm config.
* @return {boolean} - Whether Widevine is the configure key system.
*/
static isConfigured(drmData: Array<Object>, drmConfig: PKDrmConfigObject): boolean {
return DrmScheme.WIDEVINE === drmConfig.keySystem && !!drmData.find(drmEntry => drmEntry.scheme === drmConfig.keySystem);
}

/**
* Widevine playback supports in case 2 conditions are met:
* 1. The environment supports Widevine playback.
* 2. The drm data of the source object contains entry with Widevine scheme.
* @param {Array<Object>} drmData - The drm data to check.
* @return {boolean} - Whether FairPlay can be play on the current environment.
* @return {boolean} - Whether Widevine can be play on the current environment.
*/
static canPlayDrm(drmData: Array<Object>): boolean {
Widevine._logger.debug('Can play DRM scheme of: ' + DrmScheme.WIDEVINE);
Expand Down
24 changes: 24 additions & 0 deletions test/src/dash-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,48 @@ describe('DashAdapter: canPlayDrm', () => {

it('should return true since widevine can play drm', function() {
sandbox.stub(Widevine, 'canPlayDrm').value(() => true);
sandbox.stub(Widevine, 'isConfigured').value(() => false);
sandbox.stub(PlayReady, 'canPlayDrm').value(() => false);
sandbox.stub(PlayReady, 'isConfigured').value(() => false);
DashAdapter.canPlayDrm().should.be.true;
DashAdapter._drmProtocol.should.equal(Widevine);
});

it('should return true since playready can play drm', function() {
sandbox.stub(Widevine, 'canPlayDrm').value(() => false);
sandbox.stub(Widevine, 'isConfigured').value(() => false);
sandbox.stub(PlayReady, 'canPlayDrm').value(() => true);
sandbox.stub(PlayReady, 'isConfigured').value(() => false);
DashAdapter.canPlayDrm().should.be.true;
DashAdapter._drmProtocol.should.equal(PlayReady);
});

it('should return false since no drm can be played', function() {
sandbox.stub(Widevine, 'canPlayDrm').value(() => false);
sandbox.stub(Widevine, 'isConfigured').value(() => false);
sandbox.stub(PlayReady, 'canPlayDrm').value(() => false);
sandbox.stub(PlayReady, 'isConfigured').value(() => false);
DashAdapter.canPlayDrm().should.be.false;
(DashAdapter._drmProtocol === null).should.be.true;
});

it('should return true even playready can be played since widevine configured', function() {
sandbox.stub(Widevine, 'isConfigured').value(() => true);
sandbox.stub(Widevine, 'canPlayDrm').value(() => false);
sandbox.stub(PlayReady, 'isConfigured').value(() => false);
sandbox.stub(PlayReady, 'canPlayDrm').value(() => true);
DashAdapter.canPlayDrm().should.be.true;
DashAdapter._drmProtocol.should.equal(Widevine);
});

it('should return true even widevine can be played since playready configured', function() {
sandbox.stub(Widevine, 'isConfigured').value(() => false);
sandbox.stub(Widevine, 'canPlayDrm').value(() => true);
sandbox.stub(PlayReady, 'isConfigured').value(() => true);
sandbox.stub(PlayReady, 'canPlayDrm').value(() => false);
DashAdapter.canPlayDrm().should.be.true;
DashAdapter._drmProtocol.should.equal(PlayReady);
});
});

describe('DashAdapter: canPlayType', () => {
Expand Down
14 changes: 14 additions & 0 deletions test/src/drm/playready.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ function isValidEnvForPlayReady() {
}

describe('PlayReady', function() {
describe('isConfigured', function() {
it('should return true for playready data if configured', function() {
PlayReady.isConfigured(prDrmData, {keySystem: DrmScheme.PLAYREADY}).should.be.true;
});

it('should return false for playready data if not configured', function() {
PlayReady.isConfigured(prDrmData, {keySystem: DrmScheme.WIDEVINE}).should.be.false;
});

it('should return false for non-playready data even configured', function() {
PlayReady.isConfigured(wwDrmData, {keySystem: DrmScheme.PLAYREADY}).should.be.false;
});
});

describe('canPlayDrm', function() {
it('should return true for playready data on valid playready env and false otherwise', function() {
if (isValidEnvForPlayReady()) {
Expand Down
14 changes: 14 additions & 0 deletions test/src/drm/widevine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ function isValidEnvForWidevine() {
}

describe('Widevine', function() {
describe('isConfigured', function() {
it('should return true for widevine data if configured', function() {
Widevine.isConfigured(wwDrmData, {keySystem: DrmScheme.WIDEVINE}).should.be.true;
});

it('should return false for widevine data if not configured', function() {
Widevine.isConfigured(wwDrmData, {keySystem: DrmScheme.PLAYREADY}).should.be.false;
});

it('should return false for non-widevine data even configured', function() {
Widevine.isConfigured(prDrmData, {keySystem: DrmScheme.WIDEVINE}).should.be.false;
});
});

describe('canPlayDrm', function() {
it('should return true for widevine data on valid widevine env and false otherwise', function() {
if (isValidEnvForWidevine()) {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# yarn lockfile v1


"@playkit-js/playkit-js@^0.37.0":
version "0.37.0"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.37.0.tgz#2249594fc04becd4c9bc0a6d171077a0b5d40823"
"@playkit-js/playkit-js@^0.44.0":
version "0.44.0"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.44.0.tgz#ef0aa375c85d630e32b32d93a290676eaa4e4768"
dependencies:
js-logger "^1.3.0"
ua-parser-js "^0.7.13"
Expand Down

0 comments on commit 5a7e528

Please sign in to comment.