From 1f9a33279e299e60a7ff7fb592edcfaf63407640 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 23 Jan 2023 18:31:20 +0000 Subject: [PATCH] Add a way to specify default buffer size Based on experimentation, when CameraX is producing input for frame processor the buffer size is not being set to match the camera capture resolution, so the output has lower resolution than expected. Expose the default buffer size setter on `SurfaceTexture` to allow apps to process frames at full resolution for use cases like this one where the producer doesn't override the default buffer size. PiperOrigin-RevId: 504022107 --- .../effect/GlEffectsFrameProcessor.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/GlEffectsFrameProcessor.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/GlEffectsFrameProcessor.java index 647e50b76e..be7ab9c1e4 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/GlEffectsFrameProcessor.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/GlEffectsFrameProcessor.java @@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.common.collect.Iterables.getLast; import android.content.Context; +import android.graphics.SurfaceTexture; import android.opengl.EGLContext; import android.opengl.EGLDisplay; import android.view.Surface; @@ -378,6 +379,22 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { return frameProcessingTaskExecutor; } + /** + * Sets the default size for input buffers, for the case where the producer providing input does + * not override the buffer size. + * + *

When input comes from a media codec it's not necessary to call this method because the codec + * (producer) sets the buffer size automatically. For the case where input comes from CameraX, + * call this method after instantiation to ensure that buffers are handled at full resolution. See + * {@link SurfaceTexture#setDefaultBufferSize(int, int)} for more information. + * + * @param width The default width for input buffers, in pixels. + * @param height The default height for input buffers, in pixels. + */ + public void setInputDefaultBufferSize(int width, int height) { + inputExternalTextureManager.getSurfaceTexture().setDefaultBufferSize(width, height); + } + @Override public Surface getInputSurface() { return inputSurface;