Search in sources :

Example 46 with FakeClock

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

the class DefaultBandwidthMeterTest method networkTypeOverride_doesFullReset.

@Test
public void networkTypeOverride_doesFullReset() {
    // Simulate transfers for an ethernet connection.
    setActiveNetworkInfo(networkInfoEthernet);
    FakeClock clock = new FakeClock(/* initialTimeMs= */
    0);
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
    long[] bitrateEstimatesWithNewInstance = simulateTransfers(bandwidthMeter, clock);
    // Create a new instance and seed with some transfers.
    setActiveNetworkInfo(networkInfo2g);
    bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
    simulateTransfers(bandwidthMeter, clock);
    // Override the network type to ethernet and simulate transfers again.
    bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_ETHERNET);
    long[] bitrateEstimatesAfterReset = simulateTransfers(bandwidthMeter, clock);
    // If overriding the network type fully reset the bandwidth meter, we expect the bitrate
    // estimates generated during simulation to be the same.
    assertThat(bitrateEstimatesAfterReset).isEqualTo(bitrateEstimatesWithNewInstance);
}
Also used : FakeClock(androidx.media3.test.utils.FakeClock) Test(org.junit.Test)

Example 47 with FakeClock

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

the class DefaultAnalyticsCollectorTest method release_withCallbacksArrivingAfterRelease_onPlayerReleasedForwardedLast.

