From 5879426c07d4265751656c46504997809a019175 Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 25 Sep 2024 09:54:41 -0700 Subject: [PATCH] Check surface validity before configuring it on a codec This check is also done when setting a surface on ExoPlayerImpl, but by the time we configure the codec the surface may have become invalid (e.g. when it is destroyed). Even though we immediately remove a destroyed surface, we could still accidentally use it before the removal is processed. To avoid these edge cases, we can simply not configure the codec with an invalid surface. PiperOrigin-RevId: 678741425 --- .../media3/exoplayer/video/MediaCodecVideoRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java index 21bab781a2..e812659768 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java @@ -1795,7 +1795,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer } private boolean hasSurfaceForCodec(MediaCodecInfo codecInfo) { - return displaySurface != null + return (displaySurface != null && displaySurface.isValid()) || shouldUseDetachedSurface(codecInfo) || shouldUsePlaceholderSurface(codecInfo); }