Commit a3ee684e by olly Committed by Oliver Woodman

Further cleanup of updateSelectedTrack

- Return early if the selection is unchanged.
- Remove unnecessary variables.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158138187
parent c1bfab3c
...@@ -154,23 +154,24 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { ...@@ -154,23 +154,24 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
@Override @Override
public void updateSelectedTrack(long bufferedDurationUs) { public void updateSelectedTrack(long bufferedDurationUs) {
long nowMs = SystemClock.elapsedRealtime(); long nowMs = SystemClock.elapsedRealtime();
// Get the current and ideal selections. // Stash the current selection, then make a new one.
int currentSelectedIndex = selectedIndex; int currentSelectedIndex = selectedIndex;
int idealSelectedIndex = determineIdealSelectedIndex(nowMs); selectedIndex = determineIdealSelectedIndex(nowMs);
// Assume we can switch to the ideal selection. if (selectedIndex == currentSelectedIndex) {
selectedIndex = idealSelectedIndex; return;
// Revert back to the current selection if conditions are not suitable for switching. }
if (!isBlacklisted(currentSelectedIndex, nowMs)) { if (!isBlacklisted(currentSelectedIndex, nowMs)) {
// Revert back to the current selection if conditions are not suitable for switching.
Format currentFormat = getFormat(currentSelectedIndex); Format currentFormat = getFormat(currentSelectedIndex);
Format idealFormat = getFormat(idealSelectedIndex); Format selectedFormat = getFormat(selectedIndex);
if (idealFormat.bitrate > currentFormat.bitrate if (selectedFormat.bitrate > currentFormat.bitrate
&& bufferedDurationUs < minDurationForQualityIncreaseUs) { && bufferedDurationUs < minDurationForQualityIncreaseUs) {
// The ideal track is a higher quality, but we have insufficient buffer to safely switch // The selected track is a higher quality, but we have insufficient buffer to safely switch
// up. Defer switching up for now. // up. Defer switching up for now.
selectedIndex = currentSelectedIndex; selectedIndex = currentSelectedIndex;
} else if (idealFormat.bitrate < currentFormat.bitrate } else if (selectedFormat.bitrate < currentFormat.bitrate
&& bufferedDurationUs >= maxDurationForQualityDecreaseUs) { && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
// The ideal track is a lower quality, but we have sufficient buffer to defer switching // The selected track is a lower quality, but we have sufficient buffer to defer switching
// down for now. // down for now.
selectedIndex = currentSelectedIndex; selectedIndex = currentSelectedIndex;
} }
......
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