Commit 5debf5a1 by olly Committed by Oliver Woodman

Use bitrate as fixed track selection tie breaker

If we don't have resolutions (and therefore cannot determine
pixel counts) then use bitrate as a tie breaker instead. Also
use pixel count as a tie breaker if pixel counts are known
but equal. Streams with known pixel counts will always be
preferred over streams without.

Issue: #2343

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145269968
parent 9ac0add4
...@@ -560,6 +560,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -560,6 +560,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
TrackGroup selectedGroup = null; TrackGroup selectedGroup = null;
int selectedTrackIndex = 0; int selectedTrackIndex = 0;
int selectedTrackScore = 0; int selectedTrackScore = 0;
int selectedBitrate = Format.NO_VALUE;
int selectedPixelCount = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE;
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
TrackGroup trackGroup = groups.get(groupIndex); TrackGroup trackGroup = groups.get(groupIndex);
...@@ -582,16 +583,24 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -582,16 +583,24 @@ public class DefaultTrackSelector extends MappingTrackSelector {
} }
boolean selectTrack = trackScore > selectedTrackScore; boolean selectTrack = trackScore > selectedTrackScore;
if (trackScore == selectedTrackScore) { if (trackScore == selectedTrackScore) {
// Use the pixel count as a tie breaker. If we're within constraints prefer a higher // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If we're
// pixel count, else prefer a lower count. If still tied then prefer the first track // within constraints prefer a higher pixel count (or bitrate), else prefer a lower
// (i.e. the one that's already selected). // count (or bitrate). If still tied then prefer the first track (i.e. the one that's
int pixelComparison = comparePixelCounts(format.getPixelCount(), selectedPixelCount); // already selected).
selectTrack = isWithinConstraints ? pixelComparison > 0 : pixelComparison < 0; int comparisonResult;
int formatPixelCount = format.getPixelCount();
if (formatPixelCount != selectedPixelCount) {
comparisonResult = compareFormatValues(format.getPixelCount(), selectedPixelCount);
} else {
comparisonResult = compareFormatValues(format.bitrate, selectedBitrate);
}
selectTrack = isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0;
} }
if (selectTrack) { if (selectTrack) {
selectedGroup = trackGroup; selectedGroup = trackGroup;
selectedTrackIndex = trackIndex; selectedTrackIndex = trackIndex;
selectedTrackScore = trackScore; selectedTrackScore = trackScore;
selectedBitrate = format.bitrate;
selectedPixelCount = format.getPixelCount(); selectedPixelCount = format.getPixelCount();
} }
} }
...@@ -602,20 +611,19 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -602,20 +611,19 @@ public class DefaultTrackSelector extends MappingTrackSelector {
} }
/** /**
* Compares two pixel counts for order. A known pixel count is considered greater than * Compares two format values for order. A known value is considered greater than
* {@link Format#NO_VALUE}. * {@link Format#NO_VALUE}.
* *
* @param first The first pixel count. * @param first The first value.
* @param second The second pixel count. * @param second The second value.
* @return A negative integer if the first pixel count is less than the second. Zero if they are * @return A negative integer if the first value is less than the second. Zero if they are equal.
* equal. A positive integer if the first pixel count is greater than the second. * A positive integer if the first value is greater than the second.
*/ */
private static int comparePixelCounts(int first, int second) { private static int compareFormatValues(int first, int second) {
return first == Format.NO_VALUE ? (second == Format.NO_VALUE ? 0 : -1) return first == Format.NO_VALUE ? (second == Format.NO_VALUE ? 0 : -1)
: (second == Format.NO_VALUE ? 1 : (first - second)); : (second == Format.NO_VALUE ? 1 : (first - second));
} }
// Audio track selection implementation. // Audio track selection implementation.
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport, protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
......
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