Search in sources :

Example 6 with MediaLoadData

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

the class ChunkSampleStream method onLoadError.

@Override
public LoadErrorAction onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    long bytesLoaded = loadable.bytesLoaded();
    boolean isMediaChunk = isMediaChunk(loadable);
    int lastChunkIndex = mediaChunks.size() - 1;
    boolean cancelable = bytesLoaded == 0 || !isMediaChunk || !haveReadFromMediaChunk(lastChunkIndex);
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, bytesLoaded);
    MediaLoadData mediaLoadData = new MediaLoadData(loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, Util.usToMs(loadable.startTimeUs), Util.usToMs(loadable.endTimeUs));
    LoadErrorInfo loadErrorInfo = new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
    @Nullable LoadErrorAction loadErrorAction = null;
    if (chunkSource.onChunkLoadError(loadable, cancelable, loadErrorInfo, loadErrorHandlingPolicy)) {
        if (cancelable) {
            loadErrorAction = Loader.DONT_RETRY;
            if (isMediaChunk) {
                BaseMediaChunk removed = discardUpstreamMediaChunksFromIndex(lastChunkIndex);
                Assertions.checkState(removed == loadable);
                if (mediaChunks.isEmpty()) {
                    pendingResetPositionUs = lastSeekPositionUs;
                }
            }
        } else {
            Log.w(TAG, "Ignoring attempt to cancel non-cancelable load.");
        }
    }
    if (loadErrorAction == null) {
        // The load was not cancelled. Either the load must be retried or the error propagated.
        long retryDelayMs = loadErrorHandlingPolicy.getRetryDelayMsFor(loadErrorInfo);
        loadErrorAction = retryDelayMs != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
        false, retryDelayMs) : Loader.DONT_RETRY_FATAL;
    }
    boolean canceled = !loadErrorAction.isRetry();
    mediaSourceEventDispatcher.loadError(loadEventInfo, loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs, error, canceled);
    if (canceled) {
        loadingChunk = null;
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
        callback.onContinueLoadingRequested(this);
    }
    return loadErrorAction;
}
Also used : LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) LoadErrorInfo(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) Nullable(androidx.annotation.Nullable) LoadErrorAction(com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)

Example 7 with MediaLoadData

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

the class DashMediaSource method onManifestLoadError.

/* package */
LoadErrorAction onManifestLoadError(ParsingLoadable<DashManifest> loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
    MediaLoadData mediaLoadData = new MediaLoadData(loadable.type);
    LoadErrorInfo loadErrorInfo = new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
    long retryDelayMs = loadErrorHandlingPolicy.getRetryDelayMsFor(loadErrorInfo);
    LoadErrorAction loadErrorAction = retryDelayMs == C.TIME_UNSET ? Loader.DONT_RETRY_FATAL : Loader.createRetryAction(/* resetErrorCount= */
    false, retryDelayMs);
    boolean wasCanceled = !loadErrorAction.isRetry();
    manifestEventDispatcher.loadError(loadEventInfo, loadable.type, error, wasCanceled);
    if (wasCanceled) {
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    return loadErrorAction;
}
Also used : LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) LoadErrorInfo(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) LoadErrorAction(com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)

Example 8 with MediaLoadData

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

the class MediaSourceTestRunner method assertCompletedMediaPeriodLoads.

/**
 * Asserts that the media source reported completed loads via {@link
 * MediaSourceEventListener#onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)} for
 * each specified media period id, and asserts that the associated window index matches the one in
 * the last known timeline returned from {@link #prepareSource()}, {@link #assertTimelineChange()}
 * or {@link #assertTimelineChangeBlocking()}.
 */
public void assertCompletedMediaPeriodLoads(MediaPeriodId... mediaPeriodIds) {
    Timeline.Period period = new Timeline.Period();
    HashSet<MediaPeriodId> expectedLoads = new HashSet<>(Arrays.asList(mediaPeriodIds));
    for (Pair<Integer, MediaPeriodId> windowIndexAndMediaPeriodId : completedLoads) {
        int windowIndex = windowIndexAndMediaPeriodId.first;
        MediaPeriodId mediaPeriodId = windowIndexAndMediaPeriodId.second;
        if (expectedLoads.remove(mediaPeriodId)) {
            int periodIndex = timeline.getIndexOfPeriod(mediaPeriodId.periodUid);
            assertThat(windowIndex).isEqualTo(timeline.getPeriod(periodIndex, period).windowIndex);
        }
    }
    assertWithMessage("Not all expected media source loads have been completed.").that(expectedLoads).isEmpty();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) HashSet(java.util.HashSet)

Example 9 with MediaLoadData

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

the class FakeMediaSource method finishSourcePreparation.

private void finishSourcePreparation(boolean sendManifestLoadEvents) {
    refreshSourceInfo(Assertions.checkStateNotNull(timeline));
    if (!timeline.isEmpty() && sendManifestLoadEvents) {
        MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MANIFEST, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
        null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
        null, /* mediaStartTimeMs= */
        C.TIME_UNSET, /* mediaEndTimeMs = */
        C.TIME_UNSET);
        long elapsedRealTimeMs = SystemClock.elapsedRealtime();
        MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */
        null);
        long loadTaskId = LoadEventInfo.getNewId();
        eventDispatcher.loadStarted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        0), mediaLoadData);
        eventDispatcher.loadCompleted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        MANIFEST_LOAD_BYTES), mediaLoadData);
    }
}
Also used : MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener)

Example 10 with MediaLoadData

use of com.google.android.exoplayer2.source.MediaLoadData 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)

Aggregations

LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)7 MediaLoadData (com.google.android.exoplayer2.source.MediaLoadData)7 LoadErrorInfo (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)7 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)6 LoadErrorAction (com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)6 Nullable (androidx.annotation.Nullable)2 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)2 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)2 Timeline (com.google.android.exoplayer2.Timeline)1 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)1 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)1 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)1 LoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy)1 HashSet (java.util.HashSet)1