Commit 7c2889c6 by andrewlewis Committed by kim-vde

Add ENCODING_ constants for AAC

PiperOrigin-RevId: 297579793
parent 6946170d
...@@ -160,6 +160,11 @@ public final class C { ...@@ -160,6 +160,11 @@ public final class C {
ENCODING_PCM_32BIT, ENCODING_PCM_32BIT,
ENCODING_PCM_FLOAT, ENCODING_PCM_FLOAT,
ENCODING_MP3, ENCODING_MP3,
ENCODING_AAC_LC,
ENCODING_AAC_HE_V1,
ENCODING_AAC_HE_V2,
ENCODING_AAC_XHE,
ENCODING_AAC_ELD,
ENCODING_AC3, ENCODING_AC3,
ENCODING_E_AC3, ENCODING_E_AC3,
ENCODING_E_AC3_JOC, ENCODING_E_AC3_JOC,
...@@ -205,6 +210,16 @@ public final class C { ...@@ -205,6 +210,16 @@ public final class C {
public static final int ENCODING_PCM_FLOAT = AudioFormat.ENCODING_PCM_FLOAT; public static final int ENCODING_PCM_FLOAT = AudioFormat.ENCODING_PCM_FLOAT;
/** @see AudioFormat#ENCODING_MP3 */ /** @see AudioFormat#ENCODING_MP3 */
public static final int ENCODING_MP3 = AudioFormat.ENCODING_MP3; public static final int ENCODING_MP3 = AudioFormat.ENCODING_MP3;
/** @see AudioFormat#ENCODING_AAC_LC */
public static final int ENCODING_AAC_LC = AudioFormat.ENCODING_AAC_LC;
/** @see AudioFormat#ENCODING_AAC_HE_V1 */
public static final int ENCODING_AAC_HE_V1 = AudioFormat.ENCODING_AAC_HE_V1;
/** @see AudioFormat#ENCODING_AAC_HE_V2 */
public static final int ENCODING_AAC_HE_V2 = AudioFormat.ENCODING_AAC_HE_V2;
/** @see AudioFormat#ENCODING_AAC_XHE */
public static final int ENCODING_AAC_XHE = AudioFormat.ENCODING_AAC_XHE;
/** @see AudioFormat#ENCODING_AAC_ELD */
public static final int ENCODING_AAC_ELD = AudioFormat.ENCODING_AAC_ELD;
/** @see AudioFormat#ENCODING_AC3 */ /** @see AudioFormat#ENCODING_AC3 */
public static final int ENCODING_AC3 = AudioFormat.ENCODING_AC3; public static final int ENCODING_AC3 = AudioFormat.ENCODING_AC3;
/** @see AudioFormat#ENCODING_E_AC3 */ /** @see AudioFormat#ENCODING_E_AC3 */
......
...@@ -26,6 +26,8 @@ import java.util.List; ...@@ -26,6 +26,8 @@ import java.util.List;
/** Provides utilities for handling various types of codec-specific data. */ /** Provides utilities for handling various types of codec-specific data. */
public final class CodecSpecificDataUtil { public final class CodecSpecificDataUtil {
private static final String TAG = "CodecSpecificDataUtil";
/** Holds sample format information for AAC audio. */ /** Holds sample format information for AAC audio. */
public static final class AacConfig { public static final class AacConfig {
...@@ -43,6 +45,24 @@ public final class CodecSpecificDataUtil { ...@@ -43,6 +45,24 @@ public final class CodecSpecificDataUtil {
} }
} }
// AAC audio sample count constants assume the frameLengthFlag in the access unit is 0.
/**
* Number of raw audio samples that are produced per channel when decoding an AAC LC access unit.
*/
public static final int AAC_LC_AUDIO_SAMPLE_COUNT = 1024;
/**
* Number of raw audio samples that are produced per channel when decoding an AAC XHE access unit.
*/
public static final int AAC_XHE_AUDIO_SAMPLE_COUNT = AAC_LC_AUDIO_SAMPLE_COUNT;
/**
* Number of raw audio samples that are produced per channel when decoding an AAC HE access unit.
*/
public static final int AAC_HE_AUDIO_SAMPLE_COUNT = 2048;
/**
* Number of raw audio samples that are produced per channel when decoding an AAC LD access unit.
*/
public static final int AAC_LD_AUDIO_SAMPLE_COUNT = 512;
private static final byte[] NAL_START_CODE = new byte[] {0, 0, 0, 1}; private static final byte[] NAL_START_CODE = new byte[] {0, 0, 0, 1};
private static final int AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY = 0xF; private static final int AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY = 0xF;
...@@ -97,10 +117,14 @@ public final class CodecSpecificDataUtil { ...@@ -97,10 +117,14 @@ public final class CodecSpecificDataUtil {
private static final int AUDIO_OBJECT_TYPE_AAC_SBR = 5; private static final int AUDIO_OBJECT_TYPE_AAC_SBR = 5;
// Error Resilient Bit-Sliced Arithmetic Coding. // Error Resilient Bit-Sliced Arithmetic Coding.
private static final int AUDIO_OBJECT_TYPE_AAC_ER_BSAC = 22; private static final int AUDIO_OBJECT_TYPE_AAC_ER_BSAC = 22;
// Enhanced low delay.
private static final int AUDIO_OBJECT_TYPE_AAC_ELD = 23;
// Parametric Stereo. // Parametric Stereo.
private static final int AUDIO_OBJECT_TYPE_AAC_PS = 29; private static final int AUDIO_OBJECT_TYPE_AAC_PS = 29;
// Escape code for extended audio object types. // Escape code for extended audio object types.
private static final int AUDIO_OBJECT_TYPE_ESCAPE = 31; private static final int AUDIO_OBJECT_TYPE_ESCAPE = 31;
// Extended high efficiency.
private static final int AUDIO_OBJECT_TYPE_AAC_XHE = 42;
private CodecSpecificDataUtil() {} private CodecSpecificDataUtil() {}
...@@ -230,6 +254,25 @@ public final class CodecSpecificDataUtil { ...@@ -230,6 +254,25 @@ public final class CodecSpecificDataUtil {
return specificConfig; return specificConfig;
} }
/** Returns the encoding for a given AAC audio object type. */
@C.Encoding
public static int getEncodingForAacAudioObjectType(int audioObjectType) {
switch (audioObjectType) {
case AUDIO_OBJECT_TYPE_AAC_LC:
return C.ENCODING_AAC_LC;
case AUDIO_OBJECT_TYPE_AAC_SBR:
return C.ENCODING_AAC_HE_V1;
case AUDIO_OBJECT_TYPE_AAC_PS:
return C.ENCODING_AAC_HE_V2;
case AUDIO_OBJECT_TYPE_AAC_XHE:
return C.ENCODING_AAC_XHE;
case AUDIO_OBJECT_TYPE_AAC_ELD:
return C.ENCODING_AAC_ELD;
default:
return C.ENCODING_INVALID;
}
}
/** /**
* Parses an ALAC AudioSpecificConfig (i.e. an <a * Parses an ALAC AudioSpecificConfig (i.e. an <a
* href="https://github.com/macosforge/alac/blob/master/ALACMagicCookieDescription.txt">ALACSpecificConfig</a>). * href="https://github.com/macosforge/alac/blob/master/ALACMagicCookieDescription.txt">ALACSpecificConfig</a>).
...@@ -406,7 +449,10 @@ public final class CodecSpecificDataUtil { ...@@ -406,7 +449,10 @@ public final class CodecSpecificDataUtil {
private static void parseGaSpecificConfig(ParsableBitArray bitArray, int audioObjectType, private static void parseGaSpecificConfig(ParsableBitArray bitArray, int audioObjectType,
int channelConfiguration) { int channelConfiguration) {
bitArray.skipBits(1); // frameLengthFlag. boolean frameLengthFlag = bitArray.readBit();
if (frameLengthFlag) {
Log.w(TAG, "Unexpected AAC frameLengthFlag = 1");
}
boolean dependsOnCoreDecoder = bitArray.readBit(); boolean dependsOnCoreDecoder = bitArray.readBit();
if (dependsOnCoreDecoder) { if (dependsOnCoreDecoder) {
bitArray.skipBits(14); // coreCoderDelay. bitArray.skipBits(14); // coreCoderDelay.
......
...@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Format; ...@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.audio.AudioProcessor.UnhandledAudioFormatException; import com.google.android.exoplayer2.audio.AudioProcessor.UnhandledAudioFormatException;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.CodecSpecificDataUtil;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -1217,6 +1218,21 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -1217,6 +1218,21 @@ public final class DefaultAudioSink implements AudioSink {
case C.ENCODING_MP3: case C.ENCODING_MP3:
// Maximum bitrate for MPEG-1 layer III: 320 kbit/s. // Maximum bitrate for MPEG-1 layer III: 320 kbit/s.
return 320 * 1000 / 8; return 320 * 1000 / 8;
case C.ENCODING_AAC_LC:
// Maximum bitrates for AAC profiles from the Fraunhofer FDK AAC encoder documentation:
// https://cs.android.com/android/platform/superproject/+/android-9.0.0_r8:external/aac/libAACenc/include/aacenc_lib.h;l=718
return 800 * 1000 / 8;
case C.ENCODING_AAC_HE_V1:
return 128 * 1000 / 8;
case C.ENCODING_AAC_HE_V2:
return 56 * 1000 / 8;
case C.ENCODING_AAC_XHE:
// Fraunhofer documentation says "500 kbit/s and above" for stereo, so we use a rate
// generously above the 500 kbit/s level.
return 2048 * 1000 / 8;
case C.ENCODING_AAC_ELD:
// Fraunhofer documentation shows AAC-ELD as useful for up to ~ 64 kbit/s.
return 64 * 1000 / 8;
case C.ENCODING_AC3: case C.ENCODING_AC3:
return 640 * 1000 / 8; return 640 * 1000 / 8;
case C.ENCODING_E_AC3: case C.ENCODING_E_AC3:
...@@ -1248,6 +1264,15 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -1248,6 +1264,15 @@ public final class DefaultAudioSink implements AudioSink {
switch (encoding) { switch (encoding) {
case C.ENCODING_MP3: case C.ENCODING_MP3:
return MpegAudioUtil.parseMpegAudioFrameSampleCount(buffer.get(buffer.position())); return MpegAudioUtil.parseMpegAudioFrameSampleCount(buffer.get(buffer.position()));
case C.ENCODING_AAC_LC:
return CodecSpecificDataUtil.AAC_LC_AUDIO_SAMPLE_COUNT;
case C.ENCODING_AAC_HE_V1:
case C.ENCODING_AAC_HE_V2:
return CodecSpecificDataUtil.AAC_HE_AUDIO_SAMPLE_COUNT;
case C.ENCODING_AAC_XHE:
return CodecSpecificDataUtil.AAC_XHE_AUDIO_SAMPLE_COUNT;
case C.ENCODING_AAC_ELD:
return CodecSpecificDataUtil.AAC_LD_AUDIO_SAMPLE_COUNT;
case C.ENCODING_DTS: case C.ENCODING_DTS:
case C.ENCODING_DTS_HD: case C.ENCODING_DTS_HD:
return DtsUtil.parseDtsAudioSampleCount(buffer); return DtsUtil.parseDtsAudioSampleCount(buffer);
......
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