Commit f7621aac by tofunmi Committed by christosts

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
parent 7497b1e0
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.effect; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.effect;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread; import androidx.annotation.WorkerThread;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -39,6 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -39,6 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger;
private final FrameProcessingTaskExecutor frameProcessingTaskExecutor; private final FrameProcessingTaskExecutor frameProcessingTaskExecutor;
private final ExternalShaderProgram externalShaderProgram; private final ExternalShaderProgram externalShaderProgram;
private final int externalTexId; private final int externalTexId;
private final Surface surface;
private final SurfaceTexture surfaceTexture; private final SurfaceTexture surfaceTexture;
private final float[] textureTransformMatrix; private final float[] textureTransformMatrix;
private final Queue<FrameInfo> pendingFrames; private final Queue<FrameInfo> pendingFrames;
...@@ -71,6 +73,8 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -71,6 +73,8 @@ import java.util.concurrent.atomic.AtomicInteger;
* @param frameProcessingTaskExecutor The {@link FrameProcessingTaskExecutor}. * @param frameProcessingTaskExecutor The {@link FrameProcessingTaskExecutor}.
* @throws FrameProcessingException If a problem occurs while creating the external texture. * @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( public ExternalTextureManager(
ExternalShaderProgram externalShaderProgram, ExternalShaderProgram externalShaderProgram,
FrameProcessingTaskExecutor frameProcessingTaskExecutor) FrameProcessingTaskExecutor frameProcessingTaskExecutor)
...@@ -86,11 +90,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -86,11 +90,7 @@ import java.util.concurrent.atomic.AtomicInteger;
textureTransformMatrix = new float[16]; textureTransformMatrix = new float[16];
pendingFrames = new ConcurrentLinkedQueue<>(); pendingFrames = new ConcurrentLinkedQueue<>();
externalShaderProgramInputCapacity = new AtomicInteger(); externalShaderProgramInputCapacity = new AtomicInteger();
previousStreamOffsetUs = C.TIME_UNSET; previousStreamOffsetUs = C.TIME_UNSET;
}
public SurfaceTexture getSurfaceTexture() {
surfaceTexture.setOnFrameAvailableListener( surfaceTexture.setOnFrameAvailableListener(
unused -> unused ->
frameProcessingTaskExecutor.submit( frameProcessingTaskExecutor.submit(
...@@ -104,7 +104,17 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -104,7 +104,17 @@ import java.util.concurrent.atomic.AtomicInteger;
maybeQueueFrameToExternalShaderProgram(); 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 @Override
...@@ -173,6 +183,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -173,6 +183,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public void release() { public void release() {
surfaceTexture.release(); surfaceTexture.release();
surface.release();
} }
@WorkerThread @WorkerThread
......
...@@ -356,8 +356,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -356,8 +356,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
private final FrameProcessingTaskExecutor frameProcessingTaskExecutor; private final FrameProcessingTaskExecutor frameProcessingTaskExecutor;
private @MonotonicNonNull InternalTextureManager inputInternalTextureManager; private @MonotonicNonNull InternalTextureManager inputInternalTextureManager;
private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager; private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager;
// TODO(262693274): Move this variable to ExternalTextureManager.
private @MonotonicNonNull Surface inputExternalSurface;
private final boolean releaseFramesAutomatically; private final boolean releaseFramesAutomatically;
private final FinalMatrixShaderProgramWrapper finalShaderProgramWrapper; private final FinalMatrixShaderProgramWrapper finalShaderProgramWrapper;
private final ImmutableList<GlShaderProgram> allShaderPrograms; private final ImmutableList<GlShaderProgram> allShaderPrograms;
...@@ -396,7 +394,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -396,7 +394,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
new ExternalTextureManager( new ExternalTextureManager(
(ExternalShaderProgram) inputShaderProgram, frameProcessingTaskExecutor); (ExternalShaderProgram) inputShaderProgram, frameProcessingTaskExecutor);
inputShaderProgram.setInputListener(inputExternalTextureManager); inputShaderProgram.setInputListener(inputExternalTextureManager);
inputExternalSurface = new Surface(inputExternalTextureManager.getSurfaceTexture());
} else { } else {
inputInternalTextureManager = inputInternalTextureManager =
new InternalTextureManager(inputShaderProgram, frameProcessingTaskExecutor); new InternalTextureManager(inputShaderProgram, frameProcessingTaskExecutor);
...@@ -430,9 +427,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -430,9 +427,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
* @param height The default height for input buffers, in pixels. * @param height The default height for input buffers, in pixels.
*/ */
public void setInputDefaultBufferSize(int width, int height) { public void setInputDefaultBufferSize(int width, int height) {
checkNotNull(inputExternalTextureManager) checkNotNull(inputExternalTextureManager).setDefaultBufferSize(width, height);
.getSurfaceTexture()
.setDefaultBufferSize(width, height);
} }
@Override @Override
...@@ -443,7 +438,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -443,7 +438,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
@Override @Override
public Surface getInputSurface() { public Surface getInputSurface() {
return checkNotNull(inputExternalSurface); return checkNotNull(inputExternalTextureManager).getInputSurface();
} }
@Override @Override
...@@ -521,7 +516,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -521,7 +516,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
} }
if (inputExternalTextureManager != null) { if (inputExternalTextureManager != null) {
inputExternalTextureManager.release(); inputExternalTextureManager.release();
checkNotNull(inputExternalSurface).release();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment