Prevent deletion of unprepared periods.

When a new Timeline arrives in the Player, we check whether we can keep
existing MediaPeriods. This check currently involves a condition that
checks if the MediaPeriod is already prepared. The only reason we do
that is to avoid calling MediaPeriod.seekToUs, which is not allowed
on an unprepared MediaPeriod.

It's better to keep the MediaPeriod to prevent restarting the
preparation process. The prepration check can move further down to the
place right before we would call seekToUs.

PiperOrigin-RevId: 297812584
This commit is contained in:
tonihei 2020-02-28 12:03:25 +00:00 committed by Oliver Woodman
parent 3ef0015817
commit 91a87b3fa0

View file

@ -971,11 +971,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
setState(Player.STATE_BUFFERING);
}
// Find the requested period if it's already prepared.
// Find the requested period if it already exists.
@Nullable MediaPeriodHolder oldPlayingPeriodHolder = queue.getPlayingPeriod();
@Nullable MediaPeriodHolder newPlayingPeriodHolder = oldPlayingPeriodHolder;
while (newPlayingPeriodHolder != null) {
if (periodId.equals(newPlayingPeriodHolder.info.id) && newPlayingPeriodHolder.prepared) {
if (periodId.equals(newPlayingPeriodHolder.info.id)) {
break;
}
newPlayingPeriodHolder = newPlayingPeriodHolder.getNext();
@ -1004,7 +1004,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
// Do the actual seeking.
if (newPlayingPeriodHolder != null) {
queue.removeAfter(newPlayingPeriodHolder);
if (newPlayingPeriodHolder.hasEnabledTracks) {
if (!newPlayingPeriodHolder.prepared) {
newPlayingPeriodHolder.info =
newPlayingPeriodHolder.info.copyWithStartPositionUs(periodPositionUs);
} else if (newPlayingPeriodHolder.hasEnabledTracks) {
periodPositionUs = newPlayingPeriodHolder.mediaPeriod.seekToUs(periodPositionUs);
newPlayingPeriodHolder.mediaPeriod.discardBuffer(
periodPositionUs - backBufferDurationUs, retainBackBufferFromKeyframe);
@ -1896,7 +1899,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
private PlaybackInfo copyWithNewPosition(
MediaPeriodId mediaPeriodId, long positionUs, long contentPositionUs) {
deliverPendingMessageAtStartPositionRequired =
positionUs != playbackInfo.positionUs || !mediaPeriodId.equals(playbackInfo.periodId);
deliverPendingMessageAtStartPositionRequired
|| positionUs != playbackInfo.positionUs
|| !mediaPeriodId.equals(playbackInfo.periodId);
TrackGroupArray trackGroupArray = playbackInfo.trackGroups;
TrackSelectorResult trackSelectorResult = playbackInfo.trackSelectorResult;
if (playlist.isPrepared()) {