From 8c4aa6b75d7c4d238d7f43862b3a40ff079197d7 Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Fri, 14 Jul 2023 18:22:59 +0100 Subject: [PATCH] Compositor: Add 10 frame test. This serves as a sort of test with more frames for the compositor for now (before more varied video system tests come later when integrating with Transformer), showing it doesn't error out and outputs the right amount of frames. Due to the VFPTestRunner having a 5s timeout, and mostly due to presubmit emulators being very slow with OpenGL, there is a sort of limitation to how many frames this type of test can have, depending on the test target PiperOrigin-RevId: 548159762 --- .../transformer/VideoCompositorPixelTest.java | 66 +++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/VideoCompositorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/VideoCompositorPixelTest.java index e749b1eeb2..dd803eec64 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/VideoCompositorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/VideoCompositorPixelTest.java @@ -44,10 +44,10 @@ import androidx.media3.test.utils.VideoFrameProcessorTestRunner; import com.google.common.collect.ImmutableList; import java.io.IOException; import java.util.List; -import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -114,16 +114,14 @@ public final class VideoCompositorPixelTest { videoCompositorTestRunner.queueBitmapsToBothInputs(/* count= */ 1); - Bitmap actualCompositorInputBitmap1 = videoCompositorTestRunner.inputBitmapReader1.getBitmap(); saveAndAssertBitmapMatchesExpected( testId, - actualCompositorInputBitmap1, + videoCompositorTestRunner.inputBitmapReader1.getBitmap(), /* actualBitmapLabel= */ "actualCompositorInputBitmap1", GRAYSCALE_PNG_ASSET_PATH); - Bitmap actualCompositorInputBitmap2 = videoCompositorTestRunner.inputBitmapReader2.getBitmap(); saveAndAssertBitmapMatchesExpected( testId, - actualCompositorInputBitmap2, + videoCompositorTestRunner.inputBitmapReader2.getBitmap(), /* actualBitmapLabel= */ "actualCompositorInputBitmap2", ROTATE180_PNG_ASSET_PATH); saveAndAssertBitmapMatchesExpected( @@ -176,12 +174,12 @@ public final class VideoCompositorPixelTest { 2L * C.MICROS_PER_SECOND, 3L * C.MICROS_PER_SECOND, 4L * C.MICROS_PER_SECOND); - Set inputTimestampsSource1 = - videoCompositorTestRunner.inputBitmapReader1.getOutputTimestamps(); - assertThat(inputTimestampsSource1).containsExactlyElementsIn(expectedTimestamps).inOrder(); - Set inputTimestampsSource2 = - videoCompositorTestRunner.inputBitmapReader2.getOutputTimestamps(); - assertThat(inputTimestampsSource2).containsExactlyElementsIn(expectedTimestamps).inOrder(); + assertThat(videoCompositorTestRunner.inputBitmapReader1.getOutputTimestamps()) + .containsExactlyElementsIn(expectedTimestamps) + .inOrder(); + assertThat(videoCompositorTestRunner.inputBitmapReader2.getOutputTimestamps()) + .containsExactlyElementsIn(expectedTimestamps) + .inOrder(); assertThat(compositorTimestamps).containsExactlyElementsIn(expectedTimestamps).inOrder(); saveAndAssertBitmapMatchesExpected( testId, @@ -190,6 +188,52 @@ public final class VideoCompositorPixelTest { GRAYSCALE_AND_ROTATE180_COMPOSITE_PNG_ASSET_PATH); } + @Test + public void compositeTwoInputs_withTenFramesFromEach_matchesExpectedFrameCount() + throws Exception { + String testId = + "compositeTwoInputs_withTenFramesFromEach_matchesExpectedFrameCount[useSharedExecutor=" + + useSharedExecutor + + "]"; + AtomicInteger compositedFrameCount = new AtomicInteger(); + AtomicReference compositedFirstOutputBitmap = new AtomicReference<>(); + videoCompositorTestRunner = + new VideoCompositorTestRunner( + testId, + (outputTexture, presentationTimeUs, releaseOutputTextureCallback, syncObject) -> { + try { + if (!useSharedExecutor) { + GlUtil.awaitSyncObject(syncObject); + } + if (compositedFirstOutputBitmap.get() == null) { + compositedFirstOutputBitmap.set( + BitmapPixelTestUtil.createArgb8888BitmapFromFocusedGlFramebuffer( + outputTexture.width, outputTexture.height)); + } + compositedFrameCount.incrementAndGet(); + } catch (GlUtil.GlException e) { + throw VideoFrameProcessingException.from(e); + } finally { + releaseOutputTextureCallback.release(presentationTimeUs); + } + }, + useSharedExecutor); + int numberOfFramesToQueue = 10; + + videoCompositorTestRunner.queueBitmapsToBothInputs(numberOfFramesToQueue); + + assertThat(videoCompositorTestRunner.inputBitmapReader1.getOutputTimestamps()) + .hasSize(numberOfFramesToQueue); + assertThat(videoCompositorTestRunner.inputBitmapReader2.getOutputTimestamps()) + .hasSize(numberOfFramesToQueue); + assertThat(compositedFrameCount.get()).isEqualTo(numberOfFramesToQueue); + saveAndAssertBitmapMatchesExpected( + testId, + compositedFirstOutputBitmap.get(), + /* actualBitmapLabel= */ "compositorOutputBitmap", + GRAYSCALE_AND_ROTATE180_COMPOSITE_PNG_ASSET_PATH); + } + /** * A test runner for {@link VideoCompositor tests} tests. *