Skip to content

Commit a18d96c

Browse files
clainclySheenaChhabra
authored andcommitted
Fix blank video when switching on/off screen
This happens when using `ExoPlayer.setVideoEffects()`. This CL also fixes the first frame not rendered problem, originally solved in 7e65cce, but rolled back in 5056dfa because the solution introduces the flash that is observed in b/292111083. Before media3 1.1 release, the output size of `VideoFrameProcessor` is not reported to the app. This was changed later after introducing `CompositingVideoSinkProvider`, where the video size after processing **is** reported to the app. After this CL, the size is again, not reported. PiperOrigin-RevId: 602345087 (cherry picked from commit dcae49a)
1 parent dfe4721 commit a18d96c

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

‎libraries/effect/src/androidTest/java/androidx/media3/effect/EffectPlaybackTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.concurrent.atomic.AtomicReference;
5656
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
5757
import org.junit.After;
58-
import org.junit.Ignore;
5958
import org.junit.Test;
6059
import org.junit.runner.RunWith;
6160
import org.junit.runners.Parameterized;
@@ -103,7 +102,6 @@ public void tearDown() {
103102
}
104103

105104
@Test
106-
@Ignore("b/292111083")
107105
public void exoplayerEffectsPreviewTest_ensuresFirstFrameRendered() throws Exception {
108106
assumeTrue(Util.SDK_INT >= 18);
109107

‎libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
154154
private boolean codecNeedsSetOutputSurfaceWorkaround;
155155
private boolean codecHandlesHdr10PlusOutOfBandMetadata;
156156
@Nullable private Surface displaySurface;
157+
@Nullable private Size outputResolution;
157158
@Nullable private PlaceholderSurface placeholderSurface;
158159
private boolean haveReportedFirstFrameRenderedForCurrentSurface;
159160
private @C.VideoScalingMode int scalingMode;
@@ -771,14 +772,14 @@ public void handleMessage(@MessageType int messageType, @Nullable Object message
771772
setVideoEffects(videoEffects);
772773
break;
773774
case MSG_SET_VIDEO_OUTPUT_RESOLUTION:
774-
Size outputResolution = (Size) checkNotNull(message);
775+
outputResolution = (Size) checkNotNull(message);
775776
// TODO: b/292111083 Set the surface on the videoSinkProvider before it's initialized
776777
// otherwise the first frames are missed until a new video output resolution arrives.
777778
if (videoSinkProvider.isInitialized()
778-
&& outputResolution.getWidth() != 0
779-
&& outputResolution.getHeight() != 0
779+
&& checkNotNull(outputResolution).getWidth() != 0
780+
&& checkNotNull(outputResolution).getHeight() != 0
780781
&& displaySurface != null) {
781-
videoSinkProvider.setOutputSurfaceInfo(displaySurface, outputResolution);
782+
videoSinkProvider.setOutputSurfaceInfo(displaySurface, checkNotNull(outputResolution));
782783
}
783784
break;
784785
case MSG_SET_AUDIO_ATTRIBUTES:
@@ -1063,6 +1064,9 @@ protected void onReadyToInitializeCodec(Format format) throws ExoPlaybackExcepti
10631064
if (frameMetadataListener != null) {
10641065
videoSinkProvider.setVideoFrameMetadataListener(frameMetadataListener);
10651066
}
1067+
if (displaySurface != null && outputResolution != null) {
1068+
videoSinkProvider.setOutputSurfaceInfo(displaySurface, outputResolution);
1069+
}
10661070
} catch (VideoSink.VideoSinkException e) {
10671071
throw createRendererException(
10681072
e, format, PlaybackException.ERROR_CODE_VIDEO_FRAME_PROCESSOR_INIT_FAILED);
@@ -1087,7 +1091,9 @@ public void onFrameDropped(VideoSink videoSink) {
10871091

10881092
@Override
10891093
public void onVideoSizeChanged(VideoSink videoSink, VideoSize videoSize) {
1090-
maybeNotifyVideoSizeChanged(videoSize);
1094+
// TODO: b/292111083 - Report video size change to app. Video size reporting is
1095+
// removed at the moment to ensure the first frame is rendered, and the video is
1096+
// rendered after switching on/off the screen.
10911097
}
10921098

10931099
@Override

‎libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/VideoFrameRenderControl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ void renderFrame(
8181

8282
private VideoSize reportedVideoSize;
8383
private long outputStreamOffsetUs;
84-
// TODO b/292111083 - Remove the field and trigger the callback on every video size change.
85-
private boolean reportedVideoSizeChange;
8684
private long lastPresentationTimeUs;
8785

8886
/** Creates an instance. */
@@ -122,8 +120,6 @@ public void flush() {
122120
// we keep the latest value of pendingOutputVideoSize
123121
videoSizeChanges.clear();
124122
}
125-
// Do not clear reportedVideoSizeChange because we report a video size change at most once
126-
// (b/292111083).
127123
}
128124

129125
/** Returns whether the renderer is ready. */
@@ -230,9 +226,8 @@ private void renderFrame(boolean shouldRenderImmediately) {
230226
long presentationTimeUs = checkStateNotNull(presentationTimestampsUs.remove());
231227

232228
boolean videoSizeUpdated = maybeUpdateVideoSize(presentationTimeUs);
233-
if (videoSizeUpdated && !reportedVideoSizeChange) {
229+
if (videoSizeUpdated) {
234230
frameRenderer.onVideoSizeChanged(reportedVideoSize);
235-
reportedVideoSizeChange = true;
236231
}
237232
long renderTimeNs =
238233
shouldRenderImmediately

0 commit comments

Comments
 (0)