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);
}
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);
}
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));
}
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");
}
Aggregations