Rabbit-R1/android (non root)/java/sources/androidx/media3/exoplayer/text/TextRenderer.java
2024-05-21 17:08:36 -04:00

243 lines
8.8 KiB
Java

package androidx.media3.exoplayer.text;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.text.CueGroup;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.BaseRenderer;
import androidx.media3.exoplayer.FormatHolder;
import androidx.media3.exoplayer.RendererCapabilities;
import androidx.media3.extractor.text.SubtitleDecoder;
import androidx.media3.extractor.text.SubtitleDecoderException;
import androidx.media3.extractor.text.SubtitleInputBuffer;
import androidx.media3.extractor.text.SubtitleOutputBuffer;
import com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.checkerframework.dataflow.qual.SideEffectFree;
/* loaded from: classes2.dex */
public final class TextRenderer extends BaseRenderer implements Handler.Callback {
private static final int MSG_UPDATE_OUTPUT = 0;
private static final int REPLACEMENT_STATE_NONE = 0;
private static final int REPLACEMENT_STATE_SIGNAL_END_OF_STREAM = 1;
private static final int REPLACEMENT_STATE_WAIT_END_OF_STREAM = 2;
private static final String TAG = "TextRenderer";
private SubtitleDecoder decoder;
private final SubtitleDecoderFactory decoderFactory;
private int decoderReplacementState;
private long finalStreamEndPositionUs;
private final FormatHolder formatHolder;
private boolean inputStreamEnded;
private long lastRendererPositionUs;
private SubtitleInputBuffer nextInputBuffer;
private SubtitleOutputBuffer nextSubtitle;
private int nextSubtitleEventIndex;
private final TextOutput output;
private final Handler outputHandler;
private boolean outputStreamEnded;
private long outputStreamOffsetUs;
private Format streamFormat;
private SubtitleOutputBuffer subtitle;
private boolean waitingForKeyFrame;
@Override // androidx.media3.exoplayer.Renderer, androidx.media3.exoplayer.RendererCapabilities
public String getName() {
return TAG;
}
@Override // androidx.media3.exoplayer.Renderer
public boolean isEnded() {
return this.outputStreamEnded;
}
@Override // androidx.media3.exoplayer.Renderer
public boolean isReady() {
return true;
}
public TextRenderer(TextOutput textOutput, Looper looper) {
this(textOutput, looper, SubtitleDecoderFactory.DEFAULT);
}
public TextRenderer(TextOutput textOutput, Looper looper, SubtitleDecoderFactory subtitleDecoderFactory) {
super(3);
this.output = (TextOutput) Assertions.checkNotNull(textOutput);
this.outputHandler = looper == null ? null : Util.createHandler(looper, this);
this.decoderFactory = subtitleDecoderFactory;
this.formatHolder = new FormatHolder();
this.finalStreamEndPositionUs = -9223372036854775807L;
this.outputStreamOffsetUs = -9223372036854775807L;
this.lastRendererPositionUs = -9223372036854775807L;
}
@Override // androidx.media3.exoplayer.RendererCapabilities
public int supportsFormat(Format format) {
if (this.decoderFactory.supportsFormat(format)) {
return RendererCapabilities.create(format.cryptoType == 0 ? 4 : 2);
}
if (MimeTypes.isText(format.sampleMimeType)) {
return RendererCapabilities.create(1);
}
return RendererCapabilities.create(0);
}
public void setFinalStreamEndPositionUs(long j) {
Assertions.checkState(isCurrentStreamFinal());
this.finalStreamEndPositionUs = j;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.media3.exoplayer.BaseRenderer
public void onStreamChanged(Format[] formatArr, long j, long j2) {
this.outputStreamOffsetUs = j2;
this.streamFormat = formatArr[0];
if (this.decoder != null) {
this.decoderReplacementState = 1;
} else {
initDecoder();
}
}
@Override // androidx.media3.exoplayer.BaseRenderer
protected void onPositionReset(long j, boolean z) {
this.lastRendererPositionUs = j;
clearOutput();
this.inputStreamEnded = false;
this.outputStreamEnded = false;
this.finalStreamEndPositionUs = -9223372036854775807L;
if (this.decoderReplacementState != 0) {
replaceDecoder();
} else {
releaseBuffers();
((SubtitleDecoder) Assertions.checkNotNull(this.decoder)).flush();
}
}
/* JADX WARN: Code restructure failed: missing block: B:97:0x00a9, code lost:
if (r11 != false) goto L48;
*/
@Override // androidx.media3.exoplayer.Renderer
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void render(long r9, long r11) {
/*
Method dump skipped, instructions count: 325
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.media3.exoplayer.text.TextRenderer.render(long, long):void");
}
@Override // androidx.media3.exoplayer.BaseRenderer
protected void onDisabled() {
this.streamFormat = null;
this.finalStreamEndPositionUs = -9223372036854775807L;
clearOutput();
this.outputStreamOffsetUs = -9223372036854775807L;
this.lastRendererPositionUs = -9223372036854775807L;
releaseDecoder();
}
private void releaseBuffers() {
this.nextInputBuffer = null;
this.nextSubtitleEventIndex = -1;
SubtitleOutputBuffer subtitleOutputBuffer = this.subtitle;
if (subtitleOutputBuffer != null) {
subtitleOutputBuffer.release();
this.subtitle = null;
}
SubtitleOutputBuffer subtitleOutputBuffer2 = this.nextSubtitle;
if (subtitleOutputBuffer2 != null) {
subtitleOutputBuffer2.release();
this.nextSubtitle = null;
}
}
private void releaseDecoder() {
releaseBuffers();
((SubtitleDecoder) Assertions.checkNotNull(this.decoder)).release();
this.decoder = null;
this.decoderReplacementState = 0;
}
private void initDecoder() {
this.waitingForKeyFrame = true;
this.decoder = this.decoderFactory.createDecoder((Format) Assertions.checkNotNull(this.streamFormat));
}
private void replaceDecoder() {
releaseDecoder();
initDecoder();
}
private long getNextEventTime() {
if (this.nextSubtitleEventIndex == -1) {
return Long.MAX_VALUE;
}
Assertions.checkNotNull(this.subtitle);
if (this.nextSubtitleEventIndex >= this.subtitle.getEventTimeCount()) {
return Long.MAX_VALUE;
}
return this.subtitle.getEventTime(this.nextSubtitleEventIndex);
}
private void updateOutput(CueGroup cueGroup) {
Handler handler = this.outputHandler;
if (handler != null) {
handler.obtainMessage(0, cueGroup).sendToTarget();
} else {
invokeUpdateOutputInternal(cueGroup);
}
}
private void clearOutput() {
updateOutput(new CueGroup(ImmutableList.of(), getPresentationTimeUs(this.lastRendererPositionUs)));
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message.what == 0) {
invokeUpdateOutputInternal((CueGroup) message.obj);
return true;
}
throw new IllegalStateException();
}
private void invokeUpdateOutputInternal(CueGroup cueGroup) {
this.output.onCues(cueGroup.cues);
this.output.onCues(cueGroup);
}
private void handleDecoderError(SubtitleDecoderException subtitleDecoderException) {
Log.e(TAG, "Subtitle decoding failed. streamFormat=" + this.streamFormat, subtitleDecoderException);
clearOutput();
replaceDecoder();
}
@RequiresNonNull({"subtitle"})
@SideEffectFree
private long getCurrentEventTimeUs(long j) {
int nextEventTimeIndex = this.subtitle.getNextEventTimeIndex(j);
if (nextEventTimeIndex == 0 || this.subtitle.getEventTimeCount() == 0) {
return this.subtitle.timeUs;
}
if (nextEventTimeIndex == -1) {
return this.subtitle.getEventTime(r1.getEventTimeCount() - 1);
}
return this.subtitle.getEventTime(nextEventTimeIndex - 1);
}
@SideEffectFree
private long getPresentationTimeUs(long j) {
Assertions.checkState(j != -9223372036854775807L);
Assertions.checkState(this.outputStreamOffsetUs != -9223372036854775807L);
return j - this.outputStreamOffsetUs;
}
}