mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Migrate usages of Timeline#getPeriodPosition to getPeriodPositionUs
#minor-release PiperOrigin-RevId: 414671861
This commit is contained in:
parent
07352a4585
commit
5c2f618613
7 changed files with 124 additions and 95 deletions
|
|
@ -700,7 +700,7 @@ public final class ImaAdsLoader implements Player.Listener, AdsLoader {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long periodPositionUs =
|
long periodPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window, period, period.windowIndex, /* windowPositionUs= */ C.TIME_UNSET)
|
window, period, period.windowIndex, /* windowPositionUs= */ C.TIME_UNSET)
|
||||||
.second;
|
.second;
|
||||||
nextAdTagLoader.maybePreloadAds(Util.usToMs(periodPositionUs), Util.usToMs(period.durationUs));
|
nextAdTagLoader.maybePreloadAds(Util.usToMs(periodPositionUs), Util.usToMs(period.durationUs));
|
||||||
|
|
|
||||||
|
|
@ -1190,13 +1190,13 @@ public abstract class Timeline implements Bundleable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls {@link #getPeriodPosition(Window, Period, int, long, long)} with a zero default position
|
* Calls {@link #getPeriodPositionUs(Window, Period, int, long)} with a zero default position
|
||||||
* projection.
|
* projection.
|
||||||
*/
|
*/
|
||||||
public final Pair<Object, Long> getPeriodPositionUs(
|
public final Pair<Object, Long> getPeriodPositionUs(
|
||||||
Window window, Period period, int windowIndex, long windowPositionUs) {
|
Window window, Period period, int windowIndex, long windowPositionUs) {
|
||||||
return Assertions.checkNotNull(
|
return Assertions.checkNotNull(
|
||||||
getPeriodPosition(
|
getPeriodPositionUs(
|
||||||
window, period, windowIndex, windowPositionUs, /* defaultPositionProjectionUs= */ 0));
|
window, period, windowIndex, windowPositionUs, /* defaultPositionProjectionUs= */ 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -499,7 +499,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
newTimeline,
|
newTimeline,
|
||||||
getPeriodPositionAfterTimelineChanged(oldTimeline, newTimeline));
|
getPeriodPositionUsAfterTimelineChanged(oldTimeline, newTimeline));
|
||||||
internalPlayer.addMediaSources(index, holders, shuffleOrder);
|
internalPlayer.addMediaSources(index, holders, shuffleOrder);
|
||||||
updatePlaybackInfo(
|
updatePlaybackInfo(
|
||||||
newPlaybackInfo,
|
newPlaybackInfo,
|
||||||
|
|
@ -543,7 +543,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
newTimeline,
|
newTimeline,
|
||||||
getPeriodPositionAfterTimelineChanged(oldTimeline, newTimeline));
|
getPeriodPositionUsAfterTimelineChanged(oldTimeline, newTimeline));
|
||||||
internalPlayer.moveMediaSources(fromIndex, toIndex, newFromIndex, shuffleOrder);
|
internalPlayer.moveMediaSources(fromIndex, toIndex, newFromIndex, shuffleOrder);
|
||||||
updatePlaybackInfo(
|
updatePlaybackInfo(
|
||||||
newPlaybackInfo,
|
newPlaybackInfo,
|
||||||
|
|
@ -562,7 +562,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
timeline,
|
timeline,
|
||||||
getPeriodPositionOrMaskWindowPosition(
|
maskWindowPositionMsOrGetPeriodPositionUs(
|
||||||
timeline, getCurrentMediaItemIndex(), getCurrentPosition()));
|
timeline, getCurrentMediaItemIndex(), getCurrentPosition()));
|
||||||
pendingOperationAcks++;
|
pendingOperationAcks++;
|
||||||
this.shuffleOrder = shuffleOrder;
|
this.shuffleOrder = shuffleOrder;
|
||||||
|
|
@ -680,7 +680,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
newPlaybackInfo,
|
newPlaybackInfo,
|
||||||
timeline,
|
timeline,
|
||||||
getPeriodPositionOrMaskWindowPosition(timeline, mediaItemIndex, positionMs));
|
maskWindowPositionMsOrGetPeriodPositionUs(timeline, mediaItemIndex, positionMs));
|
||||||
internalPlayer.seekTo(timeline, mediaItemIndex, Util.msToUs(positionMs));
|
internalPlayer.seekTo(timeline, mediaItemIndex, Util.msToUs(positionMs));
|
||||||
updatePlaybackInfo(
|
updatePlaybackInfo(
|
||||||
newPlaybackInfo,
|
newPlaybackInfo,
|
||||||
|
|
@ -1441,7 +1441,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
timeline,
|
timeline,
|
||||||
getPeriodPositionOrMaskWindowPosition(timeline, startWindowIndex, startPositionMs));
|
maskWindowPositionMsOrGetPeriodPositionUs(timeline, startWindowIndex, startPositionMs));
|
||||||
// Mask the playback state.
|
// Mask the playback state.
|
||||||
int maskingPlaybackState = newPlaybackInfo.playbackState;
|
int maskingPlaybackState = newPlaybackInfo.playbackState;
|
||||||
if (startWindowIndex != C.INDEX_UNSET && newPlaybackInfo.playbackState != STATE_IDLE) {
|
if (startWindowIndex != C.INDEX_UNSET && newPlaybackInfo.playbackState != STATE_IDLE) {
|
||||||
|
|
@ -1499,7 +1499,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
maskTimelineAndPosition(
|
maskTimelineAndPosition(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
newTimeline,
|
newTimeline,
|
||||||
getPeriodPositionAfterTimelineChanged(oldTimeline, newTimeline));
|
getPeriodPositionUsAfterTimelineChanged(oldTimeline, newTimeline));
|
||||||
// Player transitions to STATE_ENDED if the current index is part of the removed tail.
|
// Player transitions to STATE_ENDED if the current index is part of the removed tail.
|
||||||
final boolean transitionsToEnded =
|
final boolean transitionsToEnded =
|
||||||
newPlaybackInfo.playbackState != STATE_IDLE
|
newPlaybackInfo.playbackState != STATE_IDLE
|
||||||
|
|
@ -1526,8 +1526,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlaybackInfo maskTimelineAndPosition(
|
private PlaybackInfo maskTimelineAndPosition(
|
||||||
PlaybackInfo playbackInfo, Timeline timeline, @Nullable Pair<Object, Long> periodPosition) {
|
PlaybackInfo playbackInfo, Timeline timeline, @Nullable Pair<Object, Long> periodPositionUs) {
|
||||||
Assertions.checkArgument(timeline.isEmpty() || periodPosition != null);
|
Assertions.checkArgument(timeline.isEmpty() || periodPositionUs != null);
|
||||||
Timeline oldTimeline = playbackInfo.timeline;
|
Timeline oldTimeline = playbackInfo.timeline;
|
||||||
// Mask the timeline.
|
// Mask the timeline.
|
||||||
playbackInfo = playbackInfo.copyWithTimeline(timeline);
|
playbackInfo = playbackInfo.copyWithTimeline(timeline);
|
||||||
|
|
@ -1552,10 +1552,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object oldPeriodUid = playbackInfo.periodId.periodUid;
|
Object oldPeriodUid = playbackInfo.periodId.periodUid;
|
||||||
boolean playingPeriodChanged = !oldPeriodUid.equals(castNonNull(periodPosition).first);
|
boolean playingPeriodChanged = !oldPeriodUid.equals(castNonNull(periodPositionUs).first);
|
||||||
MediaPeriodId newPeriodId =
|
MediaPeriodId newPeriodId =
|
||||||
playingPeriodChanged ? new MediaPeriodId(periodPosition.first) : playbackInfo.periodId;
|
playingPeriodChanged ? new MediaPeriodId(periodPositionUs.first) : playbackInfo.periodId;
|
||||||
long newContentPositionUs = periodPosition.second;
|
long newContentPositionUs = periodPositionUs.second;
|
||||||
long oldContentPositionUs = Util.msToUs(getContentPosition());
|
long oldContentPositionUs = Util.msToUs(getContentPosition());
|
||||||
if (!oldTimeline.isEmpty()) {
|
if (!oldTimeline.isEmpty()) {
|
||||||
oldContentPositionUs -=
|
oldContentPositionUs -=
|
||||||
|
|
@ -1631,25 +1631,25 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Pair<Object, Long> getPeriodPositionAfterTimelineChanged(
|
private Pair<Object, Long> getPeriodPositionUsAfterTimelineChanged(
|
||||||
Timeline oldTimeline, Timeline newTimeline) {
|
Timeline oldTimeline, Timeline newTimeline) {
|
||||||
long currentPositionMs = getContentPosition();
|
long currentPositionMs = getContentPosition();
|
||||||
if (oldTimeline.isEmpty() || newTimeline.isEmpty()) {
|
if (oldTimeline.isEmpty() || newTimeline.isEmpty()) {
|
||||||
boolean isCleared = !oldTimeline.isEmpty() && newTimeline.isEmpty();
|
boolean isCleared = !oldTimeline.isEmpty() && newTimeline.isEmpty();
|
||||||
return getPeriodPositionOrMaskWindowPosition(
|
return maskWindowPositionMsOrGetPeriodPositionUs(
|
||||||
newTimeline,
|
newTimeline,
|
||||||
isCleared ? C.INDEX_UNSET : getCurrentWindowIndexInternal(),
|
isCleared ? C.INDEX_UNSET : getCurrentWindowIndexInternal(),
|
||||||
isCleared ? C.TIME_UNSET : currentPositionMs);
|
isCleared ? C.TIME_UNSET : currentPositionMs);
|
||||||
}
|
}
|
||||||
int currentMediaItemIndex = getCurrentMediaItemIndex();
|
int currentMediaItemIndex = getCurrentMediaItemIndex();
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> oldPeriodPosition =
|
Pair<Object, Long> oldPeriodPositionUs =
|
||||||
oldTimeline.getPeriodPosition(
|
oldTimeline.getPeriodPositionUs(
|
||||||
window, period, currentMediaItemIndex, Util.msToUs(currentPositionMs));
|
window, period, currentMediaItemIndex, Util.msToUs(currentPositionMs));
|
||||||
Object periodUid = castNonNull(oldPeriodPosition).first;
|
Object periodUid = castNonNull(oldPeriodPositionUs).first;
|
||||||
if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) {
|
if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) {
|
||||||
// The old period position is still available in the new timeline.
|
// The old period position is still available in the new timeline.
|
||||||
return oldPeriodPosition;
|
return oldPeriodPositionUs;
|
||||||
}
|
}
|
||||||
// Period uid not found in new timeline. Try to get subsequent period.
|
// Period uid not found in new timeline. Try to get subsequent period.
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
@ -1659,19 +1659,19 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
if (nextPeriodUid != null) {
|
if (nextPeriodUid != null) {
|
||||||
// Reset position to the default position of the window of the subsequent period.
|
// Reset position to the default position of the window of the subsequent period.
|
||||||
newTimeline.getPeriodByUid(nextPeriodUid, period);
|
newTimeline.getPeriodByUid(nextPeriodUid, period);
|
||||||
return getPeriodPositionOrMaskWindowPosition(
|
return maskWindowPositionMsOrGetPeriodPositionUs(
|
||||||
newTimeline,
|
newTimeline,
|
||||||
period.windowIndex,
|
period.windowIndex,
|
||||||
newTimeline.getWindow(period.windowIndex, window).getDefaultPositionMs());
|
newTimeline.getWindow(period.windowIndex, window).getDefaultPositionMs());
|
||||||
} else {
|
} else {
|
||||||
// No subsequent period found and the new timeline is not empty. Use the default position.
|
// No subsequent period found and the new timeline is not empty. Use the default position.
|
||||||
return getPeriodPositionOrMaskWindowPosition(
|
return maskWindowPositionMsOrGetPeriodPositionUs(
|
||||||
newTimeline, /* windowIndex= */ C.INDEX_UNSET, /* windowPositionMs= */ C.TIME_UNSET);
|
newTimeline, /* windowIndex= */ C.INDEX_UNSET, /* windowPositionMs= */ C.TIME_UNSET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Pair<Object, Long> getPeriodPositionOrMaskWindowPosition(
|
private Pair<Object, Long> maskWindowPositionMsOrGetPeriodPositionUs(
|
||||||
Timeline timeline, int windowIndex, long windowPositionMs) {
|
Timeline timeline, int windowIndex, long windowPositionMs) {
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
// If empty we store the initial seek in the masking variables.
|
// If empty we store the initial seek in the masking variables.
|
||||||
|
|
@ -1686,7 +1686,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
windowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
|
windowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
|
||||||
windowPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs();
|
windowPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs();
|
||||||
}
|
}
|
||||||
return timeline.getPeriodPosition(window, period, windowIndex, Util.msToUs(windowPositionMs));
|
return timeline.getPeriodPositionUs(window, period, windowIndex, Util.msToUs(windowPositionMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private long periodPositionUsToWindowPositionUs(
|
private long periodPositionUsToWindowPositionUs(
|
||||||
|
|
|
||||||
|
|
@ -1123,7 +1123,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
boolean seekPositionAdjusted;
|
boolean seekPositionAdjusted;
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> resolvedSeekPosition =
|
Pair<Object, Long> resolvedSeekPosition =
|
||||||
resolveSeekPosition(
|
resolveSeekPositionUs(
|
||||||
playbackInfo.timeline,
|
playbackInfo.timeline,
|
||||||
seekPosition,
|
seekPosition,
|
||||||
/* trySubsequentPeriods= */ true,
|
/* trySubsequentPeriods= */ true,
|
||||||
|
|
@ -1134,10 +1134,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
if (resolvedSeekPosition == null) {
|
if (resolvedSeekPosition == null) {
|
||||||
// The seek position was valid for the timeline that it was performed into, but the
|
// The seek position was valid for the timeline that it was performed into, but the
|
||||||
// timeline has changed or is not ready and a suitable seek position could not be resolved.
|
// timeline has changed or is not ready and a suitable seek position could not be resolved.
|
||||||
Pair<MediaPeriodId, Long> firstPeriodAndPosition =
|
Pair<MediaPeriodId, Long> firstPeriodAndPositionUs =
|
||||||
getPlaceholderFirstMediaPeriodPosition(playbackInfo.timeline);
|
getPlaceholderFirstMediaPeriodPositionUs(playbackInfo.timeline);
|
||||||
periodId = firstPeriodAndPosition.first;
|
periodId = firstPeriodAndPositionUs.first;
|
||||||
periodPositionUs = firstPeriodAndPosition.second;
|
periodPositionUs = firstPeriodAndPositionUs.second;
|
||||||
requestedContentPositionUs = C.TIME_UNSET;
|
requestedContentPositionUs = C.TIME_UNSET;
|
||||||
seekPositionAdjusted = !playbackInfo.timeline.isEmpty();
|
seekPositionAdjusted = !playbackInfo.timeline.isEmpty();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1412,10 +1412,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
boolean resetTrackInfo = false;
|
boolean resetTrackInfo = false;
|
||||||
if (resetPosition) {
|
if (resetPosition) {
|
||||||
pendingInitialSeekPosition = null;
|
pendingInitialSeekPosition = null;
|
||||||
Pair<MediaPeriodId, Long> firstPeriodAndPosition =
|
Pair<MediaPeriodId, Long> firstPeriodAndPositionUs =
|
||||||
getPlaceholderFirstMediaPeriodPosition(playbackInfo.timeline);
|
getPlaceholderFirstMediaPeriodPositionUs(playbackInfo.timeline);
|
||||||
mediaPeriodId = firstPeriodAndPosition.first;
|
mediaPeriodId = firstPeriodAndPositionUs.first;
|
||||||
startPositionUs = firstPeriodAndPosition.second;
|
startPositionUs = firstPeriodAndPositionUs.second;
|
||||||
requestedContentPositionUs = C.TIME_UNSET;
|
requestedContentPositionUs = C.TIME_UNSET;
|
||||||
if (!mediaPeriodId.equals(playbackInfo.periodId)) {
|
if (!mediaPeriodId.equals(playbackInfo.periodId)) {
|
||||||
resetTrackInfo = true;
|
resetTrackInfo = true;
|
||||||
|
|
@ -1451,19 +1451,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<MediaPeriodId, Long> getPlaceholderFirstMediaPeriodPosition(Timeline timeline) {
|
private Pair<MediaPeriodId, Long> getPlaceholderFirstMediaPeriodPositionUs(Timeline timeline) {
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
return Pair.create(PlaybackInfo.getDummyPeriodForEmptyTimeline(), 0L);
|
return Pair.create(PlaybackInfo.getDummyPeriodForEmptyTimeline(), 0L);
|
||||||
}
|
}
|
||||||
int firstWindowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
|
int firstWindowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
|
||||||
Pair<Object, Long> firstPeriodAndPosition =
|
Pair<Object, Long> firstPeriodAndPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window, period, firstWindowIndex, /* windowPositionUs= */ C.TIME_UNSET);
|
window, period, firstWindowIndex, /* windowPositionUs= */ C.TIME_UNSET);
|
||||||
// Add ad metadata if any and propagate the window sequence number to new period id.
|
// Add ad metadata if any and propagate the window sequence number to new period id.
|
||||||
MediaPeriodId firstPeriodId =
|
MediaPeriodId firstPeriodId =
|
||||||
queue.resolveMediaPeriodIdForAds(
|
queue.resolveMediaPeriodIdForAds(
|
||||||
timeline, firstPeriodAndPosition.first, /* positionUs= */ 0);
|
timeline, firstPeriodAndPositionUs.first, /* positionUs= */ 0);
|
||||||
long positionUs = firstPeriodAndPosition.second;
|
long positionUs = firstPeriodAndPositionUs.second;
|
||||||
if (firstPeriodId.isAd()) {
|
if (firstPeriodId.isAd()) {
|
||||||
timeline.getPeriodByUid(firstPeriodId.periodUid, period);
|
timeline.getPeriodByUid(firstPeriodId.periodUid, period);
|
||||||
positionUs =
|
positionUs =
|
||||||
|
|
@ -2543,7 +2543,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
// Resolve initial seek position.
|
// Resolve initial seek position.
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> periodPosition =
|
Pair<Object, Long> periodPosition =
|
||||||
resolveSeekPosition(
|
resolveSeekPositionUs(
|
||||||
timeline,
|
timeline,
|
||||||
pendingInitialSeekPosition,
|
pendingInitialSeekPosition,
|
||||||
/* trySubsequentPeriods= */ true,
|
/* trySubsequentPeriods= */ true,
|
||||||
|
|
@ -2608,10 +2608,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
// at position 0 and don't need to be resolved.
|
// at position 0 and don't need to be resolved.
|
||||||
long windowPositionUs = oldContentPositionUs + period.getPositionInWindowUs();
|
long windowPositionUs = oldContentPositionUs + period.getPositionInWindowUs();
|
||||||
int windowIndex = timeline.getPeriodByUid(newPeriodUid, period).windowIndex;
|
int windowIndex = timeline.getPeriodByUid(newPeriodUid, period).windowIndex;
|
||||||
Pair<Object, Long> periodPosition =
|
Pair<Object, Long> periodPositionUs =
|
||||||
timeline.getPeriodPosition(window, period, windowIndex, windowPositionUs);
|
timeline.getPeriodPositionUs(window, period, windowIndex, windowPositionUs);
|
||||||
newPeriodUid = periodPosition.first;
|
newPeriodUid = periodPositionUs.first;
|
||||||
newContentPositionUs = periodPosition.second;
|
newContentPositionUs = periodPositionUs.second;
|
||||||
}
|
}
|
||||||
// Use an explicitly requested content position as new target live offset.
|
// Use an explicitly requested content position as new target live offset.
|
||||||
setTargetLiveOffset = true;
|
setTargetLiveOffset = true;
|
||||||
|
|
@ -2620,14 +2620,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
// Set period uid for default positions and resolve position for ad resolution.
|
// Set period uid for default positions and resolve position for ad resolution.
|
||||||
long contentPositionForAdResolutionUs = newContentPositionUs;
|
long contentPositionForAdResolutionUs = newContentPositionUs;
|
||||||
if (startAtDefaultPositionWindowIndex != C.INDEX_UNSET) {
|
if (startAtDefaultPositionWindowIndex != C.INDEX_UNSET) {
|
||||||
Pair<Object, Long> defaultPosition =
|
Pair<Object, Long> defaultPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window,
|
window,
|
||||||
period,
|
period,
|
||||||
startAtDefaultPositionWindowIndex,
|
startAtDefaultPositionWindowIndex,
|
||||||
/* windowPositionUs= */ C.TIME_UNSET);
|
/* windowPositionUs= */ C.TIME_UNSET);
|
||||||
newPeriodUid = defaultPosition.first;
|
newPeriodUid = defaultPositionUs.first;
|
||||||
contentPositionForAdResolutionUs = defaultPosition.second;
|
contentPositionForAdResolutionUs = defaultPositionUs.second;
|
||||||
newContentPositionUs = C.TIME_UNSET;
|
newContentPositionUs = C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2741,7 +2741,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
: Util.msToUs(pendingMessageInfo.message.getPositionMs());
|
: Util.msToUs(pendingMessageInfo.message.getPositionMs());
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> periodPosition =
|
Pair<Object, Long> periodPosition =
|
||||||
resolveSeekPosition(
|
resolveSeekPositionUs(
|
||||||
newTimeline,
|
newTimeline,
|
||||||
new SeekPosition(
|
new SeekPosition(
|
||||||
pendingMessageInfo.message.getTimeline(),
|
pendingMessageInfo.message.getTimeline(),
|
||||||
|
|
@ -2786,12 +2786,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
pendingMessageInfo.resolvedPeriodTimeUs + period.getPositionInWindowUs();
|
pendingMessageInfo.resolvedPeriodTimeUs + period.getPositionInWindowUs();
|
||||||
int windowIndex =
|
int windowIndex =
|
||||||
newTimeline.getPeriodByUid(pendingMessageInfo.resolvedPeriodUid, period).windowIndex;
|
newTimeline.getPeriodByUid(pendingMessageInfo.resolvedPeriodUid, period).windowIndex;
|
||||||
Pair<Object, Long> periodPosition =
|
Pair<Object, Long> periodPositionUs =
|
||||||
newTimeline.getPeriodPosition(window, period, windowIndex, windowPositionUs);
|
newTimeline.getPeriodPositionUs(window, period, windowIndex, windowPositionUs);
|
||||||
pendingMessageInfo.setResolvedPosition(
|
pendingMessageInfo.setResolvedPosition(
|
||||||
/* periodIndex= */ newTimeline.getIndexOfPeriod(periodPosition.first),
|
/* periodIndex= */ newTimeline.getIndexOfPeriod(periodPositionUs.first),
|
||||||
/* periodTimeUs= */ periodPosition.second,
|
/* periodTimeUs= */ periodPositionUs.second,
|
||||||
/* periodUid= */ periodPosition.first);
|
/* periodUid= */ periodPositionUs.first);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -2820,7 +2820,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
* bounds of the timeline.
|
* bounds of the timeline.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Pair<Object, Long> resolveSeekPosition(
|
private static Pair<Object, Long> resolveSeekPositionUs(
|
||||||
Timeline timeline,
|
Timeline timeline,
|
||||||
SeekPosition seekPosition,
|
SeekPosition seekPosition,
|
||||||
boolean trySubsequentPeriods,
|
boolean trySubsequentPeriods,
|
||||||
|
|
@ -2839,10 +2839,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
seekTimeline = timeline;
|
seekTimeline = timeline;
|
||||||
}
|
}
|
||||||
// Map the SeekPosition to a position in the corresponding timeline.
|
// Map the SeekPosition to a position in the corresponding timeline.
|
||||||
Pair<Object, Long> periodPosition;
|
Pair<Object, Long> periodPositionUs;
|
||||||
try {
|
try {
|
||||||
periodPosition =
|
periodPositionUs =
|
||||||
seekTimeline.getPeriodPosition(
|
seekTimeline.getPeriodPositionUs(
|
||||||
window, period, seekPosition.windowIndex, seekPosition.windowPositionUs);
|
window, period, seekPosition.windowIndex, seekPosition.windowPositionUs);
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
// The window index of the seek position was outside the bounds of the timeline.
|
// The window index of the seek position was outside the bounds of the timeline.
|
||||||
|
|
@ -2850,24 +2850,24 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
}
|
}
|
||||||
if (timeline.equals(seekTimeline)) {
|
if (timeline.equals(seekTimeline)) {
|
||||||
// Our internal timeline is the seek timeline, so the mapped position is correct.
|
// Our internal timeline is the seek timeline, so the mapped position is correct.
|
||||||
return periodPosition;
|
return periodPositionUs;
|
||||||
}
|
}
|
||||||
// Attempt to find the mapped period in the internal timeline.
|
// Attempt to find the mapped period in the internal timeline.
|
||||||
int periodIndex = timeline.getIndexOfPeriod(periodPosition.first);
|
int periodIndex = timeline.getIndexOfPeriod(periodPositionUs.first);
|
||||||
if (periodIndex != C.INDEX_UNSET) {
|
if (periodIndex != C.INDEX_UNSET) {
|
||||||
// We successfully located the period in the internal timeline.
|
// We successfully located the period in the internal timeline.
|
||||||
if (seekTimeline.getPeriodByUid(periodPosition.first, period).isPlaceholder
|
if (seekTimeline.getPeriodByUid(periodPositionUs.first, period).isPlaceholder
|
||||||
&& seekTimeline.getWindow(period.windowIndex, window).firstPeriodIndex
|
&& seekTimeline.getWindow(period.windowIndex, window).firstPeriodIndex
|
||||||
== seekTimeline.getIndexOfPeriod(periodPosition.first)) {
|
== seekTimeline.getIndexOfPeriod(periodPositionUs.first)) {
|
||||||
// The seek timeline was using a placeholder, so we need to re-resolve using the updated
|
// The seek timeline was using a placeholder, so we need to re-resolve using the updated
|
||||||
// timeline in case the resolved position changed. Only resolve the first period in a window
|
// timeline in case the resolved position changed. Only resolve the first period in a window
|
||||||
// because subsequent periods must start at position 0 and don't need to be resolved.
|
// because subsequent periods must start at position 0 and don't need to be resolved.
|
||||||
int newWindowIndex = timeline.getPeriodByUid(periodPosition.first, period).windowIndex;
|
int newWindowIndex = timeline.getPeriodByUid(periodPositionUs.first, period).windowIndex;
|
||||||
periodPosition =
|
periodPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window, period, newWindowIndex, seekPosition.windowPositionUs);
|
window, period, newWindowIndex, seekPosition.windowPositionUs);
|
||||||
}
|
}
|
||||||
return periodPosition;
|
return periodPositionUs;
|
||||||
}
|
}
|
||||||
if (trySubsequentPeriods) {
|
if (trySubsequentPeriods) {
|
||||||
// Try and find a subsequent period from the seek timeline in the internal timeline.
|
// Try and find a subsequent period from the seek timeline in the internal timeline.
|
||||||
|
|
@ -2878,12 +2878,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
period,
|
period,
|
||||||
repeatMode,
|
repeatMode,
|
||||||
shuffleModeEnabled,
|
shuffleModeEnabled,
|
||||||
periodPosition.first,
|
periodPositionUs.first,
|
||||||
seekTimeline,
|
seekTimeline,
|
||||||
timeline);
|
timeline);
|
||||||
if (periodUid != null) {
|
if (periodUid != null) {
|
||||||
// We found one. Use the default position of the corresponding window.
|
// We found one. Use the default position of the corresponding window.
|
||||||
return timeline.getPeriodPosition(
|
return timeline.getPeriodPositionUs(
|
||||||
window,
|
window,
|
||||||
period,
|
period,
|
||||||
timeline.getPeriodByUid(periodUid, period).windowIndex,
|
timeline.getPeriodByUid(periodUid, period).windowIndex,
|
||||||
|
|
|
||||||
|
|
@ -661,18 +661,18 @@ import com.google.common.collect.ImmutableList;
|
||||||
// forward by the duration of the buffer, and start buffering from this point.
|
// forward by the duration of the buffer, and start buffering from this point.
|
||||||
contentPositionUs = C.TIME_UNSET;
|
contentPositionUs = C.TIME_UNSET;
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> defaultPosition =
|
Pair<Object, Long> defaultPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window,
|
window,
|
||||||
period,
|
period,
|
||||||
nextWindowIndex,
|
nextWindowIndex,
|
||||||
/* windowPositionUs= */ C.TIME_UNSET,
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
/* defaultPositionProjectionUs= */ max(0, bufferedDurationUs));
|
/* defaultPositionProjectionUs= */ max(0, bufferedDurationUs));
|
||||||
if (defaultPosition == null) {
|
if (defaultPositionUs == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
nextPeriodUid = defaultPosition.first;
|
nextPeriodUid = defaultPositionUs.first;
|
||||||
startPositionUs = defaultPosition.second;
|
startPositionUs = defaultPositionUs.second;
|
||||||
MediaPeriodHolder nextMediaPeriodHolder = mediaPeriodHolder.getNext();
|
MediaPeriodHolder nextMediaPeriodHolder = mediaPeriodHolder.getNext();
|
||||||
if (nextMediaPeriodHolder != null && nextMediaPeriodHolder.uid.equals(nextPeriodUid)) {
|
if (nextMediaPeriodHolder != null && nextMediaPeriodHolder.uid.equals(nextPeriodUid)) {
|
||||||
windowSequenceNumber = nextMediaPeriodHolder.info.id.windowSequenceNumber;
|
windowSequenceNumber = nextMediaPeriodHolder.info.id.windowSequenceNumber;
|
||||||
|
|
@ -716,17 +716,17 @@ import com.google.common.collect.ImmutableList;
|
||||||
// If we're transitioning from an ad group to content starting from its default position,
|
// If we're transitioning from an ad group to content starting from its default position,
|
||||||
// project the start position forward as if this were a transition to a new window.
|
// project the start position forward as if this were a transition to a new window.
|
||||||
@Nullable
|
@Nullable
|
||||||
Pair<Object, Long> defaultPosition =
|
Pair<Object, Long> defaultPositionUs =
|
||||||
timeline.getPeriodPosition(
|
timeline.getPeriodPositionUs(
|
||||||
window,
|
window,
|
||||||
period,
|
period,
|
||||||
period.windowIndex,
|
period.windowIndex,
|
||||||
/* windowPositionUs= */ C.TIME_UNSET,
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
/* defaultPositionProjectionUs= */ max(0, bufferedDurationUs));
|
/* defaultPositionProjectionUs= */ max(0, bufferedDurationUs));
|
||||||
if (defaultPosition == null) {
|
if (defaultPositionUs == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
startPositionUs = defaultPosition.second;
|
startPositionUs = defaultPositionUs.second;
|
||||||
}
|
}
|
||||||
long minStartPositionUs =
|
long minStartPositionUs =
|
||||||
getMinStartPositionAfterAdGroupUs(
|
getMinStartPositionAfterAdGroupUs(
|
||||||
|
|
|
||||||
|
|
@ -179,11 +179,11 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
|
||||||
windowStartPositionUs = windowPreparePositionUs;
|
windowStartPositionUs = windowPreparePositionUs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pair<Object, Long> periodPosition =
|
Pair<Object, Long> periodUidAndPositionUs =
|
||||||
newTimeline.getPeriodPosition(
|
newTimeline.getPeriodPositionUs(
|
||||||
window, period, /* windowIndex= */ 0, windowStartPositionUs);
|
window, period, /* windowIndex= */ 0, windowStartPositionUs);
|
||||||
Object periodUid = periodPosition.first;
|
Object periodUid = periodUidAndPositionUs.first;
|
||||||
long periodPositionUs = periodPosition.second;
|
long periodPositionUs = periodUidAndPositionUs.second;
|
||||||
timeline =
|
timeline =
|
||||||
hasRealTimeline
|
hasRealTimeline
|
||||||
? timeline.cloneWithUpdatedTimeline(newTimeline)
|
? timeline.cloneWithUpdatedTimeline(newTimeline)
|
||||||
|
|
|
||||||
|
|
@ -45,19 +45,31 @@ public final class SinglePeriodTimelineTest {
|
||||||
public void getPeriodPositionDynamicWindowUnknownDuration() {
|
public void getPeriodPositionDynamicWindowUnknownDuration() {
|
||||||
SinglePeriodTimeline timeline =
|
SinglePeriodTimeline timeline =
|
||||||
new SinglePeriodTimeline(
|
new SinglePeriodTimeline(
|
||||||
C.TIME_UNSET,
|
/* durationUs= */ C.TIME_UNSET,
|
||||||
/* isSeekable= */ false,
|
/* isSeekable= */ false,
|
||||||
/* isDynamic= */ true,
|
/* isDynamic= */ true,
|
||||||
/* isLive= */ true,
|
/* isLive= */ true,
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
MediaItem.fromUri(Uri.EMPTY));
|
MediaItem.fromUri(Uri.EMPTY));
|
||||||
// Should return null with any positive position projection.
|
// Should return null with any positive position projection.
|
||||||
Pair<Object, Long> position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 1);
|
Pair<Object, Long> positionUs =
|
||||||
assertThat(position).isNull();
|
timeline.getPeriodPositionUs(
|
||||||
|
window,
|
||||||
|
period,
|
||||||
|
/* windowIndex= */ 0,
|
||||||
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
|
/* defaultPositionProjectionUs= */ 1);
|
||||||
|
assertThat(positionUs).isNull();
|
||||||
// Should return (0, 0) without a position projection.
|
// Should return (0, 0) without a position projection.
|
||||||
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 0);
|
positionUs =
|
||||||
assertThat(position.first).isEqualTo(timeline.getUidOfPeriod(0));
|
timeline.getPeriodPositionUs(
|
||||||
assertThat(position.second).isEqualTo(0);
|
window,
|
||||||
|
period,
|
||||||
|
/* windowIndex= */ 0,
|
||||||
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
|
/* defaultPositionProjectionUs= */ 0);
|
||||||
|
assertThat(positionUs.first).isEqualTo(timeline.getUidOfPeriod(0));
|
||||||
|
assertThat(positionUs.second).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -75,17 +87,34 @@ public final class SinglePeriodTimelineTest {
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
MediaItem.fromUri(Uri.EMPTY));
|
MediaItem.fromUri(Uri.EMPTY));
|
||||||
// Should return null with a positive position projection beyond window duration.
|
// Should return null with a positive position projection beyond window duration.
|
||||||
Pair<Object, Long> position =
|
Pair<Object, Long> positionUs =
|
||||||
timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, windowDurationUs + 1);
|
timeline.getPeriodPositionUs(
|
||||||
assertThat(position).isNull();
|
window,
|
||||||
|
period,
|
||||||
|
/* windowIndex= */ 0,
|
||||||
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
|
/* defaultPositionProjectionUs= */ windowDurationUs + 1);
|
||||||
|
assertThat(positionUs).isNull();
|
||||||
// Should return (0, duration) with a projection equal to window duration.
|
// Should return (0, duration) with a projection equal to window duration.
|
||||||
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, windowDurationUs - 1);
|
positionUs =
|
||||||
assertThat(position.first).isEqualTo(timeline.getUidOfPeriod(0));
|
timeline.getPeriodPositionUs(
|
||||||
assertThat(position.second).isEqualTo(windowDurationUs - 1);
|
window,
|
||||||
|
period,
|
||||||
|
/* windowIndex= */ 0,
|
||||||
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
|
/* defaultPositionProjectionUs= */ windowDurationUs - 1);
|
||||||
|
assertThat(positionUs.first).isEqualTo(timeline.getUidOfPeriod(0));
|
||||||
|
assertThat(positionUs.second).isEqualTo(windowDurationUs - 1);
|
||||||
// Should return (0, 0) without a position projection.
|
// Should return (0, 0) without a position projection.
|
||||||
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 0);
|
positionUs =
|
||||||
assertThat(position.first).isEqualTo(timeline.getUidOfPeriod(0));
|
timeline.getPeriodPositionUs(
|
||||||
assertThat(position.second).isEqualTo(0);
|
window,
|
||||||
|
period,
|
||||||
|
/* windowIndex= */ 0,
|
||||||
|
/* windowPositionUs= */ C.TIME_UNSET,
|
||||||
|
/* defaultPositionProjectionUs= */ 0);
|
||||||
|
assertThat(positionUs.first).isEqualTo(timeline.getUidOfPeriod(0));
|
||||||
|
assertThat(positionUs.second).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue