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

94 lines
3.7 KiB
Java

package androidx.media3.extractor.ts;
import androidx.media3.common.Format;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.ExtractorOutput;
import androidx.media3.extractor.TrackOutput;
import androidx.media3.extractor.ts.TsPayloadReader;
import java.util.Collections;
import java.util.List;
/* loaded from: classes2.dex */
public final class DvbSubtitleReader implements ElementaryStreamReader {
private int bytesToCheck;
private final TrackOutput[] outputs;
private int sampleBytesWritten;
private long sampleTimeUs = -9223372036854775807L;
private final List<TsPayloadReader.DvbSubtitleInfo> subtitleInfos;
private boolean writingSample;
@Override // androidx.media3.extractor.ts.ElementaryStreamReader
public void packetStarted(long j, int i) {
if ((i & 4) == 0) {
return;
}
this.writingSample = true;
if (j != -9223372036854775807L) {
this.sampleTimeUs = j;
}
this.sampleBytesWritten = 0;
this.bytesToCheck = 2;
}
@Override // androidx.media3.extractor.ts.ElementaryStreamReader
public void seek() {
this.writingSample = false;
this.sampleTimeUs = -9223372036854775807L;
}
public DvbSubtitleReader(List<TsPayloadReader.DvbSubtitleInfo> list) {
this.subtitleInfos = list;
this.outputs = new TrackOutput[list.size()];
}
@Override // androidx.media3.extractor.ts.ElementaryStreamReader
public void createTracks(ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator trackIdGenerator) {
for (int i = 0; i < this.outputs.length; i++) {
TsPayloadReader.DvbSubtitleInfo dvbSubtitleInfo = this.subtitleInfos.get(i);
trackIdGenerator.generateNewId();
TrackOutput track = extractorOutput.track(trackIdGenerator.getTrackId(), 3);
track.format(new Format.Builder().setId(trackIdGenerator.getFormatId()).setSampleMimeType("application/dvbsubs").setInitializationData(Collections.singletonList(dvbSubtitleInfo.initializationData)).setLanguage(dvbSubtitleInfo.language).build());
this.outputs[i] = track;
}
}
@Override // androidx.media3.extractor.ts.ElementaryStreamReader
public void packetFinished() {
if (this.writingSample) {
if (this.sampleTimeUs != -9223372036854775807L) {
for (TrackOutput trackOutput : this.outputs) {
trackOutput.sampleMetadata(this.sampleTimeUs, 1, this.sampleBytesWritten, 0, null);
}
}
this.writingSample = false;
}
}
@Override // androidx.media3.extractor.ts.ElementaryStreamReader
public void consume(ParsableByteArray parsableByteArray) {
if (this.writingSample) {
if (this.bytesToCheck != 2 || checkNextByte(parsableByteArray, 32)) {
if (this.bytesToCheck != 1 || checkNextByte(parsableByteArray, 0)) {
int position = parsableByteArray.getPosition();
int bytesLeft = parsableByteArray.bytesLeft();
for (TrackOutput trackOutput : this.outputs) {
parsableByteArray.setPosition(position);
trackOutput.sampleData(parsableByteArray, bytesLeft);
}
this.sampleBytesWritten += bytesLeft;
}
}
}
}
private boolean checkNextByte(ParsableByteArray parsableByteArray, int i) {
if (parsableByteArray.bytesLeft() == 0) {
return false;
}
if (parsableByteArray.readUnsignedByte() != i) {
this.writingSample = false;
}
this.bytesToCheck--;
return this.writingSample;
}
}