Fix application of maxAudioBitrate for adaptive audio track groups

Issue:#6006
PiperOrigin-RevId: 253781533
This commit is contained in:
aquilescanta 2019-06-18 14:59:11 +01:00 committed by Oliver Woodman
parent b89dc8fbfd
commit 5aeaa6e8bf
3 changed files with 84 additions and 2 deletions

View file

@ -23,6 +23,8 @@
([#6036](https://github.com/google/ExoPlayer/pull/6036)).
* Gracefully handle revoked `ACCESS_NETWORK_STATE` permission
([#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 ###

View file

@ -1934,6 +1934,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
getAdaptiveAudioTracks(
selectedGroup,
formatSupports[selectedGroupIndex],
params.maxAudioBitrate,
params.allowAudioMixedMimeTypeAdaptiveness,
params.allowAudioMixedSampleRateAdaptiveness);
if (adaptiveTracks.length > 0) {
@ -1951,6 +1952,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private static int[] getAdaptiveAudioTracks(
TrackGroup group,
int[] formatSupport,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) {
int selectedConfigurationTrackCount = 0;
@ -1967,6 +1969,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
group,
formatSupport,
configuration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness);
if (configurationCount > selectedConfigurationTrackCount) {
@ -1977,13 +1980,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
}
if (selectedConfigurationTrackCount > 1) {
Assertions.checkNotNull(selectedConfiguration);
int[] adaptiveIndices = new int[selectedConfigurationTrackCount];
int index = 0;
for (int i = 0; i < group.length; i++) {
Format format = group.getFormat(i);
if (isSupportedAdaptiveAudioTrack(
group.getFormat(i),
format,
formatSupport[i],
Assertions.checkNotNull(selectedConfiguration),
selectedConfiguration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness)) {
adaptiveIndices[index++] = i;
@ -1998,6 +2004,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
TrackGroup group,
int[] formatSupport,
AudioConfigurationTuple configuration,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) {
int count = 0;
@ -2006,6 +2013,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
group.getFormat(i),
formatSupport[i],
configuration,
maxAudioBitrate,
allowMixedMimeTypeAdaptiveness,
allowMixedSampleRateAdaptiveness)) {
count++;
@ -2018,9 +2026,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
Format format,
int formatSupport,
AudioConfigurationTuple configuration,
int maxAudioBitrate,
boolean allowMixedMimeTypeAdaptiveness,
boolean allowMixedSampleRateAdaptiveness) {
return isSupported(formatSupport, false)
&& (format.bitrate == Format.NO_VALUE || format.bitrate <= maxAudioBitrate)
&& (format.channelCount != Format.NO_VALUE
&& format.channelCount == configuration.channelCount)
&& (allowMixedMimeTypeAdaptiveness

View file

@ -341,6 +341,76 @@ public final class DefaultTrackSelectorTest {
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
* given by {@link Parameters}.