Commit 5aeaa6e8 by aquilescanta Committed by Oliver Woodman

Fix application of maxAudioBitrate for adaptive audio track groups

Issue:#6006
PiperOrigin-RevId: 253781533
parent b89dc8fb
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
([#6036](https://github.com/google/ExoPlayer/pull/6036)). ([#6036](https://github.com/google/ExoPlayer/pull/6036)).
* Gracefully handle revoked `ACCESS_NETWORK_STATE` permission * Gracefully handle revoked `ACCESS_NETWORK_STATE` permission
([#6019](https://github.com/google/ExoPlayer/issues/6019)). ([#6019](https://github.com/google/ExoPlayer/issues/6019)).
* Fix application of `maxAudioBitrate` for adaptive audio track groups
([#6006](https://github.com/google/ExoPlayer/issues/6006)).
### 2.10.2 ### ### 2.10.2 ###
......
...@@ -1934,6 +1934,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -1934,6 +1934,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
getAdaptiveAudioTracks( getAdaptiveAudioTracks(
selectedGroup, selectedGroup,
formatSupports[selectedGroupIndex], formatSupports[selectedGroupIndex],
params.maxAudioBitrate,
params.allowAudioMixedMimeTypeAdaptiveness, params.allowAudioMixedMimeTypeAdaptiveness,
params.allowAudioMixedSampleRateAdaptiveness); params.allowAudioMixedSampleRateAdaptiveness);
if (adaptiveTracks.length > 0) { if (adaptiveTracks.length > 0) {
...@@ -1951,6 +1952,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -1951,6 +1952,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private static int[] getAdaptiveAudioTracks( private static int[] getAdaptiveAudioTracks(
TrackGroup group, TrackGroup group,
int[] formatSupport, int[] formatSupport,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness, boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) { boolean allowMixedSampleRateAdaptiveness) {
int selectedConfigurationTrackCount = 0; int selectedConfigurationTrackCount = 0;
...@@ -1967,6 +1969,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -1967,6 +1969,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
group, group,
formatSupport, formatSupport,
configuration, configuration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness, allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness); allowMixedSampleRateAdaptiveness);
if (configurationCount > selectedConfigurationTrackCount) { if (configurationCount > selectedConfigurationTrackCount) {
...@@ -1977,13 +1980,16 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -1977,13 +1980,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
} }
if (selectedConfigurationTrackCount > 1) { if (selectedConfigurationTrackCount > 1) {
Assertions.checkNotNull(selectedConfiguration);
int[] adaptiveIndices = new int[selectedConfigurationTrackCount]; int[] adaptiveIndices = new int[selectedConfigurationTrackCount];
int index = 0; int index = 0;
for (int i = 0; i < group.length; i++) { for (int i = 0; i < group.length; i++) {
Format format = group.getFormat(i);
if (isSupportedAdaptiveAudioTrack( if (isSupportedAdaptiveAudioTrack(
group.getFormat(i), format,
formatSupport[i], formatSupport[i],
Assertions.checkNotNull(selectedConfiguration), selectedConfiguration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness, allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness)) { allowMixedSampleRateAdaptiveness)) {
adaptiveIndices[index++] = i; adaptiveIndices[index++] = i;
...@@ -1998,6 +2004,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -1998,6 +2004,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
TrackGroup group, TrackGroup group,
int[] formatSupport, int[] formatSupport,
AudioConfigurationTuple configuration, AudioConfigurationTuple configuration,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness, boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) { boolean allowMixedSampleRateAdaptiveness) {
int count = 0; int count = 0;
...@@ -2006,6 +2013,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -2006,6 +2013,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
group.getFormat(i), group.getFormat(i),
formatSupport[i], formatSupport[i],
configuration, configuration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness, allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness)) { allowMixedSampleRateAdaptiveness)) {
count++; count++;
...@@ -2018,9 +2026,11 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -2018,9 +2026,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
Format format, Format format,
int formatSupport, int formatSupport,
AudioConfigurationTuple configuration, AudioConfigurationTuple configuration,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness, boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) { boolean allowMixedSampleRateAdaptiveness) {
return isSupported(formatSupport, false) return isSupported(formatSupport, false)
&& (format.bitrate == Format.NO_VALUE || format.bitrate <= maxAudioBitrate)
&& (format.channelCount != Format.NO_VALUE && (format.channelCount != Format.NO_VALUE
&& format.channelCount == configuration.channelCount) && format.channelCount == configuration.channelCount)
&& (allowMixedMimeTypeAdaptiveness && (allowMixedMimeTypeAdaptiveness
......
...@@ -341,6 +341,76 @@ public final class DefaultTrackSelectorTest { ...@@ -341,6 +341,76 @@ public final class DefaultTrackSelectorTest {
assertFixedSelection(result.selections.get(0), trackGroups, formatWithSelectionFlag); assertFixedSelection(result.selections.get(0), trackGroups, formatWithSelectionFlag);
} }
/** Tests that adaptive audio track selections respect the maximum audio bitrate. */
public void testSelectAdaptiveAudioTrackGroupWithMaxBitrate() throws ExoPlaybackException {
Format format128k =
Format.createAudioSampleFormat(
/* id= */ "128",
/* sampleMimeType= */ MimeTypes.AUDIO_AAC,
/* codecs= */ "mp4a.40.2",
/* bitrate= */ 128 * 1024,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ null);
Format format192k =
Format.createAudioSampleFormat(
/* id= */ "192",
/* sampleMimeType= */ MimeTypes.AUDIO_AAC,
/* codecs= */ "mp4a.40.2",
/* bitrate= */ 192 * 1024,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ null);
Format format256k =
Format.createAudioSampleFormat(
/* id= */ "256",
/* sampleMimeType= */ MimeTypes.AUDIO_AAC,
/* codecs= */ "mp4a.40.2",
/* bitrate= */ 256 * 1024,
/* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2,
/* sampleRate= */ 44100,
/* initializationData= */ null,
/* drmInitData= */ null,
/* selectionFlags= */ 0,
/* language= */ null);
RendererCapabilities[] rendererCapabilities = {
ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES
};
TrackGroupArray trackGroups =
new TrackGroupArray(new TrackGroup(format192k, format128k, format256k));
TrackSelectorResult result =
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1, 2);
trackSelector.setParameters(
trackSelector.buildUponParameters().setMaxAudioBitrate(256 * 1024 - 1));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1);
trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1);
trackSelector.setParameters(
trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024 - 1));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1);
trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(10));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1);
}
/** /**
* Tests that track selector will select audio track with language that match preferred language * Tests that track selector will select audio track with language that match preferred language
* given by {@link Parameters}. * given by {@link Parameters}.
......
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