Skip to content

Commit

Permalink
chore: Add encrypted flag to init segments
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Feb 27, 2025
1 parent 6c01f18 commit 0d5980d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3604,19 +3604,23 @@ shaka.hls.HlsParser = class {
/** @type {shaka.extern.aesKey|undefined} */
let aesKey = undefined;
let byteRangeTag = null;
let encrypted = false;
for (const tag of tags) {
if (tag.name == 'EXT-X-KEY') {
if (this.isAesMethod_(tag.getRequiredAttrValue('METHOD')) &&
tag.id < mapTag.id) {
const method = tag.getRequiredAttrValue('METHOD');
if (this.isAesMethod_(method) && tag.id < mapTag.id) {
encrypted = false;
aesKey =
this.parseAESDrmTag_(tag, playlist, getUris, variables);
} else {
encrypted = method != 'NONE';
}
} else if (tag.name == 'EXT-X-BYTERANGE' && tag.id < mapTag.id) {
byteRangeTag = tag;
}
}
const initSegmentRef = this.createInitSegmentReference_(
absoluteInitSegmentUris, mapTag, byteRangeTag, aesKey);
absoluteInitSegmentUris, mapTag, byteRangeTag, aesKey, encrypted);
this.mapTagToInitSegmentRefMap_.set(mapTagKey, initSegmentRef);
}
return this.mapTagToInitSegmentRefMap_.get(mapTagKey);
Expand All @@ -3629,11 +3633,12 @@ shaka.hls.HlsParser = class {
* @param {!shaka.hls.Tag} mapTag EXT-X-MAP
* @param {shaka.hls.Tag=} byteRangeTag EXT-X-BYTERANGE
* @param {shaka.extern.aesKey=} aesKey
* @param {boolean=} encrypted
* @return {!shaka.media.InitSegmentReference}
* @private
*/
createInitSegmentReference_(absoluteInitSegmentUris, mapTag, byteRangeTag,
aesKey) {
aesKey, encrypted) {
let startByte = 0;
let endByte = null;
let byterange = mapTag.getAttributeValue('BYTERANGE');
Expand Down Expand Up @@ -3666,7 +3671,8 @@ shaka.hls.HlsParser = class {
/* mediaQuality= */ null,
/* timescale= */ null,
/* segmentData= */ null,
aesKey);
aesKey,
encrypted);
return initSegmentRef;
}

Expand Down
6 changes: 5 additions & 1 deletion lib/media/segment_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ shaka.media.InitSegmentReference = class {
* @param {(null|BufferSource)=} segmentData
* @param {?shaka.extern.aesKey=} aesKey
* The segment's AES-128-CBC full segment encryption key and iv.
* @param {boolean=} encrypted
*/
constructor(uris, startByte, endByte, mediaQuality = null, timescale = null,
segmentData = null, aesKey = null) {
segmentData = null, aesKey = null, encrypted = false) {
/** @type {function(): !Array<string>} */
this.getUris = uris;

Expand All @@ -63,6 +64,9 @@ shaka.media.InitSegmentReference = class {

/** @type {?string} */
this.mimeType = null;

/** @const {boolean} */
this.encrypted = encrypted;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/mss/mss_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,9 @@ shaka.mss.MssParser = class {
/* endByte= */ null,
qualityInfo,
stream.mssPrivateData.timescale,
initSegmentData);
initSegmentData,
/* aesKey= */ null,
stream.encrypted);

const segments = this.createSegments_(initSegmentRef,
stream, streamIndex, timeline);
Expand Down

0 comments on commit 0d5980d

Please sign in to comment.