Parse initialization data from AV1 tracks

Initialization data is not passed to `MediaCodecRenderer` as it is not required for playing AV1 video.

See: https://developer.android.com/reference/android/media/MediaCodec#CSD
PiperOrigin-RevId: 629729301
This commit is contained in:
rohks 2024-05-01 08:20:42 -07:00 committed by Copybara-Service
parent 1af86d4c4d
commit e25bd07a81
13 changed files with 37 additions and 0 deletions

View File

@ -1544,6 +1544,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
newFormat,
PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
}
// Remove the initialization data from the format if present when dealing with AV1, as it is not
// required for playing AV1 video.
// Reference: https://developer.android.com/reference/android/media/MediaCodec#CSD
if (Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_AV1)
&& !newFormat.initializationData.isEmpty()) {
newFormat = newFormat.buildUpon().setInitializationData(null).build();
}
setSourceDrmSession(formatHolder.drmSession);
inputFormat = newFormat;

View File

@ -1227,6 +1227,12 @@ import java.util.Objects;
ColorInfo.isoTransferCharacteristicsToColorTransfer(transferCharacteristics);
} else if (childAtomType == Atom.TYPE_av1C) {
mimeType = MimeTypes.VIDEO_AV1;
int childAtomBodySize = childAtomSize - Atom.HEADER_SIZE;
byte[] initializationDataChunk = new byte[childAtomBodySize];
parent.readBytes(initializationDataChunk, /* offset= */ 0, childAtomBodySize);
initializationData = ImmutableList.of(initializationDataChunk);
parent.setPosition(childStartPosition + Atom.HEADER_SIZE);
ColorInfo colorInfo = parseAv1c(parent);

View File

@ -23,6 +23,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf60.3.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 3DFDDB0E
sample 0:
time = 0
flags = 1

View File

@ -23,6 +23,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf60.3.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 3DFDDB0E
sample 0:
time = 0
flags = 1

View File

@ -23,6 +23,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf60.3.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 3DFDDB0E
sample 0:
time = 0
flags = 1

View File

@ -23,6 +23,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf60.3.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 3DFDDB0E
sample 0:
time = 0
flags = 1

View File

@ -23,6 +23,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf60.3.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 3DFDDB0E
sample 0:
time = 0
flags = 1

View File

@ -24,6 +24,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf58.76.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 4DF5B288
sample 0:
time = 0
flags = 1

View File

@ -24,6 +24,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf58.76.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 4DF5B288
sample 0:
time = 0
flags = 1

View File

@ -24,6 +24,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf58.76.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 4DF5B288
sample 0:
time = 0
flags = 1

View File

@ -24,6 +24,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf58.76.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 4DF5B288
sample 0:
time = 0
flags = 1

View File

@ -24,6 +24,8 @@ track 0:
lumaBitdepth = 10
chromaBitdepth = 10
metadata = entries=[TSSE: description=null: values=[Lavf58.76.100], Mp4Timestamp: creation time=0, modification time=0, timescale=1000]
initializationData:
data = length 20, hash 4DF5B288
sample 0:
time = 0
flags = 1

View File

@ -20,6 +20,8 @@ track 0:
lumaBitdepth = 8
chromaBitdepth = 8
metadata = entries=[Mp4Timestamp: creation time=100000000, modification time=500000000, timescale=10000]
initializationData:
data = length 17, hash 54AC4E6D
sample 0:
time = 0
flags = 1