Search in sources :

Example 16 with FixedTrackSelection

use of com.google.android.exoplayer2.trackselection.FixedTrackSelection 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)13 Test (org.junit.Test)9 Format (com.google.android.exoplayer2.Format)6 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)6 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)6 Point (android.graphics.Point)4 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)3 FormatHolder (com.google.android.exoplayer2.FormatHolder)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 ChunkHolder (com.google.android.exoplayer2.source.chunk.ChunkHolder)2 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)2 DashManifestParser (com.google.android.exoplayer2.source.dash.manifest.DashManifestParser)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 LoaderErrorThrower (com.google.android.exoplayer2.upstream.LoaderErrorThrower)2 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)1 TracksInfo (com.google.android.exoplayer2.TracksInfo)1 TrackGroupInfo (com.google.android.exoplayer2.TracksInfo.TrackGroupInfo)1 Definition (com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition)1