Search in sources :

Example 1 with FixedTrackSelection

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

the class TrackSelectionUtil method createTrackSelectionsForDefinitions.

/**
 * Creates track selections for an array of track selection definitions, with at most one
 * multi-track adaptive selection.
 *
 * @param definitions The list of track selection {@link Definition definitions}. May include null
 *     values.
 * @param adaptiveTrackSelectionFactory A factory for the multi-track adaptive track selection.
 * @return The array of created track selection. For null entries in {@code definitions} returns
 *     null values.
 */
@NullableType
public static ExoTrackSelection[] createTrackSelectionsForDefinitions(@NullableType Definition[] definitions, AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory) {
    ExoTrackSelection[] selections = new ExoTrackSelection[definitions.length];
    boolean createdAdaptiveTrackSelection = false;
    for (int i = 0; i < definitions.length; i++) {
        Definition definition = definitions[i];
        if (definition == null) {
            continue;
        }
        if (definition.tracks.length > 1 && !createdAdaptiveTrackSelection) {
            createdAdaptiveTrackSelection = true;
            selections[i] = adaptiveTrackSelectionFactory.createAdaptiveTrackSelection(definition);
        } else {
            selections[i] = new FixedTrackSelection(definition.group, definition.tracks[0], /* type= */
            definition.type);
        }
    }
    return selections;
}
Also used : Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType)

Example 2 with FixedTrackSelection

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

the class MergingMediaPeriodTest method selectTracks_createsSampleStreamsFromChildPeriods.

@Test
public void selectTracks_createsSampleStreamsFromChildPeriods() throws Exception {
    MergingMediaPeriod mergingMediaPeriod = prepareMergingPeriod(new MergingPeriodDefinition(/* timeOffsetUs= */
    0, /* singleSampleTimeUs= */
    0, childFormat11, childFormat12), new MergingPeriodDefinition(/* timeOffsetUs= */
    0, /* singleSampleTimeUs= */
    0, childFormat21, childFormat22));
    ExoTrackSelection selectionForChild1 = new FixedTrackSelection(mergingMediaPeriod.getTrackGroups().get(1), /* track= */
    0);
    ExoTrackSelection selectionForChild2 = new FixedTrackSelection(mergingMediaPeriod.getTrackGroups().get(2), /* track= */
    0);
    SampleStream[] streams = new SampleStream[4];
    mergingMediaPeriod.selectTracks(/* selections= */
    new ExoTrackSelection[] { null, selectionForChild1, selectionForChild2, null }, /* mayRetainStreamFlags= */
    new boolean[] { false, false, false, false }, streams, /* streamResetFlags= */
    new boolean[] { false, false, false, false }, /* positionUs= */
    0);
    mergingMediaPeriod.continueLoading(/* positionUs= */
    0);
    assertThat(streams[0]).isNull();
    assertThat(streams[3]).isNull();
    FormatHolder formatHolder = new FormatHolder();
    DecoderInputBuffer inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
    assertThat(streams[1].readData(formatHolder, inputBuffer, FLAG_REQUIRE_FORMAT)).isEqualTo(C.RESULT_FORMAT_READ);
    assertThat(formatHolder.format).isEqualTo(childFormat12);
    assertThat(streams[2].readData(formatHolder, inputBuffer, FLAG_REQUIRE_FORMAT)).isEqualTo(C.RESULT_FORMAT_READ);
    assertThat(formatHolder.format).isEqualTo(childFormat21);
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) FormatHolder(com.google.android.exoplayer2.FormatHolder) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) Test(org.junit.Test)

Example 3 with FixedTrackSelection

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

the class DefaultTrackSelectorTest method selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect.

/**
 * Tests that an empty override is not applied for a different set of available track groups.
 */
@Test
public void selectTracks_withEmptyTrackOverrideForDifferentTracks_hasNoEffect() throws ExoPlaybackException {
    TrackGroup videoGroup0 = VIDEO_TRACK_GROUP.copyWithId("0");
    TrackGroup videoGroup1 = VIDEO_TRACK_GROUP.copyWithId("1");
    trackSelector.setParameters(trackSelector.buildUponParameters().setTrackSelectionOverrides(new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(new TrackGroup(VIDEO_FORMAT, VIDEO_FORMAT), ImmutableList.of())).build()));
    TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, new TrackGroupArray(videoGroup0, AUDIO_TRACK_GROUP, videoGroup1), periodId, TIMELINE);
    assertThat(result.selections).asList().containsExactly(new FixedTrackSelection(videoGroup0, /* track= */
    0), new FixedTrackSelection(AUDIO_TRACK_GROUP, /* track= */
    0)).inOrder();
    assertThat(result.rendererConfigurations).isEqualTo(new RendererConfiguration[] { DEFAULT, DEFAULT });
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 4 with FixedTrackSelection

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

the class DefaultTrackSelectorTest method selectTrack_withOverrideForDifferentRenderer_clearsDefaultSelectionOfSameType.

@Test
public void selectTrack_withOverrideForDifferentRenderer_clearsDefaultSelectionOfSameType() throws Exception {
    Format videoFormatH264 = VIDEO_FORMAT.buildUpon().setId("H264").setSampleMimeType(MimeTypes.VIDEO_H264).build();
    Format videoFormatAv1 = VIDEO_FORMAT.buildUpon().setId("AV1").setSampleMimeType(MimeTypes.VIDEO_AV1).build();
    TrackGroup videoGroupH264 = new TrackGroup(videoFormatH264);
    TrackGroup videoGroupAv1 = new TrackGroup(videoFormatAv1);
    Map<String, Integer> rendererCapabilitiesMap = ImmutableMap.of(videoFormatH264.id, FORMAT_HANDLED, videoFormatAv1.id, FORMAT_UNSUPPORTED_TYPE);
    RendererCapabilities rendererCapabilitiesH264 = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    rendererCapabilitiesMap = ImmutableMap.of(videoFormatH264.id, FORMAT_UNSUPPORTED_TYPE, videoFormatAv1.id, FORMAT_HANDLED);
    RendererCapabilities rendererCapabilitiesAv1 = new FakeMappedRendererCapabilities(C.TRACK_TYPE_VIDEO, rendererCapabilitiesMap);
    // Try to force selection of one TrackGroup in both directions to ensure the default gets
    // overridden without having to know what the default is.
    trackSelector.setParameters(trackSelector.buildUponParameters().setTrackSelectionOverrides(new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(videoGroupH264)).build()));
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilitiesH264, rendererCapabilitiesAv1 }, new TrackGroupArray(videoGroupH264, videoGroupAv1), periodId, TIMELINE);
    assertThat(result.selections).asList().containsExactly(new FixedTrackSelection(videoGroupH264, /* track= */
    0), null).inOrder();
    trackSelector.setParameters(trackSelector.buildUponParameters().setTrackSelectionOverrides(new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(videoGroupAv1)).build()));
    result = trackSelector.selectTracks(new RendererCapabilities[] { rendererCapabilitiesH264, rendererCapabilitiesAv1 }, new TrackGroupArray(videoGroupH264, videoGroupAv1), periodId, TIMELINE);
    assertThat(result.selections).asList().containsExactly(null, new FixedTrackSelection(videoGroupAv1, /* track= */
    0)).inOrder();
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 5 with FixedTrackSelection

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

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