Skip to content

Commit

Permalink
chore: Rename hlsAes128Key to aes128Key (#5653)
Browse files Browse the repository at this point in the history
This change is required in preparation for
#5622
  • Loading branch information
avelad authored Sep 13, 2023
1 parent bc99401 commit 7874667
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 52 deletions.
10 changes: 5 additions & 5 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ shaka.extern.CreateSegmentIndexFunction;
* }}
*
* @description
* AES-128 key and iv info from the HLS manifest.
* AES-128 key and iv info from the manifest.
*
* @property {string} method
* The key method defined in the HLS manifest.
* The key method defined in the manifest.
* @property {webCrypto.CryptoKey|undefined} cryptoKey
* Web crypto key object of the AES-128 CBC key. If unset, the "fetchKey"
* property should be provided.
Expand All @@ -330,15 +330,15 @@ shaka.extern.CreateSegmentIndexFunction;
* Should be provided if the "cryptoKey" property is unset.
* Should update this object in-place, to set "cryptoKey".
* @property {(!Uint8Array|undefined)} iv
* The IV in the HLS manifest, if defined. See HLS RFC 8216 Section 5.2 for
* handling undefined IV.
* The IV in the manifest, if defined. For HLS see HLS RFC 8216 Section 5.2
* for handling undefined IV.
* @property {number} firstMediaSequenceNumber
* The starting Media Sequence Number of the playlist, used when IV is
* undefined.
*
* @exportDoc
*/
shaka.extern.HlsAes128Key;
shaka.extern.aes128Key;


