use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracks_withPreferredAudioRoleFlags_selectPreferredTrack.
/**
* Tests that track selector will select the audio track with the highest number of matching role
* flags given by {@link Parameters}.
*/
@Test
public void selectTracks_withPreferredAudioRoleFlags_selectPreferredTrack() throws Exception {
Format.Builder formatBuilder = AUDIO_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().setPreferredAudioRoleFlags(C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_COMMENTARY));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_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().setPreferredAudioRoleFlags(C.ROLE_FLAG_CAPTION));
result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_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 selectTracksWithMultipleAudioTracksWithMixedChannelCounts.
@Test
public void selectTracksWithMultipleAudioTracksWithMixedChannelCounts() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format stereoAudioFormat = formatBuilder.setChannelCount(2).build();
Format surroundAudioFormat = formatBuilder.setChannelCount(5).build();
// Should not adapt between different channel counts, so we expect a fixed selection containing
// the track with more channels.
TrackGroupArray trackGroups = singleTrackGroup(stereoAudioFormat, surroundAudioFormat);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
// The same applies if the tracks are provided in the opposite order.
trackGroups = singleTrackGroup(surroundAudioFormat, stereoAudioFormat);
result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
// If we constrain the channel count to 4 we expect a fixed selection containing the track with
// fewer channels.
trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(4));
result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we constrain the channel count to 2 we expect a fixed selection containing the track with
// fewer channels.
trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(2));
result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we constrain the channel count to 1 we expect a fixed selection containing the track with
// fewer channels.
trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(1));
result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we disable exceeding of constraints we expect no selection.
trackSelector.setParameters(defaultParameters.buildUpon().setMaxAudioChannelCount(1).setExceedAudioConstraintsIfNecessary(false));
result = trackSelector.selectTracks(new RendererCapabilities[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertNoSelection(result.selections[0]);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack.
/**
* Tests that track selector will select a track that exceeds the renderer's capabilities when
* there are no other choice, given the default {@link Parameters}.
*/
@Test
public void selectTracksWithNoTrackWithinCapabilitiesSelectExceededCapabilityTrack() throws Exception {
TrackGroupArray trackGroups = singleTrackGroup(AUDIO_FORMAT);
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_EXCEEDED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, AUDIO_FORMAT);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksWithinCapabilitiesAndForceHighestBitrateSelectHigherBitrate.
/**
* Tests that track selector will select the highest bitrate supported audio track when {@link
* Parameters#forceHighestSupportedBitrate} is set.
*/
@Test
public void selectTracksWithinCapabilitiesAndForceHighestBitrateSelectHigherBitrate() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format lowerBitrateFormat = formatBuilder.setId("5000").setAverageBitrate(5000).build();
Format higherBitrateFormat = formatBuilder.setId("15000").setAverageBitrate(15000).build();
Format exceedsBitrateFormat = formatBuilder.setId("30000").setAverageBitrate(30000).build();
TrackGroupArray trackGroups = wrapFormats(lowerBitrateFormat, higherBitrateFormat, exceedsBitrateFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(lowerBitrateFormat.id, FORMAT_HANDLED);
mappedCapabilities.put(higherBitrateFormat.id, FORMAT_HANDLED);
mappedCapabilities.put(exceedsBitrateFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
trackSelector.setParameters(defaultParameters.buildUpon().setForceHighestSupportedBitrate(true));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, higherBitrateFormat);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectorResult in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage.
/**
* Tests that track selector will prefer tracks that are within renderer's capabilities over track
* that have language matching preferred audio given by {@link Parameters} but exceed renderer's
* capabilities.
*/
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverPreferredLanguage() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format exceededEnFormat = formatBuilder.setId("exceededFormat").setLanguage("eng").build();
Format supportedFrFormat = formatBuilder.setId("supportedFormat").setLanguage("fra").build();
TrackGroupArray trackGroups = wrapFormats(exceededEnFormat, supportedFrFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(exceededEnFormat.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);
}
Aggregations