mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Factor out VideoFrameProcessor logic
PiperOrigin-RevId: 559780905
This commit is contained in:
parent
cd0b7d9e29
commit
28fd43617e
2 changed files with 141 additions and 102 deletions
|
|
@ -45,7 +45,7 @@ import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/** Processes decoded video frames from one single input. */
|
/** Processes decoded video frames from one single input. */
|
||||||
/* package */ final class SingleInputVideoGraph implements GraphInput {
|
/* package */ final class SingleInputVideoGraph {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for video frame processing events.
|
* Listener for video frame processing events.
|
||||||
|
|
@ -68,11 +68,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
void onEnded(long finalFramePresentationTimeUs);
|
void onEnded(long finalFramePresentationTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final VideoFrameProcessor videoFrameProcessor;
|
private final VideoFrameProcessingWrapper videoFrameProcessingWrapper;
|
||||||
private final AtomicLong mediaItemOffsetUs;
|
|
||||||
private final ColorInfo inputColorInfo;
|
|
||||||
|
|
||||||
@Nullable final Presentation presentation;
|
|
||||||
|
|
||||||
private volatile boolean hasProducedFrameWithTimestampZero;
|
private volatile boolean hasProducedFrameWithTimestampZero;
|
||||||
|
|
||||||
|
|
@ -105,17 +101,14 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
boolean renderFramesAutomatically,
|
boolean renderFramesAutomatically,
|
||||||
@Nullable Presentation presentation)
|
@Nullable Presentation presentation)
|
||||||
throws VideoFrameProcessingException {
|
throws VideoFrameProcessingException {
|
||||||
this.mediaItemOffsetUs = new AtomicLong();
|
|
||||||
this.inputColorInfo = inputColorInfo;
|
|
||||||
this.presentation = presentation;
|
|
||||||
|
|
||||||
videoFrameProcessor =
|
videoFrameProcessingWrapper =
|
||||||
videoFrameProcessorFactory.create(
|
new VideoFrameProcessingWrapper(
|
||||||
context,
|
context,
|
||||||
debugViewProvider,
|
videoFrameProcessorFactory,
|
||||||
inputColorInfo,
|
inputColorInfo,
|
||||||
outputColorInfo,
|
outputColorInfo,
|
||||||
renderFramesAutomatically,
|
debugViewProvider,
|
||||||
listenerExecutor,
|
listenerExecutor,
|
||||||
new VideoFrameProcessor.Listener() {
|
new VideoFrameProcessor.Listener() {
|
||||||
private long lastProcessedFramePresentationTimeUs;
|
private long lastProcessedFramePresentationTimeUs;
|
||||||
|
|
@ -124,14 +117,12 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
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) {
|
||||||
// TODO: b/289986435 - Allow setting output surface info on VideoGraph.
|
// TODO: b/289986435 - Allow setting output surface info on VideoGraph.
|
||||||
checkNotNull(videoFrameProcessor)
|
checkNotNull(videoFrameProcessingWrapper)
|
||||||
.setOutputSurfaceInfo(listener.onOutputSizeChanged(width, height));
|
.setOutputSurfaceInfo(listener.onOutputSizeChanged(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +145,54 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
public void onEnded() {
|
public void onEnded() {
|
||||||
listener.onEnded(lastProcessedFramePresentationTimeUs);
|
listener.onEnded(lastProcessedFramePresentationTimeUs);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
renderFramesAutomatically,
|
||||||
|
presentation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the {@link GraphInput}. */
|
||||||
|
public GraphInput getInput() {
|
||||||
|
return videoFrameProcessingWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* package */ boolean hasProducedFrameWithTimestampZero() {
|
||||||
|
return hasProducedFrameWithTimestampZero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
videoFrameProcessingWrapper.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class VideoFrameProcessingWrapper implements GraphInput {
|
||||||
|
private final VideoFrameProcessor videoFrameProcessor;
|
||||||
|
private final AtomicLong mediaItemOffsetUs;
|
||||||
|
private final ColorInfo inputColorInfo;
|
||||||
|
|
||||||
|
@Nullable private final Presentation presentation;
|
||||||
|
|
||||||
|
public VideoFrameProcessingWrapper(
|
||||||
|
Context context,
|
||||||
|
VideoFrameProcessor.Factory videoFrameProcessorFactory,
|
||||||
|
ColorInfo inputColorInfo,
|
||||||
|
ColorInfo outputColorInfo,
|
||||||
|
DebugViewProvider debugViewProvider,
|
||||||
|
Executor listenerExecutor,
|
||||||
|
VideoFrameProcessor.Listener listener,
|
||||||
|
boolean renderFramesAutomatically,
|
||||||
|
@Nullable Presentation presentation)
|
||||||
|
throws VideoFrameProcessingException {
|
||||||
|
this.videoFrameProcessor =
|
||||||
|
videoFrameProcessorFactory.create(
|
||||||
|
context,
|
||||||
|
debugViewProvider,
|
||||||
|
inputColorInfo,
|
||||||
|
outputColorInfo,
|
||||||
|
renderFramesAutomatically,
|
||||||
|
listenerExecutor,
|
||||||
|
listener);
|
||||||
|
this.mediaItemOffsetUs = new AtomicLong();
|
||||||
|
this.inputColorInfo = inputColorInfo;
|
||||||
|
this.presentation = presentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -216,8 +254,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
videoFrameProcessor.signalEndOfInput();
|
videoFrameProcessor.signalEndOfInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ boolean hasProducedFrameWithTimestampZero() {
|
public void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) {
|
||||||
return hasProducedFrameWithTimestampZero;
|
videoFrameProcessor.setOutputSurfaceInfo(outputSurfaceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release() {
|
public void release() {
|
||||||
|
|
@ -254,3 +292,4 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
return effectsWithPresentationBuilder.build();
|
return effectsWithPresentationBuilder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphInput getInput(EditedMediaItem item, Format format) {
|
public GraphInput getInput(EditedMediaItem item, Format format) {
|
||||||
return singleInputVideoGraph;
|
return singleInputVideoGraph.getInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue