use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.
the class DefaultTrackSelectorTest method roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance.
/**
* Tests {@link SelectionOverride}'s {@link Bundleable} implementation.
*/
@Test
public void roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance() {
SelectionOverride selectionOverrideToBundle = new SelectionOverride(/* groupIndex= */
1, /* tracks...= */
2, 3);
SelectionOverride selectionOverrideFromBundle = DefaultTrackSelector.SelectionOverride.CREATOR.fromBundle(selectionOverrideToBundle.toBundle());
assertThat(selectionOverrideFromBundle).isEqualTo(selectionOverrideToBundle);
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride 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.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.
the class TrackSelectionHelper method setOverride.
private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveTrackSelectionFactory);
override = new SelectionOverride(factory, group, tracks);
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.
the class MappingTrackSelector method selectTracks.
// TrackSelector implementation.
@Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups) throws ExoPlaybackException {
// Structures into which data will be written during the selection. The extra item at the end
// of each array is to store data associated with track groups that cannot be associated with
// any renderer.
int[] rendererTrackGroupCounts = new int[rendererCapabilities.length + 1];
TrackGroup[][] rendererTrackGroups = new TrackGroup[rendererCapabilities.length + 1][];
int[][][] rendererFormatSupports = new int[rendererCapabilities.length + 1][][];
for (int i = 0; i < rendererTrackGroups.length; i++) {
rendererTrackGroups[i] = new TrackGroup[trackGroups.length];
rendererFormatSupports[i] = new int[trackGroups.length][];
}
// Determine the extent to which each renderer supports mixed mimeType adaptation.
int[] mixedMimeTypeAdaptationSupport = getMixedMimeTypeAdaptationSupport(rendererCapabilities);
// renderer provides for each track in the group.
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
TrackGroup group = trackGroups.get(groupIndex);
// Associate the group to a preferred renderer.
int rendererIndex = findRenderer(rendererCapabilities, group);
// Evaluate the support that the renderer provides for each track in the group.
int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length ? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
// Stash the results.
int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
rendererTrackGroupCounts[rendererIndex]++;
}
// Create a track group array for each renderer, and trim each rendererFormatSupports entry.
TrackGroupArray[] rendererTrackGroupArrays = new TrackGroupArray[rendererCapabilities.length];
int[] rendererTrackTypes = new int[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
int rendererTrackGroupCount = rendererTrackGroupCounts[i];
rendererTrackGroupArrays[i] = new TrackGroupArray(Arrays.copyOf(rendererTrackGroups[i], rendererTrackGroupCount));
rendererFormatSupports[i] = Arrays.copyOf(rendererFormatSupports[i], rendererTrackGroupCount);
rendererTrackTypes[i] = rendererCapabilities[i].getTrackType();
}
// Create a track group array for track groups not associated with a renderer.
int unassociatedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
TrackGroupArray unassociatedTrackGroupArray = new TrackGroupArray(Arrays.copyOf(rendererTrackGroups[rendererCapabilities.length], unassociatedTrackGroupCount));
TrackSelection[] trackSelections = selectTracks(rendererCapabilities, rendererTrackGroupArrays, rendererFormatSupports);
// Apply track disabling and overriding.
for (int i = 0; i < rendererCapabilities.length; i++) {
if (rendererDisabledFlags.get(i)) {
trackSelections[i] = null;
} else {
TrackGroupArray rendererTrackGroup = rendererTrackGroupArrays[i];
Map<TrackGroupArray, SelectionOverride> overrides = selectionOverrides.get(i);
SelectionOverride override = overrides == null ? null : overrides.get(rendererTrackGroup);
if (override != null) {
trackSelections[i] = override.createTrackSelection(rendererTrackGroup);
}
}
}
// Package up the track information and selections.
MappedTrackInfo mappedTrackInfo = new MappedTrackInfo(rendererTrackTypes, rendererTrackGroupArrays, mixedMimeTypeAdaptationSupport, rendererFormatSupports, unassociatedTrackGroupArray);
// Initialize the renderer configurations to the default configuration for all renderers with
// selections, and null otherwise.
RendererConfiguration[] rendererConfigurations = new RendererConfiguration[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
rendererConfigurations[i] = trackSelections[i] != null ? RendererConfiguration.DEFAULT : null;
}
// Configure audio and video renderers to use tunneling if appropriate.
maybeConfigureRenderersForTunneling(rendererCapabilities, rendererTrackGroupArrays, rendererFormatSupports, rendererConfigurations, trackSelections, tunnelingAudioSessionId);
return new TrackSelectorResult(trackGroups, new TrackSelectionArray(trackSelections), mappedTrackInfo, rendererConfigurations);
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksWithMultipleAudioTracksOverrideReturnsAdaptiveTrackSelection.
@Test
public void selectTracksWithMultipleAudioTracksOverrideReturnsAdaptiveTrackSelection() throws Exception {
Format.Builder formatBuilder = AUDIO_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[] { AUDIO_CAPABILITIES }, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 1, 2);
}
Aggregations