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,36 +122,38 @@ public final class CodecSpecificDataUtil {
} }
} }
switch (audioObjectType) { if (forceReadToEnd) {
case 1: switch (audioObjectType) {
case 2: case 1:
case 3: case 2:
case 4: case 3:
case 6: case 4:
case 7: case 6:
case 17: case 7:
case 19: case 17:
case 20: case 19:
case 21: case 20:
case 22: case 21:
case 23: case 22:
parseGaSpecificConfig(bitArray, audioObjectType, channelConfiguration); case 23:
break; parseGaSpecificConfig(bitArray, audioObjectType, channelConfiguration);
default: break;
throw new ParserException("Unsupported audio object type: " + audioObjectType); default:
} throw new ParserException("Unsupported audio object type: " + audioObjectType);
switch (audioObjectType) { }
case 17: switch (audioObjectType) {
case 19: case 17:
case 20: case 19:
case 21: case 20:
case 22: case 21:
case 23: case 22:
int epConfig = bitArray.readBits(2); case 23:
if (epConfig == 2 || epConfig == 3) { int epConfig = bitArray.readBits(2);
throw new ParserException("Unsupported epConfig: " + epConfig); if (epConfig == 2 || epConfig == 3) {
} throw new ParserException("Unsupported epConfig: " + epConfig);
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];