Search in sources :

Example 6 with EVENT_POSITION_DISCONTINUITY

use of com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method playlistOperations.

@Test
public void playlistOperations() throws Exception {
    MediaSource fakeMediaSource = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).addMediaSources(fakeMediaSource).waitForIsLoading(true).waitForIsLoading(false).removeMediaItem(/* index= */
    0).waitForPlaybackState(Player.STATE_BUFFERING).waitForPlaybackState(Player.STATE_READY).play().build();
    TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
    // Populate event ids with second to last timeline that still contained both periods.
    populateEventIds(listener.reportedTimelines.get(listener.reportedTimelines.size() - 2));
    // Expect the second period with window index 0 and increased window sequence after the removal
    // moved the period to another window index.
    period0Seq1 = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    1));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    period0Seq0, /* READY */
    period0Seq1, /* BUFFERING */
    period0Seq1, /* READY */
    period0Seq1, /* setPlayWhenReady=true */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    period0Seq0, /* SOURCE_UPDATE (first item) */
    period0Seq0, /* PLAYLIST_CHANGED (add) */
    period0Seq0, /* SOURCE_UPDATE (second item) */
    period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0Seq0, period0Seq0, period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0Seq0, period0Seq1, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0Seq0, period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0Seq0, period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0Seq0, period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0Seq0, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0Seq0, period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0Seq0, period1Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq1);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0Seq0, period1Seq1, period0Seq1).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0Seq0, period1Seq1, period0Seq1);
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0Seq1);
    listener.assertNoMoreEvents();
}
Also used : ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 7 with EVENT_POSITION_DISCONTINUITY

use of com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method onEvents_isReportedWithCorrectEventTimes.

@Test
public void onEvents_isReportedWithCorrectEventTimes() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).build();
    Surface surface = new Surface(new SurfaceTexture(/* texName= */
    0));
    player.setVideoSurface(surface);
    AnalyticsListener listener = mock(AnalyticsListener.class);
    Format[] formats = new Format[] { new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).build(), new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_AAC).build() };
    player.addAnalyticsListener(listener);
    // Trigger some simultaneous events.
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(), formats));
    player.seekTo(2_000);
    player.setPlaybackParameters(new PlaybackParameters(/* speed= */
    2.0f));
    ShadowLooper.runMainLooperToNextTask();
    // Move to another item and fail with a third one to trigger events with different EventTimes.
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    player.addMediaSource(new FakeMediaSource(new FakeTimeline(), formats));
    player.play();
    TestPlayerRunHelper.runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    player.setMediaItem(MediaItem.fromUri("http://this-will-throw-an-exception.mp4"));
    TestPlayerRunHelper.runUntilError(player);
    ShadowLooper.runMainLooperToNextTask();
    player.release();
    surface.release();
    // Verify that expected individual callbacks have been called and capture EventTimes.
    ArgumentCaptor<AnalyticsListener.EventTime> individualTimelineChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onTimelineChanged(individualTimelineChangedEventTimes.capture(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualMediaItemTransitionEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onMediaItemTransition(individualMediaItemTransitionEventTimes.capture(), any(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualPositionDiscontinuityEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onPositionDiscontinuity(individualPositionDiscontinuityEventTimes.capture(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualPlaybackStateChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onPlaybackStateChanged(individualPlaybackStateChangedEventTimes.capture(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualIsLoadingChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onIsLoadingChanged(individualIsLoadingChangedEventTimes.capture(), anyBoolean());
    ArgumentCaptor<AnalyticsListener.EventTime> individualTracksChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onTracksChanged(individualTracksChangedEventTimes.capture(), any(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualPlayWhenReadyChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onPlayWhenReadyChanged(individualPlayWhenReadyChangedEventTimes.capture(), anyBoolean(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualIsPlayingChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onIsPlayingChanged(individualIsPlayingChangedEventTimes.capture(), anyBoolean());
    ArgumentCaptor<AnalyticsListener.EventTime> individualPlayerErrorEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onPlayerError(individualPlayerErrorEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualPlaybackParametersChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onPlaybackParametersChanged(individualPlaybackParametersChangedEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualLoadStartedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onLoadStarted(individualLoadStartedEventTimes.capture(), any(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualLoadCompletedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onLoadCompleted(individualLoadCompletedEventTimes.capture(), any(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualLoadErrorEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onLoadError(individualLoadErrorEventTimes.capture(), any(), any(), any(), anyBoolean());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoEnabledEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoEnabled(individualVideoEnabledEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualAudioEnabledEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onAudioEnabled(individualAudioEnabledEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualDownstreamFormatChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onDownstreamFormatChanged(individualDownstreamFormatChangedEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoInputFormatChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoInputFormatChanged(individualVideoInputFormatChangedEventTimes.capture(), any(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualAudioInputFormatChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onAudioInputFormatChanged(individualAudioInputFormatChangedEventTimes.capture(), any(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoDecoderInitializedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoDecoderInitialized(individualVideoDecoderInitializedEventTimes.capture(), any(), anyLong(), anyLong());
    ArgumentCaptor<AnalyticsListener.EventTime> individualAudioDecoderInitializedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onAudioDecoderInitialized(individualAudioDecoderInitializedEventTimes.capture(), any(), anyLong(), anyLong());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoDisabledEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoDisabled(individualVideoDisabledEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualAudioDisabledEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onAudioDisabled(individualAudioDisabledEventTimes.capture(), any());
    ArgumentCaptor<AnalyticsListener.EventTime> individualRenderedFirstFrameEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onRenderedFirstFrame(individualRenderedFirstFrameEventTimes.capture(), any(), anyLong());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoSizeChangedEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoSizeChanged(individualVideoSizeChangedEventTimes.capture(), any());
    verify(listener, atLeastOnce()).onVideoSizeChanged(individualVideoSizeChangedEventTimes.capture(), anyInt(), anyInt(), anyInt(), anyFloat());
    ArgumentCaptor<AnalyticsListener.EventTime> individualAudioPositionAdvancingEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onAudioPositionAdvancing(individualAudioPositionAdvancingEventTimes.capture(), anyLong());
    ArgumentCaptor<AnalyticsListener.EventTime> individualVideoProcessingOffsetEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onVideoFrameProcessingOffset(individualVideoProcessingOffsetEventTimes.capture(), anyLong(), anyInt());
    ArgumentCaptor<AnalyticsListener.EventTime> individualDroppedFramesEventTimes = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
    verify(listener, atLeastOnce()).onDroppedVideoFrames(individualDroppedFramesEventTimes.capture(), anyInt(), anyLong());
    // Verify the EventTimes reported with onEvents are a non-empty subset of the individual
    // callback EventTimes. We can only assert they are a non-empty subset because there may be
    // multiple events of the same type arriving in the same message queue iteration.
    ArgumentCaptor<AnalyticsListener.Events> eventsCaptor = ArgumentCaptor.forClass(AnalyticsListener.Events.class);
    verify(listener, atLeastOnce()).onEvents(eq(player), eventsCaptor.capture());
    SparseArray<List<AnalyticsListener.EventTime>> onEventsEventTimes = new SparseArray<>();
    for (AnalyticsListener.Events events : eventsCaptor.getAllValues()) {
        for (int i = 0; i < events.size(); i++) {
            @AnalyticsListener.EventFlags int event = events.get(i);
            if (onEventsEventTimes.get(event) == null) {
                onEventsEventTimes.put(event, new ArrayList<>());
            }
            onEventsEventTimes.get(event).add(events.getEventTime(event));
        }
    }
    // SparseArray.get returns null if the key doesn't exist, thus verifying the sets are non-empty.
    assertThat(individualTimelineChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_TIMELINE_CHANGED)).inOrder();
    assertThat(individualMediaItemTransitionEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_MEDIA_ITEM_TRANSITION)).inOrder();
    assertThat(individualPositionDiscontinuityEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_POSITION_DISCONTINUITY)).inOrder();
    assertThat(individualPlaybackStateChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_PLAYBACK_STATE_CHANGED)).inOrder();
    assertThat(individualIsLoadingChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_IS_LOADING_CHANGED)).inOrder();
    assertThat(individualTracksChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_TRACKS_CHANGED)).inOrder();
    assertThat(individualPlayWhenReadyChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_PLAY_WHEN_READY_CHANGED)).inOrder();
    assertThat(individualIsPlayingChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_IS_PLAYING_CHANGED)).inOrder();
    assertThat(individualPlayerErrorEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_PLAYER_ERROR)).inOrder();
    assertThat(individualPlaybackParametersChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_PLAYBACK_PARAMETERS_CHANGED)).inOrder();
    assertThat(individualLoadStartedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_LOAD_STARTED)).inOrder();
    assertThat(individualLoadCompletedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_LOAD_COMPLETED)).inOrder();
    assertThat(individualLoadErrorEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_LOAD_ERROR)).inOrder();
    assertThat(individualVideoEnabledEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_ENABLED)).inOrder();
    assertThat(individualAudioEnabledEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_AUDIO_ENABLED)).inOrder();
    assertThat(individualDownstreamFormatChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_DOWNSTREAM_FORMAT_CHANGED)).inOrder();
    assertThat(individualVideoInputFormatChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).inOrder();
    assertThat(individualAudioInputFormatChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_AUDIO_INPUT_FORMAT_CHANGED)).inOrder();
    assertThat(individualVideoDecoderInitializedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_DECODER_INITIALIZED)).inOrder();
    assertThat(individualAudioDecoderInitializedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_AUDIO_DECODER_INITIALIZED)).inOrder();
    assertThat(individualVideoDisabledEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_DISABLED)).inOrder();
    assertThat(individualAudioDisabledEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_AUDIO_DISABLED)).inOrder();
    assertThat(individualRenderedFirstFrameEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_RENDERED_FIRST_FRAME)).inOrder();
    assertThat(individualVideoSizeChangedEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_SIZE_CHANGED)).inOrder();
    assertThat(individualAudioPositionAdvancingEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_AUDIO_POSITION_ADVANCING)).inOrder();
    assertThat(individualVideoProcessingOffsetEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).inOrder();
    assertThat(individualDroppedFramesEventTimes.getAllValues()).containsAtLeastElementsIn(onEventsEventTimes.get(EVENT_DROPPED_VIDEO_FRAMES)).inOrder();
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Surface(android.view.Surface) SparseArray(android.util.SparseArray) SurfaceTexture(android.graphics.SurfaceTexture) Format(com.google.android.exoplayer2.Format) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Example 8 with EVENT_POSITION_DISCONTINUITY

use of com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method seekAfterMidroll.

@Test
public void seekAfterMidroll() throws Exception {
    long windowOffsetInFirstPeriodUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND)));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(adTimeline, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, mediaPeriodId) -> {
        if (mediaPeriodId.isAd()) {
            return ImmutableList.of(oneByteSample(/* timeUs= */
            0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        } else {
            // Provide a sample before the midroll and another after the seek point below (6s).
            return ImmutableList.of(oneByteSample(windowOffsetInFirstPeriodUs + C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + 7 * C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        }
    }, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).seek(6 * C.MICROS_PER_SECOND).waitForIsLoading(true).play().waitForPlaybackState(Player.STATE_ENDED).build();
    TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
    Object periodUid = listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    EventWindowAndPeriodId midrollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId contentBeforeMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0));
    EventWindowAndPeriodId contentAfterMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    C.INDEX_UNSET));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    contentBeforeMidroll, /* READY */
    contentAfterMidroll, /* BUFFERING */
    midrollAd, /* setPlayWhenReady=true */
    midrollAd, /* READY */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(contentAfterMidroll, /* seek */
    midrollAd, /* seek adjustment */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(contentBeforeMidroll, contentBeforeMidroll, midrollAd, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(contentAfterMidroll);
    listener.assertNoMoreEvents();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 9 with EVENT_POSITION_DISCONTINUITY

use of com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method seekToOtherPeriod.

@Test
public void seekToOtherPeriod() throws Exception {
    MediaSource mediaSource = new ConcatenatingMediaSource(new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT), new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.AUDIO_FORMAT));
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).seek(/* mediaItemIndex= */
    1, /* positionMs= */
    0).play().build();
    TestAnalyticsListener listener = runAnalyticsTest(mediaSource, actionSchedule);
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* BUFFERING */
    WINDOW_0, /* setPlayWhenReady=false */
    period0, /* READY */
    period1, /* BUFFERING */
    period1, /* setPlayWhenReady=true */
    period1, /* READY */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    period0).inOrder();
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(period1);
    assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(period1);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0, period0).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0, period1, period1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
    WINDOW_1, /* manifest */
    period0, /* media */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
    WINDOW_1, /* manifest */
    period0, /* media */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0, /* video */
    period0, /* audio */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0, /* video */
    period0, /* audio */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0, /* video */
    period0, /* audio */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0, /* video */
    period0, /* audio */
    period1).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0, /* video */
    period0).inOrder();
    assertThat(listener.getEvents(EVENT_AUDIO_ENABLED)).containsExactly(period0, period1).inOrder();
    assertThat(listener.getEvents(EVENT_AUDIO_DECODER_INITIALIZED)).containsExactly(period0, period1).inOrder();
    assertThat(listener.getEvents(EVENT_AUDIO_INPUT_FORMAT_CHANGED)).containsExactly(period0, period1).inOrder();
    assertThat(listener.getEvents(EVENT_AUDIO_POSITION_ADVANCING)).containsExactly(period0, period1).inOrder();
    assertThat(listener.getEvents(EVENT_AUDIO_DISABLED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0);
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0);
    listener.assertNoMoreEvents();
}
Also used : ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Test(org.junit.Test)

Example 10 with EVENT_POSITION_DISCONTINUITY

use of com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method reprepareAfterError.

@Test
public void reprepareAfterError() throws Exception {
    MediaSource mediaSource = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).throwPlaybackException(ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)).waitForPlaybackState(Player.STATE_IDLE).seek(/* positionMs= */
    0).prepare().waitForIsLoading(true).play().waitForPlaybackState(Player.STATE_ENDED).build();
    TestAnalyticsListener listener = runAnalyticsTest(mediaSource, actionSchedule);
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    period0Seq0, /* READY */
    period0Seq0, /* IDLE */
    period0Seq0, /* BUFFERING */
    period0Seq0, /* setPlayWhenReady=true */
    period0Seq0, /* READY */
    period0Seq0).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* prepared */
    period0Seq0);
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(period0Seq0, period0Seq0, period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    WINDOW_0, /* manifest */
    period0Seq0).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* manifest */
    period0Seq0, /* media */
    WINDOW_0, /* manifest */
    period0Seq0).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0Seq0, period0Seq0);
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0Seq0);
    listener.assertNoMoreEvents();
}
Also used : ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)10 Test (org.junit.Test)10 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)7 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)7 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)6 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)4 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 Timeline (com.google.android.exoplayer2.Timeline)2 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)2 SurfaceTexture (android.graphics.SurfaceTexture)1 SparseArray (android.util.SparseArray)1 Surface (android.view.Surface)1 Format (com.google.android.exoplayer2.Format)1 PlaybackParameters (com.google.android.exoplayer2.PlaybackParameters)1 Window (com.google.android.exoplayer2.Timeline.Window)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)1 ImmutableList (com.google.common.collect.ImmutableList)1