Skip to content

Commit

Permalink
Move drmInfos array to Stream
Browse files Browse the repository at this point in the history
Period-flattening will concatenate Stream objects, so this information
should be available per-Stream instead of at the Variant level.

Issue shaka-project#1339

Change-Id: I96195fea48cab1e4a349b2ab0b16064a443e928a
  • Loading branch information
joeyparrish committed Apr 9, 2020
1 parent 5d07b5f commit e8ac57f
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 233 deletions.
23 changes: 11 additions & 12 deletions docs/tutorials/manifest-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ MyManifestParser.prototype.loadVariant_ = function(hasVideo, hasAudio) {
audio: hasAudio ? this.loadStream_('audio') : null,
video: hasVideo ? this.loadStream_('video') : null,
bandwidth: 8000, // bits/sec, audio+video combined
drmInfos: [],
allowedByApplication: true, // always initially true
allowedByKeySystem: true // always initially true
};
Expand Down Expand Up @@ -313,6 +312,7 @@ MyManifestParser.prototype.loadStream_ = function(type) {
kind: type == 'text' ? 'subtitles' : undefined,
channelsCount: type == 'audio' ? 2 : undefined,
encrypted: false,
drmInfos: [],
keyId: null,
language: 'en',
label: 'my_stream',
Expand Down Expand Up @@ -342,17 +342,16 @@ MyManifestParser.prototype.loadReference_ =
## Encrypted Content

If your content is encrypted, there are a few changes to the manifest you need
to do. First, for each Variant that contains encrypted content, you need to set
`variant.drmInfos` to an array of {@link shaka.extern.DrmInfo} objects. All the
fields (except the key-system name) can be set to the default and will be
replaced by settings from the Player configuration. If the `drmInfos` array
is empty, the content is expected to be clear.

In each stream that is encrypted, set `stream.encrypted` to `true` and
optionally set `stream.keyId` to the key ID that the stream is encrypted with.
The `keyId` field is optional, but it allows the player to choose streams more
intelligently based on which keys are available. If `keyId` is omitted, missing
keys may cause playback to stall.
to do. First, for each Stream that contains encrypted content, you need to set
`stream.encrypted` to true and set `stream.keyId` to the key ID that the stream
is encrypted with. The `keyId` field is technically optional, but it allows the
player to choose streams more intelligently based on which keys are available.
If `keyId` is omitted, missing keys may cause playback to stall.

You must also set `stream.drmInfos` to an array of {@link shaka.extern.DrmInfo}
objects. All the fields (except the key-system name) can be set to the default
and will be replaced by settings from the Player configuration. If the
`drmInfos` array is empty, the content is expected to be clear.

If you set `drmInfo.initData` to a non-empty array, we will use that to
initialize EME. We will override any encryption info in the media (e.g.
Expand Down
10 changes: 5 additions & 5 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ shaka.extern.DrmInfo;
* audio: ?shaka.extern.Stream,
* video: ?shaka.extern.Stream,
* bandwidth: number,
* drmInfos: !Array.<shaka.extern.DrmInfo>,
* allowedByApplication: boolean,
* allowedByKeySystem: boolean
* }}
Expand Down Expand Up @@ -191,10 +190,6 @@ shaka.extern.DrmInfo;
* The video stream of the variant.
* @property {number} bandwidth
* The variant's required bandwidth in bits per second.
* @property {!Array.<!shaka.extern.DrmInfo>} drmInfos
* <i>Defaults to [] (i.e., no DRM).</i> <br>
* An array of DrmInfo objects which describe DRM schemes are compatible with
* the content.
* @property {boolean} allowedByApplication
* <i>Defaults to true.</i><br>
* Set by the Player to indicate whether the variant is allowed to be played
Expand Down Expand Up @@ -234,6 +229,7 @@ shaka.extern.CreateSegmentIndexFunction;
* height: (number|undefined),
* kind: (string|undefined),
* encrypted: boolean,
* drmInfos: !Array.<shaka.extern.DrmInfo>,
* keyIds: !Array.<string>,
* language: string,
* label: ?string,
Expand Down Expand Up @@ -294,6 +290,10 @@ shaka.extern.CreateSegmentIndexFunction;
* @property {boolean} encrypted
* <i>Defaults to false.</i><br>
* True if the stream is encrypted.
* @property {!Array.<!shaka.extern.DrmInfo>} drmInfos
* <i>Defaults to [] (i.e., no DRM).</i> <br>
* An array of DrmInfo objects which describe DRM schemes are compatible with
* the content.
* @property {!Array.<string>} keyIds
* <i>Defaults to empty (i.e., unencrypted or key ID unknown).</i> <br>
* The stream's key IDs as lowercase hex strings. These key IDs identify the
Expand Down
6 changes: 1 addition & 5 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,6 @@ shaka.dash.DashParser = class {
// Audio+video variants.
const DrmEngine = shaka.media.DrmEngine;
if (DrmEngine.areDrmCompatible(audio.drmInfos, video.drmInfos)) {
const drmInfos = DrmEngine.getCommonDrmInfos(audio.drmInfos,
video.drmInfos);

for (const audioStream of audio.streams) {
for (const videoStream of video.streams) {
bandwidth =
Expand All @@ -701,7 +698,6 @@ shaka.dash.DashParser = class {
audio: audioStream,
video: videoStream,
bandwidth: bandwidth,
drmInfos: drmInfos,
allowedByApplication: true,
allowedByKeySystem: true,
};
Expand All @@ -722,7 +718,6 @@ shaka.dash.DashParser = class {
audio: audio ? stream : null,
video: video ? stream : null,
bandwidth: bandwidth,
drmInfos: set.drmInfos,
allowedByApplication: true,
allowedByKeySystem: true,
};
Expand Down Expand Up @@ -1072,6 +1067,7 @@ shaka.dash.DashParser = class {
height: context.representation.height,
kind,
encrypted: contentProtection.drmInfos.length > 0,
drmInfos: contentProtection.drmInfos,
keyIds,
language,
label,
Expand Down
46 changes: 17 additions & 29 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,28 +866,20 @@ shaka.hls.HlsParser = class {
for (const videoInfo of videoInfos) {
const audioStream = audioInfo ? audioInfo.stream : null;
const videoStream = videoInfo ? videoInfo.stream : null;
const audioDrmInfos = audioInfo ? audioInfo.drmInfos : null;
const videoDrmInfos = videoInfo ? videoInfo.drmInfos : null;
const audioDrmInfos = audioInfo ? audioInfo.stream.drmInfos : null;
const videoDrmInfos = videoInfo ? videoInfo.stream.drmInfos : null;
const videoStreamUri =
videoInfo ? videoInfo.verbatimMediaPlaylistUri : '';
videoInfo ? videoInfo.verbatimMediaPlaylistUri : '';
const audioStreamUri =
audioInfo ? audioInfo.verbatimMediaPlaylistUri : '';
audioInfo ? audioInfo.verbatimMediaPlaylistUri : '';
const variantUriKey = videoStreamUri + ' - ' + audioStreamUri;

let drmInfos;
if (audioStream && videoStream) {
if (DrmEngine.areDrmCompatible(audioDrmInfos, videoDrmInfos)) {
drmInfos =
DrmEngine.getCommonDrmInfos(audioDrmInfos, videoDrmInfos);
} else {
if (!DrmEngine.areDrmCompatible(audioDrmInfos, videoDrmInfos)) {
shaka.log.warning(
'Incompatible DRM info in HLS variant. Skipping.');
continue;
}
} else if (audioStream) {
drmInfos = audioDrmInfos;
} else if (videoStream) {
drmInfos = videoDrmInfos;
}

if (this.variantUriSet_.has(variantUriKey)) {
Expand All @@ -911,8 +903,7 @@ shaka.hls.HlsParser = class {
(!!videoStream && videoStream.primary),
audio: audioStream,
video: videoStream,
bandwidth: bandwidth,
drmInfos: drmInfos,
bandwidth,
allowedByApplication: true,
allowedByKeySystem: true,
};
Expand Down Expand Up @@ -1182,16 +1173,17 @@ shaka.hls.HlsParser = class {
id: this.globalId_++,
originalId: name,
createSegmentIndex: () => Promise.resolve(),
segmentIndex: segmentIndex,
mimeType: mimeType,
codecs: codecs,
kind: kind,
encrypted: encrypted,
segmentIndex,
mimeType,
codecs,
kind,
encrypted,
drmInfos,
keyIds: [keyId],
language: language,
language,
label: name, // For historical reasons, since before "originalId".
type: type,
primary: primary,
type,
primary,
// TODO: trick mode
trickModeVideo: null,
emsgSchemeIdUris: null,
Expand All @@ -1201,14 +1193,13 @@ shaka.hls.HlsParser = class {
height: undefined,
bandwidth: undefined,
roles: [],
channelsCount: channelsCount,
channelsCount,
audioSamplingRate: null,
closedCaptions: closedCaptions,
closedCaptions,
};

return {
stream,
drmInfos,
verbatimMediaPlaylistUri,
absoluteMediaPlaylistUri,
minTimestamp,
Expand Down Expand Up @@ -2213,7 +2204,6 @@ shaka.hls.HlsParser = class {
/**
* @typedef {{
* stream: !shaka.extern.Stream,
* drmInfos: !Array.<shaka.extern.DrmInfo>,
* verbatimMediaPlaylistUri: string,
* absoluteMediaPlaylistUri: string,
* minTimestamp: number,
Expand All @@ -2226,8 +2216,6 @@ shaka.hls.HlsParser = class {
*
* @property {!shaka.extern.Stream} stream
* The Stream itself.
* @property {!Array.<shaka.extern.DrmInfo>} drmInfos
* DrmInfos of the stream. There may be multiple for multi-DRM content.
* @property {string} verbatimMediaPlaylistUri
* The verbatim media playlist URI, as it appeared in the master playlist.
* This has not been canonicalized into an absolute URI. This gives us a
Expand Down
Loading

0 comments on commit e8ac57f

Please sign in to comment.