Don't read GaSpecificConfig unless required

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164125579
This commit is contained in:
aquilescanta 2017-08-03 08:17:26 -07:00 committed by Oliver Woodman
parent ccd05cbd04
commit 72daef7a4c
2 changed files with 38 additions and 34 deletions

View File

@ -256,7 +256,7 @@ public final class LatmReader implements ElementaryStreamReader {
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException {
int bitsLeft = data.bitsLeft(); int bitsLeft = data.bitsLeft();
Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true);
sampleRateHz = config.first; sampleRateHz = config.first;
channelCount = config.second; channelCount = config.second;
return bitsLeft - data.bitsLeft(); return bitsLeft - data.bitsLeft();

View File

@ -90,7 +90,7 @@ public final class CodecSpecificDataUtil {
*/ */
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpecificConfig) public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpecificConfig)
throws ParserException { 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 * @param bitArray A {@link ParsableBitArray} containing the AudioSpecificConfig to parse. The
* position is advanced to the end of the AudioSpecificConfig. * 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. * @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. * @throws ParserException If the AudioSpecificConfig cannot be parsed as it's not supported.
*/ */
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(ParsableBitArray bitArray) public static Pair<Integer, Integer> parseAacAudioSpecificConfig(ParsableBitArray bitArray,
throws ParserException { boolean forceReadToEnd) throws ParserException {
int audioObjectType = getAacAudioObjectType(bitArray); int audioObjectType = getAacAudioObjectType(bitArray);
int sampleRate = getAacSamplingFrequency(bitArray); int sampleRate = getAacSamplingFrequency(bitArray);
int channelConfiguration = bitArray.readBits(4); int channelConfiguration = bitArray.readBits(4);
@ -120,6 +122,7 @@ public final class CodecSpecificDataUtil {
} }
} }
if (forceReadToEnd) {
switch (audioObjectType) { switch (audioObjectType) {
case 1: case 1:
case 2: case 2:
@ -151,6 +154,7 @@ public final class CodecSpecificDataUtil {
} }
break; break;
} }
}
// For supported containers, bits_to_decode() is always 0. // For supported containers, bits_to_decode() is always 0.
int channelCount = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[channelConfiguration]; int channelCount = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[channelConfiguration];
Assertions.checkArgument(channelCount != AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID); Assertions.checkArgument(channelCount != AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID);