Rename MediaFormatUtil constants

PiperOrigin-RevId: 406816023
This commit is contained in:
olly 2021-11-01 14:00:45 +00:00 committed by tonihei
parent f45a8bc4f4
commit eeaa617160
2 changed files with 15 additions and 13 deletions

View File

@ -32,17 +32,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.
*
* <p>Equivalent to {@link MediaFormat#KEY_PCM_ENCODING}, except it allows additional
* ExoPlayer-specific values including {@link C#ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link
* <p>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;
@ -52,8 +54,8 @@ public final class MediaFormatUtil {
* <p>May include the following custom keys:
*
* <ul>
* <li>{@link #KEY_EXO_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT}.
* <li>{@link #KEY_EXO_PCM_ENCODING}.
* <li>{@link #KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT}.
* <li>{@link #KEY_PCM_ENCODING_EXTENDED}.
* </ul>
*/
@SuppressLint("InlinedApi") // Inlined MediaFormat keys.
@ -184,7 +186,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
@ -207,7 +209,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;

View File

@ -37,7 +37,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,
@ -46,7 +46,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);
@ -116,7 +116,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);
@ -140,7 +140,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);
}
@ -148,7 +148,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();
}