Skip to content

Commit

Permalink
feat: Progress toward FairPlay DRM w/ MSE (#3347)
Browse files Browse the repository at this point in the history
Related to: #3346
  • Loading branch information
Álvaro Velad Galván authored and ismena committed May 17, 2021
1 parent 02a0fbf commit 31ba8d3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 20 deletions.
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ shakaDemo.Main = class {
shakaDemo.Main.commonDrmSystems = [
'com.widevine.alpha',
'com.microsoft.playready',
'com.apple.fps.1_0',
'com.apple.fps',
'com.adobe.primetime',
'org.w3.clearkey',
];
Expand Down
19 changes: 19 additions & 0 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,17 @@ shaka.media.DrmEngine = class {
return false;
}

/**
* @param {?string} keySystem
* @return {boolean} */
static isFairPlayKeySystem(keySystem) {
if (keySystem) {
return !!keySystem.match(/^com\.apple\.fps/);
}

return false;
}

/**
* Check if DrmEngine (as initialized) will likely be able to support the
* given content type.
Expand Down Expand Up @@ -789,6 +800,14 @@ shaka.media.DrmEngine = class {
];
}

// FairPlay does not support distinctiveIdentifier, persistentState
// and also only supports temporary sessions.
if (shaka.media.DrmEngine.isFairPlayKeySystem(info.keySystem)) {
config.distinctiveIdentifier = 'not-allowed';
config.persistentState = 'not-allowed';
config.sessionTypes = ['temporary'];
}

if (info.distinctiveIdentifierRequired) {
config.distinctiveIdentifier = 'required';
}
Expand Down
55 changes: 36 additions & 19 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,24 +1142,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
if (!mimeType) {
// Try using the uri extension.
const extension = shaka.media.ManifestParser.getExtension(uri);
mimeType = {
'mp4': 'video/mp4',
'm4v': 'video/mp4',
'm4a': 'audio/mp4',
'webm': 'video/webm',
'weba': 'audio/webm',
'mkv': 'video/webm', // Chromium browsers supports it.
'ts': 'video/mp2t',
'ogv': 'video/ogg',
'ogg': 'audio/ogg',
'mpg': 'video/mpeg',
'mpeg': 'video/mpeg',
'm3u8': 'application/x-mpegurl',
'mp3': 'audio/mpeg',
'aac': 'audio/aac',
'flac': 'audio/flac',
'wav': 'audio/wav',
}[extension];
mimeType = shaka.Player.SRC_EQUAL_EXTENSIONS_TO_MIME_TYPES_[extension];
}

// TODO: The load graph system has a design limitation that requires routing
Expand Down Expand Up @@ -2001,6 +1984,16 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

this.drmEngine_.configure(this.config_.drm);

const uri = has.uri || '';
const extension = shaka.media.ManifestParser.getExtension(uri);
let mimeType = shaka.Player.SRC_EQUAL_EXTENSIONS_TO_MIME_TYPES_[extension];
if (mimeType == 'application/x-mpegurl' && shaka.util.Platform.isApple()) {
mimeType = 'application/vnd.apple.mpegurl';
}
if (!mimeType) {
mimeType = 'video/mp4';
}

// TODO: Instead of feeding DrmEngine with Variants, we should refactor
// DrmEngine so that it takes a minimal config derived from Variants. In
// cases like this one or in removal of stored content, the details are
Expand All @@ -2021,7 +2014,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
createSegmentIndex: () => Promise.resolve(),
segmentIndex: null,
mimeType: wants.mimeType ?
shaka.util.MimeUtils.getBasicType(wants.mimeType) : 'video/mp4',
shaka.util.MimeUtils.getBasicType(wants.mimeType) : mimeType,
codecs: wants.mimeType ?
shaka.util.MimeUtils.getCodecs(wants.mimeType) : '',
encrypted: true,
Expand Down Expand Up @@ -6075,6 +6068,30 @@ shaka.Player.supportPlugins_ = {};
shaka.Player.adManagerFactory_ = null;


/**
* @const {!Object.<string, string>}
* @private
*/
shaka.Player.SRC_EQUAL_EXTENSIONS_TO_MIME_TYPES_ = {
'mp4': 'video/mp4',
'm4v': 'video/mp4',
'm4a': 'audio/mp4',
'webm': 'video/webm',
'weba': 'audio/webm',
'mkv': 'video/webm', // Chromium browsers supports it.
'ts': 'video/mp2t',
'ogv': 'video/ogg',
'ogg': 'audio/ogg',
'mpg': 'video/mpeg',
'mpeg': 'video/mpeg',
'm3u8': 'application/x-mpegurl',
'mp3': 'audio/mpeg',
'aac': 'audio/aac',
'flac': 'audio/flac',
'wav': 'audio/wav',
};


/**
* @const {string}
*/
Expand Down
20 changes: 20 additions & 0 deletions test/media/drm_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,26 @@ function testDrmEngine(useMediaCapabilities) {
});
});

describe('isFairPlayKeySystem', () => {
it('should return true for FairPlay', () => {
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.apple.fps')).toBe(true);
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.apple.fps.1_0')).toBe(true);
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.apple.fps.2_0')).toBe(true);
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.apple.fps.3_0')).toBe(true);
});

it('should return false for non-FairPlay key systems', () => {
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.widevine.alpha')).toBe(false);
expect(shaka.media.DrmEngine.isFairPlayKeySystem(
'com.abc.playready')).toBe(false);
});
});

describe('getDrmInfo', () => {
it('includes correct info', async () => {
// Leave only one drmInfo
Expand Down

0 comments on commit 31ba8d3

Please sign in to comment.