From 5056dfaa2b9f37f3708cea9ca1c0d4624c149190 Mon Sep 17 00:00:00 2001 From: christosts Date: Fri, 12 Jan 2024 05:18:18 -0800 Subject: [PATCH] Regression fix of ExoPlayer.setVideoEffects() https://github.com/androidx/media/commit/7e65cce9678447b7420a0809f88709f0f98b203e introduced a regression on ExoPlayer.setVideoEffects() where there is flash on the screen after the first few frames are shown. Before https://github.com/androidx/media/commit/7e65cce9678447b7420a0809f88709f0f98b203e, the first frames of the content are missed, until MediaCodecVideoRenderer sends the onVideoSizeChanged() callback. The first frame is processed but not shown, the onVideoSizeChanged() is triggered and the renderer receives a video output resolution message as a response from the UI. https://github.com/androidx/media/commit/7e65cce9678447b7420a0809f88709f0f98b203e fixed the missed first frames by setting a surface on the CompositingVideoSinkProvider before the provider is initialized, and as as result: - the first frames are rendered - the MediaCodecVideoRenderer sends the the onVideoSizeChanged() after frames are shown - the UI sends a video output resolution change - the MediaCodecVideoRenderer updates the CompositingVideoSinkProvider which causes the flash. The underlying problem is with onVideoSizeChanged() not being triggered early enough, before the first frame is shown. Because the flashing is a regression, this commit is reverting https://github.com/androidx/media/commit/7e65cce9678447b7420a0809f88709f0f98b203e but keeps the test that was added as ignored, so that the test is re-enabled as soon as we address the underlying issue. PiperOrigin-RevId: 597814013 --- .../java/androidx/media3/effect/EffectPlaybackTest.java | 2 ++ .../exoplayer/video/CompositingVideoSinkProvider.java | 7 ------- .../media3/exoplayer/video/MediaCodecVideoRenderer.java | 5 ++++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectPlaybackTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectPlaybackTest.java index 29de571455..1dcdc24c0f 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectPlaybackTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectPlaybackTest.java @@ -55,6 +55,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.junit.After; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -102,6 +103,7 @@ public class EffectPlaybackTest { } @Test + @Ignore("b/292111083") public void exoplayerEffectsPreviewTest_ensuresFirstFrameRendered() throws Exception { assumeTrue(Util.SDK_INT >= 18); diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java index 9fd2fa6ba5..244328c3e5 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java @@ -286,13 +286,6 @@ public final class CompositingVideoSinkProvider } videoSinkImpl = new VideoSinkImpl(context, /* compositingVideoSinkProvider= */ this, videoGraph); - if (currentSurfaceAndSize != null) { - Surface outputSurface = currentSurfaceAndSize.first; - Size outputSize = currentSurfaceAndSize.second; - checkStateNotNull(videoGraph) - .setOutputSurfaceInfo( - new SurfaceInfo(outputSurface, outputSize.getWidth(), outputSize.getHeight())); - } } catch (VideoFrameProcessingException e) { throw new VideoSink.VideoSinkException(e, sourceFormat); } 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 d59de48af4..4a5b576688 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 @@ -771,7 +771,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer break; case MSG_SET_VIDEO_OUTPUT_RESOLUTION: Size outputResolution = (Size) checkNotNull(message); - if (outputResolution.getWidth() != 0 + // TODO: b/292111083 Set the surface on the videoSinkProvider before it's initialized + // otherwise the first frames are missed until a new video output resolution arrives. + if (videoSinkProvider.isInitialized() + && outputResolution.getWidth() != 0 && outputResolution.getHeight() != 0 && displaySurface != null) { videoSinkProvider.setOutputSurfaceInfo(displaySurface, outputResolution);