use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_oneMidrollAdGroupTwoAds_eachAdSplitsToOnePeriod.
@Test
public void splitAdPlaybackStateForPeriods_oneMidrollAdGroupTwoAds_eachAdSplitsToOnePeriod() {
int periodCount = 5;
long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId", DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs).withAdCount(/* adGroupIndex= */
0, 2).withAdDurationsUs(/* adGroupIndex= */
0, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
0, 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(0);
for (int i = 1; i < 3; i++) {
Pair<Long, Integer> periodUid = new Pair<>(0L, i);
AdPlaybackState periodAdPlaybackState = adPlaybackStates.get(periodUid);
assertThat(periodAdPlaybackState.adGroupCount).isEqualTo(1);
assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs).hasLength(1);
assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs[0]).isEqualTo(2_000_000);
}
assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).adGroupCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method expandAdGroupPlaceHolder_expandWithFirstAdInGroup_correctExpansion.
@Test
public void expandAdGroupPlaceHolder_expandWithFirstAdInGroup_correctExpansion() {
AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
30_000_000);
adPlaybackState = ImaUtil.expandAdGroupPlaceholder(/* adGroupIndex= */
0, /* adGroupDurationUs= */
30_000_000, /* adIndexInAdGroup= */
0, /* adDurationUs= */
10_000_000, /* adsInAdGroupCount= */
3, adPlaybackState);
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
0);
assertThat(adGroup.count).isEqualTo(3);
assertThat(adGroup.durationsUs[0]).isEqualTo(10_000_000);
assertThat(adGroup.durationsUs[1]).isEqualTo(20_000_000);
assertThat(adGroup.durationsUs[2]).isEqualTo(0);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method insertAdDurationInAdGroup_insertLast_correctDurationAndPropagation.
@Test
public void insertAdDurationInAdGroup_insertLast_correctDurationAndPropagation() {
AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
0, 10_000_000, 20_000_000);
adPlaybackState = ImaUtil.updateAdDurationInAdGroup(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
2, /* adDurationUs= */
15_000_000, adPlaybackState);
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(0);
assertThat(adGroup.count).isEqualTo(3);
assertThat(adGroup.durationsUs[0]).isEqualTo(5_000_000);
assertThat(adGroup.durationsUs[1]).isEqualTo(10_000_000);
assertThat(adGroup.durationsUs[2]).isEqualTo(15_000_000);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_noAds_splitToEmptyAdPlaybackStates.
@Test
public void splitAdPlaybackStateForPeriods_noAds_splitToEmptyAdPlaybackStates() {
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId");
FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
11, /* id= */
0L));
ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
assertThat(adPlaybackStates).hasSize(11);
for (AdPlaybackState periodAdPlaybackState : adPlaybackStates.values()) {
assertThat(periodAdPlaybackState.adsId).isEqualTo("adsId");
assertThat(periodAdPlaybackState.adGroupCount).isEqualTo(0);
}
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method insertAdDurationInAdGroup_correctDurationAndPropagation.
@Test
public void insertAdDurationInAdGroup_correctDurationAndPropagation() {
AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
10_000_000, 20_000_000, 0);
adPlaybackState = ImaUtil.updateAdDurationInAdGroup(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
1, /* adDurationUs= */
15_000_000, adPlaybackState);
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(0);
assertThat(adGroup.count).isEqualTo(3);
assertThat(adGroup.durationsUs[0]).isEqualTo(10_000_000);
assertThat(adGroup.durationsUs[1]).isEqualTo(15_000_000);
assertThat(adGroup.durationsUs[2]).isEqualTo(5_000_000);
}
Aggregations