use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ExoPlayerTest method mediaItemOfSources_correctInTimelineWindows.
@Test
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake1"));
FakeMediaSource fakeMediaSource1 = new FakeMediaSource(new FakeTimeline(window1));
TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake2"));
FakeMediaSource fakeMediaSource2 = new FakeMediaSource(new FakeTimeline(window2));
TimelineWindowDefinition window3 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
3, /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, /* durationUs = */
100_000, /* defaultPositionUs = */
0, /* windowOffsetInFirstPeriodUs= */
0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake3"));
FakeMediaSource fakeMediaSource3 = new FakeMediaSource(new FakeTimeline(window3));
final Player[] playerHolder = { null };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
playerHolder[0] = player;
}
}).waitForPlaybackState(Player.STATE_READY).seek(/* positionMs= */
0).play().build();
List<MediaItem> currentMediaItems = new ArrayList<>();
List<MediaItem> mediaItemsInTimeline = new ArrayList<>();
Player.Listener playerListener = new Player.Listener() {
@Override
public void onTimelineChanged(Timeline timeline, int reason) {
if (reason != Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
return;
}
Window window = new Window();
for (int i = 0; i < timeline.getWindowCount(); i++) {
mediaItemsInTimeline.add(timeline.getWindow(i, window).mediaItem);
}
}
@Override
public void onPositionDiscontinuity(int reason) {
if (reason == Player.DISCONTINUITY_REASON_SEEK || reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
}
}
};
new ExoPlayerTestRunner.Builder(context).setPlayerListener(playerListener).setActionSchedule(actionSchedule).setMediaSources(fakeMediaSource1, fakeMediaSource2, fakeMediaSource3).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
assertThat(currentMediaItems.get(0).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake1");
assertThat(currentMediaItems.get(1).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake2");
assertThat(currentMediaItems.get(2).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake3");
assertThat(mediaItemsInTimeline).containsExactlyElementsIn(currentMediaItems);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ServerSideAdInsertionMediaSourceTest method timeline_containsAdsDefinedInAdPlaybackState.
@Test
public void timeline_containsAdsDefinedInAdPlaybackState() throws Exception {
FakeTimeline wrappedTimeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
10_000_000, /* defaultPositionUs= */
3_000_000, /* windowOffsetInFirstPeriodUs= */
42_000_000L, AdPlaybackState.NONE));
ServerSideAdInsertionMediaSource mediaSource = new ServerSideAdInsertionMediaSource(new FakeMediaSource(wrappedTimeline), /* adPlaybackStateUpdater= */
null);
// Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
15_000_000, 41_500_000, 42_200_000).withIsServerSideInserted(/* adGroupIndex= */
0, /* isServerSideInserted= */
true).withIsServerSideInserted(/* adGroupIndex= */
1, /* isServerSideInserted= */
true).withIsServerSideInserted(/* adGroupIndex= */
2, /* isServerSideInserted= */
true).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdCount(/* adGroupIndex= */
1, /* adCount= */
2).withAdCount(/* adGroupIndex= */
2, /* adCount= */
1).withAdDurationsUs(/* adGroupIndex= */
0, /* adDurationsUs...= */
500_000).withAdDurationsUs(/* adGroupIndex= */
1, /* adDurationsUs...= */
300_000, 100_000).withAdDurationsUs(/* adGroupIndex= */
2, /* adDurationsUs...= */
400_000).withContentResumeOffsetUs(/* adGroupIndex= */
0, /* contentResumeOffsetUs= */
100_000).withContentResumeOffsetUs(/* adGroupIndex= */
1, /* contentResumeOffsetUs= */
400_000).withContentResumeOffsetUs(/* adGroupIndex= */
2, /* contentResumeOffsetUs= */
200_000);
AtomicReference<Timeline> timelineReference = new AtomicReference<>();
mediaSource.setAdPlaybackStates(ImmutableMap.of(new Pair<>(0, 0), adPlaybackState));
mediaSource.prepareSource((source, timeline) -> timelineReference.set(timeline), /* mediaTransferListener= */
null, PlayerId.UNSET);
runMainLooperUntil(() -> timelineReference.get() != null);
Timeline timeline = timelineReference.get();
assertThat(timeline.getPeriodCount()).isEqualTo(1);
Timeline.Period period = timeline.getPeriod(/* periodIndex= */
0, new Timeline.Period());
assertThat(period.getAdGroupCount()).isEqualTo(3);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
0)).isEqualTo(1);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
1)).isEqualTo(2);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
2)).isEqualTo(1);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
0)).isEqualTo(15_000_000);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
1)).isEqualTo(41_500_000);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
2)).isEqualTo(42_200_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0)).isEqualTo(500_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
1, /* adIndexInAdGroup= */
0)).isEqualTo(300_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
1, /* adIndexInAdGroup= */
1)).isEqualTo(100_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
2, /* adIndexInAdGroup= */
0)).isEqualTo(400_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
0)).isEqualTo(100_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
1)).isEqualTo(400_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
2)).isEqualTo(200_000);
// windowDurationUs + windowOffsetInFirstPeriodUs - sum(adDurations) + sum(contentResumeOffsets)
assertThat(period.getDurationUs()).isEqualTo(51_400_000);
// positionInWindowUs + sum(adDurationsBeforeWindow) - sum(contentResumeOffsetsBeforeWindow)
assertThat(period.getPositionInWindowUs()).isEqualTo(-41_600_000);
Timeline.Window window = timeline.getWindow(/* windowIndex= */
0, new Timeline.Window());
assertThat(window.positionInFirstPeriodUs).isEqualTo(41_600_000);
// windowDurationUs - sum(adDurationsInWindow) + sum(applicableContentResumeOffsetUs)
assertThat(window.durationUs).isEqualTo(9_800_000);
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.
@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
TrackGroup fixedGroup = new TrackGroup(fixedFormat);
Definition definition1 = new Definition(trackGroup1, /* tracks...= */
0, 1);
Definition definition2 = new Definition(trackGroup2, /* tracks...= */
0, 1, 2);
Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
0);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {
@Override
protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
checkPoints.add(adaptationCheckpoints);
return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
}
};
Timeline timeline = new FakeTimeline();
factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0)), timeline);
assertThat(checkPoints).hasSize(2);
assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
5750, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6000, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
1000), new AdaptationCheckpoint(/* totalBandwidth= */
7250, /* allocatedBandwidth= */
1000), new AdaptationCheckpoint(/* totalBandwidth= */
9500, /* allocatedBandwidth= */
2000)).inOrder();
assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
5750, /* allocatedBandwidth= */
250), new AdaptationCheckpoint(/* totalBandwidth= */
6000, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
500), new AdaptationCheckpoint(/* totalBandwidth= */
7250, /* allocatedBandwidth= */
1250), new AdaptationCheckpoint(/* totalBandwidth= */
9500, /* allocatedBandwidth= */
2500)).inOrder();
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints.
@Test
public void builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints() {
Format formatFixed1 = new Format.Builder().setAverageBitrate(500).build();
Format formatFixed2 = new Format.Builder().setAverageBitrate(1000).build();
Format formatAdaptive1 = new Format.Builder().setAverageBitrate(2000).build();
Format formatAdaptive2 = new Format.Builder().setAverageBitrate(3000).build();
Format formatAdaptive3 = new Format.Builder().setAverageBitrate(4000).build();
Format formatAdaptive4 = new Format.Builder().setAverageBitrate(5000).build();
TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
TrackGroup trackGroupAdaptive = new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */
0);
Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */
1);
Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */
1, 2, 3);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {
@Override
protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
checkPoints.add(adaptationCheckpoints);
return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
}
};
Timeline timeline = new FakeTimeline();
factory.createTrackSelections(new Definition[] { null, definitionFixed1, null, definitionFixed2, definitionAdaptive }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0)), timeline);
assertThat(checkPoints).hasSize(1);
assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
0, /* allocatedBandwidth= */
0), new AdaptationCheckpoint(/* totalBandwidth= */
4500, /* allocatedBandwidth= */
3000), new AdaptationCheckpoint(/* totalBandwidth= */
5500, /* allocatedBandwidth= */
4000), new AdaptationCheckpoint(/* totalBandwidth= */
6500, /* allocatedBandwidth= */
5000), new AdaptationCheckpoint(/* totalBandwidth= */
11500, /* allocatedBandwidth= */
10000)).inOrder();
}
use of com.google.android.exoplayer2.testutil.FakeTimeline in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method periodCreationWithAds.
@Test
public void periodCreationWithAds() throws IOException, InterruptedException {
// Create concatenated media source with ad child source.
Timeline timelineContentOnly = new FakeTimeline(new TimelineWindowDefinition(2, 111, true, false, 10 * C.MICROS_PER_SECOND));
Timeline timelineWithAds = new FakeTimeline(new TimelineWindowDefinition(2, 222, true, false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs=... */
0)));
FakeMediaSource mediaSourceContentOnly = new FakeMediaSource(timelineContentOnly);
FakeMediaSource mediaSourceWithAds = new FakeMediaSource(timelineWithAds);
mediaSource.addMediaSource(mediaSourceContentOnly);
mediaSource.addMediaSource(mediaSourceWithAds);
Timeline timeline = testRunner.prepareSource();
// Assert the timeline contains ad groups.
TimelineAsserts.assertAdGroupCounts(timeline, 0, 0, 1, 1);
// Create all periods and assert period creation of child media sources has been called.
testRunner.assertPrepareAndReleaseAllPeriods();
Object timelineContentOnlyPeriodUid0 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
0);
Object timelineContentOnlyPeriodUid1 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
1);
Object timelineWithAdsPeriodUid0 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
0);
Object timelineWithAdsPeriodUid1 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
1);
mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid0, /* windowSequenceNumber= */
0));
mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid1, /* windowSequenceNumber= */
0));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
1));
mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
1));
testRunner.assertCompletedManifestLoads(0, 1);
assertCompletedAllMediaPeriodLoads(timeline);
}
Aggregations