Commit e039e335 by olly Committed by tonihei

Rename MediaFormatUtil constants

PiperOrigin-RevId: 406816023
parent 8e03a065
...@@ -32,17 +32,19 @@ public final class MediaFormatUtil { ...@@ -32,17 +32,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;
...@@ -52,8 +54,8 @@ public final class MediaFormatUtil { ...@@ -52,8 +54,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.
...@@ -184,7 +186,7 @@ public final class MediaFormatUtil { ...@@ -184,7 +186,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
...@@ -207,7 +209,7 @@ public final class MediaFormatUtil { ...@@ -207,7 +209,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;
......
...@@ -37,7 +37,7 @@ public class MediaFormatUtilTest { ...@@ -37,7 +37,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,
...@@ -46,7 +46,7 @@ public class MediaFormatUtilTest { ...@@ -46,7 +46,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);
...@@ -116,7 +116,7 @@ public class MediaFormatUtilTest { ...@@ -116,7 +116,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);
...@@ -140,7 +140,7 @@ public class MediaFormatUtilTest { ...@@ -140,7 +140,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);
} }
...@@ -148,7 +148,7 @@ public class MediaFormatUtilTest { ...@@ -148,7 +148,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();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment