Rabbit-R1/original r1/java/sources/androidx/media3/exoplayer/source/CompositeMediaSource.java
2024-05-21 17:08:36 -04:00

254 lines
13 KiB
Java

package androidx.media3.exoplayer.source;
import android.os.Handler;
import androidx.media3.common.Timeline;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util;
import androidx.media3.datasource.TransferListener;
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.MediaSourceEventListener;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
/* loaded from: classes2.dex */
public abstract class CompositeMediaSource<T> extends BaseMediaSource {
private final HashMap<T, MediaSourceAndListener<T>> childSources = new HashMap<>();
private Handler eventHandler;
private TransferListener mediaTransferListener;
protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(T t, MediaSource.MediaPeriodId mediaPeriodId) {
return mediaPeriodId;
}
protected long getMediaTimeForChildMediaTime(T t, long j) {
return j;
}
protected int getWindowIndexForChildWindowIndex(T t, int i) {
return i;
}
/* JADX INFO: Access modifiers changed from: protected */
/* renamed from: onChildSourceInfoRefreshed, reason: merged with bridge method [inline-methods] */
public abstract void m5257x28f9175(T t, MediaSource mediaSource, Timeline timeline);
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.media3.exoplayer.source.BaseMediaSource
public void prepareSourceInternal(TransferListener transferListener) {
this.mediaTransferListener = transferListener;
this.eventHandler = Util.createHandlerForCurrentLooper();
}
@Override // androidx.media3.exoplayer.source.MediaSource
public void maybeThrowSourceInfoRefreshError() throws IOException {
Iterator<MediaSourceAndListener<T>> it = this.childSources.values().iterator();
while (it.hasNext()) {
it.next().mediaSource.maybeThrowSourceInfoRefreshError();
}
}
@Override // androidx.media3.exoplayer.source.BaseMediaSource
protected void enableInternal() {
for (MediaSourceAndListener<T> mediaSourceAndListener : this.childSources.values()) {
mediaSourceAndListener.mediaSource.enable(mediaSourceAndListener.caller);
}
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.media3.exoplayer.source.BaseMediaSource
public void disableInternal() {
for (MediaSourceAndListener<T> mediaSourceAndListener : this.childSources.values()) {
mediaSourceAndListener.mediaSource.disable(mediaSourceAndListener.caller);
}
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.media3.exoplayer.source.BaseMediaSource
public void releaseSourceInternal() {
for (MediaSourceAndListener<T> mediaSourceAndListener : this.childSources.values()) {
mediaSourceAndListener.mediaSource.releaseSource(mediaSourceAndListener.caller);
mediaSourceAndListener.mediaSource.removeEventListener(mediaSourceAndListener.eventListener);
mediaSourceAndListener.mediaSource.removeDrmEventListener(mediaSourceAndListener.eventListener);
}
this.childSources.clear();
}
/* JADX INFO: Access modifiers changed from: protected */
public final void prepareChildSource(final T t, MediaSource mediaSource) {
Assertions.checkArgument(!this.childSources.containsKey(t));
MediaSource.MediaSourceCaller mediaSourceCaller = new MediaSource.MediaSourceCaller() { // from class: androidx.media3.exoplayer.source.CompositeMediaSource$$ExternalSyntheticLambda0
@Override // androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller
public final void onSourceInfoRefreshed(MediaSource mediaSource2, Timeline timeline) {
CompositeMediaSource.this.m5257x28f9175(t, mediaSource2, timeline);
}
};
ForwardingEventListener forwardingEventListener = new ForwardingEventListener(t);
this.childSources.put(t, new MediaSourceAndListener<>(mediaSource, mediaSourceCaller, forwardingEventListener));
mediaSource.addEventListener((Handler) Assertions.checkNotNull(this.eventHandler), forwardingEventListener);
mediaSource.addDrmEventListener((Handler) Assertions.checkNotNull(this.eventHandler), forwardingEventListener);
mediaSource.prepareSource(mediaSourceCaller, this.mediaTransferListener, getPlayerId());
if (isEnabled()) {
return;
}
mediaSource.disable(mediaSourceCaller);
}
/* JADX INFO: Access modifiers changed from: protected */
public final void enableChildSource(T t) {
MediaSourceAndListener mediaSourceAndListener = (MediaSourceAndListener) Assertions.checkNotNull(this.childSources.get(t));
mediaSourceAndListener.mediaSource.enable(mediaSourceAndListener.caller);
}
/* JADX INFO: Access modifiers changed from: protected */
public final void disableChildSource(T t) {
MediaSourceAndListener mediaSourceAndListener = (MediaSourceAndListener) Assertions.checkNotNull(this.childSources.get(t));
mediaSourceAndListener.mediaSource.disable(mediaSourceAndListener.caller);
}
/* JADX INFO: Access modifiers changed from: protected */
public final void releaseChildSource(T t) {
MediaSourceAndListener mediaSourceAndListener = (MediaSourceAndListener) Assertions.checkNotNull(this.childSources.remove(t));
mediaSourceAndListener.mediaSource.releaseSource(mediaSourceAndListener.caller);
mediaSourceAndListener.mediaSource.removeEventListener(mediaSourceAndListener.eventListener);
mediaSourceAndListener.mediaSource.removeDrmEventListener(mediaSourceAndListener.eventListener);
}
/* loaded from: classes2.dex */
private static final class MediaSourceAndListener<T> {
public final MediaSource.MediaSourceCaller caller;
public final CompositeMediaSource<T>.ForwardingEventListener eventListener;
public final MediaSource mediaSource;
public MediaSourceAndListener(MediaSource mediaSource, MediaSource.MediaSourceCaller mediaSourceCaller, CompositeMediaSource<T>.ForwardingEventListener forwardingEventListener) {
this.mediaSource = mediaSource;
this.caller = mediaSourceCaller;
this.eventListener = forwardingEventListener;
}
}
/* loaded from: classes2.dex */
private final class ForwardingEventListener implements MediaSourceEventListener, DrmSessionEventListener {
private DrmSessionEventListener.EventDispatcher drmEventDispatcher;
private final T id;
private MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher;
public ForwardingEventListener(T t) {
this.mediaSourceEventDispatcher = CompositeMediaSource.this.createEventDispatcher(null);
this.drmEventDispatcher = CompositeMediaSource.this.createDrmEventDispatcher(null);
this.id = t;
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onLoadStarted(int i, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.loadStarted(loadEventInfo, maybeUpdateMediaLoadData(mediaLoadData));
}
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onLoadCompleted(int i, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.loadCompleted(loadEventInfo, maybeUpdateMediaLoadData(mediaLoadData));
}
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onLoadCanceled(int i, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.loadCanceled(loadEventInfo, maybeUpdateMediaLoadData(mediaLoadData));
}
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onLoadError(int i, MediaSource.MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException iOException, boolean z) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.loadError(loadEventInfo, maybeUpdateMediaLoadData(mediaLoadData), iOException, z);
}
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onUpstreamDiscarded(int i, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.upstreamDiscarded(maybeUpdateMediaLoadData(mediaLoadData));
}
}
@Override // androidx.media3.exoplayer.source.MediaSourceEventListener
public void onDownstreamFormatChanged(int i, MediaSource.MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.mediaSourceEventDispatcher.downstreamFormatChanged(maybeUpdateMediaLoadData(mediaLoadData));
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmSessionAcquired(int i, MediaSource.MediaPeriodId mediaPeriodId, int i2) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmSessionAcquired(i2);
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmKeysLoaded(int i, MediaSource.MediaPeriodId mediaPeriodId) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmKeysLoaded();
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmSessionManagerError(int i, MediaSource.MediaPeriodId mediaPeriodId, Exception exc) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmSessionManagerError(exc);
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmKeysRestored(int i, MediaSource.MediaPeriodId mediaPeriodId) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmKeysRestored();
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmKeysRemoved(int i, MediaSource.MediaPeriodId mediaPeriodId) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmKeysRemoved();
}
}
@Override // androidx.media3.exoplayer.drm.DrmSessionEventListener
public void onDrmSessionReleased(int i, MediaSource.MediaPeriodId mediaPeriodId) {
if (maybeUpdateEventDispatcher(i, mediaPeriodId)) {
this.drmEventDispatcher.drmSessionReleased();
}
}
private boolean maybeUpdateEventDispatcher(int i, MediaSource.MediaPeriodId mediaPeriodId) {
MediaSource.MediaPeriodId mediaPeriodId2;
if (mediaPeriodId != null) {
mediaPeriodId2 = CompositeMediaSource.this.getMediaPeriodIdForChildMediaPeriodId(this.id, mediaPeriodId);
if (mediaPeriodId2 == null) {
return false;
}
} else {
mediaPeriodId2 = null;
}
int windowIndexForChildWindowIndex = CompositeMediaSource.this.getWindowIndexForChildWindowIndex(this.id, i);
if (this.mediaSourceEventDispatcher.windowIndex != windowIndexForChildWindowIndex || !Util.areEqual(this.mediaSourceEventDispatcher.mediaPeriodId, mediaPeriodId2)) {
this.mediaSourceEventDispatcher = CompositeMediaSource.this.createEventDispatcher(windowIndexForChildWindowIndex, mediaPeriodId2);
}
if (this.drmEventDispatcher.windowIndex == windowIndexForChildWindowIndex && Util.areEqual(this.drmEventDispatcher.mediaPeriodId, mediaPeriodId2)) {
return true;
}
this.drmEventDispatcher = CompositeMediaSource.this.createDrmEventDispatcher(windowIndexForChildWindowIndex, mediaPeriodId2);
return true;
}
private MediaLoadData maybeUpdateMediaLoadData(MediaLoadData mediaLoadData) {
long mediaTimeForChildMediaTime = CompositeMediaSource.this.getMediaTimeForChildMediaTime(this.id, mediaLoadData.mediaStartTimeMs);
long mediaTimeForChildMediaTime2 = CompositeMediaSource.this.getMediaTimeForChildMediaTime(this.id, mediaLoadData.mediaEndTimeMs);
return (mediaTimeForChildMediaTime == mediaLoadData.mediaStartTimeMs && mediaTimeForChildMediaTime2 == mediaLoadData.mediaEndTimeMs) ? mediaLoadData : new MediaLoadData(mediaLoadData.dataType, mediaLoadData.trackType, mediaLoadData.trackFormat, mediaLoadData.trackSelectionReason, mediaLoadData.trackSelectionData, mediaTimeForChildMediaTime, mediaTimeForChildMediaTime2);
}
}
}