@Override public int getCurrentWindowIndex() { if (shouldMaskPosition()) { return maskingWindowIndex; } else { return playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period) .windowIndex; } }
private long periodPositionUsToWindowPositionMs(MediaPeriodId periodId, long positionUs) { long positionMs = C.usToMs(positionUs); playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period); positionMs += period.getPositionInWindowMs(); return positionMs; }
@Override protected FakeMediaPeriod createFakeMediaPeriod( MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, EventDispatcher eventDispatcher, @Nullable TransferListener transferListener) { Period period = timeline.getPeriodByUid(id.periodUid, new Period()); return new FakeAdaptiveMediaPeriod( trackGroupArray, eventDispatcher, allocator, chunkSourceFactory, period.durationUs, transferListener); }
@Override public long getDuration() { if (isPlayingAd()) { MediaPeriodId periodId = playbackInfo.periodId; playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period); long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup); return C.usToMs(adDurationUs); } return getContentDuration(); }
@Override public long getContentPosition() { if (isPlayingAd()) { playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period); return period.getPositionInWindowMs() + C.usToMs(playbackInfo.contentPositionUs); } else { return getCurrentPosition(); } }
private MediaPeriodInfo getMediaPeriodInfo( MediaPeriodId id, long contentPositionUs, long startPositionUs) { timeline.getPeriodByUid(id.periodUid, period); if (id.isAd()) { if (!period.isAdAvailable(id.adGroupIndex, id.adIndexInAdGroup)) { return null; } return getMediaPeriodInfoForAd( id.periodUid, id.adGroupIndex, id.adIndexInAdGroup, contentPositionUs, id.windowSequenceNumber); } else { return getMediaPeriodInfoForContent(id.periodUid, startPositionUs, id.windowSequenceNumber); } }
@Override protected FakeMediaPeriod createFakeMediaPeriod( MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, EventDispatcher eventDispatcher, @Nullable TransferListener transferListener) { Period period = timeline.getPeriodByUid(id.periodUid, new Period()); return new FakeAdaptiveMediaPeriod( trackGroupArray, eventDispatcher, allocator, chunkSourceFactory, period.durationUs, transferListener); }
@Override public final Period getPeriodByUid(Object uid, Period period) { Object childUid = getChildTimelineUidFromConcatenatedUid(uid); Object periodUid = getChildPeriodUidFromConcatenatedUid(uid); int childIndex = getChildIndexByChildUid(childUid); int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex); getTimelineByChildIndex(childIndex).getPeriodByUid(periodUid, period); period.windowIndex += firstWindowIndexInChild; period.uid = uid; return period; }
private boolean isLastInPeriod(MediaPeriodId id) { int adGroupCount = timeline.getPeriodByUid(id.periodUid, period).getAdGroupCount(); if (adGroupCount == 0) { return true; } int lastAdGroupIndex = adGroupCount - 1; boolean isAd = id.isAd(); if (period.getAdGroupTimeUs(lastAdGroupIndex) != C.TIME_END_OF_SOURCE) { // There's no postroll ad. return !isAd && id.endPositionUs == C.TIME_END_OF_SOURCE; } int postrollAdCount = period.getAdCountInAdGroup(lastAdGroupIndex); if (postrollAdCount == C.LENGTH_UNSET) { // We won't know if this is the last ad until we know how many postroll ads there are. return false; } boolean isLastAd = isAd && id.adGroupIndex == lastAdGroupIndex && id.adIndexInAdGroup == postrollAdCount - 1; return isLastAd || (!isAd && period.getFirstAdIndexToPlay(lastAdGroupIndex) == postrollAdCount); }
int windowIndex = timeline.getPeriodByUid(periodUid, period).windowIndex; if (oldFrontPeriodUid != null) { int oldFrontPeriodIndex = timeline.getIndexOfPeriod(oldFrontPeriodUid);
private MediaPeriodInfo getMediaPeriodInfoForContent( Object periodUid, long startPositionUs, long windowSequenceNumber) { int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(startPositionUs); long endPositionUs = nextAdGroupIndex == C.INDEX_UNSET ? C.TIME_END_OF_SOURCE : period.getAdGroupTimeUs(nextAdGroupIndex); MediaPeriodId id = new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs); timeline.getPeriodByUid(id.periodUid, period); boolean isLastInPeriod = isLastInPeriod(id); boolean isLastInTimeline = isLastInTimeline(id, isLastInPeriod); long durationUs = endPositionUs == C.TIME_END_OF_SOURCE ? period.getDurationUs() : endPositionUs; return new MediaPeriodInfo( id, startPositionUs, C.TIME_UNSET, durationUs, isLastInPeriod, isLastInTimeline); }
/** * Returns new media period info based on specified {@code mediaPeriodInfo} but taking into * account the current timeline. This method must only be called if the period is still part of * the current timeline. * * @param info Media period info for a media period based on an old timeline. * @return The updated media period info for the current timeline. */ public MediaPeriodInfo getUpdatedMediaPeriodInfo(MediaPeriodInfo info) { boolean isLastInPeriod = isLastInPeriod(info.id); boolean isLastInTimeline = isLastInTimeline(info.id, isLastInPeriod); timeline.getPeriodByUid(info.id.periodUid, period); long durationUs = info.id.isAd() ? period.getAdDurationUs(info.id.adGroupIndex, info.id.adIndexInAdGroup) : (info.id.endPositionUs == C.TIME_END_OF_SOURCE ? period.getDurationUs() : info.id.endPositionUs); return new MediaPeriodInfo( info.id, info.startPositionUs, info.contentPositionUs, durationUs, isLastInPeriod, isLastInTimeline); }
/** * Resolves the specified timeline period and position to a {@link MediaPeriodId} that should be * played, returning an identifier for an ad group if one needs to be played before the specified * position, or an identifier for a content media period if not. * * @param periodUid The uid of the timeline period to play. * @param positionUs The next content position in the period to play. * @param windowSequenceNumber The sequence number of the window in the buffered sequence of * windows this period is part of. * @return The identifier for the first media period to play, taking into account unplayed ads. */ private MediaPeriodId resolveMediaPeriodIdForAds( Object periodUid, long positionUs, long windowSequenceNumber) { timeline.getPeriodByUid(periodUid, period); int adGroupIndex = period.getAdGroupIndexForPositionUs(positionUs); if (adGroupIndex == C.INDEX_UNSET) { int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(positionUs); long endPositionUs = nextAdGroupIndex == C.INDEX_UNSET ? C.TIME_END_OF_SOURCE : period.getAdGroupTimeUs(nextAdGroupIndex); return new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs); } else { int adIndexInAdGroup = period.getFirstAdIndexToPlay(adGroupIndex); return new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber); } }
@Override public long getContentBufferedPosition() { if (shouldMaskPosition()) { return maskingWindowPositionMs; } if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber != playbackInfo.periodId.windowSequenceNumber) { return playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); } long contentBufferedPositionUs = playbackInfo.bufferedPositionUs; if (playbackInfo.loadingMediaPeriodId.isAd()) { Timeline.Period loadingPeriod = playbackInfo.timeline.getPeriodByUid(playbackInfo.loadingMediaPeriodId.periodUid, period); contentBufferedPositionUs = loadingPeriod.getAdGroupTimeUs(playbackInfo.loadingMediaPeriodId.adGroupIndex); if (contentBufferedPositionUs == C.TIME_END_OF_SOURCE) { contentBufferedPositionUs = loadingPeriod.durationUs; } } return periodPositionUsToWindowPositionMs( playbackInfo.loadingMediaPeriodId, contentBufferedPositionUs); }
private MediaPeriodInfo getMediaPeriodInfoForAd( Object periodUid, int adGroupIndex, int adIndexInAdGroup, long contentPositionUs, long windowSequenceNumber) { MediaPeriodId id = new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber); boolean isLastInPeriod = isLastInPeriod(id); boolean isLastInTimeline = isLastInTimeline(id, isLastInPeriod); long durationUs = timeline .getPeriodByUid(id.periodUid, period) .getAdDurationUs(id.adGroupIndex, id.adIndexInAdGroup); long startPositionUs = adIndexInAdGroup == period.getFirstAdIndexToPlay(adGroupIndex) ? period.getAdResumePositionUs() : 0; return new MediaPeriodInfo( id, startPositionUs, contentPositionUs, durationUs, isLastInPeriod, isLastInTimeline); }
timeline.getPeriodByUid(currentPeriodId.periodUid, period); if (currentPeriodId.isAd()) { int adGroupIndex = currentPeriodId.adGroupIndex;
timeline, timeline.getPeriodByUid(newPeriodUid, period).windowIndex, C.TIME_UNSET); newPeriodUid = defaultPosition.first; contentPositionUs = defaultPosition.second;