Skip to content

Commit c872af4

Browse files
icbakercopybara-github
authored andcommitted
Consolidate requiresSecureDecoder logic in ExoMediaDrm
This change: 1. Updates the implementation of `FrameworkMediaDrm.requiresSecureDecoder` to include the 'force allow insecure decoder' workaround logic. 2. Removes the 'force allow insecure decoder' logic from MCR 3. Removes the `requiresSecureDecoder` field from MCR (it can just be a local derived from `codecDrmSession` now). PiperOrigin-RevId: 607664186
1 parent fa3212e commit c872af4

3 files changed

Lines changed: 38 additions & 46 deletions

File tree

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/FrameworkCryptoConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ public final class FrameworkCryptoConfig implements CryptoConfig {
4747
public final byte[] sessionId;
4848

4949
/**
50-
* Whether to allow use of insecure decoder components even if the underlying platform says
51-
* otherwise.
50+
* @deprecated Use {@link ExoMediaDrm#requiresSecureDecoder} instead, which incorporates this
51+
* logic.
5252
*/
53-
public final boolean forceAllowInsecureDecoderComponents;
53+
@Deprecated public final boolean forceAllowInsecureDecoderComponents;
5454

5555
/**
5656
* @param uuid The DRM scheme UUID.
5757
* @param sessionId The DRM session id.
5858
* @param forceAllowInsecureDecoderComponents Whether to allow use of insecure decoder components
5959
* even if the underlying platform says otherwise.
6060
*/
61+
@SuppressWarnings("deprecation") // Setting deprecated field
6162
public FrameworkCryptoConfig(
6263
UUID uuid, byte[] sessionId, boolean forceAllowInsecureDecoderComponents) {
6364
this.uuid = uuid;

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/FrameworkMediaDrm.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,24 @@ public Map<String, String> queryKeyStatus(byte[] sessionId) {
287287
@UnstableApi
288288
@Override
289289
public boolean requiresSecureDecoder(byte[] sessionId, String mimeType) {
290+
boolean result;
290291
if (Util.SDK_INT >= 31) {
291-
return Api31.requiresSecureDecoder(mediaDrm, mimeType);
292-
}
293-
294-
MediaCrypto mediaCrypto;
295-
try {
296-
mediaCrypto = new MediaCrypto(uuid, sessionId);
297-
} catch (MediaCryptoException e) {
298-
// This shouldn't happen, but if it does then assume that a secure decoder may be required.
299-
return true;
300-
}
301-
try {
302-
return mediaCrypto.requiresSecureDecoderComponent(mimeType);
303-
} finally {
304-
mediaCrypto.release();
292+
result = Api31.requiresSecureDecoder(mediaDrm, mimeType);
293+
} else {
294+
MediaCrypto mediaCrypto = null;
295+
try {
296+
mediaCrypto = new MediaCrypto(uuid, sessionId);
297+
result = mediaCrypto.requiresSecureDecoderComponent(mimeType);
298+
} catch (MediaCryptoException e) {
299+
// This shouldn't happen, but if it does then assume that a secure decoder may be required.
300+
result = true;
301+
} finally {
302+
if (mediaCrypto != null) {
303+
mediaCrypto.release();
304+
}
305+
}
305306
}
307+
return result && !shouldForceAllowInsecureDecoderComponents();
306308
}
307309

308310
@UnstableApi
@@ -383,16 +385,19 @@ public void setPropertyByteArray(String propertyName, byte[] value) {
383385
@UnstableApi
384386
@Override
385387
public FrameworkCryptoConfig createCryptoConfig(byte[] sessionId) throws MediaCryptoException {
386-
// Work around a bug prior to Lollipop where L1 Widevine forced into L3 mode would still
387-
// indicate that it required secure video decoders [Internal ref: b/11428937].
388-
boolean forceAllowInsecureDecoderComponents =
389-
Util.SDK_INT < 21
390-
&& C.WIDEVINE_UUID.equals(uuid)
391-
&& "L3".equals(getPropertyString("securityLevel"));
388+
boolean forceAllowInsecureDecoderComponents = shouldForceAllowInsecureDecoderComponents();
392389
return new FrameworkCryptoConfig(
393390
adjustUuid(uuid), sessionId, forceAllowInsecureDecoderComponents);
394391
}
395392

393+
// Work around a bug prior to Lollipop where L1 Widevine forced into L3 mode would still
394+
// indicate that it required secure video decoders [Internal ref: b/11428937].
395+
private boolean shouldForceAllowInsecureDecoderComponents() {
396+
return Util.SDK_INT < 21
397+
&& C.WIDEVINE_UUID.equals(uuid)
398+
&& "L3".equals(getPropertyString("securityLevel"));
399+
}
400+
396401
@UnstableApi
397402
@Override
398403
public @C.CryptoType int getCryptoType() {

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecRenderer.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ private static String buildCustomDiagnosticInfo(int errorCode) {
360360
*/
361361
@Nullable private MediaCrypto mediaCrypto;
362362

363-
private boolean mediaCryptoRequiresSecureDecoder;
364363
private long renderTimeLimitMs;
365364
private float currentPlaybackSpeed;
366365
private float targetPlaybackSpeed;
@@ -539,6 +538,7 @@ protected final void maybeInitCodecOrBypass() throws ExoPlaybackException {
539538
// We have a codec, are bypassing it, or don't have a format to decide how to render.
540539
return;
541540
}
541+
Format inputFormat = this.inputFormat;
542542

543543
if (isBypassPossible(inputFormat)) {
544544
initBypass(inputFormat);
@@ -548,6 +548,10 @@ protected final void maybeInitCodecOrBypass() throws ExoPlaybackException {
548548
setCodecDrmSession(sourceDrmSession);
549549
if (codecDrmSession == null || initMediaCryptoIfDrmSessionReady()) {
550550
try {
551+
boolean mediaCryptoRequiresSecureDecoder =
552+
codecDrmSession != null
553+
&& codecDrmSession.requiresSecureDecoder(
554+
checkStateNotNull(inputFormat.sampleMimeType));
551555
maybeInitCodecWithFallback(mediaCrypto, mediaCryptoRequiresSecureDecoder);
552556
} catch (DecoderInitializationException e) {
553557
throw createRendererException(
@@ -558,7 +562,6 @@ protected final void maybeInitCodecOrBypass() throws ExoPlaybackException {
558562
// mediaCrypto was created, but a codec wasn't, so release the mediaCrypto before returning.
559563
mediaCrypto.release();
560564
mediaCrypto = null;
561-
mediaCryptoRequiresSecureDecoder = false;
562565
}
563566
}
564567

@@ -968,7 +971,6 @@ protected void resetCodecStateForRelease() {
968971
codecNeedsEosPropagation = false;
969972
codecReconfigured = false;
970973
codecReconfigurationState = RECONFIGURATION_STATE_NONE;
971-
mediaCryptoRequiresSecureDecoder = false;
972974
}
973975

974976
protected MediaCodecDecoderException createDecoderException(
@@ -1011,7 +1013,6 @@ private boolean readSourceOmittingSampleData(@SampleStream.ReadFlags int readFla
10111013
private boolean initMediaCryptoIfDrmSessionReady() throws ExoPlaybackException {
10121014
checkState(mediaCrypto == null);
10131015
DrmSession codecDrmSession = this.codecDrmSession;
1014-
String mimeType = checkNotNull(inputFormat).sampleMimeType;
10151016
@Nullable CryptoConfig cryptoConfig = codecDrmSession.getCryptoConfig();
10161017
if (FrameworkCryptoConfig.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC
10171018
&& cryptoConfig instanceof FrameworkCryptoConfig) {
@@ -1044,9 +1045,6 @@ private boolean initMediaCryptoIfDrmSessionReady() throws ExoPlaybackException {
10441045
throw createRendererException(
10451046
e, inputFormat, PlaybackException.ERROR_CODE_DRM_SYSTEM_ERROR);
10461047
}
1047-
mediaCryptoRequiresSecureDecoder =
1048-
!frameworkCryptoConfig.forceAllowInsecureDecoderComponents
1049-
&& mediaCrypto.requiresSecureDecoderComponent(checkStateNotNull(mimeType));
10501048
}
10511049
return true;
10521050
}
@@ -2228,8 +2226,6 @@ private boolean drmNeedsCodecReinitialization(
22282226
return false;
22292227
}
22302228

2231-
FrameworkCryptoConfig newFrameworkCryptoConfig = (FrameworkCryptoConfig) newCryptoConfig;
2232-
22332229
// Note: Both oldSession and newSession are non-null, and they are different sessions.
22342230

22352231
if (!newSession.getSchemeUuid().equals(oldSession.getSchemeUuid())) {
@@ -2250,20 +2246,10 @@ private boolean drmNeedsCodecReinitialization(
22502246
return true;
22512247
}
22522248

2253-
boolean requiresSecureDecoder;
2254-
if (newFrameworkCryptoConfig.forceAllowInsecureDecoderComponents) {
2255-
requiresSecureDecoder = false;
2256-
} else {
2257-
requiresSecureDecoder =
2258-
newSession.requiresSecureDecoder(checkNotNull(newFormat.sampleMimeType));
2259-
}
2260-
if (!codecInfo.secure && requiresSecureDecoder) {
2261-
// Re-initialization is required because newSession might require switching to the secure
2262-
// output path.
2263-
return true;
2264-
}
2265-
2266-
return false;
2249+
// Re-initialization is required if newSession might require switching to the secure output
2250+
// path.
2251+
return !codecInfo.secure
2252+
&& newSession.requiresSecureDecoder(checkNotNull(newFormat.sampleMimeType));
22672253
}
22682254

22692255
private void reinitializeCodec() throws ExoPlaybackException {

0 commit comments

Comments
 (0)