use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksWithMultipleVideoTracksOverrideReturnsAdaptiveTrackSelection.
@Test
public void selectTracksWithMultipleVideoTracksOverrideReturnsAdaptiveTrackSelection() throws Exception {
Format.Builder formatBuilder = VIDEO_FORMAT.buildUpon();
TrackGroupArray trackGroups = singleTrackGroup(formatBuilder.setId("0").build(), formatBuilder.setId("1").build(), formatBuilder.setId("2").build());
trackSelector.setParameters(trackSelector.buildUponParameters().setSelectionOverride(/* rendererIndex= */
0, trackGroups, new SelectionOverride(/* groupIndex= */
0, /* tracks=... */
1, 2)));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 1, 2);
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlag.
/**
* Tests that track selector will prefer tracks that are within renderer's capabilities over
* tracks that have {@link C#SELECTION_FLAG_DEFAULT} but exceed renderer's capabilities.
*/
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlag() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format exceededWithSelectionFlagFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
Format supportedFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).build();
TrackGroupArray trackGroups = wrapFormats(exceededWithSelectionFlagFormat, supportedFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
mappedCapabilities.put(exceededWithSelectionFlagFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect.
/**
* Tests that an empty override is not applied for a different set of available track groups.
*/
@Test
public void selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect() throws ExoPlaybackException {
TrackGroup videoGroup0 = VIDEO_TRACK_GROUP.copyWithId("0");
TrackGroup videoGroup1 = VIDEO_TRACK_GROUP.copyWithId("1");
trackSelector.setParameters(trackSelector.buildUponParameters().setTrackSelectionOverrides(new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(new TrackGroup(VIDEO_FORMAT, VIDEO_FORMAT), ImmutableList.of())).build()));
TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, new TrackGroupArray(videoGroup0, AUDIO_TRACK_GROUP, videoGroup1), periodId, TIMELINE);
assertThat(result.selections).asList().containsExactly(new FixedTrackSelection(videoGroup0, /* track= */
0), new FixedTrackSelection(AUDIO_TRACK_GROUP, /* track= */
0)).inOrder();
assertThat(result.rendererConfigurations).isEqualTo(new RendererConfiguration[] { DEFAULT, DEFAULT });
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectPreferredTextTrackMultipleRenderers.
/**
* Tests audio track selection when there are multiple audio renderers.
*/
@Test
public void selectPreferredTextTrackMultipleRenderers() throws Exception {
Format.Builder formatBuilder = TEXT_FORMAT.buildUpon();
Format english = formatBuilder.setId("en").setLanguage("en").build();
Format german = formatBuilder.setId("de").setLanguage("de").build();
// First renderer handles english.
Map<String, Integer> firstRendererMappedCapabilities = new HashMap<>();
firstRendererMappedCapabilities.put(english.id, FORMAT_HANDLED);
firstRendererMappedCapabilities.put(german.id, FORMAT_UNSUPPORTED_SUBTYPE);
RendererCapabilities firstRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_TEXT, firstRendererMappedCapabilities);
// Second renderer handles german.
Map<String, Integer> secondRendererMappedCapabilities = new HashMap<>();
secondRendererMappedCapabilities.put(english.id, FORMAT_UNSUPPORTED_SUBTYPE);
secondRendererMappedCapabilities.put(german.id, FORMAT_HANDLED);
RendererCapabilities secondRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_TEXT, secondRendererMappedCapabilities);
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, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections[0]);
assertNoSelection(result.selections[1]);
// Explicit language preference for english. First renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("en"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, english);
assertNoSelection(result.selections[1]);
// Explicit language preference for German. Second renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("de"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections[0]);
assertFixedSelection(result.selections[1], trackGroups, german);
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracks_withPreferredTextRoleFlags_selectPreferredTrack.
/**
* Tests that track selector will select the text track with the highest number of matching role
* flags given by {@link Parameters}.
*/
@Test
public void selectTracks_withPreferredTextRoleFlags_selectPreferredTrack() throws Exception {
Format.Builder formatBuilder = TEXT_FORMAT.buildUpon();
Format noRoleFlags = formatBuilder.build();
Format lessRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION).build();
Format moreRoleFlags = formatBuilder.setRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY | C.ROLE_FLAG_DUB).build();
TrackGroupArray trackGroups = wrapFormats(noRoleFlags, moreRoleFlags, lessRoleFlags);
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, moreRoleFlags);
// Also verify that exact match between parameters and tracks is preferred.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION));
result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, lessRoleFlags);
}
Aggregations