From 58e307c6b00d95280fd6f2d7310ae3532f6b39e8 Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 1 Jun 2021 15:11:25 +0100 Subject: [PATCH] Keep secure MediaCodec instances when disabling the renderer A renderer is disabled (without being reset) in two situations: * When transitioning into a period that starts with a discontinuity * When stopping the player with setForegroundMode(true) Before this change the behaviour of `MediaCodecRenderer` when disabled (but not reset) depended on whether the content being decoded had an associated `DrmSession`: * For content without an associated DRM session the MediaCodec instance was kept alive. * For content with an associated DRM session, the MediaCodec instance was released. This was to prevent the DRM session from staying alive and continuing to make license refresh network requests while the player was stopped in 'foreground mode'. This change removes the second bullet, and keeps MediaCodec instances alive in both the secure and insecure case. This will result in the DRM machinery making occasional license refresh network requests (at a frequency defined by the license policy) while the player is stopped and in 'foreground mode'. This network usage is considered to be a 'limited resource' as described by the `ExoPlayer#setForegroundMode` javadoc. This means that switches between secure content (or between secure and clear content when `MediaItem.drmConfiguration.sessionForClearTypes` indicates a secure decoder should be used for clear content) should keep the same video decoder, thus avoiding the 'black flash' that occurs on some devices when switching the surface away from a secure decoder. Issue: #8842 #minor-release PiperOrigin-RevId: 376825501 --- RELEASENOTES.md | 7 +++++++ .../android/exoplayer2/mediacodec/MediaCodecRenderer.java | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index e085209e2d..8cd1e5fdd1 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -70,6 +70,13 @@ must be released without restoring them first. * Ensure `DefaultDrmSession` instances keep working even after their `DefaultDrmSessionManager` instance is released. + * Keep secure `MediaCodec` instances initialized when disabling (but not + resetting) `MediaCodecRenderer`. This helps re-use secure decoders in + more contexts, which avoids the 'black flash' caused by detaching a + `Surface` from a secure decoder on some devices + ([#8842](https://github.com/google/ExoPlayer/issues/8842)). It will also + result in DRM license refresh network requests while the player is + stopped if `Player#setForegroundMode` is true. * UI: * Keep subtitle language features embedded (e.g. rubies & tate-chu-yoko) in `Cue.text` even when `SubtitleView#setApplyEmbeddedStyles()` is diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index 4eb750ecb6..bd9312798a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -745,12 +745,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { outputStreamStartPositionUs = C.TIME_UNSET; outputStreamOffsetUs = C.TIME_UNSET; pendingOutputStreamOffsetCount = 0; - if (sourceDrmSession != null || codecDrmSession != null) { - // TODO: Do something better with this case. - onReset(); - } else { - flushOrReleaseCodec(); - } + flushOrReleaseCodec(); } @Override