Search in sources :

Example 6 with AdaptiveSupport

use of com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport in project ExoPlayer by google.

the class MappingTrackSelector method selectTracks.

@Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups, MediaPeriodId periodId, Timeline timeline) throws ExoPlaybackException {
    // Structures into which data will be written during the selection. The extra item at the end
    // of each array is to store data associated with track groups that cannot be associated with
    // any renderer.
    int[] rendererTrackGroupCounts = new int[rendererCapabilities.length + 1];
    TrackGroup[][] rendererTrackGroups = new TrackGroup[rendererCapabilities.length + 1][];
    @Capabilities int[][][] rendererFormatSupports = new int[rendererCapabilities.length + 1][][];
    for (int i = 0; i < rendererTrackGroups.length; i++) {
        rendererTrackGroups[i] = new TrackGroup[trackGroups.length];
        rendererFormatSupports[i] = new int[trackGroups.length][];
    }
    // Determine the extent to which each renderer supports mixed mimeType adaptation.
    @AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports = getMixedMimeTypeAdaptationSupports(rendererCapabilities);
    // renderer provides for each track in the group.
    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup group = trackGroups.get(groupIndex);
        // Associate the group to a preferred renderer.
        boolean preferUnassociatedRenderer = MimeTypes.getTrackType(group.getFormat(0).sampleMimeType) == C.TRACK_TYPE_METADATA;
        int rendererIndex = findRenderer(rendererCapabilities, group, rendererTrackGroupCounts, preferUnassociatedRenderer);
        // Evaluate the support that the renderer provides for each track in the group.
        @Capabilities int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length ? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
        // Stash the results.
        int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
        rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
        rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
        rendererTrackGroupCounts[rendererIndex]++;
    }
    // Create a track group array for each renderer, and trim each rendererFormatSupports entry.
    TrackGroupArray[] rendererTrackGroupArrays = new TrackGroupArray[rendererCapabilities.length];
    String[] rendererNames = new String[rendererCapabilities.length];
    int[] rendererTrackTypes = new int[rendererCapabilities.length];
    for (int i = 0; i < rendererCapabilities.length; i++) {
        int rendererTrackGroupCount = rendererTrackGroupCounts[i];
        rendererTrackGroupArrays[i] = new TrackGroupArray(Util.nullSafeArrayCopy(rendererTrackGroups[i], rendererTrackGroupCount));
        rendererFormatSupports[i] = Util.nullSafeArrayCopy(rendererFormatSupports[i], rendererTrackGroupCount);
        rendererNames[i] = rendererCapabilities[i].getName();
        rendererTrackTypes[i] = rendererCapabilities[i].getTrackType();
    }
    // Create a track group array for track groups not mapped to a renderer.
    int unmappedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
    TrackGroupArray unmappedTrackGroupArray = new TrackGroupArray(Util.nullSafeArrayCopy(rendererTrackGroups[rendererCapabilities.length], unmappedTrackGroupCount));
    // Package up the track information and selections.
    MappedTrackInfo mappedTrackInfo = new MappedTrackInfo(rendererNames, rendererTrackTypes, rendererTrackGroupArrays, rendererMixedMimeTypeAdaptationSupports, rendererFormatSupports, unmappedTrackGroupArray);
    Pair<@NullableType RendererConfiguration[], @NullableType ExoTrackSelection[]> result = selectTracks(mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports, periodId, timeline);
    TracksInfo tracksInfo = buildTracksInfo(result.second, mappedTrackInfo);
    return new TrackSelectorResult(result.first, result.second, tracksInfo, mappedTrackInfo);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) TracksInfo(com.google.android.exoplayer2.TracksInfo) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) AdaptiveSupport(com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)

Example 7 with AdaptiveSupport

use of com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport in project ExoPlayer by google.

the class DefaultTrackSelector method selectTracks.

// MappingTrackSelector implementation.
@Override
protected final Pair<@NullableType RendererConfiguration[], @NullableType ExoTrackSelection[]> selectTracks(MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] rendererFormatSupports, @AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports, MediaPeriodId mediaPeriodId, Timeline timeline) throws ExoPlaybackException {
    Parameters params = parametersReference.get();
    int rendererCount = mappedTrackInfo.getRendererCount();
    ExoTrackSelection.@NullableType Definition[] definitions = selectAllTracks(mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports, params);
    // Apply per track type overrides.
    SparseArray<Pair<TrackSelectionOverride, Integer>> applicableOverridesByTrackType = getApplicableOverrides(mappedTrackInfo, params);
    for (int i = 0; i < applicableOverridesByTrackType.size(); i++) {
        Pair<TrackSelectionOverride, Integer> overrideAndRendererIndex = applicableOverridesByTrackType.valueAt(i);
        applyTrackTypeOverride(mappedTrackInfo, definitions, /* trackType= */
        applicableOverridesByTrackType.keyAt(i), /* override= */
        overrideAndRendererIndex.first, /* overrideRendererIndex= */
        overrideAndRendererIndex.second);
    }
    // Apply legacy per renderer overrides.
    for (int i = 0; i < rendererCount; i++) {
        if (hasLegacyRendererOverride(mappedTrackInfo, params, /* rendererIndex= */
        i)) {
            definitions[i] = getLegacyRendererOverride(mappedTrackInfo, params, /* rendererIndex= */
            i);
        }
    }
    // Disable renderers if needed.
    for (int i = 0; i < rendererCount; i++) {
        if (isRendererDisabled(mappedTrackInfo, params, /* rendererIndex= */
        i)) {
            definitions[i] = null;
        }
    }
    @NullableType ExoTrackSelection[] rendererTrackSelections = trackSelectionFactory.createTrackSelections(definitions, getBandwidthMeter(), mediaPeriodId, timeline);
    // Initialize the renderer configurations to the default configuration for all renderers with
    // selections, and null otherwise.
    @NullableType RendererConfiguration[] rendererConfigurations = new RendererConfiguration[rendererCount];
    for (int i = 0; i < rendererCount; i++) {
        @C.TrackType int rendererType = mappedTrackInfo.getRendererType(i);
        boolean forceRendererDisabled = params.getRendererDisabled(i) || params.disabledTrackTypes.contains(rendererType);
        boolean rendererEnabled = !forceRendererDisabled && (mappedTrackInfo.getRendererType(i) == C.TRACK_TYPE_NONE || rendererTrackSelections[i] != null);
        rendererConfigurations[i] = rendererEnabled ? RendererConfiguration.DEFAULT : null;
    }
    // Configure audio and video renderers to use tunneling if appropriate.
    if (params.tunnelingEnabled) {
        maybeConfigureRenderersForTunneling(mappedTrackInfo, rendererFormatSupports, rendererConfigurations, rendererTrackSelections);
    }
    return Pair.create(rendererConfigurations, rendererTrackSelections);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) Pair(android.util.Pair) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)

Aggregations

RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)4 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)4 SuppressLint (android.annotation.SuppressLint)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 Point (android.graphics.Point)2 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)2 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 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)2 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)1 Pair (android.util.Pair)1 Nullable (androidx.annotation.Nullable)1 AdaptiveSupport (com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)1 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)1 TracksInfo (com.google.android.exoplayer2.TracksInfo)1 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)1 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1 Util.getFormatSupportString (com.google.android.exoplayer2.util.Util.getFormatSupportString)1