Skip to content

Commit

Permalink
Merge branch 'shaka-project:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Robloche committed Dec 12, 2023
2 parents 00fd38e + 8649e7e commit 20a81ac
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 148 deletions.
32 changes: 20 additions & 12 deletions externs/isoboxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,35 @@
/**
* @typedef {{
* Utils: !ISOBoxerUtils,
* parseBuffer: function(!(ArrayBuffer|ArrayBufferView)):!ISOBoxer,
* parseBuffer: function(!(ArrayBuffer|ArrayBufferView)):!ISOFile,
* createBox: function(string, !ISOBoxer, boolean=):!ISOBoxer,
* createFullBox: function(string, !ISOBoxer, ?ISOBoxer=):!ISOBoxer,
* addBoxProcessor: function(string, function()):!ISOBoxer,
* createFile: function():!ISOBoxer,
* write: function():!ArrayBuffer,
* fetch: function(!ArrayBuffer):!ISOBoxer
* createFile: function():!ISOFile,
* }}
* @property {!ISOBoxerUtils} Utils
* @property {function(!(ArrayBuffer|ArrayBufferView)):!ISOBoxer} parseBuffer
* @property {function(!(ArrayBuffer|ArrayBufferView)):!ISOFile} parseBuffer
* @property {function(string, !ISOBoxer, boolean=):!ISOBoxer} createBox
* @property {function(string, !ISOBoxer, ?ISOBoxer=):!ISOBoxer} createFullBox
* @property {function(string, function()):!ISOBoxer} addBoxProcessor
* @property {function():!ISOBoxer} createFile
* @property {function():!ArrayBuffer} write
* @property {function(!ArrayBuffer):!ISOBoxer} fetch
* @property {function():!ISOFile} createFile
* @const
*/
var ISOBoxer;


/**
* @typedef {{
* write: function():!ArrayBuffer,
* fetch: function(string):!ISOBox
* }}
* @property {function():!ArrayBuffer} write
* @property {function(string):!ISOBox} fetch
* @const
*/
var ISOFile;


/**
* @typedef {{
* appendBox: function(!ISOBoxer, !ISOBoxer):!ISOBox
Expand Down Expand Up @@ -91,7 +99,7 @@ var ISOBoxerUtils;
* graphicsmode: number,
* opcolor: Array.<number>,
* balance: number,
* entries: Array.<!ISOBox>,
* entries: Array.<!ISOEntry>,
* location: string,
* data_reference_index: number,
* pre_defined1: number,
Expand Down Expand Up @@ -119,7 +127,7 @@ var ISOBoxerUtils;
* default_sample_size: number,
* default_sample_flags: number,
* baseMediaDecodeTime: number,
* usertype: ?string,
* usertype: (string|null|undefined),
* offset: Array.<number>,
* sample_info_size: Array.<number>,
* data_offset: number
Expand Down Expand Up @@ -170,7 +178,7 @@ var ISOBoxerUtils;
* @property {number} graphicsmode
* @property {Array.<number>} opcolor
* @property {number} balance
* @property {Array.<!ISOBox} entries
* @property {Array.<!ISOEntry>} entries
* @property {string} location
* @property {number} data_reference_index
* @property {number} pre_defined1
Expand Down Expand Up @@ -198,7 +206,7 @@ var ISOBoxerUtils;
* @property {number} default_sample_size
* @property {number} default_sample_flags
* @property {number} baseMediaDecodeTime
* @property {?string} usertype
* @property {string|null|undefined} usertype
* @property {Array.<number} offset
* @property {Array.<number} sample_info_size
* @property {number} data_offset
Expand Down
4 changes: 4 additions & 0 deletions externs/shaka/codecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @externs
*/

/**
* @typedef {{
* data: !Uint8Array,
Expand Down
15 changes: 9 additions & 6 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,23 @@ shaka.extern.CreateSegmentIndexFunction;

/**
* @typedef {{
* method: string,
* bitsKey: number,
* blockCipherMode: string,
* cryptoKey: (webCrypto.CryptoKey|undefined),
* fetchKey: (shaka.extern.CreateSegmentIndexFunction|undefined),
* iv: (!Uint8Array|undefined),
* firstMediaSequenceNumber: number
* }}
*
* @description
* AES-128 key and iv info from the manifest.
* AES key and iv info from the manifest.
*
* @property {string} method
* The key method defined in the manifest.
* @property {number} bitsKey
* The number of the bit key (eg: 128, 256).
* @property {string} blockCipherMode
* The block cipher mode of operation. Possible values: 'CTR' or 'CBC'.
* @property {webCrypto.CryptoKey|undefined} cryptoKey
* Web crypto key object of the AES-128 CBC key. If unset, the "fetchKey"
* Web crypto key object of the AES key. If unset, the "fetchKey"
* property should be provided.
* @property {shaka.extern.FetchCryptoKeysFunction|undefined} fetchKey
* A function that fetches the key.
Expand All @@ -346,7 +349,7 @@ shaka.extern.CreateSegmentIndexFunction;
*
* @exportDoc
*/
shaka.extern.aes128Key;
shaka.extern.aesKey;


