Search in sources :

Example 11 with FormatSupport

use of com.google.android.exoplayer2.C.FormatSupport in project ExoPlayer by google.

the class DefaultTrackSelector method selectOtherTrack.

// Generic track selection methods.
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link ExoTrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The {@link Capabilities} for each mapped track, indexed by track group and
 *     track (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link ExoTrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected ExoTrackSelection.Definition selectOtherTrack(int trackType, TrackGroupArray groups, @Capabilities int[][] formatSupport, Parameters params) throws ExoPlaybackException {
    @Nullable TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    @Nullable OtherTrackScore selectedTrackScore = null;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        @Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                OtherTrackScore trackScore = new OtherTrackScore(format, trackFormatSupport[trackIndex]);
                if (selectedTrackScore == null || trackScore.compareTo(selectedTrackScore) > 0) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                }
            }
        }
    }
    return selectedGroup == null ? null : new ExoTrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Example 12 with FormatSupport

use of com.google.android.exoplayer2.C.FormatSupport in project ExoPlayer by google.

the class MappingTrackSelector method findRenderer.

/**
 * Finds the renderer to which the provided {@link TrackGroup} should be mapped.
 *
 * <p>A {@link TrackGroup} is mapped to the renderer that reports the highest of (listed in
 * decreasing order of support) {@link C#FORMAT_HANDLED}, {@link C#FORMAT_EXCEEDS_CAPABILITIES},
 * {@link C#FORMAT_UNSUPPORTED_DRM} and {@link C#FORMAT_UNSUPPORTED_SUBTYPE}.
 *
 * <p>In the case that two or more renderers report the same level of support, the assignment
 * depends on {@code preferUnassociatedRenderer}.
 *
 * <ul>
 *   <li>If {@code preferUnassociatedRenderer} is false, the renderer with the lowest index is
 *       chosen regardless of how many other track groups are already mapped to this renderer.
 *   <li>If {@code preferUnassociatedRenderer} is true, the renderer with the lowest index and no
 *       other mapped track group is chosen, or the renderer with the lowest index if all
 *       available renderers have already mapped track groups.
 * </ul>
 *
 * <p>If all renderers report {@link C#FORMAT_UNSUPPORTED_TYPE} for all of the tracks in the
 * group, then {@code renderers.length} is returned to indicate that the group was not mapped to
 * any renderer.
 *
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
 * @param group The track group to map to a renderer.
 * @param rendererTrackGroupCounts The number of already mapped track groups for each renderer.
 * @param preferUnassociatedRenderer Whether renderers unassociated to any track group should be
 *     preferred.
 * @return The index of the renderer to which the track group was mapped, or {@code
 *     renderers.length} if it was not mapped to any renderer.
 * @throws ExoPlaybackException If an error occurs finding a renderer.
 */
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group, int[] rendererTrackGroupCounts, boolean preferUnassociatedRenderer) throws ExoPlaybackException {
    int bestRendererIndex = rendererCapabilities.length;
    @FormatSupport int bestFormatSupportLevel = C.FORMAT_UNSUPPORTED_TYPE;
    boolean bestRendererIsUnassociated = true;
    for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
        RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
        @FormatSupport int formatSupportLevel = C.FORMAT_UNSUPPORTED_TYPE;
        for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
            @FormatSupport int trackFormatSupportLevel = RendererCapabilities.getFormatSupport(rendererCapability.supportsFormat(group.getFormat(trackIndex)));
            formatSupportLevel = max(formatSupportLevel, trackFormatSupportLevel);
        }
        boolean rendererIsUnassociated = rendererTrackGroupCounts[rendererIndex] == 0;
        if (formatSupportLevel > bestFormatSupportLevel || (formatSupportLevel == bestFormatSupportLevel && preferUnassociatedRenderer && !bestRendererIsUnassociated && rendererIsUnassociated)) {
            bestRendererIndex = rendererIndex;
            bestFormatSupportLevel = formatSupportLevel;
            bestRendererIsUnassociated = rendererIsUnassociated;
        }
    }
    return bestRendererIndex;
}
Also used : FormatSupport(com.google.android.exoplayer2.C.FormatSupport) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities)

Example 13 with FormatSupport

use of com.google.android.exoplayer2.C.FormatSupport in project NewPipe by TeamNewPipe.

the class CustomTrackSelector method selectTextTrack.

/**
 * @see DefaultTrackSelector#selectTextTrack(TrackGroupArray, int[][], Parameters)
 */
@Override
protected TrackSelection selectTextTrack(TrackGroupArray groups, int[][] formatSupport, Parameters params) throws ExoPlaybackException {
    TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    int selectedTrackScore = 0;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                int maskedSelectionFlags = format.selectionFlags & ~params.disabledTextTrackSelectionFlags;
                boolean isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                boolean isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
                int trackScore;
                boolean preferredLanguageFound = formatHasLanguage(format, preferredTextLanguage);
                if (preferredLanguageFound || (params.selectUndeterminedTextLanguage && formatHasNoLanguage(format))) {
                    if (isDefault) {
                        trackScore = 8;
                    } else if (!isForced) {
                        // Prefer non-forced to forced if a preferred text language has been specified. Where
                        // both are provided the non-forced track will usually contain the forced subtitles as
                        // a subset.
                        trackScore = 6;
                    } else {
                        trackScore = 4;
                    }
                    trackScore += preferredLanguageFound ? 1 : 0;
                } else if (isDefault) {
                    trackScore = 3;
                } else if (isForced) {
                    if (formatHasLanguage(format, params.preferredAudioLanguage)) {
                        trackScore = 2;
                    } else {
                        trackScore = 1;
                    }
                } else {
                    // Track should not be selected.
                    continue;
                }
                if (isSupported(trackFormatSupport[trackIndex], false)) {
                    trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
                }
                if (trackScore > selectedTrackScore) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                }
            }
        }
    }
    return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection)

Aggregations

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