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
This commit is contained in:
tonihei 2024-09-25 09:54:41 -07:00 committed by Copybara-Service
parent 3ec9c99644
commit 5879426c07

View File

@ -1795,7 +1795,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
} }
private boolean hasSurfaceForCodec(MediaCodecInfo codecInfo) { private boolean hasSurfaceForCodec(MediaCodecInfo codecInfo) {
return displaySurface != null return (displaySurface != null && displaySurface.isValid())
|| shouldUseDetachedSurface(codecInfo) || shouldUseDetachedSurface(codecInfo)
|| shouldUsePlaceholderSurface(codecInfo); || shouldUsePlaceholderSurface(codecInfo);
} }