Change FrameProcessor.create() inputTrackType parameter to a boolean
PiperOrigin-RevId: 509808913
This commit is contained in:
parent
f03a6ba0f0
commit
7e33bdfc94
@ -51,8 +51,10 @@ public interface FrameProcessor {
|
||||
* @param debugViewProvider A {@link DebugViewProvider}.
|
||||
* @param inputColorInfo The {@link ColorInfo} for input frames.
|
||||
* @param outputColorInfo The {@link ColorInfo} for output frames.
|
||||
* @param inputTrackType The {@link C.TrackType} of the input. Supported track types are {@link
|
||||
* C#TRACK_TYPE_VIDEO} and {@link C#TRACK_TYPE_IMAGE}.
|
||||
* @param isInputTextureExternal Whether the input frames are produced externally (e.g. from a
|
||||
* video) or not (e.g. from a {@link Bitmap}). See <a
|
||||
* href="https://source.android.com/docs/core/graphics/arch-st#ext_texture">the
|
||||
* SurfaceTexture docs</a> for more information on external textures.
|
||||
* @param releaseFramesAutomatically If {@code true}, the {@link FrameProcessor} will render
|
||||
* output frames to the {@linkplain #setOutputSurfaceInfo(SurfaceInfo) output surface}
|
||||
* automatically as {@link FrameProcessor} is done processing them. If {@code false}, the
|
||||
@ -70,7 +72,7 @@ public interface FrameProcessor {
|
||||
DebugViewProvider debugViewProvider,
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
@C.TrackType int inputTrackType,
|
||||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor executor,
|
||||
Listener listener)
|
||||
@ -127,8 +129,8 @@ public interface FrameProcessor {
|
||||
/**
|
||||
* Provides an input {@link Bitmap} to the {@link FrameProcessor}.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_IMAGE} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code false}.
|
||||
*
|
||||
* <p>Can be called on any thread.
|
||||
*
|
||||
@ -143,8 +145,8 @@ public interface FrameProcessor {
|
||||
/**
|
||||
* Returns the input {@link Surface}, where {@link FrameProcessor} consumes input frames from.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_VIDEO} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code true}.
|
||||
*
|
||||
* <p>Can be called on any thread.
|
||||
*/
|
||||
@ -172,8 +174,8 @@ public interface FrameProcessor {
|
||||
*
|
||||
* <p>Must be called before rendering a frame to the frame processor's input surface.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_VIDEO} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code true}.
|
||||
*
|
||||
* <p>Can be called on any thread.
|
||||
*
|
||||
@ -186,8 +188,8 @@ public interface FrameProcessor {
|
||||
* Returns the number of input frames that have been {@linkplain #registerInputFrame() registered}
|
||||
* but not processed off the {@linkplain #getInputSurface() input surface} yet.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_VIDEO} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code true}.
|
||||
*
|
||||
* <p>Can be called on any thread.
|
||||
*/
|
||||
@ -246,8 +248,8 @@ public interface FrameProcessor {
|
||||
* <p>All the frames that are {@linkplain #registerInputFrame() registered} prior to calling this
|
||||
* method are no longer considered to be registered when this method returns.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_VIDEO} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code true}.
|
||||
*
|
||||
* <p>{@link Listener} methods invoked prior to calling this method should be ignored.
|
||||
*/
|
||||
|
@ -24,7 +24,6 @@ import android.graphics.PixelFormat;
|
||||
import android.media.Image;
|
||||
import android.media.ImageReader;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.ColorInfo;
|
||||
import androidx.media3.common.DebugViewProvider;
|
||||
import androidx.media3.common.FrameInfo;
|
||||
@ -296,7 +295,7 @@ public final class GlEffectsFrameProcessorFrameReleaseTest {
|
||||
DebugViewProvider.NONE,
|
||||
/* inputColorInfo= */ ColorInfo.SDR_BT709_LIMITED,
|
||||
/* outputColorInfo= */ ColorInfo.SDR_BT709_LIMITED,
|
||||
C.TRACK_TYPE_VIDEO,
|
||||
/* isInputTextureExternal= */ true,
|
||||
releaseFramesAutomatically,
|
||||
MoreExecutors.directExecutor(),
|
||||
new FrameProcessor.Listener() {
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package androidx.media3.effect;
|
||||
|
||||
import static androidx.media3.common.C.TRACK_TYPE_IMAGE;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||
import static androidx.media3.effect.OverlayShaderProgramPixelTest.OVERLAY_PNG_ASSET_PATH;
|
||||
@ -107,9 +106,7 @@ public final class GlEffectsFrameProcessorPixelTest {
|
||||
public void noEffects_withImageInput_matchesGoldenFile() throws Exception {
|
||||
String testId = "noEffects_withImageInput_matchesGoldenFile";
|
||||
frameProcessorTestRunner =
|
||||
getDefaultFrameProcessorTestRunnerBuilder(testId)
|
||||
.setInputTrackType(TRACK_TYPE_IMAGE)
|
||||
.build();
|
||||
getDefaultFrameProcessorTestRunnerBuilder(testId).setIsInputTextureExternal(false).build();
|
||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||
|
||||
Bitmap actualBitmap = frameProcessorTestRunner.processImageFrameAndEnd(expectedBitmap);
|
||||
@ -125,7 +122,7 @@ public final class GlEffectsFrameProcessorPixelTest {
|
||||
String testId = "wrappedCrop_withImageInput_matchesGoldenFile";
|
||||
frameProcessorTestRunner =
|
||||
getDefaultFrameProcessorTestRunnerBuilder(testId)
|
||||
.setInputTrackType(TRACK_TYPE_IMAGE)
|
||||
.setIsInputTextureExternal(false)
|
||||
.setEffects(
|
||||
new GlEffectWrapper(
|
||||
new Crop(
|
||||
|
@ -72,7 +72,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
private final EGLContext eglContext;
|
||||
private final DebugViewProvider debugViewProvider;
|
||||
private final boolean sampleFromInputTexture;
|
||||
private final boolean isInputExternal;
|
||||
private final boolean isInputTextureExternal;
|
||||
private final ColorInfo inputColorInfo;
|
||||
private final ColorInfo outputColorInfo;
|
||||
private final boolean releaseFramesAutomatically;
|
||||
@ -110,7 +110,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
boolean sampleFromInputTexture,
|
||||
boolean isInputExternal,
|
||||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor frameProcessorListenerExecutor,
|
||||
FrameProcessor.Listener frameProcessorListener) {
|
||||
@ -121,7 +121,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
this.eglContext = eglContext;
|
||||
this.debugViewProvider = debugViewProvider;
|
||||
this.sampleFromInputTexture = sampleFromInputTexture;
|
||||
this.isInputExternal = isInputExternal;
|
||||
this.isInputTextureExternal = isInputTextureExternal;
|
||||
this.inputColorInfo = inputColorInfo;
|
||||
this.outputColorInfo = outputColorInfo;
|
||||
this.releaseFramesAutomatically = releaseFramesAutomatically;
|
||||
@ -406,7 +406,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
ImmutableList<GlMatrixTransformation> expandedMatrixTransformations =
|
||||
matrixTransformationListBuilder.build();
|
||||
if (sampleFromInputTexture) {
|
||||
if (isInputExternal) {
|
||||
if (isInputTextureExternal) {
|
||||
matrixShaderProgram =
|
||||
MatrixShaderProgram.createWithExternalSampler(
|
||||
context,
|
||||
|
@ -98,7 +98,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
DebugViewProvider debugViewProvider,
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
@C.TrackType int inputTrackType,
|
||||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor listenerExecutor,
|
||||
Listener listener)
|
||||
@ -109,7 +109,6 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
checkArgument(inputColorInfo.colorTransfer != C.COLOR_TRANSFER_LINEAR);
|
||||
checkArgument(outputColorInfo.isValid());
|
||||
checkArgument(outputColorInfo.colorTransfer != C.COLOR_TRANSFER_LINEAR);
|
||||
checkArgument(inputTrackType == C.TRACK_TYPE_VIDEO || inputTrackType == C.TRACK_TYPE_IMAGE);
|
||||
|
||||
if (inputColorInfo.colorSpace != outputColorInfo.colorSpace
|
||||
|| ColorInfo.isTransferHdr(inputColorInfo) != ColorInfo.isTransferHdr(outputColorInfo)) {
|
||||
@ -136,7 +135,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
debugViewProvider,
|
||||
inputColorInfo,
|
||||
outputColorInfo,
|
||||
/* isInputExternal= */ inputTrackType == C.TRACK_TYPE_VIDEO,
|
||||
isInputTextureExternal,
|
||||
releaseFramesAutomatically,
|
||||
singleThreadExecutorService,
|
||||
listenerExecutor,
|
||||
@ -170,7 +169,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
DebugViewProvider debugViewProvider,
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
boolean isInputExternal,
|
||||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
ExecutorService singleThreadExecutorService,
|
||||
Executor executor,
|
||||
@ -212,7 +211,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
debugViewProvider,
|
||||
inputColorInfo,
|
||||
outputColorInfo,
|
||||
isInputExternal,
|
||||
isInputTextureExternal,
|
||||
releaseFramesAutomatically,
|
||||
executor,
|
||||
listener);
|
||||
@ -224,7 +223,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
return new GlEffectsFrameProcessor(
|
||||
eglDisplay,
|
||||
eglContext,
|
||||
isInputExternal,
|
||||
isInputTextureExternal,
|
||||
frameProcessingTaskExecutor,
|
||||
shaderPrograms,
|
||||
releaseFramesAutomatically);
|
||||
@ -249,7 +248,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
DebugViewProvider debugViewProvider,
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
boolean isInputExternal,
|
||||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor executor,
|
||||
Listener listener)
|
||||
@ -288,7 +287,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
if (!matrixTransformations.isEmpty() || !rgbMatrices.isEmpty() || sampleFromInputTexture) {
|
||||
MatrixShaderProgram matrixShaderProgram;
|
||||
if (sampleFromInputTexture) {
|
||||
if (isInputExternal) {
|
||||
if (isInputTextureExternal) {
|
||||
matrixShaderProgram =
|
||||
MatrixShaderProgram.createWithExternalSampler(
|
||||
context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo);
|
||||
@ -321,7 +320,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
/* inputColorInfo= */ sampleFromInputTexture ? inputColorInfo : linearColorInfo,
|
||||
outputColorInfo,
|
||||
sampleFromInputTexture,
|
||||
isInputExternal,
|
||||
isInputTextureExternal,
|
||||
releaseFramesAutomatically,
|
||||
executor,
|
||||
listener));
|
||||
@ -374,7 +373,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
private GlEffectsFrameProcessor(
|
||||
EGLDisplay eglDisplay,
|
||||
EGLContext eglContext,
|
||||
boolean isInputExternal,
|
||||
boolean isInputTextureExternal,
|
||||
FrameProcessingTaskExecutor frameProcessingTaskExecutor,
|
||||
ImmutableList<GlShaderProgram> shaderPrograms,
|
||||
boolean releaseFramesAutomatically)
|
||||
@ -390,7 +389,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
|
||||
GlShaderProgram inputShaderProgram = shaderPrograms.get(0);
|
||||
|
||||
if (isInputExternal) {
|
||||
if (isInputTextureExternal) {
|
||||
checkState(inputShaderProgram instanceof ExternalShaderProgram);
|
||||
inputExternalTextureManager =
|
||||
new ExternalTextureManager(
|
||||
@ -422,8 +421,8 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
|
||||
* call this method after instantiation to ensure that buffers are handled at full resolution. See
|
||||
* {@link SurfaceTexture#setDefaultBufferSize(int, int)} for more information.
|
||||
*
|
||||
* <p>This method should only be used for when the {@link FrameProcessor} was created with {@link
|
||||
* C#TRACK_TYPE_VIDEO} as the {@code inputTrackType}.
|
||||
* <p>This method should only be used for when the {@link FrameProcessor}'s {@code
|
||||
* isInputTextureExternal} parameter is set to {@code true}.
|
||||
*
|
||||
* @param width The default width for input buffers, in pixels.
|
||||
* @param height The default height for input buffers, in pixels.
|
||||
|
@ -1992,7 +1992,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||
DebugViewProvider.NONE,
|
||||
inputColorInfo,
|
||||
outputColorInfo,
|
||||
C.TRACK_TYPE_VIDEO,
|
||||
/* isInputTextureExternal= */ true,
|
||||
/* releaseFramesAutomatically= */ false,
|
||||
/* executor= */ handler::post,
|
||||
new FrameProcessor.Listener() {
|
||||
|
@ -62,12 +62,12 @@ public final class FrameProcessorTestRunner {
|
||||
private float pixelWidthHeightRatio;
|
||||
private @MonotonicNonNull ColorInfo inputColorInfo;
|
||||
private @MonotonicNonNull ColorInfo outputColorInfo;
|
||||
private @C.TrackType int inputTrackType;
|
||||
private boolean isInputTextureExternal;
|
||||
|
||||
/** Creates a new instance with default values. */
|
||||
public Builder() {
|
||||
pixelWidthHeightRatio = DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO;
|
||||
inputTrackType = C.TRACK_TYPE_VIDEO;
|
||||
isInputTextureExternal = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,11 +173,11 @@ public final class FrameProcessorTestRunner {
|
||||
/**
|
||||
* Sets the input track type. See {@link FrameProcessor.Factory#create}.
|
||||
*
|
||||
* <p>The default value is {@link C#TRACK_TYPE_VIDEO}.
|
||||
* <p>The default value is {@code true}.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Builder setInputTrackType(@C.TrackType int inputTrackType) {
|
||||
this.inputTrackType = inputTrackType;
|
||||
public Builder setIsInputTextureExternal(boolean isInputTextureExternal) {
|
||||
this.isInputTextureExternal = isInputTextureExternal;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ public final class FrameProcessorTestRunner {
|
||||
pixelWidthHeightRatio,
|
||||
inputColorInfo == null ? ColorInfo.SDR_BT709_LIMITED : inputColorInfo,
|
||||
outputColorInfo == null ? ColorInfo.SDR_BT709_LIMITED : outputColorInfo,
|
||||
inputTrackType);
|
||||
isInputTextureExternal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ public final class FrameProcessorTestRunner {
|
||||
float pixelWidthHeightRatio,
|
||||
ColorInfo inputColorInfo,
|
||||
ColorInfo outputColorInfo,
|
||||
@C.TrackType int inputTrackType)
|
||||
boolean isInputTextureExternal)
|
||||
throws FrameProcessingException {
|
||||
this.testId = testId;
|
||||
this.videoAssetPath = videoAssetPath;
|
||||
@ -240,7 +240,7 @@ public final class FrameProcessorTestRunner {
|
||||
DebugViewProvider.NONE,
|
||||
inputColorInfo,
|
||||
outputColorInfo,
|
||||
inputTrackType,
|
||||
isInputTextureExternal,
|
||||
/* releaseFramesAutomatically= */ true,
|
||||
MoreExecutors.directExecutor(),
|
||||
new FrameProcessor.Listener() {
|
||||
|
@ -140,7 +140,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
debugViewProvider,
|
||||
frameProcessorInputColor,
|
||||
frameProcessorOutputColor,
|
||||
MimeTypes.getTrackType(firstInputFormat.sampleMimeType),
|
||||
MimeTypes.isVideo(firstInputFormat.sampleMimeType),
|
||||
/* releaseFramesAutomatically= */ true,
|
||||
MoreExecutors.directExecutor(),
|
||||
new FrameProcessor.Listener() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user