mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Read init data for AAC (and not other formats) in AVI files
AAC is the only format where the codec data buffer is actually used. Invalid or obscure versions of the relevant syntax can break extraction when we try to read the codec data, so it's better to read it only when it's required. PiperOrigin-RevId: 704308925
This commit is contained in:
parent
12546070ee
commit
1f6c795407
@ -86,18 +86,17 @@ import com.google.common.collect.ImmutableList;
|
||||
int bitsPerSample = body.readLittleEndianUnsignedShort();
|
||||
int pcmEncoding = Util.getPcmEncoding(bitsPerSample);
|
||||
int cbSize = body.bytesLeft() > 0 ? body.readLittleEndianUnsignedShort() : 0;
|
||||
byte[] codecData = new byte[cbSize];
|
||||
body.readBytes(codecData, /* offset= */ 0, codecData.length);
|
||||
|
||||
Format.Builder formatBuilder = new Format.Builder();
|
||||
formatBuilder
|
||||
.setSampleMimeType(mimeType)
|
||||
.setChannelCount(channelCount)
|
||||
.setSampleRate(samplesPerSecond);
|
||||
if (MimeTypes.AUDIO_RAW.equals(mimeType) && pcmEncoding != C.ENCODING_INVALID) {
|
||||
if (mimeType.equals(MimeTypes.AUDIO_RAW) && pcmEncoding != C.ENCODING_INVALID) {
|
||||
formatBuilder.setPcmEncoding(pcmEncoding);
|
||||
}
|
||||
if (MimeTypes.AUDIO_AAC.equals(mimeType) && codecData.length > 0) {
|
||||
if (mimeType.equals(MimeTypes.AUDIO_AAC) && cbSize > 0) {
|
||||
byte[] codecData = new byte[cbSize];
|
||||
body.readBytes(codecData, /* offset= */ 0, codecData.length);
|
||||
formatBuilder.setInitializationData(ImmutableList.of(codecData));
|
||||
}
|
||||
return new StreamFormatChunk(formatBuilder.build());
|
||||
|
Loading…
x
Reference in New Issue
Block a user