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