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

55 lines
2.4 KiB
Java

package androidx.media3.extractor.ts;
import androidx.media3.common.Format;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.TimestampAdjuster;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.ExtractorOutput;
import androidx.media3.extractor.TrackOutput;
import androidx.media3.extractor.ts.TsPayloadReader;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
/* loaded from: classes2.dex */
public final class PassthroughSectionPayloadReader implements SectionPayloadReader {
private Format format;
private TrackOutput output;
private TimestampAdjuster timestampAdjuster;
public PassthroughSectionPayloadReader(String str) {
this.format = new Format.Builder().setSampleMimeType(str).build();
}
@Override // androidx.media3.extractor.ts.SectionPayloadReader
public void init(TimestampAdjuster timestampAdjuster, ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator trackIdGenerator) {
this.timestampAdjuster = timestampAdjuster;
trackIdGenerator.generateNewId();
TrackOutput track = extractorOutput.track(trackIdGenerator.getTrackId(), 5);
this.output = track;
track.format(this.format);
}
@Override // androidx.media3.extractor.ts.SectionPayloadReader
public void consume(ParsableByteArray parsableByteArray) {
assertInitialized();
long lastAdjustedTimestampUs = this.timestampAdjuster.getLastAdjustedTimestampUs();
long timestampOffsetUs = this.timestampAdjuster.getTimestampOffsetUs();
if (lastAdjustedTimestampUs == -9223372036854775807L || timestampOffsetUs == -9223372036854775807L) {
return;
}
if (timestampOffsetUs != this.format.subsampleOffsetUs) {
Format build = this.format.buildUpon().setSubsampleOffsetUs(timestampOffsetUs).build();
this.format = build;
this.output.format(build);
}
int bytesLeft = parsableByteArray.bytesLeft();
this.output.sampleData(parsableByteArray, bytesLeft);
this.output.sampleMetadata(lastAdjustedTimestampUs, 1, bytesLeft, 0, null);
}
@EnsuresNonNull({"timestampAdjuster", "output"})
private void assertInitialized() {
Assertions.checkStateNotNull(this.timestampAdjuster);
Util.castNonNull(this.output);
}
}