Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/source/BaseMediaSource.java
2024-05-21 17:08:36 -04:00

165 lines
7.1 KiB
Java

package androidx.media3.exoplayer.source;
import android.os.Handler;
import android.os.Looper;
import androidx.media3.common.Timeline;
import androidx.media3.common.util.Assertions;
import androidx.media3.datasource.TransferListener;
import androidx.media3.exoplayer.analytics.PlayerId;
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.MediaSourceEventListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
/* loaded from: classes2.dex */
public abstract class BaseMediaSource implements MediaSource {
private Looper looper;
private PlayerId playerId;
private Timeline timeline;
private final ArrayList<MediaSource.MediaSourceCaller> mediaSourceCallers = new ArrayList<>(1);
private final HashSet<MediaSource.MediaSourceCaller> enabledMediaSourceCallers = new HashSet<>(1);
private final MediaSourceEventListener.EventDispatcher eventDispatcher = new MediaSourceEventListener.EventDispatcher();
private final DrmSessionEventListener.EventDispatcher drmEventDispatcher = new DrmSessionEventListener.EventDispatcher();
protected void disableInternal() {
}
protected void enableInternal() {
}
protected abstract void prepareSourceInternal(TransferListener transferListener);
protected abstract void releaseSourceInternal();
/* JADX INFO: Access modifiers changed from: protected */
public final void refreshSourceInfo(Timeline timeline) {
this.timeline = timeline;
Iterator<MediaSource.MediaSourceCaller> it = this.mediaSourceCallers.iterator();
while (it.hasNext()) {
it.next().onSourceInfoRefreshed(this, timeline);
}
}
/* JADX INFO: Access modifiers changed from: protected */
public final MediaSourceEventListener.EventDispatcher createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId) {
return this.eventDispatcher.withParameters(0, mediaPeriodId);
}
/* JADX INFO: Access modifiers changed from: protected */
public final MediaSourceEventListener.EventDispatcher createEventDispatcher(int i, MediaSource.MediaPeriodId mediaPeriodId) {
return this.eventDispatcher.withParameters(i, mediaPeriodId);
}
@Deprecated
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId, long j) {
Assertions.checkNotNull(mediaPeriodId);
return this.eventDispatcher.withParameters(0, mediaPeriodId);
}
@Deprecated
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(int i, MediaSource.MediaPeriodId mediaPeriodId, long j) {
return this.eventDispatcher.withParameters(i, mediaPeriodId);
}
/* JADX INFO: Access modifiers changed from: protected */
public final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(MediaSource.MediaPeriodId mediaPeriodId) {
return this.drmEventDispatcher.withParameters(0, mediaPeriodId);
}
/* JADX INFO: Access modifiers changed from: protected */
public final DrmSessionEventListener.EventDispatcher createDrmEventDispatcher(int i, MediaSource.MediaPeriodId mediaPeriodId) {
return this.drmEventDispatcher.withParameters(i, mediaPeriodId);
}
/* JADX INFO: Access modifiers changed from: protected */
public final boolean isEnabled() {
return !this.enabledMediaSourceCallers.isEmpty();
}
/* JADX INFO: Access modifiers changed from: protected */
public final PlayerId getPlayerId() {
return (PlayerId) Assertions.checkStateNotNull(this.playerId);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void addEventListener(Handler handler, MediaSourceEventListener mediaSourceEventListener) {
Assertions.checkNotNull(handler);
Assertions.checkNotNull(mediaSourceEventListener);
this.eventDispatcher.addEventListener(handler, mediaSourceEventListener);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void removeEventListener(MediaSourceEventListener mediaSourceEventListener) {
this.eventDispatcher.removeEventListener(mediaSourceEventListener);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void addDrmEventListener(Handler handler, DrmSessionEventListener drmSessionEventListener) {
Assertions.checkNotNull(handler);
Assertions.checkNotNull(drmSessionEventListener);
this.drmEventDispatcher.addEventListener(handler, drmSessionEventListener);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void removeDrmEventListener(DrmSessionEventListener drmSessionEventListener) {
this.drmEventDispatcher.removeEventListener(drmSessionEventListener);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void prepareSource(MediaSource.MediaSourceCaller mediaSourceCaller, TransferListener transferListener) {
prepareSource(mediaSourceCaller, transferListener, PlayerId.UNSET);
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void prepareSource(MediaSource.MediaSourceCaller mediaSourceCaller, TransferListener transferListener, PlayerId playerId) {
Looper myLooper = Looper.myLooper();
Looper looper = this.looper;
Assertions.checkArgument(looper == null || looper == myLooper);
this.playerId = playerId;
Timeline timeline = this.timeline;
this.mediaSourceCallers.add(mediaSourceCaller);
if (this.looper == null) {
this.looper = myLooper;
this.enabledMediaSourceCallers.add(mediaSourceCaller);
prepareSourceInternal(transferListener);
} else if (timeline != null) {
enable(mediaSourceCaller);
mediaSourceCaller.onSourceInfoRefreshed(this, timeline);
}
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void enable(MediaSource.MediaSourceCaller mediaSourceCaller) {
Assertions.checkNotNull(this.looper);
boolean isEmpty = this.enabledMediaSourceCallers.isEmpty();
this.enabledMediaSourceCallers.add(mediaSourceCaller);
if (isEmpty) {
enableInternal();
}
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void disable(MediaSource.MediaSourceCaller mediaSourceCaller) {
boolean z = !this.enabledMediaSourceCallers.isEmpty();
this.enabledMediaSourceCallers.remove(mediaSourceCaller);
if (z && this.enabledMediaSourceCallers.isEmpty()) {
disableInternal();
}
}
@Override // androidx.media3.exoplayer.source.MediaSource
public final void releaseSource(MediaSource.MediaSourceCaller mediaSourceCaller) {
this.mediaSourceCallers.remove(mediaSourceCaller);
if (this.mediaSourceCallers.isEmpty()) {
this.looper = null;
this.timeline = null;
this.playerId = null;
this.enabledMediaSourceCallers.clear();
releaseSourceInternal();
return;
}
disable(mediaSourceCaller);
}
}