use of com.google.android.exoplayer2.RendererCapabilities 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.RendererCapabilities 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.RendererCapabilities 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);
}
use of com.google.android.exoplayer2.RendererCapabilities in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage.
/**
* Tests that track selector will prefer tracks that are within renderer's capabilities over track
* that have both language matching preferred audio given by {@link Parameters} and {@link
* C#SELECTION_FLAG_DEFAULT}, but exceed renderer's capabilities.
*/
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format exceededDefaultSelectionEnFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setLanguage("eng").build();
Format supportedFrFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).setLanguage("fra").build();
TrackGroupArray trackGroups = wrapFormats(exceededDefaultSelectionEnFormat, supportedFrFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(exceededDefaultSelectionEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
mappedCapabilities.put(supportedFrFormat.id, FORMAT_HANDLED);
RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("eng"));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
}
use of com.google.android.exoplayer2.RendererCapabilities in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferHigherSampleRateBeforeBitrate.
/**
* Tests that track selector will prefer audio tracks with higher sample rate over tracks with
* higher bitrate when other factors are the same, and tracks are within renderer's capabilities.
*/
@Test
public void selectTracksPreferHigherSampleRateBeforeBitrate() 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_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, higherSampleRateLowerBitrateFormat);
}
Aggregations