Search in sources :

Example 6 with LoadEventInfo

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

the class SingleSampleMediaPeriod method onLoadCompleted.

// Loader.Callback implementation.
@Override
public void onLoadCompleted(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) {
    sampleSize = (int) loadable.dataSource.getBytesRead();
    sampleData = Assertions.checkNotNull(loadable.sampleData);
    loadingFinished = true;
    StatsDataSource dataSource = loadable.dataSource;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, sampleSize);
    loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    eventDispatcher.loadCompleted(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs);
}
Also used : StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource)

Example 7 with LoadEventInfo

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

the class SingleSampleMediaPeriod method onLoadError.

@Override
public LoadErrorAction onLoadError(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    StatsDataSource dataSource = loadable.dataSource;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, dataSource.getBytesRead());
    MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeMs= */
    0, Util.usToMs(durationUs));
    long retryDelay = loadErrorHandlingPolicy.getRetryDelayMsFor(new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount));
    boolean errorCanBePropagated = retryDelay == C.TIME_UNSET || errorCount >= loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA);
    LoadErrorAction action;
    if (treatLoadErrorsAsEndOfStream && errorCanBePropagated) {
        Log.w(TAG, "Loading failed, treating as end-of-stream.", error);
        loadingFinished = true;
        action = Loader.DONT_RETRY;
    } else {
        action = retryDelay != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
        false, retryDelay) : Loader.DONT_RETRY_FATAL;
    }
    boolean wasCanceled = !action.isRetry();
    eventDispatcher.loadError(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs, error, wasCanceled);
    if (wasCanceled) {
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    return action;
}
Also used : LoadErrorInfo(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource) LoadErrorAction(com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)

Example 8 with LoadEventInfo

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

the class ChunkSampleStream method onLoadCanceled.

@Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released) {
    loadingChunk = null;
    canceledMediaChunk = null;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
    loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    mediaSourceEventDispatcher.loadCanceled(loadEventInfo, loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs);
    if (!released) {
        if (isPendingReset()) {
            resetSampleQueues();
        } else if (isMediaChunk(loadable)) {
            // TODO: Support splicing to keep data from canceled chunk. See [internal b/161130873].
            discardUpstreamMediaChunksFromIndex(mediaChunks.size() - 1);
            if (mediaChunks.isEmpty()) {
                pendingResetPositionUs = lastSeekPositionUs;
            }
        }
        callback.onContinueLoadingRequested(this);
    }
}
Also used : LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo)

Example 9 with LoadEventInfo

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

the class ChunkSampleStream method continueLoading.

// SequenceableLoader implementation
@Override
public boolean continueLoading(long positionUs) {
    if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
        return false;
    }
    boolean pendingReset = isPendingReset();
    List<BaseMediaChunk> chunkQueue;
    long loadPositionUs;
    if (pendingReset) {
        chunkQueue = Collections.emptyList();
        loadPositionUs = pendingResetPositionUs;
    } else {
        chunkQueue = readOnlyMediaChunks;
        loadPositionUs = getLastMediaChunk().endTimeUs;
    }
    chunkSource.getNextChunk(positionUs, loadPositionUs, chunkQueue, nextChunkHolder);
    boolean endOfStream = nextChunkHolder.endOfStream;
    @Nullable Chunk loadable = nextChunkHolder.chunk;
    nextChunkHolder.clear();
    if (endOfStream) {
        pendingResetPositionUs = C.TIME_UNSET;
        loadingFinished = true;
        return true;
    }
    if (loadable == null) {
        return false;
    }
    loadingChunk = loadable;
    if (isMediaChunk(loadable)) {
        BaseMediaChunk mediaChunk = (BaseMediaChunk) loadable;
        if (pendingReset) {
            // even if its timestamp is slightly earlier than the advertised chunk start time.
            if (mediaChunk.startTimeUs != pendingResetPositionUs) {
                primarySampleQueue.setStartTimeUs(pendingResetPositionUs);
                for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
                    embeddedSampleQueue.setStartTimeUs(pendingResetPositionUs);
                }
            }
            pendingResetPositionUs = C.TIME_UNSET;
        }
        mediaChunk.init(chunkOutput);
        mediaChunks.add(mediaChunk);
    } else if (loadable instanceof InitializationChunk) {
        ((InitializationChunk) loadable).init(chunkOutput);
    }
    long elapsedRealtimeMs = loader.startLoading(loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type));
    mediaSourceEventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, elapsedRealtimeMs), loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs);
    return true;
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) Nullable(androidx.annotation.Nullable)

Example 10 with LoadEventInfo

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

Aggregations

LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)27 MediaLoadData (com.google.android.exoplayer2.source.MediaLoadData)7 LoadErrorInfo (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)7 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)7 LoadErrorAction (com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)6 Nullable (androidx.annotation.Nullable)4 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)4 SampleQueue (com.google.android.exoplayer2.source.SampleQueue)2 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)2 ParsingLoadable (com.google.android.exoplayer2.upstream.ParsingLoadable)2 Uri (android.net.Uri)1 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 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)1 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)1 SsManifest (com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest)1 DataSource (com.google.android.exoplayer2.upstream.DataSource)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1