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

95 lines
4 KiB
Java

package androidx.media3.exoplayer.trackselection;
import android.os.SystemClock;
import androidx.media3.common.Timeline;
import androidx.media3.common.TrackGroup;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.chunk.MediaChunk;
import androidx.media3.exoplayer.source.chunk.MediaChunkIterator;
import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
import androidx.media3.exoplayer.trackselection.RandomTrackSelection;
import androidx.media3.exoplayer.trackselection.TrackSelectionUtil;
import androidx.media3.exoplayer.upstream.BandwidthMeter;
import java.util.List;
import java.util.Random;
/* loaded from: classes2.dex */
public final class RandomTrackSelection extends BaseTrackSelection {
private final Random random;
private int selectedIndex;
@Override // androidx.media3.exoplayer.trackselection.ExoTrackSelection
public int getSelectedIndex() {
return this.selectedIndex;
}
@Override // androidx.media3.exoplayer.trackselection.ExoTrackSelection
public Object getSelectionData() {
return null;
}
@Override // androidx.media3.exoplayer.trackselection.ExoTrackSelection
public int getSelectionReason() {
return 3;
}
/* loaded from: classes2.dex */
public static final class Factory implements ExoTrackSelection.Factory {
private final Random random;
public Factory() {
this.random = new Random();
}
public Factory(int i) {
this.random = new Random(i);
}
@Override // androidx.media3.exoplayer.trackselection.ExoTrackSelection.Factory
public ExoTrackSelection[] createTrackSelections(ExoTrackSelection.Definition[] definitionArr, BandwidthMeter bandwidthMeter, MediaSource.MediaPeriodId mediaPeriodId, Timeline timeline) {
return TrackSelectionUtil.createTrackSelectionsForDefinitions(definitionArr, new TrackSelectionUtil.AdaptiveTrackSelectionFactory() { // from class: androidx.media3.exoplayer.trackselection.RandomTrackSelection$Factory$$ExternalSyntheticLambda0
@Override // androidx.media3.exoplayer.trackselection.TrackSelectionUtil.AdaptiveTrackSelectionFactory
public final ExoTrackSelection createAdaptiveTrackSelection(ExoTrackSelection.Definition definition) {
return RandomTrackSelection.Factory.this.m5276xa167648d(definition);
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$createTrackSelections$0$androidx-media3-exoplayer-trackselection-RandomTrackSelection$Factory, reason: not valid java name */
public /* synthetic */ ExoTrackSelection m5276xa167648d(ExoTrackSelection.Definition definition) {
return new RandomTrackSelection(definition.group, definition.tracks, definition.type, this.random);
}
}
public RandomTrackSelection(TrackGroup trackGroup, int[] iArr, int i, Random random) {
super(trackGroup, iArr, i);
this.random = random;
this.selectedIndex = random.nextInt(this.length);
}
@Override // androidx.media3.exoplayer.trackselection.ExoTrackSelection
public void updateSelectedTrack(long j, long j2, long j3, List<? extends MediaChunk> list, MediaChunkIterator[] mediaChunkIteratorArr) {
long elapsedRealtime = SystemClock.elapsedRealtime();
int i = 0;
for (int i2 = 0; i2 < this.length; i2++) {
if (!isTrackExcluded(i2, elapsedRealtime)) {
i++;
}
}
this.selectedIndex = this.random.nextInt(i);
if (i != this.length) {
int i3 = 0;
for (int i4 = 0; i4 < this.length; i4++) {
if (!isTrackExcluded(i4, elapsedRealtime)) {
int i5 = i3 + 1;
if (this.selectedIndex == i3) {
this.selectedIndex = i4;
return;
}
i3 = i5;
}
}
}
}
}