Search in sources :

Example 46 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState 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 47 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState 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 48 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState 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 49 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState 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 50 with AdPlaybackState

use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.

the class ServerSideAdInsertionUtilTest method addAdGroupToAdPlaybackState_emptyLeadingAds_markedAsSkipped.

@Test
public void addAdGroupToAdPlaybackState_emptyLeadingAds_markedAsSkipped() {
    AdPlaybackState state = new AdPlaybackState(ADS_ID);
    state = addAdGroupToAdPlaybackState(state, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    50_000, /* adDurationsUs...= */
    0, 0, 10_000, 40_000, 0);
    AdPlaybackState.AdGroup adGroup = state.getAdGroup(/* adGroupIndex= */
    0);
    assertThat(adGroup.durationsUs[0]).isEqualTo(0);
    assertThat(adGroup.states[0]).isEqualTo(AdPlaybackState.AD_STATE_SKIPPED);
    assertThat(adGroup.durationsUs[1]).isEqualTo(0);
    assertThat(adGroup.states[1]).isEqualTo(AdPlaybackState.AD_STATE_SKIPPED);
    assertThat(adGroup.durationsUs[2]).isEqualTo(10_000);
    assertThat(adGroup.states[2]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
    assertThat(adGroup.durationsUs[4]).isEqualTo(0);
    assertThat(adGroup.states[4]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
    assertThat(stream(adGroup.durationsUs).sum()).isEqualTo(50_000);
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)89 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)87 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)51 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)35 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)32 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)27 Pair (android.util.Pair)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)17 Timeline (com.google.android.exoplayer2.Timeline)16 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)14 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)14 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)13 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Listener (com.google.android.exoplayer2.Player.Listener)10 Context (android.content.Context)9 Nullable (androidx.annotation.Nullable)9 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)9 SurfaceTexture (android.graphics.SurfaceTexture)7 Surface (android.view.Surface)7