implement top down approach for passing input source id

This commit is contained in:
Patrik Aradi 2024-02-13 10:41:16 +08:00 committed by Luyuan Chen
parent 3cccecf368
commit 52adaf8d26
10 changed files with 21 additions and 29 deletions

View File

@ -76,10 +76,8 @@ public interface VideoGraph {
* <p>If the method throws, the caller must call {@link #release}.
*
* @param sequenceIndex The sequence index of the input which can aid ordering of the inputs.
* @return The id of the registered input, which can be used to get the underlying {@link
* VideoFrameProcessor} via {@link #getProcessor(int)}.
*/
int registerInput(int sequenceIndex) throws VideoFrameProcessingException;
void registerInput(int sequenceIndex) throws VideoFrameProcessingException;
/**
* Returns the {@link VideoFrameProcessor} that handles the processing for an input registered via

View File

@ -142,9 +142,8 @@ public final class DefaultVideoCompositor implements VideoCompositor {
}
@Override
public synchronized int registerInputSource(int sequenceIndex) {
public synchronized void registerInputSource(int sequenceIndex) {
inputSources.put(sequenceIndex, new InputSource());
return sequenceIndex;
}
@Override

View File

@ -211,10 +211,9 @@ public abstract class MultipleInputVideoGraph implements VideoGraph {
}
@Override
public int registerInput(int sequenceIndex) throws VideoFrameProcessingException {
public void registerInput(int sequenceIndex) throws VideoFrameProcessingException {
checkStateNotNull(videoCompositor);
int videoCompositorInputId = videoCompositor.registerInputSource(sequenceIndex);
videoCompositor.registerInputSource(sequenceIndex);
// Creating a new VideoFrameProcessor for the input.
VideoFrameProcessor preProcessor =
videoFrameProcessorFactory
@ -223,7 +222,7 @@ public abstract class MultipleInputVideoGraph implements VideoGraph {
// Texture output to compositor.
(textureProducer, texture, presentationTimeUs, syncObject) ->
queuePreProcessingOutputToCompositor(
videoCompositorInputId, textureProducer, texture, presentationTimeUs),
sequenceIndex, textureProducer, texture, presentationTimeUs),
PRE_COMPOSITOR_TEXTURE_OUTPUT_CAPACITY)
.build()
.create(
@ -254,11 +253,10 @@ public abstract class MultipleInputVideoGraph implements VideoGraph {
@Override
public void onEnded() {
onPreProcessingVideoFrameProcessorEnded(videoCompositorInputId);
onPreProcessingVideoFrameProcessorEnded(sequenceIndex);
}
});
preProcessors.put(videoCompositorInputId, preProcessor);
return videoCompositorInputId;
preProcessors.put(sequenceIndex, preProcessor);
}
@Override

View File

@ -99,7 +99,7 @@ public abstract class SingleInputVideoGraph implements VideoGraph {
}
@Override
public int registerInput(int sequenceIndex) throws VideoFrameProcessingException {
public void registerInput(int sequenceIndex) throws VideoFrameProcessingException {
checkStateNotNull(videoFrameProcessor == null && !released);
videoFrameProcessor =
@ -159,7 +159,6 @@ public abstract class SingleInputVideoGraph implements VideoGraph {
if (outputSurfaceInfo != null) {
videoFrameProcessor.setOutputSurfaceInfo(outputSurfaceInfo);
}
return SINGLE_INPUT_INDEX;
}
@Override

View File

@ -52,7 +52,7 @@ public interface VideoCompositor extends GlTextureProducer {
* @param sequenceIndex The sequence index of the input source, which is can be used to determine
* the order of the input sources.
*/
int registerInputSource(int sequenceIndex);
void registerInputSource(int sequenceIndex);
/**
* Signals that no more frames will come from the upstream {@link GlTextureProducer.Listener}.

View File

@ -550,8 +550,8 @@ public final class CompositingVideoSinkProvider
// reduces decoder timeouts, and consider restoring.
videoFrameProcessorMaxPendingFrameCount =
Util.getMaxPendingFramesCountForMediaCodecDecoders(context);
int videoGraphInputId = videoGraph.registerInput(0);
videoFrameProcessor = videoGraph.getProcessor(videoGraphInputId);
videoGraph.registerInput(0);
videoFrameProcessor = videoGraph.getProcessor(0);
videoEffects = new ArrayList<>();
finalBufferPresentationTimeUs = C.TIME_UNSET;

View File

@ -856,7 +856,8 @@ public final class DefaultVideoCompositorPixelTest {
VideoCompositor videoCompositor,
@Nullable ExecutorService executorService,
GlObjectsProvider glObjectsProvider) {
int inputId = videoCompositor.registerInputSource(0);
int sequenceIndex = 0;
videoCompositor.registerInputSource(sequenceIndex);
DefaultVideoFrameProcessor.Factory.Builder defaultVideoFrameProcessorFactoryBuilder =
new DefaultVideoFrameProcessor.Factory.Builder()
.setGlObjectsProvider(glObjectsProvider)
@ -870,7 +871,7 @@ public final class DefaultVideoCompositorPixelTest {
textureBitmapReader.readBitmapUnpremultipliedAlpha(
outputTexture, presentationTimeUs);
videoCompositor.queueInputTexture(
inputId,
sequenceIndex,
outputTextureProducer,
outputTexture,
ColorInfo.SRGB_BT709_FULL,
@ -884,7 +885,7 @@ public final class DefaultVideoCompositorPixelTest {
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactoryBuilder.build())
.setBitmapReader(textureBitmapReader)
.setOnEndedListener(() -> videoCompositor.signalEndOfInputSource(inputId));
.setOnEndedListener(() -> videoCompositor.signalEndOfInputSource(sequenceIndex));
}
}

View File

@ -80,8 +80,8 @@ import java.util.concurrent.Executor;
@Override
public GraphInput createInput(int sequenceIndex) throws VideoFrameProcessingException {
int inputId = registerInput(sequenceIndex);
registerInput(sequenceIndex);
return new VideoFrameProcessingWrapper(
getProcessor(inputId), /* presentation= */ null, getInitialTimestampOffsetUs());
getProcessor(sequenceIndex), /* presentation= */ null, getInitialTimestampOffsetUs());
}
}

View File

@ -108,13 +108,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public GraphInput createInput(int sequenceIndex) throws VideoFrameProcessingException {
checkState(videoFrameProcessingWrapper == null);
int inputId = registerInput(sequenceIndex);
registerInput(sequenceIndex);
videoFrameProcessingWrapper =
new VideoFrameProcessingWrapper(
getProcessor(inputId),
getInputColorInfo(),
getPresentation(),
getInitialTimestampOffsetUs());
getProcessor(sequenceIndex), getPresentation(), getInitialTimestampOffsetUs());
return videoFrameProcessingWrapper;
}
}

View File

@ -543,8 +543,8 @@ import org.checkerframework.dataflow.qual.Pure;
}
@Override
public int registerInput(int sequenceIndex) throws VideoFrameProcessingException {
return videoGraph.registerInput(sequenceIndex);
public void registerInput(int sequenceIndex) throws VideoFrameProcessingException {
videoGraph.registerInput(sequenceIndex);
}
@Override