Skip to content

Commit

Permalink
feat(DRM): add initData and initDataType to license requests (#4039)
Browse files Browse the repository at this point in the history
Adds initData and initDataType field to all LICENSE-type requests.

Based on comments here: #4001 (comment)
  • Loading branch information
Álvaro Velad Galván committed Mar 21, 2022
1 parent 3c5ae1c commit bdc5ea7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions externs/shaka/net.js
Expand Up @@ -61,6 +61,8 @@ shaka.extern.RetryParameters;
* licenseRequestType: ?string,
* sessionId: ?string,
* drmInfo: ?shaka.extern.DrmInfo,
* initData: ?Uint8Array,
* initDataType: ?string,
* streamDataCallback: ?function(BufferSource):!Promise
* }}
*
Expand Down Expand Up @@ -94,6 +96,12 @@ shaka.extern.RetryParameters;
* @property {?shaka.extern.DrmInfo} drmInfo
* If this is a LICENSE request, this field contains the DRM info used to
* initialize EME.
* @property {?Uint8Array} initData
* If this is a LICENSE request, this field contains the initData info used
* to initialize EME.
* @property {?string} initDataType
* If this is a LICENSE request, this field contains the initDataType info
* used to initialize EME.
* @property {?function(BufferSource):!Promise} streamDataCallback
* A callback function to handle the chunked data of the ReadableStream.
* @exportDoc
Expand Down
9 changes: 9 additions & 0 deletions lib/media/drm_engine.js
Expand Up @@ -1169,6 +1169,7 @@ shaka.media.DrmEngine = class {

const metadata = {
initData: null,
initDataType: null,
loaded: false,
oldExpiration: Infinity,
updatePromise: null,
Expand Down Expand Up @@ -1245,6 +1246,7 @@ shaka.media.DrmEngine = class {

const metadata = {
initData: initData,
initDataType: initDataType,
loaded: false,
oldExpiration: Infinity,
updatePromise: null,
Expand Down Expand Up @@ -1386,6 +1388,10 @@ shaka.media.DrmEngine = class {
request.licenseRequestType = event.messageType;
request.sessionId = session.sessionId;
request.drmInfo = this.currentDrmInfo_;
if (metadata) {
request.initData = metadata.initData;
request.initDataType = metadata.initDataType;
}
// NOTE: allowCrossSiteCredentials can be set in a request filter.

if (shaka.media.DrmEngine.isPlayReadyKeySystem(
Expand Down Expand Up @@ -2342,6 +2348,7 @@ shaka.media.DrmEngine = class {
* @typedef {{
* loaded: boolean,
* initData: Uint8Array,
* initDataType: ?string,
* oldExpiration: number,
* type: string,
* updatePromise: shaka.util.PublicPromise
Expand All @@ -2353,6 +2360,8 @@ shaka.media.DrmEngine = class {
* does not mean the session is 'usable'.
* @property {Uint8Array} initData
* The init data used to create the session.
* @property {?string} initDataType
* The init data type used to create the session.
* @property {!MediaKeySession} session
* The session object.
* @property {number} oldExpiration
Expand Down
2 changes: 2 additions & 0 deletions lib/net/networking_engine.js
Expand Up @@ -221,6 +221,8 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
licenseRequestType: null,
sessionId: null,
drmInfo: null,
initData: null,
initDataType: null,
streamDataCallback: streamDataCallback,
};
}
Expand Down
2 changes: 2 additions & 0 deletions test/util/cmcd_manager_unit.js
Expand Up @@ -124,6 +124,8 @@ describe('CmcdManager', () => {
licenseRequestType: null,
sessionId: null,
drmInfo: null,
initData: null,
initDataType: null,
streamDataCallback: null,
};

Expand Down

0 comments on commit bdc5ea7

Please sign in to comment.