Skip to content

Commit

Permalink
Move playback speed adjustment of available bandwidth.
Browse files Browse the repository at this point in the history
When comparing stream bitrate with available (allocated) bandwidth,
we need to take the playback speed into account. In the current
calculation, this can happen on both sides of the equation, but we
take the time to first byte into account, we need to move the speed
into the available, allocated bandwidth.

This change moves the speed adjustment to the bandwidth calculation
side in AdaptiveTrackSelection.

PiperOrigin-RevId: 362540071
  • Loading branch information
tonihei authored and ojw28 committed Mar 15, 2021
1 parent e14180e commit 7c8ab13
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,12 @@ public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk>
* @param format The {@link Format} of the candidate track.
* @param trackBitrate The estimated bitrate of the track. May differ from {@link Format#bitrate}
* if a more accurate estimate of the current track bitrate is available.
* @param playbackSpeed The current factor by which playback is sped up.
* @param effectiveBitrate The bitrate available to this selection.
* @return Whether this {@link Format} can be selected.
*/
@SuppressWarnings("unused")
protected boolean canSelectFormat(
Format format, int trackBitrate, float playbackSpeed, long effectiveBitrate) {
return Math.round(trackBitrate * playbackSpeed) <= effectiveBitrate;
protected boolean canSelectFormat(Format format, int trackBitrate, long effectiveBitrate) {
return trackBitrate <= effectiveBitrate;
}

/**
Expand Down Expand Up @@ -468,7 +466,7 @@ private int determineIdealSelectedIndex(long nowMs) {
for (int i = 0; i < length; i++) {
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
Format format = getFormat(i);
if (canSelectFormat(format, format.bitrate, playbackSpeed, effectiveBitrate)) {
if (canSelectFormat(format, format.bitrate, effectiveBitrate)) {
return i;
} else {
lowestBitrateAllowedIndex = i;
Expand All @@ -487,7 +485,8 @@ private long minDurationForQualityIncreaseUs(long availableDurationUs) {
}

private long getAllocatedBandwidth() {
long totalBandwidth = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction);
long totalBandwidth =
(long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction / playbackSpeed);
if (adaptationCheckpoints.isEmpty()) {
return totalBandwidth;
}
Expand Down

0 comments on commit 7c8ab13

Please sign in to comment.