Search in sources :

Example 16 with CapturingRenderersFactory

use of androidx.media3.test.utils.CapturingRenderersFactory in project media by androidx.

the class SilencePlaybackTest method test_500ms.

@Test
public void test_500ms() throws Exception {
    Context applicationContext = ApplicationProvider.getApplicationContext();
    CapturingRenderersFactory capturingRenderersFactory = new CapturingRenderersFactory(applicationContext);
    ExoPlayer player = new ExoPlayer.Builder(applicationContext, capturingRenderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
    player.setMediaSource(new SilenceMediaSource(/* durationUs= */
    500_000));
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/silence/500ms.dump");
}
Also used : Context(android.content.Context) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) SilenceMediaSource(androidx.media3.exoplayer.source.SilenceMediaSource) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) FakeClock(androidx.media3.test.utils.FakeClock) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Test(org.junit.Test)

Example 17 with CapturingRenderersFactory

use of androidx.media3.test.utils.CapturingRenderersFactory in project media by androidx.

the class SilencePlaybackTest method test_0ms.

@Test
public void test_0ms() throws Exception {
    Context applicationContext = ApplicationProvider.getApplicationContext();
    CapturingRenderersFactory capturingRenderersFactory = new CapturingRenderersFactory(applicationContext);
    ExoPlayer player = new ExoPlayer.Builder(applicationContext, capturingRenderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
    player.setMediaSource(new SilenceMediaSource(/* durationUs= */
    0));
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/silence/0ms.dump");
}
Also used : Context(android.content.Context) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) SilenceMediaSource(androidx.media3.exoplayer.source.SilenceMediaSource) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) FakeClock(androidx.media3.test.utils.FakeClock) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Test(org.junit.Test)

Example 18 with CapturingRenderersFactory

use of androidx.media3.test.utils.CapturingRenderersFactory in project media by androidx.

the class ServerSideAdInsertionMediaSourceTest method playbackWithNewlyInsertedAds_playsSuccessfulWithoutRendererResets.

@Test
public void playbackWithNewlyInsertedAds_playsSuccessfulWithoutRendererResets() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    AtomicReference<Object> periodUid = new AtomicReference<>();
    CapturingRenderersFactory renderersFactory = new CapturingRenderersFactory(context);
    ExoPlayer player = new ExoPlayer.Builder(context, renderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */
    1)));
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, renderersFactory);
    AdPlaybackState firstAdPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState(/* adsId= */
    new Object()), /* fromPositionUs= */
    900_000, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    100_000);
    AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
    mediaSourceRef.set(new ServerSideAdInsertionMediaSource(new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(TEST_ASSET)), /* adPlaybackStateUpdater= */
    contentTimeline -> {
        periodUid.set(checkNotNull(contentTimeline.getPeriod(/* periodIndex= */
        0, new Timeline.Period(), /* setIds= */
        true).uid));
        mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), firstAdPlaybackState));
        return true;
    }));
    AnalyticsListener listener = mock(AnalyticsListener.class);
    player.addAnalyticsListener(listener);
    player.setMediaSource(mediaSourceRef.get());
    player.prepare();
    // Add ad at the current playback position during playback.
    runUntilPlaybackState(player, Player.STATE_READY);
    AdPlaybackState secondAdPlaybackState = addAdGroupToAdPlaybackState(firstAdPlaybackState, /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    500_000);
    mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
    runUntilPendingCommandsAreFullyHandled(player);
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // Assert all samples have been played.
    DumpFileAsserts.assertOutput(context, playbackOutput, TEST_ASSET_DUMP);
    // Assert playback has been reported with ads: [content][ad0][content][ad1][content]
    // 5*2(audio+video) format changes, 4 discontinuities between parts.
    verify(listener, times(4)).onPositionDiscontinuity(any(), any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    verify(listener, times(10)).onDownstreamFormatChanged(any(), any());
    // Assert renderers played through without reset (=decoders have been enabled only once).
    verify(listener).onVideoEnabled(any(), any());
    verify(listener).onAudioEnabled(any(), any());
    // Assert playback progression was smooth (=no unexpected delays that cause audio to underrun)
    verify(listener, never()).onAudioUnderrun(any(), anyInt(), anyLong(), anyLong());
}
Also used : Context(android.content.Context) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) Assertions.checkNotNull(androidx.media3.common.util.Assertions.checkNotNull) DumpFileAsserts(androidx.media3.test.utils.DumpFileAsserts) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AdPlaybackState(androidx.media3.common.AdPlaybackState) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Pair(android.util.Pair) RunWith(org.junit.runner.RunWith) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) ShadowMediaCodecConfig(androidx.media3.test.utils.robolectric.ShadowMediaCodecConfig) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) MediaItem(androidx.media3.common.MediaItem) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) RobolectricUtil.runMainLooperUntil(androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil) SurfaceTexture(android.graphics.SurfaceTexture) TestPlayerRunHelper.playUntilPosition(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilPosition) Player(androidx.media3.common.Player) Surface(android.view.Surface) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Timeline(androidx.media3.common.Timeline) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) Assert(org.junit.Assert) FakeClock(androidx.media3.test.utils.FakeClock) TestPlayerRunHelper.runUntilPlaybackState(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPlaybackState) Mockito.mock(org.mockito.Mockito.mock) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) FakeClock(androidx.media3.test.utils.FakeClock) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Surface(android.view.Surface) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) SurfaceTexture(android.graphics.SurfaceTexture) AdPlaybackState(androidx.media3.common.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) Test(org.junit.Test)

Example 19 with CapturingRenderersFactory

use of androidx.media3.test.utils.CapturingRenderersFactory in project media by androidx.

the class ServerSideAdInsertionMediaSourceTest method playbackWithAdditionalAdsInAdGroup_playsSuccessfulWithoutRendererResets.

@Test
public void playbackWithAdditionalAdsInAdGroup_playsSuccessfulWithoutRendererResets() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    AtomicReference<Object> periodUid = new AtomicReference<>();
    CapturingRenderersFactory renderersFactory = new CapturingRenderersFactory(context);
    ExoPlayer player = new ExoPlayer.Builder(context, renderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */
    1)));
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, renderersFactory);
    AdPlaybackState firstAdPlaybackState = addAdGroupToAdPlaybackState(new AdPlaybackState(/* adsId= */
    new Object()), /* fromPositionUs= */
    0, /* contentResumeOffsetUs= */
    0, /* adDurationsUs...= */
    500_000);
    AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
    mediaSourceRef.set(new ServerSideAdInsertionMediaSource(new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(TEST_ASSET)), /* adPlaybackStateUpdater= */
    contentTimeline -> {
        if (periodUid.get() == null) {
            periodUid.set(checkNotNull(contentTimeline.getPeriod(/* periodIndex= */
            0, new Timeline.Period(), /* setIds= */
            true).uid));
            mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), firstAdPlaybackState));
        }
        return true;
    }));
    AnalyticsListener listener = mock(AnalyticsListener.class);
    player.addAnalyticsListener(listener);
    player.setMediaSource(mediaSourceRef.get());
    player.prepare();
    // Wait until playback is ready with first ad and then replace by 3 ads.
    runUntilPlaybackState(player, Player.STATE_READY);
    AdPlaybackState secondAdPlaybackState = firstAdPlaybackState.withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    3).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    50_000, 250_000, 200_000);
    mediaSourceRef.get().setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
    runUntilPendingCommandsAreFullyHandled(player);
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // Assert all samples have been played.
    DumpFileAsserts.assertOutput(context, playbackOutput, TEST_ASSET_DUMP);
    // Assert playback has been reported with ads: [ad0][ad1][ad2][content]
    // 4*2(audio+video) format changes, 3 discontinuities between parts.
    verify(listener, times(3)).onPositionDiscontinuity(any(), any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
    verify(listener, times(8)).onDownstreamFormatChanged(any(), any());
    // Assert renderers played through without reset (=decoders have been enabled only once).
    verify(listener).onVideoEnabled(any(), any());
    verify(listener).onAudioEnabled(any(), any());
    // Assert playback progression was smooth (=no unexpected delays that cause audio to underrun)
    verify(listener, never()).onAudioUnderrun(any(), anyInt(), anyLong(), anyLong());
}
Also used : Context(android.content.Context) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) Assertions.checkNotNull(androidx.media3.common.util.Assertions.checkNotNull) DumpFileAsserts(androidx.media3.test.utils.DumpFileAsserts) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AdPlaybackState(androidx.media3.common.AdPlaybackState) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Pair(android.util.Pair) RunWith(org.junit.runner.RunWith) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) ShadowMediaCodecConfig(androidx.media3.test.utils.robolectric.ShadowMediaCodecConfig) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) MediaItem(androidx.media3.common.MediaItem) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) RobolectricUtil.runMainLooperUntil(androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil) SurfaceTexture(android.graphics.SurfaceTexture) TestPlayerRunHelper.playUntilPosition(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilPosition) Player(androidx.media3.common.Player) Surface(android.view.Surface) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Timeline(androidx.media3.common.Timeline) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) Assert(org.junit.Assert) FakeClock(androidx.media3.test.utils.FakeClock) TestPlayerRunHelper.runUntilPlaybackState(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.runUntilPlaybackState) Mockito.mock(org.mockito.Mockito.mock) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) FakeClock(androidx.media3.test.utils.FakeClock) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Surface(android.view.Surface) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) SurfaceTexture(android.graphics.SurfaceTexture) AdPlaybackState(androidx.media3.common.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) Test(org.junit.Test)

