package com.mbridge.msdk.playercommon.exoplayer2.text; import android.os.Handler; import android.os.Looper; import android.os.Message; import com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer; import com.mbridge.msdk.playercommon.exoplayer2.ExoPlaybackException; import com.mbridge.msdk.playercommon.exoplayer2.Format; import com.mbridge.msdk.playercommon.exoplayer2.FormatHolder; import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions; import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Collections; import java.util.List; /* loaded from: classes4.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 SubtitleDecoder decoder; private final SubtitleDecoderFactory decoderFactory; private int decoderReplacementState; private final FormatHolder formatHolder; private boolean inputStreamEnded; private SubtitleInputBuffer nextInputBuffer; private SubtitleOutputBuffer nextSubtitle; private int nextSubtitleEventIndex; private final TextOutput output; private final Handler outputHandler; private boolean outputStreamEnded; private Format streamFormat; private SubtitleOutputBuffer subtitle; @Deprecated public interface Output extends TextOutput { } @Retention(RetentionPolicy.SOURCE) public @interface ReplacementState { } @Override // com.mbridge.msdk.playercommon.exoplayer2.Renderer public final boolean isEnded() { return this.outputStreamEnded; } @Override // com.mbridge.msdk.playercommon.exoplayer2.Renderer public final 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 : new Handler(looper, this); this.decoderFactory = subtitleDecoderFactory; this.formatHolder = new FormatHolder(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.RendererCapabilities public final int supportsFormat(Format format) { return this.decoderFactory.supportsFormat(format) ? BaseRenderer.supportsFormatDrm(null, format.drmInitData) ? 4 : 2 : MimeTypes.isText(format.sampleMimeType) ? 1 : 0; } @Override // com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public final void onStreamChanged(Format[] formatArr, long j) throws ExoPlaybackException { Format format = formatArr[0]; this.streamFormat = format; if (this.decoder != null) { this.decoderReplacementState = 1; } else { this.decoder = this.decoderFactory.createDecoder(format); } } @Override // com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public final void onPositionReset(long j, boolean z) { clearOutput(); this.inputStreamEnded = false; this.outputStreamEnded = false; if (this.decoderReplacementState != 0) { replaceDecoder(); } else { releaseBuffers(); this.decoder.flush(); } } /* JADX WARN: Code restructure failed: missing block: B:82:0x008a, code lost: if (r11 != false) goto L41; */ @Override // com.mbridge.msdk.playercommon.exoplayer2.Renderer /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final void render(long r9, long r11) throws com.mbridge.msdk.playercommon.exoplayer2.ExoPlaybackException { /* Method dump skipped, instructions count: 257 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.mbridge.msdk.playercommon.exoplayer2.text.TextRenderer.render(long, long):void"); } @Override // com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public final void onDisabled() { this.streamFormat = null; clearOutput(); 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(); this.decoder.release(); this.decoder = null; this.decoderReplacementState = 0; } private void replaceDecoder() { releaseDecoder(); this.decoder = this.decoderFactory.createDecoder(this.streamFormat); } private long getNextEventTime() { int i = this.nextSubtitleEventIndex; if (i == -1 || i >= this.subtitle.getEventTimeCount()) { return Long.MAX_VALUE; } return this.subtitle.getEventTime(this.nextSubtitleEventIndex); } private void updateOutput(List list) { Handler handler = this.outputHandler; if (handler != null) { handler.obtainMessage(0, list).sendToTarget(); } else { invokeUpdateOutputInternal(list); } } private void clearOutput() { updateOutput(Collections.emptyList()); } @Override // android.os.Handler.Callback public final boolean handleMessage(Message message) { if (message.what == 0) { invokeUpdateOutputInternal((List) message.obj); return true; } throw new IllegalStateException(); } private void invokeUpdateOutputInternal(List list) { this.output.onCues(list); } }