Search in sources :

Example 11 with FakeTimeline

use of com.google.android.exoplayer2.testutil.FakeTimeline 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);
}
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 12 with FakeTimeline

use of com.google.android.exoplayer2.testutil.FakeTimeline 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);
    }
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 13 with FakeTimeline

use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.

the class ImaUtilTest method splitAdPlaybackStateForPeriods_correctAdPlaybackStates.

@Test
public void splitAdPlaybackStateForPeriods_correctAdPlaybackStates() {
    int periodCount = 7;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0).withAdCount(/* adGroupIndex= */
    0, periodCount).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs).withPlayedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0).withSkippedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    1).withAdLoadError(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    2).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.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_SKIPPED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
}
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 14 with FakeTimeline

use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.

the class ImaUtilTest method splitAdPlaybackStateForPeriods_correctAdsIdInSplitPlaybackStates.

@Test
public void splitAdPlaybackStateForPeriods_correctAdsIdInSplitPlaybackStates() {
    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, 1).withAdDurationsUs(/* adGroupIndex= */
    0, 2 * periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    for (int i = 0; i < adPlaybackStates.size(); i++) {
        assertThat(adPlaybackStates.get(new Pair<>(0L, i)).adsId).isEqualTo("adsId");
    }
}
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 15 with FakeTimeline

use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.

the class ImaUtilTest method splitAdPlaybackStateForPeriods_livePlaceholder_isIgnored.

@Test
public void splitAdPlaybackStateForPeriods_livePlaceholder_isIgnored() {
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "", C.TIME_END_OF_SOURCE).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    FakeTimeline singlePeriodTimeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    3, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, singlePeriodTimeline);
    assertThat(adPlaybackStates).hasSize(3);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 0)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).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)

Aggregations

FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)242 Test (org.junit.Test)240 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)159 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)136 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)118 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)117 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)117 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)98 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)87 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)69 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)62 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)62 MediaSource (com.google.android.exoplayer2.source.MediaSource)60 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)60 Timeline (com.google.android.exoplayer2.Timeline)53 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)50 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)49 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)49 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)49 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)49