BaseRenderer.java 源代码
package com.mbridge.msdk.playercommon.exoplayer2;
import com.mbridge.msdk.playercommon.exoplayer2.decoder.DecoderInputBuffer;
import com.mbridge.msdk.playercommon.exoplayer2.drm.DrmInitData;
import com.mbridge.msdk.playercommon.exoplayer2.drm.DrmSessionManager;
import com.mbridge.msdk.playercommon.exoplayer2.source.SampleStream;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.MediaClock;
import java.io.IOException;
public abstract class BaseRenderer implements Renderer, RendererCapabilities {
private RendererConfiguration configuration;
private int index;
private boolean readEndOfStream = true;
private int state;
private SampleStream stream;
private Format[] streamFormats;
private boolean streamIsFinal;
private long streamOffsetUs;
private final int trackType;
public BaseRenderer(int i6) {
this.trackType = i6;
}
public static boolean supportsFormatDrm(DrmSessionManager<?> drmSessionManager, DrmInitData drmInitData) {
if (drmInitData == null) {
return true;
}
if (drmSessionManager == null) {
return false;
}
return drmSessionManager.canAcquireSession(drmInitData);
}
@Override
public final void disable() {
boolean z6 = true;
if (this.state != 1) {
z6 = false;
}
Assertions.checkState(z6);
this.state = 0;
this.stream = null;
this.streamFormats = null;
this.streamIsFinal = false;
onDisabled();
}
@Override
public final void enable(RendererConfiguration rendererConfiguration, Format[] formatArr, SampleStream sampleStream, long j6, boolean z6, long j7) throws ExoPlaybackException {
boolean z7;
if (this.state == 0) {
z7 = true;
} else {
z7 = false;
}
Assertions.checkState(z7);
this.configuration = rendererConfiguration;
this.state = 1;
onEnabled(z6);
replaceStream(formatArr, sampleStream, j7);
onPositionReset(j6, z6);
}
@Override
public final RendererCapabilities getCapabilities() {
return this;
}
public final RendererConfiguration getConfiguration() {
return this.configuration;
}
public final int getIndex() {
return this.index;
}
@Override
public MediaClock getMediaClock() {
return null;
}
@Override
public final int getState() {
return this.state;
}
@Override
public final SampleStream getStream() {
return this.stream;
}
public final Format[] getStreamFormats() {
return this.streamFormats;
}
@Override
public final int getTrackType() {
return this.trackType;
}
@Override
public void handleMessage(int i6, Object obj) throws ExoPlaybackException {
}
@Override
public final boolean hasReadStreamToEnd() {
return this.readEndOfStream;
}
@Override
public final boolean isCurrentStreamFinal() {
return this.streamIsFinal;
}
public final boolean isSourceReady() {
if (this.readEndOfStream) {
return this.streamIsFinal;
}
return this.stream.isReady();
}
@Override
public final void maybeThrowStreamError() throws IOException {
this.stream.maybeThrowError();
}
protected void onDisabled() {
}
protected void onEnabled(boolean z6) throws ExoPlaybackException {
}
protected void onPositionReset(long j6, boolean z6) throws ExoPlaybackException {
}
protected void onStarted() throws ExoPlaybackException {
}
protected void onStopped() throws ExoPlaybackException {
}
public void onStreamChanged(Format[] formatArr, long j6) throws ExoPlaybackException {
}
public final int readSource(FormatHolder formatHolder, DecoderInputBuffer decoderInputBuffer, boolean z6) {
int readData = this.stream.readData(formatHolder, decoderInputBuffer, z6);
if (readData == -4) {
if (decoderInputBuffer.isEndOfStream()) {
this.readEndOfStream = true;
if (this.streamIsFinal) {
return -4;
}
return -3;
}
decoderInputBuffer.timeUs += this.streamOffsetUs;
} else if (readData == -5) {
Format format = formatHolder.format;
long j6 = format.subsampleOffsetUs;
if (j6 != Long.MAX_VALUE) {
formatHolder.format = format.copyWithSubsampleOffsetUs(j6 + this.streamOffsetUs);
}
}
return readData;
}
@Override
public final void replaceStream(Format[] formatArr, SampleStream sampleStream, long j6) throws ExoPlaybackException {
Assertions.checkState(!this.streamIsFinal);
this.stream = sampleStream;
this.readEndOfStream = false;
this.streamFormats = formatArr;
this.streamOffsetUs = j6;
onStreamChanged(formatArr, j6);
}
@Override
public final void resetPosition(long j6) throws ExoPlaybackException {
this.streamIsFinal = false;
this.readEndOfStream = false;
onPositionReset(j6, false);
}
@Override
public final void setCurrentStreamFinal() {
this.streamIsFinal = true;
}
@Override
public final void setIndex(int i6) {
this.index = i6;
}
public int skipSource(long j6) {
return this.stream.skipData(j6 - this.streamOffsetUs);
}
@Override
public final void start() throws ExoPlaybackException {
boolean z6 = true;
if (this.state != 1) {
z6 = false;
}
Assertions.checkState(z6);
this.state = 2;
onStarted();
}
@Override
public final void stop() throws ExoPlaybackException {
boolean z6;
if (this.state == 2) {
z6 = true;
} else {
z6 = false;
}
Assertions.checkState(z6);
this.state = 1;
onStopped();
}
@Override
public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
return 0;
}
}