Commit 46bf710c by tonihei Committed by Oliver Woodman

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 0085a7e7
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* Reset `DefaultBandwidthMeter` to initial values on network change. * Reset `DefaultBandwidthMeter` to initial values on network change.
* Increase maximum buffer size for video in `DefaultLoadControl` to ensure high * Increase maximum buffer size for video in `DefaultLoadControl` to ensure high
quality video can be loaded up to the full default buffer duration. quality video can be loaded up to the full default buffer duration.
* Fix audio selection issue where languages are compared by bit rate
([#6335](https://github.com/google/ExoPlayer/issues/6335)).
### 2.10.4 ### ### 2.10.4 ###
......
...@@ -2501,6 +2501,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -2501,6 +2501,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
public final boolean isWithinConstraints; public final boolean isWithinConstraints;
@Nullable private final String language;
private final Parameters parameters; private final Parameters parameters;
private final boolean isWithinRendererCapabilities; private final boolean isWithinRendererCapabilities;
private final int preferredLanguageScore; private final int preferredLanguageScore;
...@@ -2513,6 +2514,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -2513,6 +2514,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
public AudioTrackScore(Format format, Parameters parameters, int formatSupport) { public AudioTrackScore(Format format, Parameters parameters, int formatSupport) {
this.parameters = parameters; this.parameters = parameters;
this.language = normalizeUndeterminedLanguageToNull(format.language);
isWithinRendererCapabilities = isSupported(formatSupport, false); isWithinRendererCapabilities = isSupported(formatSupport, false);
preferredLanguageScore = getFormatLanguageScore(format, parameters.preferredAudioLanguage); preferredLanguageScore = getFormatLanguageScore(format, parameters.preferredAudioLanguage);
isDefaultSelectionFlag = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0; isDefaultSelectionFlag = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
...@@ -2580,7 +2582,11 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -2580,7 +2582,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
if (this.sampleRate != other.sampleRate) { if (this.sampleRate != other.sampleRate) {
return resultSign * compareInts(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;
} }
} }
......
...@@ -719,37 +719,38 @@ public final class DefaultTrackSelectorTest { ...@@ -719,37 +719,38 @@ public final class DefaultTrackSelectorTest {
} }
/** /**
* Tests that track selector will select audio tracks with higher bit-rate when other factors are * 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. * the same, and tracks are within renderer's capabilities, and have the same language.
*/ */
@Test @Test
public void testSelectTracksWithinCapabilitiesSelectHigherBitrate() throws Exception { public void selectAudioTracks_withinCapabilities_andSameLanguage_selectsHigherBitrate()
throws Exception {
Format lowerBitrateFormat = Format lowerBitrateFormat =
Format.createAudioSampleFormat( Format.createAudioSampleFormat(
"audioFormat", "audioFormat",
MimeTypes.AUDIO_AAC, MimeTypes.AUDIO_AAC,
null, /* codecs= */ null,
15000, /* bitrate= */ 15000,
Format.NO_VALUE, /* maxInputSize= */ Format.NO_VALUE,
2, /* channelCount= */ 2,
44100, /* sampleRate= */ 44100,
null, /* initializationData= */ null,
null, /* drmInitData= */ null,
0, /* selectionFlags= */ 0,
null); /* language= */ "hi");
Format higherBitrateFormat = Format higherBitrateFormat =
Format.createAudioSampleFormat( Format.createAudioSampleFormat(
"audioFormat", "audioFormat",
MimeTypes.AUDIO_AAC, MimeTypes.AUDIO_AAC,
null, /* codecs= */ null,
30000, /* bitrate= */ 30000,
Format.NO_VALUE, /* maxInputSize= */ Format.NO_VALUE,
2, /* channelCount= */ 2,
44100, /* sampleRate= */ 44100,
null, /* initializationData= */ null,
null, /* drmInitData= */ null,
0, /* selectionFlags= */ 0,
null); /* language= */ "hi");
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat); TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
TrackSelectorResult result = TrackSelectorResult result =
...@@ -762,13 +763,57 @@ public final class DefaultTrackSelectorTest { ...@@ -762,13 +763,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 * 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 * higher sample rate when other factors are the same, and tracks are within renderer's
* capabilities. * capabilities.
*/ */
@Test @Test
public void testSelectTracksPreferHigherNumChannelBeforeSampleRate() public void testSelectTracksPreferHigherNumChannelBeforeSampleRate() throws Exception {
throws Exception {
Format higherChannelLowerSampleRateFormat = Format higherChannelLowerSampleRateFormat =
Format.createAudioSampleFormat( Format.createAudioSampleFormat(
"audioFormat", "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