@Test
public void release_withCallbacksArrivingAfterRelease_onPlayerReleasedForwardedLast() throws Exception {
    FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
    0, /* isAutoAdvancing= */
    true);
    ExoPlayer exoPlayer = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).setClock(fakeClock).build();
    AnalyticsListener analyticsListener = spy(new AnalyticsListener() {

        @Override
        public void onVideoDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
            // Add delay in callback to test whether event timestamp and release timestamp are
            // in the correct order.
            fakeClock.advanceTime(1);
        }
    });
    exoPlayer.addAnalyticsListener(analyticsListener);
    // Prepare with media to ensure video renderer is enabled.
    exoPlayer.setMediaSource(new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT));
    exoPlayer.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(exoPlayer, Player.STATE_READY);
    // Release and add delay on releasing thread to verify timestamps of events.
    exoPlayer.release();
    long releaseTimeMs = fakeClock.currentTimeMillis();
    fakeClock.advanceTime(1);
    ShadowLooper.idleMainLooper();
    // Verify video disable events and release events arrived in order.
    ArgumentCaptor<AnalyticsListener.EventTime> videoDisabledEventTime = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    ArgumentCaptor<AnalyticsListener.EventTime> releasedEventTime = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    InOrder inOrder = inOrder(analyticsListener);
    inOrder.verify(analyticsListener).onVideoDisabled(videoDisabledEventTime.capture(), any());
    inOrder.verify(analyticsListener).onEvents(same(exoPlayer), argThat(events -> events.contains(EVENT_VIDEO_DISABLED)));
    inOrder.verify(analyticsListener).onPlayerReleased(releasedEventTime.capture());
    inOrder.verify(analyticsListener).onEvents(same(exoPlayer), argThat(events -> events.contains(EVENT_PLAYER_RELEASED)));
    // Verify order of timestamps of these events.
    // This verification is needed as a regression test against [internal ref: b/195396384]. The
    // root cause of the regression was an onPlayerReleased timestamp that was less than the
    // previously reported timestamps for other events triggered as part of the release.
    long videoDisableTimeMs = videoDisabledEventTime.getValue().realtimeMs;
    assertThat(videoDisableTimeMs).isGreaterThan(releaseTimeMs);
    assertThat(releasedEventTime.getValue().realtimeMs).isGreaterThan(videoDisableTimeMs);
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) EVENT_PLAYER_RELEASED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYER_RELEASED) FakeExoMediaDrm(androidx.media3.test.utils.FakeExoMediaDrm) ExoMediaDrm(androidx.media3.exoplayer.drm.ExoMediaDrm) Looper(android.os.Looper) DecoderCounters(androidx.media3.exoplayer.DecoderCounters) EVENT_DRM_SESSION_ACQUIRED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED) EVENT_AUDIO_INPUT_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED) EVENT_AUDIO_DECODER_INITIALIZED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_DECODER_INITIALIZED) Surface(android.view.Surface) DrmSession(androidx.media3.exoplayer.drm.DrmSession) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) EVENT_PLAY_WHEN_READY_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAY_WHEN_READY_CHANGED) TestPlayerRunHelper(androidx.media3.test.utils.robolectric.TestPlayerRunHelper) EVENT_DRM_KEYS_LOADED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_KEYS_LOADED) EVENT_IS_PLAYING_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_IS_PLAYING_CHANGED) EVENT_PLAYBACK_STATE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYBACK_STATE_CHANGED) Nullable(androidx.annotation.Nullable) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) Timeline(androidx.media3.common.Timeline) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeClock(androidx.media3.test.utils.FakeClock) Mockito.mock(org.mockito.Mockito.mock) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) AdPlaybackState(androidx.media3.common.AdPlaybackState) RunWith(org.junit.runner.RunWith) EVENT_TIMELINE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_TIMELINE_CHANGED) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) FakeAudioRenderer(androidx.media3.test.utils.FakeAudioRenderer) EVENT_MEDIA_ITEM_TRANSITION(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION) EVENT_AUDIO_DISABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_DISABLED) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) EVENT_DOWNSTREAM_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DOWNSTREAM_FORMAT_CHANGED) Player(androidx.media3.common.Player) ShadowLooper(org.robolectric.shadows.ShadowLooper) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) EVENT_IS_LOADING_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_IS_LOADING_CHANGED) EVENT_LOAD_COMPLETED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_COMPLETED) IOException(java.io.IOException) Test(org.junit.Test) ConditionVariable(androidx.media3.common.util.ConditionVariable) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) DrmInitData(androidx.media3.common.DrmInitData) ExoPlaybackException(androidx.media3.exoplayer.ExoPlaybackException) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) EVENT_LOAD_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_ERROR) EVENT_DROPPED_VIDEO_FRAMES(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DROPPED_VIDEO_FRAMES) EVENT_PLAYER_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYER_ERROR) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) EVENT_TRACKS_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_TRACKS_CHANGED) ApplicationProvider(androidx.test.core.app.ApplicationProvider) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) END_OF_STREAM_ITEM(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Renderer(androidx.media3.exoplayer.Renderer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtil(androidx.media3.test.utils.TestUtil) EVENT_DRM_SESSION_MANAGER_ERROR(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_MANAGER_ERROR) EVENT_VIDEO_ENABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_ENABLED) EVENT_DRM_SESSION_RELEASED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_DRM_SESSION_RELEASED) MediaItem(androidx.media3.common.MediaItem) EVENT_VIDEO_FRAME_PROCESSING_OFFSET(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_FRAME_PROCESSING_OFFSET) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) Method(java.lang.reflect.Method) MediaDrmCallback(androidx.media3.exoplayer.drm.MediaDrmCallback) EVENT_POSITION_DISCONTINUITY(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY) VideoSize(androidx.media3.common.VideoSize) PlaybackException(androidx.media3.common.PlaybackException) UUID(java.util.UUID) Util(androidx.media3.common.util.Util) MediaDrmCallbackException(androidx.media3.exoplayer.drm.MediaDrmCallbackException) Format(androidx.media3.common.Format) EVENT_PLAYBACK_PARAMETERS_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_PLAYBACK_PARAMETERS_CHANGED) SparseArray(android.util.SparseArray) PlaybackParameters(androidx.media3.common.PlaybackParameters) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) EVENT_LOAD_STARTED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_LOAD_STARTED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Metadata(androidx.media3.common.Metadata) TracksInfo(androidx.media3.common.TracksInfo) EVENT_VIDEO_DISABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_DISABLED) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionSchedule(androidx.media3.test.utils.ActionSchedule) EVENT_AUDIO_POSITION_ADVANCING(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_POSITION_ADVANCING) EVENT_VIDEO_INPUT_FORMAT_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) EVENT_VIDEO_SIZE_CHANGED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED) Window(androidx.media3.common.Timeline.Window) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) EVENT_VIDEO_DECODER_INITIALIZED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_DECODER_INITIALIZED) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) SurfaceTexture(android.graphics.SurfaceTexture) MediaSource(androidx.media3.exoplayer.source.MediaSource) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) MimeTypes(androidx.media3.common.MimeTypes) Clock(androidx.media3.common.util.Clock) Truth.assertThat(com.google.common.truth.Truth.assertThat) EVENT_AUDIO_ENABLED(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_AUDIO_ENABLED) Mockito.verify(org.mockito.Mockito.verify) C(androidx.media3.common.C) EVENT_RENDERED_FIRST_FRAME(androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_RENDERED_FIRST_FRAME) FakeSampleStreamItem.oneByteSample(androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.oneByteSample) RobolectricUtil(androidx.media3.test.utils.robolectric.RobolectricUtil) InOrder(org.mockito.InOrder) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeClock(androidx.media3.test.utils.FakeClock) DecoderCounters(androidx.media3.exoplayer.DecoderCounters) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 48 with FakeClock

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

