Search in sources :

Example 1 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride in project ExoPlayer by google.

the class TrackSelectionHelper method onClick.

// View.OnClickListener
@Override
public void onClick(View view) {
    if (view == disableView) {
        isDisabled = true;
        override = null;
    } else if (view == defaultView) {
        isDisabled = false;
        override = null;
    } else if (view == enableRandomAdaptationView) {
        setOverride(override.groupIndex, override.tracks, !enableRandomAdaptationView.isChecked());
    } else {
        isDisabled = false;
        @SuppressWarnings("unchecked") Pair<Integer, Integer> tag = (Pair<Integer, Integer>) view.getTag();
        int groupIndex = tag.first;
        int trackIndex = tag.second;
        if (!trackGroupsAdaptive[groupIndex] || override == null || override.groupIndex != groupIndex) {
            override = new SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex);
        } else {
            // The group being modified is adaptive and we already have a non-null override.
            boolean isEnabled = ((CheckedTextView) view).isChecked();
            int overrideLength = override.length;
            if (isEnabled) {
                // Remove the track from the override.
                if (overrideLength == 1) {
                    // The last track is being removed, so the override becomes empty.
                    override = null;
                    isDisabled = true;
                } else {
                    setOverride(groupIndex, getTracksRemoving(override, trackIndex), enableRandomAdaptationView.isChecked());
                }
            } else {
                // Add the track to the override.
                setOverride(groupIndex, getTracksAdding(override, trackIndex), enableRandomAdaptationView.isChecked());
            }
        }
    }
    // Update the views with the new state.
    updateViews();
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) CheckedTextView(android.widget.CheckedTextView) SuppressLint(android.annotation.SuppressLint) Pair(android.util.Pair) SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)

Example 2 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride in project LeafPic by HoraApps.

the class TrackSelectionHelper method onClick.

// View.OnClickListener
@Override
public void onClick(View view) {
    isDisabled = false;
    @SuppressWarnings("unchecked") Pair<Integer, Integer> tag = (Pair<Integer, Integer>) view.getTag();
    int groupIndex = tag.first;
    int trackIndex = tag.second;
    if (!trackGroupsAdaptive[groupIndex] || override == null || override.groupIndex != groupIndex) {
        override = new SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex);
    } else {
        // The group being modified is adaptive and we already have a non-null override.
        boolean isEnabled = ((CheckedTextView) view).isChecked();
        int overrideLength = override.length;
        if (isEnabled) {
            // Remove the track from the override.
            if (overrideLength == 1) {
                // The last track is being removed, so the override becomes empty.
                override = null;
                isDisabled = true;
            } else {
                setOverride(groupIndex, getTracksRemoving(override, trackIndex), false);
            }
        } else {
            // Add the track to the override.
            setOverride(groupIndex, getTracksAdding(override, trackIndex), false);
        }
    }
    // Update the views with the new state.
    updateViews();
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) CheckedTextView(android.widget.CheckedTextView) SuppressLint(android.annotation.SuppressLint) Pair(android.util.Pair) SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)

Example 3 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride in project LeafPic by HoraApps.

the class TrackSelectionHelper method setOverride.

private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveVideoTrackSelectionFactory);
    override = new SelectionOverride(factory, group, tracks);
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) RandomTrackSelection(com.google.android.exoplayer2.trackselection.RandomTrackSelection)

Example 4 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride in project ExoPlayer by google.

the class TrackSelectionHelper method setOverride.

private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveTrackSelectionFactory);
    override = new SelectionOverride(factory, group, tracks);
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) RandomTrackSelection(com.google.android.exoplayer2.trackselection.RandomTrackSelection)

Example 5 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride in project ExoPlayer by google.

the class MappingTrackSelector method selectTracks.

// TrackSelector implementation.
@Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups) 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][];
    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.
    int[] mixedMimeTypeAdaptationSupport = getMixedMimeTypeAdaptationSupport(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.
        int rendererIndex = findRenderer(rendererCapabilities, group);
        // Evaluate the support that the renderer provides for each track in the group.
        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];
    int[] rendererTrackTypes = new int[rendererCapabilities.length];
    for (int i = 0; i < rendererCapabilities.length; i++) {
        int rendererTrackGroupCount = rendererTrackGroupCounts[i];
        rendererTrackGroupArrays[i] = new TrackGroupArray(Arrays.copyOf(rendererTrackGroups[i], rendererTrackGroupCount));
        rendererFormatSupports[i] = Arrays.copyOf(rendererFormatSupports[i], rendererTrackGroupCount);
        rendererTrackTypes[i] = rendererCapabilities[i].getTrackType();
    }
    // Create a track group array for track groups not associated with a renderer.
    int unassociatedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
    TrackGroupArray unassociatedTrackGroupArray = new TrackGroupArray(Arrays.copyOf(rendererTrackGroups[rendererCapabilities.length], unassociatedTrackGroupCount));
    TrackSelection[] trackSelections = selectTracks(rendererCapabilities, rendererTrackGroupArrays, rendererFormatSupports);
    // Apply track disabling and overriding.
    for (int i = 0; i < rendererCapabilities.length; i++) {
        if (rendererDisabledFlags.get(i)) {
            trackSelections[i] = null;
        } else {
            TrackGroupArray rendererTrackGroup = rendererTrackGroupArrays[i];
            Map<TrackGroupArray, SelectionOverride> overrides = selectionOverrides.get(i);
            SelectionOverride override = overrides == null ? null : overrides.get(rendererTrackGroup);
            if (override != null) {
                trackSelections[i] = override.createTrackSelection(rendererTrackGroup);
            }
        }
    }
    // Package up the track information and selections.
    MappedTrackInfo mappedTrackInfo = new MappedTrackInfo(rendererTrackTypes, rendererTrackGroupArrays, mixedMimeTypeAdaptationSupport, rendererFormatSupports, unassociatedTrackGroupArray);
    // Initialize the renderer configurations to the default configuration for all renderers with
    // selections, and null otherwise.
    RendererConfiguration[] rendererConfigurations = new RendererConfiguration[rendererCapabilities.length];
    for (int i = 0; i < rendererCapabilities.length; i++) {
        rendererConfigurations[i] = trackSelections[i] != null ? RendererConfiguration.DEFAULT : null;
    }
    // Configure audio and video renderers to use tunneling if appropriate.
    maybeConfigureRenderersForTunneling(rendererCapabilities, rendererTrackGroupArrays, rendererFormatSupports, rendererConfigurations, trackSelections, tunnelingAudioSessionId);
    return new TrackSelectorResult(trackGroups, new TrackSelectionArray(trackSelections), mappedTrackInfo, rendererConfigurations);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration)

Aggregations

SelectionOverride (com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)4 SuppressLint (android.annotation.SuppressLint)2 Pair (android.util.Pair)2 CheckedTextView (android.widget.CheckedTextView)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 RandomTrackSelection (com.google.android.exoplayer2.trackselection.RandomTrackSelection)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1