From 877ba22b200c8fd521fc9a1e028153a4ee372ca3 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/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java index 6f92811095..e0bd109ce9 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/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/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java index b04e23a362..b8cfb3c8c8 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/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/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java index 0d75f4cb72..3425ca1d7e 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/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); }