From f7621aacc3f73c4b8db192fbdc10798dc77bdb5e Mon Sep 17 00:00:00 2001 From: tofunmi Date: Wed, 15 Feb 2023 11:51:07 +0000 Subject: [PATCH] Move inputExternalSurfaceTexture to the ExternalTextureManager Now that the GLEffectFrameProcessor handles external (video) and internal (image) input, components used only for external input needs should be moved to the ExternalTextureManager for code clarity PiperOrigin-RevId: 509787494 --- .../effect/ExternalTextureManager.java | 21 ++++++++++++++----- .../effect/GlEffectsFrameProcessor.java | 10 ++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java index bfc473e66c..1d8102cd2b 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.effect; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import android.graphics.SurfaceTexture; +import android.view.Surface; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import com.google.android.exoplayer2.C; @@ -39,6 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger; private final FrameProcessingTaskExecutor frameProcessingTaskExecutor; private final ExternalShaderProgram externalShaderProgram; private final int externalTexId; + private final Surface surface; private final SurfaceTexture surfaceTexture; private final float[] textureTransformMatrix; private final Queue pendingFrames; @@ -71,6 +73,8 @@ import java.util.concurrent.atomic.AtomicInteger; * @param frameProcessingTaskExecutor The {@link FrameProcessingTaskExecutor}. * @throws FrameProcessingException If a problem occurs while creating the external texture. */ + // The onFrameAvailableListener will not be invoked until the constructor returns. + @SuppressWarnings("nullness:method.invocation.invalid") public ExternalTextureManager( ExternalShaderProgram externalShaderProgram, FrameProcessingTaskExecutor frameProcessingTaskExecutor) @@ -86,11 +90,7 @@ import java.util.concurrent.atomic.AtomicInteger; textureTransformMatrix = new float[16]; pendingFrames = new ConcurrentLinkedQueue<>(); externalShaderProgramInputCapacity = new AtomicInteger(); - previousStreamOffsetUs = C.TIME_UNSET; - } - - public SurfaceTexture getSurfaceTexture() { surfaceTexture.setOnFrameAvailableListener( unused -> frameProcessingTaskExecutor.submit( @@ -104,7 +104,17 @@ import java.util.concurrent.atomic.AtomicInteger; maybeQueueFrameToExternalShaderProgram(); } })); - return surfaceTexture; + surface = new Surface(surfaceTexture); + } + + /** See {@link GlEffectsFrameProcessor#setInputDefaultBufferSize}. */ + public void setDefaultBufferSize(int width, int height) { + surfaceTexture.setDefaultBufferSize(width, height); + } + + /** Returns the {@linkplain Surface input surface} that wraps the external texture. */ + public Surface getInputSurface() { + return surface; } @Override @@ -173,6 +183,7 @@ import java.util.concurrent.atomic.AtomicInteger; public void release() { surfaceTexture.release(); + surface.release(); } @WorkerThread 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 2248f2888c..a06e2a33b5 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 @@ -356,8 +356,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { private final FrameProcessingTaskExecutor frameProcessingTaskExecutor; private @MonotonicNonNull InternalTextureManager inputInternalTextureManager; private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager; - // TODO(262693274): Move this variable to ExternalTextureManager. - private @MonotonicNonNull Surface inputExternalSurface; private final boolean releaseFramesAutomatically; private final FinalMatrixShaderProgramWrapper finalShaderProgramWrapper; private final ImmutableList allShaderPrograms; @@ -396,7 +394,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { new ExternalTextureManager( (ExternalShaderProgram) inputShaderProgram, frameProcessingTaskExecutor); inputShaderProgram.setInputListener(inputExternalTextureManager); - inputExternalSurface = new Surface(inputExternalTextureManager.getSurfaceTexture()); } else { inputInternalTextureManager = new InternalTextureManager(inputShaderProgram, frameProcessingTaskExecutor); @@ -430,9 +427,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { * @param height The default height for input buffers, in pixels. */ public void setInputDefaultBufferSize(int width, int height) { - checkNotNull(inputExternalTextureManager) - .getSurfaceTexture() - .setDefaultBufferSize(width, height); + checkNotNull(inputExternalTextureManager).setDefaultBufferSize(width, height); } @Override @@ -443,7 +438,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { @Override public Surface getInputSurface() { - return checkNotNull(inputExternalSurface); + return checkNotNull(inputExternalTextureManager).getInputSurface(); } @Override @@ -521,7 +516,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { } if (inputExternalTextureManager != null) { inputExternalTextureManager.release(); - checkNotNull(inputExternalSurface).release(); } }