use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class MappingTrackSelectorTest method buildTrackInfos_withTestValues_isAsExpected.
@Test
public void buildTrackInfos_withTestValues_isAsExpected() {
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = new MappingTrackSelector.MappedTrackInfo(new String[] { "1", "2" }, new int[] { C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_VIDEO }, new TrackGroupArray[] { new TrackGroupArray(new TrackGroup("0", new Format.Builder().build()), new TrackGroup("1", new Format.Builder().build())), new TrackGroupArray(new TrackGroup("2", new Format.Builder().build(), new Format.Builder().build())) }, new int[] { RendererCapabilities.ADAPTIVE_SEAMLESS, RendererCapabilities.ADAPTIVE_NOT_SUPPORTED }, new int[][][] { new int[][] { new int[] { C.FORMAT_HANDLED }, new int[] { C.FORMAT_UNSUPPORTED_SUBTYPE } }, new int[][] { new int[] { C.FORMAT_UNSUPPORTED_DRM, C.FORMAT_EXCEEDS_CAPABILITIES } } }, new TrackGroupArray(new TrackGroup(new Format.Builder().build())));
TrackSelection[] selections = new TrackSelection[] { new FixedTrackSelection(mappedTrackInfo.getTrackGroups(0).get(1), 0), new FixedTrackSelection(mappedTrackInfo.getTrackGroups(1).get(0), 1) };
TracksInfo tracksInfo = MappingTrackSelector.buildTracksInfo(selections, mappedTrackInfo);
ImmutableList<TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
assertThat(trackGroupInfos).hasSize(4);
assertThat(trackGroupInfos.get(0).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
assertThat(trackGroupInfos.get(1).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
assertThat(trackGroupInfos.get(2).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(1).get(0));
assertThat(trackGroupInfos.get(3).getTrackGroup()).isEqualTo(mappedTrackInfo.getUnmappedTrackGroups().get(0));
assertThat(trackGroupInfos.get(0).getTrackSupport(0)).isEqualTo(C.FORMAT_HANDLED);
assertThat(trackGroupInfos.get(1).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_SUBTYPE);
assertThat(trackGroupInfos.get(2).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_DRM);
assertThat(trackGroupInfos.get(2).getTrackSupport(1)).isEqualTo(C.FORMAT_EXCEEDS_CAPABILITIES);
assertThat(trackGroupInfos.get(3).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_TYPE);
assertThat(trackGroupInfos.get(0).isTrackSelected(0)).isFalse();
assertThat(trackGroupInfos.get(1).isTrackSelected(0)).isTrue();
assertThat(trackGroupInfos.get(2).isTrackSelected(0)).isFalse();
assertThat(trackGroupInfos.get(2).isTrackSelected(1)).isTrue();
assertThat(trackGroupInfos.get(3).isTrackSelected(0)).isFalse();
assertThat(trackGroupInfos.get(0).getTrackType()).isEqualTo(C.TRACK_TYPE_AUDIO);
assertThat(trackGroupInfos.get(1).getTrackType()).isEqualTo(C.TRACK_TYPE_AUDIO);
assertThat(trackGroupInfos.get(2).getTrackType()).isEqualTo(C.TRACK_TYPE_VIDEO);
assertThat(trackGroupInfos.get(3).getTrackType()).isEqualTo(C.TRACK_TYPE_UNKNOWN);
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class DownloadHelper method addTextLanguagesToSelection.
/**
* Convenience method to add selections of tracks for all specified text languages. Must not be
* called until after preparation completes.
*
* @param selectUndeterminedTextLanguage Whether a text track with undetermined language should be
* selected for downloading if no track with one of the specified {@code languages} is
* available.
* @param languages A list of text languages for which tracks should be added to the download
* selection, as IETF BCP 47 conformant tags.
*/
public void addTextLanguagesToSelection(boolean selectUndeterminedTextLanguage, String... languages) {
assertPreparedWithMedia();
for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) {
DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT.buildUpon();
MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex];
int rendererCount = mappedTrackInfo.getRendererCount();
for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_TEXT) {
parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */
true);
}
}
parametersBuilder.setSelectUndeterminedTextLanguage(selectUndeterminedTextLanguage);
for (String language : languages) {
parametersBuilder.setPreferredTextLanguage(language);
addTrackSelection(periodIndex, parametersBuilder.build());
}
}
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class TrackSelectionView method init.
/**
* Initialize the view to select tracks for a specified renderer using {@link MappedTrackInfo} and
* a set of {@link DefaultTrackSelector.Parameters}.
*
* @param mappedTrackInfo The {@link MappedTrackInfo}.
* @param rendererIndex The index of the renderer.
* @param isDisabled Whether the renderer should be initially shown as disabled.
* @param overrides List of initial overrides to be shown for this renderer. There must be at most
* one override for each track group. If {@link #setAllowMultipleOverrides(boolean)} hasn't
* been set to {@code true}, only the first override is used.
* @param trackFormatComparator An optional comparator used to determine the display order of the
* tracks within each track group.
* @param listener An optional listener for track selection updates.
*/
public void init(MappedTrackInfo mappedTrackInfo, int rendererIndex, boolean isDisabled, List<SelectionOverride> overrides, @Nullable Comparator<Format> trackFormatComparator, @Nullable TrackSelectionListener listener) {
this.mappedTrackInfo = mappedTrackInfo;
this.rendererIndex = rendererIndex;
this.isDisabled = isDisabled;
this.trackInfoComparator = trackFormatComparator == null ? null : (o1, o2) -> trackFormatComparator.compare(o1.format, o2.format);
this.listener = listener;
int maxOverrides = allowMultipleOverrides ? overrides.size() : Math.min(overrides.size(), 1);
for (int i = 0; i < maxOverrides; i++) {
SelectionOverride override = overrides.get(i);
this.overrides.put(override.groupIndex, override);
}
updateViews();
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class TrackSelectionView method onTrackViewClicked.
private void onTrackViewClicked(View view) {
isDisabled = false;
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(view.getTag());
int groupIndex = trackInfo.groupIndex;
int trackIndex = trackInfo.trackIndex;
SelectionOverride override = overrides.get(groupIndex);
Assertions.checkNotNull(mappedTrackInfo);
if (override == null) {
// Start new override.
if (!allowMultipleOverrides && overrides.size() > 0) {
// Removed other overrides if we don't allow multiple overrides.
overrides.clear();
}
overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
} else {
// An existing override is being modified.
int overrideLength = override.length;
int[] overrideTracks = override.tracks;
boolean isCurrentlySelected = ((CheckedTextView) view).isChecked();
boolean isAdaptiveAllowed = shouldEnableAdaptiveSelection(groupIndex);
boolean isUsingCheckBox = isAdaptiveAllowed || shouldEnableMultiGroupSelection();
if (isCurrentlySelected && isUsingCheckBox) {
// Remove the track from the override.
if (overrideLength == 1) {
// The last track is being removed, so the override becomes empty.
overrides.remove(groupIndex);
} else {
int[] tracks = getTracksRemoving(overrideTracks, trackIndex);
overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
}
} else if (!isCurrentlySelected) {
if (isAdaptiveAllowed) {
// Add new track to adaptive override.
int[] tracks = getTracksAdding(overrideTracks, trackIndex);
overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
} else {
// Replace existing track in override.
overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
}
}
}
}
use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.
the class DefaultTrackSelector method maybeConfigureRenderersForTunneling.
// Utility methods.
/**
* Determines whether tunneling can be enabled, replacing {@link RendererConfiguration}s in {@code
* rendererConfigurations} with configurations that enable tunneling on the appropriate renderers
* if so.
*
* @param mappedTrackInfo Mapped track information.
* @param renderererFormatSupports The {@link Capabilities} for each mapped track, indexed by
* renderer, track group and track (in that order).
* @param rendererConfigurations The renderer configurations. Configurations may be replaced with
* ones that enable tunneling as a result of this call.
* @param trackSelections The renderer track selections.
*/
private static void maybeConfigureRenderersForTunneling(MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] renderererFormatSupports, @NullableType RendererConfiguration[] rendererConfigurations, @NullableType ExoTrackSelection[] trackSelections) {
// Check whether we can enable tunneling. To enable tunneling we require exactly one audio and
// one video renderer to support tunneling and have a selection.
int tunnelingAudioRendererIndex = -1;
int tunnelingVideoRendererIndex = -1;
boolean enableTunneling = true;
for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
int rendererType = mappedTrackInfo.getRendererType(i);
ExoTrackSelection trackSelection = trackSelections[i];
if ((rendererType == C.TRACK_TYPE_AUDIO || rendererType == C.TRACK_TYPE_VIDEO) && trackSelection != null) {
if (rendererSupportsTunneling(renderererFormatSupports[i], mappedTrackInfo.getTrackGroups(i), trackSelection)) {
if (rendererType == C.TRACK_TYPE_AUDIO) {
if (tunnelingAudioRendererIndex != -1) {
enableTunneling = false;
break;
} else {
tunnelingAudioRendererIndex = i;
}
} else {
if (tunnelingVideoRendererIndex != -1) {
enableTunneling = false;
break;
} else {
tunnelingVideoRendererIndex = i;
}
}
}
}
}
enableTunneling &= tunnelingAudioRendererIndex != -1 && tunnelingVideoRendererIndex != -1;
if (enableTunneling) {
RendererConfiguration tunnelingRendererConfiguration = new RendererConfiguration(/* tunneling= */
true);
rendererConfigurations[tunnelingAudioRendererIndex] = tunnelingRendererConfiguration;
rendererConfigurations[tunnelingVideoRendererIndex] = tunnelingRendererConfiguration;
}
}
Aggregations