/**
Expand Down
20 changes: 10 additions & 10 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ shaka.hls.HlsParser = class {
/**
* @param {!shaka.hls.Tag} drmTag
* @param {!shaka.hls.Playlist} playlist
* @return {!shaka.extern.HlsAes128Key}
* @return {!shaka.extern.aes128Key}
* @private
*/
parseAES128DrmTag_(drmTag, playlist) {
Expand Down Expand Up @@ -2882,14 +2882,14 @@ shaka.hls.HlsParser = class {
* @param {string} type
* @param {string} mimeType
* @param {number} timestampOffset
* @param {shaka.extern.HlsAes128Key=} hlsAes128Key
* @param {shaka.extern.aes128Key=} aes128Key
* @return {shaka.media.SegmentReference}
* @private
*/
createSegmentReference_(
initSegmentReference, previousReference, hlsSegment, startTime,
variables, absoluteMediaPlaylistUri, type, mimeType, timestampOffset,
hlsAes128Key) {
aes128Key) {
const tags = hlsSegment.tags;
const extinfTag =
shaka.hls.Utils.getFirstTagWithName(tags, 'EXTINF');
Expand Down Expand Up @@ -3034,7 +3034,7 @@ shaka.hls.HlsParser = class {
/* tileDuration= */ null,
partialSyncTime,
partialStatus,
hlsAes128Key);
aes128Key);
if (item.name == 'EXT-X-PRELOAD-HINT') {
partial.markAsPreload();
isPreloadSegment = true;
Expand Down Expand Up @@ -3143,7 +3143,7 @@ shaka.hls.HlsParser = class {
tileDuration,
syncTime,
status,
hlsAes128Key,
aes128Key,
);

if (segmentWithByteRangeOptimization) {
Expand Down Expand Up @@ -3210,8 +3210,8 @@ shaka.hls.HlsParser = class {
/** @type {shaka.media.InitSegmentReference} */
let initSegmentRef;

/** @type {shaka.extern.HlsAes128Key|undefined} */
let hlsAes128Key = undefined;
/** @type {shaka.extern.aes128Key|undefined} */
let aes128Key = undefined;

let discontinuitySequence = shaka.hls.Utils.getFirstTagWithNameAsNumber(
playlist.tags, 'EXT-X-DISCONTINUITY-SEQUENCE', 0);
Expand Down Expand Up @@ -3256,9 +3256,9 @@ shaka.hls.HlsParser = class {
for (const drmTag of item.tags) {
if (drmTag.name == 'EXT-X-KEY') {
if (drmTag.getRequiredAttrValue('METHOD') == 'AES-128') {
hlsAes128Key = this.parseAES128DrmTag_(drmTag, playlist);
aes128Key = this.parseAES128DrmTag_(drmTag, playlist);
} else {
hlsAes128Key = undefined;
aes128Key = undefined;
}
}
}
Expand Down Expand Up @@ -3290,7 +3290,7 @@ shaka.hls.HlsParser = class {
type,
mimeType,
lastDiscontinuityStartTime,
hlsAes128Key);
aes128Key);

if (reference) {
const bitrate = shaka.hls.Utils.getFirstTagWithNameAsNumber(
Expand Down
2 changes: 1 addition & 1 deletion lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ shaka.media.SegmentIndex = class {
lastReference.tileDuration,
lastReference.syncTime,
lastReference.status,
lastReference.hlsAes128Key,
lastReference.aes128Key,
);
this.references[this.references.length - 1].discontinuitySequence =
lastReference.discontinuitySequence;
Expand Down
8 changes: 4 additions & 4 deletions lib/media/segment_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ shaka.media.SegmentReference = class {
* @param {shaka.media.SegmentReference.Status=} status
* The segment status is used to indicate that a segment does not exist or is
* not available.
* @param {?shaka.extern.HlsAes128Key=} hlsAes128Key
* @param {?shaka.extern.aes128Key=} aes128Key
* The segment's AES-128-CBC full segment encryption key and iv.
*/
constructor(
startTime, endTime, uris, startByte, endByte, initSegmentReference,
timestampOffset, appendWindowStart, appendWindowEnd,
partialReferences = [], tilesLayout = '', tileDuration = null,
syncTime = null, status = shaka.media.SegmentReference.Status.AVAILABLE,
hlsAes128Key = null) {
aes128Key = null) {
// A preload hinted Partial Segment has the same startTime and endTime.
goog.asserts.assert(startTime <= endTime,
'startTime must be less than or equal to endTime');
Expand Down Expand Up @@ -271,8 +271,8 @@ shaka.media.SegmentReference = class {
/** @type {boolean} */
this.byterangeOptimization = false;

/** @type {?shaka.extern.HlsAes128Key} */
this.hlsAes128Key = hlsAes128Key;
/** @type {?shaka.extern.aes128Key} */
this.aes128Key = aes128Key;

/** @type {?shaka.media.SegmentReference.ThumbnailSprite} */
this.thumbnailSprite = null;
Expand Down
4 changes: 2 additions & 2 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ shaka.media.StreamingEngine = class {
if (this.fatalError_) {
return;
}
if (reference.hlsAes128Key) {
if (reference.aes128Key) {
goog.asserts.assert(iter, 'mediaState.segmentIterator should exist');
result = await this.aes128Decrypt_(result, reference, iter);
}
Expand Down Expand Up @@ -1508,7 +1508,7 @@ shaka.media.StreamingEngine = class {
* @private
*/
async aes128Decrypt_(rawResult, reference, iter) {
const key = reference.hlsAes128Key;
const key = reference.aes128Key;
if (!key.cryptoKey) {
goog.asserts.assert(key.fetchKey, 'If AES-128 cryptoKey was not ' +
'preloaded, fetchKey function should be provided');
Expand Down
8 changes: 4 additions & 4 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3182,19 +3182,19 @@ describe('HlsParser', () => {
'Null segmentIndex!');

const firstMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(0);
expect(firstMp4Segment.hlsAes128Key).toBeDefined();
expect(firstMp4Segment.aes128Key).toBeDefined();
const secondMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(1);
expect(secondMp4Segment.hlsAes128Key).toBeNull();
expect(secondMp4Segment.aes128Key).toBeNull();

const tsAesEncryptionVideo = actual.variants[2].video;
await tsAesEncryptionVideo.createSegmentIndex();
goog.asserts.assert(tsAesEncryptionVideo.segmentIndex != null,
'Null segmentIndex!');

const firstTsSegment = tsAesEncryptionVideo.segmentIndex.get(0);
expect(firstTsSegment.hlsAes128Key).toBeDefined();
expect(firstTsSegment.aes128Key).toBeDefined();
const secondTsSegment = tsAesEncryptionVideo.segmentIndex.get(1);
expect(secondTsSegment.hlsAes128Key).toBeNull();
expect(secondTsSegment.aes128Key).toBeNull();
});

it('fails on AES-128 if WebCrypto APIs are not available', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/media/segment_index_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {

index.fit(/* windowStart= */ 0, /* windowEnd= */ 10);
expect(
index.references[index.references.length - 1].hlsAes128Key,
index.references[index.references.length - 1].aes128Key,
).toEqual({method: 'AES-128', firstMediaSequenceNumber: 0});
});
});
Expand Down Expand Up @@ -1054,11 +1054,11 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
* @param {number} startTime
* @param {number} endTime
* @param {!Array.<!shaka.media.SegmentReference>=} partialReferences
* @param {?shaka.extern.HlsAes128Key=} hlsAes128Key
* @param {?shaka.extern.aes128Key=} aes128Key
* @return {shaka.media.SegmentReference}
*/
function makeReference(uri, startTime, endTime, partialReferences = [],
hlsAes128Key = null) {
aes128Key = null) {
return new shaka.media.SegmentReference(
startTime,
endTime,
Expand All @@ -1074,6 +1074,6 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
/* tileDuration= */ undefined,
/* syncTime= */ undefined,
/* status= */ undefined,
/* hlsAes128Key= */ hlsAes128Key);
/* aes128Key= */ aes128Key);
}
});
2 changes: 1 addition & 1 deletion test/media/segment_prefetch_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('SegmentPrefetch', () => {
/* tileDuration= */ undefined,
/* syncTime= */ undefined,
/* status= */ undefined,
/* hlsAes128Key= */ null);
/* aes128Key= */ null);
}

/**
Expand Down
34 changes: 17 additions & 17 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ describe('StreamingEngine', () => {
/**
* @param {boolean=} trickMode
* @param {number=} mediaOffset The offset from 0 for the segment start times
* @param {shaka.extern.HlsAes128Key=} hlsAes128Key The AES-128 key to put in
* @param {shaka.extern.aes128Key=} aes128Key The AES-128 key to put in
* the manifest, if one should exist
*/
function setupVod(trickMode, mediaOffset, hlsAes128Key) {
function setupVod(trickMode, mediaOffset, aes128Key) {
// For VOD, we fake a presentation that has 2 Periods of equal duration
// (20 seconds), where each Period has 1 Variant and 1 text stream.
//
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('StreamingEngine', () => {
/* firstPeriodStartTime= */ 0,
/* secondPeriodStartTime= */ 20,
/* presentationDuration= */ 40,
hlsAes128Key);
aes128Key);
}

function setupLive() {
Expand Down Expand Up @@ -370,11 +370,11 @@ describe('StreamingEngine', () => {
* @param {number} firstPeriodStartTime
* @param {number} secondPeriodStartTime
* @param {number} presentationDuration
* @param {shaka.extern.HlsAes128Key=} hlsAes128Key
* @param {shaka.extern.aes128Key=} aes128Key
*/
function setupManifest(
firstPeriodStartTime, secondPeriodStartTime, presentationDuration,
hlsAes128Key) {
aes128Key) {
const segmentDurations = {
audio: segmentData[ContentType.AUDIO].segmentDuration,
video: segmentData[ContentType.VIDEO].segmentDuration,
Expand All @@ -397,7 +397,7 @@ describe('StreamingEngine', () => {
/** @type {!shaka.media.PresentationTimeline} */(timeline),
[firstPeriodStartTime, secondPeriodStartTime],
presentationDuration, segmentDurations, initSegmentRanges,
timestampOffsets, hlsAes128Key);
timestampOffsets, aes128Key);

audioStream = manifest.variants[0].audio;
videoStream = manifest.variants[0].video;
Expand Down Expand Up @@ -3809,8 +3809,8 @@ describe('StreamingEngine', () => {

describe('AES-128', () => {
let key;
/** @type {!shaka.extern.HlsAes128Key} */
let hlsAes128Key;
/** @type {!shaka.extern.aes128Key} */
let aes128Key;

beforeEach(async () => {
// Get a key.
Expand All @@ -3823,10 +3823,10 @@ describe('StreamingEngine', () => {
// Set up a manifest with AES-128 key info.
// We don't actually provide the imported key OR the key fetching function
// here, though, so that the individual tests can choose what the starting
// state of the hlsAes128Key object is.
hlsAes128Key = {method: 'AES-128', firstMediaSequenceNumber: 0};
// state of the aes128Key object is.
aes128Key = {method: 'AES-128', firstMediaSequenceNumber: 0};

setupVod(false, 0, hlsAes128Key);
setupVod(false, 0, aes128Key);
mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData);
presentationTimeInSeconds = 0;
createStreamingEngine();
Expand All @@ -3851,22 +3851,22 @@ describe('StreamingEngine', () => {
}

it('decrypts segments', async () => {
hlsAes128Key.cryptoKey = key;
aes128Key.cryptoKey = key;
await runTest();
});

it('downloads key if not pre-filled', async () => {
hlsAes128Key.fetchKey = () => {
hlsAes128Key.cryptoKey = key;
hlsAes128Key.fetchKey = undefined;
aes128Key.fetchKey = () => {
aes128Key.cryptoKey = key;
aes128Key.fetchKey = undefined;
return Promise.resolve();
};

await runTest();

// The key should have been fetched.
expect(hlsAes128Key.cryptoKey).not.toBeUndefined();
expect(hlsAes128Key.fetchKey).toBeUndefined();
expect(aes128Key.cryptoKey).not.toBeUndefined();
expect(aes128Key.fetchKey).toBeUndefined();
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/test/util/streaming_engine_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ shaka.test.StreamingEngineUtil = class {
* ranges for each type of init segment.
* @param {!Object.<string,number>=} timestampOffsets The timestamp offset
* for each type of segment
* @param {shaka.extern.HlsAes128Key=} hlsAes128Key The AES-128 key to provide
* @param {shaka.extern.aes128Key=} aes128Key The AES-128 key to provide
* to streams, if desired.
* @return {shaka.extern.Manifest}
*/
static createManifest(
presentationTimeline, periodStartTimes, presentationDuration,
segmentDurations, initSegmentRanges, timestampOffsets, hlsAes128Key) {
segmentDurations, initSegmentRanges, timestampOffsets, aes128Key) {
const Util = shaka.test.Util;

/**
Expand Down Expand Up @@ -268,9 +268,9 @@ shaka.test.StreamingEngineUtil = class {
appendWindowStart,
appendWindowEnd);
const ContentType = shaka.util.ManifestParserUtils.ContentType;
if (hlsAes128Key &&
if (aes128Key &&
(type == ContentType.AUDIO || type == ContentType.VIDEO)) {
ref.hlsAes128Key = hlsAes128Key;
ref.aes128Key = aes128Key;
}
return ref;
};
Expand Down

0 comments on commit 7874667

Please sign in to comment.