Rabbit-R1/android (non root)/java/sources/androidx/media3/extractor/AacUtil.java

190 lines
7.6 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.extractor;
import androidx.compose.material3.MenuKt;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.ParsableBitArray;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/* loaded from: classes2.dex */
public final class AacUtil {
public static final int AAC_ELD_MAX_RATE_BYTES_PER_SECOND = 8000;
public static final int AAC_HE_AUDIO_SAMPLE_COUNT = 2048;
public static final int AAC_HE_V1_MAX_RATE_BYTES_PER_SECOND = 16000;
public static final int AAC_HE_V2_MAX_RATE_BYTES_PER_SECOND = 7000;
public static final int AAC_LC_AUDIO_SAMPLE_COUNT = 1024;
public static final int AAC_LC_MAX_RATE_BYTES_PER_SECOND = 100000;
public static final int AAC_LD_AUDIO_SAMPLE_COUNT = 512;
public static final int AAC_XHE_AUDIO_SAMPLE_COUNT = 1024;
public static final int AAC_XHE_MAX_RATE_BYTES_PER_SECOND = 256000;
public static final int AUDIO_OBJECT_TYPE_AAC_ELD = 23;
public static final int AUDIO_OBJECT_TYPE_AAC_ER_BSAC = 22;
public static final int AUDIO_OBJECT_TYPE_AAC_LC = 2;
public static final int AUDIO_OBJECT_TYPE_AAC_PS = 29;
public static final int AUDIO_OBJECT_TYPE_AAC_SBR = 5;
public static final int AUDIO_OBJECT_TYPE_AAC_XHE = 42;
private static final int AUDIO_OBJECT_TYPE_ESCAPE = 31;
private static final int AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID = -1;
private static final int AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY = 15;
private static final String CODECS_STRING_PREFIX = "mp4a.40.";
private static final String TAG = "AacUtil";
private static final int[] AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350};
private static final int[] AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE = {0, 1, 2, 3, 4, 5, 6, 8, -1, -1, -1, 7, 8, -1, 8, -1};
@Target({ElementType.TYPE_USE})
@Documented
@Retention(RetentionPolicy.SOURCE)
/* loaded from: classes2.dex */
public @interface AacAudioObjectType {
}
public static byte[] buildAudioSpecificConfig(int i, int i2, int i3) {
return new byte[]{(byte) (((i << 3) & 248) | ((i2 >> 1) & 7)), (byte) (((i2 << 7) & 128) | ((i3 << 3) & MenuKt.InTransitionDuration))};
}
/* loaded from: classes2.dex */
public static final class Config {
public final int channelCount;
public final String codecs;
public final int sampleRateHz;
private Config(int i, int i2, String str) {
this.sampleRateHz = i;
this.channelCount = i2;
this.codecs = str;
}
}
public static Config parseAudioSpecificConfig(byte[] bArr) throws ParserException {
return parseAudioSpecificConfig(new ParsableBitArray(bArr), false);
}
public static Config parseAudioSpecificConfig(ParsableBitArray parsableBitArray, boolean z) throws ParserException {
int audioObjectType = getAudioObjectType(parsableBitArray);
int samplingFrequency = getSamplingFrequency(parsableBitArray);
int readBits = parsableBitArray.readBits(4);
String str = CODECS_STRING_PREFIX + audioObjectType;
if (audioObjectType == 5 || audioObjectType == 29) {
samplingFrequency = getSamplingFrequency(parsableBitArray);
audioObjectType = getAudioObjectType(parsableBitArray);
if (audioObjectType == 22) {
readBits = parsableBitArray.readBits(4);
}
}
if (z) {
if (audioObjectType != 1 && audioObjectType != 2 && audioObjectType != 3 && audioObjectType != 4 && audioObjectType != 6 && audioObjectType != 7 && audioObjectType != 17) {
switch (audioObjectType) {
case 19:
case 20:
case 21:
case 22:
case 23:
break;
default:
throw ParserException.createForUnsupportedContainerFeature("Unsupported audio object type: " + audioObjectType);
}
}
parseGaSpecificConfig(parsableBitArray, audioObjectType, readBits);
switch (audioObjectType) {
case 17:
case 19:
case 20:
case 21:
case 22:
case 23:
int readBits2 = parsableBitArray.readBits(2);
if (readBits2 == 2 || readBits2 == 3) {
throw ParserException.createForUnsupportedContainerFeature("Unsupported epConfig: " + readBits2);
}
}
}
int i = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[readBits];
if (i == -1) {
throw ParserException.createForMalformedContainer(null, null);
}
return new Config(samplingFrequency, i, str);
}
public static byte[] buildAacLcAudioSpecificConfig(int i, int i2) {
int i3 = 0;
int i4 = -1;
int i5 = 0;
while (true) {
int[] iArr = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE;
if (i5 >= iArr.length) {
break;
}
if (i == iArr[i5]) {
i4 = i5;
}
i5++;
}
int i6 = -1;
while (true) {
int[] iArr2 = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE;
if (i3 >= iArr2.length) {
break;
}
if (i2 == iArr2[i3]) {
i6 = i3;
}
i3++;
}
if (i == -1 || i6 == -1) {
throw new IllegalArgumentException("Invalid sample rate or number of channels: " + i + ", " + i2);
}
return buildAudioSpecificConfig(2, i4, i6);
}
private static int getAudioObjectType(ParsableBitArray parsableBitArray) {
int readBits = parsableBitArray.readBits(5);
return readBits == 31 ? parsableBitArray.readBits(6) + 32 : readBits;
}
private static int getSamplingFrequency(ParsableBitArray parsableBitArray) throws ParserException {
int readBits = parsableBitArray.readBits(4);
if (readBits == 15) {
if (parsableBitArray.bitsLeft() < 24) {
throw ParserException.createForMalformedContainer("AAC header insufficient data", null);
}
return parsableBitArray.readBits(24);
}
if (readBits < 13) {
return AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[readBits];
}
throw ParserException.createForMalformedContainer("AAC header wrong Sampling Frequency Index", null);
}
private static void parseGaSpecificConfig(ParsableBitArray parsableBitArray, int i, int i2) {
if (parsableBitArray.readBit()) {
Log.w(TAG, "Unexpected frameLengthFlag = 1");
}
if (parsableBitArray.readBit()) {
parsableBitArray.skipBits(14);
}
boolean readBit = parsableBitArray.readBit();
if (i2 == 0) {
throw new UnsupportedOperationException();
}
if (i == 6 || i == 20) {
parsableBitArray.skipBits(3);
}
if (readBit) {
if (i == 22) {
parsableBitArray.skipBits(16);
}
if (i == 17 || i == 19 || i == 20 || i == 23) {
parsableBitArray.skipBits(3);
}
parsableBitArray.skipBits(1);
}
}
private AacUtil() {
}
}