Search in sources :

Example 21 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

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(androidx.media3.common.TrackGroupArray) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TrackGroup(androidx.media3.common.TrackGroup) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Capabilities(androidx.media3.exoplayer.RendererCapabilities.Capabilities) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Nullable(androidx.annotation.Nullable)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)11 TrackGroup (androidx.media3.common.TrackGroup)8 MappedTrackInfo (androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo)8 SuppressLint (android.annotation.SuppressLint)5 Point (android.graphics.Point)5 Nullable (androidx.annotation.Nullable)5 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)5 Capabilities (androidx.media3.exoplayer.RendererCapabilities.Capabilities)4 DefaultTrackSelector (androidx.media3.exoplayer.trackselection.DefaultTrackSelector)4 CheckedTextView (android.widget.CheckedTextView)3 TrackSelection (androidx.media3.common.TrackSelection)3 TracksInfo (androidx.media3.common.TracksInfo)3 SelectionOverride (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Pair (android.util.Pair)2 SparseArray (android.util.SparseArray)2 Format (androidx.media3.common.Format)2 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)2 RendererConfiguration (androidx.media3.exoplayer.RendererConfiguration)2