mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove initial bitrate estimate from AdaptiveTrackSelection.
This value can now be set in the DefaultBandwidthMeter instead. As a result NO_VALUE can be removed from BandwidthMeter as we now always provide an estimate. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187865341
This commit is contained in:
parent
c3d6731188
commit
6e5ae87cae
5 changed files with 46 additions and 85 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
### dev-v2 (not yet released) ###
|
### dev-v2 (not yet released) ###
|
||||||
|
|
||||||
|
* Moved initial bitrate estimate from `AdaptiveTrackSelection` to
|
||||||
|
`DefaultBandwidthMeter`.
|
||||||
* UI components:
|
* UI components:
|
||||||
* Add support for listening to `AspectRatioFrameLayout`'s aspect ratio update
|
* Add support for listening to `AspectRatioFrameLayout`'s aspect ratio update
|
||||||
([#3736](https://github.com/google/ExoPlayer/issues/3736)).
|
([#3736](https://github.com/google/ExoPlayer/issues/3736)).
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
public static final class Factory implements TrackSelection.Factory {
|
public static final class Factory implements TrackSelection.Factory {
|
||||||
|
|
||||||
private final BandwidthMeter bandwidthMeter;
|
private final BandwidthMeter bandwidthMeter;
|
||||||
private final int maxInitialBitrate;
|
|
||||||
private final int minDurationForQualityIncreaseMs;
|
private final int minDurationForQualityIncreaseMs;
|
||||||
private final int maxDurationForQualityDecreaseMs;
|
private final int maxDurationForQualityDecreaseMs;
|
||||||
private final int minDurationToRetainAfterDiscardMs;
|
private final int minDurationToRetainAfterDiscardMs;
|
||||||
|
|
@ -51,7 +50,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
public Factory(BandwidthMeter bandwidthMeter) {
|
public Factory(BandwidthMeter bandwidthMeter) {
|
||||||
this(
|
this(
|
||||||
bandwidthMeter,
|
bandwidthMeter,
|
||||||
DEFAULT_MAX_INITIAL_BITRATE,
|
|
||||||
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -63,26 +61,26 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
||||||
* @param maxInitialBitrate The maximum bitrate in bits per second that should be assumed
|
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
||||||
* when a bandwidth estimate is unavailable.
|
* selected track to switch to one of higher quality.
|
||||||
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for
|
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
||||||
* the selected track to switch to one of higher quality.
|
* selected track to switch to one of lower quality.
|
||||||
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for
|
|
||||||
* the selected track to switch to one of lower quality.
|
|
||||||
* @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
|
* @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
|
||||||
* quality, the selection may indicate that media already buffered at the lower quality can
|
* 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
|
* 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.
|
||||||
* @param bandwidthFraction The fraction of the available bandwidth that the selection should
|
* @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
|
* consider available for use. Setting to a value less than 1 is recommended to account for
|
||||||
* for inaccuracies in the bandwidth estimator.
|
* inaccuracies in the bandwidth estimator.
|
||||||
*/
|
*/
|
||||||
public Factory(BandwidthMeter bandwidthMeter, int maxInitialBitrate,
|
public Factory(
|
||||||
int minDurationForQualityIncreaseMs, int maxDurationForQualityDecreaseMs,
|
BandwidthMeter bandwidthMeter,
|
||||||
int minDurationToRetainAfterDiscardMs, float bandwidthFraction) {
|
int minDurationForQualityIncreaseMs,
|
||||||
|
int maxDurationForQualityDecreaseMs,
|
||||||
|
int minDurationToRetainAfterDiscardMs,
|
||||||
|
float bandwidthFraction) {
|
||||||
this(
|
this(
|
||||||
bandwidthMeter,
|
bandwidthMeter,
|
||||||
maxInitialBitrate,
|
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
minDurationToRetainAfterDiscardMs,
|
minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -93,9 +91,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
* @param bandwidthMeter Provides an estimate of the currently available bandwidth..
|
||||||
* @param maxInitialBitrate The maximum bitrate in bits per second that should be assumed when a
|
|
||||||
* bandwidth estimate is unavailable.
|
|
||||||
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
||||||
* selected track to switch to one of higher quality.
|
* selected track to switch to one of higher quality.
|
||||||
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
||||||
|
|
@ -121,7 +117,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
*/
|
*/
|
||||||
public Factory(
|
public Factory(
|
||||||
BandwidthMeter bandwidthMeter,
|
BandwidthMeter bandwidthMeter,
|
||||||
int maxInitialBitrate,
|
|
||||||
int minDurationForQualityIncreaseMs,
|
int minDurationForQualityIncreaseMs,
|
||||||
int maxDurationForQualityDecreaseMs,
|
int maxDurationForQualityDecreaseMs,
|
||||||
int minDurationToRetainAfterDiscardMs,
|
int minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -130,7 +125,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
long minTimeBetweenBufferReevaluationMs,
|
long minTimeBetweenBufferReevaluationMs,
|
||||||
Clock clock) {
|
Clock clock) {
|
||||||
this.bandwidthMeter = bandwidthMeter;
|
this.bandwidthMeter = bandwidthMeter;
|
||||||
this.maxInitialBitrate = maxInitialBitrate;
|
|
||||||
this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
|
this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
|
||||||
this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
|
this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
|
||||||
this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
|
this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
|
||||||
|
|
@ -147,7 +141,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
group,
|
group,
|
||||||
tracks,
|
tracks,
|
||||||
bandwidthMeter,
|
bandwidthMeter,
|
||||||
maxInitialBitrate,
|
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
minDurationToRetainAfterDiscardMs,
|
minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -156,10 +149,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
minTimeBetweenBufferReevaluationMs,
|
minTimeBetweenBufferReevaluationMs,
|
||||||
clock);
|
clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int DEFAULT_MAX_INITIAL_BITRATE = 800000;
|
|
||||||
public static final int DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS = 10000;
|
public static final int DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS = 10000;
|
||||||
public static final int DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS = 25000;
|
public static final int DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS = 25000;
|
||||||
public static final int DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS = 25000;
|
public static final int DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS = 25000;
|
||||||
|
|
@ -168,7 +159,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
public static final long DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS = 2000;
|
public static final long DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS = 2000;
|
||||||
|
|
||||||
private final BandwidthMeter bandwidthMeter;
|
private final BandwidthMeter bandwidthMeter;
|
||||||
private final int maxInitialBitrate;
|
|
||||||
private final long minDurationForQualityIncreaseUs;
|
private final long minDurationForQualityIncreaseUs;
|
||||||
private final long maxDurationForQualityDecreaseUs;
|
private final long maxDurationForQualityDecreaseUs;
|
||||||
private final long minDurationToRetainAfterDiscardUs;
|
private final long minDurationToRetainAfterDiscardUs;
|
||||||
|
|
@ -194,7 +184,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
group,
|
group,
|
||||||
tracks,
|
tracks,
|
||||||
bandwidthMeter,
|
bandwidthMeter,
|
||||||
DEFAULT_MAX_INITIAL_BITRATE,
|
|
||||||
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -209,8 +198,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
|
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
|
||||||
* empty. May be in any order.
|
* empty. May be in any order.
|
||||||
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
||||||
* @param maxInitialBitrate The maximum bitrate in bits per second that should be assumed when a
|
|
||||||
* bandwidth estimate is unavailable.
|
|
||||||
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
||||||
* selected track to switch to one of higher quality.
|
* selected track to switch to one of higher quality.
|
||||||
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
||||||
|
|
@ -237,7 +224,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
TrackGroup group,
|
TrackGroup group,
|
||||||
int[] tracks,
|
int[] tracks,
|
||||||
BandwidthMeter bandwidthMeter,
|
BandwidthMeter bandwidthMeter,
|
||||||
int maxInitialBitrate,
|
|
||||||
long minDurationForQualityIncreaseMs,
|
long minDurationForQualityIncreaseMs,
|
||||||
long maxDurationForQualityDecreaseMs,
|
long maxDurationForQualityDecreaseMs,
|
||||||
long minDurationToRetainAfterDiscardMs,
|
long minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -247,7 +233,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
Clock clock) {
|
Clock clock) {
|
||||||
super(group, tracks);
|
super(group, tracks);
|
||||||
this.bandwidthMeter = bandwidthMeter;
|
this.bandwidthMeter = bandwidthMeter;
|
||||||
this.maxInitialBitrate = maxInitialBitrate;
|
|
||||||
this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
|
this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
|
||||||
this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
|
this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
|
||||||
this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
|
this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
|
||||||
|
|
@ -369,9 +354,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
* Long#MIN_VALUE} to ignore blacklisting.
|
* Long#MIN_VALUE} to ignore blacklisting.
|
||||||
*/
|
*/
|
||||||
private int determineIdealSelectedIndex(long nowMs) {
|
private int determineIdealSelectedIndex(long nowMs) {
|
||||||
long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
|
long effectiveBitrate = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction);
|
||||||
long effectiveBitrate = bitrateEstimate == BandwidthMeter.NO_ESTIMATE
|
|
||||||
? maxInitialBitrate : (long) (bitrateEstimate * bandwidthFraction);
|
|
||||||
int lowestBitrateNonBlacklistedIndex = 0;
|
int lowestBitrateNonBlacklistedIndex = 0;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
|
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
|
||||||
|
|
@ -393,5 +376,4 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
? (long) (availableDurationUs * bufferedFractionToLiveEdgeForQualityIncrease)
|
? (long) (availableDurationUs * bufferedFractionToLiveEdgeForQualityIncrease)
|
||||||
: minDurationForQualityIncreaseUs;
|
: minDurationForQualityIncreaseUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,28 +27,17 @@ public interface BandwidthMeter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called periodically to indicate that bytes have been transferred.
|
* Called periodically to indicate that bytes have been transferred.
|
||||||
* <p>
|
*
|
||||||
* Note: The estimated bitrate is typically derived from more information than just
|
* <p>Note: The estimated bitrate is typically derived from more information than just {@code
|
||||||
* {@code bytes} and {@code elapsedMs}.
|
* bytes} and {@code elapsedMs}.
|
||||||
*
|
*
|
||||||
* @param elapsedMs The time taken to transfer the bytes, in milliseconds.
|
* @param elapsedMs The time taken to transfer the bytes, in milliseconds.
|
||||||
* @param bytes The number of bytes transferred.
|
* @param bytes The number of bytes transferred.
|
||||||
* @param bitrate The estimated bitrate in bits/sec, or {@link #NO_ESTIMATE} if an estimate is
|
* @param bitrate The estimated bitrate in bits/sec.
|
||||||
* not available.
|
|
||||||
*/
|
*/
|
||||||
void onBandwidthSample(int elapsedMs, long bytes, long bitrate);
|
void onBandwidthSample(int elapsedMs, long bytes, long bitrate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the estimated bandwidth in bits/sec. */
|
||||||
* Indicates no bandwidth estimate is available.
|
|
||||||
*/
|
|
||||||
long NO_ESTIMATE = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the estimated bandwidth in bits/sec, or {@link #NO_ESTIMATE} if an estimate is not
|
|
||||||
* available.
|
|
||||||
*/
|
|
||||||
long getBitrateEstimate();
|
long getBitrateEstimate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import com.google.android.exoplayer2.util.SlidingPercentile;
|
||||||
public final class DefaultBandwidthMeter implements BandwidthMeter, TransferListener<Object> {
|
public final class DefaultBandwidthMeter implements BandwidthMeter, TransferListener<Object> {
|
||||||
|
|
||||||
/** Default initial bitrate estimate in bits per second. */
|
/** Default initial bitrate estimate in bits per second. */
|
||||||
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE = BandwidthMeter.NO_ESTIMATE;
|
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE = 1_000_000;
|
||||||
|
|
||||||
/** Default maximum weight for the sliding window. */
|
/** Default maximum weight for the sliding window. */
|
||||||
public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000;
|
public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000;
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
fakeClock = new FakeClock(0);
|
fakeClock = new FakeClock(0);
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(BandwidthMeter.NO_ESTIMATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -62,7 +61,8 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup, /* initialBitrate= */ 1000);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
|
||||||
|
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup);
|
||||||
|
|
||||||
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
|
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
|
||||||
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
|
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
|
||||||
|
|
@ -76,8 +76,7 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
|
||||||
|
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup);
|
||||||
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup, /* initialBitrate= */ 1000);
|
|
||||||
|
|
||||||
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
|
assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
|
||||||
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
|
assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
|
||||||
|
|
@ -90,13 +89,12 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
// initially bandwidth meter does not have any estimation. The second measurement onward returns
|
// The second measurement onward returns 2000L, which prompts the track selection to switch up
|
||||||
// 2000L, which prompts the track selection to switch up if possible.
|
// if possible.
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(BandwidthMeter.NO_ESTIMATE, 2000L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 2000L);
|
||||||
|
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
||||||
trackGroup, /* initialBitrate= */ 1000, /* minDurationForQualityIncreaseMs= */ 10_000);
|
trackGroup, /* minDurationForQualityIncreaseMs= */ 10_000);
|
||||||
|
|
||||||
adaptiveTrackSelection.updateSelectedTrack(
|
adaptiveTrackSelection.updateSelectedTrack(
|
||||||
/* playbackPositionUs= */ 0,
|
/* playbackPositionUs= */ 0,
|
||||||
|
|
@ -117,13 +115,12 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
// initially bandwidth meter does not have any estimation. The second measurement onward returns
|
// The second measurement onward returns 2000L, which prompts the track selection to switch up
|
||||||
// 2000L, which prompts the track selection to switch up if possible.
|
// if possible.
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(BandwidthMeter.NO_ESTIMATE, 2000L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 2000L);
|
||||||
|
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
||||||
trackGroup, /* initialBitrate= */ 1000, /* minDurationForQualityIncreaseMs= */ 10_000);
|
trackGroup, /* minDurationForQualityIncreaseMs= */ 10_000);
|
||||||
|
|
||||||
adaptiveTrackSelection.updateSelectedTrack(
|
adaptiveTrackSelection.updateSelectedTrack(
|
||||||
/* playbackPositionUs= */ 0,
|
/* playbackPositionUs= */ 0,
|
||||||
|
|
@ -144,13 +141,12 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
// initially bandwidth meter does not have any estimation. The second measurement onward returns
|
// The second measurement onward returns 500L, which prompts the track selection to switch down
|
||||||
// 500L, which prompts the track selection to switch down if necessary.
|
// if necessary.
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(BandwidthMeter.NO_ESTIMATE, 500L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 500L);
|
||||||
|
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
||||||
trackGroup, /* initialBitrate= */ 1000, /* maxDurationForQualityDecreaseMs= */ 25_000);
|
trackGroup, /* maxDurationForQualityDecreaseMs= */ 25_000);
|
||||||
|
|
||||||
adaptiveTrackSelection.updateSelectedTrack(
|
adaptiveTrackSelection.updateSelectedTrack(
|
||||||
/* playbackPositionUs= */ 0,
|
/* playbackPositionUs= */ 0,
|
||||||
|
|
@ -171,13 +167,12 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
Format format3 = videoFormat(/* bitrate= */ 2000, /* width= */ 960, /* height= */ 720);
|
||||||
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
|
||||||
|
|
||||||
// initially bandwidth meter does not have any estimation. The second measurement onward returns
|
// The second measurement onward returns 500L, which prompts the track selection to switch down
|
||||||
// 500L, which prompts the track selection to switch down if necessary.
|
// if necessary.
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(BandwidthMeter.NO_ESTIMATE, 500L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 500L);
|
||||||
|
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
||||||
trackGroup, /* initialBitrate= */ 1000, /* maxDurationForQualityDecreaseMs= */ 25_000);
|
trackGroup, /* maxDurationForQualityDecreaseMs= */ 25_000);
|
||||||
|
|
||||||
adaptiveTrackSelection.updateSelectedTrack(
|
adaptiveTrackSelection.updateSelectedTrack(
|
||||||
/* playbackPositionUs= */ 0,
|
/* playbackPositionUs= */ 0,
|
||||||
|
|
@ -210,7 +205,7 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
queue.add(chunk3);
|
queue.add(chunk3);
|
||||||
|
|
||||||
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
|
when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
|
||||||
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup, /* initialBitrate= */ 1000);
|
adaptiveTrackSelection = adaptiveTrackSelection(trackGroup);
|
||||||
|
|
||||||
int size = adaptiveTrackSelection.evaluateQueueSize(0, queue);
|
int size = adaptiveTrackSelection.evaluateQueueSize(0, queue);
|
||||||
assertThat(size).isEqualTo(3);
|
assertThat(size).isEqualTo(3);
|
||||||
|
|
@ -238,7 +233,6 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
/* initialBitrate= */ 1000,
|
|
||||||
/* durationToRetainAfterDiscardMs= */ 15_000,
|
/* durationToRetainAfterDiscardMs= */ 15_000,
|
||||||
/* minTimeBetweenBufferReevaluationMs= */ 2000);
|
/* minTimeBetweenBufferReevaluationMs= */ 2000);
|
||||||
|
|
||||||
|
|
@ -276,7 +270,6 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
adaptiveTrackSelection =
|
adaptiveTrackSelection =
|
||||||
adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
/* initialBitrate= */ 1000,
|
|
||||||
/* durationToRetainAfterDiscardMs= */ 15_000,
|
/* durationToRetainAfterDiscardMs= */ 15_000,
|
||||||
/* minTimeBetweenBufferReevaluationMs= */ 2000);
|
/* minTimeBetweenBufferReevaluationMs= */ 2000);
|
||||||
|
|
||||||
|
|
@ -294,12 +287,11 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
assertThat(newSize).isEqualTo(2);
|
assertThat(newSize).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdaptiveTrackSelection adaptiveTrackSelection(TrackGroup trackGroup, int initialBitrate) {
|
private AdaptiveTrackSelection adaptiveTrackSelection(TrackGroup trackGroup) {
|
||||||
return new AdaptiveTrackSelection(
|
return new AdaptiveTrackSelection(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
initialBitrate,
|
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -310,12 +302,11 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdaptiveTrackSelection adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
private AdaptiveTrackSelection adaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(
|
||||||
TrackGroup trackGroup, int initialBitrate, long minDurationForQualityIncreaseMs) {
|
TrackGroup trackGroup, long minDurationForQualityIncreaseMs) {
|
||||||
return new AdaptiveTrackSelection(
|
return new AdaptiveTrackSelection(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
initialBitrate,
|
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -326,12 +317,11 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdaptiveTrackSelection adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
private AdaptiveTrackSelection adaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(
|
||||||
TrackGroup trackGroup, int initialBitrate, long maxDurationForQualityDecreaseMs) {
|
TrackGroup trackGroup, long maxDurationForQualityDecreaseMs) {
|
||||||
return new AdaptiveTrackSelection(
|
return new AdaptiveTrackSelection(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
initialBitrate,
|
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -343,18 +333,16 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
|
|
||||||
private AdaptiveTrackSelection adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
private AdaptiveTrackSelection adaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(
|
||||||
TrackGroup trackGroup,
|
TrackGroup trackGroup,
|
||||||
int initialBitrate,
|
|
||||||
long durationToRetainAfterDiscardMs,
|
long durationToRetainAfterDiscardMs,
|
||||||
long minTimeBetweenBufferReevaluationMs) {
|
long minTimeBetweenBufferReevaluationMs) {
|
||||||
return new AdaptiveTrackSelection(
|
return new AdaptiveTrackSelection(
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
initialBitrate,
|
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
durationToRetainAfterDiscardMs,
|
durationToRetainAfterDiscardMs,
|
||||||
/* bandwidth fraction= */ 1.0f,
|
/* bandwidthFraction= */ 1.0f,
|
||||||
AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
|
AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
|
||||||
minTimeBetweenBufferReevaluationMs,
|
minTimeBetweenBufferReevaluationMs,
|
||||||
fakeClock);
|
fakeClock);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue