Skip to content

Commit

Permalink
refactor(MediaCap): Remove MediaCapabilities config
Browse files Browse the repository at this point in the history
Remove "useMediaCapabilities" configuration in the code base.

Issue #1391

Change-Id: I5fc74e31666840828e9dc04a5733db3eaed0d21a
  • Loading branch information
michellezhuogg committed May 21, 2021
1 parent 9a706ef commit 9709086
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 822 deletions.
1 change: 0 additions & 1 deletion demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ shakaDemo.MessageIds = {
TRICK_PLAY_CONTROLS_WARNING: 'DEMO_TRICK_PLAY_CONTROLS_WARNING',
UI_LOCALE: 'DEMO_UI_LOCALE',
UPDATE_EXPIRATION_TIME: 'DEMO_UPDATE_EXPIRATION_TIME',
USE_MEDIA_CAPABILITIES: 'DEMO_USE_MEDIA_CAPABILITIES',
USE_NATIVE_HLS_SAFARI: 'DEMO_USE_NATIVE_HLS_SAFARI',
USE_PERSISTENT_LICENSES: 'DEMO_USE_PERSISTENT_LICENSES',
VIDEO_ROBUSTNESS: 'DEMO_VIDEO_ROBUSTNESS',
Expand Down
4 changes: 1 addition & 3 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ shakaDemo.Config = class {
.addBoolInput_(MessageIds.FORCE_HTTPS,
'streaming.forceHTTPS')
.addBoolInput_(MessageIds.PREFER_NATIVE_HLS,
'streaming.preferNativeHls')
.addBoolInput_(MessageIds.USE_MEDIA_CAPABILITIES,
'useMediaCapabilities');
'streaming.preferNativeHls');

if (!shakaDemoMain.getNativeControlsEnabled()) {
this.addBoolInput_(MessageIds.ALWAYS_STREAM_TEXT,
Expand Down
1 change: 0 additions & 1 deletion demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"DEMO_MAX_PIXELS": "Max Pixels",
"DEMO_MAX_SMALL_GAP_SIZE": "Maximum Small Gap Size",
"DEMO_MAX_WIDTH": "Max Width",
"DEMO_USE_MEDIA_CAPABILITIES": "Use MediaCapabilities",
"DEMO_METACDN": "MetaCDN",
"DEMO_MICROSOFT": "Microsoft",
"DEMO_MIME_TYPE": "MIME Type",
Expand Down
4 changes: 0 additions & 4 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@
"description": "The name of a configuration value.",
"message": "Max Width"
},
"DEMO_USE_MEDIA_CAPABILITIES": {
"description": "The name of a configuration value.",
"message": "Use [JARGON:MediaCapabilities]"
},
"DEMO_METACDN": {
"description": "Text that describes an asset that comes from the MetaCDN asset library.",
"message": "[PROPER_NAME:MetaCDN]"
Expand Down
7 changes: 1 addition & 6 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,7 @@ shaka.extern.OfflineConfiguration;
* restrictions: shaka.extern.Restrictions,
* playRangeStart: number,
* playRangeEnd: number,
* textDisplayFactory: shaka.extern.TextDisplayer.Factory,
* useMediaCapabilities: boolean
* textDisplayFactory: shaka.extern.TextDisplayer.Factory
* }}
*
* @property {shaka.extern.DrmConfiguration} drm
Expand Down Expand Up @@ -1045,10 +1044,6 @@ shaka.extern.OfflineConfiguration;
* @property {shaka.extern.TextDisplayer.Factory} textDisplayFactory
* A factory to construct a text displayer. Note that, if this is changed
* during playback, it will cause the text tracks to be reloaded.
* @property {boolean} useMediaCapabilities
* If true, use MediaCapabilities.decodingInfo() to filter the manifest, and
* get MediaKeys information for encrypted content. Default to false.
* Shaka Player's integration with MediaCapabilities is now in BETA.
* @exportDoc
*/
shaka.extern.PlayerConfiguration;
Expand Down
188 changes: 12 additions & 176 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.IDestroyable');
goog.require('shaka.util.Iterables');
goog.require('shaka.util.Lazy');
goog.require('shaka.util.ManifestParserUtils');
goog.require('shaka.util.MapUtils');
goog.require('shaka.util.MimeUtils');
goog.require('shaka.util.Platform');
Expand Down Expand Up @@ -202,10 +201,9 @@ shaka.media.DrmEngine = class {
* @param {boolean} usePersistentLicenses
* Whether or not persistent licenses should be requested and stored for
* |manifest|.
* @param {boolean=} useMediaCapabilities
* @return {!Promise}
*/
initForStorage(variants, usePersistentLicenses, useMediaCapabilities) {
initForStorage(variants, usePersistentLicenses) {
this.initializedForStorage_ = true;
// There are two cases for this call:
// 1. We are about to store a manifest - in that case, there are no offline
Expand All @@ -219,7 +217,7 @@ shaka.media.DrmEngine = class {
// persistent licenses.
this.usePersistentLicenses_ = usePersistentLicenses;

return this.init_(variants, !!useMediaCapabilities);
return this.init_(variants);
}

/**
Expand All @@ -228,14 +226,13 @@ shaka.media.DrmEngine = class {
* @param {!Array.<shaka.extern.Variant>} variants
* The variants that we want to support playing.
* @param {!Array.<string>} offlineSessionIds
* @param {boolean=} useMediaCapabilities
* @return {!Promise}
*/
initForPlayback(variants, offlineSessionIds, useMediaCapabilities) {
initForPlayback(variants, offlineSessionIds) {
this.offlineSessionIds_ = offlineSessionIds;
this.usePersistentLicenses_ = offlineSessionIds.length > 0;

return this.init_(variants, !!useMediaCapabilities);
return this.init_(variants);
}

/**
Expand Down Expand Up @@ -281,8 +278,7 @@ shaka.media.DrmEngine = class {

configsByKeySystem.set(keySystem, config);
return this.queryMediaKeys_(configsByKeySystem,
/* variants= */ [],
/* useMediaCapabilities= */ false);
/* variants= */ []);
}

/**
Expand All @@ -293,11 +289,10 @@ shaka.media.DrmEngine = class {
* @param {!Array.<shaka.extern.Variant>} variants
* The variants that we expect to operate with during the drm engine's
* lifespan of the drm engine.
* @param {boolean} useMediaCapabilities
* @return {!Promise} Resolved if/when a key system has been chosen.
* @private
*/
async init_(variants, useMediaCapabilities) {
async init_(variants) {
goog.asserts.assert(this.config_,
'DrmEngine configure() must be called before init()!');

Expand Down Expand Up @@ -355,13 +350,8 @@ shaka.media.DrmEngine = class {

// We should get the decodingInfo results for the variants after we filling
// in the drm infos, and before queryMediaKeys_().
if (useMediaCapabilities) {
await shaka.util.StreamUtils.getDecodingInfosForVariants(variants,
this.usePersistentLicenses_);
} else {
configsByKeySystem =
this.prepareMediaKeyConfigsForVariants_(variants);
}
await shaka.util.StreamUtils.getDecodingInfosForVariants(variants,
this.usePersistentLicenses_);

const hasDrmInfo = hadDrmInfo || Object.keys(this.config_.servers).length;
// An unencrypted content is initialized.
Expand All @@ -370,8 +360,7 @@ shaka.media.DrmEngine = class {
return Promise.resolve();
}

const p = this.queryMediaKeys_(configsByKeySystem, variants,
useMediaCapabilities);
const p = this.queryMediaKeys_(configsByKeySystem, variants);

// TODO(vaage): Look into the assertion below. If we do not have any drm
// info, we create drm info so that content can play if it has drm info
Expand Down Expand Up @@ -743,158 +732,6 @@ shaka.media.DrmEngine = class {
return shaka.util.MapUtils.asObject(this.announcedKeyStatusByKeyId_);
}

/**
* @param {!Array.<shaka.extern.Variant>} variants
* @see https://bit.ly/EmeConfig for MediaKeySystemConfiguration spec
* @return {!Map.<string, MediaKeySystemConfiguration>}
* @private
*/
prepareMediaKeyConfigsForVariants_(variants) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;

// Get all the drm info so that we can avoid using nested loops when we just
// need the drm info.
const allDrmInfo = new Set();
for (const variant of variants) {
const drmInfos = this.getVariantDrmInfos_(variant);
for (const info of drmInfos) {
allDrmInfo.add(info);
}
}

// Make sure all the drm infos are valid and filled in correctly.
for (const info of allDrmInfo) {
shaka.media.DrmEngine.fillInDrmInfoDefaults_(
info,
shaka.util.MapUtils.asMap(this.config_.servers),
shaka.util.MapUtils.asMap(this.config_.advanced || {}));
}

const persistentState =
this.usePersistentLicenses_ ? 'required' : 'optional';
const sessionTypes =
this.usePersistentLicenses_ ? ['persistent-license'] : ['temporary'];

const configs = new Map();

// Create a config entry for each key system.
for (const info of allDrmInfo) {
const config = {
initDataTypes: ['cenc'],
audioCapabilities: [],
videoCapabilities: [],
distinctiveIdentifier: 'optional',
persistentState: persistentState,
sessionTypes: sessionTypes,
label: info.keySystem, // Tracked by us, ignored by EME.
};
// TODO: refactor, don't stick drmInfos onto MediaKeySystemConfiguration
config['drmInfos'] = []; // Non-standard attribute, ignored by EME.

// Multiple calls to |set| will still respect the insertion order of the
// first call to |set| for a given key.
configs.set(info.keySystem, config);
}

// Connect each key system with each stream using it.
for (const variant of variants) {
/** @type {?shaka.extern.Stream} */
const audio = variant.audio;
/** @type {?shaka.extern.Stream} */
const video = variant.video;

// Add the last bit of information to each config;
for (const stream of [audio, video]) {
if (!stream) {
continue;
}

const mimeType = shaka.media.DrmEngine.computeMimeType_(stream);
let fallbackMimeType = null;

if (stream.codecs.toLowerCase() == 'ac-3' &&
shaka.util.Platform.isTizen()) {
// Some Tizen devices seem to misreport AC-3 support, but correctly
// report EC-3 support. So query EC-3 as a fallback for AC-3.
// See https://github.com/google/shaka-player/issues/2989 for details.
fallbackMimeType = shaka.media.DrmEngine.computeMimeType_(stream,
'ec-3');
}

for (const info of stream.drmInfos) {
const config = configs.get(info.keySystem);
goog.asserts.assert(
config,
'Any missing configs should have be filled in before.');

// TODO: refactor, don't stick drmInfos onto
// MediaKeySystemConfiguration
config['drmInfos'].push(info);

if (info.initData && info.initData.length) {
config.initDataTypes = [
...new Set(
info.initData.map((initData) => initData.initDataType)),
];
}

// 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';
}

if (info.persistentStateRequired) {
config.persistentState = 'required';
}

if (info.sessionType) {
config.sessionTypes = [info.sessionType];
}

const robustness = (stream.type == ContentType.AUDIO) ?
info.audioRobustness : info.videoRobustness;

/** @type {MediaKeySystemMediaCapability} */
const capability = {
robustness: robustness || '',
contentType: mimeType,
};

if (stream.type == ContentType.AUDIO) {
config.audioCapabilities.push(capability);
} else {
config.videoCapabilities.push(capability);
}

// This is how we work around some misbehaving platforms by adding
// synthetic capability records using a fallback MIME type.
if (fallbackMimeType) {
/** @type {MediaKeySystemMediaCapability} */
const fallbackCapability = {
robustness: robustness || '',
contentType: fallbackMimeType,
};

if (stream.type == ContentType.AUDIO) {
config.audioCapabilities.push(fallbackCapability);
} else {
config.videoCapabilities.push(fallbackCapability);
}
}
} // for (const info of stream.drmInfos)
} // for (const stream of [audio, video])
} // for (const variant of variants)

return configs;
}

/**
* @param {shaka.extern.Stream} stream
* @param {string=} codecOverride
Expand All @@ -917,14 +754,13 @@ shaka.media.DrmEngine = class {
* A dictionary of configs, indexed by key system, with an iteration order
* (insertion order) that reflects the preference for the application.
* @param {!Array.<shaka.extern.Variant>} variants
* @param {boolean} useMediaCapabilities
* @return {!Promise} Resolved if/when a key system has been chosen.
* @private
*/
async queryMediaKeys_(configsByKeySystem, variants, useMediaCapabilities) {
async queryMediaKeys_(configsByKeySystem, variants) {
const drmInfosByKeySystem = new Map();

const mediaKeySystemAccess = useMediaCapabilities ?
const mediaKeySystemAccess = variants.length ?
this.getKeySystemAccessFromVariants_(variants, drmInfosByKeySystem) :
await this.getKeySystemAccessByConfigs_(configsByKeySystem);

Expand Down Expand Up @@ -963,7 +799,7 @@ shaka.media.DrmEngine = class {
goog.asserts.assert(this.supportedTypes_.size,
'We should get at least one supported MIME type');

if (useMediaCapabilities) {
if (variants.length) {
this.currentDrmInfo_ = this.createDrmInfoByInfos_(
mediaKeySystemAccess.keySystem,
drmInfosByKeySystem.get(mediaKeySystemAccess.keySystem));
Expand Down
18 changes: 5 additions & 13 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,10 @@ shaka.offline.Storage = class {
const maxHwRes = {width: Infinity, height: Infinity};
StreamUtils.filterByRestrictions(manifest, config.restrictions, maxHwRes);

// Filter the manifest based on what we know media source will be able to
// play later (no point storing something we can't play).
if (config.useMediaCapabilities) {
StreamUtils.filterManifestByMediaCapabilities(
manifest, config.offline.usePersistentLicense);
} else {
StreamUtils.filterManifestByMediaSource(manifest);
// Filter the manifest based on what we know our drm system will support
// playing later.
StreamUtils.filterManifestByDrm(manifest, drmEngine);
}
// Filter the manifest based on what we know MediaCapabilities will be able
// to play later (no point storing something we can't play).
StreamUtils.filterManifestByMediaCapabilities(
manifest, config.offline.usePersistentLicense);

// Gather all tracks.
const allTracks = [];
Expand Down Expand Up @@ -1006,8 +999,7 @@ shaka.offline.Storage = class {

drmEngine.configure(config.drm);
await drmEngine.initForStorage(
manifest.variants, config.offline.usePersistentLicense,
config.useMediaCapabilities);
manifest.variants, config.offline.usePersistentLicense);
await drmEngine.setServerCertificate();
await drmEngine.createOrLoad();

Expand Down
11 changes: 2 additions & 9 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1725,17 +1725,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
},
});

// TODO: remove once MediaCap implementation is complete.
if (!this.config_.useMediaCapabilities) {
shaka.util.StreamUtils.filterManifestByMediaSource(this.manifest_);
}

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

await this.drmEngine_.initForPlayback(
this.manifest_.variants,
this.manifest_.offlineSessionIds,
this.config_.useMediaCapabilities);
this.manifest_.offlineSessionIds);

await this.drmEngine_.attach(has.mediaElement);

Expand Down Expand Up @@ -4642,8 +4636,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.streamingEngine_.getCurrentVariant() : null;

await shaka.util.StreamUtils.filterManifest(
this.drmEngine_, currentVariant, manifest,
this.config_.useMediaCapabilities);
this.drmEngine_, currentVariant, manifest);
this.checkPlayableVariants_(manifest);
}

Expand Down
Loading

0 comments on commit 9709086

Please sign in to comment.