From 3cf7f58edfac8d11827061dda3bc00aabf59fb9d Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Tue, 26 Apr 2022 11:37:03 +0100 Subject: [PATCH] Transformer GL: save actual bitmap before checking pixel diffs. This allows the actual bitmap to be saved, even if output dimensions are different than expected. Otherwise, differing output dimensions would throw an exception, preventing the bitmap from being saved. PiperOrigin-RevId: 444512210 --- .../AdvancedFrameProcessorPixelTest.java | 16 ++++----- .../FrameProcessorChainPixelTest.java | 24 ++++++------- .../PresentationFrameProcessorPixelTest.java | 36 +++++++++---------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AdvancedFrameProcessorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AdvancedFrameProcessorPixelTest.java index 8b61f2fd97..c64a5dc34d 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AdvancedFrameProcessorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AdvancedFrameProcessorPixelTest.java @@ -98,12 +98,12 @@ public final class AdvancedFrameProcessorPixelTest { Bitmap actualBitmap = BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -120,12 +120,12 @@ public final class AdvancedFrameProcessorPixelTest { Bitmap actualBitmap = BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -142,12 +142,12 @@ public final class AdvancedFrameProcessorPixelTest { Bitmap actualBitmap = BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -164,12 +164,12 @@ public final class AdvancedFrameProcessorPixelTest { Bitmap actualBitmap = BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/FrameProcessorChainPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/FrameProcessorChainPixelTest.java index 9d0d837522..6b550d2544 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/FrameProcessorChainPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/FrameProcessorChainPixelTest.java @@ -95,12 +95,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -116,12 +116,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -140,12 +140,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -164,12 +164,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -184,12 +184,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -204,12 +204,12 @@ public final class FrameProcessorChainPixelTest { Bitmap actualBitmap = processFirstFrameAndEnd(); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/PresentationFrameProcessorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/PresentationFrameProcessorPixelTest.java index e2d97206a7..e484053512 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/PresentationFrameProcessorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/PresentationFrameProcessorPixelTest.java @@ -109,12 +109,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -136,12 +136,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -163,12 +163,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -192,12 +192,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -221,12 +221,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -250,12 +250,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -279,12 +279,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -308,12 +308,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } @@ -337,12 +337,12 @@ public final class PresentationFrameProcessorPixelTest { BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( outputSize.getWidth(), outputSize.getHeight()); + BitmapTestUtil.saveTestBitmapToCacheDirectory( + testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); // TODO(b/207848601): switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( expectedBitmap, actualBitmap, testId); - BitmapTestUtil.saveTestBitmapToCacheDirectory( - testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); }