Commit 4a059884 by tofunmi Committed by Ian Baker

Refactor ChainingGlShaderProgramListener to use FrameConsumptionManager

PiperOrigin-RevId: 531180020
parent 25e793ff
......@@ -15,15 +15,9 @@
*/
package com.google.android.exoplayer2.effect;
import android.util.Pair;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.effect.GlShaderProgram.InputListener;
import com.google.android.exoplayer2.effect.GlShaderProgram.OutputListener;
import com.google.android.exoplayer2.util.GlTextureInfo;
import java.util.ArrayDeque;
import java.util.Queue;
/**
* Connects a producing and a consuming {@link GlShaderProgram} instance.
......@@ -35,15 +29,9 @@ import java.util.Queue;
implements GlShaderProgram.InputListener, GlShaderProgram.OutputListener {
private final GlShaderProgram producingGlShaderProgram;
private final GlShaderProgram consumingGlShaderProgram;
private final FrameConsumptionManager frameConsumptionManager;
private final VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor;
@GuardedBy("this")
private final Queue<Pair<GlTextureInfo, Long>> availableFrames;
@GuardedBy("this")
private int consumingGlShaderProgramInputCapacity;
/**
* Creates a new instance.
*
......@@ -61,29 +49,14 @@ import java.util.Queue;
GlShaderProgram consumingGlShaderProgram,
VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor) {
this.producingGlShaderProgram = producingGlShaderProgram;
this.consumingGlShaderProgram = consumingGlShaderProgram;
frameConsumptionManager =
new FrameConsumptionManager(consumingGlShaderProgram, videoFrameProcessingTaskExecutor);
this.videoFrameProcessingTaskExecutor = videoFrameProcessingTaskExecutor;
availableFrames = new ArrayDeque<>();
}
@Override
public synchronized void onReadyToAcceptInputFrame() {
@Nullable Pair<GlTextureInfo, Long> pendingFrame = availableFrames.poll();
if (pendingFrame == null) {
consumingGlShaderProgramInputCapacity++;
return;
}
long presentationTimeUs = pendingFrame.second;
if (presentationTimeUs == C.TIME_END_OF_SOURCE) {
videoFrameProcessingTaskExecutor.submit(
consumingGlShaderProgram::signalEndOfCurrentInputStream);
} else {
videoFrameProcessingTaskExecutor.submit(
() ->
consumingGlShaderProgram.queueInputFrame(
/* inputTexture= */ pendingFrame.first, presentationTimeUs));
}
frameConsumptionManager.onReadyToAcceptInputFrame();
}
@Override
......@@ -94,32 +67,18 @@ import java.util.Queue;
@Override
public synchronized void onFlush() {
consumingGlShaderProgramInputCapacity = 0;
availableFrames.clear();
frameConsumptionManager.onFlush();
videoFrameProcessingTaskExecutor.submit(producingGlShaderProgram::flush);
}
@Override
public synchronized void onOutputFrameAvailable(
GlTextureInfo outputTexture, long presentationTimeUs) {
if (consumingGlShaderProgramInputCapacity > 0) {
videoFrameProcessingTaskExecutor.submit(
() ->
consumingGlShaderProgram.queueInputFrame(
/* inputTexture= */ outputTexture, presentationTimeUs));
consumingGlShaderProgramInputCapacity--;
} else {
availableFrames.add(new Pair<>(outputTexture, presentationTimeUs));
}
frameConsumptionManager.queueInputFrame(outputTexture, presentationTimeUs);
}
@Override
public synchronized void onCurrentOutputStreamEnded() {
if (!availableFrames.isEmpty()) {
availableFrames.add(new Pair<>(GlTextureInfo.UNSET, C.TIME_END_OF_SOURCE));
} else {
videoFrameProcessingTaskExecutor.submit(
consumingGlShaderProgram::signalEndOfCurrentInputStream);
}
frameConsumptionManager.signalEndOfCurrentStream();
}
}
......@@ -26,12 +26,11 @@ import java.util.Queue;
/**
* Manages queueing frames and sending them to a given {@link GlShaderProgram
* consumingGLShaderProgram} at a consumable pace.
* consumingGlShaderProgram} at a consumable pace.
*
* <p>Frames are stored as a {@link GlTextureInfo} with a {@code presentationTimeUs}.
*/
// TODO(b/261820382): Converge ChainingGlShaderProgramListener with this class.
/* package */ final class FrameConsumptionManager implements GlShaderProgram.InputListener {
private final GlShaderProgram consumingGlShaderProgram;
private final VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor;
......@@ -45,8 +44,7 @@ import java.util.Queue;
/**
* Creates a new instance.
*
* @param consumingGlShaderProgram The {@link GlShaderProgram} for which this {@code
* texIdTextureManager} will be set as the {@link GlShaderProgram.InputListener}.
* @param consumingGlShaderProgram The {@link GlShaderProgram} that frames are queued to.
* @param videoFrameProcessingTaskExecutor The {@link VideoFrameProcessingTaskExecutor}.
*/
public FrameConsumptionManager(
......
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