Support escaped AAC AOTs.

Issue: #2514

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151418949
This commit is contained in:
andrewlewis 2017-03-28 00:09:10 -07:00 committed by Oliver Woodman
parent 21eecb679d
commit 422c2d0ab7

View File

@ -75,6 +75,8 @@ public final class CodecSpecificDataUtil {
private static final int AUDIO_OBJECT_TYPE_ER_BSAC = 22; private static final int AUDIO_OBJECT_TYPE_ER_BSAC = 22;
// Parametric Stereo. // Parametric Stereo.
private static final int AUDIO_OBJECT_TYPE_PS = 29; private static final int AUDIO_OBJECT_TYPE_PS = 29;
// Escape code for extended audio object types.
private static final int AUDIO_OBJECT_TYPE_ESCAPE = 31;
private CodecSpecificDataUtil() {} private CodecSpecificDataUtil() {}
@ -86,15 +88,8 @@ public final class CodecSpecificDataUtil {
*/ */
public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpecificConfig) { public static Pair<Integer, Integer> parseAacAudioSpecificConfig(byte[] audioSpecificConfig) {
ParsableBitArray bitArray = new ParsableBitArray(audioSpecificConfig); ParsableBitArray bitArray = new ParsableBitArray(audioSpecificConfig);
int audioObjectType = bitArray.readBits(5); int audioObjectType = getAacAudioObjectType(bitArray);
int frequencyIndex = bitArray.readBits(4); int sampleRate = getAacSamplingFrequency(bitArray);
int sampleRate;
if (frequencyIndex == AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY) {
sampleRate = bitArray.readBits(24);
} else {
Assertions.checkArgument(frequencyIndex < 13);
sampleRate = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
}
int channelConfiguration = bitArray.readBits(4); int channelConfiguration = bitArray.readBits(4);
if (audioObjectType == AUDIO_OBJECT_TYPE_SBR || audioObjectType == AUDIO_OBJECT_TYPE_PS) { if (audioObjectType == AUDIO_OBJECT_TYPE_SBR || audioObjectType == AUDIO_OBJECT_TYPE_PS) {
// For an AAC bitstream using spectral band replication (SBR) or parametric stereo (PS) with // For an AAC bitstream using spectral band replication (SBR) or parametric stereo (PS) with
@ -102,14 +97,8 @@ public final class CodecSpecificDataUtil {
// content; this is identical to the sample rate of the decoded output but may differ from // content; this is identical to the sample rate of the decoded output but may differ from
// the sample rate set above. // the sample rate set above.
// Use the extensionSamplingFrequencyIndex. // Use the extensionSamplingFrequencyIndex.
frequencyIndex = bitArray.readBits(4); sampleRate = getAacSamplingFrequency(bitArray);
if (frequencyIndex == AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY) { audioObjectType = getAacAudioObjectType(bitArray);
sampleRate = bitArray.readBits(24);
} else {
Assertions.checkArgument(frequencyIndex < 13);
sampleRate = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
}
audioObjectType = bitArray.readBits(5);
if (audioObjectType == AUDIO_OBJECT_TYPE_ER_BSAC) { if (audioObjectType == AUDIO_OBJECT_TYPE_ER_BSAC) {
// Use the extensionChannelConfiguration. // Use the extensionChannelConfiguration.
channelConfiguration = bitArray.readBits(4); channelConfiguration = bitArray.readBits(4);
@ -247,4 +236,37 @@ public final class CodecSpecificDataUtil {
return true; return true;
} }
/**
* Returns the AAC audio object type as specified in 14496-3 (2005) Table 1.14.
*
* @param bitArray The bit array containing the audio specific configuration.
* @return The audio object type.
*/
private static int getAacAudioObjectType(ParsableBitArray bitArray) {
int audioObjectType = bitArray.readBits(5);
if (audioObjectType == AUDIO_OBJECT_TYPE_ESCAPE) {
audioObjectType = 32 + bitArray.readBits(6);
}
return audioObjectType;
}
/**
* Returns the AAC sampling frequency (or extension sampling frequency) as specified in 14496-3
* (2005) Table 1.13.
*
* @param bitArray The bit array containing the audio specific configuration.
* @return The sampling frequency.
*/
private static int getAacSamplingFrequency(ParsableBitArray bitArray) {
int samplingFrequency;
int frequencyIndex = bitArray.readBits(4);
if (frequencyIndex == AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY) {
samplingFrequency = bitArray.readBits(24);
} else {
Assertions.checkArgument(frequencyIndex < 13);
samplingFrequency = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
}
return samplingFrequency;
}
} }