- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
186 lines
8.8 KiB
Java
186 lines
8.8 KiB
Java
package com.mbridge.msdk.playercommon.exoplayer2.trackselection;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.work.WorkRequest;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.C;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.Format;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.source.TrackGroup;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.source.chunk.MediaChunk;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.upstream.BandwidthMeter;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Clock;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|
public static final float DEFAULT_BANDWIDTH_FRACTION = 0.75f;
|
|
public static final float DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE = 0.75f;
|
|
public static final int DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS = 25000;
|
|
public static final int DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS = 10000;
|
|
public static final int DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS = 25000;
|
|
public static final long DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS = 2000;
|
|
private final float bandwidthFraction;
|
|
private final BandwidthMeter bandwidthMeter;
|
|
private final float bufferedFractionToLiveEdgeForQualityIncrease;
|
|
private final Clock clock;
|
|
private long lastBufferEvaluationMs;
|
|
private final long maxDurationForQualityDecreaseUs;
|
|
private final long minDurationForQualityIncreaseUs;
|
|
private final long minDurationToRetainAfterDiscardUs;
|
|
private final long minTimeBetweenBufferReevaluationMs;
|
|
private float playbackSpeed;
|
|
private int reason;
|
|
private int selectedIndex;
|
|
|
|
private long minDurationForQualityIncreaseUs(long j) {
|
|
return (j == C.TIME_UNSET || j > this.minDurationForQualityIncreaseUs) ? this.minDurationForQualityIncreaseUs : (long) (j * this.bufferedFractionToLiveEdgeForQualityIncrease);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.BaseTrackSelection, com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public void enable() {
|
|
this.lastBufferEvaluationMs = C.TIME_UNSET;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public int getSelectedIndex() {
|
|
return this.selectedIndex;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
@Nullable
|
|
public Object getSelectionData() {
|
|
return null;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public int getSelectionReason() {
|
|
return this.reason;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.BaseTrackSelection, com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public void onPlaybackSpeed(float f) {
|
|
this.playbackSpeed = f;
|
|
}
|
|
|
|
public static final class Factory implements TrackSelection.Factory {
|
|
private final float bandwidthFraction;
|
|
private final BandwidthMeter bandwidthMeter;
|
|
private final float bufferedFractionToLiveEdgeForQualityIncrease;
|
|
private final Clock clock;
|
|
private final int maxDurationForQualityDecreaseMs;
|
|
private final int minDurationForQualityIncreaseMs;
|
|
private final int minDurationToRetainAfterDiscardMs;
|
|
private final long minTimeBetweenBufferReevaluationMs;
|
|
|
|
public Factory(BandwidthMeter bandwidthMeter) {
|
|
this(bandwidthMeter, 10000, 25000, 25000, 0.75f, 0.75f, 2000L, Clock.DEFAULT);
|
|
}
|
|
|
|
public Factory(BandwidthMeter bandwidthMeter, int i, int i2, int i3, float f) {
|
|
this(bandwidthMeter, i, i2, i3, f, 0.75f, 2000L, Clock.DEFAULT);
|
|
}
|
|
|
|
public Factory(BandwidthMeter bandwidthMeter, int i, int i2, int i3, float f, float f2, long j, Clock clock) {
|
|
this.bandwidthMeter = bandwidthMeter;
|
|
this.minDurationForQualityIncreaseMs = i;
|
|
this.maxDurationForQualityDecreaseMs = i2;
|
|
this.minDurationToRetainAfterDiscardMs = i3;
|
|
this.bandwidthFraction = f;
|
|
this.bufferedFractionToLiveEdgeForQualityIncrease = f2;
|
|
this.minTimeBetweenBufferReevaluationMs = j;
|
|
this.clock = clock;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection.Factory
|
|
public final AdaptiveTrackSelection createTrackSelection(TrackGroup trackGroup, int... iArr) {
|
|
return new AdaptiveTrackSelection(trackGroup, iArr, this.bandwidthMeter, this.minDurationForQualityIncreaseMs, this.maxDurationForQualityDecreaseMs, this.minDurationToRetainAfterDiscardMs, this.bandwidthFraction, this.bufferedFractionToLiveEdgeForQualityIncrease, this.minTimeBetweenBufferReevaluationMs, this.clock);
|
|
}
|
|
}
|
|
|
|
public AdaptiveTrackSelection(TrackGroup trackGroup, int[] iArr, BandwidthMeter bandwidthMeter) {
|
|
this(trackGroup, iArr, bandwidthMeter, WorkRequest.MIN_BACKOFF_MILLIS, 25000L, 25000L, 0.75f, 0.75f, 2000L, Clock.DEFAULT);
|
|
}
|
|
|
|
public AdaptiveTrackSelection(TrackGroup trackGroup, int[] iArr, BandwidthMeter bandwidthMeter, long j, long j2, long j3, float f, float f2, long j4, Clock clock) {
|
|
super(trackGroup, iArr);
|
|
this.bandwidthMeter = bandwidthMeter;
|
|
this.minDurationForQualityIncreaseUs = j * 1000;
|
|
this.maxDurationForQualityDecreaseUs = j2 * 1000;
|
|
this.minDurationToRetainAfterDiscardUs = j3 * 1000;
|
|
this.bandwidthFraction = f;
|
|
this.bufferedFractionToLiveEdgeForQualityIncrease = f2;
|
|
this.minTimeBetweenBufferReevaluationMs = j4;
|
|
this.clock = clock;
|
|
this.playbackSpeed = 1.0f;
|
|
this.reason = 1;
|
|
this.lastBufferEvaluationMs = C.TIME_UNSET;
|
|
this.selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public void updateSelectedTrack(long j, long j2, long j3) {
|
|
long elapsedRealtime = this.clock.elapsedRealtime();
|
|
int i = this.selectedIndex;
|
|
int determineIdealSelectedIndex = determineIdealSelectedIndex(elapsedRealtime);
|
|
this.selectedIndex = determineIdealSelectedIndex;
|
|
if (determineIdealSelectedIndex == i) {
|
|
return;
|
|
}
|
|
if (!isBlacklisted(i, elapsedRealtime)) {
|
|
Format format = getFormat(i);
|
|
Format format2 = getFormat(this.selectedIndex);
|
|
if (format2.bitrate > format.bitrate && j2 < minDurationForQualityIncreaseUs(j3)) {
|
|
this.selectedIndex = i;
|
|
} else if (format2.bitrate < format.bitrate && j2 >= this.maxDurationForQualityDecreaseUs) {
|
|
this.selectedIndex = i;
|
|
}
|
|
}
|
|
if (this.selectedIndex != i) {
|
|
this.reason = 3;
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.trackselection.BaseTrackSelection, com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelection
|
|
public int evaluateQueueSize(long j, List<? extends MediaChunk> list) {
|
|
int i;
|
|
int i2;
|
|
long elapsedRealtime = this.clock.elapsedRealtime();
|
|
long j2 = this.lastBufferEvaluationMs;
|
|
if (j2 != C.TIME_UNSET && elapsedRealtime - j2 < this.minTimeBetweenBufferReevaluationMs) {
|
|
return list.size();
|
|
}
|
|
this.lastBufferEvaluationMs = elapsedRealtime;
|
|
if (list.isEmpty()) {
|
|
return 0;
|
|
}
|
|
int size = list.size();
|
|
if (Util.getPlayoutDurationForMediaDuration(list.get(size - 1).startTimeUs - j, this.playbackSpeed) < this.minDurationToRetainAfterDiscardUs) {
|
|
return size;
|
|
}
|
|
Format format = getFormat(determineIdealSelectedIndex(elapsedRealtime));
|
|
for (int i3 = 0; i3 < size; i3++) {
|
|
MediaChunk mediaChunk = list.get(i3);
|
|
Format format2 = mediaChunk.trackFormat;
|
|
if (Util.getPlayoutDurationForMediaDuration(mediaChunk.startTimeUs - j, this.playbackSpeed) >= this.minDurationToRetainAfterDiscardUs && format2.bitrate < format.bitrate && (i = format2.height) != -1 && i < 720 && (i2 = format2.width) != -1 && i2 < 1280 && i < format.height) {
|
|
return i3;
|
|
}
|
|
}
|
|
return size;
|
|
}
|
|
|
|
private int determineIdealSelectedIndex(long j) {
|
|
long bitrateEstimate = (long) (this.bandwidthMeter.getBitrateEstimate() * this.bandwidthFraction);
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < this.length; i2++) {
|
|
if (j == Long.MIN_VALUE || !isBlacklisted(i2, j)) {
|
|
if (Math.round(getFormat(i2).bitrate * this.playbackSpeed) <= bitrateEstimate) {
|
|
return i2;
|
|
}
|
|
i = i2;
|
|
}
|
|
}
|
|
return i;
|
|
}
|
|
}
|