package com.google.android.exoplayer2; import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.MediaClock; 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 int state; private SampleStream stream; private Format[] streamFormats; private boolean streamIsFinal; private long streamOffsetUs; private boolean throwRendererExceptionIsExecuting; private final int trackType; private final FormatHolder formatHolder = new FormatHolder(); private long readingPositionUs = Long.MIN_VALUE; @Override // com.google.android.exoplayer2.Renderer public final RendererCapabilities getCapabilities() { return this; } protected final int getIndex() { return this.index; } protected final long getLastResetPositionUs() { return this.lastResetPositionUs; } @Override // com.google.android.exoplayer2.Renderer public MediaClock getMediaClock() { return null; } @Override // com.google.android.exoplayer2.Renderer public final long getReadingPositionUs() { return this.readingPositionUs; } @Override // com.google.android.exoplayer2.Renderer public final int getState() { return this.state; } @Override // com.google.android.exoplayer2.Renderer public final SampleStream getStream() { return this.stream; } @Override // com.google.android.exoplayer2.Renderer, com.google.android.exoplayer2.RendererCapabilities public final int getTrackType() { return this.trackType; } @Override // com.google.android.exoplayer2.PlayerMessage.Target public void handleMessage(int i, Object obj) throws ExoPlaybackException { } @Override // com.google.android.exoplayer2.Renderer public final boolean hasReadStreamToEnd() { return this.readingPositionUs == Long.MIN_VALUE; } @Override // com.google.android.exoplayer2.Renderer public final void init(int i, PlayerId playerId) { this.index = i; this.playerId = playerId; } @Override // com.google.android.exoplayer2.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 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 // com.google.android.exoplayer2.Renderer public final void setCurrentStreamFinal() { this.streamIsFinal = true; } @Override // com.google.android.exoplayer2.RendererCapabilities public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException { return 0; } public BaseRenderer(int i) { this.trackType = i; } @Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.Renderer public final void start() throws ExoPlaybackException { Assertions.checkState(this.state == 1); this.state = 2; onStarted(); } @Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.Renderer public final void maybeThrowStreamError() throws IOException { ((SampleStream) Assertions.checkNotNull(this.stream)).maybeThrowError(); } @Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.Renderer public final void stop() { Assertions.checkState(this.state == 2); this.state = 1; onStopped(); } @Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.Renderer public final void reset() { Assertions.checkState(this.state == 0); this.formatHolder.clear(); onReset(); } /* 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(); } }