use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class DefaultPlaybackSessionManagerTest method timelineUpdate_toNewMediaWithMediaPeriodId_finishesOtherSessions.
@Test
public void timelineUpdate_toNewMediaWithMediaPeriodId_finishesOtherSessions() {
Timeline firstTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1000), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2000), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3000));
EventTime eventTimeFirstTimeline1 = createEventTime(firstTimeline, /* windowIndex= */
0, new MediaPeriodId(firstTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
EventTime eventTimeFirstTimeline2 = createEventTime(firstTimeline, /* windowIndex= */
1, new MediaPeriodId(firstTimeline.getUidOfPeriod(/* periodIndex= */
1), /* windowSequenceNumber= */
1));
EventTime eventTimeFirstTimeline3 = createEventTime(firstTimeline, /* windowIndex= */
2, new MediaPeriodId(firstTimeline.getUidOfPeriod(/* periodIndex= */
2), /* windowSequenceNumber= */
2));
Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2000), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1000), new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3000));
EventTime eventTimeSecondTimeline = createEventTime(secondTimeline, /* windowIndex= */
0, new MediaPeriodId(secondTimeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
1));
sessionManager.updateSessionsWithTimelineChange(eventTimeFirstTimeline1);
sessionManager.updateSessions(eventTimeFirstTimeline2);
sessionManager.updateSessions(eventTimeFirstTimeline3);
sessionManager.updateSessionsWithTimelineChange(eventTimeSecondTimeline);
InOrder inOrder = inOrder(mockListener);
ArgumentCaptor<String> firstId = ArgumentCaptor.forClass(String.class);
inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimeline1), firstId.capture());
inOrder.verify(mockListener).onSessionActive(eventTimeFirstTimeline1, firstId.getValue());
ArgumentCaptor<String> secondId = ArgumentCaptor.forClass(String.class);
inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimeline2), secondId.capture());
ArgumentCaptor<String> thirdId = ArgumentCaptor.forClass(String.class);
inOrder.verify(mockListener).onSessionCreated(eq(eventTimeFirstTimeline3), thirdId.capture());
inOrder.verify(mockListener).onSessionFinished(eventTimeSecondTimeline, firstId.getValue(), /* automaticTransitionToNextPlayback= */
false);
inOrder.verify(mockListener).onSessionActive(eventTimeSecondTimeline, secondId.getValue());
inOrder.verifyNoMoreInteractions();
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class MergingMediaSourceTest method prepare_differentPeriodCounts_fails.
@Test
public void prepare_differentPeriodCounts_fails() throws IOException {
FakeTimeline firstTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1));
FakeTimeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
2, /* id= */
2));
IllegalMergeException exception = assertThrows(IllegalMergeException.class, () -> prepareMergingMediaSource(/* clipDurations= */
false, firstTimeline, secondTimeline));
assertThat(exception.reason).isEqualTo(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class MergingMediaSourceTest method prepare_withoutDurationClipping_usesTimelineOfFirstSource.
@Test
public void prepare_withoutDurationClipping_usesTimelineOfFirstSource() throws IOException {
FakeTimeline timeline1 = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
30));
FakeTimeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
C.TIME_UNSET));
FakeTimeline timeline3 = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
10));
Timeline mergedTimeline = prepareMergingMediaSource(/* clipDurations= */
false, timeline1, timeline2, timeline3);
assertThat(mergedTimeline).isEqualTo(timeline1);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled.
@Test
public void newServerSideInsertedAdAtPlaybackPosition_keepsRenderersEnabled() throws Exception {
// Injecting renderer to count number of renderer resets.
AtomicReference<FakeVideoRenderer> videoRenderer = new AtomicReference<>();
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderersFactory((handler, videoListener, audioListener, textOutput, metadataOutput) -> {
videoRenderer.set(new FakeVideoRenderer(handler, videoListener));
return new Renderer[] { videoRenderer.get() };
}).build();
// Live stream timeline with unassigned next ad group.
AdPlaybackState initialAdPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
C.TIME_END_OF_SOURCE).withIsServerSideInserted(/* adGroupIndex= */
0, /* isServerSideInserted= */
true).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdDurationsUs(new long[][] { new long[] { 10 * C.MICROS_PER_SECOND } });
// Updated timeline with ad group at 18 seconds.
long firstSampleTimeUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
Timeline initialTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
C.TIME_UNSET, initialAdPlaybackState));
AdPlaybackState updatedAdPlaybackState = initialAdPlaybackState.withAdGroupTimeUs(/* adGroupIndex= */
0, /* adGroupTimeUs= */
firstSampleTimeUs + 18 * C.MICROS_PER_SECOND);
Timeline updatedTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
C.TIME_UNSET, updatedAdPlaybackState));
// Add samples to allow player to load and start playing (but no EOS as this is a live stream).
FakeMediaSource mediaSource = new FakeMediaSource(initialTimeline, DrmSessionManager.DRM_UNSUPPORTED, (format, mediaPeriodId) -> ImmutableList.of(oneByteSample(firstSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(firstSampleTimeUs + 40 * C.MICROS_PER_SECOND)), ExoPlayerTestRunner.VIDEO_FORMAT);
// Set updated ad group once we reach 20 seconds, and then continue playing until 40 seconds.
player.createMessage((message, payload) -> mediaSource.setNewSourceInfo(updatedTimeline)).setPosition(20_000).send();
player.setMediaSource(mediaSource);
player.prepare();
playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
40_000);
player.release();
// Assert that the renderer hasn't been reset despite the inserted ad group.
assertThat(videoRenderer.get().positionResetCount).isEqualTo(1);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition in project ExoPlayer by google.
the class ExoPlayerTest method play_playedSSAIPreMidPostRollsSinglePeriodWindow_noDiscontinuities.
@Test
public void play_playedSSAIPreMidPostRollsSinglePeriodWindow_noDiscontinuities() throws Exception {
AdPlaybackState adPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState("adsId"), /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (3 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (5 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (9 * C.MICROS_PER_SECOND), /* contentResumeOffsetUs= */
0, /* adDurationsUs...= */
C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
0, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
1, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
2, /* adIndexInAdGroup+ */
0);
adPlaybackState = adPlaybackState.withPlayedAd(/* adGroupIndex= */
3, /* adIndexInAdGroup+ */
0);
FakeTimeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, "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= */
ImmutableList.of(adPlaybackState), MediaItem.EMPTY));
Listener listener = mock(Listener.class);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(listener);
AtomicReference<ServerSideAdInsertionMediaSource> sourceReference = new AtomicReference<>();
sourceReference.set(new ServerSideAdInsertionMediaSource(new FakeMediaSource(adTimeline, ExoPlayerTestRunner.AUDIO_FORMAT), contentTimeline -> {
sourceReference.get().setAdPlaybackStates(adTimeline.getAdPlaybackStates(/* windowIndex= */
0));
return true;
}));
player.setMediaSource(sourceReference.get());
player.prepare();
player.play();
runUntilPlaybackState(player, Player.STATE_ENDED);
long finalPositionMs = player.getCurrentPosition();
player.release();
assertThat(finalPositionMs).isEqualTo(6000);
verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt());
ArgumentCaptor<Integer> playbackStateCaptor = ArgumentCaptor.forClass(Integer.class);
verify(listener, times(3)).onPlaybackStateChanged(playbackStateCaptor.capture());
assertThat(playbackStateCaptor.getAllValues()).containsExactly(2, 3, 4).inOrder();
}
Aggregations