Skip to content

Commit 7e716ef

Browse files
committed
fix: Avoid launch RESTRICTIONS_CANNOT_BE_MET when it's not necessary (#8014)
This can happen with HLS, when there is Widevine with keyId and PlayReady without keyId and the system only supports Playready.
1 parent a35e9d7 commit 7e716ef

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

lib/player.js

+40-10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ goog.require('shaka.util.Functional');
5555
goog.require('shaka.util.IDestroyable');
5656
goog.require('shaka.util.LanguageUtils');
5757
goog.require('shaka.util.ManifestParserUtils');
58+
goog.require('shaka.util.MapUtils');
5859
goog.require('shaka.util.MediaReadyState');
5960
goog.require('shaka.util.MimeUtils');
6061
goog.require('shaka.util.Mutex');
@@ -7991,6 +7992,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
79917992

79927993
// Only filter tracks for keys if we have some key statuses to look at.
79937994
if (keyIds.length) {
7995+
const currentKeySystem = this.keySystem();
7996+
const clearKeys = shaka.util.MapUtils.asMap(this.config_.drm.clearKeys);
7997+
79947998
for (const variant of this.manifest_.variants) {
79957999
const streams = shaka.util.StreamUtils.getVariantStreams(variant);
79968000

@@ -8000,16 +8004,42 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
80008004
// Only update if we have key IDs for the stream. If the keys aren't
80018005
// all present, then the track should be restricted.
80028006
if (stream.keyIds.size) {
8003-
variant.allowedByKeySystem = true;
8004-
8005-
for (const keyId of stream.keyIds) {
8006-
const keyStatus = keyStatusMap[isGlobalStatus ? '00' : keyId];
8007-
if (keyStatus || this.drmEngine_.hasManifestInitData()) {
8008-
variant.allowedByKeySystem = variant.allowedByKeySystem &&
8009-
!!keyStatus && !restrictedStatuses.includes(keyStatus);
8010-
}
8011-
}
8012-
}
8007+
// If we are not using clearkeys, and the stream has drmInfos we
8008+
// only want to check the keyIds of the keySystem we are using.
8009+
// Other keySystems might have other keyIds that might not be
8010+
// valid in this case. This can happen in HLS if the manifest
8011+
// has Widevine with keyIds and PlayReady without keyIds and we are
8012+
// using PlayReady.
8013+
if (stream.drmInfos.length && !clearKeys.size) {
8014+
for (const drmInfo of stream.drmInfos) {
8015+
if (drmInfo.keyIds.size &&
8016+
drmInfo.keySystem == currentKeySystem) {
8017+
variant.allowedByKeySystem = true;
8018+
8019+
for (const keyId of drmInfo.keyIds) {
8020+
const keyStatus =
8021+
keyStatusMap[isGlobalStatus ? '00' : keyId];
8022+
if (keyStatus || this.drmEngine_.hasManifestInitData()) {
8023+
variant.allowedByKeySystem =
8024+
variant.allowedByKeySystem &&
8025+
!!keyStatus &&
8026+
!restrictedStatuses.includes(keyStatus);
8027+
} // if (keyStatus || this.drmEngine_.hasManifestInitData())
8028+
} // for (const keyId of drmInfo.keyIds)
8029+
} // if (drmInfo.keyIds.size && ...
8030+
} // for (const drmInfo of stream.drmInfos
8031+
} else {
8032+
variant.allowedByKeySystem = true;
8033+
8034+
for (const keyId of stream.keyIds) {
8035+
const keyStatus = keyStatusMap[isGlobalStatus ? '00' : keyId];
8036+
if (keyStatus || this.drmEngine_.hasManifestInitData()) {
8037+
variant.allowedByKeySystem = variant.allowedByKeySystem &&
8038+
!!keyStatus && !restrictedStatuses.includes(keyStatus);
8039+
}
8040+
} // for (const keyId of stream.keyIds)
8041+
} // if (stream.drmInfos.length && !clearKeys.size)
8042+
} // if (stream.keyIds.size)
80138043

80148044
if (originalAllowed != variant.allowedByKeySystem) {
80158045
tracksChanged = true;

0 commit comments

Comments
 (0)