Search in sources :

Example 1 with Definition

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

the class DefaultTrackSelector method getLegacyRendererOverride.

// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
    TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
    @Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
    if (override == null) {
        return null;
    }
    return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Nullable(androidx.annotation.Nullable)

Example 2 with Definition

use of com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition 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 3 with Definition

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

the class MergingMediaPeriodTest method prepareMergingPeriod.

private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
    MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
    long[] timeOffsetsUs = new long[definitions.length];
    for (int i = 0; i < definitions.length; i++) {
        MergingPeriodDefinition definition = definitions[i];
        timeOffsetsUs[i] = definition.timeOffsetUs;
        TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
        for (int j = 0; j < definition.formats.length; j++) {
            trackGroups[j] = new TrackGroup(definition.formats[j]);
        }
        mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
        i, new MediaPeriodId(/* periodUid= */
        i), /* mediaTimeOffsetMs= */
        0), /* trackDataFactory= */
        (unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
    }
    MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
    CountDownLatch prepareCountDown = new CountDownLatch(1);
    mergingMediaPeriod.prepare(new MediaPeriod.Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            prepareCountDown.countDown();
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
            mergingMediaPeriod.continueLoading(/* positionUs= */
            0);
        }
    }, /* positionUs= */
    0);
    prepareCountDown.await();
    return mergingMediaPeriod;
}
Also used : FLAG_REQUIRE_FORMAT(com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) Format(com.google.android.exoplayer2.Format) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) CountDownLatch(java.util.concurrent.CountDownLatch) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) FormatHolder(com.google.android.exoplayer2.FormatHolder) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ImmutableList(com.google.common.collect.ImmutableList) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) CountDownLatch(java.util.concurrent.CountDownLatch) EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod)

Example 4 with Definition

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

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
    Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
    Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
    Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
    Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
    Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
    Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
    Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
    TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
    TrackGroup fixedGroup = new TrackGroup(fixedFormat);
    Definition definition1 = new Definition(trackGroup1, /* tracks...= */
    0, 1);
    Definition definition2 = new Definition(trackGroup2, /* tracks...= */
    0, 1, 2);
    Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
    0);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(2);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2000)).inOrder();
    assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    250), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1250), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2500)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 5 with Definition

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

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints() {
    Format formatFixed1 = new Format.Builder().setAverageBitrate(500).build();
    Format formatFixed2 = new Format.Builder().setAverageBitrate(1000).build();
    Format formatAdaptive1 = new Format.Builder().setAverageBitrate(2000).build();
    Format formatAdaptive2 = new Format.Builder().setAverageBitrate(3000).build();
    Format formatAdaptive3 = new Format.Builder().setAverageBitrate(4000).build();
    Format formatAdaptive4 = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
    TrackGroup trackGroupAdaptive = new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
    Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    0);
    Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    1);
    Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */
    1, 2, 3);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definitionFixed1, null, definitionFixed2, definitionAdaptive }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(1);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    4500, /* allocatedBandwidth= */
    3000), new AdaptationCheckpoint(/* totalBandwidth= */
    5500, /* allocatedBandwidth= */
    4000), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    5000), new AdaptationCheckpoint(/* totalBandwidth= */
    11500, /* allocatedBandwidth= */
    10000)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)3 Definition (com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition)3 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)3 Test (org.junit.Test)3 Nullable (androidx.annotation.Nullable)2 Timeline (com.google.android.exoplayer2.Timeline)2 MediaSource (com.google.android.exoplayer2.source.MediaSource)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 AdaptationCheckpoint (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)2 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)2 BandwidthMeter (com.google.android.exoplayer2.upstream.BandwidthMeter)2 List (java.util.List)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Pair (android.util.Pair)1