Search in sources :

Example 76 with AdPlaybackState

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

the class ImaUtilTest method expandAdGroupPlaceHolder_expandSingleAdInAdGroup_noExpansionCorrectDuration.

@Test
public void expandAdGroupPlaceHolder_expandSingleAdInAdGroup_noExpansionCorrectDuration() {
    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= */
    1, adPlaybackState);
    AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(/* adGroupIndex= */
    0);
    assertThat(adGroup.count).isEqualTo(1);
    assertThat(adGroup.durationsUs[0]).isEqualTo(10_000_000);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) Test(org.junit.Test)

Example 77 with AdPlaybackState

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

the class ImaUtilTest method insertAdDurationInAdGroup_allDurationsSetAlready_setDurationNoPropagation.

@Test
public void insertAdDurationInAdGroup_allDurationsSetAlready_setDurationNoPropagation() {
    AdPlaybackState adPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(AdPlaybackState.NONE, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    5_000_000, 10_000_000, 20_000_000);
    adPlaybackState = ImaUtil.updateAdDurationInAdGroup(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    1, /* adDurationUs= */
    5_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(5_000_000);
    assertThat(adGroup.durationsUs[2]).isEqualTo(20_000_000);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) Test(org.junit.Test)

Example 78 with AdPlaybackState

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_twoMidrollAds_splitToMiddleTwoPeriods.

@Test
public void splitAdPlaybackStateForPeriods_twoMidrollAds_splitToMiddleTwoPeriods() {
    int periodCount = 4;
    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).timeUs).isEqualTo(0);
        assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs).hasLength(1);
        assertThat(periodAdPlaybackState.getAdGroup(0).durationsUs[0]).isEqualTo(2_500_000);
    }
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
}
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 79 with AdPlaybackState

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_earlyMidrollAdGroupStartTimeUs_adGroupIgnored.

@Test
public void splitAdPlaybackStateForPeriods_earlyMidrollAdGroupStartTimeUs_adGroupIgnored() {
    int periodCount = 4;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", periodDurationUs - 1).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);
        assertThat(periodAdPlaybackState.adsId).isEqualTo("adsId");
    }
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 80 with AdPlaybackState

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_singlePeriod_doesNotSplit.

@Test
public void splitAdPlaybackStateForPeriods_singlePeriod_doesNotSplit() {
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "", 0, 20_000, C.TIME_END_OF_SOURCE);
    FakeTimeline singlePeriodTimeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, singlePeriodTimeline);
    assertThat(adPlaybackStates).hasSize(1);
    assertThat(adPlaybackStates).containsEntry(new Pair<>(0L, 0), adPlaybackState);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) 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