From c736a72c75ba5460de8db79482e920ff923dc580 Mon Sep 17 00:00:00 2001 From: ibaker Date: Fri, 10 Jun 2022 09:20:32 +0000 Subject: [PATCH] Ensure `DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION` is always executed `codecDrainAction` is set to `DRAIN_ACTION_NONE` in 3 places in `MediaCodecRenderer`: * The constructor (so there's no prior state to worry about) * `updateDrmSessionV23()`: Where `mediaCrypto` is reconfigured based on `sourceDrmSession` and `codecDrmSession` is also updated to `sourceDrmSession`. * `resetCodecStateForFlush()`: Where (before this change) the action is unconditionally set back to `DRAIN_ACTION_NONE` and so any required updated implied by `DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION` is not done. This change ensures that `flushOrReleaseCodec()` handles `DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION` before calling . This probably also resolves Issue: google/ExoPlayer#10274 #minor-release PiperOrigin-RevId: 454114428 --- .../exoplayer2/mediacodec/MediaCodecRenderer.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 cf3b3882200..ead8d64163f 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 @@ -854,6 +854,19 @@ protected boolean flushOrReleaseCodec() { releaseCodec(); return true; } + if (codecDrainAction == DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION) { + checkState(Util.SDK_INT >= 23); // Implied by DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION + // Needed to keep lint happy (it doesn't understand the checkState call alone) + if (Util.SDK_INT >= 23) { + try { + updateDrmSessionV23(); + } catch (ExoPlaybackException e) { + Log.w(TAG, "Failed to update the DRM session, releasing the codec instead.", e); + releaseCodec(); + return true; + } + } + } flushCodec(); return false; }