Search in sources :

Example 31 with MappedTrackInfo

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());
        }
    }
}
Also used : DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 32 with MappedTrackInfo

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();
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) AttrRes(androidx.annotation.AttrRes) Arrays(java.util.Arrays) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) AttributeSet(android.util.AttributeSet) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) View(android.view.View) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) C(com.google.android.exoplayer2.C) LayoutInflater(android.view.LayoutInflater) SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull) SparseArray(android.util.SparseArray) List(java.util.List) Nullable(androidx.annotation.Nullable) CheckedTextView(android.widget.CheckedTextView) Comparator(java.util.Comparator) Assertions(com.google.android.exoplayer2.util.Assertions) SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)

Example 33 with MappedTrackInfo

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));
            }
        }
    }
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) CheckedTextView(android.widget.CheckedTextView)

Example 34 with MappedTrackInfo

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;
    }
}
Also used : RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 35 with MappedTrackInfo

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo in project ExoPlayer by google.

the class DefaultTrackSelector method selectTracks.

// MappingTrackSelector implementation.
@Override
protected final Pair<@NullableType RendererConfiguration[], @NullableType ExoTrackSelection[]> selectTracks(MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] rendererFormatSupports, @AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports, MediaPeriodId mediaPeriodId, Timeline timeline) throws ExoPlaybackException {
    Parameters params = parametersReference.get();
    int rendererCount = mappedTrackInfo.getRendererCount();
    ExoTrackSelection.@NullableType Definition[] definitions = selectAllTracks(mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports, params);
    // Apply per track type overrides.
    SparseArray<Pair<TrackSelectionOverride, Integer>> applicableOverridesByTrackType = getApplicableOverrides(mappedTrackInfo, params);
    for (int i = 0; i < applicableOverridesByTrackType.size(); i++) {
        Pair<TrackSelectionOverride, Integer> overrideAndRendererIndex = applicableOverridesByTrackType.valueAt(i);
        applyTrackTypeOverride(mappedTrackInfo, definitions, /* trackType= */
        applicableOverridesByTrackType.keyAt(i), /* override= */
        overrideAndRendererIndex.first, /* overrideRendererIndex= */
        overrideAndRendererIndex.second);
    }
    // Apply legacy per renderer overrides.
    for (int i = 0; i < rendererCount; i++) {
        if (hasLegacyRendererOverride(mappedTrackInfo, params, /* rendererIndex= */
        i)) {
            definitions[i] = getLegacyRendererOverride(mappedTrackInfo, params, /* rendererIndex= */
            i);
        }
    }
    // Disable renderers if needed.
    for (int i = 0; i < rendererCount; i++) {
        if (isRendererDisabled(mappedTrackInfo, params, /* rendererIndex= */
        i)) {
            definitions[i] = null;
        }
    }
    @NullableType ExoTrackSelection[] rendererTrackSelections = trackSelectionFactory.createTrackSelections(definitions, getBandwidthMeter(), mediaPeriodId, timeline);
    // Initialize the renderer configurations to the default configuration for all renderers with
    // selections, and null otherwise.
    @NullableType RendererConfiguration[] rendererConfigurations = new RendererConfiguration[rendererCount];
    for (int i = 0; i < rendererCount; i++) {
        @C.TrackType int rendererType = mappedTrackInfo.getRendererType(i);
        boolean forceRendererDisabled = params.getRendererDisabled(i) || params.disabledTrackTypes.contains(rendererType);
        boolean rendererEnabled = !forceRendererDisabled && (mappedTrackInfo.getRendererType(i) == C.TRACK_TYPE_NONE || rendererTrackSelections[i] != null);
        rendererConfigurations[i] = rendererEnabled ? RendererConfiguration.DEFAULT : null;
    }
    // Configure audio and video renderers to use tunneling if appropriate.
    if (params.tunnelingEnabled) {
        maybeConfigureRenderersForTunneling(mappedTrackInfo, rendererFormatSupports, rendererConfigurations, rendererTrackSelections);
    }
    return Pair.create(rendererConfigurations, rendererTrackSelections);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) Pair(android.util.Pair) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)

Aggregations

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)24 MappedTrackInfo (com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)21 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)18 Nullable (androidx.annotation.Nullable)11 Point (android.graphics.Point)10 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)10 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)10 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)8 SuppressLint (android.annotation.SuppressLint)7 Format (com.google.android.exoplayer2.Format)7 CheckedTextView (android.widget.CheckedTextView)6 SelectionOverride (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)6 ArrayList (java.util.ArrayList)6 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)5 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)5 List (java.util.List)5 SparseArray (android.util.SparseArray)3 TracksInfo (com.google.android.exoplayer2.TracksInfo)3 Metadata (com.google.android.exoplayer2.metadata.Metadata)3 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)3