From 8a40952e1bdde83cf6346ec1a384d5750c4ea0d6 Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Fri, 22 Sep 2023 11:00:25 -0700 Subject: [PATCH] Test: Use timestamp iterator in texture output test. Simplify tests, before we add some similar tests. PiperOrigin-RevId: 567666340 --- ...ocessorMultipleTextureOutputPixelTest.java | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java index df803901ba..4547d308e7 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java @@ -19,10 +19,11 @@ import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.test.utils.BitmapPixelTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE; import static androidx.media3.test.utils.BitmapPixelTestUtil.maybeSaveTestBitmap; import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap; +import static androidx.media3.test.utils.VideoFrameProcessorTestRunner.createTimestampIterator; import static com.google.common.truth.Truth.assertThat; import android.graphics.Bitmap; -import androidx.media3.common.C; +import android.util.Pair; import androidx.media3.common.ColorInfo; import androidx.media3.common.VideoFrameProcessor; import androidx.media3.effect.DefaultVideoFrameProcessor; @@ -30,6 +31,9 @@ import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.TextureBitmapReader; import androidx.media3.test.utils.VideoFrameProcessorTestRunner; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.common.collect.ImmutableList; +import java.io.IOException; +import java.util.List; import java.util.Set; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.junit.After; @@ -66,21 +70,15 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest { public void textureOutput_queueBitmap_matchesGoldenFile() throws Exception { String testId = "textureOutput_queueBitmap_matchesGoldenFile"; videoFrameProcessorTestRunner = getFrameProcessorTestRunnerBuilder(testId).build(); + ImmutableList inputTimestamps = ImmutableList.of(1_000_000L, 2_000_000L, 3_000_000L); - long offsetUs = 1_000_000L; - videoFrameProcessorTestRunner.queueInputBitmap( - readBitmap(ORIGINAL_PNG_ASSET_PATH), - /* durationUs= */ 3 * C.MICROS_PER_SECOND, - /* offsetToAddUs= */ offsetUs, - /* frameRate= */ 1); + queueBitmaps(videoFrameProcessorTestRunner, ORIGINAL_PNG_ASSET_PATH, inputTimestamps); videoFrameProcessorTestRunner.endFrameProcessing(); TextureBitmapReader textureBitmapReader = checkNotNull(this.textureBitmapReader); Set outputTimestamps = textureBitmapReader.getOutputTimestamps(); - assertThat(outputTimestamps) - .containsExactly( - offsetUs, offsetUs + C.MICROS_PER_SECOND, offsetUs + 2 * C.MICROS_PER_SECOND); - Bitmap actualBitmap = textureBitmapReader.getBitmap(offsetUs); + assertThat(outputTimestamps).containsExactlyElementsIn(inputTimestamps).inOrder(); + Bitmap actualBitmap = textureBitmapReader.getBitmap(/* presentationTimeUs= */ 1_000_000L); maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual", actualBitmap, /* path= */ null); float averagePixelAbsoluteDifference = BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888( @@ -93,33 +91,21 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest { public void textureOutput_queueTwoBitmaps_matchesGoldenFiles() throws Exception { String testId = "textureOutput_queueTwoBitmaps_matchesGoldenFiles"; videoFrameProcessorTestRunner = getFrameProcessorTestRunnerBuilder(testId).build(); + ImmutableList inputTimestamps1 = ImmutableList.of(1_000_000L, 1_500_000L); + ImmutableList inputTimestamps2 = ImmutableList.of(2_000_000L, 3_000_000L, 4_000_000L); + ImmutableList outputTimestamps = + ImmutableList.of(1_000_000L, 1_500_000L, 2_000_000L, 3_000_000L, 4_000_000L); - long offsetUs1 = 1_000_000L; - videoFrameProcessorTestRunner.queueInputBitmap( - readBitmap(ORIGINAL_PNG_ASSET_PATH), - /* durationUs= */ C.MICROS_PER_SECOND, - /* offsetToAddUs= */ offsetUs1, - /* frameRate= */ 2); - long offsetUs2 = 2_000_000L; - videoFrameProcessorTestRunner.queueInputBitmap( - readBitmap(MEDIA3_TEST_PNG_ASSET_PATH), - /* durationUs= */ 3 * C.MICROS_PER_SECOND, - /* offsetToAddUs= */ offsetUs2, - /* frameRate= */ 1); + queueBitmaps(videoFrameProcessorTestRunner, ORIGINAL_PNG_ASSET_PATH, inputTimestamps1); + queueBitmaps(videoFrameProcessorTestRunner, MEDIA3_TEST_PNG_ASSET_PATH, inputTimestamps2); videoFrameProcessorTestRunner.endFrameProcessing(); TextureBitmapReader textureBitmapReader = checkNotNull(this.textureBitmapReader); - Set outputTimestamps = textureBitmapReader.getOutputTimestamps(); - assertThat(outputTimestamps) - .containsExactly( - offsetUs1, - offsetUs1 + C.MICROS_PER_SECOND / 2, - offsetUs2, - offsetUs2 + C.MICROS_PER_SECOND, - offsetUs2 + 2 * C.MICROS_PER_SECOND); - Bitmap actualBitmap1 = textureBitmapReader.getBitmap(offsetUs1); + Set actualOutputTimestamps = textureBitmapReader.getOutputTimestamps(); + assertThat(actualOutputTimestamps).containsExactlyElementsIn(outputTimestamps).inOrder(); + Bitmap actualBitmap1 = textureBitmapReader.getBitmap(/* presentationTimeUs= */ 1_000_000L); maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual1", actualBitmap1, /* path= */ null); - Bitmap actualBitmap2 = textureBitmapReader.getBitmap(offsetUs2); + Bitmap actualBitmap2 = textureBitmapReader.getBitmap(/* presentationTimeUs= */ 2_000_000L); maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual2", actualBitmap2, /* path= */ null); float averagePixelAbsoluteDifference1 = BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888( @@ -133,6 +119,18 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest { .isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE); } + private void queueBitmaps( + VideoFrameProcessorTestRunner videoFrameProcessorTestRunner, + String bitmapAssetPath, + List timestamps) + throws IOException, InterruptedException { + Bitmap bitmap = readBitmap(bitmapAssetPath); + videoFrameProcessorTestRunner.queueInputBitmaps( + bitmap.getWidth(), + bitmap.getHeight(), + Pair.create(bitmap, createTimestampIterator(timestamps))); + } + private VideoFrameProcessorTestRunner.Builder getFrameProcessorTestRunnerBuilder(String testId) { textureBitmapReader = new TextureBitmapReader(); VideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =