Search in sources :

Example 6 with DashSegmentIndex

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

the class DashMediaSource method getIntervalUntilNextManifestRefreshMs.

private static long getIntervalUntilNextManifestRefreshMs(DashManifest manifest, long nowUnixTimeMs) {
    int periodIndex = manifest.getPeriodCount() - 1;
    Period period = manifest.getPeriod(periodIndex);
    long periodStartUs = Util.msToUs(period.startMs);
    long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
    long nowUnixTimeUs = Util.msToUs(nowUnixTimeMs);
    long availabilityStartTimeUs = Util.msToUs(manifest.availabilityStartTimeMs);
    long intervalUs = Util.msToUs(DEFAULT_NOTIFY_MANIFEST_INTERVAL_MS);
    for (int i = 0; i < period.adaptationSets.size(); i++) {
        List<Representation> representations = period.adaptationSets.get(i).representations;
        if (representations.isEmpty()) {
            continue;
        }
        @Nullable DashSegmentIndex index = representations.get(0).getIndex();
        if (index != null) {
            long nextSegmentShiftUnixTimeUs = availabilityStartTimeUs + periodStartUs + index.getNextSegmentAvailableTimeUs(periodDurationUs, nowUnixTimeUs);
            long requiredIntervalUs = nextSegmentShiftUnixTimeUs - nowUnixTimeUs;
            // Avoid multiple refreshes within a very small amount of time.
            if (requiredIntervalUs < intervalUs - 100_000 || (requiredIntervalUs > intervalUs && requiredIntervalUs < intervalUs + 100_000)) {
                intervalUs = requiredIntervalUs;
            }
        }
    }
    // Round up to compensate for a potential loss in the us to ms conversion.
    return LongMath.divide(intervalUs, 1000, RoundingMode.CEILING);
}
Also used : MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) Period(com.google.android.exoplayer2.source.dash.manifest.Period) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)5 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)5 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)2 IOException (java.io.IOException)2 ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)1 DownloadException (com.google.android.exoplayer2.offline.DownloadException)1 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)1 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)1 DashWrappingSegmentIndex (com.google.android.exoplayer2.source.dash.DashWrappingSegmentIndex)1 Period (com.google.android.exoplayer2.source.dash.manifest.Period)1 RunnableFutureTask (com.google.android.exoplayer2.util.RunnableFutureTask)1 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)1