the class ExoPlayerTest method targetLiveOffsetInMedia_afterAutomaticPeriodTransition_adjustsLiveOffsetToTargetOffset.

@Test
public void targetLiveOffsetInMedia_afterAutomaticPeriodTransition_adjustsLiveOffsetToTargetOffset() throws Exception {
    long windowStartUnixTimeMs = 987_654_321_000L;
    long nowUnixTimeMs = windowStartUnixTimeMs + 10_000;
    ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
    nowUnixTimeMs, /* isAutoAdvancing= */
    true)).build();
    Timeline nonLiveTimeline = new FakeTimeline();
    Timeline liveTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
    Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
    player.pause();
    player.addMediaSource(new FakeMediaSource(nonLiveTimeline));
    player.addMediaSource(new FakeMediaSource(liveTimeline));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    // Play until close to the end of the available live window.
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    1, /* positionMs= */
    999_000);
    long liveOffsetAtEnd = player.getCurrentLiveOffset();
    player.release();
    // Assert that player adjusted live offset to the media value.
    assertThat(liveOffsetAtEnd).isIn(Range.closed(8_900L, 9_100L));
}
Also used : Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeClock(androidx.media3.test.utils.FakeClock) FakeTimeline(androidx.media3.test.utils.FakeTimeline) MediaItem(androidx.media3.common.MediaItem) TestPlayerRunHelper.playUntilStartOfMediaItem(androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 49 with FakeClock

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

the class DashPlaybackTest method webvttInMp4.

// https://github.com/google/ExoPlayer/issues/7985
@Test
@Ignore("Disabled until subtitles are reliably asserted in robolectric tests [internal b/174661563].")
public void webvttInMp4() throws Exception {
    Context applicationContext = ApplicationProvider.getApplicationContext();
    CapturingRenderersFactory capturingRenderersFactory = new CapturingRenderersFactory(applicationContext);
    ExoPlayer player = new ExoPlayer.Builder(applicationContext, capturingRenderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */
    1)));
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
    // Ensure the subtitle track is selected.
    DefaultTrackSelector trackSelector = checkNotNull((DefaultTrackSelector) player.getTrackSelector());
    trackSelector.setParameters(trackSelector.buildUponParameters().setPreferredTextLanguage("en"));
    player.setMediaItem(MediaItem.fromUri("asset:///media/dash/webvtt-in-mp4/sample.mpd"));
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/dash/webvtt-in-mp4.dump");
}
Also used : Context(android.content.Context) PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) SurfaceTexture(android.graphics.SurfaceTexture) CapturingRenderersFactory(androidx.media3.test.utils.CapturingRenderersFactory) FakeClock(androidx.media3.test.utils.FakeClock) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Surface(android.view.Surface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 FakeClock (androidx.media3.test.utils.FakeClock)39 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)23 Context (android.content.Context)21 CapturingRenderersFactory (androidx.media3.test.utils.CapturingRenderersFactory)21 PlaybackOutput (androidx.media3.test.utils.robolectric.PlaybackOutput)21 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)16 MediaItem (androidx.media3.common.MediaItem)15 Timeline (androidx.media3.common.Timeline)15 FakeTimeline (androidx.media3.test.utils.FakeTimeline)15 SurfaceTexture (android.graphics.SurfaceTexture)13 Surface (android.view.Surface)13 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)12 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)10 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)10 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)10 HandlerThread (android.os.HandlerThread)9 HandlerWrapper (androidx.media3.common.util.HandlerWrapper)9 TestPlayerRunHelper.playUntilStartOfMediaItem (androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)9 Player (androidx.media3.common.Player)8