Search in sources :

Example 6 with DefaultAllocator

use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.

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());
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with DefaultAllocator

use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.

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());
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 8 with DefaultAllocator

use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.

the class MediaCodecVideoRendererTest method render_dropsLateBuffer.

@Test
public void render_dropsLateBuffer() 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(// First buffer.
    oneByteSample(/* timeUs= */
    0, C.BUFFER_FLAG_KEY_FRAME), // Late buffer.
    oneByteSample(/* timeUs= */
    50_000), // Last buffer.
    oneByteSample(/* timeUs= */
    100_000), 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.start();
    mediaCodecVideoRenderer.render(0, SystemClock.elapsedRealtime() * 1000);
    mediaCodecVideoRenderer.render(40_000, SystemClock.elapsedRealtime() * 1000);
    mediaCodecVideoRenderer.setCurrentStreamFinal();
    // Ensures buffer will be 30_001us late.
    int posUs = 80_001;
    while (!mediaCodecVideoRenderer.isEnded()) {
        mediaCodecVideoRenderer.render(posUs, SystemClock.elapsedRealtime() * 1000);
        posUs += 40_000;
    }
    shadowOf(testMainLooper).idle();
    verify(eventListener).onDroppedFrames(eq(1), anyLong());
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 9 with DefaultAllocator

use of com.google.android.exoplayer2.upstream.DefaultAllocator 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));
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 10 with DefaultAllocator

use of com.google.android.exoplayer2.upstream.DefaultAllocator in project ExoPlayer by google.

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());
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Aggregations

DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)24 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)21 Test (org.junit.Test)21 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)19 MediaFormat (android.media.MediaFormat)4 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)4 C (com.google.android.exoplayer2.C)4 Format (com.google.android.exoplayer2.Format)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 RunWith (org.junit.runner.RunWith)4 Uri (android.net.Uri)3 ImmutableList (com.google.common.collect.ImmutableList)3 After (org.junit.After)3 Before (org.junit.Before)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 Nullable (androidx.annotation.Nullable)2 ApplicationProvider (androidx.test.core.app.ApplicationProvider)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 RobolectricUtil (com.google.android.exoplayer2.robolectric.RobolectricUtil)2