Commit d1084f27 by tonihei Committed by Toni

Do not compare bitrates of audio tracks with different languages.

The last selection criteria is the audio bitrate to prefer higher-quality
streams. We shouldn't apply this criterium though if the languages of the
tracks are different.

Issue:#6335
PiperOrigin-RevId: 265064756
parent 34cc5f4c
......@@ -44,6 +44,8 @@
* Support out-of-band HDR10+ metadata for VP9 in WebM/Matroska.
* Fix issue where HLS streams get stuck in infinite buffering state after
postroll ad ([#6314](https://github.com/google/ExoPlayer/issues/6314)).
* Fix audio selection issue where languages are compared by bit rate
([#6335](https://github.com/google/ExoPlayer/issues/6335)).
### 2.10.4 ###
......
......@@ -2548,6 +2548,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
*/
public final boolean isWithinConstraints;
@Nullable private final String language;
private final Parameters parameters;
private final boolean isWithinRendererCapabilities;
private final int preferredLanguageScore;
......@@ -2560,6 +2561,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
public AudioTrackScore(Format format, Parameters parameters, int formatSupport) {
this.parameters = parameters;
this.language = normalizeUndeterminedLanguageToNull(format.language);
isWithinRendererCapabilities = isSupported(formatSupport, false);
preferredLanguageScore =
getFormatLanguageScore(
......@@ -2633,7 +2635,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
if (this.sampleRate != other.sampleRate) {
return resultSign * compareInts(this.sampleRate, other.sampleRate);
}
return resultSign * compareInts(this.bitrate, other.bitrate);
if (Util.areEqual(this.language, other.language)) {
// Only compare bit rates of tracks with the same or unknown language.
return resultSign * compareInts(this.bitrate, other.bitrate);
}
return 0;
}
}
......
......@@ -717,37 +717,38 @@ public final class DefaultTrackSelectorTest {
}
/**
* Tests that track selector will select audio tracks with higher bit-rate when other factors are
* the same, and tracks are within renderer's capabilities.
* Tests that track selector will select audio tracks with higher bit rate when other factors are
* the same, and tracks are within renderer's capabilities, and have the same language.
*/
@Test
public void testSelectTracksWithinCapabilitiesSelectHigherBitrate() throws Exception {
public void selectAudioTracks_withinCapabilities_andSameLanguage_selectsHigherBitrate()
throws Exception {
Format lowerBitrateFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
null,
15000,
Format.NO_VALUE,
2,
44100,
null,
null,
0,
null);
/* codecs= */ null,
/* bitrate= */ 15000,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ "hi");
Format higherBitrateFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
null,
30000,
Format.NO_VALUE,
2,
44100,
null,
null,
0,
null);
/* codecs= */ null,
/* bitrate= */ 30000,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ "hi");
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
TrackSelectorResult result =
......@@ -760,13 +761,57 @@ public final class DefaultTrackSelectorTest {
}
/**
* Tests that track selector will select the first audio track even if other tracks with a
* different language have higher bit rates, all other factors are the same, and tracks are within
* renderer's capabilities.
*/
@Test
public void selectAudioTracks_withinCapabilities_andDifferentLanguage_selectsFirstTrack()
throws Exception {
Format firstLanguageFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
/* codecs= */ null,
/* bitrate= */ 15000,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ "hi");
Format higherBitrateFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
/* codecs= */ null,
/* bitrate= */ 30000,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ "te");
TrackGroupArray trackGroups = wrapFormats(firstLanguageFormat, higherBitrateFormat);
TrackSelectorResult result =
trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
trackGroups,
periodId,
TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, firstLanguageFormat);
}
/**
* Tests that track selector will prefer audio tracks with higher channel count over tracks with
* higher sample rate when other factors are the same, and tracks are within renderer's
* capabilities.
*/
@Test
public void testSelectTracksPreferHigherNumChannelBeforeSampleRate()
throws Exception {
public void testSelectTracksPreferHigherNumChannelBeforeSampleRate() throws Exception {
Format higherChannelLowerSampleRateFormat =
Format.createAudioSampleFormat(
"audioFormat",
......
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