Search in sources :

Example 71 with Timeline

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

the class ServerSideAdInsertionMediaSourceTest method timeline_containsAdsDefinedInAdPlaybackState.

@Test
public void timeline_containsAdsDefinedInAdPlaybackState() throws Exception {
    FakeTimeline wrappedTimeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    10_000_000, /* defaultPositionUs= */
    3_000_000, /* windowOffsetInFirstPeriodUs= */
    42_000_000L, AdPlaybackState.NONE));
    ServerSideAdInsertionMediaSource mediaSource = new ServerSideAdInsertionMediaSource(new FakeMediaSource(wrappedTimeline), /* adPlaybackStateUpdater= */
    null);
    // Test with one ad group before the window, and the window starting within the second ad group.
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    15_000_000, 41_500_000, 42_200_000).withIsServerSideInserted(/* adGroupIndex= */
    0, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    1, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    1, /* adCount= */
    2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    1).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    500_000).withAdDurationsUs(/* adGroupIndex= */
    1, /* adDurationsUs...= */
    300_000, 100_000).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    400_000).withContentResumeOffsetUs(/* adGroupIndex= */
    0, /* contentResumeOffsetUs= */
    100_000).withContentResumeOffsetUs(/* adGroupIndex= */
    1, /* contentResumeOffsetUs= */
    400_000).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    200_000);
    AtomicReference<Timeline> timelineReference = new AtomicReference<>();
    mediaSource.setAdPlaybackStates(ImmutableMap.of(new Pair<>(0, 0), adPlaybackState));
    mediaSource.prepareSource((source, timeline) -> timelineReference.set(timeline), /* mediaTransferListener= */
    null, PlayerId.UNSET);
    runMainLooperUntil(() -> timelineReference.get() != null);
    Timeline timeline = timelineReference.get();
    assertThat(timeline.getPeriodCount()).isEqualTo(1);
    Timeline.Period period = timeline.getPeriod(/* periodIndex= */
    0, new Timeline.Period());
    assertThat(period.getAdGroupCount()).isEqualTo(3);
    assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
    0)).isEqualTo(1);
    assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
    1)).isEqualTo(2);
    assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
    2)).isEqualTo(1);
    assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
    0)).isEqualTo(15_000_000);
    assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
    1)).isEqualTo(41_500_000);
    assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
    2)).isEqualTo(42_200_000);
    assertThat(period.getAdDurationUs(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0)).isEqualTo(500_000);
    assertThat(period.getAdDurationUs(/* adGroupIndex= */
    1, /* adIndexInAdGroup= */
    0)).isEqualTo(300_000);
    assertThat(period.getAdDurationUs(/* adGroupIndex= */
    1, /* adIndexInAdGroup= */
    1)).isEqualTo(100_000);
    assertThat(period.getAdDurationUs(/* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    0)).isEqualTo(400_000);
    assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
    0)).isEqualTo(100_000);
    assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
    1)).isEqualTo(400_000);
    assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
    2)).isEqualTo(200_000);
    // windowDurationUs + windowOffsetInFirstPeriodUs - sum(adDurations) + sum(contentResumeOffsets)
    assertThat(period.getDurationUs()).isEqualTo(51_400_000);
    // positionInWindowUs + sum(adDurationsBeforeWindow) - sum(contentResumeOffsetsBeforeWindow)
    assertThat(period.getPositionInWindowUs()).isEqualTo(-41_600_000);
    Timeline.Window window = timeline.getWindow(/* windowIndex= */
    0, new Timeline.Window());
    assertThat(window.positionInFirstPeriodUs).isEqualTo(41_600_000);
    // windowDurationUs - sum(adDurationsInWindow) + sum(applicableContentResumeOffsetUs)
    assertThat(window.durationUs).isEqualTo(9_800_000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) Pair(android.util.Pair) Test(org.junit.Test)

Example 72 with Timeline

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

the class ServerSideAdInsertionUtilTest method addAdGroupToAdPlaybackState_insertsCorrectAdGroupData.

@Test
public void addAdGroupToAdPlaybackState_insertsCorrectAdGroupData() {
    AdPlaybackState state = new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 1, C.TIME_END_OF_SOURCE).withRemovedAdGroupCount(2);
    // stream: 0-- content --4300-- ad1 --4500-- content
    // content timeline: 0-4300 - [ad1] - 4700-end
    state = addAdGroupToAdPlaybackState(state, /* fromPositionUs= */
    4300, /* contentResumeOffsetUs= */
    400, /* adDurationsUs...= */
    200);
    assertThat(state).isEqualTo(new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 4300, C.TIME_END_OF_SOURCE).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    1).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    200));
    // stream: 0-- content --2100-- ad1 --2400-- content --4300-- ad2 --4500-- content
    // content timeline: 0-2100 - [ad1] - 2100-4000 - [ad2] - 4400-end
    state = addAdGroupToAdPlaybackState(state, /* fromPositionUs= */
    2100, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    300);
    assertThat(state).isEqualTo(new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 2100, 4000, C.TIME_END_OF_SOURCE).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    3, /* adCount= */
    1).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    3, /* isServerSideInserted= */
    true).withContentResumeOffsetUs(/* adGroupIndex= */
    3, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    300).withAdDurationsUs(/* adGroupIndex= */
    3, /* adDurationsUs...= */
    200));
    // stream: 0-- ad1 --100-- content --2100-- ad2 --2400-- content --4300-- ad3 --4500-- content
    // content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-end
    state = addAdGroupToAdPlaybackState(state, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    50, /* adDurationsUs...= */
    100);
    assertThat(state).isEqualTo(new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 0, 2050, 3950, C.TIME_END_OF_SOURCE).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    3, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    4, /* adCount= */
    1).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    3, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    4, /* isServerSideInserted= */
    true).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    50).withContentResumeOffsetUs(/* adGroupIndex= */
    4, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    100).withAdDurationsUs(/* adGroupIndex= */
    3, /* adDurationsUs...= */
    300).withAdDurationsUs(/* adGroupIndex= */
    4, /* adDurationsUs...= */
    200));
    // stream: 0-- ad1 --100-- c --2100-- ad2 --2400-- c --4300-- ad3 --4500-- c --5000-- ad4 --6000
    // content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-4850 - [ad4] - 4850
    state = addAdGroupToAdPlaybackState(state, /* fromPositionUs= */
    5000, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    1000);
    assertThat(state).isEqualTo(new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 0, 2050, 3950, 4850, C.TIME_END_OF_SOURCE).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    3, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    4, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    5, /* adCount= */
    1).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    3, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    4, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    5, /* isServerSideInserted= */
    true).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    50).withContentResumeOffsetUs(/* adGroupIndex= */
    4, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    100).withAdDurationsUs(/* adGroupIndex= */
    3, /* adDurationsUs...= */
    300).withAdDurationsUs(/* adGroupIndex= */
    4, /* adDurationsUs...= */
    200).withAdDurationsUs(/* adGroupIndex= */
    5, /* adDurationsUs...= */
    1000));
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Test(org.junit.Test)

