Commit 72daef7a by aquilescanta Committed by Oliver Woodman

Don't read GaSpecificConfig unless required

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164125579
parent ccd05cbd
......@@ -256,7 +256,7 @@ public final class LatmReader implements ElementaryStreamReader {
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException {
int bitsLeft = data.bitsLeft();
Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data);
Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true);
sampleRateHz = config.first;
channelCount = config.second;
return bitsLeft - data.bitsLeft();
......
......@@ -90,7 +90,7 @@ public final class CodecSpecificDataUtil {
*/
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpecificConfig)
throws ParserException {
return parseAacAudioSpecificConfig(new ParsableBitArray(audioSpecificConfig));
return parseAacAudioSpecificConfig(new ParsableBitArray(audioSpecificConfig), false);
}
/**
......@@ -98,11 +98,13 @@ public final class CodecSpecificDataUtil {
*
* @param bitArray A {@link ParsableBitArray} containing the AudioSpecificConfig to parse. The
* position is advanced to the end of the AudioSpecificConfig.
* @param forceReadToEnd Whether the entire AudioSpecificConfig should be read. Required for
* knowing the length of the configuration payload.
* @return A pair consisting of the sample rate in Hz and the channel count.
* @throws ParserException If the AudioSpecificConfig cannot be parsed as it's not supported.
*/
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(ParsableBitArray bitArray)
throws ParserException {
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(ParsableBitArray bitArray,
boolean forceReadToEnd) throws ParserException {
int audioObjectType = getAacAudioObjectType(bitArray);
int sampleRate = getAacSamplingFrequency(bitArray);
int channelConfiguration = bitArray.readBits(4);
......@@ -120,6 +122,7 @@ public final class CodecSpecificDataUtil {
}
}
if (forceReadToEnd) {
switch (audioObjectType) {
case 1:
case 2:
......@@ -151,6 +154,7 @@ public final class CodecSpecificDataUtil {
}
break;
}
}
// For supported containers, bits_to_decode() is always 0.
int channelCount = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[channelConfiguration];
Assertions.checkArgument(channelCount != AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment