Search in sources :

Example 16 with END_OF_STREAM_ITEM

use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.

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);
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaFormat(android.media.MediaFormat) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) MediaCodecInfo(com.google.android.exoplayer2.mediacodec.MediaCodecInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) ImmutableList(com.google.common.collect.ImmutableList) Handler(android.os.Handler) Looper(android.os.Looper) After(org.junit.After) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) MockitoJUnit(org.mockito.junit.MockitoJUnit) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) Before(org.junit.Before) FakeSampleStreamItem.format(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.format) SurfaceTexture(android.graphics.SurfaceTexture) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) ShadowLooper(org.robolectric.shadows.ShadowLooper) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Surface(android.view.Surface) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) Mockito.never(org.mockito.Mockito.never) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) MockitoRule(org.mockito.junit.MockitoRule) Renderer(com.google.android.exoplayer2.Renderer) Collections(java.util.Collections) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 17 with END_OF_STREAM_ITEM

use of com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM in project ExoPlayer by google.

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

Aggregations

Test (org.junit.Test)16 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)14 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)14 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)13 Format (com.google.android.exoplayer2.Format)5 MediaFormat (android.media.MediaFormat)4 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)3 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)3 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 Nullable (androidx.annotation.Nullable)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 Timeline (com.google.android.exoplayer2.Timeline)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)2 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)2 END_OF_STREAM_ITEM (com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM)2 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)2