Search in sources :

Example 6 with LoadEventInfo

use of androidx.media3.exoplayer.source.LoadEventInfo 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;
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

Example 7 with LoadEventInfo

use of androidx.media3.exoplayer.source.LoadEventInfo in project media by androidx.

the class DashMediaSource method onManifestLoadCompleted.

// Loadable callbacks.
/* package */
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable, long elapsedRealtimeMs, long loadDurationMs) {
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
    loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    manifestEventDispatcher.loadCompleted(loadEventInfo, loadable.type);
    DashManifest newManifest = loadable.getResult();
    int oldPeriodCount = manifest == null ? 0 : manifest.getPeriodCount();
    int removedPeriodCount = 0;
    long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
    while (removedPeriodCount < oldPeriodCount && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
        removedPeriodCount++;
    }
    if (newManifest.dynamic) {
        boolean isManifestStale = false;
        if (oldPeriodCount - removedPeriodCount > newManifest.getPeriodCount()) {
            // After discarding old periods, we should never have more periods than listed in the new
            // manifest. That would mean that a previously announced period is no longer advertised. If
            // this condition occurs, assume that we are hitting a manifest server that is out of sync
            // and
            // behind.
            Log.w(TAG, "Loaded out of sync manifest");
            isManifestStale = true;
        } else if (expiredManifestPublishTimeUs != C.TIME_UNSET && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs) {
            // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
            // expired, or it's dynamic and we know the presentation has ended), then this manifest is
            // stale.
            Log.w(TAG, "Loaded stale dynamic manifest: " + newManifest.publishTimeMs + ", " + expiredManifestPublishTimeUs);
            isManifestStale = true;
        }
        if (isManifestStale) {
            if (staleManifestReloadAttempt++ < loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type)) {
                scheduleManifestRefresh(getManifestLoadRetryDelayMillis());
            } else {
                manifestFatalError = new DashManifestStaleException();
            }
            return;
        }
        staleManifestReloadAttempt = 0;
    }
    manifest = newManifest;
    manifestLoadPending &= manifest.dynamic;
    manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
    manifestLoadEndTimestampMs = elapsedRealtimeMs;
    synchronized (manifestUriLock) {
        // Checks whether replaceManifestUri(Uri) was called to manually replace the URI between the
        // start and end of this load. If it was then isSameUriInstance evaluates to false, and we
        // prefer the manual replacement to one derived from the previous request.
        @SuppressWarnings("ReferenceEquality") boolean isSameUriInstance = loadable.dataSpec.uri == manifestUri;
        if (isSameUriInstance) {
            // Replace the manifest URI with one specified by a manifest Location element (if present),
            // or with the final (possibly redirected) URI. This follows the recommendation in
            // DASH-IF-IOP 4.3, section 3.2.15.3. See: https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf.
            manifestUri = manifest.location != null ? manifest.location : loadable.getUri();
        }
    }
    if (oldPeriodCount == 0) {
        if (manifest.dynamic) {
            if (manifest.utcTiming != null) {
                resolveUtcTimingElement(manifest.utcTiming);
            } else {
                loadNtpTimeOffset();
            }
        } else {
            processManifest(true);
        }
    } else {
        firstPeriodId += removedPeriodCount;
        processManifest(true);
    }
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest)

Example 8 with LoadEventInfo

use of androidx.media3.exoplayer.source.LoadEventInfo in project media by androidx.

the class DefaultDashChunkSourceTest method createFakeLoadErrorInfo.

private LoadErrorHandlingPolicy.LoadErrorInfo createFakeLoadErrorInfo(DataSpec dataSpec, int httpResponseCode, int errorCount) {
    LoadEventInfo loadEventInfo = new LoadEventInfo(/* loadTaskId= */
    0, dataSpec, SystemClock.elapsedRealtime());
    MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA);
    HttpDataSource.InvalidResponseCodeException invalidResponseCodeException = new HttpDataSource.InvalidResponseCodeException(httpResponseCode, /* responseMessage= */
    null, /* cause= */
    null, ImmutableMap.of(), dataSpec, new byte[0]);
    return new LoadErrorHandlingPolicy.LoadErrorInfo(loadEventInfo, mediaLoadData, invalidResponseCodeException, errorCount);
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) HttpDataSource(androidx.media3.datasource.HttpDataSource)

Example 9 with LoadEventInfo

use of androidx.media3.exoplayer.source.LoadEventInfo 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;
}
Also used : MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) LoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) HttpDataSource(androidx.media3.datasource.HttpDataSource) Nullable(androidx.annotation.Nullable) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

Example 10 with LoadEventInfo

use of androidx.media3.exoplayer.source.LoadEventInfo in project media by androidx.

the class DefaultHlsPlaylistTracker method start.

// HlsPlaylistTracker implementation.
@Override
public void start(Uri initialPlaylistUri, EventDispatcher eventDispatcher, PrimaryPlaylistListener primaryPlaylistListener) {
    this.playlistRefreshHandler = Util.createHandlerForCurrentLooper();
    this.eventDispatcher = eventDispatcher;
    this.primaryPlaylistListener = primaryPlaylistListener;
    ParsingLoadable<HlsPlaylist> multivariantPlaylistLoadable = new ParsingLoadable<>(dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST), initialPlaylistUri, C.DATA_TYPE_MANIFEST, playlistParserFactory.createPlaylistParser());
    Assertions.checkState(initialPlaylistLoader == null);
    initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MultivariantPlaylist");
    long elapsedRealtime = initialPlaylistLoader.startLoading(multivariantPlaylistLoadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(multivariantPlaylistLoadable.type));
    eventDispatcher.loadStarted(new LoadEventInfo(multivariantPlaylistLoadable.loadTaskId, multivariantPlaylistLoadable.dataSpec, elapsedRealtime), multivariantPlaylistLoadable.type);
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) ParsingLoadable(androidx.media3.exoplayer.upstream.ParsingLoadable) Loader(androidx.media3.exoplayer.upstream.Loader)

Aggregations

LoadEventInfo (androidx.media3.exoplayer.source.LoadEventInfo)27 StatsDataSource (androidx.media3.datasource.StatsDataSource)7 MediaLoadData (androidx.media3.exoplayer.source.MediaLoadData)7 LoadErrorInfo (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)7 LoadErrorAction (androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)6 Nullable (androidx.annotation.Nullable)4 EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)4 HttpDataSource (androidx.media3.datasource.HttpDataSource)2 SampleQueue (androidx.media3.exoplayer.source.SampleQueue)2 ParsingLoadable (androidx.media3.exoplayer.upstream.ParsingLoadable)2 Uri (android.net.Uri)1 Timeline (androidx.media3.common.Timeline)1 DataSource (androidx.media3.datasource.DataSource)1 DataSpec (androidx.media3.datasource.DataSpec)1 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)1 SsManifest (androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest)1 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)1 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)1 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)1 Chunk (androidx.media3.exoplayer.source.chunk.Chunk)1