Refactor get editable track types from map logic

The new method will be reused when Mp4Extractor need to
parse this metadata.

PiperOrigin-RevId: 658372567
This commit is contained in:
sheenachhabra 2024-08-01 05:53:44 -07:00 committed by Copybara-Service
parent 34d3dc926d
commit bd399eb601
2 changed files with 17 additions and 10 deletions

View File

@ -24,8 +24,11 @@ import androidx.media3.common.Metadata;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.common.base.Joiner;
import com.google.common.primitives.Ints;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Stores extensible metadata with handler type 'mdta'. See also the QuickTime File Format
@ -202,16 +205,20 @@ public final class MdtaMetadataEntry implements Metadata.Entry {
};
private static String getFormattedValueForEditableTracksMap(byte[] value) {
// Value has 1 byte version, 1 byte track count, n bytes track types.
int numberOfTracks = value[1];
StringBuilder sb = new StringBuilder();
sb.append("track types = ");
for (int i = 0; i < numberOfTracks; i++) {
sb.append(value[i + 2]);
if (i < numberOfTracks - 1) {
sb.append(", ");
}
}
List<Integer> trackTypes = getEditableTrackTypesFromMap(value);
Joiner.on(',').appendTo(sb, trackTypes);
return sb.toString();
}
private static List<Integer> getEditableTrackTypesFromMap(byte[] value) {
// Value has 1 byte version, 1 byte track count, n bytes track types.
int numberOfTracks = value[1];
List<Integer> trackTypes = new ArrayList<>();
for (int i = 0; i < numberOfTracks; i++) {
trackTypes.add((int) value[i + 2]);
}
return trackTypes;
}
}

View File

@ -21,7 +21,7 @@ track 0:
colorRange = 1
lumaBitdepth = 8
chromaBitdepth = 8
metadata = entries=[mdta: key=editable.tracks.map, value=track types = 0, 1, Mp4Timestamp: creation time=1000000, modification time=5000000, timescale=10000]
metadata = entries=[mdta: key=editable.tracks.map, value=track types = 0,1, Mp4Timestamp: creation time=1000000, modification time=5000000, timescale=10000]
initializationData:
data = length 28, hash 410B510
data = length 9, hash FBADD682
@ -60,7 +60,7 @@ track 1:
colorRange = 1
lumaBitdepth = 8
chromaBitdepth = 8
metadata = entries=[mdta: key=editable.tracks.map, value=track types = 0, 1, Mp4Timestamp: creation time=1000000, modification time=5000000, timescale=10000]
metadata = entries=[mdta: key=editable.tracks.map, value=track types = 0,1, Mp4Timestamp: creation time=1000000, modification time=5000000, timescale=10000]
initializationData:
data = length 28, hash 410B510
data = length 9, hash FBADD682