use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.
the class MediaCodecVideoRendererTest method render_sendsVideoSizeChangeWithCurrentFormatValues.
@Test
public void render_sendsVideoSizeChangeWithCurrentFormatValues() throws Exception {
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
VIDEO_H264, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
0);
mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { VIDEO_H264 }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0, /* offsetUs */
0);
mediaCodecVideoRenderer.setCurrentStreamFinal();
mediaCodecVideoRenderer.start();
int positionUs = 0;
do {
mediaCodecVideoRenderer.render(positionUs, SystemClock.elapsedRealtime() * 1000);
positionUs += 10;
} while (!mediaCodecVideoRenderer.isEnded());
shadowOf(testMainLooper).idle();
verify(eventListener).onVideoSizeChanged(new VideoSize(VIDEO_H264.width, VIDEO_H264.height, VIDEO_H264.rotationDegrees, VIDEO_H264.pixelWidthHeightRatio));
}
use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.
the class MediaCodecVideoRendererTest method replaceStream_whenNotStarted_doesNotRenderFirstFrameOfNewStream.
@Test
public void replaceStream_whenNotStarted_doesNotRenderFirstFrameOfNewStream() throws Exception {
ShadowLooper shadowLooper = shadowOf(testMainLooper);
FakeSampleStream fakeSampleStream1 = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
VIDEO_H264, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
fakeSampleStream1.writeData(/* startPositionUs= */
0);
FakeSampleStream fakeSampleStream2 = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
VIDEO_H264, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
fakeSampleStream2.writeData(/* startPositionUs= */
0);
mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { VIDEO_H264 }, fakeSampleStream1, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0, /* offsetUs */
0);
boolean replacedStream = false;
for (int i = 0; i < 10; i++) {
mediaCodecVideoRenderer.render(/* positionUs= */
i * 10, SystemClock.elapsedRealtime() * 1000);
if (!replacedStream && mediaCodecVideoRenderer.hasReadStreamToEnd()) {
mediaCodecVideoRenderer.replaceStream(new Format[] { VIDEO_H264 }, fakeSampleStream2, /* startPositionUs= */
100, /* offsetUs= */
100);
replacedStream = true;
}
}
shadowLooper.idle();
verify(eventListener).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
// Render to streamOffsetUs and verify the new first frame gets rendered.
mediaCodecVideoRenderer.render(/* positionUs= */
100, SystemClock.elapsedRealtime() * 1000);
shadowLooper.idle();
verify(eventListener, times(2)).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.
the class MergingMediaPeriodTest method prepareMergingPeriod.
private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
long[] timeOffsetsUs = new long[definitions.length];
for (int i = 0; i < definitions.length; i++) {
MergingPeriodDefinition definition = definitions[i];
timeOffsetsUs[i] = definition.timeOffsetUs;
TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
for (int j = 0; j < definition.formats.length; j++) {
trackGroups[j] = new TrackGroup(definition.formats[j]);
}
mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
i, new MediaPeriodId(/* periodUid= */
i), /* mediaTimeOffsetMs= */
0), /* trackDataFactory= */
(unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
}
MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
CountDownLatch prepareCountDown = new CountDownLatch(1);
mergingMediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
prepareCountDown.countDown();
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
mergingMediaPeriod.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
prepareCountDown.await();
return mergingMediaPeriod;
}
use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method seekAfterMidroll.
@Test
public void seekAfterMidroll() throws Exception {
long windowOffsetInFirstPeriodUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND)));
FakeMediaSource fakeMediaSource = new FakeMediaSource(adTimeline, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, mediaPeriodId) -> {
if (mediaPeriodId.isAd()) {
return ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
} else {
// Provide a sample before the midroll and another after the seek point below (6s).
return ImmutableList.of(oneByteSample(windowOffsetInFirstPeriodUs + C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + 7 * C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
}
}, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).seek(6 * C.MICROS_PER_SECOND).waitForIsLoading(true).play().waitForPlaybackState(Player.STATE_ENDED).build();
TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
Object periodUid = listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
0);
EventWindowAndPeriodId midrollAd = new EventWindowAndPeriodId(/* windowIndex= */
0, new MediaPeriodId(periodUid, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* windowSequenceNumber= */
0));
EventWindowAndPeriodId contentBeforeMidroll = new EventWindowAndPeriodId(/* windowIndex= */
0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
0));
EventWindowAndPeriodId contentAfterMidroll = new EventWindowAndPeriodId(/* windowIndex= */
0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
0, /* nextAdGroupIndex= */
C.INDEX_UNSET));
assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
WINDOW_0, /* setPlayWhenReady=false */
WINDOW_0, /* BUFFERING */
contentBeforeMidroll, /* READY */
contentAfterMidroll, /* BUFFERING */
midrollAd, /* setPlayWhenReady=true */
midrollAd, /* READY */
contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
contentBeforeMidroll);
assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(contentAfterMidroll, /* seek */
midrollAd, /* seek adjustment */
contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(contentBeforeMidroll);
assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(contentAfterMidroll);
assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(contentBeforeMidroll, contentBeforeMidroll, midrollAd, midrollAd).inOrder();
assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll);
assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* content manifest */
contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* content manifest */
contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(contentBeforeMidroll);
assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(contentBeforeMidroll);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterMidroll);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(contentAfterMidroll);
listener.assertNoMoreEvents();
}
use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.
the class ExoPlayerTest method playlistWithMediaWithStartOffsets_andStartOffsetChangesDuringPreparation_appliesCorrectRenderingOffsetToAllPeriods.
/**
* This tests that renderer offsets and buffer times in the renderer are set correctly even when
* the sources have a window-to-period offset and a non-zero default start position. The start
* offset of the first source is also updated during preparation to make sure the player adapts
* everything accordingly.
*/
@Test
public void playlistWithMediaWithStartOffsets_andStartOffsetChangesDuringPreparation_appliesCorrectRenderingOffsetToAllPeriods() throws Exception {
List<Long> rendererStreamOffsetsUs = new ArrayList<>();
List<Long> firstBufferTimesUsWithOffset = new ArrayList<>();
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO) {
boolean pendingFirstBufferTime = false;
@Override
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) {
rendererStreamOffsetsUs.add(offsetUs);
pendingFirstBufferTime = true;
}
@Override
protected boolean shouldProcessBuffer(long bufferTimeUs, long playbackPositionUs) {
if (pendingFirstBufferTime) {
firstBufferTimesUsWithOffset.add(bufferTimeUs);
pendingFirstBufferTime = false;
}
return super.shouldProcessBuffer(bufferTimeUs, playbackPositionUs);
}
};
Timeline timelineWithOffsets = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
new Object(), /* isSeekable= */
true, /* isDynamic= */
false, /* isLive= */
false, /* isPlaceholder= */
false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, /* defaultPositionUs= */
4_567_890, /* windowOffsetInFirstPeriodUs= */
1_234_567, AdPlaybackState.NONE));
ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
long firstSampleTimeUs = 4_567_890 + 1_234_567;
FakeMediaSource firstMediaSource = new FakeMediaSource(/* timeline= */
null, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(firstSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM), ExoPlayerTestRunner.VIDEO_FORMAT);
FakeMediaSource secondMediaSource = new FakeMediaSource(timelineWithOffsets, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(firstSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM), ExoPlayerTestRunner.VIDEO_FORMAT);
player.setMediaSources(ImmutableList.of(firstMediaSource, secondMediaSource));
// Start playback and wait until player is idly waiting for an update of the first source.
player.prepare();
player.play();
runUntilPendingCommandsAreFullyHandled(player);
// Update media with a non-zero default start position and window offset.
firstMediaSource.setNewSourceInfo(timelineWithOffsets);
// Wait until player transitions to second source (which also has non-zero offsets).
runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1);
player.release();
assertThat(rendererStreamOffsetsUs).hasSize(2);
assertThat(firstBufferTimesUsWithOffset).hasSize(2);
// Assert that the offsets and buffer times match the expected sample time.
assertThat(firstBufferTimesUsWithOffset.get(0)).isEqualTo(rendererStreamOffsetsUs.get(0) + firstSampleTimeUs);
assertThat(firstBufferTimesUsWithOffset.get(1)).isEqualTo(rendererStreamOffsetsUs.get(1) + firstSampleTimeUs);
// Assert that the second source continues rendering seamlessly at the point where the first one
// ended.
long periodDurationUs = timelineWithOffsets.getPeriod(/* periodIndex= */
0, new Timeline.Period()).durationUs;
assertThat(firstBufferTimesUsWithOffset.get(1)).isEqualTo(rendererStreamOffsetsUs.get(0) + periodDurationUs);
}
Aggregations