From 99ace2dbb17a992a69334a4fd39d445a08ff7ca5 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 1 Nov 2021 14:00:45 +0000 Subject: [PATCH] Rename MediaFormatUtil constants PiperOrigin-RevId: 406816023 --- .../media3/common/util/MediaFormatUtil.java | 18 ++++++++++-------- .../common/util/MediaFormatUtilTest.java | 10 +++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libraries/common/src/main/java/androidx/media3/common/util/MediaFormatUtil.java b/libraries/common/src/main/java/androidx/media3/common/util/MediaFormatUtil.java index 35cf6a2133..e8ea10aca8 100644 --- a/libraries/common/src/main/java/androidx/media3/common/util/MediaFormatUtil.java +++ b/libraries/common/src/main/java/androidx/media3/common/util/MediaFormatUtil.java @@ -33,17 +33,19 @@ public final class MediaFormatUtil { * Custom {@link MediaFormat} key associated with a float representing the ratio between a pixel's * width and height. */ - public static final String KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = + // The constant value must not be changed, because it's also set by the framework MediaParser API. + public static final String KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float"; /** * Custom {@link MediaFormat} key associated with an integer representing the PCM encoding. * - *

Equivalent to {@link MediaFormat#KEY_PCM_ENCODING}, except it allows additional - * ExoPlayer-specific values including {@link C#ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link + *

Equivalent to {@link MediaFormat#KEY_PCM_ENCODING}, except it allows additional values + * defined by {@link C.PcmEncoding}, including {@link C#ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link * C#ENCODING_PCM_24BIT}, and {@link C#ENCODING_PCM_32BIT}. */ - public static final String KEY_EXO_PCM_ENCODING = "exo-pcm-encoding-int"; + // The constant value must not be changed, because it's also set by the framework MediaParser API. + public static final String KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int"; private static final int MAX_POWER_OF_TWO_INT = 1 << 30; @@ -53,8 +55,8 @@ public final class MediaFormatUtil { *

May include the following custom keys: * *

*/ @SuppressLint("InlinedApi") // Inlined MediaFormat keys. @@ -185,7 +187,7 @@ public final class MediaFormatUtil { @SuppressLint("InlinedApi") private static void maybeSetPixelAspectRatio( MediaFormat mediaFormat, float pixelWidthHeightRatio) { - mediaFormat.setFloat(KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT, pixelWidthHeightRatio); + mediaFormat.setFloat(KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT, pixelWidthHeightRatio); int pixelAspectRatioWidth = 1; int pixelAspectRatioHeight = 1; // ExoPlayer extractors output the pixel aspect ratio as a float. Do our best to recreate the @@ -208,7 +210,7 @@ public final class MediaFormatUtil { return; } int mediaFormatPcmEncoding; - maybeSetInteger(mediaFormat, KEY_EXO_PCM_ENCODING, exoPcmEncoding); + maybeSetInteger(mediaFormat, KEY_PCM_ENCODING_EXTENDED, exoPcmEncoding); switch (exoPcmEncoding) { case C.ENCODING_PCM_8BIT: mediaFormatPcmEncoding = AudioFormat.ENCODING_PCM_8BIT; diff --git a/libraries/common/src/test/java/androidx/media3/common/util/MediaFormatUtilTest.java b/libraries/common/src/test/java/androidx/media3/common/util/MediaFormatUtilTest.java index 72cee1a71f..9979f7e921 100644 --- a/libraries/common/src/test/java/androidx/media3/common/util/MediaFormatUtilTest.java +++ b/libraries/common/src/test/java/androidx/media3/common/util/MediaFormatUtilTest.java @@ -38,7 +38,7 @@ public class MediaFormatUtilTest { // Assert that no invalid keys are accidentally being populated. assertThat(mediaFormat.getKeys()) .containsExactly( - MediaFormatUtil.KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT, + MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT, MediaFormat.KEY_ENCODER_DELAY, MediaFormat.KEY_ENCODER_PADDING, MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH, @@ -47,7 +47,7 @@ public class MediaFormatUtilTest { MediaFormat.KEY_IS_FORCED_SUBTITLE, MediaFormat.KEY_IS_AUTOSELECT, MediaFormat.KEY_ROTATION); - assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)) + assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)) .isEqualTo(1.f); assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_DELAY)).isEqualTo(0); assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_PADDING)).isEqualTo(0); @@ -117,7 +117,7 @@ public class MediaFormatUtilTest { .isEqualTo(format.initializationData.get(1)); assertThat(mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING)).isEqualTo(format.pcmEncoding); - assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_EXO_PCM_ENCODING)) + assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_PCM_ENCODING_EXTENDED)) .isEqualTo(format.pcmEncoding); assertThat(mediaFormat.getString(MediaFormat.KEY_LANGUAGE)).isEqualTo(format.language); @@ -141,7 +141,7 @@ public class MediaFormatUtilTest { (float) mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) / mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT); assertThat(calculatedPixelAspectRatio).isWithin(.0001f).of(format.pixelWidthHeightRatio); - assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)) + assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)) .isEqualTo(format.pixelWidthHeightRatio); } @@ -149,7 +149,7 @@ public class MediaFormatUtilTest { public void createMediaFormatFromFormat_withPcmEncoding_setsCustomPcmEncodingEntry() { Format format = new Format.Builder().setPcmEncoding(C.ENCODING_PCM_32BIT).build(); MediaFormat mediaFormat = MediaFormatUtil.createMediaFormatFromFormat(format); - assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_EXO_PCM_ENCODING)) + assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_PCM_ENCODING_EXTENDED)) .isEqualTo(C.ENCODING_PCM_32BIT); assertThat(mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)).isFalse(); }