Commit 069e3cbf by olly Committed by Oliver Woodman

Clean up DefaultTrackSelectorTest

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=219139356
parent 03823843
...@@ -20,9 +20,6 @@ import static com.google.android.exoplayer2.RendererCapabilities.FORMAT_HANDLED; ...@@ -20,9 +20,6 @@ import static com.google.android.exoplayer2.RendererCapabilities.FORMAT_HANDLED;
import static com.google.android.exoplayer2.RendererCapabilities.FORMAT_UNSUPPORTED_SUBTYPE; import static com.google.android.exoplayer2.RendererCapabilities.FORMAT_UNSUPPORTED_SUBTYPE;
import static com.google.android.exoplayer2.RendererConfiguration.DEFAULT; import static com.google.android.exoplayer2.RendererConfiguration.DEFAULT;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyVararg;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -87,13 +84,13 @@ public final class DefaultTrackSelectorTest { ...@@ -87,13 +84,13 @@ public final class DefaultTrackSelectorTest {
private static final TrackGroup AUDIO_TRACK_GROUP = new TrackGroup(AUDIO_FORMAT); private static final TrackGroup AUDIO_TRACK_GROUP = new TrackGroup(AUDIO_FORMAT);
private static final TrackGroupArray TRACK_GROUPS = private static final TrackGroupArray TRACK_GROUPS =
new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP); new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
private static final TrackSelection[] TRACK_SELECTIONS = private static final TrackSelection[] TRACK_SELECTIONS =
new TrackSelection[] { new TrackSelection[] {
new FixedTrackSelection(VIDEO_TRACK_GROUP, 0), new FixedTrackSelection(AUDIO_TRACK_GROUP, 0) new FixedTrackSelection(VIDEO_TRACK_GROUP, 0), new FixedTrackSelection(AUDIO_TRACK_GROUP, 0)
}; };
private static final TrackSelection[] TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER = private static final TrackSelection[] TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER =
new TrackSelection[] {new FixedTrackSelection(VIDEO_TRACK_GROUP, 0), null}; new TrackSelection[] {new FixedTrackSelection(VIDEO_TRACK_GROUP, 0), null};
private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1); private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1);
private static MediaPeriodId periodId; private static MediaPeriodId periodId;
...@@ -186,15 +183,13 @@ public final class DefaultTrackSelectorTest { ...@@ -186,15 +183,13 @@ public final class DefaultTrackSelectorTest {
/** Tests that a null override clears a track selection. */ /** Tests that a null override clears a track selection. */
@Test @Test
public void testSelectTracksWithNullOverride() throws ExoPlaybackException { public void testSelectTracksWithNullOverride() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
.setSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP), null)); .setSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP), null));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE); trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, new TrackSelection[] {null, TRACK_SELECTIONS[1]}); assertSelections(result, new TrackSelection[] {null, TRACK_SELECTIONS[1]});
assertThat(result.rendererConfigurations) assertThat(result.rendererConfigurations)
.isEqualTo(new RendererConfiguration[] {null, DEFAULT}); .isEqualTo(new RendererConfiguration[] {null, DEFAULT});
} }
...@@ -202,8 +197,6 @@ public final class DefaultTrackSelectorTest { ...@@ -202,8 +197,6 @@ public final class DefaultTrackSelectorTest {
/** Tests that a null override can be cleared. */ /** Tests that a null override can be cleared. */
@Test @Test
public void testSelectTracksWithClearedNullOverride() throws ExoPlaybackException { public void testSelectTracksWithClearedNullOverride() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
...@@ -211,7 +204,7 @@ public final class DefaultTrackSelectorTest { ...@@ -211,7 +204,7 @@ public final class DefaultTrackSelectorTest {
.clearSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP))); .clearSelectionOverride(0, new TrackGroupArray(VIDEO_TRACK_GROUP)));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE); trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, TRACK_SELECTIONS); assertSelections(result, TRACK_SELECTIONS);
assertThat(result.rendererConfigurations) assertThat(result.rendererConfigurations)
.isEqualTo(new RendererConfiguration[] {DEFAULT, DEFAULT}); .isEqualTo(new RendererConfiguration[] {DEFAULT, DEFAULT});
} }
...@@ -219,8 +212,6 @@ public final class DefaultTrackSelectorTest { ...@@ -219,8 +212,6 @@ public final class DefaultTrackSelectorTest {
/** Tests that an override is not applied for a different set of available track groups. */ /** Tests that an override is not applied for a different set of available track groups. */
@Test @Test
public void testSelectTracksWithNullOverrideForDifferentTracks() throws ExoPlaybackException { public void testSelectTracksWithNullOverrideForDifferentTracks() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
...@@ -231,7 +222,7 @@ public final class DefaultTrackSelectorTest { ...@@ -231,7 +222,7 @@ public final class DefaultTrackSelectorTest {
new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP, VIDEO_TRACK_GROUP), new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP, VIDEO_TRACK_GROUP),
periodId, periodId,
TIMELINE); TIMELINE);
assertTrackSelections(result, TRACK_SELECTIONS); assertSelections(result, TRACK_SELECTIONS);
assertThat(result.rendererConfigurations) assertThat(result.rendererConfigurations)
.isEqualTo(new RendererConfiguration[] {DEFAULT, DEFAULT}); .isEqualTo(new RendererConfiguration[] {DEFAULT, DEFAULT});
} }
...@@ -239,12 +230,10 @@ public final class DefaultTrackSelectorTest { ...@@ -239,12 +230,10 @@ public final class DefaultTrackSelectorTest {
/** Tests disabling a renderer. */ /** Tests disabling a renderer. */
@Test @Test
public void testSelectTracksWithDisabledRenderer() throws ExoPlaybackException { public void testSelectTracksWithDisabledRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setRendererDisabled(1, true));
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE); trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, new TrackSelection[] {TRACK_SELECTIONS[0], null}); assertSelections(result, new TrackSelection[] {TRACK_SELECTIONS[0], null});
assertThat(new RendererConfiguration[] {DEFAULT, null}) assertThat(new RendererConfiguration[] {DEFAULT, null})
.isEqualTo(result.rendererConfigurations); .isEqualTo(result.rendererConfigurations);
} }
...@@ -252,8 +241,6 @@ public final class DefaultTrackSelectorTest { ...@@ -252,8 +241,6 @@ public final class DefaultTrackSelectorTest {
/** Tests that a disabled renderer can be enabled again. */ /** Tests that a disabled renderer can be enabled again. */
@Test @Test
public void testSelectTracksWithClearedDisabledRenderer() throws ExoPlaybackException { public void testSelectTracksWithClearedDisabledRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
...@@ -261,7 +248,7 @@ public final class DefaultTrackSelectorTest { ...@@ -261,7 +248,7 @@ public final class DefaultTrackSelectorTest {
.setRendererDisabled(1, false)); .setRendererDisabled(1, false));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE); trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, TRACK_SELECTIONS); assertSelections(result, TRACK_SELECTIONS);
assertThat(new RendererConfiguration[] {DEFAULT, DEFAULT}) assertThat(new RendererConfiguration[] {DEFAULT, DEFAULT})
.isEqualTo(result.rendererConfigurations); .isEqualTo(result.rendererConfigurations);
} }
...@@ -269,12 +256,10 @@ public final class DefaultTrackSelectorTest { ...@@ -269,12 +256,10 @@ public final class DefaultTrackSelectorTest {
/** Tests a no-sample renderer is enabled without a track selection by default. */ /** Tests a no-sample renderer is enabled without a track selection by default. */
@Test @Test
public void testSelectTracksWithNoSampleRenderer() throws ExoPlaybackException { public void testSelectTracksWithNoSampleRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS, periodId, TIMELINE); RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER); assertSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER);
assertThat(new RendererConfiguration[] {DEFAULT, DEFAULT}) assertThat(new RendererConfiguration[] {DEFAULT, DEFAULT})
.isEqualTo(result.rendererConfigurations); .isEqualTo(result.rendererConfigurations);
} }
...@@ -282,13 +267,11 @@ public final class DefaultTrackSelectorTest { ...@@ -282,13 +267,11 @@ public final class DefaultTrackSelectorTest {
/** Tests disabling a no-sample renderer. */ /** Tests disabling a no-sample renderer. */
@Test @Test
public void testSelectTracksWithDisabledNoSampleRenderer() throws ExoPlaybackException { public void testSelectTracksWithDisabledNoSampleRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setRendererDisabled(1, true));
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS, periodId, TIMELINE); RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS, periodId, TIMELINE);
assertTrackSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER); assertSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER);
assertThat(new RendererConfiguration[] {DEFAULT, null}) assertThat(new RendererConfiguration[] {DEFAULT, null})
.isEqualTo(result.rendererConfigurations); .isEqualTo(result.rendererConfigurations);
} }
...@@ -301,8 +284,7 @@ public final class DefaultTrackSelectorTest { ...@@ -301,8 +284,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSetParameterWithDefaultParametersDoesNotNotifyInvalidationListener() public void testSetParameterWithDefaultParametersDoesNotNotifyInvalidationListener()
throws Exception { throws Exception {
trackSelector.init(invalidationListener, /* bandwidthMeter= */ null); trackSelector.setParameters(Parameters.DEFAULT);
verify(invalidationListener, never()).onTrackSelectionsInvalidated(); verify(invalidationListener, never()).onTrackSelectionsInvalidated();
} }
...@@ -313,10 +295,8 @@ public final class DefaultTrackSelectorTest { ...@@ -313,10 +295,8 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSetParameterWithNonDefaultParameterNotifyInvalidationListener() public void testSetParameterWithNonDefaultParameterNotifyInvalidationListener()
throws Exception { throws Exception {
Parameters parameters = new ParametersBuilder().setPreferredAudioLanguage("eng").build(); Parameters parameters = Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng").build();
trackSelector.init(invalidationListener, /* bandwidthMeter= */ null);
trackSelector.setParameters(parameters); trackSelector.setParameters(parameters);
verify(invalidationListener).onTrackSelectionsInvalidated(); verify(invalidationListener).onTrackSelectionsInvalidated();
} }
...@@ -328,11 +308,9 @@ public final class DefaultTrackSelectorTest { ...@@ -328,11 +308,9 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSetParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain() public void testSetParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain()
throws Exception { throws Exception {
ParametersBuilder builder = new ParametersBuilder().setPreferredAudioLanguage("eng"); ParametersBuilder builder = Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng");
trackSelector.init(invalidationListener, /* bandwidthMeter= */ null);
trackSelector.setParameters(builder.build()); trackSelector.setParameters(builder.build());
trackSelector.setParameters(builder.build()); trackSelector.setParameters(builder.build());
verify(invalidationListener, times(1)).onTrackSelectionsInvalidated(); verify(invalidationListener, times(1)).onTrackSelectionsInvalidated();
} }
...@@ -342,17 +320,21 @@ public final class DefaultTrackSelectorTest { ...@@ -342,17 +320,21 @@ public final class DefaultTrackSelectorTest {
*/ */
@Test @Test
public void testSelectTracksSelectTrackWithSelectionFlag() throws Exception { public void testSelectTracksSelectTrackWithSelectionFlag() throws Exception {
Format audioFormat = buildAudioFormat("audio", /* language= */ null, /* selectionFlags= */ 0); Format audioFormat =
buildAudioFormatWithLanguageAndFlags(
"audio", /* language= */ null, /* selectionFlags= */ 0);
Format formatWithSelectionFlag = Format formatWithSelectionFlag =
buildAudioFormat("audio", /* language= */ null, C.SELECTION_FLAG_DEFAULT); buildAudioFormatWithLanguageAndFlags(
"audio", /* language= */ null, C.SELECTION_FLAG_DEFAULT);
TrackGroupArray trackGroups = wrapFormats(audioFormat, formatWithSelectionFlag);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup(formatWithSelectionFlag, audioFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(formatWithSelectionFlag); assertFixedSelection(result.selections.get(0), trackGroups, formatWithSelectionFlag);
} }
/** /**
...@@ -362,23 +344,23 @@ public final class DefaultTrackSelectorTest { ...@@ -362,23 +344,23 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksSelectPreferredAudioLanguage() public void testSelectTracksSelectPreferredAudioLanguage()
throws Exception { throws Exception {
trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build());
Format frAudioFormat = Format frAudioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, "fra"); Format.NO_VALUE, 2, 44100, null, null, 0, "fra");
Format enAudioFormat = Format enAudioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, "eng"); Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
TrackGroupArray trackGroups = wrapFormats(frAudioFormat, enAudioFormat);
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng").build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
wrapFormats(frAudioFormat, enAudioFormat), wrapFormats(frAudioFormat, enAudioFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, enAudioFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat);
} }
/** /**
...@@ -388,23 +370,23 @@ public final class DefaultTrackSelectorTest { ...@@ -388,23 +370,23 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksSelectPreferredAudioLanguageOverSelectionFlag() public void testSelectTracksSelectPreferredAudioLanguageOverSelectionFlag()
throws Exception { throws Exception {
trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build());
Format frAudioFormat = Format frAudioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, "fra"); Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, "fra");
Format enAudioFormat = Format enAudioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, "eng"); Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
TrackGroupArray trackGroups = wrapFormats(frAudioFormat, enAudioFormat);
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng").build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
wrapFormats(frAudioFormat, enAudioFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, enAudioFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat);
} }
/** /**
...@@ -415,6 +397,7 @@ public final class DefaultTrackSelectorTest { ...@@ -415,6 +397,7 @@ public final class DefaultTrackSelectorTest {
public void testSelectTracksPreferTrackWithinCapabilities() throws Exception { public void testSelectTracksPreferTrackWithinCapabilities() throws Exception {
Format supportedFormat = buildAudioFormat("supportedFormat"); Format supportedFormat = buildAudioFormat("supportedFormat");
Format exceededFormat = buildAudioFormat("exceededFormat"); Format exceededFormat = buildAudioFormat("exceededFormat");
TrackGroupArray trackGroups = wrapFormats(exceededFormat, supportedFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>(); Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED); mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
...@@ -425,11 +408,10 @@ public final class DefaultTrackSelectorTest { ...@@ -425,11 +408,10 @@ public final class DefaultTrackSelectorTest {
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {mappedAudioRendererCapabilities}, new RendererCapabilities[] {mappedAudioRendererCapabilities},
singleTrackGroup(exceededFormat, supportedFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(supportedFormat);
} }
/** /**
...@@ -442,14 +424,15 @@ public final class DefaultTrackSelectorTest { ...@@ -442,14 +424,15 @@ public final class DefaultTrackSelectorTest {
Format audioFormat = Format audioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
TrackGroupArray trackGroups = singleTrackGroup(audioFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup(audioFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, audioFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(audioFormat);
} }
/** /**
...@@ -460,20 +443,20 @@ public final class DefaultTrackSelectorTest { ...@@ -460,20 +443,20 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithNoTrackWithinCapabilitiesAndSetByParamsReturnNoSelection() public void testSelectTracksWithNoTrackWithinCapabilitiesAndSetByParamsReturnNoSelection()
throws Exception { throws Exception {
trackSelector.setParameters(
new ParametersBuilder().setExceedRendererCapabilitiesIfNecessary(false).build());
Format audioFormat = Format audioFormat =
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
TrackGroupArray trackGroups = singleTrackGroup(audioFormat);
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setExceedRendererCapabilitiesIfNecessary(false).build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup(audioFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertNoSelection(result.selections.get(0));
assertThat(result.selections.get(0)).isNull();
} }
/** /**
...@@ -483,12 +466,23 @@ public final class DefaultTrackSelectorTest { ...@@ -483,12 +466,23 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlag() public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlag()
throws Exception { throws Exception {
Format exceededWithSelectionFlagFormat =
Format.createAudioSampleFormat(
"exceededFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
2,
44100,
null,
null,
C.SELECTION_FLAG_DEFAULT,
null);
Format supportedFormat = Format supportedFormat =
Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null, Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null,
Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null);
Format exceededWithSelectionFlagFormat = TrackGroupArray trackGroups = wrapFormats(exceededWithSelectionFlagFormat, supportedFormat);
Format.createAudioSampleFormat("exceededFormat", MimeTypes.AUDIO_AAC, null,
Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, null);
Map<String, Integer> mappedCapabilities = new HashMap<>(); Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED); mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
...@@ -499,11 +493,10 @@ public final class DefaultTrackSelectorTest { ...@@ -499,11 +493,10 @@ public final class DefaultTrackSelectorTest {
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {mappedAudioRendererCapabilities}, new RendererCapabilities[] {mappedAudioRendererCapabilities},
singleTrackGroup(exceededWithSelectionFlagFormat, supportedFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(supportedFormat);
} }
/** /**
...@@ -514,14 +507,23 @@ public final class DefaultTrackSelectorTest { ...@@ -514,14 +507,23 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage() public void testSelectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage()
throws Exception { throws Exception {
trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build()); Format exceededEnFormat =
Format.createAudioSampleFormat(
"exceededFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
2,
44100,
null,
null,
0,
"eng");
Format supportedFrFormat = Format supportedFrFormat =
Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null, Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null,
Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, "fra"); Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, "fra");
Format exceededEnFormat = TrackGroupArray trackGroups = wrapFormats(exceededEnFormat, supportedFrFormat);
Format.createAudioSampleFormat("exceededFormat", MimeTypes.AUDIO_AAC, null,
Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
Map<String, Integer> mappedCapabilities = new HashMap<>(); Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(exceededEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES); mappedCapabilities.put(exceededEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
...@@ -529,14 +531,15 @@ public final class DefaultTrackSelectorTest { ...@@ -529,14 +531,15 @@ public final class DefaultTrackSelectorTest {
RendererCapabilities mappedAudioRendererCapabilities = RendererCapabilities mappedAudioRendererCapabilities =
new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities); new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng").build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {mappedAudioRendererCapabilities}, new RendererCapabilities[] {mappedAudioRendererCapabilities},
singleTrackGroup(exceededEnFormat, supportedFrFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFrFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(supportedFrFormat);
} }
/** /**
...@@ -547,14 +550,23 @@ public final class DefaultTrackSelectorTest { ...@@ -547,14 +550,23 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage() public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage()
throws Exception { throws Exception {
trackSelector.setParameters(new ParametersBuilder().setPreferredAudioLanguage("eng").build()); Format exceededDefaultSelectionEnFormat =
Format.createAudioSampleFormat(
"exceededFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
2,
44100,
null,
null,
C.SELECTION_FLAG_DEFAULT,
"eng");
Format supportedFrFormat = Format supportedFrFormat =
Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null, Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null,
Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, "fra"); Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, "fra");
Format exceededDefaultSelectionEnFormat = TrackGroupArray trackGroups = wrapFormats(exceededDefaultSelectionEnFormat, supportedFrFormat);
Format.createAudioSampleFormat("exceededFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, C.SELECTION_FLAG_DEFAULT, "eng");
Map<String, Integer> mappedCapabilities = new HashMap<>(); Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(exceededDefaultSelectionEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES); mappedCapabilities.put(exceededDefaultSelectionEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
...@@ -562,14 +574,15 @@ public final class DefaultTrackSelectorTest { ...@@ -562,14 +574,15 @@ public final class DefaultTrackSelectorTest {
RendererCapabilities mappedAudioRendererCapabilities = RendererCapabilities mappedAudioRendererCapabilities =
new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities); new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("eng").build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {mappedAudioRendererCapabilities}, new RendererCapabilities[] {mappedAudioRendererCapabilities},
singleTrackGroup(exceededDefaultSelectionEnFormat, supportedFrFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFrFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(supportedFrFormat);
} }
/** /**
...@@ -579,21 +592,31 @@ public final class DefaultTrackSelectorTest { ...@@ -579,21 +592,31 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithinCapabilitiesSelectHigherNumChannel() public void testSelectTracksWithinCapabilitiesSelectHigherNumChannel()
throws Exception { throws Exception {
Format higherChannelFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
6,
44100,
null,
null,
0,
null);
Format lowerChannelFormat = Format lowerChannelFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
Format higherChannelFormat = TrackGroupArray trackGroups = wrapFormats(higherChannelFormat, lowerChannelFormat);
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 6, 44100, null, null, 0, null);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup(higherChannelFormat, lowerChannelFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherChannelFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherChannelFormat);
} }
/** /**
...@@ -609,39 +632,58 @@ public final class DefaultTrackSelectorTest { ...@@ -609,39 +632,58 @@ public final class DefaultTrackSelectorTest {
Format lowerSampleRateFormat = Format lowerSampleRateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 22050, null, null, 0, null); Format.NO_VALUE, 2, 22050, null, null, 0, null);
TrackGroupArray trackGroups = wrapFormats(higherSampleRateFormat, lowerSampleRateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup(higherSampleRateFormat, lowerSampleRateFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherSampleRateFormat);
} }
/** /**
* Tests that track selector will select audio tracks with higher bit-rate when other factors * Tests that track selector will select audio tracks with higher bit-rate when other factors are
* are the same, and tracks are within renderer's capabilities. * the same, and tracks are within renderer's capabilities.
*/ */
@Test @Test
public void testSelectTracksWithinCapabilitiesSelectHigherBitrate() public void testSelectTracksWithinCapabilitiesSelectHigherBitrate() throws Exception {
throws Exception {
Format lowerBitrateFormat = Format lowerBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.createAudioSampleFormat(
Format.NO_VALUE, 2, 44100, null, null, 0, null); "audioFormat",
MimeTypes.AUDIO_AAC,
null,
15000,
Format.NO_VALUE,
2,
44100,
null,
null,
0,
null);
Format higherBitrateFormat = Format higherBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.createAudioSampleFormat(
Format.NO_VALUE, 2, 44100, null, null, 0, null); "audioFormat",
MimeTypes.AUDIO_AAC,
null,
30000,
Format.NO_VALUE,
2,
44100,
null,
null,
0,
null);
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup(lowerBitrateFormat, higherBitrateFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherBitrateFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(higherBitrateFormat);
} }
/** /**
...@@ -652,23 +694,32 @@ public final class DefaultTrackSelectorTest { ...@@ -652,23 +694,32 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksPreferHigherNumChannelBeforeSampleRate() public void testSelectTracksPreferHigherNumChannelBeforeSampleRate()
throws Exception { throws Exception {
Format higherChannelLowerSampleRateFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
6,
22050,
null,
null,
0,
null);
Format lowerChannelHigherSampleRateFormat = Format lowerChannelHigherSampleRateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
Format higherChannelLowerSampleRateFormat = TrackGroupArray trackGroups =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, wrapFormats(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat);
Format.NO_VALUE, 6, 22050, null, null, 0, null);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup( trackGroups,
higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherChannelLowerSampleRateFormat);
assertThat(result.selections.get(0).getSelectedFormat())
.isEqualTo(higherChannelLowerSampleRateFormat);
} }
/** /**
...@@ -685,17 +736,16 @@ public final class DefaultTrackSelectorTest { ...@@ -685,17 +736,16 @@ public final class DefaultTrackSelectorTest {
Format lowerSampleRateHigherBitrateFormat = Format lowerSampleRateHigherBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
Format.NO_VALUE, 2, 22050, null, null, 0, null); Format.NO_VALUE, 2, 22050, null, null, 0, null);
TrackGroupArray trackGroups =
wrapFormats(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup( trackGroups,
higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateLowerBitrateFormat);
assertThat(result.selections.get(0).getSelectedFormat())
.isEqualTo(higherSampleRateLowerBitrateFormat);
} }
/** /**
...@@ -705,21 +755,31 @@ public final class DefaultTrackSelectorTest { ...@@ -705,21 +755,31 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksExceedingCapabilitiesSelectLowerNumChannel() public void testSelectTracksExceedingCapabilitiesSelectLowerNumChannel()
throws Exception { throws Exception {
Format higherChannelFormat =
Format.createAudioSampleFormat(
"audioFormat",
MimeTypes.AUDIO_AAC,
null,
Format.NO_VALUE,
Format.NO_VALUE,
6,
44100,
null,
null,
0,
null);
Format lowerChannelFormat = Format lowerChannelFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
Format higherChannelFormat = TrackGroupArray trackGroups = wrapFormats(higherChannelFormat, lowerChannelFormat);
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 6, 44100, null, null, 0, null);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup(higherChannelFormat, lowerChannelFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerChannelFormat);
} }
/** /**
...@@ -735,15 +795,15 @@ public final class DefaultTrackSelectorTest { ...@@ -735,15 +795,15 @@ public final class DefaultTrackSelectorTest {
Format higherSampleRateFormat = Format higherSampleRateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
TrackGroupArray trackGroups = wrapFormats(higherSampleRateFormat, lowerSampleRateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup(higherSampleRateFormat, lowerSampleRateFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerSampleRateFormat);
} }
/** /**
...@@ -759,15 +819,15 @@ public final class DefaultTrackSelectorTest { ...@@ -759,15 +819,15 @@ public final class DefaultTrackSelectorTest {
Format higherBitrateFormat = Format higherBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup(lowerBitrateFormat, higherBitrateFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerBitrateFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerBitrateFormat);
} }
/** /**
...@@ -784,17 +844,16 @@ public final class DefaultTrackSelectorTest { ...@@ -784,17 +844,16 @@ public final class DefaultTrackSelectorTest {
Format higherChannelLowerSampleRateFormat = Format higherChannelLowerSampleRateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 6, 22050, null, null, 0, null); Format.NO_VALUE, 6, 22050, null, null, 0, null);
TrackGroupArray trackGroups =
wrapFormats(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup( trackGroups,
higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelHigherSampleRateFormat);
assertThat(result.selections.get(0).getSelectedFormat())
.isEqualTo(lowerChannelHigherSampleRateFormat);
} }
/** /**
...@@ -811,17 +870,16 @@ public final class DefaultTrackSelectorTest { ...@@ -811,17 +870,16 @@ public final class DefaultTrackSelectorTest {
Format lowerSampleRateHigherBitrateFormat = Format lowerSampleRateHigherBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
Format.NO_VALUE, 2, 22050, null, null, 0, null); Format.NO_VALUE, 2, 22050, null, null, 0, null);
TrackGroupArray trackGroups =
wrapFormats(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES},
singleTrackGroup( trackGroups,
higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateHigherBitrateFormat);
assertThat(result.selections.get(0).getSelectedFormat())
.isEqualTo(lowerSampleRateHigherBitrateFormat);
} }
/** Tests text track selection flags. */ /** Tests text track selection flags. */
...@@ -838,105 +896,71 @@ public final class DefaultTrackSelectorTest { ...@@ -838,105 +896,71 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}; new RendererCapabilities[] {ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES};
// There is no text language preference, the first track flagged as default should be selected. // There is no text language preference, the first track flagged as default should be selected.
TrackGroupArray trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
textRendererCapabilities, assertFixedSelection(result.selections.get(0), trackGroups, forcedDefault);
wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(forcedDefault);
// Ditto. // Ditto.
result = trackGroups = wrapFormats(forcedOnly, noFlag, defaultOnly);
trackSelector.selectTracks( result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
textRendererCapabilities, assertFixedSelection(result.selections.get(0), trackGroups, defaultOnly);
wrapFormats(forcedOnly, noFlag, defaultOnly),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(defaultOnly);
// With no language preference and no text track flagged as default, the first forced should be // With no language preference and no text track flagged as default, the first forced should be
// selected. // selected.
result = trackGroups = wrapFormats(forcedOnly, noFlag);
trackSelector.selectTracks( result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
textRendererCapabilities, wrapFormats(forcedOnly, noFlag), periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, forcedOnly);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(forcedOnly);
// Default flags are disabled, so the first track flagged as forced should be selected.
trackGroups = wrapFormats(defaultOnly, noFlag, forcedOnly, forcedDefault);
trackSelector.setParameters( trackSelector.setParameters(
Parameters.DEFAULT Parameters.DEFAULT
.buildUpon() .buildUpon()
.setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT) .setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build()); .build());
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
// Default flags are disabled, so the first track flagged as forced should be selected. assertFixedSelection(result.selections.get(0), trackGroups, forcedOnly);
result =
trackSelector.selectTracks(
textRendererCapabilities,
wrapFormats(defaultOnly, noFlag, forcedOnly, forcedDefault),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(forcedOnly);
trackSelector.setParameters(
trackSelector.getParameters().buildUpon().setPreferredAudioLanguage("spa").build());
// Default flags are disabled, but there is a text track flagged as forced whose language // Default flags are disabled, but there is a text track flagged as forced whose language
// matches the preferred audio language. // matches the preferred audio language.
result = trackGroups = wrapFormats(forcedDefault, forcedOnly, defaultOnly, noFlag, forcedOnlySpanish);
trackSelector.selectTracks( trackSelector.setParameters(
textRendererCapabilities, trackSelector.getParameters().buildUpon().setPreferredAudioLanguage("spa").build());
wrapFormats(forcedDefault, forcedOnly, defaultOnly, noFlag, forcedOnlySpanish), result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
periodId, assertFixedSelection(result.selections.get(0), trackGroups, forcedOnlySpanish);
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(forcedOnlySpanish);
// All selection flags are disabled and there is no language preference, so nothing should be
// selected.
trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.getParameters() .getParameters()
.buildUpon() .buildUpon()
.setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED) .setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED)
.build()); .build());
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
// All selection flags are disabled and there is no language preference, so nothing should be assertNoSelection(result.selections.get(0));
// selected.
result =
trackSelector.selectTracks(
textRendererCapabilities,
wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag),
periodId,
TIMELINE);
assertThat(result.selections.get(0)).isNull();
trackSelector.setParameters(
Parameters.DEFAULT.buildUpon().setPreferredTextLanguage("eng").build());
// There is a preferred language, so the first language-matching track flagged as default should // There is a preferred language, so the first language-matching track flagged as default should
// be selected. // be selected.
result = trackSelector.setParameters(
trackSelector.selectTracks( Parameters.DEFAULT.buildUpon().setPreferredTextLanguage("eng").build());
textRendererCapabilities, result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag), assertFixedSelection(result.selections.get(0), trackGroups, forcedDefault);
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(forcedDefault);
// Same as above, but the default flag is disabled. If multiple tracks match the preferred
// language, those not flagged as forced are preferred, as they likely include the contents of
// forced subtitles.
trackGroups = wrapFormats(noFlag, forcedOnly, forcedDefault, defaultOnly);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.getParameters() .getParameters()
.buildUpon() .buildUpon()
.setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT) .setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build()); .build());
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
// Same as above, but the default flag is disabled. If multiple tracks match the preferred assertFixedSelection(result.selections.get(0), trackGroups, noFlag);
// language, those not flagged as forced are preferred, as they likely include the contents of
// forced subtitles.
result =
trackSelector.selectTracks(
textRendererCapabilities,
wrapFormats(noFlag, forcedOnly, forcedDefault, defaultOnly),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(noFlag);
} }
/** /**
...@@ -954,60 +978,37 @@ public final class DefaultTrackSelectorTest { ...@@ -954,60 +978,37 @@ public final class DefaultTrackSelectorTest {
RendererCapabilities[] textRendererCapabilites = RendererCapabilities[] textRendererCapabilites =
new RendererCapabilities[] {ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}; new RendererCapabilities[] {ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES};
TrackGroupArray trackGroups = wrapFormats(spanish, german, undeterminedUnd, undeterminedNull);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
textRendererCapabilites, assertNoSelection(result.selections.get(0));
wrapFormats(spanish, german, undeterminedUnd, undeterminedNull),
periodId,
TIMELINE);
assertThat(result.selections.get(0)).isNull();
trackSelector.setParameters( trackSelector.setParameters(
new ParametersBuilder().setSelectUndeterminedTextLanguage(true).build()); Parameters.DEFAULT.buildUpon().setSelectUndeterminedTextLanguage(true).build());
result = result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
trackSelector.selectTracks( assertFixedSelection(result.selections.get(0), trackGroups, undeterminedUnd);
textRendererCapabilites,
wrapFormats(spanish, german, undeterminedUnd, undeterminedNull),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(undeterminedUnd);
ParametersBuilder builder = new ParametersBuilder().setPreferredTextLanguage("spa"); ParametersBuilder builder = Parameters.DEFAULT.buildUpon().setPreferredTextLanguage("spa");
trackSelector.setParameters(builder.build()); trackSelector.setParameters(builder.build());
result = result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
trackSelector.selectTracks( assertFixedSelection(result.selections.get(0), trackGroups, spanish);
textRendererCapabilites,
wrapFormats(spanish, german, undeterminedUnd, undeterminedNull),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(spanish);
result = trackGroups = wrapFormats(german, undeterminedUnd, undeterminedNull);
trackSelector.selectTracks(
textRendererCapabilites, result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
wrapFormats(german, undeterminedUnd, undeterminedNull), assertNoSelection(result.selections.get(0));
periodId,
TIMELINE);
assertThat(result.selections.get(0)).isNull();
trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true).build()); trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true).build());
result = result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
trackSelector.selectTracks( assertFixedSelection(result.selections.get(0), trackGroups, undeterminedUnd);
textRendererCapabilites,
wrapFormats(german, undeterminedUnd, undeterminedNull),
periodId,
TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(undeterminedUnd);
result = trackGroups = wrapFormats(german, undeterminedNull);
trackSelector.selectTracks( result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
textRendererCapabilites, wrapFormats(german, undeterminedNull), periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, undeterminedNull);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(undeterminedNull);
result = trackGroups = wrapFormats(german);
trackSelector.selectTracks( result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
textRendererCapabilites, wrapFormats(german), periodId, TIMELINE); assertNoSelection(result.selections.get(0));
assertThat(result.selections.get(0)).isNull();
} }
/** Tests audio track selection when there are multiple audio renderers. */ /** Tests audio track selection when there are multiple audio renderers. */
...@@ -1032,29 +1033,25 @@ public final class DefaultTrackSelectorTest { ...@@ -1032,29 +1033,25 @@ public final class DefaultTrackSelectorTest {
RendererCapabilities[] rendererCapabilities = RendererCapabilities[] rendererCapabilities =
new RendererCapabilities[] {firstRendererCapabilities, secondRendererCapabilities}; new RendererCapabilities[] {firstRendererCapabilities, secondRendererCapabilities};
TrackGroupArray trackGroups = wrapFormats(english, german);
// Without an explicit language preference, nothing should be selected. // Without an explicit language preference, nothing should be selected.
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE); assertNoSelection(result.selections.get(0));
assertThat(result.selections.get(0)).isNull(); assertNoSelection(result.selections.get(1));
assertThat(result.selections.get(1)).isNull();
// Explicit language preference for english. First renderer should be used. // Explicit language preference for english. First renderer should be used.
trackSelector.setParameters(trackSelector.buildUponParameters().setPreferredTextLanguage("en")); trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setPreferredTextLanguage("en"));
result = result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.selectTracks( assertFixedSelection(result.selections.get(0), trackGroups, english);
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE); assertNoSelection(result.selections.get(1));
assertThat(result.selections.get(0).getFormat(0)).isSameAs(english);
assertThat(result.selections.get(1)).isNull();
// Explicit language preference for German. Second renderer should be used. // Explicit language preference for German. Second renderer should be used.
trackSelector.setParameters(trackSelector.buildUponParameters().setPreferredTextLanguage("de")); trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setPreferredTextLanguage("de"));
result = result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.selectTracks( assertNoSelection(result.selections.get(0));
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE); assertFixedSelection(result.selections.get(1), trackGroups, german);
assertThat(result.selections.get(0)).isNull();
assertThat(result.selections.get(1).getFormat(0)).isSameAs(german);
} }
/** /**
...@@ -1064,81 +1061,60 @@ public final class DefaultTrackSelectorTest { ...@@ -1064,81 +1061,60 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithinCapabilitiesAndForceLowestBitrateSelectLowerBitrate() public void testSelectTracksWithinCapabilitiesAndForceLowestBitrateSelectLowerBitrate()
throws Exception { throws Exception {
trackSelector.setParameters(new ParametersBuilder().setForceLowestBitrate(true).build());
Format lowerBitrateFormat = Format lowerBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 15000,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
Format higherBitrateFormat = Format higherBitrateFormat =
Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000, Format.createAudioSampleFormat("audioFormat", MimeTypes.AUDIO_AAC, null, 30000,
Format.NO_VALUE, 2, 44100, null, null, 0, null); Format.NO_VALUE, 2, 44100, null, null, 0, null);
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat);
trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setForceLowestBitrate(true).build());
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
singleTrackGroup(lowerBitrateFormat, higherBitrateFormat), trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerBitrateFormat);
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(lowerBitrateFormat);
} }
@Test @Test
public void testSelectTracksWithMultipleAudioTracksReturnsAdaptiveTrackSelection() public void testSelectTracksWithMultipleAudioTracks() throws Exception {
throws Exception { TrackGroupArray trackGroups = singleTrackGroup(buildAudioFormat("0"), buildAudioFormat("1"));
TrackSelection adaptiveTrackSelection = mock(TrackSelection.class);
TrackSelection.Factory adaptiveTrackSelectionFactory = mock(TrackSelection.Factory.class);
when(adaptiveTrackSelectionFactory.createTrackSelection(any(), any(), anyVararg()))
.thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroupArray, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertThat(result.selections.get(0)).isEqualTo(adaptiveTrackSelection); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1);
verify(adaptiveTrackSelectionFactory)
.createTrackSelection(trackGroupArray.get(0), bandwidthMeter, 0, 1);
} }
@Test @Test
public void testSelectTracksWithMultipleAudioTracksOverrideReturnsAdaptiveTrackSelection() public void testSelectTracksWithMultipleAudioTracksOverrideReturnsAdaptiveTrackSelection()
throws Exception { throws Exception {
TrackSelection adaptiveTrackSelection = mock(TrackSelection.class); TrackGroupArray trackGroups =
TrackSelection.Factory adaptiveTrackSelectionFactory = mock(TrackSelection.Factory.class); singleTrackGroup(buildAudioFormat("0"), buildAudioFormat("1"), buildAudioFormat("2"));
when(adaptiveTrackSelectionFactory.createTrackSelection(any(), any(), anyVararg()))
.thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
.setSelectionOverride( .setSelectionOverride(
/* rendererIndex= */ 0, /* rendererIndex= */ 0,
trackGroupArray, trackGroups,
new SelectionOverride(/* groupIndex= */ 0, /* tracks= */ 1, 2))); new SelectionOverride(/* groupIndex= */ 0, /* tracks= */ 1, 2)));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroupArray, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertThat(result.selections.get(0)).isEqualTo(adaptiveTrackSelection); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1, 2);
verify(adaptiveTrackSelectionFactory)
.createTrackSelection(trackGroupArray.get(0), bandwidthMeter, 1, 2);
} }
/** Tests audio track selection when there are multiple audio renderers. */ /** Tests audio track selection when there are multiple audio renderers. */
@Test @Test
public void testSelectPreferredAudioTrackMultipleRenderers() throws Exception { public void testSelectPreferredAudioTrackMultipleRenderers() throws Exception {
Format english = buildAudioFormat("en", "en"); Format english = buildAudioFormatWithLanguage("en", "en");
Format german = buildAudioFormat("de", "de"); Format german = buildAudioFormatWithLanguage("de", "de");
// First renderer handles english. // First renderer handles english.
Map<String, Integer> firstRendererMappedCapabilities = new HashMap<>(); Map<String, Integer> firstRendererMappedCapabilities = new HashMap<>();
...@@ -1158,89 +1134,104 @@ public final class DefaultTrackSelectorTest { ...@@ -1158,89 +1134,104 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {firstRendererCapabilities, secondRendererCapabilities}; new RendererCapabilities[] {firstRendererCapabilities, secondRendererCapabilities};
// Without an explicit language preference, prefer the first renderer. // Without an explicit language preference, prefer the first renderer.
TrackGroupArray trackGroups = wrapFormats(english, german);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE); assertFixedSelection(result.selections.get(0), trackGroups, english);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(english); assertNoSelection(result.selections.get(1));
assertThat(result.selections.get(1)).isNull();
// Explicit language preference for english. First renderer should be used. // Explicit language preference for english. First renderer should be used.
trackSelector.setParameters( trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("en"));
trackSelector.buildUponParameters().setPreferredAudioLanguage("en")); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
result = assertFixedSelection(result.selections.get(0), trackGroups, english);
trackSelector.selectTracks( assertNoSelection(result.selections.get(1));
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE);
assertThat(result.selections.get(0).getFormat(0)).isSameAs(english);
assertThat(result.selections.get(1)).isNull();
// Explicit language preference for German. Second renderer should be used. // Explicit language preference for German. Second renderer should be used.
trackSelector.setParameters( trackSelector.setParameters(Parameters.DEFAULT.buildUpon().setPreferredAudioLanguage("de"));
trackSelector.buildUponParameters().setPreferredAudioLanguage("de")); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
result = assertNoSelection(result.selections.get(0));
trackSelector.selectTracks( assertFixedSelection(result.selections.get(1), trackGroups, german);
rendererCapabilities, wrapFormats(english, german), periodId, TIMELINE);
assertThat(result.selections.get(0)).isNull();
assertThat(result.selections.get(1).getFormat(0)).isSameAs(german);
} }
@Test @Test
public void testSelectTracksWithMultipleVideoTracksReturnsAdaptiveTrackSelection() public void testSelectTracksWithMultipleVideoTracks() throws Exception {
throws Exception { TrackGroupArray trackGroups = singleTrackGroup(buildVideoFormat("0"), buildVideoFormat("1"));
TrackSelection adaptiveTrackSelection = mock(TrackSelection.class);
TrackSelection.Factory adaptiveTrackSelectionFactory = mock(TrackSelection.Factory.class);
when(adaptiveTrackSelectionFactory.createTrackSelection(any(), any(), anyVararg()))
.thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroupArray, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertThat(result.selections.get(0)).isEqualTo(adaptiveTrackSelection); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1);
verify(adaptiveTrackSelectionFactory)
.createTrackSelection(trackGroupArray.get(0), bandwidthMeter, 0, 1);
} }
@Test @Test
public void testSelectTracksWithMultipleVideoTracksOverrideReturnsAdaptiveTrackSelection() public void testSelectTracksWithMultipleVideoTracksOverrideReturnsAdaptiveTrackSelection()
throws Exception { throws Exception {
TrackSelection adaptiveTrackSelection = mock(TrackSelection.class); TrackGroupArray trackGroups =
TrackSelection.Factory adaptiveTrackSelectionFactory = mock(TrackSelection.Factory.class); singleTrackGroup(buildVideoFormat("0"), buildVideoFormat("1"), buildVideoFormat("2"));
when(adaptiveTrackSelectionFactory.createTrackSelection(any(), any(), anyVararg()))
.thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT, VIDEO_FORMAT);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
.setSelectionOverride( .setSelectionOverride(
/* rendererIndex= */ 0, /* rendererIndex= */ 0,
trackGroupArray, trackGroups,
new SelectionOverride(/* groupIndex= */ 0, /* tracks= */ 1, 2))); new SelectionOverride(/* groupIndex= */ 0, /* tracks= */ 1, 2)));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroupArray, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertThat(result.selections.get(0)).isEqualTo(adaptiveTrackSelection); assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1, 2);
verify(adaptiveTrackSelectionFactory)
.createTrackSelection(trackGroupArray.get(0), bandwidthMeter, 1, 2);
} }
private static void assertTrackSelections(TrackSelectorResult result, TrackSelection[] expected) { private static void assertSelections(TrackSelectorResult result, TrackSelection[] expected) {
assertThat(result.length).isEqualTo(expected.length); assertThat(result.length).isEqualTo(expected.length);
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertThat(result.selections.get(i)).isEqualTo(expected[i]); assertThat(result.selections.get(i)).isEqualTo(expected[i]);
} }
} }
private static void assertFixedSelection(
TrackSelection selection, TrackGroupArray trackGroups, Format expectedFormat) {
int trackGroupIndex = -1;
for (int i = 0; i < trackGroups.length; i++) {
int expectedTrack = trackGroups.get(i).indexOf(expectedFormat);
if (expectedTrack != -1) {
assertThat(trackGroupIndex).isEqualTo(-1);
assertFixedSelection(selection, trackGroups.get(i), expectedTrack);
trackGroupIndex = i;
}
}
// Assert that we found the expected format in a track group
assertThat(trackGroupIndex).isNotEqualTo(-1);
}
private static void assertFixedSelection(
TrackSelection selection, TrackGroup expectedTrackGroup, int expectedTrack) {
assertThat(selection).isInstanceOf(FixedTrackSelection.class);
assertThat(selection.getTrackGroup()).isEqualTo(expectedTrackGroup);
assertThat(selection.length()).isEqualTo(1);
assertThat(selection.getIndexInTrackGroup(0)).isEqualTo(expectedTrack);
assertThat(selection.getFormat(0))
.isSameAs(expectedTrackGroup.getFormat(selection.getIndexInTrackGroup(0)));
}
private static void assertNoSelection(TrackSelection selection) {
assertThat(selection).isNull();
}
private static void assertAdaptiveSelection(
TrackSelection selection, TrackGroup expectedTrackGroup, int... expectedTracks) {
assertThat(selection).isInstanceOf(AdaptiveTrackSelection.class);
assertThat(selection.getTrackGroup()).isEqualTo(expectedTrackGroup);
assertThat(selection.length()).isEqualTo(expectedTracks.length);
for (int i = 0; i < expectedTracks.length; i++) {
assertThat(selection.getIndexInTrackGroup(i)).isEqualTo(expectedTracks[i]);
assertThat(selection.getFormat(i))
.isSameAs(expectedTrackGroup.getFormat(selection.getIndexInTrackGroup(i)));
}
}
private static TrackGroupArray singleTrackGroup(Format... formats) { private static TrackGroupArray singleTrackGroup(Format... formats) {
return new TrackGroupArray(new TrackGroup(formats)); return new TrackGroupArray(new TrackGroup(formats));
} }
...@@ -1253,10 +1244,10 @@ public final class DefaultTrackSelectorTest { ...@@ -1253,10 +1244,10 @@ public final class DefaultTrackSelectorTest {
return new TrackGroupArray(trackGroups); return new TrackGroupArray(trackGroups);
} }
private static Format buildVideoFormat(String id) { private static Format buildVideoFormatWithMimeType(String id, String mimeType) {
return Format.createVideoSampleFormat( return Format.createVideoSampleFormat(
id, id,
MimeTypes.VIDEO_H264, mimeType,
null, null,
Format.NO_VALUE, Format.NO_VALUE,
Format.NO_VALUE, Format.NO_VALUE,
...@@ -1267,23 +1258,50 @@ public final class DefaultTrackSelectorTest { ...@@ -1267,23 +1258,50 @@ public final class DefaultTrackSelectorTest {
null); null);
} }
private static Format buildAudioFormat(String id) { private static Format buildVideoFormat(String id) {
return buildAudioFormat(id, /* language= */ null); return buildVideoFormatWithMimeType(id, MimeTypes.VIDEO_H264);
} }
private static Format buildAudioFormat(String id, String language) { private static Format buildAudioFormatWithLanguage(String id, String language) {
return buildAudioFormat(id, language, /* selectionFlags= */ 0); return buildAudioFormatWithLanguageAndFlags(id, language, /* selectionFlags= */ 0);
} }
private static Format buildAudioFormat(String id, String language, int selectionFlags) { private static Format buildAudioFormatWithLanguageAndFlags(
return Format.createAudioSampleFormat( String id, String language, int selectionFlags) {
return buildAudioFormat(
id, id,
MimeTypes.AUDIO_AAC, MimeTypes.AUDIO_AAC,
language,
selectionFlags,
/* channelCount= */ 2,
/* sampleRate= */ 44100);
}
private static Format buildAudioFormat(String id) {
return buildAudioFormat(
id,
MimeTypes.AUDIO_AAC,
/* language= */ null,
/* selectionFlags= */ 0,
/* channelCount= */ 2,
/* sampleRate= */ 44100);
}
private static Format buildAudioFormat(
String id,
String mimeType,
String language,
int selectionFlags,
int channelCount,
int sampleRate) {
return Format.createAudioSampleFormat(
id,
mimeType,
/* codecs= */ null, /* codecs= */ null,
/* bitrate= */ Format.NO_VALUE, /* bitrate= */ Format.NO_VALUE,
/* maxInputSize= */ Format.NO_VALUE, /* maxInputSize= */ Format.NO_VALUE,
/* channelCount= */ 2, channelCount,
/* sampleRate= */ 44100, sampleRate,
/* initializationData= */ null, /* initializationData= */ null,
/* drmInitData= */ null, /* drmInitData= */ null,
selectionFlags, selectionFlags,
......
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