Example 73 with Timeline

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

the class ServerSideAdInsertionUtilTest method getMediaPeriodPositionUsForContent_returnsCorrectPositions.

@Test
public void getMediaPeriodPositionUsForContent_returnsCorrectPositions() {
    // stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
    // content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
    AdPlaybackState state = new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 0, 2000, 4000).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    2).withAdCount(/* adGroupIndex= */
    3, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    4, /* adCount= */
    3).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    100).withContentResumeOffsetUs(/* adGroupIndex= */
    3, /* contentResumeOffsetUs= */
    0).withContentResumeOffsetUs(/* adGroupIndex= */
    4, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    150, 50).withAdDurationsUs(/* adGroupIndex= */
    3, /* adDurationsUs...= */
    200).withAdDurationsUs(/* adGroupIndex= */
    4, /* adDurationsUs...= */
    50, 50, 100);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    0, /* nextAdGroupIndex= */
    2, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    0, /* nextAdGroupIndex= */
    3, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    0, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    100, /* nextAdGroupIndex= */
    2, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    100, /* nextAdGroupIndex= */
    3, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    100, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    200, /* nextAdGroupIndex= */
    3, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    200, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2099, /* nextAdGroupIndex= */
    3, state)).isEqualTo(1999);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2099, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(1999);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2100, /* nextAdGroupIndex= */
    3, state)).isEqualTo(2000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2100, /* nextAdGroupIndex= */
    4, state)).isEqualTo(2000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2100, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(2000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2300, /* nextAdGroupIndex= */
    3, state)).isEqualTo(2200);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2300, /* nextAdGroupIndex= */
    4, state)).isEqualTo(2000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    2300, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(2000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4299, /* nextAdGroupIndex= */
    4, state)).isEqualTo(3999);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4299, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(3999);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4300, /* nextAdGroupIndex= */
    4, state)).isEqualTo(4000);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4300, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(4200);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4500, /* nextAdGroupIndex= */
    4, state)).isEqualTo(4200);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4500, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(4400);
    assertThat(getMediaPeriodPositionUsForContent(/* positionUs= */
    4700, /* nextAdGroupIndex= */
    C.INDEX_UNSET, state)).isEqualTo(4600);
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Test(org.junit.Test)

