use of androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo in project media by androidx.
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;
}
use of androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo in project media by androidx.
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;
}
use of androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo in project media by androidx.
the class DefaultDashChunkSource method onChunkLoadError.
@Override
public boolean onChunkLoadError(Chunk chunk, boolean cancelable, LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
if (!cancelable) {
return false;
}
if (playerTrackEmsgHandler != null && playerTrackEmsgHandler.onChunkLoadError(chunk)) {
return true;
}
// Workaround for missing segment at the end of the period
if (!manifest.dynamic && chunk instanceof MediaChunk && loadErrorInfo.exception instanceof InvalidResponseCodeException && ((InvalidResponseCodeException) loadErrorInfo.exception).responseCode == 404) {
RepresentationHolder representationHolder = representationHolders[trackSelection.indexOf(chunk.trackFormat)];
long segmentCount = representationHolder.getSegmentCount();
if (segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && segmentCount != 0) {
long lastAvailableSegmentNum = representationHolder.getFirstSegmentNum() + segmentCount - 1;
if (((MediaChunk) chunk).getNextChunkIndex() > lastAvailableSegmentNum) {
missingLastSegment = true;
return true;
}
}
}
int trackIndex = trackSelection.indexOf(chunk.trackFormat);
RepresentationHolder representationHolder = representationHolders[trackIndex];
@Nullable BaseUrl newBaseUrl = baseUrlExclusionList.selectBaseUrl(representationHolder.representation.baseUrls);
if (newBaseUrl != null && !representationHolder.selectedBaseUrl.equals(newBaseUrl)) {
// which will use the new base URL.
return true;
}
LoadErrorHandlingPolicy.FallbackOptions fallbackOptions = createFallbackOptions(trackSelection, representationHolder.representation.baseUrls);
if (!fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) && !fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION)) {
return false;
}
@Nullable LoadErrorHandlingPolicy.FallbackSelection fallbackSelection = loadErrorHandlingPolicy.getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
if (fallbackSelection == null || !fallbackOptions.isFallbackAvailable(fallbackSelection.type)) {
// Policy indicated to not use any fallback or a fallback type that is not available.
return false;
}
boolean cancelLoad = false;
if (fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) {
cancelLoad = trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), fallbackSelection.exclusionDurationMs);
} else if (fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION) {
baseUrlExclusionList.exclude(representationHolder.selectedBaseUrl, fallbackSelection.exclusionDurationMs);
cancelLoad = true;
}
return cancelLoad;
}
use of androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo in project media by androidx.
the class HlsSampleStreamWrapper method onLoadError.
@Override
public LoadErrorAction onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
boolean isMediaChunk = isMediaChunk(loadable);
if (isMediaChunk && !((HlsMediaChunk) loadable).isPublished() && error instanceof HttpDataSource.InvalidResponseCodeException) {
int responseCode = ((HttpDataSource.InvalidResponseCodeException) error).responseCode;
if (responseCode == 410 || responseCode == 404) {
// streams with HTTP 410 (Gone) also.
return Loader.RETRY;
}
}
long bytesLoaded = loadable.bytesLoaded();
boolean exclusionSucceeded = false;
LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, bytesLoaded);
MediaLoadData mediaLoadData = new MediaLoadData(loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, Util.usToMs(loadable.startTimeUs), Util.usToMs(loadable.endTimeUs));
LoadErrorInfo loadErrorInfo = new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
LoadErrorAction loadErrorAction;
@Nullable LoadErrorHandlingPolicy.FallbackSelection fallbackSelection = loadErrorHandlingPolicy.getFallbackSelectionFor(createFallbackOptions(chunkSource.getTrackSelection()), loadErrorInfo);
if (fallbackSelection != null && fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) {
exclusionSucceeded = chunkSource.maybeExcludeTrack(loadable, fallbackSelection.exclusionDurationMs);
}
if (exclusionSucceeded) {
if (isMediaChunk && bytesLoaded == 0) {
HlsMediaChunk removed = mediaChunks.remove(mediaChunks.size() - 1);
Assertions.checkState(removed == loadable);
if (mediaChunks.isEmpty()) {
pendingResetPositionUs = lastSeekPositionUs;
} else {
Iterables.getLast(mediaChunks).invalidateExtractor();
}
}
loadErrorAction = Loader.DONT_RETRY;
} else /* did not exclude */
{
long retryDelayMs = loadErrorHandlingPolicy.getRetryDelayMsFor(loadErrorInfo);
loadErrorAction = retryDelayMs != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
false, retryDelayMs) : Loader.DONT_RETRY_FATAL;
}
boolean wasCanceled = !loadErrorAction.isRetry();
mediaSourceEventDispatcher.loadError(loadEventInfo, loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs, error, wasCanceled);
if (wasCanceled) {
loadingChunk = null;
loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
}
if (exclusionSucceeded) {
if (!prepared) {
continueLoading(lastSeekPositionUs);
} else {
callback.onContinueLoadingRequested(this);
}
}
return loadErrorAction;
}
use of androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo in project media by androidx.
the class DefaultLoadErrorHandlingPolicyTest method getDefaultPolicyFallbackSelection.
@Nullable
private static LoadErrorHandlingPolicy.FallbackSelection getDefaultPolicyFallbackSelection(IOException exception, int numberOfLocations, int numberOfExcludedLocations, int numberOfTracks, int numberOfExcludedTracks) {
LoadErrorInfo loadErrorInfo = new LoadErrorInfo(PLACEHOLDER_LOAD_EVENT_INFO, PLACEHOLDER_MEDIA_LOAD_DATA, exception, /* errorCount= */
1);
LoadErrorHandlingPolicy.FallbackOptions fallbackOptions = new LoadErrorHandlingPolicy.FallbackOptions(numberOfLocations, numberOfExcludedLocations, numberOfTracks, numberOfExcludedTracks);
return new DefaultLoadErrorHandlingPolicy().getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
}
Aggregations