From f3b4575436d86024e537eb6afa582b752a38e916 Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 19 Oct 2018 13:47:45 -0700 Subject: [PATCH] Temporarily disable codec reuse There are multiple subtle issues with the current implementation: 1. setOperatingRate can cause a codec initialization even if the renderer is disabled. This is not supposed to happen. 2. If the codec is released whilst the renderer is disabled, the renderer can instantiate a new codec using the old format when it's enabled again, only to immediately have to reconfigure or release it if the actual format to be played is different. 3. Codec reuse does not take into account renderer configuration. The specific case where this is problematic is if the video renderer is re-enabled with a different tunneling session id. The reused codec is then not configured correctly. Also moved availableCodecInfos reset into releaseCodec for sanity. Issue: #2826 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217924592 --- .../exoplayer2/mediacodec/MediaCodecRenderer.java | 13 +------------ .../exoplayer2/video/MediaCodecVideoRenderer.java | 4 +--- 2 files changed, 2 insertions(+), 15 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 27b0d89a3fb..a35240668e3 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 @@ -558,18 +558,7 @@ public final void setOperatingRate(float operatingRate) throws ExoPlaybackExcept @Override protected void onDisabled() { - if (drmSession != null || pendingDrmSession != null) { - // TODO: Do something better with this case. - onReset(); - } else { - flushOrReleaseCodec(); - } - } - - @Override - protected void onReset() { format = null; - availableCodecInfos = null; try { releaseCodec(); } finally { @@ -591,6 +580,7 @@ protected void onReset() { } protected void releaseCodec() { + availableCodecInfos = null; codecHotswapDeadlineMs = C.TIME_UNSET; resetInputBuffer(); resetOutputBuffer(); @@ -1307,7 +1297,6 @@ private void updateCodecOperatingRate() throws ExoPlaybackException { * @throws ExoPlaybackException If an error occurs releasing or initializing a codec. */ private void reinitializeCodec(boolean release) throws ExoPlaybackException { - availableCodecInfos = null; if (codecReceivedBuffers) { // Signal end of stream and wait for any final output buffers before re-initialization. codecReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index 18aeada04bd..a0e794764a5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -436,9 +436,7 @@ private void setSurface(Surface surface) throws ExoPlaybackException { setOutputSurfaceV23(codec, surface); } else { releaseCodec(); - if (state == STATE_ENABLED || state == STATE_STARTED) { - maybeInitCodec(); - } + maybeInitCodec(); } } if (surface != null && surface != dummySurface) {