mirror of
https://github.com/androidx/media.git
synced 2025-05-05 06:30:24 +08:00
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
This commit is contained in:
parent
8241bb8a6e
commit
79048ffae6
@ -154,23 +154,24 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||
@Override
|
||||
public void updateSelectedTrack(long bufferedDurationUs) {
|
||||
long nowMs = SystemClock.elapsedRealtime();
|
||||
// Get the current and ideal selections.
|
||||
// Stash the current selection, then make a new one.
|
||||
int currentSelectedIndex = selectedIndex;
|
||||
int idealSelectedIndex = determineIdealSelectedIndex(nowMs);
|
||||
// Assume we can switch to the ideal selection.
|
||||
selectedIndex = idealSelectedIndex;
|
||||
// Revert back to the current selection if conditions are not suitable for switching.
|
||||
selectedIndex = determineIdealSelectedIndex(nowMs);
|
||||
if (selectedIndex == currentSelectedIndex) {
|
||||
return;
|
||||
}
|
||||
if (!isBlacklisted(currentSelectedIndex, nowMs)) {
|
||||
// Revert back to the current selection if conditions are not suitable for switching.
|
||||
Format currentFormat = getFormat(currentSelectedIndex);
|
||||
Format idealFormat = getFormat(idealSelectedIndex);
|
||||
if (idealFormat.bitrate > currentFormat.bitrate
|
||||
Format selectedFormat = getFormat(selectedIndex);
|
||||
if (selectedFormat.bitrate > currentFormat.bitrate
|
||||
&& 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.
|
||||
selectedIndex = currentSelectedIndex;
|
||||
} else if (idealFormat.bitrate < currentFormat.bitrate
|
||||
} else if (selectedFormat.bitrate < currentFormat.bitrate
|
||||
&& 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.
|
||||
selectedIndex = currentSelectedIndex;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user