Handle potential timeline updates that switch from content to ad.

We currently don't test if an ad needs to be played in case we are already
playing content.

This is to prevent recreating the current content period when
an ad is marked as skipped. We prefer playing until the designated ad group
position and appending another piece of content. This is less likely to cause
visible discontinuities in case the ad group position is at a key frame
boundary.

However, this means we currently miss updates that require us to play an ad
after a timeline update.

PiperOrigin-RevId: 267553459
This commit is contained in:
tonihei 2019-09-06 10:00:53 +01:00 committed by Oliver Woodman
parent b77688533b
commit de915bd6a1

View File

@ -1326,9 +1326,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
timeline, timeline.getPeriodByUid(newPeriodUid, period).windowIndex, C.TIME_UNSET);
newContentPositionUs = defaultPosition.second;
newPeriodId = queue.resolveMediaPeriodIdForAds(defaultPosition.first, newContentPositionUs);
} else if (newPeriodId.isAd()) {
// Recheck if the current ad still needs to be played.
newPeriodId = queue.resolveMediaPeriodIdForAds(newPeriodId.periodUid, newContentPositionUs);
} else {
// Recheck if the current ad still needs to be played or if we need to start playing an ad.
newPeriodId =
queue.resolveMediaPeriodIdForAds(playbackInfo.periodId.periodUid, newContentPositionUs);
if (!playbackInfo.periodId.isAd() && !newPeriodId.isAd()) {
// Drop update if we keep playing the same content (MediaPeriod.periodUid are identical) and
// only MediaPeriodId.nextAdGroupIndex may have changed. This postpones a potential
// discontinuity until we reach the former next ad group position.
newPeriodId = playbackInfo.periodId;
}
}
if (playbackInfo.periodId.equals(newPeriodId) && oldContentPositionUs == newContentPositionUs) {