Commit 3bd59f8c by tonihei Committed by marcbaechinger

Ensure minDurationToRetainAfterDiscard >= minDurationForQualityIncrease

If this condition isn't true, the player may enter a cycle of discarding
and reloading the same format. As minDurationToRetainAfterDiscard is a
parameter likely left at its default, and minDurationForQualityIncrease
is likely adjusted more often, we correct the value in the problematic
case and log a warning instead of asserting it outright to prevent
unnecessary app breakages.

Issue: #8807
PiperOrigin-RevId: 368207417
parent cc26a92e
......@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
......@@ -42,6 +43,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
*/
public class AdaptiveTrackSelection extends BaseTrackSelection {
private static final String TAG = "AdaptiveTrackSelection";
/** Factory for {@link AdaptiveTrackSelection} instances. */
public static class Factory implements ExoTrackSelection.Factory {
......@@ -73,7 +76,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
* quality, the selection may indicate that media already buffered at the lower quality can
* be discarded to speed up the switch. This is the minimum duration of media that must be
* retained at the lower quality.
* retained at the lower quality. It must be at least {@code
* minDurationForQualityIncreaseMs}.
* @param bandwidthFraction The fraction of the available bandwidth that the selection should
* consider available for use. Setting to a value less than 1 is recommended to account for
* inaccuracies in the bandwidth estimator.
......@@ -102,7 +106,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
* quality, the selection may indicate that media already buffered at the lower quality can
* be discarded to speed up the switch. This is the minimum duration of media that must be
* retained at the lower quality.
* retained at the lower quality. It must be at least {@code
* minDurationForQualityIncreaseMs}.
* @param bandwidthFraction The fraction of the available bandwidth that the selection should
* consider available for use. Setting to a value less than 1 is recommended to account for
* inaccuracies in the bandwidth estimator.
......@@ -249,7 +254,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
* quality, the selection may indicate that media already buffered at the lower quality can be
* discarded to speed up the switch. This is the minimum duration of media that must be
* retained at the lower quality.
* retained at the lower quality. It must be at least {@code minDurationForQualityIncreaseMs}.
* @param bandwidthFraction The fraction of the available bandwidth that the selection should
* consider available for use. Setting to a value less than 1 is recommended to account for
* inaccuracies in the bandwidth estimator.
......@@ -276,6 +281,13 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
List<AdaptationCheckpoint> adaptationCheckpoints,
Clock clock) {
super(group, tracks, type);
if (minDurationToRetainAfterDiscardMs < minDurationForQualityIncreaseMs) {
Log.w(
TAG,
"Adjusting minDurationToRetainAfterDiscardMs to be at least"
+ " minDurationForQualityIncreaseMs");
minDurationToRetainAfterDiscardMs = minDurationForQualityIncreaseMs;
}
this.bandwidthMeter = bandwidthMeter;
this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment