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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations