Do not bundle metadata when creating Format bundle

Metadata does not provide a `toBundle` method. It implements
`Parcelable` which is not safe for IPCs between binaries with
potentially different class definitions (e.g. two apps built from
different versions of media3).

If we get a use case to bundle metadata as well, then the `Metadata`
class needs to provide a `toBundle()` method.

PiperOrigin-RevId: 705920231
This commit is contained in:
sheenachhabra 2024-12-13 10:09:23 -08:00 committed by Copybara-Service
parent 36466cf883
commit 1326a92350
4 changed files with 9 additions and 31 deletions

View File

@ -3,6 +3,8 @@
### Unreleased changes
* Common Library:
* Remove `Format.toBundle(boolean excludeMetadata)` method, use
`Format.toBundle()` instead.
* ExoPlayer:
* Consider language when selecting a video track. By default select a
'main' video track that matches the language of the selected audio

View File

@ -1496,7 +1496,8 @@ public final class Format {
private static final String FIELD_AVERAGE_BITRATE = Util.intToStringMaxRadix(5);
private static final String FIELD_PEAK_BITRATE = Util.intToStringMaxRadix(6);
private static final String FIELD_CODECS = Util.intToStringMaxRadix(7);
private static final String FIELD_METADATA = Util.intToStringMaxRadix(8);
// Do not reuse this key.
private static final String UNUSED_FIELD_METADATA = Util.intToStringMaxRadix(8);
private static final String FIELD_CONTAINER_MIME_TYPE = Util.intToStringMaxRadix(9);
private static final String FIELD_SAMPLE_MIME_TYPE = Util.intToStringMaxRadix(10);
private static final String FIELD_MAX_INPUT_SIZE = Util.intToStringMaxRadix(11);
@ -1523,21 +1524,12 @@ public final class Format {
private static final String FIELD_LABELS = Util.intToStringMaxRadix(32);
private static final String FIELD_AUXILIARY_TRACK_TYPE = Util.intToStringMaxRadix(33);
/**
* @deprecated Use {@link #toBundle(boolean)} instead.
*/
@UnstableApi
@Deprecated
public Bundle toBundle() {
return toBundle(/* excludeMetadata= */ false);
}
/**
* Returns a {@link Bundle} representing the information stored in this object. If {@code
* excludeMetadata} is true, {@linkplain Format#metadata metadata} is excluded.
*/
@UnstableApi
public Bundle toBundle(boolean excludeMetadata) {
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putString(FIELD_ID, id);
bundle.putString(FIELD_LABEL, label);
@ -1552,10 +1544,7 @@ public final class Format {
bundle.putInt(FIELD_AVERAGE_BITRATE, averageBitrate);
bundle.putInt(FIELD_PEAK_BITRATE, peakBitrate);
bundle.putString(FIELD_CODECS, codecs);
if (!excludeMetadata) {
// TODO (internal ref: b/239701618)
bundle.putParcelable(FIELD_METADATA, metadata);
}
// The metadata does not implement toBundle() method, hence can not be added.
// Container specific.
bundle.putString(FIELD_CONTAINER_MIME_TYPE, containerMimeType);
// Sample specific.
@ -1618,7 +1607,6 @@ public final class Format {
.setAverageBitrate(bundle.getInt(FIELD_AVERAGE_BITRATE, DEFAULT.averageBitrate))
.setPeakBitrate(bundle.getInt(FIELD_PEAK_BITRATE, DEFAULT.peakBitrate))
.setCodecs(defaultIfNull(bundle.getString(FIELD_CODECS), DEFAULT.codecs))
.setMetadata(defaultIfNull(bundle.getParcelable(FIELD_METADATA), DEFAULT.metadata))
// Container specific.
.setContainerMimeType(
defaultIfNull(bundle.getString(FIELD_CONTAINER_MIME_TYPE), DEFAULT.containerMimeType))

View File

@ -169,7 +169,7 @@ public final class TrackGroup {
Bundle bundle = new Bundle();
ArrayList<Bundle> arrayList = new ArrayList<>(formats.length);
for (Format format : formats) {
arrayList.add(format.toBundle(/* excludeMetadata= */ true));
arrayList.add(format.toBundle());
}
bundle.putParcelableArrayList(FIELD_FORMATS, arrayList);
bundle.putString(FIELD_ID, id);

View File

@ -43,22 +43,10 @@ public final class FormatTest {
}
@Test
public void roundTripViaBundle_includeMetadata_includesAllBundledFields() {
Format formatToBundle = createTestFormat();
Format formatFromBundle =
Format.fromBundle(formatToBundle.toBundle(/* excludeMetadata= */ false));
// Expect all data to be bundled except the custom data.
Format expectedRoundTripFormat = formatToBundle.buildUpon().setCustomData(null).build();
assertThat(formatFromBundle).isEqualTo(expectedRoundTripFormat);
}
@Test
public void roundTripViaBundle_excludeMetadata_includesAllBundledFieldsExceptMetadata() {
public void roundTripViaBundle_includesAllBundledFieldsExceptMetadata() {
Format format = createTestFormat();
Format formatFromBundle = Format.fromBundle(format.toBundle(/* excludeMetadata= */ true));
Format formatFromBundle = Format.fromBundle(format.toBundle());
// Expect all data to be bundled except the custom data and metadata.
Format expectedRoundTripFormat =