Search in sources :

Example 76 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultPlaybackSessionManager method updateSessions.

@Override
public synchronized void updateSessions(EventTime eventTime) {
    Assertions.checkNotNull(listener);
    if (eventTime.timeline.isEmpty()) {
        // Don't try to create new sessions for empty timelines.
        return;
    }
    @Nullable SessionDescriptor currentSession = sessions.get(currentSessionId);
    if (eventTime.mediaPeriodId != null && currentSession != null) {
        // If we receive an event associated with a media period, then it needs to be either part of
        // the current window if it's the first created media period, or a window that will be played
        // in the future. Otherwise, we know that it belongs to a session that was already finished
        // and we can ignore the event.
        boolean isAlreadyFinished = currentSession.windowSequenceNumber == C.INDEX_UNSET ? currentSession.windowIndex != eventTime.windowIndex : eventTime.mediaPeriodId.windowSequenceNumber < currentSession.windowSequenceNumber;
        if (isAlreadyFinished) {
            return;
        }
    }
    SessionDescriptor eventSession = getOrAddSession(eventTime.windowIndex, eventTime.mediaPeriodId);
    if (currentSessionId == null) {
        currentSessionId = eventSession.sessionId;
    }
    if (eventTime.mediaPeriodId != null && eventTime.mediaPeriodId.isAd()) {
        // Ensure that the content session for an ad session is created first.
        MediaPeriodId contentMediaPeriodId = new MediaPeriodId(eventTime.mediaPeriodId.periodUid, eventTime.mediaPeriodId.windowSequenceNumber, eventTime.mediaPeriodId.adGroupIndex);
        SessionDescriptor contentSession = getOrAddSession(eventTime.windowIndex, contentMediaPeriodId);
        if (!contentSession.isCreated) {
            contentSession.isCreated = true;
            eventTime.timeline.getPeriodByUid(eventTime.mediaPeriodId.periodUid, period);
            long adGroupPositionMs = Util.usToMs(period.getAdGroupTimeUs(eventTime.mediaPeriodId.adGroupIndex)) + period.getPositionInWindowMs();
            // getAdGroupTimeUs may return 0 for prerolls despite period offset.
            adGroupPositionMs = max(0, adGroupPositionMs);
            EventTime eventTimeForContent = new EventTime(eventTime.realtimeMs, eventTime.timeline, eventTime.windowIndex, contentMediaPeriodId, /* eventPlaybackPositionMs= */
            adGroupPositionMs, eventTime.currentTimeline, eventTime.currentWindowIndex, eventTime.currentMediaPeriodId, eventTime.currentPlaybackPositionMs, eventTime.totalBufferedDurationMs);
            listener.onSessionCreated(eventTimeForContent, contentSession.sessionId);
        }
    }
    if (!eventSession.isCreated) {
        eventSession.isCreated = true;
        listener.onSessionCreated(eventTime, eventSession.sessionId);
    }
    if (eventSession.sessionId.equals(currentSessionId) && !eventSession.isActive) {
        eventSession.isActive = true;
        listener.onSessionActive(eventTime, eventSession.sessionId);
    }
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Nullable(androidx.annotation.Nullable)

Example 77 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onDrmKeysLoaded.

@Override
public final void onDrmKeysLoaded(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_DRM_KEYS_LOADED, listener -> listener.onDrmKeysLoaded(eventTime));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 78 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onDownstreamFormatChanged.

@Override
public final void onDownstreamFormatChanged(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_DOWNSTREAM_FORMAT_CHANGED, listener -> listener.onDownstreamFormatChanged(eventTime, mediaLoadData));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 79 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onLoadError.

@Override
public final void onLoadError(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException error, boolean wasCanceled) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_LOAD_ERROR, listener -> listener.onLoadError(eventTime, loadEventInfo, mediaLoadData, error, wasCanceled));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 80 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onDrmSessionManagerError.

@Override
public final void onDrmSessionManagerError(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, Exception error) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_DRM_SESSION_MANAGER_ERROR, listener -> listener.onDrmSessionManagerError(eventTime, error));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Aggregations

MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)106 Test (org.junit.Test)85 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)75 Timeline (com.google.android.exoplayer2.Timeline)50 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)48 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)28 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 Nullable (androidx.annotation.Nullable)26 Allocator (com.google.android.exoplayer2.upstream.Allocator)22 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)19 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)17 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)16 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)15 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)15 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)15 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)15 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)11