use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method expandAdGroupPlaceHolder_expandWithMiddleAdInGroup_correctExpansion.
@Test
public void expandAdGroupPlaceHolder_expandWithMiddleAdInGroup_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= */
1, /* adDurationUs= */
10_000_000, /* adsInAdGroupCount= */
3, adPlaybackState);
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
0);
assertThat(adGroup.count).isEqualTo(3);
assertThat(adGroup.durationsUs[0]).isEqualTo(0);
assertThat(adGroup.durationsUs[1]).isEqualTo(10_000_000);
assertThat(adGroup.durationsUs[2]).isEqualTo(20_000_000);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method expandAdGroupPlaceHolder_singleAdInAdGroupOverLength_correctsAdDuration.
@Test
public void expandAdGroupPlaceHolder_singleAdInAdGroupOverLength_correctsAdDuration() {
AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
10_000_001);
adPlaybackState = ImaUtil.expandAdGroupPlaceholder(/* adGroupIndex= */
0, /* adGroupDurationUs= */
10_000_000, /* adIndexInAdGroup= */
0, /* adDurationUs= */
10_000_000, /* adsInAdGroupCount= */
1, adPlaybackState);
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
0);
assertThat(adGroup.count).isEqualTo(1);
assertThat(adGroup.durationsUs[0]).isEqualTo(10_000_000);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_twoPrerollAds_splitToFirstTwoPeriods.
@Test
public void splitAdPlaybackStateForPeriods_twoPrerollAds_splitToFirstTwoPeriods() {
int periodCount = 4;
long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId", /* adGroupTimesUs... */
0).withAdCount(/* adGroupIndex= */
0, 2).withAdDurationsUs(/* adGroupIndex= */
0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 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);
for (int i = 0; i < 2; i++) {
Pair<Long, Integer> periodUid = new Pair<>(0L, i);
AdPlaybackState periodAdPlaybackState = adPlaybackStates.get(periodUid);
assertThat(periodAdPlaybackState.adGroupCount).isEqualTo(1);
assertThat(periodAdPlaybackState.adsId).isEqualTo("adsId");
assertThat(periodAdPlaybackState.getAdGroup(0).timeUs).isEqualTo(0);
assertThat(periodAdPlaybackState.getAdGroup(0).isServerSideInserted).isTrue();
assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs).hasLength(1);
int adDurationUs = i == 0 ? 125_500_000 : 2_500_000;
assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs[0]).isEqualTo(adDurationUs);
}
assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(0);
assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_lateMidrollAdGroupStartTimeUs_adGroupIgnored.
@Test
public void splitAdPlaybackStateForPeriods_lateMidrollAdGroupStartTimeUs_adGroupIgnored() {
int periodCount = 4;
long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId", // around removed.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs + 2).withAdCount(/* adGroupIndex= */
0, 1).withAdDurationsUs(/* adGroupIndex= */
0, /* adDurationsUs...= */
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);
for (AdPlaybackState periodAdPlaybackState : adPlaybackStates.values()) {
assertThat(periodAdPlaybackState.adGroupCount).isEqualTo(0);
}
}
use of com.google.android.exoplayer2.source.ads.AdPlaybackState in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_emptyTimeline_emptyMapOfAdPlaybackStates.
@Test
public void splitAdPlaybackStateForPeriods_emptyTimeline_emptyMapOfAdPlaybackStates() {
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"", 0, 20_000, C.TIME_END_OF_SOURCE);
ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, Timeline.EMPTY);
assertThat(adPlaybackStates).isEmpty();
}
Aggregations