Search in sources :

Example 11 with DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_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_OFFSET_IN_FIRST_PERIOD_US

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

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_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 14 with DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US

use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_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)

Example 15 with DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US

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

the class FakeTimeline method createMultiPeriodAdTimeline.

/**
 * Creates a multi-period timeline with ad and content periods specified by the flags passed as
 * var-arg arguments.
 *
 * <p>Period uid end up being a {@code new Pair<>(windowId, periodIndex)}.
 *
 * @param windowId The window ID.
 * @param numberOfPlayedAds The number of ads that should be marked as played.
 * @param isAdPeriodFlags A value of true indicates an ad period. A value of false indicated a
 *     content period.
 * @return A timeline with a single window with as many periods as var-arg arguments.
 */
public static FakeTimeline createMultiPeriodAdTimeline(Object windowId, int numberOfPlayedAds, boolean... isAdPeriodFlags) {
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / isAdPeriodFlags.length;
    AdPlaybackState contentPeriodState = new AdPlaybackState(/* adsId= */
    "adsId");
    AdPlaybackState firstAdPeriodState = contentPeriodState.withNewAdGroup(/* adGroupIndex= */
    0, /* adGroupTimesUs */
    0).withAdCount(/* adGroupIndex= */
    0, 1).withAdDurationsUs(/* adGroupIndex= */
    0, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    AdPlaybackState commonAdPeriodState = firstAdPeriodState.withAdDurationsUs(0, periodDurationUs);
    List<AdPlaybackState> adPlaybackStates = new ArrayList<>();
    int playedAdsCounter = 0;
    for (boolean isAd : isAdPeriodFlags) {
        AdPlaybackState periodAdPlaybackState = isAd ? (adPlaybackStates.isEmpty() ? firstAdPeriodState : commonAdPeriodState) : contentPeriodState;
        if (isAd && playedAdsCounter < numberOfPlayedAds) {
            periodAdPlaybackState = periodAdPlaybackState.withPlayedAd(/* adGroupIndex= */
            0, /* adIndexInAdGroup= */
            0);
            playedAdsCounter++;
        }
        adPlaybackStates.add(periodAdPlaybackState);
    }
    return new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(isAdPeriodFlags.length, windowId, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    DEFAULT_WINDOW_DURATION_US, /* defaultPositionUs= */
    0, /* windowOffsetInFirstPeriodUs= */
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* adPlaybackStates= */
    adPlaybackStates, MediaItem.EMPTY));
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ArrayList(java.util.ArrayList)

Aggregations

AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)19 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)19 Test (org.junit.Test)19 Pair (android.util.Pair)12 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)5 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)4 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