From 75c72f3b6de1ba34361f95b6b4e87afe423670d9 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Fri, 29 Apr 2022 11:46:14 +0100 Subject: [PATCH] Return recommended output size for FrameProcessorChain. Also add warning for what can happen if this is ignored. Previously the return value was overridden by setOutputSurface, now setOutputSurface only overrides the values using internally. PiperOrigin-RevId: 445377036 --- .../transformer/FrameProcessorChain.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java index 8ac2aef5c2..31cf0f2bb0 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java @@ -236,7 +236,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; */ private final int[] framebuffers; - private Size outputSize; + private int outputWidth; + private int outputHeight; /** * Wraps the output {@link Surface} that is populated with the output of the final {@link * GlFrameProcessor} for each frame. @@ -277,20 +278,27 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; inputSurfaceTexture = new SurfaceTexture(inputExternalTexId); inputSurface = new Surface(inputSurfaceTexture); textureTransformMatrix = new float[16]; - outputSize = getLast(frameProcessors).getOutputSize(); + outputWidth = C.LENGTH_UNSET; + outputHeight = C.LENGTH_UNSET; debugPreviewWidth = C.LENGTH_UNSET; debugPreviewHeight = C.LENGTH_UNSET; } - /** Returns the output {@link Size}. */ + /** + * Returns the recommended output size. + * + *

This is the recommended size to use for the {@linkplain #setOutputSurface(Surface, int, int, + * SurfaceView) output surface}. + */ public Size getOutputSize() { - return outputSize; + return getLast(frameProcessors).getOutputSize(); } /** * Sets the output {@link Surface}. * - *

This method may override the output size of the final {@link GlFrameProcessor}. + *

The recommended output size is given by {@link #getOutputSize()}. Setting a different output + * size may cause poor quality or distortion. * * @param outputSurface The output {@link Surface}. * @param outputWidth The output width, in pixels. @@ -304,7 +312,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; @Nullable SurfaceView debugSurfaceView) { // TODO(b/218488308): Don't override output size for encoder fallback. Instead allow the final // GlFrameProcessor to be re-configured or append another GlFrameProcessor. - outputSize = new Size(outputWidth, outputHeight); + this.outputWidth = outputWidth; + this.outputHeight = outputHeight; if (debugSurfaceView != null) { debugPreviewWidth = debugSurfaceView.getWidth(); @@ -483,8 +492,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; clearOutputFrame(); frameProcessors.get(i).drawFrame(presentationTimeUs); } - GlUtil.focusEglSurface( - eglDisplay, eglContext, eglSurface, outputSize.getWidth(), outputSize.getHeight()); + GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight); clearOutputFrame(); getLast(frameProcessors).drawFrame(presentationTimeUs);