use of androidx.media3.test.utils.FakeSampleStream in project media by androidx.
the class ExoPlayerTest method sampleStreamMaybeThrowError_isNotThrownUntilPlaybackReachedFailingItem.
@Test
public void sampleStreamMaybeThrowError_isNotThrownUntilPlaybackReachedFailingItem() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Timeline timeline = new FakeTimeline();
player.addMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
player.addMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {
@Override
protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
return new FakeMediaPeriod(trackGroupArray, allocator, /* trackDataFactory= */
(format, mediaPeriodId) -> ImmutableList.of(), mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
false) {
@Override
protected FakeSampleStream createSampleStream(Allocator allocator, @Nullable MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List<FakeSampleStreamItem> fakeSampleStreamItems) {
return new FakeSampleStream(allocator, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, initialFormat, fakeSampleStreamItems) {
@Override
public void maybeThrowError() throws IOException {
throw new IOException();
}
};
}
};
}
});
player.prepare();
player.play();
ExoPlaybackException error = TestPlayerRunHelper.runUntilError(player);
Object period1Uid = player.getCurrentTimeline().getPeriod(/* periodIndex= */
1, new Timeline.Period(), /* setIds= */
true).uid;
assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid);
assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1);
}
use of androidx.media3.test.utils.FakeSampleStream in project media by androidx.
the class DecoderAudioRendererTest method immediatelyReadEndOfStreamPlaysAudioSinkToEndOfStream.
@Test
public void immediatelyReadEndOfStreamPlaysAudioSinkToEndOfStream() throws Exception {
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), FORMAT, ImmutableList.of(END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
0);
audioRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { FORMAT }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0, /* offsetUs= */
0);
audioRenderer.setCurrentStreamFinal();
when(mockAudioSink.isEnded()).thenReturn(true);
while (!audioRenderer.isEnded()) {
audioRenderer.render(0, 0);
}
verify(mockAudioSink, times(1)).playToEndOfStream();
audioRenderer.disable();
audioRenderer.reset();
verify(mockAudioSink, times(1)).reset();
}
use of androidx.media3.test.utils.FakeSampleStream in project media by androidx.
the class MediaCodecAudioRendererTest method render_configuresAudioSink_afterFormatChange.
@Test
public void render_configuresAudioSink_afterFormatChange() throws Exception {
Format changedFormat = AUDIO_AAC.buildUpon().setSampleRate(48_000).setEncoderDelay(400).build();
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
AUDIO_AAC, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
50, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
100, C.BUFFER_FLAG_KEY_FRAME), format(changedFormat), oneByteSample(/* timeUs= */
150, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
200, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(/* timeUs= */
250, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
0);
mediaCodecAudioRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { AUDIO_AAC, changedFormat }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
false, /* startPositionUs= */
0, /* offsetUs */
0);
mediaCodecAudioRenderer.start();
mediaCodecAudioRenderer.render(/* positionUs= */
0, SystemClock.elapsedRealtime() * 1000);
mediaCodecAudioRenderer.render(/* positionUs= */
250, SystemClock.elapsedRealtime() * 1000);
mediaCodecAudioRenderer.setCurrentStreamFinal();
int positionUs = 500;
do {
mediaCodecAudioRenderer.render(positionUs, SystemClock.elapsedRealtime() * 1000);
positionUs += 250;
} while (!mediaCodecAudioRenderer.isEnded());
verify(audioSink).configure(getAudioSinkFormat(AUDIO_AAC), /* specifiedBufferSize= */
0, /* outputChannels= */
null);
verify(audioSink).configure(getAudioSinkFormat(changedFormat), /* specifiedBufferSize= */
0, /* outputChannels= */
null);
}
use of androidx.media3.test.utils.FakeSampleStream in project media by androidx.
the class MetadataRendererTest method runRenderer.
private static List<Metadata> runRenderer(byte[] input) throws ExoPlaybackException {
List<Metadata> metadata = new ArrayList<>();
MetadataRenderer renderer = new MetadataRenderer(metadata::add, /* outputLooper= */
null);
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), EMSG_FORMAT, ImmutableList.of(sample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME, input), END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
0);
renderer.replaceStream(new Format[] { EMSG_FORMAT }, fakeSampleStream, /* startPositionUs= */
0L, /* offsetUs= */
0L);
// Read the format
renderer.render(/* positionUs= */
0, /* elapsedRealtimeUs= */
0);
// Read the data
renderer.render(/* positionUs= */
0, /* elapsedRealtimeUs= */
0);
return Collections.unmodifiableList(metadata);
}
use of androidx.media3.test.utils.FakeSampleStream in project media by androidx.
the class DecoderVideoRendererTest method enable_withMayRenderStartOfStream_rendersFirstFrameBeforeStart.
@Test
public void enable_withMayRenderStartOfStream_rendersFirstFrameBeforeStart() throws Exception {
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
H264_FORMAT, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME)));
fakeSampleStream.writeData(/* startPositionUs= */
0);
renderer.enable(RendererConfiguration.DEFAULT, new Format[] { H264_FORMAT }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0L, /* offsetUs */
0);
for (int i = 0; i < 10; i++) {
renderer.render(/* positionUs= */
0, SystemClock.elapsedRealtime() * 1000);
// Ensure pending messages are delivered.
ShadowLooper.idleMainLooper();
}
verify(eventListener).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
Aggregations