Guard DrmSession.requiresSecureDecoder calls with state checks

This method is documented that it may only be called in `STATE_OPENED`
or `STATE_OPENED_WITH_KEYS`. It's possible for it to be called in other
states (like `STATE_ERROR`) without this guard.

Previously this didn't cause issues, but since 9d62845c45
we assume that the `sessionId` is non-null in this method, which results
in an `IllegalStateException` when the documented state restriction is
ignored.

PiperOrigin-RevId: 675969256
This commit is contained in:
ibaker 2024-09-18 06:39:10 -07:00 committed by Copybara-Service
parent caf70e54db
commit 0b86f89498
2 changed files with 10 additions and 2 deletions

View File

@ -51,6 +51,9 @@
* Image: * Image:
* DataSource: * DataSource:
* DRM: * DRM:
* Fix `IllegalStateException` from
`DefaultDrmSession.requiresSecureDecoder` after opening a DRM session
failed. This issue was introduced in `1.5.0-alpha01`.
* Effect: * Effect:
* Muxers: * Muxers:
* IMA extension: * IMA extension:

View File

@ -578,6 +578,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
try { try {
boolean mediaCryptoRequiresSecureDecoder = boolean mediaCryptoRequiresSecureDecoder =
codecDrmSession != null codecDrmSession != null
&& (codecDrmSession.getState() == DrmSession.STATE_OPENED
|| codecDrmSession.getState() == DrmSession.STATE_OPENED_WITH_KEYS)
&& codecDrmSession.requiresSecureDecoder( && codecDrmSession.requiresSecureDecoder(
checkStateNotNull(inputFormat.sampleMimeType)); checkStateNotNull(inputFormat.sampleMimeType));
maybeInitCodecWithFallback(mediaCrypto, mediaCryptoRequiresSecureDecoder); maybeInitCodecWithFallback(mediaCrypto, mediaCryptoRequiresSecureDecoder);
@ -2292,9 +2294,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
// Re-initialization is required if newSession might require switching to the secure output // Re-initialization is required if newSession might require switching to the secure output
// path. // path. We assume newSession might require a secure decoder if it's not fully open yet.
return !codecInfo.secure return !codecInfo.secure
&& newSession.requiresSecureDecoder(checkNotNull(newFormat.sampleMimeType)); && (newSession.getState() == DrmSession.STATE_OPENING
|| ((newSession.getState() == DrmSession.STATE_OPENED
|| newSession.getState() == DrmSession.STATE_OPENED_WITH_KEYS)
&& newSession.requiresSecureDecoder(checkNotNull(newFormat.sampleMimeType))));
} }
private void reinitializeCodec() throws ExoPlaybackException { private void reinitializeCodec() throws ExoPlaybackException {