Test: Remove setInputColorInfo from VFP test runner.

Instead, for input videos, use the colorInfo provided by the extractor. Similarly, for input images, use sRGB, the only color currently in use.

Textures do still need the input ColorInfo provided though.

PiperOrigin-RevId: 592875967
This commit is contained in:
huangdarwin 2023-12-21 09:03:06 -08:00 committed by Copybara-Service
parent 57d00fcca0
commit 0ed19937d3
8 changed files with 22 additions and 47 deletions

View File

@ -22,7 +22,6 @@ import static org.junit.Assert.assertThrows;
import android.graphics.Bitmap;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.test.utils.VideoFrameProcessorTestRunner;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -115,7 +114,6 @@ public class DefaultVideoFrameProcessorFlushTest {
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(new DefaultVideoFrameProcessor.Factory.Builder().build())
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setOnOutputFrameAvailableForRenderingListener(unused -> outputFrameCount++)
.build();
}

View File

@ -23,7 +23,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.graphics.Bitmap;
import android.util.Pair;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.test.utils.VideoFrameProcessorTestRunner;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
@ -196,7 +195,6 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(new DefaultVideoFrameProcessor.Factory.Builder().build())
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setOnOutputFrameAvailableForRenderingListener(
unused -> checkNotNull(framesProduced).incrementAndGet());
}

View File

