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

chore: Move DrmEngine and DrmUtils to drm namespace #7788

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions build/types/core
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
+../../lib/deprecate/enforcer.js
+../../lib/deprecate/version.js

+../../lib/drm/drm_engine.js
+../../lib/drm/drm_utils.js
+../../lib/drm/playready.js

+../../lib/media/adaptation_set.js
+../../lib/media/adaptation_set_criteria.js
+../../lib/media/buffering_observer.js
+../../lib/media/closed_caption_parser.js
+../../lib/media/content_workarounds.js
+../../lib/media/drm_engine.js
+../../lib/media/gap_jumping_controller.js
+../../lib/media/manifest_filterer.js
+../../lib/media/manifest_parser.js
Expand Down Expand Up @@ -82,7 +83,6 @@
+../../lib/util/delayed_tick.js
+../../lib/util/destroyer.js
+../../lib/util/dom_utils.js
+../../lib/util/drm_utils.js
+../../lib/util/ebml_parser.js
+../../lib/util/error.js
+../../lib/util/event_manager.js
Expand Down
46 changes: 23 additions & 23 deletions lib/media/drm_engine.js → lib/drm/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.media.DrmEngine');
goog.provide('shaka.drm.DrmEngine');

goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.drm.DrmUtils');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.Destroyer');
goog.require('shaka.util.DrmUtils');
goog.require('shaka.util.Error');
goog.require('shaka.util.EventManager');
goog.require('shaka.util.FakeEvent');
Expand All @@ -33,12 +33,12 @@ goog.require('shaka.util.Uint8ArrayUtils');


/** @implements {shaka.util.IDestroyable} */
shaka.media.DrmEngine = class {
shaka.drm.DrmEngine = class {
/**
* @param {shaka.media.DrmEngine.PlayerInterface} playerInterface
* @param {shaka.drm.DrmEngine.PlayerInterface} playerInterface
*/
constructor(playerInterface) {
/** @private {?shaka.media.DrmEngine.PlayerInterface} */
/** @private {?shaka.drm.DrmEngine.PlayerInterface} */
this.playerInterface_ = playerInterface;

/** @private {MediaKeys} */
Expand All @@ -64,7 +64,7 @@ shaka.media.DrmEngine = class {

/**
* @private {!Map.<MediaKeySession,
* shaka.media.DrmEngine.SessionMetaData>}
* shaka.drm.DrmEngine.SessionMetaData>}
*/
this.activeSessions_ = new Map();

Expand Down Expand Up @@ -390,7 +390,7 @@ shaka.media.DrmEngine = class {
// systems as possible so that we will be ready.
if (!hadDrmInfo) {
const servers = shaka.util.MapUtils.asMap(this.config_.servers);
shaka.media.DrmEngine.replaceDrmInfo_(variants, servers);
shaka.drm.DrmEngine.replaceDrmInfo_(variants, servers);
}

/** @type {!Set<shaka.extern.DrmInfo>} */
Expand All @@ -403,7 +403,7 @@ shaka.media.DrmEngine = class {
}

for (const info of drmInfos) {
shaka.media.DrmEngine.fillInDrmInfoDefaults_(
shaka.drm.DrmEngine.fillInDrmInfoDefaults_(
info,
shaka.util.MapUtils.asMap(this.config_.servers),
shaka.util.MapUtils.asMap(this.config_.advanced || {}),
Expand Down Expand Up @@ -942,7 +942,7 @@ shaka.media.DrmEngine = class {
this.currentDrmInfo_ = this.createDrmInfoByInfos_(
keySystem, drmInfosByKeySystem.get(keySystem));
} else {
this.currentDrmInfo_ = shaka.media.DrmEngine.createDrmInfoByConfigs_(
this.currentDrmInfo_ = shaka.drm.DrmEngine.createDrmInfoByConfigs_(
keySystem, configsByKeySystem.get(keySystem));
}
if (!this.currentDrmInfo_.licenseServerUri) {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ shaka.media.DrmEngine = class {
* In case there are no key statuses, consider this session loaded
* after a reasonable timeout. It should definitely not take 5
* seconds to process a license.
* @param {!shaka.media.DrmEngine.SessionMetaData} metadata
* @param {!shaka.drm.DrmEngine.SessionMetaData} metadata
* @private
*/
setLoadSessionTimeoutTimer_(metadata) {
Expand All @@ -1200,7 +1200,7 @@ shaka.media.DrmEngine = class {
});

timer.tickAfter(
/* seconds= */ shaka.media.DrmEngine.SESSION_LOAD_TIMEOUT_);
/* seconds= */ shaka.drm.DrmEngine.SESSION_LOAD_TIMEOUT_);
}

/**
Expand Down Expand Up @@ -1462,7 +1462,7 @@ shaka.media.DrmEngine = class {
}
// NOTE: allowCrossSiteCredentials can be set in a request filter.

if (shaka.util.DrmUtils.isPlayReadyKeySystem(
if (shaka.drm.DrmUtils.isPlayReadyKeySystem(
this.currentDrmInfo_.keySystem)) {
this.unpackPlayReadyRequest_(request);
}
Expand Down Expand Up @@ -1649,7 +1649,7 @@ shaka.media.DrmEngine = class {
// NOTE that we skip this if byteLength != 16. This is used for Edge
// which uses single-byte dummy key IDs.
// However, unlike Edge and Chromecast, Tizen doesn't have this problem.
if (shaka.util.DrmUtils.isPlayReadyKeySystem(
if (shaka.drm.DrmUtils.isPlayReadyKeySystem(
this.currentDrmInfo_.keySystem) &&
keyId.byteLength == 16 &&
(shaka.util.Platform.isEdge() || shaka.util.Platform.isPS4())) {
Expand Down Expand Up @@ -1713,7 +1713,7 @@ shaka.media.DrmEngine = class {
// each of them. By batching these up, we only send one status change event
// and at most one EXPIRED error on expiration.
this.keyStatusTimer_.tickAfter(
/* seconds= */ shaka.media.DrmEngine.KEY_STATUS_BATCH_TIME);
/* seconds= */ shaka.drm.DrmEngine.KEY_STATUS_BATCH_TIME);
}

/** @private */
Expand Down Expand Up @@ -1759,7 +1759,7 @@ shaka.media.DrmEngine = class {
'com.apple.fps',
];

if (!shaka.util.DrmUtils.isBrowserSupported()) {
if (!shaka.drm.DrmUtils.isBrowserSupported()) {
const result = {};
for (const keySystem of testKeySystems) {
result[keySystem] = null;
Expand Down Expand Up @@ -2020,7 +2020,7 @@ shaka.media.DrmEngine = class {
async closeSession_(session) {
try {
await shaka.util.Functional.promiseWithTimeout(
shaka.media.DrmEngine.CLOSE_TIMEOUT_,
shaka.drm.DrmEngine.CLOSE_TIMEOUT_,
Promise.all([session.close(), session.closed]));
} catch (e) {
shaka.log.warning('Timeout waiting for session close');
Expand Down Expand Up @@ -2193,7 +2193,7 @@ shaka.media.DrmEngine = class {
/** @type {!Set.<string>} */
const keySystemUris = new Set();

shaka.media.DrmEngine.processDrmInfos_(
shaka.drm.DrmEngine.processDrmInfos_(
drmInfos, encryptionSchemes, licenseServers, serverCerts,
serverCertificateUris, initDatas, keyIds, keySystemUris);

Expand Down Expand Up @@ -2283,7 +2283,7 @@ shaka.media.DrmEngine = class {
const keyIds = new Set();

// TODO: refactor, don't stick drmInfos onto MediaKeySystemConfiguration
shaka.media.DrmEngine.processDrmInfos_(
shaka.drm.DrmEngine.processDrmInfos_(
config['drmInfos'], encryptionSchemes, licenseServers, serverCerts,
serverCertificateUris, initDatas, keyIds);

Expand Down Expand Up @@ -2613,7 +2613,7 @@ shaka.media.DrmEngine = class {
* call. This is used to track the 'license-release' message when calling
* remove().
*/
shaka.media.DrmEngine.SessionMetaData;
shaka.drm.DrmEngine.SessionMetaData;


/**
Expand All @@ -2639,14 +2639,14 @@ shaka.media.DrmEngine.SessionMetaData;
* @property {function(!Event)} onEvent
* Called when an event occurs that should be sent to the app.
*/
shaka.media.DrmEngine.PlayerInterface;
shaka.drm.DrmEngine.PlayerInterface;

/**
* The amount of time, in seconds, we wait to consider a session closed.
* This allows us to work around Chrome bug https://crbug.com/1108158.
* @private {number}
*/
shaka.media.DrmEngine.CLOSE_TIMEOUT_ = 1;
shaka.drm.DrmEngine.CLOSE_TIMEOUT_ = 1;


/**
Expand All @@ -2655,12 +2655,12 @@ shaka.media.DrmEngine.CLOSE_TIMEOUT_ = 1;
* without key statuses.
* @private {number}
*/
shaka.media.DrmEngine.SESSION_LOAD_TIMEOUT_ = 5;
shaka.drm.DrmEngine.SESSION_LOAD_TIMEOUT_ = 5;


/**
* The amount of time, in seconds, we wait to batch up rapid key status changes.
* This allows us to avoid multiple expiration events in most cases.
* @type {number}
*/
shaka.media.DrmEngine.KEY_STATUS_BATCH_TIME = 0.5;
shaka.drm.DrmEngine.KEY_STATUS_BATCH_TIME = 0.5;
18 changes: 9 additions & 9 deletions lib/util/drm_utils.js → lib/drm/drm_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.util.DrmUtils');
goog.provide('shaka.drm.DrmUtils');

goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.Lazy');


shaka.util.DrmUtils = class {
shaka.drm.DrmUtils = class {
/**
* Returns true if the browser has recent EME APIs.
*
Expand Down Expand Up @@ -45,7 +45,7 @@ shaka.util.DrmUtils = class {
return true;
}

return shaka.util.DrmUtils.getCommonDrmInfos(
return shaka.drm.DrmUtils.getCommonDrmInfos(
drms1, drms2).length > 0;
}

Expand Down Expand Up @@ -160,7 +160,7 @@ shaka.util.DrmUtils = class {
* @return {boolean}
*/
static hasMediaKeySystemAccess(videoCodec, audioCodec, keySystem) {
const DrmUtils = shaka.util.DrmUtils;
const DrmUtils = shaka.drm.DrmUtils;
const key = DrmUtils.generateKeySystemCacheKey_(
videoCodec, audioCodec, keySystem);
return DrmUtils.memoizedMediaKeySystemAccessRequests_.has(key);
Expand All @@ -175,7 +175,7 @@ shaka.util.DrmUtils = class {
* @return {?MediaKeySystemAccess}
*/
static getMediaKeySystemAccess(videoCodec, audioCodec, keySystem) {
const DrmUtils = shaka.util.DrmUtils;
const DrmUtils = shaka.drm.DrmUtils;
const key = DrmUtils.generateKeySystemCacheKey_(
videoCodec, audioCodec, keySystem);
return DrmUtils.memoizedMediaKeySystemAccessRequests_.get(key) || null;
Expand All @@ -190,7 +190,7 @@ shaka.util.DrmUtils = class {
* @param {!MediaKeySystemAccess} mksa
*/
static setMediaKeySystemAccess(videoCodec, audioCodec, keySystem, mksa) {
const DrmUtils = shaka.util.DrmUtils;
const DrmUtils = shaka.drm.DrmUtils;
const key = DrmUtils.generateKeySystemCacheKey_(
videoCodec, audioCodec, keySystem);
return DrmUtils.memoizedMediaKeySystemAccessRequests_.set(key, mksa);
Expand All @@ -200,7 +200,7 @@ shaka.util.DrmUtils = class {
* Clears underlying cache.
*/
static clearMediaKeySystemAccessMap() {
const DrmUtils = shaka.util.DrmUtils;
const DrmUtils = shaka.drm.DrmUtils;
DrmUtils.memoizedMediaKeySystemAccessRequests_.clear();
}
};
Expand All @@ -211,7 +211,7 @@ shaka.util.DrmUtils = class {
* have a per-key key status. See w3c/encrypted-media#32.
* @type {!shaka.util.Lazy<!ArrayBuffer>}
*/
shaka.util.DrmUtils.DUMMY_KEY_ID = new shaka.util.Lazy(
shaka.drm.DrmUtils.DUMMY_KEY_ID = new shaka.util.Lazy(
() => shaka.util.BufferUtils.toArrayBuffer(new Uint8Array([0])));


Expand All @@ -222,4 +222,4 @@ shaka.util.DrmUtils.DUMMY_KEY_ID = new shaka.util.Lazy(
*
* @private {!Map<string, !MediaKeySystemAccess>}
*/
shaka.util.DrmUtils.memoizedMediaKeySystemAccessRequests_ = new Map();
shaka.drm.DrmUtils.memoizedMediaKeySystemAccessRequests_ = new Map();
4 changes: 2 additions & 2 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ goog.provide('shaka.hls.HlsParser');
goog.require('goog.Uri');
goog.require('goog.asserts');
goog.require('shaka.abr.Ewma');
goog.require('shaka.drm.DrmUtils');
goog.require('shaka.hls.Attribute');
goog.require('shaka.hls.ManifestTextParser');
goog.require('shaka.hls.Playlist');
Expand All @@ -28,7 +29,6 @@ goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.net.NetworkingEngine.PendingRequest');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.DrmUtils');
goog.require('shaka.util.ContentSteeringManager');
goog.require('shaka.util.Error');
goog.require('shaka.util.EventManager');
Expand Down Expand Up @@ -2006,7 +2006,7 @@ shaka.hls.HlsParser = class {
audioInfos, videoInfos, bandwidth, width, height, frameRate, videoRange,
videoLayout, drmInfos, keyIds, iFrameStreams) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const DrmUtils = shaka.util.DrmUtils;
const DrmUtils = shaka.drm.DrmUtils;

for (const info of videoInfos) {
this.addVideoAttributes_(
Expand Down
8 changes: 4 additions & 4 deletions lib/media/manifest_filterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
goog.provide('shaka.media.ManifestFilterer');

goog.require('goog.asserts');
goog.require('shaka.drm.DrmEngine');
avelad marked this conversation as resolved.
Show resolved Hide resolved
goog.require('shaka.util.StreamUtils');
goog.require('shaka.media.DrmEngine');
goog.require('shaka.util.Error');

/**
Expand All @@ -20,7 +20,7 @@ shaka.media.ManifestFilterer = class {
/**
* @param {?shaka.extern.PlayerConfiguration} config
* @param {shaka.extern.Resolution} maxHwRes
* @param {?shaka.media.DrmEngine} drmEngine
* @param {?shaka.drm.DrmEngine} drmEngine
*/
constructor(config, maxHwRes, drmEngine) {
goog.asserts.assert(config, 'Must have config');
Expand All @@ -31,11 +31,11 @@ shaka.media.ManifestFilterer = class {
/** @private {shaka.extern.Resolution} */
this.maxHwRes_ = maxHwRes;

/** @private {?shaka.media.DrmEngine} drmEngine */
/** @private {?shaka.drm.DrmEngine} drmEngine */
this.drmEngine_ = drmEngine;
}

/** @param {!shaka.media.DrmEngine} drmEngine */
/** @param {!shaka.drm.DrmEngine} drmEngine */
setDrmEngine(drmEngine) {
this.drmEngine_ = drmEngine;
}
Expand Down
Loading
Loading