Move listener methods into private method for readability
The logic that handles components' boundaries are grouped together in private methods, like handling VideoCompositor's output textures. PiperOrigin-RevId: 565131579
This commit is contained in:
parent
1d8135e563
commit
bf25b3e89d
@ -182,6 +182,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
/* renderFramesAutomatically= */ true,
|
/* renderFramesAutomatically= */ true,
|
||||||
/* listenerExecutor= */ MoreExecutors.directExecutor(),
|
/* listenerExecutor= */ MoreExecutors.directExecutor(),
|
||||||
new VideoFrameProcessor.Listener() {
|
new VideoFrameProcessor.Listener() {
|
||||||
|
// All of this listener's methods are called on the sharedExecutorService.
|
||||||
@Override
|
@Override
|
||||||
public void onInputStreamRegistered(
|
public void onInputStreamRegistered(
|
||||||
@VideoFrameProcessor.InputType int inputType,
|
@VideoFrameProcessor.InputType int inputType,
|
||||||
@ -207,7 +208,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(VideoFrameProcessingException exception) {
|
public void onError(VideoFrameProcessingException exception) {
|
||||||
handleException(exception);
|
handleVideoFrameProcessingException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -217,12 +218,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
});
|
});
|
||||||
// Release the compositor's output texture.
|
// Release the compositor's output texture.
|
||||||
compositionVideoFrameProcessor.setOnInputFrameProcessedListener(
|
compositionVideoFrameProcessor.setOnInputFrameProcessedListener(
|
||||||
(textureId, syncObject) -> {
|
this::onCompositionVideoFrameProcessorInputFrameProcessed);
|
||||||
checkState(contains(compositorOutputTextureReleases, textureId));
|
|
||||||
compositorOutputTextureReleases.get(textureId).release();
|
|
||||||
compositorOutputTextureReleases.remove(textureId);
|
|
||||||
queueCompositionOutputInternal();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Setting up the compositor.
|
// Setting up the compositor.
|
||||||
videoCompositor =
|
videoCompositor =
|
||||||
@ -232,19 +228,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
new DefaultVideoCompositor.Settings(),
|
new DefaultVideoCompositor.Settings(),
|
||||||
sharedExecutorService,
|
sharedExecutorService,
|
||||||
new VideoCompositor.Listener() {
|
new VideoCompositor.Listener() {
|
||||||
|
// All of this listener's methods are called on the sharedExecutorService.
|
||||||
@Override
|
@Override
|
||||||
public void onError(VideoFrameProcessingException exception) {
|
public void onError(VideoFrameProcessingException exception) {
|
||||||
handleException(exception);
|
handleVideoFrameProcessingException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnded() {
|
public void onEnded() {
|
||||||
compositorEnded = true;
|
onVideoCompositorEnded();
|
||||||
if (compositorOutputTextures.isEmpty()) {
|
|
||||||
compositionVideoFrameProcessor.signalEndOfInput();
|
|
||||||
} else {
|
|
||||||
queueCompositionOutputInternal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* textureOutputListener= */ this::processCompositorOutputTexture,
|
/* textureOutputListener= */ this::processCompositorOutputTexture,
|
||||||
@ -264,17 +256,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
.buildUpon()
|
.buildUpon()
|
||||||
.setTextureOutput(
|
.setTextureOutput(
|
||||||
// Texture output to compositor.
|
// Texture output to compositor.
|
||||||
(textureProducer, texture, presentationTimeUs, syncObject) -> {
|
(textureProducer, texture, presentationTimeUs, syncObject) ->
|
||||||
logEvent(EVENT_VFP_OUTPUT_TEXTURE_RENDERED, presentationTimeUs);
|
queuePreProcessingOutputToCompositor(
|
||||||
checkNotNull(videoCompositor)
|
videoCompositorInputId, textureProducer, texture, presentationTimeUs),
|
||||||
.queueInputTexture(
|
|
||||||
videoCompositorInputId,
|
|
||||||
textureProducer,
|
|
||||||
texture,
|
|
||||||
// Color is converted to outputColor in pre processing.
|
|
||||||
/* colorInfo= */ outputColorInfo,
|
|
||||||
presentationTimeUs);
|
|
||||||
},
|
|
||||||
PRE_COMPOSITOR_TEXTURE_OUTPUT_CAPACITY)
|
PRE_COMPOSITOR_TEXTURE_OUTPUT_CAPACITY)
|
||||||
.build(),
|
.build(),
|
||||||
inputColorInfo,
|
inputColorInfo,
|
||||||
@ -282,13 +266,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
DebugViewProvider.NONE,
|
DebugViewProvider.NONE,
|
||||||
listenerExecutor,
|
listenerExecutor,
|
||||||
new VideoFrameProcessor.Listener() {
|
new VideoFrameProcessor.Listener() {
|
||||||
|
// All of this listener's methods are called on the sharedExecutorService.
|
||||||
@Override
|
@Override
|
||||||
public void onInputStreamRegistered(
|
public void onInputStreamRegistered(
|
||||||
@VideoFrameProcessor.InputType int inputType,
|
@VideoFrameProcessor.InputType int inputType,
|
||||||
List<Effect> effects,
|
List<Effect> effects,
|
||||||
FrameInfo frameInfo) {
|
FrameInfo frameInfo) {}
|
||||||
// Do nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOutputSizeChanged(int width, int height) {}
|
public void onOutputSizeChanged(int width, int height) {}
|
||||||
@ -297,13 +280,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
public void onOutputFrameAvailableForRendering(long presentationTimeUs) {}
|
public void onOutputFrameAvailableForRendering(long presentationTimeUs) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(VideoFrameProcessingException ex) {
|
public void onError(VideoFrameProcessingException exception) {
|
||||||
errorConsumer.accept(ExportException.createForVideoFrameProcessingException(ex));
|
handleVideoFrameProcessingException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnded() {
|
public void onEnded() {
|
||||||
checkNotNull(videoCompositor).signalEndOfInputSource(videoCompositorInputId);
|
onPreProcessingVideoFrameProcessorEnded(videoCompositorInputId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* renderFramesAutomatically= */ true,
|
/* renderFramesAutomatically= */ true,
|
||||||
@ -351,14 +334,24 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
released = true;
|
released = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleException(Exception e) {
|
// This method is called on the sharedExecutorService.
|
||||||
errorConsumer.accept(
|
private void queuePreProcessingOutputToCompositor(
|
||||||
ExportException.createForVideoFrameProcessingException(
|
int videoCompositorInputId,
|
||||||
e instanceof VideoFrameProcessingException
|
GlTextureProducer textureProducer,
|
||||||
? (VideoFrameProcessingException) e
|
GlTextureInfo texture,
|
||||||
: VideoFrameProcessingException.from(e)));
|
long presentationTimeUs) {
|
||||||
|
logEvent(EVENT_VFP_OUTPUT_TEXTURE_RENDERED, presentationTimeUs);
|
||||||
|
checkNotNull(videoCompositor)
|
||||||
|
.queueInputTexture(
|
||||||
|
videoCompositorInputId,
|
||||||
|
textureProducer,
|
||||||
|
texture,
|
||||||
|
// Color is converted to outputColor in pre processing.
|
||||||
|
/* colorInfo= */ outputColorInfo,
|
||||||
|
presentationTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
private void processCompositorOutputTexture(
|
private void processCompositorOutputTexture(
|
||||||
GlTextureProducer textureProducer,
|
GlTextureProducer textureProducer,
|
||||||
GlTextureInfo outputTexture,
|
GlTextureInfo outputTexture,
|
||||||
@ -387,6 +380,31 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
queueCompositionOutputInternal();
|
queueCompositionOutputInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
|
private void onCompositionVideoFrameProcessorInputFrameProcessed(int textureId, long syncObject) {
|
||||||
|
// CompositionVideoFrameProcessor's input is VideoCompositor's output.
|
||||||
|
checkState(contains(compositorOutputTextureReleases, textureId));
|
||||||
|
compositorOutputTextureReleases.get(textureId).release();
|
||||||
|
compositorOutputTextureReleases.remove(textureId);
|
||||||
|
queueCompositionOutputInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
|
private void onPreProcessingVideoFrameProcessorEnded(int videoCompositorInputId) {
|
||||||
|
checkNotNull(videoCompositor).signalEndOfInputSource(videoCompositorInputId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
|
private void onVideoCompositorEnded() {
|
||||||
|
compositorEnded = true;
|
||||||
|
if (compositorOutputTextures.isEmpty()) {
|
||||||
|
checkNotNull(compositionVideoFrameProcessor).signalEndOfInput();
|
||||||
|
} else {
|
||||||
|
queueCompositionOutputInternal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
private void queueCompositionOutputInternal() {
|
private void queueCompositionOutputInternal() {
|
||||||
checkStateNotNull(compositionVideoFrameProcessor);
|
checkStateNotNull(compositionVideoFrameProcessor);
|
||||||
if (!compositionVideoFrameProcessorInputStreamRegistrationCompleted) {
|
if (!compositionVideoFrameProcessorInputStreamRegistrationCompleted) {
|
||||||
@ -408,6 +426,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is called on the sharedExecutorService.
|
||||||
|
private void handleVideoFrameProcessingException(Exception e) {
|
||||||
|
errorConsumer.accept(
|
||||||
|
ExportException.createForVideoFrameProcessingException(
|
||||||
|
e instanceof VideoFrameProcessingException
|
||||||
|
? (VideoFrameProcessingException) e
|
||||||
|
: VideoFrameProcessingException.from(e)));
|
||||||
|
}
|
||||||
|
|
||||||
private static final class CompositorOutputTextureInfo {
|
private static final class CompositorOutputTextureInfo {
|
||||||
public final GlTextureInfo glTextureInfo;
|
public final GlTextureInfo glTextureInfo;
|
||||||
public final long presentationTimeUs;
|
public final long presentationTimeUs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user