Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FairPlay DRM updates #3347

Merged
merged 11 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,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 @@ -591,6 +591,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 @@ -788,6 +799,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 @@ -1140,24 +1140,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 @@ -1998,6 +1981,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 @@ -2017,7 +2010,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
originalId: null,
createSegmentIndex: () => Promise.resolve(),
segmentIndex: null,
mimeType: 'video/mp4',
mimeType: mimeType,
codecs: '',
encrypted: true,
drmInfos: [], // Filled in by DrmEngine config.
Expand Down Expand Up @@ -6039,6 +6032,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