Commit 6f028be9 by claincly Committed by Tofunmi Adigun-Hameed

Add a getter method for texture manager

PiperOrigin-RevId: 533402277
(cherry picked from commit 03e3ce19f1a58668f0bc7fe14172abf817836beb)
parent 6ac3dd96
...@@ -296,9 +296,6 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -296,9 +296,6 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
// CountDownLatch to wait for the current input stream to finish processing. // CountDownLatch to wait for the current input stream to finish processing.
private volatile @MonotonicNonNull CountDownLatch latch; private volatile @MonotonicNonNull CountDownLatch latch;
// TODO(b/274109008) Use InputSwither to interact with texture manager.
// Owned and released by inputSwitcher.
private @MonotonicNonNull TextureManager textureManager;
private volatile @MonotonicNonNull FrameInfo nextInputFrameInfo; private volatile @MonotonicNonNull FrameInfo nextInputFrameInfo;
private volatile boolean inputStreamEnded; private volatile boolean inputStreamEnded;
private volatile boolean hasRefreshedNextInputFrameInfo; private volatile boolean hasRefreshedNextInputFrameInfo;
...@@ -361,7 +358,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -361,7 +358,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
* @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(textureManager).setDefaultBufferSize(width, height); inputSwitcher.activeTextureManager().setDefaultBufferSize(width, height);
} }
@Override @Override
...@@ -369,7 +366,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -369,7 +366,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
checkState( checkState(
hasRefreshedNextInputFrameInfo, hasRefreshedNextInputFrameInfo,
"setInputFrameInfo must be called before queueing another bitmap"); "setInputFrameInfo must be called before queueing another bitmap");
checkNotNull(textureManager) inputSwitcher
.activeTextureManager()
.queueInputBitmap( .queueInputBitmap(
inputBitmap, inputBitmap,
durationUs, durationUs,
...@@ -381,24 +379,24 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -381,24 +379,24 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
@Override @Override
public void queueInputTexture(int textureId, long presentationTimeUs) { public void queueInputTexture(int textureId, long presentationTimeUs) {
checkNotNull(textureManager).queueInputTexture(textureId, presentationTimeUs); inputSwitcher.activeTextureManager().queueInputTexture(textureId, presentationTimeUs);
} }
@Override @Override
public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) { public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) {
checkNotNull(textureManager).setOnInputFrameProcessedListener(listener); inputSwitcher.activeTextureManager().setOnInputFrameProcessedListener(listener);
} }
@Override @Override
public Surface getInputSurface() { public Surface getInputSurface() {
return checkNotNull(textureManager).getInputSurface(); return inputSwitcher.activeTextureManager().getInputSurface();
} }
@Override @Override
public void registerInputStream(@InputType int inputType) { public void registerInputStream(@InputType int inputType) {
synchronized (lock) { synchronized (lock) {
if (unprocessedInputStreams.isEmpty()) { if (unprocessedInputStreams.isEmpty()) {
textureManager = inputSwitcher.switchToInput(inputType); inputSwitcher.switchToInput(inputType);
unprocessedInputStreams.add(inputType); unprocessedInputStreams.add(inputType);
return; return;
} }
...@@ -406,14 +404,14 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -406,14 +404,14 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
// Wait until the current input stream is processed before continuing to the next input. // Wait until the current input stream is processed before continuing to the next input.
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
checkNotNull(textureManager).signalEndOfCurrentInputStream(); inputSwitcher.activeTextureManager().signalEndOfCurrentInputStream();
try { try {
latch.await(); latch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
listenerExecutor.execute(() -> listener.onError(VideoFrameProcessingException.from(e))); listenerExecutor.execute(() -> listener.onError(VideoFrameProcessingException.from(e)));
} }
textureManager = inputSwitcher.switchToInput(inputType); inputSwitcher.switchToInput(inputType);
synchronized (lock) { synchronized (lock) {
unprocessedInputStreams.add(inputType); unprocessedInputStreams.add(inputType);
} }
...@@ -422,7 +420,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -422,7 +420,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
@Override @Override
public void setInputFrameInfo(FrameInfo inputFrameInfo) { public void setInputFrameInfo(FrameInfo inputFrameInfo) {
nextInputFrameInfo = adjustForPixelWidthHeightRatio(inputFrameInfo); nextInputFrameInfo = adjustForPixelWidthHeightRatio(inputFrameInfo);
checkNotNull(textureManager).setInputFrameInfo(nextInputFrameInfo); inputSwitcher.activeTextureManager().setInputFrameInfo(nextInputFrameInfo);
hasRefreshedNextInputFrameInfo = true; hasRefreshedNextInputFrameInfo = true;
} }
...@@ -432,13 +430,13 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -432,13 +430,13 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
checkStateNotNull( checkStateNotNull(
nextInputFrameInfo, "setInputFrameInfo must be called before registering input frames"); nextInputFrameInfo, "setInputFrameInfo must be called before registering input frames");
checkNotNull(textureManager).registerInputFrame(nextInputFrameInfo); inputSwitcher.activeTextureManager().registerInputFrame(nextInputFrameInfo);
hasRefreshedNextInputFrameInfo = false; hasRefreshedNextInputFrameInfo = false;
} }
@Override @Override
public int getPendingInputFrameCount() { public int getPendingInputFrameCount() {
return checkNotNull(textureManager).getPendingFrameCount(); return inputSwitcher.activeTextureManager().getPendingFrameCount();
} }
/** /**
...@@ -479,7 +477,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -479,7 +477,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
if (allInputStreamsProcessed) { if (allInputStreamsProcessed) {
inputSwitcher.signalEndOfInput(); inputSwitcher.signalEndOfInput();
} else { } else {
checkNotNull(textureManager).signalEndOfCurrentInputStream(); inputSwitcher.signalEndOfCurrentInputStream();
} }
} }
...@@ -488,10 +486,10 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -488,10 +486,10 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
try { try {
videoFrameProcessingTaskExecutor.flush(); videoFrameProcessingTaskExecutor.flush();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
checkNotNull(textureManager).setOnFlushCompleteListener(latch::countDown); inputSwitcher.activeTextureManager().setOnFlushCompleteListener(latch::countDown);
videoFrameProcessingTaskExecutor.submit(finalShaderProgramWrapper::flush); videoFrameProcessingTaskExecutor.submit(finalShaderProgramWrapper::flush);
latch.await(); latch.await();
checkNotNull(textureManager).setOnFlushCompleteListener(null); inputSwitcher.activeTextureManager().setOnFlushCompleteListener(null);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
......
...@@ -23,7 +23,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; ...@@ -23,7 +23,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.content.Context; import android.content.Context;
import android.util.SparseArray; import android.util.SparseArray;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlObjectsProvider; import com.google.android.exoplayer2.util.GlObjectsProvider;
import com.google.android.exoplayer2.util.GlTextureInfo; import com.google.android.exoplayer2.util.GlTextureInfo;
...@@ -46,6 +45,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -46,6 +45,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private final boolean enableColorTransfers; private final boolean enableColorTransfers;
private @MonotonicNonNull GlShaderProgram downstreamShaderProgram; private @MonotonicNonNull GlShaderProgram downstreamShaderProgram;
private @MonotonicNonNull TextureManager activeTextureManager;
private boolean inputEnded; private boolean inputEnded;
private int activeInputType; private int activeInputType;
...@@ -159,17 +159,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -159,17 +159,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* registered}. * registered}.
* *
* @param newInputType The new {@link VideoFrameProcessor.InputType} to switch to. * @param newInputType The new {@link VideoFrameProcessor.InputType} to switch to.
* @return The {@link TextureManager} associated with the {@code newInputType}.
*/ */
public TextureManager switchToInput(@VideoFrameProcessor.InputType int newInputType) { public void switchToInput(@VideoFrameProcessor.InputType int newInputType) {
checkStateNotNull(downstreamShaderProgram); checkStateNotNull(downstreamShaderProgram);
checkState(inputs.indexOfKey(newInputType) >= 0, "Input type not registered: " + newInputType); checkState(inputs.indexOfKey(newInputType) >= 0, "Input type not registered: " + newInputType);
if (newInputType == activeInputType) { if (newInputType == activeInputType) {
return inputs.get(activeInputType).textureManager; activeTextureManager = inputs.get(activeInputType).textureManager;
} }
@Nullable TextureManager activeTextureManager = null;
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
@VideoFrameProcessor.InputType int inputType = inputs.keyAt(i); @VideoFrameProcessor.InputType int inputType = inputs.keyAt(i);
Input input = inputs.get(inputType); Input input = inputs.get(inputType);
...@@ -181,11 +179,26 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -181,11 +179,26 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
input.setActive(false); input.setActive(false);
} }
} }
activeInputType = newInputType; activeInputType = newInputType;
}
/**
* Returns the {@link TextureManager} that is currently being used.
*
* <p>Must call {@link #switchToInput} before calling this method.
*/
public TextureManager activeTextureManager() {
return checkNotNull(activeTextureManager); return checkNotNull(activeTextureManager);
} }
/**
* Invokes {@link TextureManager#signalEndOfCurrentInputStream} on the active {@link
* TextureManager}.
*/
public void signalEndOfCurrentInputStream() {
checkNotNull(activeTextureManager).signalEndOfCurrentInputStream();
}
/** Signals end of input to all {@linkplain #registerInput registered inputs}. */ /** Signals end of input to all {@linkplain #registerInput registered inputs}. */
public void signalEndOfInput() { public void signalEndOfInput() {
checkState(!inputEnded); checkState(!inputEnded);
......
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