Constructor
new DrmEngine(playerInterface)
Parameters:
Name | Type | Description |
---|---|---|
playerInterface |
shaka.media.DrmEngine.PlayerInterface |
- Implements:
- Source:
Members
CLOSE_TIMEOUT_ :number
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.
Type:
- number
- Source:
KEY_STATUS_BATCH_TIME :number
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
- Source:
SESSION_LOAD_TIMEOUT_ :number
The amount of time, in seconds, we wait to consider session loaded even if no
key status information is available. This allows us to support browsers/CDMs
without key statuses.
Type:
- number
- Source:
activeSessions_ :Map.<MediaKeySession, shaka.media.DrmEngine.SessionMetaData>
Type:
- Map.<MediaKeySession, shaka.media.DrmEngine.SessionMetaData>
- Source:
announcedKeyStatusByKeyId_ :Map.<string, string>
The key statuses most recently announced to other classes.
We may have more up-to-date information being collected in
this.keyStatusByKeyId_, which has not been batched up and released yet.
Type:
- Map.<string, string>
- Source:
keyStatusByKeyId_ :Map.<string, string>
The most recent key status information we have.
We may not have announced this information to the outside world yet,
which we delay to batch up changes and avoid spurious "missing key"
errors.
Type:
- Map.<string, string>
- Source:
mediaKeyMessageEvents_ :Array.<!MediaKeyMessageEvent>
Type:
- Array.<!MediaKeyMessageEvent>
- Source:
storedPersistentSessions_ :Map.<string, {initData: ?Uint8Array, initDataType: ?string}>
Type:
- Map.<string, {initData: ?Uint8Array, initDataType: ?string}>
- Source:
Methods
createDrmInfoByConfigs_(keySystem, config) → {shaka.extern.DrmInfo}
Creates a DrmInfo object describing the settings used to initialize the
engine.
Parameters:
Name | Type | Description |
---|---|---|
keySystem |
string | |
config |
MediaKeySystemConfiguration |
- Source:
Returns:
- Type
- shaka.extern.DrmInfo
fillInDrmInfoDefaults_(drmInfo, serversnon-null, advancedConfigsnon-null, keySystemsMappingnon-null)
Use |servers| and |advancedConfigs| to fill in missing values in drmInfo
that the parser left blank. Before working with any drmInfo, it should be
passed through here as it is uncommon for drmInfo to be complete when
fetched from a manifest because most manifest formats do not have the
required information. Also applies the key systems mapping.
Parameters:
Name | Type | Description |
---|---|---|
drmInfo |
shaka.extern.DrmInfo | |
servers |
Map.<string, string> | |
advancedConfigs |
Map.<string, shaka.extern.AdvancedDrmConfiguration> | |
keySystemsMapping |
Object.<string, string> |
- Source:
probeSupport() → {Promise.<!Object.<string, ?shaka.extern.DrmSupportType>>}
Returns a Promise to a map of EME support for well-known key systems.
- Source:
Returns:
- Type
- Promise.<!Object.<string, ?shaka.extern.DrmSupportType>>
processDrmInfos_(drmInfosnon-null, licenseServersnon-null, encryptionSchemesnon-null, serverCertsnon-null, serverCertificateUrisnon-null, initDatasnon-null, keyIdsnon-null, keySystemUrisopt, non-null)
Extract license server, server cert, and init data from |drmInfos|, taking
care to eliminate duplicates.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
drmInfos |
Array.<shaka.extern.DrmInfo> | ||
licenseServers |
Array.<string> | ||
encryptionSchemes |
Array.<string> | ||
serverCerts |
Array.<!Uint8Array> | ||
serverCertificateUris |
Array.<string> | ||
initDatas |
Array.<!shaka.extern.InitDataOverride> | ||
keyIds |
Set.<string> | ||
keySystemUris |
Set.<string> |
<optional> |
- Source:
replaceDrmInfo_(variantsnon-null, keySystemsnon-null)
Replace the drm info used in each variant in |variants| to reflect each
key service in |keySystems|.
Parameters:
Name | Type | Description |
---|---|---|
variants |
Array.<shaka.extern.Variant> | |
keySystems |
Map.<string, string> |
- Source:
areAllSessionsLoaded_() → {boolean}
- Source:
Returns:
- Type
- boolean
attach(video) → {Promise}
Start processing events.
Parameters:
Name | Type | Description |
---|---|---|
video |
HTMLMediaElement |
- Source:
Returns:
- Type
- Promise
attachMediaKeys_() → {Promise}
Attach MediaKeys to the video element
- Source:
Returns:
- Type
- Promise
checkSessionsLoaded_()
Resolves the allSessionsLoaded_ promise when all the sessions are loaded
- Source:
closeOpenSessions_()
- Source:
closeSession_(sessionnon-null) → {Promise}
Close a drm session while accounting for a bug in Chrome. Sometimes the
Promise returned by close() never resolves.
See issue #2741 and http://crbug.com/1108158.
Parameters:
Name | Type | Description |
---|---|---|
session |
MediaKeySession |
- Source:
Returns:
- Type
- Promise
configure(config, isPreloadopt)
Called by the Player to provide an updated configuration any time it
changes.
Must be called at least once before init().
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
shaka.extern.DrmConfiguration | ||
isPreload |
function |
<optional> |
- Source:
configureClearKey_() → {shaka.extern.DrmInfo}
Create a DrmInfo using configured clear keys.
The server URI will be a data URI which decodes to a clearkey license.
- Source:
- See:
Returns:
or null if clear keys are not configured.
- Type
- shaka.extern.DrmInfo
createDrmInfoByInfos_(keySystem, drmInfosnon-null) → {shaka.extern.DrmInfo}
Creates a DrmInfo object describing the settings used to initialize the
engine.
Parameters:
Name | Type | Description |
---|---|---|
keySystem |
string | |
drmInfos |
Array.<shaka.extern.DrmInfo> |
- Source:
Returns:
- Type
- shaka.extern.DrmInfo
createOrLoad() → {Promise}
Creates the sessions for the init data and waits for them to become ready.
- Source:
Returns:
- Type
- Promise
createSession(initDataType, initDatanon-null, sessionType)
Parameters:
Name | Type | Description |
---|---|---|
initDataType |
string | |
initData |
Uint8Array | |
sessionType |
string |
- Source:
destroy() → {Promise}
Request that this object be destroyed, releasing all resources and shutting
down all operations. Returns a Promise which is resolved when destruction
is complete. This Promise should never be rejected.
- Implements:
- Source:
Returns:
- Type
- Promise
destroyNow_()
Destroy this instance of DrmEngine. This assumes that all other checks
about "if it should" have passed.
- Source:
getActiveSessionsMetadata() → {Array.<shaka.extern.DrmSessionMetadata>}
Returns the active sessions metadata
- Source:
Returns:
- Type
- Array.<shaka.extern.DrmSessionMetadata>
getDrmInfo() → {shaka.extern.DrmInfo}
Returns the DrmInfo that was used to initialize the current key system.
- Source:
Returns:
- Type
- shaka.extern.DrmInfo
getExpiration() → {number}
Returns the next expiration time, or Infinity.
- Source:
Returns:
- Type
- number
getKeyStatuses() → {Object.<string, string>}
Returns the current key statuses.
- Source:
Returns:
- Type
- Object.<string, string>
getKeySystemAccessByConfigs_(configsByKeySystemnon-null) → {Promise.<MediaKeySystemAccess>}
Get the MediaKeySystemAccess by querying requestMediaKeySystemAccess.
Parameters:
Name | Type | Description |
---|---|---|
configsByKeySystem |
Map.<string, MediaKeySystemConfiguration> | A dictionary of configs, indexed by key system, with an iteration order (insertion order) that reflects the preference for the application. |
- Source:
Returns:
Resolved if/when a
mediaKeySystemAccess has been chosen.
- Type
- Promise.<MediaKeySystemAccess>
getKeySystemAccessFromVariants_(variantsnon-null, drmInfosByKeySystemnon-null) → {MediaKeySystemAccess}
Get the MediaKeySystemAccess from the decodingInfos of the variants.
Parameters:
Name | Type | Description |
---|---|---|
variants |
Array.<shaka.extern.Variant> | |
drmInfosByKeySystem |
Map.<string, !Array.<shaka.extern.DrmInfo>> | A dictionary of drmInfos, indexed by key system. |
- Source:
Returns:
- Type
- MediaKeySystemAccess
getLicenseTime() → {number}
Returns the time spent on license requests during this session, or NaN.
- Source:
Returns:
- Type
- number
getMediaKeys() → {MediaKeys}
Return the media keys created from the current mediaKeySystemAccess.
- Source:
Returns:
- Type
- MediaKeys
getMediaKeySessions() → {Array.<MediaKeySession>}
Returns the current media key sessions.
- Source:
Returns:
- Type
- Array.<MediaKeySession>
getSessionIds() → {Array.<string>}
Returns the ID of the sessions currently active.
- Source:
Returns:
- Type
- Array.<string>
getVariantDrmInfos_(variant) → {Array.<!shaka.extern.DrmInfo>}
Concat the audio and video drmInfos in a variant.
Parameters:
Name | Type | Description |
---|---|---|
variant |
shaka.extern.Variant |
- Source:
Returns:
- Type
- Array.<!shaka.extern.DrmInfo>
hasManifestInitData() → {boolean}
Returns true if the manifest has init data.
- Source:
Returns:
- Type
- boolean
init_(variantsnon-null) → {Promise}
Negotiate for a key system and set up MediaKeys.
This will assume that both |usePersistentLicences_| and
|storedPersistentSessions_| have been properly set.
Parameters:
Name | Type | Description |
---|---|---|
variants |
Array.<shaka.extern.Variant> | The variants that we expect to operate with during the drm engine's lifespan of the drm engine. |
- Source:
Returns:
Resolved if/when a key system has been chosen.
- Type
- Promise
initForPlayback(variantsnon-null, offlineSessionIdsnon-null) → {Promise}
Initialize the drm engine for playback operations.
Parameters:
Name | Type | Description |
---|---|---|
variants |
Array.<shaka.extern.Variant> | The variants that we want to support playing. |
offlineSessionIds |
Array.<string> |
- Source:
Returns:
- Type
- Promise
initForRemoval(keySystem, licenseServerUri, serverCertificate, audioCapabilitiesnon-null, videoCapabilitiesnon-null) → {Promise}
Initializes the drm engine for removing persistent sessions. Only the
removeSession(s) methods will work correctly, creating new sessions may not
work as desired.
Parameters:
Name | Type | Description |
---|---|---|
keySystem |
string | |
licenseServerUri |
string | |
serverCertificate |
Uint8Array | |
audioCapabilities |
Array.<MediaKeySystemMediaCapability> | |
videoCapabilities |
Array.<MediaKeySystemMediaCapability> |
- Source:
Returns:
- Type
- Promise
initForStorage(variantsnon-null, usePersistentLicenses) → {Promise}
Initialize the drm engine for storing and deleting stored content.
Parameters:
Name | Type | Description |
---|---|---|
variants |
Array.<shaka.extern.Variant> | The variants that are going to be stored. |
usePersistentLicenses |
boolean | Whether or not persistent licenses should be requested and stored for |manifest|. |
- Source:
Returns:
- Type
- Promise
isPreload_()
- Source:
loadOfflineSession_(sessionId, sessionMetadata) → {Promise.<MediaKeySession>}
Parameters:
Name | Type | Description |
---|---|---|
sessionId |
string | |
sessionMetadata |
{initData: ?Uint8Array, initDataType: ?string} |
- Source:
Returns:
- Type
- Promise.<MediaKeySession>
newInitData(initDataType, initDatanon-null)
Called when new initialization data is encountered. If this data hasn't
been seen yet, this will create a new session for it.
Parameters:
Name | Type | Description |
---|---|---|
initDataType |
string | |
initData |
Uint8Array |
- Source:
onEncryptedEvent_() → {Promise}
Processes encrypted event and start licence challenging
- Source:
Returns:
- Type
- Promise
onError_()
- Source:
onKeyStatusesChange_(eventnon-null)
Parameters:
Name | Type | Description |
---|---|---|
event |
Event |
- Source:
onPlay_()
- Source:
onSessionMessage_(eventnon-null)
Parameters:
Name | Type | Description |
---|---|---|
event |
MediaKeyMessageEvent |
- Source:
parseInbandPssh(contentType, mediaSegmentnon-null) → {Promise.<void>}
Parse pssh from a media segment and announce new initData
Parameters:
Name | Type | Description |
---|---|---|
contentType |
shaka.util.ManifestParserUtils.ContentType | |
mediaSegment |
BufferSource |
- Source:
Returns:
- Type
- Promise.<void>
pollExpiration_()
Called in an interval timer to poll the expiration times of the sessions.
We don't get an event from EME when the expiration updates, so we poll it
so we can fire an event when it happens.
- Source:
processKeyStatusChanges_()
- Source:
queryMediaKeys_(configsByKeySystemnon-null, variantsnon-null) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
configsByKeySystem |
Map.<string, MediaKeySystemConfiguration> | A dictionary of configs, indexed by key system, with an iteration order (insertion order) that reflects the preference for the application. |
variants |
Array.<shaka.extern.Variant> |
- Source:
Returns:
Resolved if/when a key system has been chosen.
- Type
- Promise
removeSession(sessionId) → {Promise}
Remove an offline session and delete it's data. This can only be called
after a successful call to |init|. This will wait until the
'license-release' message is handled. The returned Promise will be rejected
if there is an error releasing the license.
Parameters:
Name | Type | Description |
---|---|---|
sessionId |
string |
- Source:
Returns:
- Type
- Promise
sendLicenseRequest_(eventnon-null)
Sends a license request.
Parameters:
Name | Type | Description |
---|---|---|
event |
MediaKeyMessageEvent |
- Source:
setLoadSessionTimeoutTimer_(metadatanon-null)
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.
Parameters:
Name | Type | Description |
---|---|---|
metadata |
shaka.media.DrmEngine.SessionMetaData |
- Source:
setServerCertificate() → {Promise}
Sets the server certificate based on the current DrmInfo.
- Source:
Returns:
- Type
- Promise
setSrcEquals(valuenon-null)
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean |
- Source:
unpackPlayReadyRequest_(request)
Unpacks PlayReady license requests. Modifies the request object.
Parameters:
Name | Type | Description |
---|---|---|
request |
shaka.extern.Request |
- Source:
Type Definitions
PlayerInterface
Type:
- {netEngine: !shaka.net.NetworkingEngine, onError: function(!shaka.util.Error), onKeyStatus: function(!Object.<string, string>), onExpirationUpdated: function(string, number), onEvent: function(!Event)}
Properties:
Name | Type | Description |
---|---|---|
netEngine |
shaka.net.NetworkingEngine | The NetworkingEngine instance to use. The caller retains ownership. |
onError |
function | Called when an error occurs. If the error is recoverable (see shaka.util.Error) then the caller may invoke either StreamingEngine.switch*() or StreamingEngine.seeked() to attempt recovery. |
onKeyStatus |
function | Called when key status changes. The argument is a map of hex key IDs to statuses. |
onExpirationUpdated |
function | Called when the session expiration value changes. |
onEvent |
function | Called when an event occurs that should be sent to the app. |
- Source:
SessionMetaData
A record to track sessions and suppress duplicate init data.
Type:
- {loaded: boolean, initData: Uint8Array, initDataType: ?string, oldExpiration: number, type: string, updatePromise: shaka.util.PublicPromise}
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
loaded |
boolean | True once the key status has been updated (to a non-pending state). This does not mean the session is 'usable'. | |
initData |
Uint8Array | The init data used to create the session. | |
initDataType |
string |
<nullable> |
The init data type used to create the session. |
session |
MediaKeySession | The session object. | |
oldExpiration |
number | The expiration of the session on the last check. This is used to fire an event when it changes. | |
type |
string | The session type | |
updatePromise |
shaka.util.PublicPromise | An optional Promise that will be resolved/rejected on the next update() call. This is used to track the 'license-release' message when calling remove(). |
- Source: