use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksWithMultipleVideoTracks.
@Test
public void selectTracksWithMultipleVideoTracks() throws Exception {
Format.Builder formatBuilder = VIDEO_FORMAT.buildUpon();
TrackGroupArray trackGroups = singleTrackGroup(formatBuilder.setId("0").build(), formatBuilder.setId("1").build());
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksSelectPreferredAudioLanguageOverSelectionFlag.
/**
* Tests that track selector will prefer selecting audio track with language that match preferred
* language given by {@link Parameters} over track with {@link C#SELECTION_FLAG_DEFAULT}.
*/
@Test
public void selectTracksSelectPreferredAudioLanguageOverSelectionFlag() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format frDefaultFormat = formatBuilder.setLanguage("fra").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
Format enNonDefaultFormat = formatBuilder.setLanguage("eng").setSelectionFlags(0).build();
TrackGroupArray trackGroups = wrapFormats(frDefaultFormat, enNonDefaultFormat);
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("eng"));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, enNonDefaultFormat);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectPreferredAudioTrackMultipleRenderers.
/**
* Tests audio track selection when there are multiple audio renderers.
*/
@Test
public void selectPreferredAudioTrackMultipleRenderers() throws Exception {
Format.Builder formatBuilder = AUDIO_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_AUDIO, 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_AUDIO, secondRendererMappedCapabilities);
RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { firstRendererCapabilities, secondRendererCapabilities };
// Without an explicit language preference, prefer the first renderer.
TrackGroupArray trackGroups = wrapFormats(english, german);
TrackSelectorResult result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, english);
assertNoSelection(result.selections[1]);
// Explicit language preference for english. First renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("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().setPreferredAudioLanguage("de"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections[0]);
assertFixedSelection(result.selections[1], trackGroups, german);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracks_withPreferredVideoRoleFlags_selectPreferredTrack.
/**
* Tests that track selector will select the video track with the highest number of matching role
* flags given by {@link Parameters}.
*/
@Test
public void selectTracks_withPreferredVideoRoleFlags_selectPreferredTrack() throws Exception {
Format.Builder formatBuilder = VIDEO_FORMAT.buildUpon();
Format noRoleFlagsLow = formatBuilder.setAverageBitrate(4000).build();
Format noRoleFlagsHigh = formatBuilder.setAverageBitrate(8000).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();
// Use an adaptive group to check that role flags have higher priority than number of tracks.
TrackGroup adaptiveNoRoleFlagsGroup = new TrackGroup(noRoleFlagsLow, noRoleFlagsHigh);
TrackGroupArray trackGroups = new TrackGroupArray(adaptiveNoRoleFlagsGroup, new TrackGroup(moreRoleFlags), new TrackGroup(lessRoleFlags));
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_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().setPreferredVideoRoleFlags(C.ROLE_FLAG_CAPTION));
result = trackSelector.selectTracks(new RendererCapabilities[] { VIDEO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, lessRoleFlags);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksExceedingCapabilitiesPreferLowerSampleRateBeforeBitrate.
/**
* Tests that track selector will prefer audio tracks with lower sample rate over tracks with
* lower bitrate when other factors are the same, and tracks are within renderer's capabilities.
*/
@Test
public void selectTracksExceedingCapabilitiesPreferLowerSampleRateBeforeBitrate() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format higherSampleRateLowerBitrateFormat = formatBuilder.setAverageBitrate(15000).setSampleRate(44100).build();
Format lowerSampleRateHigherBitrateFormat = formatBuilder.setAverageBitrate(30000).setSampleRate(22050).build();
TrackGroupArray trackGroups = wrapFormats(higherSampleRateLowerBitrateFormat, lowerSampleRateHigherBitrateFormat);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, lowerSampleRateHigherBitrateFormat);
}
Aggregations