Migrate performance tests to use AndroidTestUtil constants.

PiperOrigin-RevId: 644058273
This commit is contained in:
samrobinson 2024-06-17 10:35:41 -07:00 committed by Copybara-Service
parent 2b55a5bc2d
commit 2698f3ffc2
2 changed files with 23 additions and 30 deletions

View File

@ -16,7 +16,6 @@
package androidx.media3.transformer.mh.performance; 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.Player.STATE_ENDED;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkStateNotNull; 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.createArgb8888BitmapFromRgba8888ImageBuffer;
import static androidx.media3.test.utils.BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888; import static androidx.media3.test.utils.BitmapPixelTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap; 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 androidx.media3.transformer.mh.performance.PlaybackTestUtil.createTimestampOverlay;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
@ -39,7 +39,6 @@ import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.Effect; import androidx.media3.common.Effect;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.common.Player; import androidx.media3.common.Player;
import androidx.media3.common.util.ConditionVariable; import androidx.media3.common.util.ConditionVariable;
@ -76,18 +75,6 @@ import org.junit.runners.Parameterized.Parameters;
public class EffectPlaybackTest { public class EffectPlaybackTest {
private static final String TEST_DIRECTORY = "test-generated-goldens/ExoPlayerPlaybackTest"; 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; private static final long TEST_TIMEOUT_MS = 10_000;
/** /**
@ -122,8 +109,8 @@ public class EffectPlaybackTest {
ConditionVariable hasRenderedFirstFrameCondition = new ConditionVariable(); ConditionVariable hasRenderedFirstFrameCondition = new ConditionVariable();
outputImageReader = outputImageReader =
ImageReader.newInstance( ImageReader.newInstance(
MP4_ASSET_VIDEO_SIZE.getWidth(), MP4_ASSET.videoFormat.width,
MP4_ASSET_VIDEO_SIZE.getHeight(), MP4_ASSET.videoFormat.height,
PixelFormat.RGBA_8888, PixelFormat.RGBA_8888,
/* maxImages= */ 1); /* maxImages= */ 1);
@ -142,14 +129,16 @@ public class EffectPlaybackTest {
Util.createHandlerForCurrentOrMainLooper()); Util.createHandlerForCurrentOrMainLooper());
setOutputSurfaceAndSizeOnPlayer( 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.setPlayWhenReady(playWhenReady);
player.setVideoEffects(ImmutableList.of(createTimestampOverlay())); player.setVideoEffects(ImmutableList.of(createTimestampOverlay()));
// Adding an EventLogger to use its log output in case the test fails. // Adding an EventLogger to use its log output in case the test fails.
player.addAnalyticsListener(new EventLogger()); player.addAnalyticsListener(new EventLogger());
player.setMediaItem(MediaItem.fromUri(MP4_ASSET_URI_STRING)); player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri));
player.prepare(); player.prepare();
}); });
@ -204,8 +193,8 @@ public class EffectPlaybackTest {
// Using maxImages=5 runs successfully on a Pixel3. // Using maxImages=5 runs successfully on a Pixel3.
outputImageReader = outputImageReader =
ImageReader.newInstance( ImageReader.newInstance(
MP4_ASSET_VIDEO_SIZE.getWidth(), MP4_ASSET.videoFormat.width,
MP4_ASSET_VIDEO_SIZE.getHeight(), MP4_ASSET.videoFormat.height,
PixelFormat.RGBA_8888, PixelFormat.RGBA_8888,
/* maxImages= */ 5); /* maxImages= */ 5);
@ -220,14 +209,16 @@ public class EffectPlaybackTest {
readImageBuffers.add( readImageBuffers.add(
BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image)); BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image));
} }
if (renderedFramesCount.incrementAndGet() == MP4_ASSET_FRAMES) { if (renderedFramesCount.incrementAndGet() == MP4_ASSET.videoFrameCount) {
readAllOutputFrames.open(); readAllOutputFrames.open();
} }
}, },
Util.createHandlerForCurrentOrMainLooper()); Util.createHandlerForCurrentOrMainLooper());
setOutputSurfaceAndSizeOnPlayer( 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.setPlayWhenReady(true);
player.setVideoEffects(ImmutableList.of(createTimestampOverlay())); 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(); player.prepare();
}); });
@ -297,8 +288,8 @@ public class EffectPlaybackTest {
// Using maxImages=5 runs successfully on a Pixel3. // Using maxImages=5 runs successfully on a Pixel3.
outputImageReader = outputImageReader =
ImageReader.newInstance( ImageReader.newInstance(
MP4_ASSET_VIDEO_SIZE.getWidth(), MP4_ASSET.videoFormat.width,
MP4_ASSET_VIDEO_SIZE.getHeight(), MP4_ASSET.videoFormat.height,
PixelFormat.RGBA_8888, PixelFormat.RGBA_8888,
/* maxImages= */ 5); /* maxImages= */ 5);
@ -313,14 +304,16 @@ public class EffectPlaybackTest {
readImageBuffers.add( readImageBuffers.add(
BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image)); BitmapPixelTestUtil.copyByteBufferFromRbga8888Image(image));
} }
if (renderedFramesCount.incrementAndGet() == MP4_ASSET_FRAMES) { if (renderedFramesCount.incrementAndGet() == MP4_ASSET.videoFrameCount) {
readAllOutputFrames.open(); readAllOutputFrames.open();
} }
}, },
Util.createHandlerForCurrentOrMainLooper()); Util.createHandlerForCurrentOrMainLooper());
setOutputSurfaceAndSizeOnPlayer( 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.setPlayWhenReady(true);
long exoPresentationTimeOffsetUs = 1000000000000L; long exoPresentationTimeOffsetUs = 1000000000000L;
player.setVideoEffects( 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(); player.prepare();
}); });

View File

@ -17,6 +17,7 @@
package androidx.media3.transformer.mh.performance; package androidx.media3.transformer.mh.performance;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.content.Context; import android.content.Context;
@ -52,7 +53,6 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class ExoplayerEffectPlaybackSeekTest { public final class ExoplayerEffectPlaybackSeekTest {
private static final String MP4_ASSET = "asset:///media/mp4/sample.mp4";
// This timeout is made longer for emulators - see // This timeout is made longer for emulators - see
// ExternalTextureManager.SURFACE_TEXTURE_TIMEOUT_MS. // ExternalTextureManager.SURFACE_TEXTURE_TIMEOUT_MS.
private static final long TEST_TIMEOUT_MS = 20_000; 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. // Adding an EventLogger to use its log output in case the test fails.
player.addAnalyticsListener(new EventLogger()); player.addAnalyticsListener(new EventLogger());
player.addListener(listener); player.addListener(listener);
player.setMediaItem(MediaItem.fromUri(MP4_ASSET)); player.setMediaItem(MediaItem.fromUri(MP4_ASSET.uri));
player.prepare(); player.prepare();
}); });