From 1201466b5cdda1c66e2ad88be6e81fb5d6f42b07 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 25 Nov 2020 14:43:04 +0000 Subject: [PATCH] Fix NPE in onInputFormatChanged PiperOrigin-RevId: 344243929 --- .../exoplayer2/mediacodec/MediaCodecRenderer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 c45e17a672..910bac30aa 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 @@ -1408,7 +1408,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer { // We have an existing codec that we may need to reconfigure, re-initialize, or release to // switch to bypass. If the existing codec instance is kept then its operating rate and DRM // session may need to be updated. - MediaCodecAdapter oldCodec = codec; + + // Copy the current codec and codecInfo to local variables so they remain accessible if the + // member variables are updated during the logic below. + MediaCodecAdapter codec = this.codec; + MediaCodecInfo codecInfo = this.codecInfo; + Format oldFormat = codecInputFormat; if (drmNeedsCodecReinitialization(codecInfo, newFormat, codecDrmSession, sourceDrmSession)) { drainAndReinitializeCodec(); @@ -1474,7 +1479,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { } if (evaluation.result != REUSE_RESULT_NO - && (codec != oldCodec || codecDrainAction == DRAIN_ACTION_REINITIALIZE)) { + && (this.codec != codec || codecDrainAction == DRAIN_ACTION_REINITIALIZE)) { // Initial evaluation indicated reuse was possible, but codec re-initialization was triggered. // The reasons are indicated by overridingDiscardReasons. return new DecoderReuseEvaluation(