public long getFirstAvailableSegmentNum( DashManifest manifest, int periodIndex, long nowUnixTimeUs) { if (getSegmentCount() == DashSegmentIndex.INDEX_UNBOUNDED && manifest.timeShiftBufferDepthMs != C.TIME_UNSET) { // The index is itself unbounded. We need to use the current time to calculate the range of // available segments. long liveEdgeTimeUs = nowUnixTimeUs - C.msToUs(manifest.availabilityStartTimeMs); long periodStartUs = C.msToUs(manifest.getPeriod(periodIndex).startMs); long liveEdgeTimeInPeriodUs = liveEdgeTimeUs - periodStartUs; long bufferDepthUs = C.msToUs(manifest.timeShiftBufferDepthMs); return Math.max( getFirstSegmentNum(), getSegmentNum(liveEdgeTimeInPeriodUs - bufferDepthUs)); } return getFirstSegmentNum(); }
boolean periodEnded = periodDurationUs != C.TIME_UNSET; if (representationHolder.getSegmentCount() == 0) {
@Override public boolean onChunkLoadError( Chunk chunk, boolean cancelable, Exception e, long blacklistDurationMs) { if (!cancelable) { return false; } if (playerTrackEmsgHandler != null && playerTrackEmsgHandler.maybeRefreshManifestOnLoadingError(chunk)) { return true; } // Workaround for missing segment at the end of the period if (!manifest.dynamic && chunk instanceof MediaChunk && e instanceof InvalidResponseCodeException && ((InvalidResponseCodeException) e).responseCode == 404) { RepresentationHolder representationHolder = representationHolders[trackSelection.indexOf(chunk.trackFormat)]; int 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; } } } return blacklistDurationMs != C.TIME_UNSET && trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), blacklistDurationMs); }
@Override public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) { // Segments are aligned across representations, so any segment index will do. for (RepresentationHolder representationHolder : representationHolders) { if (representationHolder.segmentIndex != null) { long segmentNum = representationHolder.getSegmentNum(positionUs); long firstSyncUs = representationHolder.getSegmentStartTimeUs(segmentNum); long secondSyncUs = firstSyncUs < positionUs && segmentNum < representationHolder.getSegmentCount() - 1 ? representationHolder.getSegmentStartTimeUs(segmentNum + 1) : firstSyncUs; return Util.resolveSeekPositionUs(positionUs, seekParameters, firstSyncUs, secondSyncUs); } } // We don't have a segment index to adjust the seek position with yet. return positionUs; }
public long getLastAvailableSegmentNum( DashManifest manifest, int periodIndex, long nowUnixTimeUs) { int availableSegmentCount = getSegmentCount(); if (availableSegmentCount == DashSegmentIndex.INDEX_UNBOUNDED) { // The index is itself unbounded. We need to use the current time to calculate the range of // available segments. long liveEdgeTimeUs = nowUnixTimeUs - C.msToUs(manifest.availabilityStartTimeMs); long periodStartUs = C.msToUs(manifest.getPeriod(periodIndex).startMs); long liveEdgeTimeInPeriodUs = liveEdgeTimeUs - periodStartUs; // getSegmentNum(liveEdgeTimeInPeriodUs) will not be completed yet, so subtract one to get // the index of the last completed segment. return getSegmentNum(liveEdgeTimeInPeriodUs) - 1; } return getFirstSegmentNum() + availableSegmentCount - 1; }