From 79a3464014f59f1cff66378cc23313f0455c8f7b Mon Sep 17 00:00:00 2001 From: samrobinson Date: Wed, 15 Feb 2023 08:34:44 +0000 Subject: [PATCH] Clarify the mime type used in EncoderUtilTest. PiperOrigin-RevId: 509750806 --- .../media3/transformer/EncoderUtilTest.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libraries/transformer/src/test/java/androidx/media3/transformer/EncoderUtilTest.java b/libraries/transformer/src/test/java/androidx/media3/transformer/EncoderUtilTest.java index de021bd17f..02e4d8977c 100644 --- a/libraries/transformer/src/test/java/androidx/media3/transformer/EncoderUtilTest.java +++ b/libraries/transformer/src/test/java/androidx/media3/transformer/EncoderUtilTest.java @@ -16,6 +16,7 @@ package androidx.media3.transformer; +import static androidx.media3.common.MimeTypes.VIDEO_H264; import static com.google.common.truth.Truth.assertThat; import android.media.MediaCodecInfo; @@ -24,7 +25,6 @@ import android.util.Size; import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.ColorInfo; -import androidx.media3.common.MimeTypes; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.ImmutableList; import org.junit.After; @@ -44,12 +44,10 @@ import org.robolectric.shadows.ShadowMediaCodecList; */ @RunWith(AndroidJUnit4.class) public class EncoderUtilTest { - private static final String MIME_TYPE = MimeTypes.VIDEO_H264; - @Before public void setUp() { MediaFormat avcFormat = new MediaFormat(); - avcFormat.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC); + avcFormat.setString(MediaFormat.KEY_MIME, VIDEO_H264); MediaCodecInfo.CodecProfileLevel profileLevel = new MediaCodecInfo.CodecProfileLevel(); profileLevel.profile = MediaCodecInfo.CodecProfileLevel.AVCProfileHigh; // Using Level4 gives us 8192 16x16 blocks. If using width 1920 uses 120 blocks, 8192 / 120 = 68 @@ -80,12 +78,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_withSupportedResolution_succeeds() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 1920, 1080); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 1920, 1080); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1920); @@ -94,12 +92,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_withUnalignedSize_findsMostCloselySupportedResolution() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 1919, 1081); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 1919, 1081); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1920); @@ -109,12 +107,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_findsThreeQuartersOfTheOriginalSize() { // The supported resolution will try to match the aspect ratio where possible. - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 1920, 1920); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 1920, 1920); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1440); @@ -123,12 +121,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_findsTwoThirdsOfTheOriginalSize() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 2880, 1620); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 2880, 1620); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1920); @@ -137,12 +135,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_findsHalfOfTheOriginalSize() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 2160, 3840); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 2160, 3840); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1080); @@ -151,12 +149,12 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_findsOneQuarterOfTheOriginalSize() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); @Nullable Size closestSupportedResolution = - EncoderUtil.getSupportedResolution(encoderInfo, MIME_TYPE, 7680, 4320); + EncoderUtil.getSupportedResolution(encoderInfo, VIDEO_H264, 7680, 4320); assertThat(closestSupportedResolution).isNotNull(); assertThat(closestSupportedResolution.getWidth()).isEqualTo(1920); @@ -165,14 +163,14 @@ public class EncoderUtilTest { @Test public void getSupportedResolution_requestedReallyLarge_matchesAspectRatio() { - ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE); + ImmutableList supportedEncoders = EncoderUtil.getSupportedEncoders(VIDEO_H264); MediaCodecInfo encoderInfo = supportedEncoders.get(0); double aspectRatio = 1.5; @Nullable Size closestSupportedResolution = EncoderUtil.getSupportedResolution( - encoderInfo, MIME_TYPE, (int) (aspectRatio * 5000), 5000); + encoderInfo, VIDEO_H264, (int) (aspectRatio * 5000), 5000); assertThat(closestSupportedResolution).isNotNull(); assertThat( @@ -192,7 +190,7 @@ public class EncoderUtilTest { // support HDR. assertThat( EncoderUtil.getSupportedEncodersForHdrEditing( - MIME_TYPE, + VIDEO_H264, new ColorInfo.Builder() .setColorSpace(C.COLOR_SPACE_BT2020) .setColorRange(C.COLOR_RANGE_FULL)