Search in sources :

Example 6 with MappedTrackInfo

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

the class TrackSelectionDialog method showTabForRenderer.

private static boolean showTabForRenderer(MappedTrackInfo mappedTrackInfo, int rendererIndex) {
    TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
    if (trackGroupArray.length == 0) {
        return false;
    }
    int trackType = mappedTrackInfo.getRendererType(rendererIndex);
    return isSupportedTrackType(trackType);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 7 with MappedTrackInfo

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

the class TrackSelectionDialog method createForTrackSelector.

/**
 * Creates a dialog for a given {@link DefaultTrackSelector}, whose parameters will be
 * automatically updated when tracks are selected.
 *
 * @param trackSelector The {@link DefaultTrackSelector}.
 * @param onDismissListener A {@link DialogInterface.OnDismissListener} to call when the dialog is
 *     dismissed.
 */
public static TrackSelectionDialog createForTrackSelector(DefaultTrackSelector trackSelector, DialogInterface.OnDismissListener onDismissListener) {
    MappedTrackInfo mappedTrackInfo = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
    TrackSelectionDialog trackSelectionDialog = new TrackSelectionDialog();
    DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
    trackSelectionDialog.init(/* titleId= */
    R.string.track_selection_title, mappedTrackInfo, /* initialParameters = */
    parameters, /* allowAdaptiveSelections= */
    true, /* allowMultipleOverrides= */
    false, /* onClickListener= */
    (dialog, which) -> {
        DefaultTrackSelector.ParametersBuilder builder = parameters.buildUpon();
        for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
            builder.clearSelectionOverrides(/* rendererIndex= */
            i).setRendererDisabled(/* rendererIndex= */
            i, trackSelectionDialog.getIsDisabled(/* rendererIndex= */
            i));
            List<SelectionOverride> overrides = trackSelectionDialog.getOverrides(/* rendererIndex= */
            i);
            if (!overrides.isEmpty()) {
                builder.setSelectionOverride(/* rendererIndex= */
                i, mappedTrackInfo.getTrackGroups(/* rendererIndex= */
                i), overrides.get(0));
            }
        }
        trackSelector.setParameters(builder);
    }, onDismissListener);
    return trackSelectionDialog;
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 8 with MappedTrackInfo

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

the class DefaultTrackSelector method selectTracksForType.

@Nullable
private <T extends TrackInfo<T>> Pair<ExoTrackSelection.Definition, Integer> selectTracksForType(@C.TrackType int trackType, MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] formatSupport, TrackInfo.Factory<T> trackInfoFactory, Comparator<List<T>> selectionComparator) {
    ArrayList<List<T>> possibleSelections = new ArrayList<>();
    int rendererCount = mappedTrackInfo.getRendererCount();
    for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
        if (trackType == mappedTrackInfo.getRendererType(rendererIndex)) {
            TrackGroupArray groups = mappedTrackInfo.getTrackGroups(rendererIndex);
            for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
                TrackGroup trackGroup = groups.get(groupIndex);
                @Capabilities int[] groupSupport = formatSupport[rendererIndex][groupIndex];
                List<T> trackInfos = trackInfoFactory.create(rendererIndex, trackGroup, groupSupport);
                boolean[] usedTrackInSelection = new boolean[trackGroup.length];
                for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                    T trackInfo = trackInfos.get(trackIndex);
                    @SelectionEligibility int eligibility = trackInfo.getSelectionEligibility();
                    if (usedTrackInSelection[trackIndex] || eligibility == SELECTION_ELIGIBILITY_NO) {
                        continue;
                    }
                    List<T> selection;
                    if (eligibility == SELECTION_ELIGIBILITY_FIXED) {
                        selection = ImmutableList.of(trackInfo);
                    } else {
                        selection = new ArrayList<>();
                        selection.add(trackInfo);
                        for (int i = trackIndex + 1; i < trackGroup.length; i++) {
                            T otherTrackInfo = trackInfos.get(i);
                            if (otherTrackInfo.getSelectionEligibility() == SELECTION_ELIGIBILITY_ADAPTIVE) {
                                if (trackInfo.isCompatibleForAdaptationWith(otherTrackInfo)) {
                                    selection.add(otherTrackInfo);
                                    usedTrackInSelection[i] = true;
                                }
                            }
                        }
                    }
                    possibleSelections.add(selection);
                }
            }
        }
    }
    if (possibleSelections.isEmpty()) {
        return null;
    }
    List<T> bestSelection = max(possibleSelections, selectionComparator);
    int[] trackIndices = new int[bestSelection.size()];
    for (int i = 0; i < bestSelection.size(); i++) {
        trackIndices[i] = bestSelection.get(i).trackIndex;
    }
    T firstTrackInfo = bestSelection.get(0);
    return Pair.create(new ExoTrackSelection.Definition(firstTrackInfo.trackGroup, trackIndices), firstTrackInfo.rendererIndex);
}
Also used : ArrayList(java.util.ArrayList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Nullable(androidx.annotation.Nullable)

Example 9 with MappedTrackInfo

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

the class DefaultTrackSelector method getLegacyRendererOverride.

// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
    TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
    @Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
    if (override == null) {
        return null;
    }
    return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Nullable(androidx.annotation.Nullable)

Example 10 with MappedTrackInfo

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

the class MappingTrackSelector method buildTracksInfo.

@VisibleForTesting
static /* package */
TracksInfo buildTracksInfo(@NullableType TrackSelection[] selections, MappedTrackInfo mappedTrackInfo) {
    ImmutableList.Builder<TracksInfo.TrackGroupInfo> builder = new ImmutableList.Builder<>();
    for (int rendererIndex = 0; rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex++) {
        TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
        @Nullable TrackSelection trackSelection = selections[rendererIndex];
        for (int groupIndex = 0; groupIndex < trackGroupArray.length; groupIndex++) {
            TrackGroup trackGroup = trackGroupArray.get(groupIndex);
            @C.FormatSupport int[] trackSupport = new int[trackGroup.length];
            boolean[] selected = new boolean[trackGroup.length];
            for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                trackSupport[trackIndex] = mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex);
                boolean isTrackSelected = trackSelection != null && trackSelection.getTrackGroup().equals(trackGroup) && trackSelection.indexOf(trackIndex) != C.INDEX_UNSET;
                selected[trackIndex] = isTrackSelected;
            }
            @C.TrackType int trackGroupType = mappedTrackInfo.getRendererType(rendererIndex);
            builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
        }
    }
    TrackGroupArray unmappedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
    for (int groupIndex = 0; groupIndex < unmappedTrackGroups.length; groupIndex++) {
        TrackGroup trackGroup = unmappedTrackGroups.get(groupIndex);
        @C.FormatSupport int[] trackSupport = new int[trackGroup.length];
        Arrays.fill(trackSupport, C.FORMAT_UNSUPPORTED_TYPE);
        // A track group only contains tracks of the same type, thus only consider the first track.
        @C.TrackType int trackGroupType = MimeTypes.getTrackType(trackGroup.getFormat(0).sampleMimeType);
        // Initialized to false.
        boolean[] selected = new boolean[trackGroup.length];
        builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
    }
    return new TracksInfo(builder.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TracksInfo(com.google.android.exoplayer2.TracksInfo) FormatSupport(com.google.android.exoplayer2.C.FormatSupport) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Nullable(androidx.annotation.Nullable) VisibleForTesting(androidx.annotation.VisibleForTesting)

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