Rabbit-R1/android (non root)/java/sources/androidx/media3/extractor/wav/WavHeaderReader.java
2024-05-21 17:08:36 -04:00

114 lines
5.2 KiB
Java

package androidx.media3.extractor.wav;
import android.util.Pair;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.ExtractorInput;
import java.io.IOException;
/* loaded from: classes2.dex */
final class WavHeaderReader {
private static final String TAG = "WavHeaderReader";
public static boolean checkFileType(ExtractorInput extractorInput) throws IOException {
ParsableByteArray parsableByteArray = new ParsableByteArray(8);
ChunkHeader peek = ChunkHeader.peek(extractorInput, parsableByteArray);
if (peek.id != 1380533830 && peek.id != 1380333108) {
return false;
}
extractorInput.peekFully(parsableByteArray.getData(), 0, 4);
parsableByteArray.setPosition(0);
int readInt = parsableByteArray.readInt();
if (readInt == 1463899717) {
return true;
}
Log.e(TAG, "Unsupported form type: " + readInt);
return false;
}
public static long readRf64SampleDataSize(ExtractorInput extractorInput) throws IOException {
ParsableByteArray parsableByteArray = new ParsableByteArray(8);
ChunkHeader peek = ChunkHeader.peek(extractorInput, parsableByteArray);
if (peek.id != 1685272116) {
extractorInput.resetPeekPosition();
return -1L;
}
extractorInput.advancePeekPosition(8);
parsableByteArray.setPosition(0);
extractorInput.peekFully(parsableByteArray.getData(), 0, 8);
long readLittleEndianLong = parsableByteArray.readLittleEndianLong();
extractorInput.skipFully(((int) peek.size) + 8);
return readLittleEndianLong;
}
public static WavFormat readFormat(ExtractorInput extractorInput) throws IOException {
byte[] bArr;
ParsableByteArray parsableByteArray = new ParsableByteArray(16);
ChunkHeader skipToChunk = skipToChunk(1718449184, extractorInput, parsableByteArray);
Assertions.checkState(skipToChunk.size >= 16);
extractorInput.peekFully(parsableByteArray.getData(), 0, 16);
parsableByteArray.setPosition(0);
int readLittleEndianUnsignedShort = parsableByteArray.readLittleEndianUnsignedShort();
int readLittleEndianUnsignedShort2 = parsableByteArray.readLittleEndianUnsignedShort();
int readLittleEndianUnsignedIntToInt = parsableByteArray.readLittleEndianUnsignedIntToInt();
int readLittleEndianUnsignedIntToInt2 = parsableByteArray.readLittleEndianUnsignedIntToInt();
int readLittleEndianUnsignedShort3 = parsableByteArray.readLittleEndianUnsignedShort();
int readLittleEndianUnsignedShort4 = parsableByteArray.readLittleEndianUnsignedShort();
int i = ((int) skipToChunk.size) - 16;
if (i > 0) {
byte[] bArr2 = new byte[i];
extractorInput.peekFully(bArr2, 0, i);
bArr = bArr2;
} else {
bArr = Util.EMPTY_BYTE_ARRAY;
}
extractorInput.skipFully((int) (extractorInput.getPeekPosition() - extractorInput.getPosition()));
return new WavFormat(readLittleEndianUnsignedShort, readLittleEndianUnsignedShort2, readLittleEndianUnsignedIntToInt, readLittleEndianUnsignedIntToInt2, readLittleEndianUnsignedShort3, readLittleEndianUnsignedShort4, bArr);
}
public static Pair<Long, Long> skipToSampleData(ExtractorInput extractorInput) throws IOException {
extractorInput.resetPeekPosition();
ChunkHeader skipToChunk = skipToChunk(1684108385, extractorInput, new ParsableByteArray(8));
extractorInput.skipFully(8);
return Pair.create(Long.valueOf(extractorInput.getPosition()), Long.valueOf(skipToChunk.size));
}
private static ChunkHeader skipToChunk(int i, ExtractorInput extractorInput, ParsableByteArray parsableByteArray) throws IOException {
ChunkHeader peek = ChunkHeader.peek(extractorInput, parsableByteArray);
while (peek.id != i) {
Log.w(TAG, "Ignoring unknown WAV chunk: " + peek.id);
long j = peek.size + 8;
if (j > 2147483647L) {
throw ParserException.createForUnsupportedContainerFeature("Chunk is too large (~2GB+) to skip; id: " + peek.id);
}
extractorInput.skipFully((int) j);
peek = ChunkHeader.peek(extractorInput, parsableByteArray);
}
return peek;
}
private WavHeaderReader() {
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public static final class ChunkHeader {
public static final int SIZE_IN_BYTES = 8;
public final int id;
public final long size;
private ChunkHeader(int i, long j) {
this.id = i;
this.size = j;
}
public static ChunkHeader peek(ExtractorInput extractorInput, ParsableByteArray parsableByteArray) throws IOException {
extractorInput.peekFully(parsableByteArray.getData(), 0, 8);
parsableByteArray.setPosition(0);
return new ChunkHeader(parsableByteArray.readInt(), parsableByteArray.readLittleEndianUnsignedInt());
}
}
}