Add MdtaMetadataEntry constructor with default locale indicator

PiperOrigin-RevId: 609427529
This commit is contained in:
sheenachhabra 2024-02-22 10:52:41 -08:00 committed by Copybara-Service
parent 82065e699a
commit fd8f45b38e
4 changed files with 23 additions and 21 deletions

View File

@ -33,6 +33,9 @@ public final class MdtaMetadataEntry implements Metadata.Entry {
/** Key for the capture frame rate (in frames per second). */ /** Key for the capture frame rate (in frames per second). */
public static final String KEY_ANDROID_CAPTURE_FPS = "com.android.capture.fps"; public static final String KEY_ANDROID_CAPTURE_FPS = "com.android.capture.fps";
/** The default locale indicator which implies all speakers in all countries. */
public static final int DEFAULT_LOCALE_INDICATOR = 0;
/** The type indicator for UTF-8 string. */ /** The type indicator for UTF-8 string. */
public static final int TYPE_INDICATOR_STRING = 1; public static final int TYPE_INDICATOR_STRING = 1;
@ -54,6 +57,14 @@ public final class MdtaMetadataEntry implements Metadata.Entry {
/** The four byte type indicator. */ /** The four byte type indicator. */
public final int typeIndicator; public final int typeIndicator;
/**
* Creates a new metadata entry for the specified metadata key/value with {@linkplain
* #DEFAULT_LOCALE_INDICATOR default locale indicator}.
*/
public MdtaMetadataEntry(String key, byte[] value, int typeIndicator) {
this(key, value, DEFAULT_LOCALE_INDICATOR, typeIndicator);
}
/** Creates a new metadata entry for the specified metadata key/value. */ /** Creates a new metadata entry for the specified metadata key/value. */
public MdtaMetadataEntry(String key, byte[] value, int localeIndicator, int typeIndicator) { public MdtaMetadataEntry(String key, byte[] value, int localeIndicator, int typeIndicator) {
this.key = key; this.key = key;

View File

@ -29,7 +29,11 @@ public final class MdtaMetadataEntryTest {
@Test @Test
public void parcelable() { public void parcelable() {
MdtaMetadataEntry mdtaMetadataEntryToParcel = MdtaMetadataEntry mdtaMetadataEntryToParcel =
new MdtaMetadataEntry("test", new byte[] {1, 2}, 3, 4); new MdtaMetadataEntry(
/* key= */ "test",
/* value= */ new byte[] {1, 2},
/* localeIndicator= */ 3,
/* typeIndicator= */ 4);
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
mdtaMetadataEntryToParcel.writeToParcel(parcel, 0); mdtaMetadataEntryToParcel.writeToParcel(parcel, 0);

View File

@ -17,6 +17,8 @@
package androidx.media3.exoplayer; package androidx.media3.exoplayer;
import static androidx.media3.container.MdtaMetadataEntry.KEY_ANDROID_CAPTURE_FPS; import static androidx.media3.container.MdtaMetadataEntry.KEY_ANDROID_CAPTURE_FPS;
import static androidx.media3.container.MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32;
import static androidx.media3.container.MdtaMetadataEntry.TYPE_INDICATOR_STRING;
import static androidx.media3.exoplayer.MetadataRetriever.retrieveMetadata; import static androidx.media3.exoplayer.MetadataRetriever.retrieveMetadata;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
@ -160,13 +162,11 @@ public class MetadataRetrieverTest {
new MdtaMetadataEntry( new MdtaMetadataEntry(
/* key= */ "com.android.version", /* key= */ "com.android.version",
/* value= */ Util.getUtf8Bytes("10"), /* value= */ Util.getUtf8Bytes("10"),
/* localeIndicator= */ 0, TYPE_INDICATOR_STRING);
MdtaMetadataEntry.TYPE_INDICATOR_STRING);
MdtaMetadataEntry expectedTemporalLayersCountMetdata = MdtaMetadataEntry expectedTemporalLayersCountMetdata =
new MdtaMetadataEntry( new MdtaMetadataEntry(
/* key= */ "com.android.video.temporal_layers_count", /* key= */ "com.android.video.temporal_layers_count",
/* value= */ Util.toByteArray(4), /* value= */ Util.toByteArray(4),
/* localeIndicator= */ 0,
MdtaMetadataEntry.TYPE_INDICATOR_INT32); MdtaMetadataEntry.TYPE_INDICATOR_INT32);
SmtaMetadataEntry expectedSmtaEntry = SmtaMetadataEntry expectedSmtaEntry =
new SmtaMetadataEntry(/* captureFrameRate= */ 240, /* svcTemporalLayerCount= */ 4); new SmtaMetadataEntry(/* captureFrameRate= */ 240, /* svcTemporalLayerCount= */ 4);
@ -185,10 +185,7 @@ public class MetadataRetrieverTest {
/* timescale= */ 1000); /* timescale= */ 1000);
MdtaMetadataEntry expectedMdtaEntry = MdtaMetadataEntry expectedMdtaEntry =
new MdtaMetadataEntry( new MdtaMetadataEntry(
KEY_ANDROID_CAPTURE_FPS, KEY_ANDROID_CAPTURE_FPS, /* value= */ Util.toByteArray(240.0f), TYPE_INDICATOR_FLOAT32);
/* value= */ new byte[] {67, 112, 0, 0},
/* localeIndicator= */ 0,
/* typeIndicator= */ 23);
ListenableFuture<TrackGroupArray> trackGroupsFuture = ListenableFuture<TrackGroupArray> trackGroupsFuture =
retrieveMetadata(context, mediaItem, clock); retrieveMetadata(context, mediaItem, clock);
@ -227,8 +224,7 @@ public class MetadataRetrieverTest {
new MdtaMetadataEntry( new MdtaMetadataEntry(
/* key= */ "com.android.version", /* key= */ "com.android.version",
/* value= */ Util.getUtf8Bytes("13"), /* value= */ Util.getUtf8Bytes("13"),
/* localeIndicator= */ 0, TYPE_INDICATOR_STRING);
MdtaMetadataEntry.TYPE_INDICATOR_STRING);
SmtaMetadataEntry expectedSmtaEntry = SmtaMetadataEntry expectedSmtaEntry =
new SmtaMetadataEntry(/* captureFrameRate= */ 240, /* svcTemporalLayerCount= */ 4); new SmtaMetadataEntry(/* captureFrameRate= */ 240, /* svcTemporalLayerCount= */ 4);
SlowMotionData expectedSlowMotionData = SlowMotionData expectedSlowMotionData =
@ -238,11 +234,7 @@ public class MetadataRetrieverTest {
/* startTimeMs= */ 2128, /* endTimeMs= */ 9856, /* speedDivisor= */ 8))); /* startTimeMs= */ 2128, /* endTimeMs= */ 9856, /* speedDivisor= */ 8)));
MdtaMetadataEntry expectedCaptureFpsMdtaEntry = MdtaMetadataEntry expectedCaptureFpsMdtaEntry =
new MdtaMetadataEntry( new MdtaMetadataEntry(
KEY_ANDROID_CAPTURE_FPS, KEY_ANDROID_CAPTURE_FPS, /* value= */ Util.toByteArray(240.0f), TYPE_INDICATOR_FLOAT32);
/* value= */ new byte[] {67, 112, 0, 0},
/* localeIndicator= */ 0,
/* typeIndicator= */ 23);
ListenableFuture<TrackGroupArray> trackGroupsFuture = ListenableFuture<TrackGroupArray> trackGroupsFuture =
retrieveMetadata(context, mediaItem, clock); retrieveMetadata(context, mediaItem, clock);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();

View File

@ -153,7 +153,6 @@ public class TransformerWithInAppMuxerEndToEndTest {
new MdtaMetadataEntry( new MdtaMetadataEntry(
MdtaMetadataEntry.KEY_ANDROID_CAPTURE_FPS, MdtaMetadataEntry.KEY_ANDROID_CAPTURE_FPS,
/* value= */ Util.toByteArray(captureFps), /* value= */ Util.toByteArray(captureFps),
/* localeIndicator= */ 0,
MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32); MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32);
Muxer.Factory inAppMuxerFactory = Muxer.Factory inAppMuxerFactory =
new InAppMuxer.Factory.Builder() new InAppMuxer.Factory.Builder()
@ -214,15 +213,11 @@ public class TransformerWithInAppMuxerEndToEndTest {
public void transmux_withCustomMetadata_writesSameCustomMetadata() throws Exception { public void transmux_withCustomMetadata_writesSameCustomMetadata() throws Exception {
MdtaMetadataEntry expectedStringMetadata = MdtaMetadataEntry expectedStringMetadata =
new MdtaMetadataEntry( new MdtaMetadataEntry(
"StringKey", "StringKey", Util.getUtf8Bytes("StringValue"), MdtaMetadataEntry.TYPE_INDICATOR_STRING);
Util.getUtf8Bytes("StringValue"),
/* localeIndicator= */ 0,
MdtaMetadataEntry.TYPE_INDICATOR_STRING);
MdtaMetadataEntry expectedFloatMetadata = MdtaMetadataEntry expectedFloatMetadata =
new MdtaMetadataEntry( new MdtaMetadataEntry(
"FloatKey", "FloatKey",
/* value= */ Util.toByteArray(600.0f), /* value= */ Util.toByteArray(600.0f),
/* localeIndicator= */ 0,
MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32); MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32);
Muxer.Factory inAppMuxerFactory = Muxer.Factory inAppMuxerFactory =
new InAppMuxer.Factory.Builder() new InAppMuxer.Factory.Builder()