mirror of
https://github.com/androidx/media.git
synced 2025-05-04 22:20:47 +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
|
@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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user