@ -26,7 +26,6 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Effect;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.Size;
@ -169,10 +168,7 @@ public final class DefaultVideoFrameProcessorPixelTest {
@Test
@RequiresNonNull("testId")
public void noEffects_withImageInput_matchesGoldenFile() throws Exception {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.build();
videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build();
Bitmap originalBitmap = readBitmap(IMAGE_JPG_ASSET_PATH);
Bitmap expectedBitmap = readBitmap(IMAGE_TO_VIDEO_PNG_ASSET_PATH);
@ -192,7 +188,6 @@ public final class DefaultVideoFrameProcessorPixelTest {
public void wrappedCrop_withImageInput_matchesGoldenFile() throws Exception {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setEffects(
new GlEffectWrapper(
new Crop(
@ -225,7 +220,6 @@ public final class DefaultVideoFrameProcessorPixelTest {
new DefaultVideoFrameProcessor.Factory.Builder()
.setEnableColorTransfers(false)
.build())
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setEffects(NO_OP_EFFECT)
.build();
Bitmap originalBitmap = readBitmap(IMAGE_JPG_ASSET_PATH);

View File

@ -48,6 +48,7 @@ import androidx.media3.common.VideoFrameProcessor;
import androidx.media3.common.util.ConditionVariable;
import androidx.media3.common.util.ConstantRateTimestampIterator;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.MediaFormatUtil;
import androidx.media3.common.util.TimestampIterator;
import androidx.media3.common.util.UnstableApi;
import com.google.common.collect.ImmutableList;
@ -76,7 +77,6 @@ public final class VideoFrameProcessorTestRunner {
private @MonotonicNonNull String outputFileLabel;
private @MonotonicNonNull ImmutableList<Effect> effects;
private float pixelWidthHeightRatio;
private @MonotonicNonNull ColorInfo inputColorInfo;
private @MonotonicNonNull ColorInfo outputColorInfo;
private OnOutputFrameAvailableForRenderingListener onOutputFrameAvailableListener;
private OnVideoFrameProcessingEndedListener onEndedListener;
@ -179,17 +179,6 @@ public final class VideoFrameProcessorTestRunner {
return this;
}
/**
* Sets the input {@link ColorInfo}.
*
* <p>The default value is {@link ColorInfo#SDR_BT709_LIMITED}.
*/
@CanIgnoreReturnValue
public Builder setInputColorInfo(ColorInfo inputColorInfo) {
this.inputColorInfo = inputColorInfo;
return this;
}
/**
* Sets the output {@link ColorInfo}.
*
@ -240,7 +229,6 @@ public final class VideoFrameProcessorTestRunner {
outputFileLabel == null ? "" : outputFileLabel,
effects == null ? ImmutableList.of() : effects,
pixelWidthHeightRatio,
inputColorInfo == null ? ColorInfo.SDR_BT709_LIMITED : inputColorInfo,
outputColorInfo == null ? ColorInfo.SDR_BT709_LIMITED : outputColorInfo,
onOutputFrameAvailableListener,
onEndedListener);
@ -262,7 +250,6 @@ public final class VideoFrameProcessorTestRunner {
private final AtomicReference<VideoFrameProcessingException> videoFrameProcessingException;
private final VideoFrameProcessor videoFrameProcessor;
private final ImmutableList<Effect> effects;
private final ColorInfo inputColorInfo;
private final @MonotonicNonNull BitmapReader bitmapReader;
private VideoFrameProcessorTestRunner(
@ -273,7 +260,6 @@ public final class VideoFrameProcessorTestRunner {
String outputFileLabel,
ImmutableList<Effect> effects,
float pixelWidthHeightRatio,
ColorInfo inputColorInfo,
ColorInfo outputColorInfo,
OnOutputFrameAvailableForRenderingListener onOutputFrameAvailableForRenderingListener,
OnVideoFrameProcessingEndedListener onEndedListener)
@ -335,7 +321,6 @@ public final class VideoFrameProcessorTestRunner {
}
});
this.effects = effects;
this.inputColorInfo = inputColorInfo;
}
public void processFirstFrameAndEnd() throws Exception {
@ -345,11 +330,12 @@ public final class VideoFrameProcessorTestRunner {
@Override
public void onContainerExtracted(MediaFormat mediaFormat) {
videoFrameProcessorReadyCondition.close();
@Nullable ColorInfo colorInfo = MediaFormatUtil.getColorInfo(mediaFormat);
videoFrameProcessor.registerInputStream(
INPUT_TYPE_SURFACE,
effects,
new FrameInfo.Builder(
inputColorInfo,
colorInfo == null ? ColorInfo.SDR_BT709_LIMITED : colorInfo,
mediaFormat.getInteger(MediaFormat.KEY_WIDTH),
mediaFormat.getInteger(MediaFormat.KEY_HEIGHT))
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
@ -375,11 +361,17 @@ public final class VideoFrameProcessorTestRunner {
public void queueInputBitmap(
Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate)
throws InterruptedException {
queueInputBitmap(inputBitmap, durationUs, offsetToAddUs, frameRate, ColorInfo.SRGB_BT709_FULL);
}
public void queueInputBitmap(
Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate, ColorInfo colorInfo)
throws InterruptedException {
videoFrameProcessorReadyCondition.close();
videoFrameProcessor.registerInputStream(
INPUT_TYPE_BITMAP,
effects,
new FrameInfo.Builder(inputColorInfo, inputBitmap.getWidth(), inputBitmap.getHeight())
new FrameInfo.Builder(colorInfo, inputBitmap.getWidth(), inputBitmap.getHeight())
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
.setOffsetToAddUs(offsetToAddUs)
.build());
@ -391,11 +383,17 @@ public final class VideoFrameProcessorTestRunner {
public void queueInputBitmaps(int width, int height, Pair<Bitmap, TimestampIterator>... frames)
throws InterruptedException {
queueInputBitmaps(width, height, ColorInfo.SRGB_BT709_FULL, frames);
}
public void queueInputBitmaps(
int width, int height, ColorInfo colorInfo, Pair<Bitmap, TimestampIterator>... frames)
throws InterruptedException {
videoFrameProcessorReadyCondition.close();
videoFrameProcessor.registerInputStream(
INPUT_TYPE_BITMAP,
effects,
new FrameInfo.Builder(inputColorInfo, width, height)
new FrameInfo.Builder(colorInfo, width, height)
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
.build());
videoFrameProcessorReadyCondition.block();
@ -404,11 +402,12 @@ public final class VideoFrameProcessorTestRunner {
}
}
public void queueInputTexture(GlTextureInfo inputTexture, long pts) throws InterruptedException {
public void queueInputTexture(GlTextureInfo inputTexture, long pts, ColorInfo colorInfo)
throws InterruptedException {
videoFrameProcessor.registerInputStream(
INPUT_TYPE_TEXTURE_ID,
effects,
new FrameInfo.Builder(inputColorInfo, inputTexture.width, inputTexture.height)
new FrameInfo.Builder(colorInfo, inputTexture.width, inputTexture.height)
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
.build());
videoFrameProcessor.setOnInputFrameProcessedListener(

View File

@ -903,7 +903,6 @@ public final class DefaultVideoCompositorPixelTest {
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactoryBuilder.build())
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setBitmapReader(textureBitmapReader)
.setOnEndedListener(() -> videoCompositor.signalEndOfInputSource(inputId));
}

View File

@ -24,7 +24,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.graphics.Bitmap;
import android.util.Pair;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.VideoFrameProcessor;
import androidx.media3.effect.DefaultVideoFrameProcessor;
import androidx.media3.test.utils.BitmapPixelTestUtil;
@ -171,7 +170,6 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest {
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactory)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setBitmapReader(textureBitmapReader);
}
}

View File

@ -224,7 +224,6 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
ColorInfo colorInfo = checkNotNull(format.colorInfo);
videoFrameProcessorTestRunner =
getSurfaceInputFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setVideoAssetPath(INPUT_HLG10_MP4_ASSET_STRING)
.build();
@ -293,7 +292,6 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
ColorInfo colorInfo = checkNotNull(format.colorInfo);
videoFrameProcessorTestRunner =
getSurfaceInputFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setVideoAssetPath(INPUT_PQ_MP4_ASSET_STRING)
.build();
@ -362,7 +360,6 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
ColorInfo colorInfo = checkNotNull(format.colorInfo);
videoFrameProcessorTestRunner =
getSurfaceInputFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setVideoAssetPath(INPUT_HLG10_MP4_ASSET_STRING)
.setEffects(NO_OP_EFFECT)
@ -432,7 +429,6 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
ColorInfo colorInfo = checkNotNull(format.colorInfo);
videoFrameProcessorTestRunner =
getSurfaceInputFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setVideoAssetPath(INPUT_PQ_MP4_ASSET_STRING)
.setEffects(NO_OP_EFFECT)
@ -513,7 +509,6 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactory)
.setVideoAssetPath(videoAssetPath)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setBitmapReader(producersBitmapReader)
.build();
@ -545,14 +540,13 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactory)
.setInputColorInfo(colorInfo)
.setOutputColorInfo(colorInfo)
.setBitmapReader(bitmapReader)
.setEffects(effects)
.build();
GlUtil.awaitSyncObject(syncObject);
try {
videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs);
videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs, colorInfo);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw VideoFrameProcessingException.from(e);

View File

@ -15,7 +15,6 @@
*/
package androidx.media3.transformer.mh;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.test.utils.BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
@ -99,7 +98,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_HLG_MP4_ASSET_STRING)
.setInputColorInfo(checkNotNull(MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.build();
Bitmap expectedBitmap = readBitmap(TONE_MAP_HLG_TO_SDR_PNG_ASSET_PATH);
@ -138,7 +136,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_HLG_MP4_ASSET_STRING)
.setInputColorInfo(checkNotNull(MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.setEffects(ImmutableList.of(NO_OP_EFFECT))
.build();
@ -179,7 +176,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_PQ_MP4_ASSET_STRING)
.setInputColorInfo(checkNotNull(MP4_ASSET_720P_4_SECOND_HDR10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.build();
Bitmap expectedBitmap = readBitmap(TONE_MAP_PQ_TO_SDR_PNG_ASSET_PATH);
@ -219,7 +215,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_PQ_MP4_ASSET_STRING)
.setInputColorInfo(checkNotNull(MP4_ASSET_720P_4_SECOND_HDR10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.setEffects(ImmutableList.of(NO_OP_EFFECT))
.build();