Search in sources :

Example 66 with RendererCapabilities

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

the class DefaultTrackSelectorTest method selectTracksWithinCapabilitiesAndForceLowestBitrateSelectLowerBitrate.

/**
 * Tests that track selector will select the lowest bitrate supported audio track when {@link
 * Parameters#forceLowestBitrate} is set.
 */
@Test
public void selectTracksWithinCapabilitiesAndForceLowestBitrateSelectLowerBitrate() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format unsupportedLowBitrateFormat = formatBuilder.setId("unsupported").setAverageBitrate(5000).build();
    Format lowerBitrateFormat = formatBuilder.setId("lower").setAverageBitrate(15000).build();
    Format higherBitrateFormat = formatBuilder.setId("higher").setAverageBitrate(30000).build();
    TrackGroupArray trackGroups = wrapFormats(unsupportedLowBitrateFormat, lowerBitrateFormat, higherBitrateFormat);
    Map<String, Integer> mappedCapabilities = new HashMap<>();
    mappedCapabilities.put(unsupportedLowBitrateFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
    mappedCapabilities.put(lowerBitrateFormat.id, FORMAT_HANDLED);
    mappedCapabilities.put(higherBitrateFormat.id, FORMAT_HANDLED);
    RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
    trackSelector.setParameters(defaultParameters.buildUpon().setForceLowestBitrate(true));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, lowerBitrateFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) HashMap(java.util.HashMap) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 67 with RendererCapabilities

use of com.google.android.exoplayer2.RendererCapabilities 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)

Aggregations

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)59 Test (org.junit.Test)57 Format (com.google.android.exoplayer2.Format)47 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)36 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)11 HashMap (java.util.HashMap)8 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)5 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)4 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)3 Nullable (androidx.annotation.Nullable)2 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)2 SelectionOverride (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)2 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)2 Point (android.graphics.Point)1 Handler (android.os.Handler)1 FormatSupport (com.google.android.exoplayer2.C.FormatSupport)1 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)1 Renderer (com.google.android.exoplayer2.Renderer)1 AdaptiveSupport (com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)1 TracksInfo (com.google.android.exoplayer2.TracksInfo)1