/**
Expand Down
5 changes: 3 additions & 2 deletions lib/ads/media_tailor_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ shaka.ads.MediaTailorAdManager = class {
if (!app.data.source.length) {
continue;
}
const imageElement = document.createElement('img');
imageElement.setAttribute('src', app.data.source[0].url);
const imageElement = /** @type {!HTMLImageElement} */ (
document.createElement('img'));
imageElement.src = app.data.source[0].url;
imageElement.style.top = (app.placeholder.top || 0) + '%';
imageElement.style.height = (100 - (app.placeholder.top || 0)) + '%';
imageElement.style.left = (app.placeholder.left || 0) + '%';
Expand Down
29 changes: 16 additions & 13 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ shaka.dash.DashParser = class {
this.contentSteeringManager_.configure(this.config_);
}

this.periodCombiner_.setAllowMultiTypeVariants(
this.config_.dash.multiTypeVariantsAllowed &&
shaka.media.Capabilities.isChangeTypeSupported());
if (this.periodCombiner_) {
this.periodCombiner_.setAllowMultiTypeVariants(
this.config_.dash.multiTypeVariantsAllowed &&
shaka.media.Capabilities.isChangeTypeSupported());
}
}

/**
Expand Down Expand Up @@ -1417,8 +1419,8 @@ shaka.dash.DashParser = class {
const isImage = contentType == ContentType.IMAGE;

try {
/** @type {shaka.extern.aes128Key|undefined} */
let aes128Key = undefined;
/** @type {shaka.extern.aesKey|undefined} */
let aesKey = undefined;
if (contentProtection.aes128Info) {
const getBaseUris = context.representation.getBaseUris;
const uris = shaka.util.ManifestParserUtils.resolveUris(
Expand All @@ -1427,15 +1429,16 @@ shaka.dash.DashParser = class {
const request = shaka.net.NetworkingEngine.makeRequest(
uris, this.config_.retryParameters);

aes128Key = {
method: 'AES-128',
aesKey = {
bitsKey: 128,
blockCipherMode: 'CBC',
iv: contentProtection.aes128Info.iv,
firstMediaSequenceNumber: 0,
};

// Don't download the key object until the segment is parsed, to
// avoid a startup delay for long manifests with lots of keys.
aes128Key.fetchKey = async () => {
aesKey.fetchKey = async () => {
const keyResponse =
await this.makeNetworkRequest_(request, requestType);

Expand All @@ -1451,27 +1454,27 @@ shaka.dash.DashParser = class {
const algorithm = {
name: 'AES-CBC',
};
aes128Key.cryptoKey = await window.crypto.subtle.importKey(
aesKey.cryptoKey = await window.crypto.subtle.importKey(
'raw', keyResponse.data, algorithm, true, ['decrypt']);
aes128Key.fetchKey = undefined; // No longer needed.
aesKey.fetchKey = undefined; // No longer needed.
};
}
const requestSegment = (uris, startByte, endByte, isInit) => {
return this.requestSegment_(uris, startByte, endByte, isInit);
};
if (context.representation.segmentBase) {
streamInfo = shaka.dash.SegmentBase.createStreamInfo(
context, requestSegment, aes128Key);
context, requestSegment, aesKey);
} else if (context.representation.segmentList) {
streamInfo = shaka.dash.SegmentList.createStreamInfo(
context, this.streamMap_, aes128Key);
context, this.streamMap_, aesKey);
} else if (context.representation.segmentTemplate) {
const hasManifest = !!this.manifest_;

streamInfo = shaka.dash.SegmentTemplate.createStreamInfo(
context, requestSegment, this.streamMap_, hasManifest,
this.config_.dash.initialSegmentLimit, this.periodDurations_,
aes128Key);
aesKey);
} else {
goog.asserts.assert(isText,
'Must have Segment* with non-text streams.');
Expand Down
12 changes: 6 additions & 6 deletions lib/dash/segment_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ shaka.dash.SegmentBase = class {
*
* @param {shaka.dash.DashParser.Context} context
* @param {function(?shaka.dash.DashParser.InheritanceFrame):Element} callback
* @param {shaka.extern.aes128Key|undefined} aes128Key
* @param {shaka.extern.aesKey|undefined} aesKey
* @return {shaka.media.InitSegmentReference}
*/
static createInitSegment(context, callback, aes128Key) {
static createInitSegment(context, callback, aesKey) {
const MpdUtils = shaka.dash.MpdUtils;
const XmlUtils = shaka.util.XmlUtils;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
Expand Down Expand Up @@ -69,18 +69,18 @@ shaka.dash.SegmentBase = class {
qualityInfo,
/* timescale= */ null,
/* segmentData= */ null,
aes128Key);
aesKey);
}

/**
* Creates a new StreamInfo object.
*
* @param {shaka.dash.DashParser.Context} context
* @param {shaka.dash.DashParser.RequestSegmentCallback} requestSegment
* @param {shaka.extern.aes128Key|undefined} aes128Key
* @param {shaka.extern.aesKey|undefined} aesKey
* @return {shaka.dash.DashParser.StreamInfo}
*/
static createStreamInfo(context, requestSegment, aes128Key) {
static createStreamInfo(context, requestSegment, aesKey) {
goog.asserts.assert(context.representation.segmentBase,
'Should only be called with SegmentBase');
// Since SegmentBase does not need updates, simply treat any call as
Expand All @@ -103,7 +103,7 @@ shaka.dash.SegmentBase = class {
(unscaledPresentationTimeOffset / timescale) || 0;

const initSegmentReference = SegmentBase.createInitSegment(
context, SegmentBase.fromInheritance_, aes128Key);
context, SegmentBase.fromInheritance_, aesKey);

// Throws an immediate error if the format is unsupported.
SegmentBase.checkSegmentIndexRangeSupport_(context, initSegmentReference);
Expand Down
14 changes: 7 additions & 7 deletions lib/dash/segment_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ shaka.dash.SegmentList = class {
*
* @param {shaka.dash.DashParser.Context} context
* @param {!Object.<string, !shaka.extern.Stream>} streamMap
* @param {shaka.extern.aes128Key|undefined} aes128Key
* @param {shaka.extern.aesKey|undefined} aesKey
* @return {shaka.dash.DashParser.StreamInfo}
*/
static createStreamInfo(context, streamMap, aes128Key) {
static createStreamInfo(context, streamMap, aesKey) {
goog.asserts.assert(context.representation.segmentList,
'Should only be called with SegmentList');
const SegmentList = shaka.dash.SegmentList;

const initSegmentReference = shaka.dash.SegmentBase.createInitSegment(
context, SegmentList.fromInheritance_, aes128Key);
context, SegmentList.fromInheritance_, aesKey);
const info = SegmentList.parseSegmentListInfo_(context);

SegmentList.checkSegmentListInfo_(context, info);
Expand All @@ -60,7 +60,7 @@ shaka.dash.SegmentList = class {
const references = SegmentList.createSegmentReferences_(
context.periodInfo.start, context.periodInfo.duration,
info.startNumber, context.representation.getBaseUris, info,
initSegmentReference, aes128Key);
initSegmentReference, aesKey);

const isNew = !segmentIndex;
if (segmentIndex) {
Expand Down Expand Up @@ -198,13 +198,13 @@ shaka.dash.SegmentList = class {
* @param {function():!Array.<string>} getBaseUris
* @param {shaka.dash.SegmentList.SegmentListInfo} info
* @param {shaka.media.InitSegmentReference} initSegmentReference
* @param {shaka.extern.aes128Key|undefined} aes128Key
* @param {shaka.extern.aesKey|undefined} aesKey
* @return {!Array.<!shaka.media.SegmentReference>}
* @private
*/
static createSegmentReferences_(
periodStart, periodDuration, startNumber, getBaseUris, info,
initSegmentReference, aes128Key) {
initSegmentReference, aesKey) {
const ManifestParserUtils = shaka.util.ManifestParserUtils;

let max = info.mediaSegments.length;
Expand Down Expand Up @@ -266,7 +266,7 @@ shaka.dash.SegmentList = class {
/* tileDuration= */ null,
/* syncTime= */ null,
shaka.media.SegmentReference.Status.AVAILABLE,
aes128Key));
aesKey));
prevEndTime = endTime;
}

Expand Down
Loading

0 comments on commit 20a81ac

Please sign in to comment.