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

99 lines
3.9 KiB
Java

package androidx.media3.extractor.ogg;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.ExtractorInput;
import androidx.media3.extractor.ExtractorUtil;
import java.io.IOException;
/* loaded from: classes2.dex */
final class OggPageHeader {
private static final int CAPTURE_PATTERN = 1332176723;
private static final int CAPTURE_PATTERN_SIZE = 4;
public static final int EMPTY_PAGE_HEADER_SIZE = 27;
public static final int MAX_PAGE_PAYLOAD = 65025;
public static final int MAX_PAGE_SIZE = 65307;
public static final int MAX_SEGMENT_COUNT = 255;
public int bodySize;
public long granulePosition;
public int headerSize;
public long pageChecksum;
public int pageSegmentCount;
public long pageSequenceNumber;
public int revision;
public long streamSerialNumber;
public int type;
public final int[] laces = new int[255];
private final ParsableByteArray scratch = new ParsableByteArray(255);
public void reset() {
this.revision = 0;
this.type = 0;
this.granulePosition = 0L;
this.streamSerialNumber = 0L;
this.pageSequenceNumber = 0L;
this.pageChecksum = 0L;
this.pageSegmentCount = 0;
this.headerSize = 0;
this.bodySize = 0;
}
public boolean skipToNextPage(ExtractorInput extractorInput) throws IOException {
return skipToNextPage(extractorInput, -1L);
}
public boolean skipToNextPage(ExtractorInput extractorInput, long j) throws IOException {
Assertions.checkArgument(extractorInput.getPosition() == extractorInput.getPeekPosition());
this.scratch.reset(4);
while (true) {
if ((j == -1 || extractorInput.getPosition() + 4 < j) && ExtractorUtil.peekFullyQuietly(extractorInput, this.scratch.getData(), 0, 4, true)) {
this.scratch.setPosition(0);
if (this.scratch.readUnsignedInt() == 1332176723) {
extractorInput.resetPeekPosition();
return true;
}
extractorInput.skipFully(1);
}
}
do {
if (j != -1 && extractorInput.getPosition() >= j) {
break;
}
} while (extractorInput.skip(1) != -1);
return false;
}
public boolean populate(ExtractorInput extractorInput, boolean z) throws IOException {
reset();
this.scratch.reset(27);
if (!ExtractorUtil.peekFullyQuietly(extractorInput, this.scratch.getData(), 0, 27, z) || this.scratch.readUnsignedInt() != 1332176723) {
return false;
}
int readUnsignedByte = this.scratch.readUnsignedByte();
this.revision = readUnsignedByte;
if (readUnsignedByte != 0) {
if (z) {
return false;
}
throw ParserException.createForUnsupportedContainerFeature("unsupported bit stream revision");
}
this.type = this.scratch.readUnsignedByte();
this.granulePosition = this.scratch.readLittleEndianLong();
this.streamSerialNumber = this.scratch.readLittleEndianUnsignedInt();
this.pageSequenceNumber = this.scratch.readLittleEndianUnsignedInt();
this.pageChecksum = this.scratch.readLittleEndianUnsignedInt();
int readUnsignedByte2 = this.scratch.readUnsignedByte();
this.pageSegmentCount = readUnsignedByte2;
this.headerSize = readUnsignedByte2 + 27;
this.scratch.reset(readUnsignedByte2);
if (!ExtractorUtil.peekFullyQuietly(extractorInput, this.scratch.getData(), 0, this.pageSegmentCount, z)) {
return false;
}
for (int i = 0; i < this.pageSegmentCount; i++) {
this.laces[i] = this.scratch.readUnsignedByte();
this.bodySize += this.laces[i];
}
return true;
}
}