mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Rename surface to display surface for previewing.
PiperOrigin-RevId: 493557119
This commit is contained in:
parent
ae8000aeca
commit
39ea5376e4
1 changed files with 33 additions and 30 deletions
|
|
@ -136,7 +136,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;
|
||||||
|
|
@ -562,7 +562,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.
|
||||||
|
|
@ -667,54 +667,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();
|
||||||
}
|
}
|
||||||
|
|
@ -722,7 +722,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
|
||||||
|
|
@ -752,17 +752,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
|
||||||
|
|
@ -1066,7 +1066,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);
|
||||||
|
|
@ -1381,8 +1381,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;
|
||||||
|
|
@ -1414,14 +1414,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1629,7 +1629,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1758,8 +1758,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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue