Search in sources :

Example 1 with ParsingLoadable

use of androidx.media3.exoplayer.upstream.ParsingLoadable in project media by androidx.

the class DashMediaSource method onUtcTimestampLoadCompleted.

/* package */
void onUtcTimestampLoadCompleted(ParsingLoadable<Long> 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);
    onUtcTimestampResolved(loadable.getResult() - elapsedRealtimeMs);
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo)

Example 2 with ParsingLoadable

use of androidx.media3.exoplayer.upstream.ParsingLoadable in project media by androidx.

the class DashMediaSource method onUtcTimestampLoadError.

/* package */
LoadErrorAction onUtcTimestampLoadError(ParsingLoadable<Long> loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error) {
    manifestEventDispatcher.loadError(new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()), loadable.type, error, /* wasCanceled= */
    true);
    loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    onUtcTimestampResolutionError(error);
    return Loader.DONT_RETRY;
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo)

Example 3 with ParsingLoadable

use of androidx.media3.exoplayer.upstream.ParsingLoadable 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 4 with ParsingLoadable

use of androidx.media3.exoplayer.upstream.ParsingLoadable 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 5 with ParsingLoadable

use of androidx.media3.exoplayer.upstream.ParsingLoadable 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)14 MediaLoadData (androidx.media3.exoplayer.source.MediaLoadData)3 LoadErrorInfo (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)3 LoadErrorAction (androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)2 ParsingLoadable (androidx.media3.exoplayer.upstream.ParsingLoadable)2 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)1 SsManifest (androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest)1 Loader (androidx.media3.exoplayer.upstream.Loader)1