Example 20 with CapturingRenderersFactory

use of androidx.media3.test.utils.CapturingRenderersFactory in project media by androidx.

the class RtspPlaybackTest method prepare_withSupportedTrack_playsTrackUntilEnded.

@Test
public void prepare_withSupportedTrack_playsTrackUntilEnded() throws Exception {
    ResponseProvider responseProvider = new ResponseProvider(clock, ImmutableList.of(aacRtpPacketStreamDump, mp4aLatmRtpPacketStreamDump), fakeRtpDataChannel);
    try (RtspServer rtspServer = new RtspServer(responseProvider)) {
        ExoPlayer player = createExoPlayer(rtspServer.startAndGetPortNumber(), rtpDataChannelFactory);
        PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
        player.prepare();
        player.play();
        TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
        player.release();
        // Only setup the supported track (aac).
        assertThat(responseProvider.getDumpsForSetUpTracks()).containsExactly(aacRtpPacketStreamDump);
        DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/rtsp/aac.dump");
    }
}
Also used : PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Test(org.junit.Test)

Aggregations

ExoPlayer (androidx.media3.exoplayer.ExoPlayer)22 PlaybackOutput (androidx.media3.test.utils.robolectric.PlaybackOutput)21 Test (org.junit.Test)21 Context (android.content.Context)20 CapturingRenderersFactory (androidx.media3.test.utils.CapturingRenderersFactory)20 FakeClock (androidx.media3.test.utils.FakeClock)20 SurfaceTexture (android.graphics.SurfaceTexture)11 Surface (android.view.Surface)11 MediaItem (androidx.media3.common.MediaItem)4 DefaultMediaSourceFactory (androidx.media3.exoplayer.source.DefaultMediaSourceFactory)4 Pair (android.util.Pair)3 AdPlaybackState (androidx.media3.common.AdPlaybackState)3 Player (androidx.media3.common.Player)3 Timeline (androidx.media3.common.Timeline)3 Assertions.checkNotNull (androidx.media3.common.util.Assertions.checkNotNull)3 AnalyticsListener (androidx.media3.exoplayer.analytics.AnalyticsListener)3 PlayerId (androidx.media3.exoplayer.analytics.PlayerId)3 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)3 DumpFileAsserts (androidx.media3.test.utils.DumpFileAsserts)3 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)3