Search in sources :

Example 6 with FormatSupport

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

the class DefaultTrackSelector method selectAudioTrack.

// Audio track selection implementation.
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport, String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
    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], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                int trackScore;
                if (formatHasLanguage(format, preferredAudioLanguage)) {
                    if (isDefault) {
                        trackScore = 4;
                    } else {
                        trackScore = 3;
                    }
                } else if (isDefault) {
                    trackScore = 2;
                } else {
                    trackScore = 1;
                }
                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) Point(android.graphics.Point)

Example 7 with FormatSupport

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

the class DefaultTrackSelector method selectOtherTrack.

// General track selection methods.
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups, int[][] formatSupport, boolean exceedRendererCapabilitiesIfNecessary) {
    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], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                int trackScore = isDefault ? 2 : 1;
                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) Point(android.graphics.Point)

Example 8 with FormatSupport

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

the class DefaultTrackSelector method selectTextTrack.

// Text track selection implementation.
protected TrackSelection selectTextTrack(TrackGroupArray groups, int[][] formatSupport, String preferredTextLanguage, String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
    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], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                boolean isForced = (format.selectionFlags & C.SELECTION_FLAG_FORCED) != 0;
                int trackScore;
                if (formatHasLanguage(format, preferredTextLanguage)) {
                    if (isDefault) {
                        trackScore = 6;
                    } 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 = 5;
                    } else {
                        trackScore = 4;
                    }
                } else if (isDefault) {
                    trackScore = 3;
                } else if (isForced) {
                    if (formatHasLanguage(format, 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) Point(android.graphics.Point)

Example 9 with FormatSupport

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

the class DefaultTrackSelector method selectAdaptiveVideoTrack.

private static TrackSelection selectAdaptiveVideoTrack(RendererCapabilities rendererCapabilities, TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight, int maxVideoBitrate, boolean allowNonSeamlessAdaptiveness, boolean allowMixedMimeAdaptiveness, int viewportWidth, int viewportHeight, boolean orientationMayChange, TrackSelection.Factory adaptiveVideoTrackSelectionFactory) throws ExoPlaybackException {
    int requiredAdaptiveSupport = allowNonSeamlessAdaptiveness ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS) : RendererCapabilities.ADAPTIVE_SEAMLESS;
    boolean allowMixedMimeTypes = allowMixedMimeAdaptiveness && (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
    for (int i = 0; i < groups.length; i++) {
        TrackGroup group = groups.get(i);
        int[] adaptiveTracks = getAdaptiveTracksForGroup(group, formatSupport[i], allowMixedMimeTypes, requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight, maxVideoBitrate, viewportWidth, viewportHeight, orientationMayChange);
        if (adaptiveTracks.length > 0) {
            return adaptiveVideoTrackSelectionFactory.createTrackSelection(group, adaptiveTracks);
        }
    }
    return null;
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Point(android.graphics.Point)

Example 10 with FormatSupport

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

the class DefaultTrackSelector method selectFixedVideoTrack.

private static TrackSelection selectFixedVideoTrack(TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight, boolean orientationMayChange, boolean exceedConstraintsIfNecessary, boolean exceedRendererCapabilitiesIfNecessary) {
    TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    int selectedTrackScore = 0;
    int selectedBitrate = Format.NO_VALUE;
    int selectedPixelCount = Format.NO_VALUE;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, viewportWidth, viewportHeight, orientationMayChange);
        int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isWithinConstraints = selectedTrackIndices.contains(trackIndex) && (format.width == Format.NO_VALUE || format.width <= maxVideoWidth) && (format.height == Format.NO_VALUE || format.height <= maxVideoHeight) && (format.bitrate == Format.NO_VALUE || format.bitrate <= maxVideoBitrate);
                if (!isWithinConstraints && !exceedConstraintsIfNecessary) {
                    // Track should not be selected.
                    continue;
                }
                int trackScore = isWithinConstraints ? 2 : 1;
                if (isSupported(trackFormatSupport[trackIndex], false)) {
                    trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
                }
                boolean selectTrack = trackScore > selectedTrackScore;
                if (trackScore == selectedTrackScore) {
                    // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If we're
                    // within constraints prefer a higher pixel count (or bitrate), else prefer a lower
                    // count (or bitrate). If still tied then prefer the first track (i.e. the one that's
                    // already selected).
                    int comparisonResult;
                    int formatPixelCount = format.getPixelCount();
                    if (formatPixelCount != selectedPixelCount) {
                        comparisonResult = compareFormatValues(format.getPixelCount(), selectedPixelCount);
                    } else {
                        comparisonResult = compareFormatValues(format.bitrate, selectedBitrate);
                    }
                    selectTrack = isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0;
                }
                if (selectTrack) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                    selectedBitrate = format.bitrate;
                    selectedPixelCount = format.getPixelCount();
                }
            }
        }
    }
    return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Point(android.graphics.Point)

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