From 2698f3ffc21c8d2bd669a4d4c40bbe023bdc649b Mon Sep 17 00:00:00 2001 From: samrobinson Date: Mon, 17 Jun 2024 10:35:41 -0700 Subject: [PATCH] Migrate performance tests to use AndroidTestUtil constants. PiperOrigin-RevId: 644058273 --- .../mh/performance/EffectPlaybackTest.java | 49 ++++++++----------- .../ExoplayerEffectPlaybackSeekTest.java | 4 +- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java index 0c241eb08d..423ad75277 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/EffectPlaybackTest.java @@ -16,7 +16,6 @@ package androidx.media3.transformer.mh.performance; -import static androidx.media3.common.MimeTypes.VIDEO_H264; import static androidx.media3.common.Player.STATE_ENDED; import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull; @@ -25,6 +24,7 @@ import static androidx.media3.test.utils.BitmapPixelTestUtil.createArgb8888Bitma import static androidx.media3.test.utils.BitmapPixelTestUtil.createArgb8888BitmapFromRgba8888ImageBuffer; import static androidx.media3.test.utils.BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888; import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap; +import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET; import static androidx.media3.transformer.mh.performance.PlaybackTestUtil.createTimestampOverlay; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; @@ -39,7 +39,6 @@ import android.view.Surface; import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.Effect; -import androidx.media3.common.Format; import androidx.media3.common.MediaItem; import androidx.media3.common.Player; import androidx.media3.common.util.ConditionVariable; @@ -76,18 +75,6 @@ import org.junit.runners.Parameterized.Parameters; public class EffectPlaybackTest { private static final String TEST_DIRECTORY = "test-generated-goldens/ExoPlayerPlaybackTest"; - private static final String MP4_ASSET_URI_STRING = "asset:///media/mp4/sample.mp4"; - private static final Format MP4_ASSET_FORMAT = - new Format.Builder() - .setSampleMimeType(VIDEO_H264) - .setWidth(1080) - .setHeight(720) - .setFrameRate(29.97f) - .setCodecs("avc1.64001F") - .build(); - private static final int MP4_ASSET_FRAMES = 30; - private static final Size MP4_ASSET_VIDEO_SIZE = - new Size(MP4_ASSET_FORMAT.width, MP4_ASSET_FORMAT.height); private static final long TEST_TIMEOUT_MS = 10_000; /** @@ -122,8 +109,8 @@ public class EffectPlaybackTest { ConditionVariable hasRenderedFirstFrameCondition = new ConditionVariable(); outputImageReader = ImageReader.newInstance( - MP4_ASSET_VIDEO_SIZE.getWidth(), - MP4_ASSET_VIDEO_SIZE.getHeight(), + MP4_ASSET.videoFormat.width, + MP4_ASSET.videoFormat.height, PixelFormat.RGBA_8888, /* maxImages= */ 1); @@ -142,14 +129,16 @@ public class EffectPlaybackTest { Util.createHandlerForCurrentOrMainLooper()); setOutputSurfaceAndSizeOnPlayer( - player, outputImageReader.getSurface(), MP4_ASSET_VIDEO_SIZE); + player, + outputImageReader.getSurface(), + new Size(MP4_ASSET.videoFormat.width, MP4_ASSET.videoFormat.height)); player.setPlayWhenReady(playWhenReady); player.setVideoEffects(ImmutableList.of(createTimestampOverlay())); // Adding an EventLogger to use its log output in case the test fails. player.addAnalyticsListener(new EventLogger()); - player.setMediaItem(MediaItem.fromUri(MP4_ASSET_URI_STRING)); + player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri)); player.prepare(); }); @@ -204,8 +193,8 @@ public class EffectPlaybackTest { // Using maxImages=5 runs successfully on a Pixel3. outputImageReader = ImageReader.newInstance( - MP4_ASSET_VIDEO_SIZE.getWidth(), - MP4_ASSET_VIDEO_SIZE.getHeight(), + MP4_ASSET.videoFormat.width, + MP4_ASSET.videoFormat.height, PixelFormat.RGBA_8888, /* maxImages= */ 5); @@ -220,14 +209,16 @@ public class EffectPlaybackTest { readImageBuffers.add( BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image)); } - if (renderedFramesCount.incrementAndGet() == MP4_ASSET_FRAMES) { + if (renderedFramesCount.incrementAndGet() == MP4_ASSET.videoFrameCount) { readAllOutputFrames.open(); } }, Util.createHandlerForCurrentOrMainLooper()); setOutputSurfaceAndSizeOnPlayer( - player, outputImageReader.getSurface(), MP4_ASSET_VIDEO_SIZE); + player, + outputImageReader.getSurface(), + new Size(MP4_ASSET.videoFormat.width, MP4_ASSET.videoFormat.height)); player.setPlayWhenReady(true); player.setVideoEffects(ImmutableList.of(createTimestampOverlay())); @@ -242,7 +233,7 @@ public class EffectPlaybackTest { } } }); - player.setMediaItem(MediaItem.fromUri(MP4_ASSET_URI_STRING)); + player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri)); player.prepare(); }); @@ -297,8 +288,8 @@ public class EffectPlaybackTest { // Using maxImages=5 runs successfully on a Pixel3. outputImageReader = ImageReader.newInstance( - MP4_ASSET_VIDEO_SIZE.getWidth(), - MP4_ASSET_VIDEO_SIZE.getHeight(), + MP4_ASSET.videoFormat.width, + MP4_ASSET.videoFormat.height, PixelFormat.RGBA_8888, /* maxImages= */ 5); @@ -313,14 +304,16 @@ public class EffectPlaybackTest { readImageBuffers.add( BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image)); } - if (renderedFramesCount.incrementAndGet() == MP4_ASSET_FRAMES) { + if (renderedFramesCount.incrementAndGet() == MP4_ASSET.videoFrameCount) { readAllOutputFrames.open(); } }, Util.createHandlerForCurrentOrMainLooper()); setOutputSurfaceAndSizeOnPlayer( - player, outputImageReader.getSurface(), MP4_ASSET_VIDEO_SIZE); + player, + outputImageReader.getSurface(), + new Size(MP4_ASSET.videoFormat.width, MP4_ASSET.videoFormat.height)); player.setPlayWhenReady(true); long exoPresentationTimeOffsetUs = 1000000000000L; player.setVideoEffects( @@ -341,7 +334,7 @@ public class EffectPlaybackTest { } } }); - player.setMediaItem(MediaItem.fromUri(MP4_ASSET_URI_STRING)); + player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri)); player.prepare(); }); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/ExoplayerEffectPlaybackSeekTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/ExoplayerEffectPlaybackSeekTest.java index 6482ea27b7..1b64e9a06b 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/ExoplayerEffectPlaybackSeekTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/performance/ExoplayerEffectPlaybackSeekTest.java @@ -17,6 +17,7 @@ package androidx.media3.transformer.mh.performance; import static androidx.media3.common.util.Assertions.checkState; +import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET; import android.app.Instrumentation; import android.content.Context; @@ -52,7 +53,6 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public final class ExoplayerEffectPlaybackSeekTest { - private static final String MP4_ASSET = "asset:///media/mp4/sample.mp4"; // This timeout is made longer for emulators - see // ExternalTextureManager.SURFACE_TEXTURE_TIMEOUT_MS. private static final long TEST_TIMEOUT_MS = 20_000; @@ -143,7 +143,7 @@ public final class ExoplayerEffectPlaybackSeekTest { // Adding an EventLogger to use its log output in case the test fails. player.addAnalyticsListener(new EventLogger()); player.addListener(listener); - player.setMediaItem(MediaItem.fromUri(MP4_ASSET)); + player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri)); player.prepare(); });