From 7c8ab133e9ffcaf464710ba813639f5b0919b053 Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 12 Mar 2021 17:41:01 +0000 Subject: [PATCH] Move playback speed adjustment of available bandwidth. 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 --- .../trackselection/AdaptiveTrackSelection.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java index b7ae416428..2358746d65 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java @@ -422,14 +422,12 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { * @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; } /** @@ -468,7 +466,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { 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; @@ -487,7 +485,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { } private long getAllocatedBandwidth() { - long totalBandwidth = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction); + long totalBandwidth = + (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction / playbackSpeed); if (adaptationCheckpoints.isEmpty()) { return totalBandwidth; }