Skip to content

Commit 6384ebe

Browse files
committed
apple-audio-lang-sandbox
1 parent 10e3d29 commit 6384ebe

18 files changed

+302
-88
lines changed

build/all.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ def main(args):
9595
if gendeps.main([]) != 0:
9696
return 1
9797

98-
check_args = []
99-
if parsed_args.fix:
100-
check_args += ['--fix']
101-
if parsed_args.force:
102-
check_args += ['--force']
103-
if check.main(check_args) != 0:
104-
return 1
105-
10698
docs_args = []
10799
if parsed_args.force:
108100
docs_args += ['--force']

externs/shaka/drm_info.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ shaka.extern.InitDataOverride;
4848
* serverCertificateUri: string,
4949
* sessionType: string,
5050
* initData: Array<!shaka.extern.InitDataOverride>,
51-
* keyIds: Set<string>
51+
* keyIds: Set<string>,
52+
* mediaTypes: (!Array<string>|undefined)
5253
* }}
5354
*
5455
* @description
@@ -103,6 +104,10 @@ shaka.extern.InitDataOverride;
103104
* <i>Defaults to the empty Set</i> <br>
104105
* If not empty, contains the default key IDs for this key system, as
105106
* lowercase hex strings.
107+
* @property {!Array<string>=} mediaTypes
108+
* An optional list specifying each component in a media type:
109+
* https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data#media-type
110+
* included in a <code>data:</code> scheme URI, separated by semicolon.
106111
* @exportDoc
107112
*/
108113
shaka.extern.DrmInfo;

lib/drm/drm_engine.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ shaka.drm.DrmEngine = class {
320320

321321
const makeDrmInfo = (encryptionScheme) => {
322322
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
323-
keySystem, encryptionScheme, null);
323+
keySystem, encryptionScheme, /* initData= */ null);
324324
drmInfo.licenseServerUri = licenseServerUri;
325325
drmInfo.serverCertificate = serverCertificate;
326326
drmInfo.persistentStateRequired = true;
@@ -800,6 +800,21 @@ shaka.drm.DrmEngine = class {
800800
return this.allSessionsLoaded_;
801801
}
802802

