From 44f461a06220a77852ec3cdda9d42a0680da889f Mon Sep 17 00:00:00 2001 From: claincly Date: Wed, 25 Jan 2023 20:06:12 +0000 Subject: [PATCH] Make sure first frame has effects applied. `FrameProcessorManager` now reports it's not ready when the output surface is set but not the output resolution. `FrameProcessorManager` allows playback without an output surface, like with ExoPlayer. PiperOrigin-RevId: 504626088 --- .../exoplayer2/video/MediaCodecVideoRenderer.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 adf150d21a..4ec5753a58 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 @@ -583,6 +583,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { @Override public boolean isReady() { if (super.isReady() + && (!frameProcessorManager.isEnabled() || frameProcessorManager.isReady()) && (renderedFirstFrameAfterReset || (placeholderSurface != null && displaySurface == placeholderSurface) || getCodec() == null @@ -725,8 +726,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { @State int state = getState(); @Nullable MediaCodecAdapter codec = getCodec(); - // When FrameProcessorManager is enabled, set FrameProcessorManager's display surface when - // surface's resolution is set on receiving MSG_SET_VIDEO_OUTPUT_RESOLUTION. if (codec != null && !frameProcessorManager.isEnabled()) { if (Util.SDK_INT >= 23 && displaySurface != null && !codecNeedsSetOutputSurfaceWorkaround) { setOutputSurfaceV23(codec, displaySurface); @@ -744,6 +743,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { // Set joining deadline to report MediaCodecVideoRenderer is ready. setJoiningDeadlineMs(); } + // When FrameProcessorManager is enabled, set FrameProcessorManager's display surface and an + // unknown size. + if (frameProcessorManager.isEnabled()) { + frameProcessorManager.setOutputSurfaceInfo(displaySurface, Size.UNKNOWN); + } } else { // The display surface has been removed. clearReportedVideoSize(); @@ -1889,6 +1893,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { return frameProcessor != null; } + /** Returns whether {@code FrameProcessorManager} is ready to accept input frames. */ + public boolean isReady() { + return currentSurfaceAndSize == null || !currentSurfaceAndSize.second.equals(Size.UNKNOWN); + } + /** Whether the {@link FrameProcessor} has released the last frame in the current stream. */ public boolean releasedLastFrame() { return releasedLastFrame; @@ -2101,7 +2110,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { * this method. * * @param format The {@link Format} associated with the frame. - * @param isLastBuffer Whether the buffer is the last from the deocder to register. + * @param isLastBuffer Whether the buffer is the last from the decoder to register. * @return Whether {@link MediaCodec} should render the frame to {@link FrameProcessor}. */ public boolean maybeRegisterFrame(