Skip to content

Commit

Permalink
chore: Add encrypted flag to init segments (#8182)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Feb 27, 2025
1 parent 22ed2be commit 5debddc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,8 @@ shaka.dash.DashParser = class {
this.config_.ignoreDrmInfo,
this.config_.dash.keySystemsByURI);

context.adaptationSet.encrypted = contentProtection.drmInfos.length > 0;

const language = shaka.util.LanguageUtils.normalize(
context.adaptationSet.language || 'und');

Expand Down Expand Up @@ -2624,6 +2626,7 @@ shaka.dash.DashParser = class {
audioSamplingRate: null,
availabilityTimeOffset: 0,
segmentSequenceCadence: 0,
encrypted: false,
});
getBaseUris = getBaseUris || parent.getBaseUris;

Expand Down Expand Up @@ -2756,6 +2759,7 @@ shaka.dash.DashParser = class {
segmentSequenceCadence:
segmentSequenceCadence || parent.segmentSequenceCadence,
label: label || null,
encrypted: false,
};
}

Expand Down Expand Up @@ -3306,7 +3310,8 @@ shaka.dash.DashParser.RequestSegmentCallback;
* initialization: ?string,
* aesKey: (shaka.extern.aesKey|undefined),
* segmentSequenceCadence: number,
* label: ?string
* label: ?string,
* encrypted: boolean
* }}
*
* @description
Expand Down Expand Up @@ -3360,6 +3365,8 @@ shaka.dash.DashParser.RequestSegmentCallback;
* Representation.
* @property {?string} label
* Label or null if unknown.
* @property {boolean} encrypted
* Specifies is encrypted or not.
*/
shaka.dash.DashParser.InheritanceFrame;

Expand Down
4 changes: 3 additions & 1 deletion lib/dash/segment_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ shaka.dash.SegmentBase = class {

const getUris = () => resolvedUris;
const qualityInfo = shaka.dash.SegmentBase.createQualityInfo(context);
const encrypted = context.adaptationSet.encrypted;
const ref = new shaka.media.InitSegmentReference(
getUris,
startByte,
endByte,
qualityInfo,
/* timescale= */ null,
/* segmentData= */ null,
aesKey);
aesKey,
encrypted);
ref.codecs = context.representation.codecs;
ref.mimeType = context.representation.mimeType;
return ref;
Expand Down
4 changes: 3 additions & 1 deletion lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,16 @@ shaka.dash.SegmentTemplate = class {
return resolvedUris;
};
const qualityInfo = shaka.dash.SegmentBase.createQualityInfo(context);
const encrypted = context.adaptationSet.encrypted;
const ref = new shaka.media.InitSegmentReference(
getUris,
/* startByte= */ 0,
/* endByte= */ null,
qualityInfo,
/* timescale= */ null,
/* segmentData= */ null,
aesKey);
aesKey,
encrypted);
ref.codecs = context.representation.codecs;
ref.mimeType = context.representation.mimeType;
return ref;
Expand Down
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 5debddc

Please sign in to comment.