Search in sources :

Example 6 with FormatSupport

use of androidx.media3.common.C.FormatSupport 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

RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)6 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)3 Nullable (androidx.annotation.Nullable)3 TrackGroup (androidx.media3.common.TrackGroup)3 Capabilities (androidx.media3.exoplayer.RendererCapabilities.Capabilities)3 TrackGroupArray (androidx.media3.common.TrackGroupArray)2 MediaCodecInfo (androidx.media3.exoplayer.mediacodec.MediaCodecInfo)2 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)1 FormatSupport (androidx.media3.common.C.FormatSupport)1 DrmInitData (androidx.media3.common.DrmInitData)1 Format (androidx.media3.common.Format)1 Metadata (androidx.media3.common.Metadata)1 TrackSelection (androidx.media3.common.TrackSelection)1 Util.getFormatSupportString (androidx.media3.common.util.Util.getFormatSupportString)1 MappedTrackInfo (androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1