private long getSegmentNum( RepresentationHolder representationHolder, @Nullable MediaChunk previousChunk, long loadPositionUs, long firstAvailableSegmentNum, long lastAvailableSegmentNum) { return previousChunk != null ? previousChunk.getNextChunkIndex() : Util.constrainValue( representationHolder.getSegmentNum(loadPositionUs), firstAvailableSegmentNum, lastAvailableSegmentNum); }
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(); }
@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; }