Search in sources :

Example 11 with DEFAULT_WINDOW_DURATION_US

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US 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 12 with DEFAULT_WINDOW_DURATION_US

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US 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 13 with DEFAULT_WINDOW_DURATION_US

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

the class ImaUtilTest method getAdGroupAndIndexInMultiPeriodWindow_correctAdGroupIndexAndAdIndexInAdGroup.

@Test
public void getAdGroupAndIndexInMultiPeriodWindow_correctAdGroupIndexAndAdIndexInAdGroup() {
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    9, new Object()));
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / 9;
    // [ad, ad, content, ad, ad, ad, content, ad, ad]
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, periodDurationUs, 2 * periodDurationUs).withAdCount(/* adGroupIndex= */
    0, 2).withAdCount(/* adGroupIndex= */
    1, 3).withAdCount(/* adGroupIndex= */
    2, 2).withAdDurationsUs(/* adGroupIndex= */
    0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs).withAdDurationsUs(/* adGroupIndex= */
    1, periodDurationUs, periodDurationUs, periodDurationUs).withAdDurationsUs(/* adGroupIndex= */
    2, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    Pair<Integer, Integer> adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    0, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(0);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    1, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(0);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
    Assert.assertThrows(IllegalStateException.class, () -> getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    2, adPlaybackState, timeline));
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    3, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    4, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    5, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(1);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(2);
    Assert.assertThrows(IllegalStateException.class, () -> getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    6, adPlaybackState, timeline));
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    7, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(2);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(0);
    adGroupIndexAndAdIndexInAdGroup = getAdGroupAndIndexInMultiPeriodWindow(/* adPeriodIndex= */
    8, adPlaybackState, timeline);
    assertThat(adGroupIndexAndAdIndexInAdGroup.first).isEqualTo(2);
    assertThat(adGroupIndexAndAdIndexInAdGroup.second).isEqualTo(1);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 14 with DEFAULT_WINDOW_DURATION_US

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_singleAdOfAdGroupSpansMultiplePeriods_correctState.

@Test
public void splitAdPlaybackStateForPeriods_singleAdOfAdGroupSpansMultiplePeriods_correctState() {
    int periodCount = 8;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, periodDurationUs, 2 * periodDurationUs).withAdCount(/* adGroupIndex= */
    0, 1).withAdCount(/* adGroupIndex= */
    1, 1).withAdCount(/* adGroupIndex= */
    2, 1).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs)).withAdDurationsUs(/* adGroupIndex= */
    1, /* adDurationsUs...= */
    (2 * periodDurationUs)).withAdDurationsUs(/* adGroupIndex= */
    2, /* adDurationsUs...= */
    (2 * periodDurationUs)).withPlayedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0).withPlayedAd(/* adGroupIndex= */
    1, /* adIndexInAdGroup= */
    0).withIsServerSideInserted(/* adGroupIndex= */
    0, true).withIsServerSideInserted(/* adGroupIndex= */
    1, true).withIsServerSideInserted(/* adGroupIndex= */
    2, 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)).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_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 5)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 6)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 7)).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 15 with DEFAULT_WINDOW_DURATION_US

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_preMidAndPostrollAdGroup_splitCorrectly.

@Test
public void splitAdPlaybackStateForPeriods_preMidAndPostrollAdGroup_splitCorrectly() {
    int periodCount = 11;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0, (2 * periodDurationUs), (5 * periodDurationUs)).withAdCount(/* adGroupIndex= */
    0, 2).withAdDurationsUs(/* adGroupIndex= */
    0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true).withAdCount(/* adGroupIndex= */
    1, 2).withAdDurationsUs(/* adGroupIndex= */
    1, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    1, true).withAdCount(/* adGroupIndex= */
    2, 2).withAdDurationsUs(/* adGroupIndex= */
    2, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    2, 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(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 5)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 6)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 7)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 8)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 9)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 10)).adGroupCount).isEqualTo(1);
}
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

AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)17 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)16 Test (org.junit.Test)16 Pair (android.util.Pair)12 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 Intent (android.content.Intent)1 SurfaceTexture (android.graphics.SurfaceTexture)1 AudioManager (android.media.AudioManager)1 Uri (android.net.Uri)1 Looper (android.os.Looper)1 Surface (android.view.Surface)1 Nullable (androidx.annotation.Nullable)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 COMMAND_ADJUST_DEVICE_VOLUME (com.google.android.exoplayer2.Player.COMMAND_ADJUST_DEVICE_VOLUME)1 COMMAND_CHANGE_MEDIA_ITEMS (com.google.android.exoplayer2.Player.COMMAND_CHANGE_MEDIA_ITEMS)1 COMMAND_GET_AUDIO_ATTRIBUTES (com.google.android.exoplayer2.Player.COMMAND_GET_AUDIO_ATTRIBUTES)1 COMMAND_GET_CURRENT_MEDIA_ITEM (com.google.android.exoplayer2.Player.COMMAND_GET_CURRENT_MEDIA_ITEM)1 COMMAND_GET_DEVICE_VOLUME (com.google.android.exoplayer2.Player.COMMAND_GET_DEVICE_VOLUME)1