Rename MediaFormatUtil constants

PiperOrigin-RevId: 406816023
This commit is contained in:
olly 2021-11-01 14:00:45 +00:00 committed by Ian Baker
parent d1e13b629d
commit 99ace2dbb1
2 changed files with 15 additions and 13 deletions

View File

@ -33,17 +33,19 @@ public final class MediaFormatUtil {
* Custom {@link MediaFormat} key associated with a float representing the ratio between a pixel's * Custom {@link MediaFormat} key associated with a float representing the ratio between a pixel's
* width and height. * 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"; "exo-pixel-width-height-ratio-float";
/** /**
* Custom {@link MediaFormat} key associated with an integer representing the PCM encoding. * Custom {@link MediaFormat} key associated with an integer representing the PCM encoding.
* *
* <p>Equivalent to {@link MediaFormat#KEY_PCM_ENCODING}, except it allows additional * <p>Equivalent to {@link MediaFormat#KEY_PCM_ENCODING}, except it allows additional values
* ExoPlayer-specific values including {@link C#ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link * defined by {@link C.PcmEncoding}, including {@link C#ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link
* C#ENCODING_PCM_24BIT}, and {@link C#ENCODING_PCM_32BIT}. * 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; private static final int MAX_POWER_OF_TWO_INT = 1 << 30;
@ -53,8 +55,8 @@ public final class MediaFormatUtil {
* <p>May include the following custom keys: * <p>May include the following custom keys:
* *
* <ul> * <ul>
* <li>{@link #KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT}. * <li>{@link #KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT}.
* <li>{@link #KEY_EXO_PCM_ENCODING}. * <li>{@link #KEY_PCM_ENCODING_EXTENDED}.
* </ul> * </ul>
*/ */
@SuppressLint("InlinedApi") // Inlined MediaFormat keys. @SuppressLint("InlinedApi") // Inlined MediaFormat keys.
@ -185,7 +187,7 @@ public final class MediaFormatUtil {
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
private static void maybeSetPixelAspectRatio( private static void maybeSetPixelAspectRatio(
MediaFormat mediaFormat, float pixelWidthHeightRatio) { 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 pixelAspectRatioWidth = 1;
int pixelAspectRatioHeight = 1; int pixelAspectRatioHeight = 1;
// ExoPlayer extractors output the pixel aspect ratio as a float. Do our best to recreate the // 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; return;
} }
int mediaFormatPcmEncoding; int mediaFormatPcmEncoding;
maybeSetInteger(mediaFormat, KEY_EXO_PCM_ENCODING, exoPcmEncoding); maybeSetInteger(mediaFormat, KEY_PCM_ENCODING_EXTENDED, exoPcmEncoding);
switch (exoPcmEncoding) { switch (exoPcmEncoding) {
case C.ENCODING_PCM_8BIT: case C.ENCODING_PCM_8BIT:
mediaFormatPcmEncoding = AudioFormat.ENCODING_PCM_8BIT; mediaFormatPcmEncoding = AudioFormat.ENCODING_PCM_8BIT;

View File

@ -38,7 +38,7 @@ public class MediaFormatUtilTest {
// Assert that no invalid keys are accidentally being populated. // Assert that no invalid keys are accidentally being populated.
assertThat(mediaFormat.getKeys()) assertThat(mediaFormat.getKeys())
.containsExactly( .containsExactly(
MediaFormatUtil.KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT, MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT,
MediaFormat.KEY_ENCODER_DELAY, MediaFormat.KEY_ENCODER_DELAY,
MediaFormat.KEY_ENCODER_PADDING, MediaFormat.KEY_ENCODER_PADDING,
MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH, MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH,
@ -47,7 +47,7 @@ public class MediaFormatUtilTest {
MediaFormat.KEY_IS_FORCED_SUBTITLE, MediaFormat.KEY_IS_FORCED_SUBTITLE,
MediaFormat.KEY_IS_AUTOSELECT, MediaFormat.KEY_IS_AUTOSELECT,
MediaFormat.KEY_ROTATION); 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); .isEqualTo(1.f);
assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_DELAY)).isEqualTo(0); assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_DELAY)).isEqualTo(0);
assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_PADDING)).isEqualTo(0); assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_PADDING)).isEqualTo(0);
@ -117,7 +117,7 @@ public class MediaFormatUtilTest {
.isEqualTo(format.initializationData.get(1)); .isEqualTo(format.initializationData.get(1));
assertThat(mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING)).isEqualTo(format.pcmEncoding); 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); .isEqualTo(format.pcmEncoding);
assertThat(mediaFormat.getString(MediaFormat.KEY_LANGUAGE)).isEqualTo(format.language); 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) (float) mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH)
/ mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT); / mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT);
assertThat(calculatedPixelAspectRatio).isWithin(.0001f).of(format.pixelWidthHeightRatio); 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); .isEqualTo(format.pixelWidthHeightRatio);
} }
@ -149,7 +149,7 @@ public class MediaFormatUtilTest {
public void createMediaFormatFromFormat_withPcmEncoding_setsCustomPcmEncodingEntry() { public void createMediaFormatFromFormat_withPcmEncoding_setsCustomPcmEncodingEntry() {
Format format = new Format.Builder().setPcmEncoding(C.ENCODING_PCM_32BIT).build(); Format format = new Format.Builder().setPcmEncoding(C.ENCODING_PCM_32BIT).build();
MediaFormat mediaFormat = MediaFormatUtil.createMediaFormatFromFormat(format); 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); .isEqualTo(C.ENCODING_PCM_32BIT);
assertThat(mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)).isFalse(); assertThat(mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)).isFalse();
} }