From f172923f0d09582d0804a8c6805aced7ed98d27b Mon Sep 17 00:00:00 2001 From: claincly Date: Wed, 8 Nov 2023 10:37:02 -0800 Subject: [PATCH] Remove possibly retained bitmap reference PiperOrigin-RevId: 580579054 --- .../effect/DefaultVideoFrameProcessorPixelTest.java | 4 +++- .../androidx/media3/effect/BitmapTextureManager.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java index 3c6249eb2b..7bfe7bd179 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java @@ -229,6 +229,8 @@ public final class DefaultVideoFrameProcessorPixelTest { .setEffects(NO_OP_EFFECT) .build(); Bitmap originalBitmap = readBitmap(IMAGE_JPG_ASSET_PATH); + // VideoFrameProcessor recycles the original bitmap so it cannot be used for comparison. + Bitmap expectedBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, /* isMutable= */ false); videoFrameProcessorTestRunner.queueInputBitmap( originalBitmap, C.MICROS_PER_SECOND, /* offsetToAddUs= */ 0L, /* frameRate= */ 1); @@ -237,7 +239,7 @@ public final class DefaultVideoFrameProcessorPixelTest { // TODO(b/207848601): Switch to using proper tooling for testing against golden data. float averagePixelAbsoluteDifference = - getBitmapAveragePixelAbsoluteDifferenceArgb8888(originalBitmap, actualBitmap, testId); + getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); } diff --git a/libraries/effect/src/main/java/androidx/media3/effect/BitmapTextureManager.java b/libraries/effect/src/main/java/androidx/media3/effect/BitmapTextureManager.java index 2b14ceb6db..70c68b0237 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/BitmapTextureManager.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/BitmapTextureManager.java @@ -53,9 +53,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; private @MonotonicNonNull GlTextureInfo currentGlTextureInfo; private int downstreamShaderProgramCapacity; - // TODO - b/262693274: Support HDR. Currently this variable is not used and will trigger error - // prone warning. + + // TODO - b/262693274: Support HDR. + @SuppressWarnings({"UnusedVariable", "FieldCanBeLocal"}) private boolean useHdr; + private boolean currentInputStreamEnded; private boolean isNextFrameInTexture; @@ -127,6 +129,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; if (currentGlTextureInfo != null) { currentGlTextureInfo.release(); } + pendingBitmaps.clear(); }); } @@ -174,7 +177,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; if (!currentBitmapInfo.inStreamOffsetsUs.hasNext()) { isNextFrameInTexture = false; - pendingBitmaps.remove(); + BitmapFrameSequenceInfo finishedBitmapInfo = pendingBitmaps.remove(); + finishedBitmapInfo.bitmap.recycle(); if (pendingBitmaps.isEmpty() && currentInputStreamEnded) { // Only signal end of stream after all pending bitmaps are processed. shaderProgram.signalEndOfCurrentInputStream();