Search in sources :

Example 81 with AdPlaybackState

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

the class ImaUtilTest method getAdGroupAndIndexInMultiPeriodWindow_correctAdGroupIndexAndAdIndexInAdGroup.

@Test
public void getAdGroupAndIndexInMultiPeriodWindow_correctAdGroupIndexAndAdIndexInAdGroup() {
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    9, new Object()));
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / 9;
    // [ad, ad, content, ad, ad, ad, content, ad, ad]
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, periodDurationUs, 2 * periodDurationUs).withAdCount(/* adGroupIndex= */
    0, 2).withAdCount(/* adGroupIndex= */
    1, 3).withAdCount(/* adGroupIndex= */
    2, 2).withAdDurationsUs(/* adGroupIndex= */
    0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs).withAdDurationsUs(/* adGroupIndex= */
    1, periodDurationUs, periodDurationUs, periodDurationUs).withAdDurationsUs(/* adGroupIndex= */
    2, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    Pair<Integer, Integer> adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    0, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(0);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    1, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(0);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
    Assert.assertThrows(IllegalStateException.class, () -> getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    2, adPlaybackState, timeline));
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    3, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    4, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    5, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(2);
    Assert.assertThrows(IllegalStateException.class, () -> getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    6, adPlaybackState, timeline));
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    7, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(2);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    8, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(2);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 82 with AdPlaybackState

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_singleAdOfAdGroupSpansMultiplePeriods_correctState.

@Test
public void splitAdPlaybackStateForPeriods_singleAdOfAdGroupSpansMultiplePeriods_correctState() {
    int periodCount = 8;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, periodDurationUs, 2 * periodDurationUs).withAdCount(/* adGroupIndex= */
    0, 1).withAdCount(/* adGroupIndex= */
    1, 1).withAdCount(/* adGroupIndex= */
    2, 1).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs)).withAdDurationsUs(/* adGroupIndex= */
    1, /* adDurationsUs...= */
    (2 * periodDurationUs)).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    (2 * periodDurationUs)).withPlayedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0).withPlayedAd(/* adGroupIndex= */
    1, /* adIndexInAdGroup= */
    0).withIsServerSideInserted(/* adGroupIndex= */
    0, true).withIsServerSideInserted(/* adGroupIndex= */
    1, true).withIsServerSideInserted(/* adGroupIndex= */
    2, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    assertThat(adPlaybackStates).hasSize(periodCount);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 0)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 5)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 6)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 7)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Pair(android.util.Pair) Test(org.junit.Test)

Example 83 with AdPlaybackState

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

the class ImaUtilTest method expandAdGroupPlaceHolder_expandWithLastAdInGroup_correctDurationWrappedAround.

@Test
public void expandAdGroupPlaceHolder_expandWithLastAdInGroup_correctDurationWrappedAround() {
    AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    30_000_000);
    adPlaybackState = ImaUtil.expandAdGroupPlaceholder(/* adGroupIndex= */
    0, /* adGroupDurationUs= */
    30_000_000, /* adIndexInAdGroup= */
    2, /* adDurationUs= */
    10_000_000, /* adsInAdGroupCount= */
    3, adPlaybackState);
    AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
    0);
    assertThat(adGroup.count).isEqualTo(3);
    assertThat(adGroup.durationsUs[0]).isEqualTo(20_000_000);
    assertThat(adGroup.durationsUs[1]).isEqualTo(0);
    assertThat(adGroup.durationsUs[2]).isEqualTo(10_000_000);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) Test(org.junit.Test)

Example 84 with AdPlaybackState

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_preMidAndPostrollAdGroup_splitCorrectly.

@Test
public void splitAdPlaybackStateForPeriods_preMidAndPostrollAdGroup_splitCorrectly() {
    int periodCount = 11;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, (2 * periodDurationUs), (5 * periodDurationUs)).withAdCount(/* adGroupIndex= */
    0, 2).withAdDurationsUs(/* adGroupIndex= */
    0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true).withAdCount(/* adGroupIndex= */
    1, 2).withAdDurationsUs(/* adGroupIndex= */
    1, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    1, true).withAdCount(/* adGroupIndex= */
    2, 2).withAdDurationsUs(/* adGroupIndex= */
    2, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    2, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    assertThat(adPlaybackStates).hasSize(periodCount);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 0)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 5)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 6)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 7)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 8)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 9)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 10)).adGroupCount).isEqualTo(1);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Pair(android.util.Pair) Test(org.junit.Test)

Example 85 with AdPlaybackState

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

the class ImaUtilTest method expandAdGroupPlaceHolder_initialDurationTooLarge_overriddenWhenExpanded.

@Test
public void expandAdGroupPlaceHolder_initialDurationTooLarge_overriddenWhenExpanded() {
    AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    30_000_000);
    adPlaybackState = ImaUtil.expandAdGroupPlaceholder(/* adGroupIndex= */
    0, /* adGroupDurationUs= */
    20_000_000, /* adIndexInAdGroup= */
    1, /* adDurationUs= */
    10_000_000, /* adsInAdGroupCount= */
    2, adPlaybackState);
    AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
    0);
    assertThat(adGroup.count).isEqualTo(2);
    assertThat(adGroup.durationsUs[0]).isEqualTo(10_000_000);
    assertThat(adGroup.durationsUs[1]).isEqualTo(10_000_000);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) 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)15 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 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)9 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)8 SurfaceTexture (android.graphics.SurfaceTexture)7 Surface (android.view.Surface)7