Rename surface to display surface for previewing.

PiperOrigin-RevId: 493557119
This commit is contained in:
claincly 2022-12-07 11:21:18 +00:00 committed by Ian Baker
parent 9d059352cf
commit 03276d1eb0

View File

@ -133,7 +133,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
private boolean codecNeedsSetOutputSurfaceWorkaround; private boolean codecNeedsSetOutputSurfaceWorkaround;
private boolean codecHandlesHdr10PlusOutOfBandMetadata; private boolean codecHandlesHdr10PlusOutOfBandMetadata;
@Nullable private Surface surface; @Nullable private Surface displaySurface;
@Nullable private PlaceholderSurface placeholderSurface; @Nullable private PlaceholderSurface placeholderSurface;
private boolean haveReportedFirstFrameRenderedForCurrentSurface; private boolean haveReportedFirstFrameRenderedForCurrentSurface;
private @C.VideoScalingMode int scalingMode; private @C.VideoScalingMode int scalingMode;
@ -559,7 +559,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
public boolean isReady() { public boolean isReady() {
if (super.isReady() if (super.isReady()
&& (renderedFirstFrameAfterReset && (renderedFirstFrameAfterReset
|| (placeholderSurface != null && surface == placeholderSurface) || (placeholderSurface != null && displaySurface == placeholderSurface)
|| getCodec() == null || getCodec() == null
|| tunneling)) { || tunneling)) {
// Ready. If we were joining then we've now joined, so clear the joining deadline. // Ready. If we were joining then we've now joined, so clear the joining deadline.
@ -664,54 +664,54 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
private void setOutput(@Nullable Object output) throws ExoPlaybackException { private void setOutput(@Nullable Object output) throws ExoPlaybackException {
// Handle unsupported (i.e., non-Surface) outputs by clearing the surface. // Handle unsupported (i.e., non-Surface) outputs by clearing the display surface.
@Nullable Surface surface = output instanceof Surface ? (Surface) output : null; @Nullable Surface displaySurface = output instanceof Surface ? (Surface) output : null;
if (surface == null) { if (displaySurface == null) {
// Use a placeholder surface if possible. // Use a placeholder surface if possible.
if (placeholderSurface != null) { if (placeholderSurface != null) {
surface = placeholderSurface; displaySurface = placeholderSurface;
} else { } else {
MediaCodecInfo codecInfo = getCodecInfo(); MediaCodecInfo codecInfo = getCodecInfo();
if (codecInfo != null && shouldUsePlaceholderSurface(codecInfo)) { if (codecInfo != null && shouldUsePlaceholderSurface(codecInfo)) {
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure); placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure);
surface = placeholderSurface; displaySurface = placeholderSurface;
} }
} }
} }
// We only need to update the codec if the surface has changed. // We only need to update the codec if the display surface has changed.
if (this.surface != surface) { if (this.displaySurface != displaySurface) {
this.surface = surface; this.displaySurface = displaySurface;
frameReleaseHelper.onSurfaceChanged(surface); frameReleaseHelper.onSurfaceChanged(displaySurface);
haveReportedFirstFrameRenderedForCurrentSurface = false; haveReportedFirstFrameRenderedForCurrentSurface = false;
@State int state = getState(); @State int state = getState();
@Nullable MediaCodecAdapter codec = getCodec(); @Nullable MediaCodecAdapter codec = getCodec();
if (codec != null) { if (codec != null) {
if (Util.SDK_INT >= 23 && surface != null && !codecNeedsSetOutputSurfaceWorkaround) { if (Util.SDK_INT >= 23 && displaySurface != null && !codecNeedsSetOutputSurfaceWorkaround) {
setOutputSurfaceV23(codec, surface); setOutputSurfaceV23(codec, displaySurface);
} else { } else {
releaseCodec(); releaseCodec();
maybeInitCodecOrBypass(); maybeInitCodecOrBypass();
} }
} }
if (surface != null && surface != placeholderSurface) { if (displaySurface != null && displaySurface != placeholderSurface) {
// If we know the video size, report it again immediately. // If we know the video size, report it again immediately.
maybeRenotifyVideoSizeChanged(); maybeRenotifyVideoSizeChanged();
// We haven't rendered to the new surface yet. // We haven't rendered to the new display surface yet.
clearRenderedFirstFrame(); clearRenderedFirstFrame();
if (state == STATE_STARTED) { if (state == STATE_STARTED) {
setJoiningDeadlineMs(); setJoiningDeadlineMs();
} }
} else { } else {
// The surface has been removed. // The display surface has been removed.
clearReportedVideoSize(); clearReportedVideoSize();
clearRenderedFirstFrame(); clearRenderedFirstFrame();
} }
} else if (surface != null && surface != placeholderSurface) { } else if (displaySurface != null && displaySurface != placeholderSurface) {
// The surface is set and unchanged. If we know the video size and/or have already rendered to // The display surface is set and unchanged. If we know the video size and/or have already
// the surface, report these again immediately. // rendered to the display surface, report these again immediately.
maybeRenotifyVideoSizeChanged(); maybeRenotifyVideoSizeChanged();
maybeRenotifyRenderedFirstFrame(); maybeRenotifyRenderedFirstFrame();
} }
@ -719,7 +719,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@Override @Override
protected boolean shouldInitCodec(MediaCodecInfo codecInfo) { protected boolean shouldInitCodec(MediaCodecInfo codecInfo) {
return surface != null || shouldUsePlaceholderSurface(codecInfo); return displaySurface != null || shouldUsePlaceholderSurface(codecInfo);
} }
@Override @Override
@ -749,17 +749,17 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
codecOperatingRate, codecOperatingRate,
deviceNeedsNoPostProcessWorkaround, deviceNeedsNoPostProcessWorkaround,
tunneling ? tunnelingAudioSessionId : C.AUDIO_SESSION_ID_UNSET); tunneling ? tunnelingAudioSessionId : C.AUDIO_SESSION_ID_UNSET);
if (surface == null) { if (displaySurface == null) {
if (!shouldUsePlaceholderSurface(codecInfo)) { if (!shouldUsePlaceholderSurface(codecInfo)) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
if (placeholderSurface == null) { if (placeholderSurface == null) {
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure); placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure);
} }
surface = placeholderSurface; displaySurface = placeholderSurface;
} }
return MediaCodecAdapter.Configuration.createForVideoDecoding( return MediaCodecAdapter.Configuration.createForVideoDecoding(
codecInfo, mediaFormat, format, surface, crypto); codecInfo, mediaFormat, format, displaySurface, crypto);
} }
@Override @Override
@ -1063,7 +1063,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
earlyUs -= elapsedRealtimeNowUs - elapsedRealtimeUs; earlyUs -= elapsedRealtimeNowUs - elapsedRealtimeUs;
} }
if (surface == placeholderSurface) { if (displaySurface == placeholderSurface) {
// Skip frames in sync with playback, so we'll be at the right frame if the mode changes. // Skip frames in sync with playback, so we'll be at the right frame if the mode changes.
if (isBufferLate(earlyUs)) { if (isBufferLate(earlyUs)) {
skipOutputBuffer(codec, bufferIndex, presentationTimeUs); skipOutputBuffer(codec, bufferIndex, presentationTimeUs);
@ -1378,8 +1378,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@RequiresApi(17) @RequiresApi(17)
private void releasePlaceholderSurface() { private void releasePlaceholderSurface() {
if (surface == placeholderSurface) { if (displaySurface == placeholderSurface) {
surface = null; displaySurface = null;
} }
placeholderSurface.release(); placeholderSurface.release();
placeholderSurface = null; placeholderSurface = null;
@ -1411,14 +1411,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
renderedFirstFrameAfterEnable = true; renderedFirstFrameAfterEnable = true;
if (!renderedFirstFrameAfterReset) { if (!renderedFirstFrameAfterReset) {
renderedFirstFrameAfterReset = true; renderedFirstFrameAfterReset = true;
eventDispatcher.renderedFirstFrame(surface); eventDispatcher.renderedFirstFrame(displaySurface);
haveReportedFirstFrameRenderedForCurrentSurface = true; haveReportedFirstFrameRenderedForCurrentSurface = true;
} }
} }
private void maybeRenotifyRenderedFirstFrame() { private void maybeRenotifyRenderedFirstFrame() {
if (haveReportedFirstFrameRenderedForCurrentSurface) { if (haveReportedFirstFrameRenderedForCurrentSurface) {
eventDispatcher.renderedFirstFrame(surface); eventDispatcher.renderedFirstFrame(displaySurface);
} }
} }
@ -1626,7 +1626,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@Override @Override
protected MediaCodecDecoderException createDecoderException( protected MediaCodecDecoderException createDecoderException(
Throwable cause, @Nullable MediaCodecInfo codecInfo) { Throwable cause, @Nullable MediaCodecInfo codecInfo) {
return new MediaCodecVideoDecoderException(cause, codecInfo, surface); return new MediaCodecVideoDecoderException(cause, codecInfo, displaySurface);
} }
/** /**
@ -1755,8 +1755,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
return deviceNeedsSetOutputSurfaceWorkaround; return deviceNeedsSetOutputSurfaceWorkaround;
} }
/** Returns the output surface. */
@Nullable
protected Surface getSurface() { protected Surface getSurface() {
return surface; // TODO(b/260702159) Consider renaming the method to getOutputSurface().
return displaySurface;
} }
protected static final class CodecMaxValues { protected static final class CodecMaxValues {