Search in sources :

Example 26 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

the class DecoderVideoRendererTest method enable_withoutMayRenderStartOfStream_rendersFirstFrameAfterStart.

@Test
public void enable_withoutMayRenderStartOfStream_rendersFirstFrameAfterStart() 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= */
    false, /* startPositionUs= */
    0, /* offsetUs */
    0);
    renderer.start();
    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 27 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

the class MediaCodecVideoRendererTest 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= */
    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= */
    true, /* startPositionUs= */
    0, /* offsetUs */
    0);
    for (int i = 0; i < 10; i++) {
        mediaCodecVideoRenderer.render(/* positionUs= */
        0, SystemClock.elapsedRealtime() * 1000);
    }
    shadowOf(testMainLooper).idle();
    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 28 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

the class MediaCodecVideoRendererTest method supportsFormat_withDolbyVisionMedia_returnsTrueWhenFallbackToH265orH264Allowed.

@Test
public void supportsFormat_withDolbyVisionMedia_returnsTrueWhenFallbackToH265orH264Allowed() throws Exception {
    // Create Dolby media formats that could fall back to H265 or H264.
    Format formatDvheDtrFallbackToH265 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvhe.04.01").build();
    Format formatDvheStFallbackToH265 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvhe.08.01").build();
    Format formatDvavSeFallbackToH264 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvav.09.01").build();
    Format formatNoFallbackPossible = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvav.01.01").build();
    // Only provide H264 and H265 decoders with codec profiles needed for fallback.
    MediaCodecSelector mediaCodecSelector = (mimeType, requiresSecureDecoder, requiresTunnelingDecoder) -> {
        switch(mimeType) {
            case MimeTypes.VIDEO_H264:
                CodecCapabilities capabilitiesH264 = new CodecCapabilities();
                capabilitiesH264.profileLevels = new CodecProfileLevel[] { new CodecProfileLevel(), new CodecProfileLevel() };
                capabilitiesH264.profileLevels[0].profile = CodecProfileLevel.AVCProfileBaseline;
                capabilitiesH264.profileLevels[0].level = CodecProfileLevel.AVCLevel42;
                capabilitiesH264.profileLevels[1].profile = CodecProfileLevel.AVCProfileHigh;
                capabilitiesH264.profileLevels[1].level = CodecProfileLevel.AVCLevel42;
                return ImmutableList.of(MediaCodecInfo.newInstance(/* name= */
                "h264-codec", /* mimeType= */
                mimeType, /* codecMimeType= */
                mimeType, /* capabilities= */
                capabilitiesH264, /* hardwareAccelerated= */
                false, /* softwareOnly= */
                true, /* vendor= */
                false, /* forceDisableAdaptive= */
                false, /* forceSecure= */
                false));
            case MimeTypes.VIDEO_H265:
                CodecCapabilities capabilitiesH265 = new CodecCapabilities();
                capabilitiesH265.profileLevels = new CodecProfileLevel[] { new CodecProfileLevel(), new CodecProfileLevel() };
                capabilitiesH265.profileLevels[0].profile = CodecProfileLevel.HEVCProfileMain;
                capabilitiesH265.profileLevels[0].level = CodecProfileLevel.HEVCMainTierLevel41;
                capabilitiesH265.profileLevels[1].profile = CodecProfileLevel.HEVCProfileMain10;
                capabilitiesH265.profileLevels[1].level = CodecProfileLevel.HEVCHighTierLevel51;
                return ImmutableList.of(MediaCodecInfo.newInstance(/* name= */
                "h265-codec", /* mimeType= */
                mimeType, /* codecMimeType= */
                mimeType, /* capabilities= */
                capabilitiesH265, /* hardwareAccelerated= */
                false, /* softwareOnly= */
                true, /* vendor= */
                false, /* forceDisableAdaptive= */
                false, /* forceSecure= */
                false));
            default:
                return ImmutableList.of();
        }
    };
    MediaCodecVideoRenderer renderer = new MediaCodecVideoRenderer(ApplicationProvider.getApplicationContext(), mediaCodecSelector, /* allowedJoiningTimeMs= */
    0, /* eventHandler= */
    new Handler(testMainLooper), /* eventListener= */
    eventListener, /* maxDroppedFramesToNotify= */
    1);
    renderer.init(/* index= */
    0, PlayerId.UNSET);
    @Capabilities int capabilitiesDvheDtrFallbackToH265 = renderer.supportsFormat(formatDvheDtrFallbackToH265);
    @Capabilities int capabilitiesDvheStFallbackToH265 = renderer.supportsFormat(formatDvheStFallbackToH265);
    @Capabilities int capabilitiesDvavSeFallbackToH264 = renderer.supportsFormat(formatDvavSeFallbackToH264);
    @Capabilities int capabilitiesNoFallbackPossible = renderer.supportsFormat(formatNoFallbackPossible);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvheDtrFallbackToH265)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvheStFallbackToH265)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvavSeFallbackToH264)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesNoFallbackPossible)).isEqualTo(C.FORMAT_UNSUPPORTED_SUBTYPE);
}
Also used : 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) CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) Handler(android.os.Handler) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test)

Example 29 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

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

Example 30 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener 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)

Aggregations

DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)18 Test (org.junit.Test)18 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)17 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)16 Nullable (androidx.annotation.Nullable)12 Collections (java.util.Collections)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Before (org.junit.Before)6 Context (android.content.Context)5 Intent (android.content.Intent)5 SurfaceTexture (android.graphics.SurfaceTexture)5 Uri (android.net.Uri)5 ShadowLooper (org.robolectric.shadows.ShadowLooper)5 ValueAnimator (android.animation.ValueAnimator)4 SuppressLint (android.annotation.SuppressLint)4 ActivityNotFoundException (android.content.ActivityNotFoundException)4 Color (android.graphics.Color)4 PorterDuff (android.graphics.PorterDuff)4