Example 74 with Timeline

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

the class ServerSideAdInsertionUtilTest method getMediaPeriodPositionUsForAd_returnsCorrectPositions.

@Test
public void getMediaPeriodPositionUsForAd_returnsCorrectPositions() {
    // stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
    // content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
    AdPlaybackState state = new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */
    0, 0, 0, 2000, 4000).withRemovedAdGroupCount(2).withAdCount(/* adGroupIndex= */
    2, /* adCount= */
    2).withAdCount(/* adGroupIndex= */
    3, /* adCount= */
    1).withAdCount(/* adGroupIndex= */
    4, /* adCount= */
    3).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    100).withContentResumeOffsetUs(/* adGroupIndex= */
    3, /* contentResumeOffsetUs= */
    0).withContentResumeOffsetUs(/* adGroupIndex= */
    4, /* contentResumeOffsetUs= */
    400).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    150, 50).withAdDurationsUs(/* adGroupIndex= */
    3, /* adDurationsUs...= */
    200).withAdDurationsUs(/* adGroupIndex= */
    4, /* adDurationsUs...= */
    50, 50, 100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    0, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    0, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    100, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    0, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    100, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    1, state)).isEqualTo(-50);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    200, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    0, state)).isEqualTo(200);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    200, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    1, state)).isEqualTo(50);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    300, /* adGroupIndex= */
    2, /* adIndexInAdGroup= */
    1, state)).isEqualTo(150);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    2000, /* adGroupIndex= */
    3, /* adIndexInAdGroup= */
    0, state)).isEqualTo(-100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    2100, /* adGroupIndex= */
    3, /* adIndexInAdGroup= */
    0, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    2300, /* adGroupIndex= */
    3, /* adIndexInAdGroup= */
    0, state)).isEqualTo(200);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4300, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    0, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4300, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    1, state)).isEqualTo(-50);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4300, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    2, state)).isEqualTo(-100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4400, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    0, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4400, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    1, state)).isEqualTo(50);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4400, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    2, state)).isEqualTo(0);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4500, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    1, state)).isEqualTo(150);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4500, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    2, state)).isEqualTo(100);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4700, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    1, state)).isEqualTo(350);
    assertThat(getMediaPeriodPositionUsForAd(/* positionUs= */
    4700, /* adGroupIndex= */
    4, /* adIndexInAdGroup= */
    2, state)).isEqualTo(300);
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Test(org.junit.Test)

Example 75 with Timeline

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

Aggregations

Test (org.junit.Test)347 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)246 Timeline (com.google.android.exoplayer2.Timeline)163 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)140 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)125 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)110 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)109 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)89 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)85 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)79 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)74 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)60 Format (com.google.android.exoplayer2.Format)49 MediaSource (com.google.android.exoplayer2.source.MediaSource)47 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)36 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)35 MediaItem (com.google.android.exoplayer2.MediaItem)34 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)33