package androidx.media3.exoplayer; import androidx.media3.common.Format; import androidx.media3.common.util.Assertions; import androidx.media3.decoder.DecoderInputBuffer; import androidx.media3.exoplayer.RendererCapabilities; import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.source.SampleStream; import java.io.IOException; /* loaded from: classes2.dex */ public abstract class BaseRenderer implements Renderer, RendererCapabilities { private RendererConfiguration configuration; private int index; private long lastResetPositionUs; private PlayerId playerId; private RendererCapabilities.Listener rendererCapabilitiesListener; private int state; private SampleStream stream; private Format[] streamFormats; private boolean streamIsFinal; private long streamOffsetUs; private boolean throwRendererExceptionIsExecuting; private final int trackType; private final Object lock = new Object(); private final FormatHolder formatHolder = new FormatHolder(); private long readingPositionUs = Long.MIN_VALUE; @Override // androidx.media3.exoplayer.Renderer public final RendererCapabilities getCapabilities() { return this; } protected final int getIndex() { return this.index; } protected final long getLastResetPositionUs() { return this.lastResetPositionUs; } @Override // androidx.media3.exoplayer.Renderer public MediaClock getMediaClock() { return null; } @Override // androidx.media3.exoplayer.Renderer public final long getReadingPositionUs() { return this.readingPositionUs; } @Override // androidx.media3.exoplayer.Renderer public final int getState() { return this.state; } @Override // androidx.media3.exoplayer.Renderer public final SampleStream getStream() { return this.stream; } @Override // androidx.media3.exoplayer.Renderer, androidx.media3.exoplayer.RendererCapabilities public final int getTrackType() { return this.trackType; } @Override // androidx.media3.exoplayer.PlayerMessage.Target public void handleMessage(int i, Object obj) throws ExoPlaybackException { } @Override // androidx.media3.exoplayer.Renderer public final boolean hasReadStreamToEnd() { return this.readingPositionUs == Long.MIN_VALUE; } @Override // androidx.media3.exoplayer.Renderer public final void init(int i, PlayerId playerId) { this.index = i; this.playerId = playerId; } @Override // androidx.media3.exoplayer.Renderer public final boolean isCurrentStreamFinal() { return this.streamIsFinal; } protected void onDisabled() { } protected void onEnabled(boolean z, boolean z2) throws ExoPlaybackException { } protected void onPositionReset(long j, boolean z) throws ExoPlaybackException { } protected void onRelease() { } protected void onReset() { } protected void onStarted() throws ExoPlaybackException { } protected void onStopped() { } /* JADX INFO: Access modifiers changed from: protected */ public void onStreamChanged(Format[] formatArr, long j, long j2) throws ExoPlaybackException { } @Override // androidx.media3.exoplayer.Renderer public final void setCurrentStreamFinal() { this.streamIsFinal = true; } @Override // androidx.media3.exoplayer.RendererCapabilities public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException { return 0; } public BaseRenderer(int i) { this.trackType = i; } @Override // androidx.media3.exoplayer.Renderer public final void enable(RendererConfiguration rendererConfiguration, Format[] formatArr, SampleStream sampleStream, long j, boolean z, boolean z2, long j2, long j3) throws ExoPlaybackException { Assertions.checkState(this.state == 0); this.configuration = rendererConfiguration; this.state = 1; onEnabled(z, z2); replaceStream(formatArr, sampleStream, j2, j3); resetPosition(j, z); } @Override // androidx.media3.exoplayer.Renderer public final void start() throws ExoPlaybackException { Assertions.checkState(this.state == 1); this.state = 2; onStarted(); } @Override // androidx.media3.exoplayer.Renderer public final void replaceStream(Format[] formatArr, SampleStream sampleStream, long j, long j2) throws ExoPlaybackException { Assertions.checkState(!this.streamIsFinal); this.stream = sampleStream; if (this.readingPositionUs == Long.MIN_VALUE) { this.readingPositionUs = j; } this.streamFormats = formatArr; this.streamOffsetUs = j2; onStreamChanged(formatArr, j, j2); } @Override // androidx.media3.exoplayer.Renderer public final void maybeThrowStreamError() throws IOException { ((SampleStream) Assertions.checkNotNull(this.stream)).maybeThrowError(); } @Override // androidx.media3.exoplayer.Renderer public final void resetPosition(long j) throws ExoPlaybackException { resetPosition(j, false); } private void resetPosition(long j, boolean z) throws ExoPlaybackException { this.streamIsFinal = false; this.lastResetPositionUs = j; this.readingPositionUs = j; onPositionReset(j, z); } @Override // androidx.media3.exoplayer.Renderer public final void stop() { Assertions.checkState(this.state == 2); this.state = 1; onStopped(); } @Override // androidx.media3.exoplayer.Renderer public final void disable() { Assertions.checkState(this.state == 1); this.formatHolder.clear(); this.state = 0; this.stream = null; this.streamFormats = null; this.streamIsFinal = false; onDisabled(); } @Override // androidx.media3.exoplayer.Renderer public final void reset() { Assertions.checkState(this.state == 0); this.formatHolder.clear(); onReset(); } @Override // androidx.media3.exoplayer.Renderer public final void release() { Assertions.checkState(this.state == 0); onRelease(); } @Override // androidx.media3.exoplayer.RendererCapabilities public final void setListener(RendererCapabilities.Listener listener) { synchronized (this.lock) { this.rendererCapabilitiesListener = listener; } } @Override // androidx.media3.exoplayer.RendererCapabilities public final void clearListener() { synchronized (this.lock) { this.rendererCapabilitiesListener = null; } } /* JADX INFO: Access modifiers changed from: protected */ public final FormatHolder getFormatHolder() { this.formatHolder.clear(); return this.formatHolder; } /* JADX INFO: Access modifiers changed from: protected */ public final Format[] getStreamFormats() { return (Format[]) Assertions.checkNotNull(this.streamFormats); } /* JADX INFO: Access modifiers changed from: protected */ public final RendererConfiguration getConfiguration() { return (RendererConfiguration) Assertions.checkNotNull(this.configuration); } /* JADX INFO: Access modifiers changed from: protected */ public final PlayerId getPlayerId() { return (PlayerId) Assertions.checkNotNull(this.playerId); } /* JADX INFO: Access modifiers changed from: protected */ public final ExoPlaybackException createRendererException(Throwable th, Format format, int i) { return createRendererException(th, format, false, i); } /* JADX INFO: Access modifiers changed from: protected */ public final ExoPlaybackException createRendererException(Throwable th, Format format, boolean z, int i) { int i2; if (format != null && !this.throwRendererExceptionIsExecuting) { this.throwRendererExceptionIsExecuting = true; try { i2 = RendererCapabilities.getFormatSupport(supportsFormat(format)); } catch (ExoPlaybackException unused) { } finally { this.throwRendererExceptionIsExecuting = false; } return ExoPlaybackException.createForRenderer(th, getName(), getIndex(), format, i2, z, i); } i2 = 4; return ExoPlaybackException.createForRenderer(th, getName(), getIndex(), format, i2, z, i); } /* JADX INFO: Access modifiers changed from: protected */ public final int readSource(FormatHolder formatHolder, DecoderInputBuffer decoderInputBuffer, int i) { int readData = ((SampleStream) Assertions.checkNotNull(this.stream)).readData(formatHolder, decoderInputBuffer, i); if (readData == -4) { if (decoderInputBuffer.isEndOfStream()) { this.readingPositionUs = Long.MIN_VALUE; return this.streamIsFinal ? -4 : -3; } decoderInputBuffer.timeUs += this.streamOffsetUs; this.readingPositionUs = Math.max(this.readingPositionUs, decoderInputBuffer.timeUs); } else if (readData == -5) { Format format = (Format) Assertions.checkNotNull(formatHolder.format); if (format.subsampleOffsetUs != Long.MAX_VALUE) { formatHolder.format = format.buildUpon().setSubsampleOffsetUs(format.subsampleOffsetUs + this.streamOffsetUs).build(); } } return readData; } /* JADX INFO: Access modifiers changed from: protected */ public int skipSource(long j) { return ((SampleStream) Assertions.checkNotNull(this.stream)).skipData(j - this.streamOffsetUs); } /* JADX INFO: Access modifiers changed from: protected */ public final boolean isSourceReady() { return hasReadStreamToEnd() ? this.streamIsFinal : ((SampleStream) Assertions.checkNotNull(this.stream)).isReady(); } /* JADX INFO: Access modifiers changed from: protected */ public final void onRendererCapabilitiesChanged() { RendererCapabilities.Listener listener; synchronized (this.lock) { listener = this.rendererCapabilitiesListener; } if (listener != null) { listener.onRendererCapabilitiesChanged(this); } } }