803+
/**
804+
* Called when new initialization data is encountered.
805+
*
806+
* Certain fields may not be set yet in currentDrmInfo_ due to
807+
* PreloadManager's early initialization of the DrmEngine
808+
* (when currentDrmInfo_ is initialized).
809+
* @param {!shaka.extern.DrmInfo} drmInfo
810+
*/
811+
updateCurrentDrmInfo(drmInfo) {
812+
if (this.currentDrmInfo_ &&
813+
(this.currentDrmInfo_.mediaTypes !== drmInfo.mediaTypes)) {
814+
this.currentDrmInfo_.mediaTypes = drmInfo.mediaTypes;
815+
}
816+
}
817+
803818
/**
804819
* Called when new initialization data is encountered. If this data hasn't
805820
* been seen yet, this will create a new session for it.
@@ -812,6 +827,22 @@ shaka.drm.DrmEngine = class {
812827
return;
813828
}
814829

830+
try {
831+
initData = this.config_.initDataTransform(
832+
initData, initDataType, this.currentDrmInfo_);
833+
} catch (error) {
834+
let shakaError = error;
835+
if (!(error instanceof shaka.util.Error)) {
836+
shakaError = new shaka.util.Error(
837+
shaka.util.Error.Severity.CRITICAL,
838+
shaka.util.Error.Category.DRM,
839+
shaka.util.Error.Code.INIT_DATA_TRANSFORM_ERROR,
840+
error);
841+
}
842+
this.onError_(shakaError);
843+
return;
844+
}
845+
815846
// Suppress duplicate init data.
816847
// Note that some init data are extremely large and can't portably be used
817848
// as keys in a dictionary.
@@ -1290,22 +1321,6 @@ shaka.drm.DrmEngine = class {
12901321
};
12911322
this.activeSessions_.set(session, metadata);
12921323

1293-
try {
1294-
initData = this.config_.initDataTransform(
1295-
initData, initDataType, this.currentDrmInfo_);
1296-
} catch (error) {
1297-
let shakaError = error;
1298-
if (!(error instanceof shaka.util.Error)) {
1299-
shakaError = new shaka.util.Error(
1300-
shaka.util.Error.Severity.CRITICAL,
1301-
shaka.util.Error.Category.DRM,
1302-
shaka.util.Error.Code.INIT_DATA_TRANSFORM_ERROR,
1303-
error);
1304-
}
1305-
this.onError_(shakaError);
1306-
return;
1307-
}
1308-
13091324
if (this.config_.logLicenseExchange) {
13101325
const str = shaka.util.Uint8ArrayUtils.toBase64(initData);
13111326
shaka.log.info('EME init data: type=', initDataType, 'data=', str);
@@ -1459,7 +1474,8 @@ shaka.drm.DrmEngine = class {
14591474
shaka.util.Error.Severity.CRITICAL,
14601475
shaka.util.Error.Category.DRM,
14611476
shaka.util.Error.Code.LICENSE_REQUEST_FAILED,
1462-
error, drmSessionMetadata);
1477+
error, drmSessionMetadata,
1478+
`activeSessionsSize=${this.activeSessions_.size}`);
14631479
if (this.activeSessions_.size == 1) {
14641480
this.onError_(shakaErr);
14651481
if (metadata && metadata.updatePromise) {
@@ -2243,6 +2259,7 @@ shaka.drm.DrmEngine = class {
22432259
serverCertificateUri: serverCertificateUris[0],
22442260
initData: initDatas,
22452261
keyIds,
2262+
mediaTypes: drmInfos[0].mediaTypes,
22462263
};
22472264

22482265
if (keySystemUris.size > 0) {
@@ -2472,7 +2489,7 @@ shaka.drm.DrmEngine = class {
24722489
}
24732490

24742491
/**
2475-
* Parse pssh from a media segment and announce new initData
2492+
* Parse pssh from a media segment and announce new initData.
24762493
*
24772494
* @param {shaka.util.ManifestParserUtils.ContentType} contentType
24782495
* @param {!BufferSource} mediaSegment

lib/drm/drm_utils.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,15 @@ shaka.drm.DrmUtils = class {
198198
* @param {string} videoCodec
199199
* @param {string} audioCodec
200200
* @param {string} keySystem
201+
* @param {!Array<string>} encryptionSchemes
201202
* @return {string}
202203
* @private
203204
*/
204-
static generateKeySystemCacheKey_(videoCodec, audioCodec, keySystem) {
205-
return `${videoCodec}#${audioCodec}#${keySystem}`;
205+
static generateKeySystemCacheKey_(videoCodec, audioCodec, keySystem,
206+
encryptionSchemes) {
207+
const uniqueSchemes = new Set(encryptionSchemes);
208+
const schemeKey = [...uniqueSchemes].sort().join('#');
209+
return `${videoCodec}#${audioCodec}#${keySystem}#${schemeKey}`;
206210
}
207211

208212
/**
@@ -212,12 +216,14 @@ shaka.drm.DrmUtils = class {
212216
* @param {string} videoCodec
213217
* @param {string} audioCodec
214218
* @param {string} keySystem
219+
* @param {!Array<string>} encryptionSchemes
215220
* @return {boolean}
216221
*/
217-
static hasMediaKeySystemAccess(videoCodec, audioCodec, keySystem) {
222+
static hasMediaKeySystemAccess(videoCodec, audioCodec, keySystem,
223+
encryptionSchemes) {
218224
const DrmUtils = shaka.drm.DrmUtils;
219225
const key = DrmUtils.generateKeySystemCacheKey_(
220-
videoCodec, audioCodec, keySystem);
226+
videoCodec, audioCodec, keySystem, encryptionSchemes);
221227
return DrmUtils.memoizedMediaKeySystemAccessRequests_.has(key);
222228
}
223229

@@ -227,12 +233,14 @@ shaka.drm.DrmUtils = class {
227233
* @param {string} videoCodec
228234
* @param {string} audioCodec
229235
* @param {string} keySystem
236+
* @param {!Array<string>} encryptionSchemes
230237
* @return {?MediaKeySystemAccess}
231238
*/
232-
static getMediaKeySystemAccess(videoCodec, audioCodec, keySystem) {
239+
static getMediaKeySystemAccess(videoCodec, audioCodec, keySystem,
240+
encryptionSchemes) {
233241
const DrmUtils = shaka.drm.DrmUtils;
234242
const key = DrmUtils.generateKeySystemCacheKey_(
235-
videoCodec, audioCodec, keySystem);
243+
videoCodec, audioCodec, keySystem, encryptionSchemes);
236244
return DrmUtils.memoizedMediaKeySystemAccessRequests_.get(key) || null;
237245
}
238246

@@ -242,12 +250,14 @@ shaka.drm.DrmUtils = class {
242250
* @param {string} videoCodec
243251
* @param {string} audioCodec
244252
* @param {string} keySystem
253+
* @param {!Array<string>} encryptionSchemes
245254
* @param {!MediaKeySystemAccess} mksa
246255
*/
247-
static setMediaKeySystemAccess(videoCodec, audioCodec, keySystem, mksa) {
256+
static setMediaKeySystemAccess(videoCodec, audioCodec, keySystem,
257+
encryptionSchemes, mksa) {
248258
const DrmUtils = shaka.drm.DrmUtils;
249259
const key = DrmUtils.generateKeySystemCacheKey_(
250-
videoCodec, audioCodec, keySystem);
260+
videoCodec, audioCodec, keySystem, encryptionSchemes);
251261
DrmUtils.memoizedMediaKeySystemAccessRequests_.set(key, mksa);
252262
}
253263

lib/hls/hls_parser.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,19 +4974,22 @@ shaka.hls.HlsParser = class {
49744974
encryptionScheme = 'cbcs';
49754975
}
49764976

4977-
const uri = drmTag.getRequiredAttrValue('URI');
4977+
const keySystemUri = drmTag.getRequiredAttrValue('URI');
49784978

49794979
/*
49804980
* Even if we're not able to construct initData through the HLS tag, adding
49814981
* a DRMInfo will allow DRM Engine to request a media key system access
49824982
* with the correct keySystem and initDataType
49834983
*/
49844984
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
4985-
'com.apple.fps', encryptionScheme, [
4985+
'com.apple.fps',
4986+
encryptionScheme,
4987+
/* initData= */ [
49864988
{initDataType: 'sinf', initData: new Uint8Array(0), keyId: null},
4987-
], uri);
4989+
],
4990+
keySystemUri);
49884991

4989-
let keyId = shaka.drm.FairPlay.defaultGetKeyId(uri);
4992+
let keyId = shaka.drm.FairPlay.defaultGetKeyId(keySystemUri);
49904993
if (!keyId && initSegmentRef) {
49914994
keyId = await this.getKeyIdFromInitSegment_(initSegmentRef);
49924995
}
@@ -5028,9 +5031,13 @@ shaka.hls.HlsParser = class {
50285031
this.psshToInitData_.set(psshKey, initData);
50295032
}
50305033
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
5031-
'com.widevine.alpha', encryptionScheme, [
5034+
'com.widevine.alpha',
5035+
encryptionScheme,
5036+
/* initData= */ [
50325037
{initDataType: 'cenc', initData: this.psshToInitData_.get(psshKey)},
5033-
]);
5038+
],
5039+
/* keySystemUri= */ undefined,
5040+
/* mediaTypeList= */ parsedData.typeInfoList);
50345041

50355042
const keyId = drmTag.getAttributeValue('KEYID');
50365043
if (keyId) {
@@ -5082,9 +5089,13 @@ shaka.hls.HlsParser = class {
50825089
const pssh =
50835090
shaka.util.Pssh.createPssh(data, systemId, keyIds, psshVersion);
50845091
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
5085-
'com.microsoft.playready', encryptionScheme, [
5092+
/* keySystem= */ 'com.microsoft.playready',
5093+
encryptionScheme,
5094+
/* initData= */ [
50865095
{initDataType: 'cenc', initData: pssh},
5087-
]);
5096+
],
5097+
/* keySystemUri= */ undefined,
5098+
/* mediaTypeList= */ parsedData.typeInfoList);
50885099

50895100
const input = shaka.util.TXml.parseXmlString([
50905101
'<PLAYREADY>',
@@ -5129,9 +5140,13 @@ shaka.hls.HlsParser = class {
51295140
this.psshToInitData_.set(psshKey, initData);
51305141
}
51315142
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
5132-
'com.huawei.wiseplay', encryptionScheme, [
5143+
/* keySystem= */ 'com.huawei.wiseplay',
5144+
encryptionScheme,
5145+
/* initData= */ [
51335146
{initDataType: 'cenc', initData: this.psshToInitData_.get(psshKey)},
5134-
]);
5147+
],
5148+
/* keySystemUri= */ undefined,
5149+
/* mediaTypeList= */ parsedData.typeInfoList);
51355150

51365151
const keyId = drmTag.getAttributeValue('KEYID');
51375152
if (keyId) {

lib/media/adaptation_set.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
goog.provide('shaka.media.AdaptationSet');
88

99
goog.require('goog.asserts');
10-
goog.require('shaka.log');
10+
// goog.require('shaka.log');
1111
goog.require('shaka.util.ArrayUtils');
1212
goog.require('shaka.util.MimeUtils');
1313

@@ -57,7 +57,8 @@ shaka.media.AdaptationSet = class {
5757

5858
// To be nice, issue a warning if someone is trying to add something that
5959
// they shouldn't.
60-
shaka.log.warning('Rejecting variant - not compatible with root.');
60+
// shaka.log.warning('[APPLE, AdaptationSet]: Rejecting variant - not compatible with root: ' +
61+
// `videoId=${variant.video.id};audioId=${variant.audio.id};${variant.audio.language};${variant.audio.label}`);
6162
return false;
6263
}
6364

lib/media/content_workarounds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ shaka.media.ContentWorkarounds = class {
360360
// changed, because they should all be within the first section we copy.
361361
for (const box of ancestorBoxes) {
362362
goog.asserts.assert(box.start < cutPoint,
363-
'Ancestor MP4 box found in the wrong location! ' +
363+
`Ancestor MP4 box ${box.name} found in the wrong location! ` +
364364
'Modified init segment will not make sense!');
365365
ContentWorkarounds.updateBoxSize_(
366366
newInitSegment, box.start, box.size + metadataBoxArray.byteLength);

0 commit comments

Comments
 (0)