use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_onePrerollAdGroup_splitToFirstThreePeriods.
@Test
public void splitAdPlaybackStateForPeriods_onePrerollAdGroup_splitToFirstThreePeriods() {
int periodCount = 4;
long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId", /* adGroupTimesUs... */
0).withAdCount(/* adGroupIndex= */
0, 1).withAdDurationsUs(/* adGroupIndex= */
0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 3 * 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 < 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);
int adDurationUs = i == 0 ? 125_500_000 : 2_500_000;
assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs[0]).isEqualTo(adDurationUs);
}
assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
}
use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.
the class ImaUtilTest method splitAdPlaybackStateForPeriods_twoPostrollAds_splitToLastTwoPeriods.
@Test
public void splitAdPlaybackStateForPeriods_twoPostrollAds_splitToLastTwoPeriods() {
int periodCount = 4;
long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
"adsId", DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 2 * 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);
assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).adGroupCount).isEqualTo(0);
for (int i = 2; i < periodCount; 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_500_000);
}
}
use of com.google.android.exoplayer2.Timeline 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.Timeline 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.Timeline 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);
}
Aggregations