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

78 lines
4.1 KiB
Java

package androidx.media3.extractor.ts;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.TimestampAdjuster;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.BinarySearchSeeker;
import androidx.media3.extractor.ExtractorInput;
import java.io.IOException;
/* loaded from: classes2.dex */
final class TsBinarySearchSeeker extends BinarySearchSeeker {
private static final int MINIMUM_SEARCH_RANGE_BYTES = 940;
private static final long SEEK_TOLERANCE_US = 100000;
public TsBinarySearchSeeker(TimestampAdjuster timestampAdjuster, long j, long j2, int i, int i2) {
super(new BinarySearchSeeker.DefaultSeekTimestampConverter(), new TsPcrSeeker(i, timestampAdjuster, i2), j, 0L, j + 1, 0L, j2, 188L, MINIMUM_SEARCH_RANGE_BYTES);
}
/* loaded from: classes2.dex */
private static final class TsPcrSeeker implements BinarySearchSeeker.TimestampSeeker {
private final ParsableByteArray packetBuffer = new ParsableByteArray();
private final int pcrPid;
private final TimestampAdjuster pcrTimestampAdjuster;
private final int timestampSearchBytes;
public TsPcrSeeker(int i, TimestampAdjuster timestampAdjuster, int i2) {
this.pcrPid = i;
this.pcrTimestampAdjuster = timestampAdjuster;
this.timestampSearchBytes = i2;
}
@Override // androidx.media3.extractor.BinarySearchSeeker.TimestampSeeker
public BinarySearchSeeker.TimestampSearchResult searchForTimestamp(ExtractorInput extractorInput, long j) throws IOException {
long position = extractorInput.getPosition();
int min = (int) Math.min(this.timestampSearchBytes, extractorInput.getLength() - position);
this.packetBuffer.reset(min);
extractorInput.peekFully(this.packetBuffer.getData(), 0, min);
return searchForPcrValueInBuffer(this.packetBuffer, j, position);
}
private BinarySearchSeeker.TimestampSearchResult searchForPcrValueInBuffer(ParsableByteArray parsableByteArray, long j, long j2) {
int findSyncBytePosition;
int findSyncBytePosition2;
int limit = parsableByteArray.limit();
long j3 = -1;
long j4 = -1;
long j5 = -9223372036854775807L;
while (parsableByteArray.bytesLeft() >= 188 && (findSyncBytePosition2 = (findSyncBytePosition = TsUtil.findSyncBytePosition(parsableByteArray.getData(), parsableByteArray.getPosition(), limit)) + 188) <= limit) {
long readPcrFromPacket = TsUtil.readPcrFromPacket(parsableByteArray, findSyncBytePosition, this.pcrPid);
if (readPcrFromPacket != -9223372036854775807L) {
long adjustTsTimestamp = this.pcrTimestampAdjuster.adjustTsTimestamp(readPcrFromPacket);
if (adjustTsTimestamp > j) {
if (j5 == -9223372036854775807L) {
return BinarySearchSeeker.TimestampSearchResult.overestimatedResult(adjustTsTimestamp, j2);
}
return BinarySearchSeeker.TimestampSearchResult.targetFoundResult(j2 + j4);
}
if (TsBinarySearchSeeker.SEEK_TOLERANCE_US + adjustTsTimestamp > j) {
return BinarySearchSeeker.TimestampSearchResult.targetFoundResult(findSyncBytePosition + j2);
}
j4 = findSyncBytePosition;
j5 = adjustTsTimestamp;
}
parsableByteArray.setPosition(findSyncBytePosition2);
j3 = findSyncBytePosition2;
}
if (j5 != -9223372036854775807L) {
return BinarySearchSeeker.TimestampSearchResult.underestimatedResult(j5, j2 + j3);
}
return BinarySearchSeeker.TimestampSearchResult.NO_TIMESTAMP_IN_RANGE_RESULT;
}
@Override // androidx.media3.extractor.BinarySearchSeeker.TimestampSeeker
public void onSeekFinished() {
this.packetBuffer.reset(Util.EMPTY_BYTE_ARRAY);
}
}
}