Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/source/MaskingMediaPeriod.java

191 lines
7.5 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.exoplayer.source;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.SeekParameters;
import androidx.media3.exoplayer.source.MediaPeriod;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
import androidx.media3.exoplayer.upstream.Allocator;
import java.io.IOException;
/* loaded from: classes2.dex */
public final class MaskingMediaPeriod implements MediaPeriod, MediaPeriod.Callback {
private final Allocator allocator;
private MediaPeriod.Callback callback;
public final MediaSource.MediaPeriodId id;
private PrepareListener listener;
private MediaPeriod mediaPeriod;
private MediaSource mediaSource;
private boolean notifiedPrepareError;
private long preparePositionOverrideUs = -9223372036854775807L;
private final long preparePositionUs;
/* loaded from: classes2.dex */
public interface PrepareListener {
void onPrepareComplete(MediaSource.MediaPeriodId mediaPeriodId);
void onPrepareError(MediaSource.MediaPeriodId mediaPeriodId, IOException iOException);
}
private long getPreparePositionWithOverride(long j) {
long j2 = this.preparePositionOverrideUs;
return j2 != -9223372036854775807L ? j2 : j;
}
public long getPreparePositionOverrideUs() {
return this.preparePositionOverrideUs;
}
public long getPreparePositionUs() {
return this.preparePositionUs;
}
public void overridePreparePositionUs(long j) {
this.preparePositionOverrideUs = j;
}
public void setPrepareListener(PrepareListener prepareListener) {
this.listener = prepareListener;
}
public MaskingMediaPeriod(MediaSource.MediaPeriodId mediaPeriodId, Allocator allocator, long j) {
this.id = mediaPeriodId;
this.allocator = allocator;
this.preparePositionUs = j;
}
public void setMediaSource(MediaSource mediaSource) {
Assertions.checkState(this.mediaSource == null);
this.mediaSource = mediaSource;
}
public void createPeriod(MediaSource.MediaPeriodId mediaPeriodId) {
long preparePositionWithOverride = getPreparePositionWithOverride(this.preparePositionUs);
MediaPeriod createPeriod = ((MediaSource) Assertions.checkNotNull(this.mediaSource)).createPeriod(mediaPeriodId, this.allocator, preparePositionWithOverride);
this.mediaPeriod = createPeriod;
if (this.callback != null) {
createPeriod.prepare(this, preparePositionWithOverride);
}
}
public void releasePeriod() {
if (this.mediaPeriod != null) {
((MediaSource) Assertions.checkNotNull(this.mediaSource)).releasePeriod(this.mediaPeriod);
}
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public void prepare(MediaPeriod.Callback callback, long j) {
this.callback = callback;
MediaPeriod mediaPeriod = this.mediaPeriod;
if (mediaPeriod != null) {
mediaPeriod.prepare(this, getPreparePositionWithOverride(this.preparePositionUs));
}
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public void maybeThrowPrepareError() throws IOException {
try {
MediaPeriod mediaPeriod = this.mediaPeriod;
if (mediaPeriod != null) {
mediaPeriod.maybeThrowPrepareError();
} else {
MediaSource mediaSource = this.mediaSource;
if (mediaSource != null) {
mediaSource.maybeThrowSourceInfoRefreshError();
}
}
} catch (IOException e) {
PrepareListener prepareListener = this.listener;
if (prepareListener == null) {
throw e;
}
if (this.notifiedPrepareError) {
return;
}
this.notifiedPrepareError = true;
prepareListener.onPrepareError(this.id, e);
}
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public TrackGroupArray getTrackGroups() {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).getTrackGroups();
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public long selectTracks(ExoTrackSelection[] exoTrackSelectionArr, boolean[] zArr, SampleStream[] sampleStreamArr, boolean[] zArr2, long j) {
long j2;
long j3 = this.preparePositionOverrideUs;
if (j3 == -9223372036854775807L || j != this.preparePositionUs) {
j2 = j;
} else {
this.preparePositionOverrideUs = -9223372036854775807L;
j2 = j3;
}
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).selectTracks(exoTrackSelectionArr, zArr, sampleStreamArr, zArr2, j2);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public void discardBuffer(long j, boolean z) {
((MediaPeriod) Util.castNonNull(this.mediaPeriod)).discardBuffer(j, z);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public long readDiscontinuity() {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).readDiscontinuity();
}
@Override // androidx.media3.exoplayer.source.MediaPeriod, androidx.media3.exoplayer.source.SequenceableLoader
public long getBufferedPositionUs() {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).getBufferedPositionUs();
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public long seekToUs(long j) {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).seekToUs(j);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod
public long getAdjustedSeekPositionUs(long j, SeekParameters seekParameters) {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).getAdjustedSeekPositionUs(j, seekParameters);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod, androidx.media3.exoplayer.source.SequenceableLoader
public long getNextLoadPositionUs() {
return ((MediaPeriod) Util.castNonNull(this.mediaPeriod)).getNextLoadPositionUs();
}
@Override // androidx.media3.exoplayer.source.MediaPeriod, androidx.media3.exoplayer.source.SequenceableLoader
public void reevaluateBuffer(long j) {
((MediaPeriod) Util.castNonNull(this.mediaPeriod)).reevaluateBuffer(j);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod, androidx.media3.exoplayer.source.SequenceableLoader
public boolean continueLoading(long j) {
MediaPeriod mediaPeriod = this.mediaPeriod;
return mediaPeriod != null && mediaPeriod.continueLoading(j);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod, androidx.media3.exoplayer.source.SequenceableLoader
public boolean isLoading() {
MediaPeriod mediaPeriod = this.mediaPeriod;
return mediaPeriod != null && mediaPeriod.isLoading();
}
@Override // androidx.media3.exoplayer.source.SequenceableLoader.Callback
public void onContinueLoadingRequested(MediaPeriod mediaPeriod) {
((MediaPeriod.Callback) Util.castNonNull(this.callback)).onContinueLoadingRequested(this);
}
@Override // androidx.media3.exoplayer.source.MediaPeriod.Callback
public void onPrepared(MediaPeriod mediaPeriod) {
((MediaPeriod.Callback) Util.castNonNull(this.callback)).onPrepared(this);
PrepareListener prepareListener = this.listener;
if (prepareListener != null) {
prepareListener.onPrepareComplete(this.id);
}
}
}