use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.
the class DecoderVideoRendererTest method replaceStream_whenNotStarted_doesNotRenderFirstFrameOfNewStream.
// TODO: Fix rendering of first frame at stream transition.
@Ignore
@Test
public void replaceStream_whenNotStarted_doesNotRenderFirstFrameOfNewStream() throws Exception {
FakeSampleStream fakeSampleStream1 = 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), 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= */
H264_FORMAT, ImmutableList.of(oneByteSample(/* timeUs= */
0), END_OF_STREAM_ITEM));
fakeSampleStream2.writeData(/* startPositionUs= */
0);
renderer.enable(RendererConfiguration.DEFAULT, new Format[] { H264_FORMAT }, fakeSampleStream1, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
true, /* startPositionUs= */
0, /* offsetUs */
0);
boolean replacedStream = false;
for (int i = 0; i < 10; i++) {
renderer.render(/* positionUs= */
i * 10, SystemClock.elapsedRealtime() * 1000);
if (!replacedStream && renderer.hasReadStreamToEnd()) {
renderer.replaceStream(new Format[] { H264_FORMAT }, fakeSampleStream2, /* startPositionUs= */
100, /* offsetUs= */
100);
replacedStream = true;
}
// Ensure pending messages are delivered.
ShadowLooper.idleMainLooper();
}
verify(eventListener).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
// Render to streamOffsetUs and verify the new first frame gets rendered.
renderer.render(/* positionUs= */
100, SystemClock.elapsedRealtime() * 1000);
verify(eventListener, times(2)).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.
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 androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.
the class MediaCodecVideoRendererTest method enable_withoutMayRenderStartOfStream_doesNotRenderFirstFrameBeforeStart.
@Test
public void enable_withoutMayRenderStartOfStream_doesNotRenderFirstFrameBeforeStart() 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)));
fakeSampleStream.writeData(/* startPositionUs= */
0);
mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { VIDEO_H264 }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
false, /* startPositionUs= */
0, /* offsetUs */
0);
for (int i = 0; i < 10; i++) {
mediaCodecVideoRenderer.render(/* positionUs= */
0, SystemClock.elapsedRealtime() * 1000);
}
shadowOf(testMainLooper).idle();
verify(eventListener, never()).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.
the class MediaCodecVideoRendererTest method replaceStream_rendersFirstFrameOnlyAfterStartPosition.
@Test
public void replaceStream_rendersFirstFrameOnlyAfterStartPosition() 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= */
1_000_000, 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);
mediaCodecVideoRenderer.start();
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;
}
}
// Expect only the first frame of the first stream to have been rendered.
shadowLooper.idle();
verify(eventListener, times(2)).onRenderedFirstFrame(eq(surface), /* renderTimeMs= */
anyLong());
}
use of androidx.media3.exoplayer.upstream.DefaultAllocator in project media by androidx.
the class MediaCodecVideoRendererTest method render_withMultipleQueued_sendsVideoSizeChangedWithCorrectPixelAspectRatioWhenMultipleQueued.
@Test
public void render_withMultipleQueued_sendsVideoSizeChangedWithCorrectPixelAspectRatioWhenMultipleQueued() throws Exception {
Format pAsp1 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(1f).build();
Format pAsp2 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(2f).build();
Format pAsp3 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(3f).build();
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
pAsp1, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME)));
fakeSampleStream.writeData(/* startPositionUs= */
0);
mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { pAsp1, pAsp2, pAsp3 }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
false, /* startPositionUs= */
0, /* offsetUs */
0);
mediaCodecVideoRenderer.start();
mediaCodecVideoRenderer.render(/* positionUs= */
0, SystemClock.elapsedRealtime() * 1000);
mediaCodecVideoRenderer.render(/* positionUs= */
250, SystemClock.elapsedRealtime() * 1000);
fakeSampleStream.append(ImmutableList.of(format(pAsp2), oneByteSample(/* timeUs= */
5_000), oneByteSample(/* timeUs= */
10_000), format(pAsp3), oneByteSample(/* timeUs= */
15_000), oneByteSample(/* timeUs= */
20_000), END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
5_000);
mediaCodecVideoRenderer.setCurrentStreamFinal();
int pos = 500;
do {
mediaCodecVideoRenderer.render(/* positionUs= */
pos, SystemClock.elapsedRealtime() * 1000);
pos += 250;
} while (!mediaCodecVideoRenderer.isEnded());
shadowOf(testMainLooper).idle();
ArgumentCaptor<VideoSize> videoSizesCaptor = ArgumentCaptor.forClass(VideoSize.class);
verify(eventListener, times(3)).onVideoSizeChanged(videoSizesCaptor.capture());
assertThat(videoSizesCaptor.getAllValues().stream().map(videoSize -> videoSize.pixelWidthHeightRatio).collect(Collectors.toList())).containsExactly(1f, 2f, 3f);
}
Aggregations