Commit 42eaee3d by andrewlewis Committed by Oliver Woodman

Update playbackInfo even if there's no period holder

This is required to correctly update the playbackInfo.periodId when
seeking close to the end of a period with ads, as the seek operation
leads to an immediate source info refresh when midroll ads are marked as
played.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164257099
parent c72278d2
...@@ -1011,20 +1011,20 @@ import java.io.IOException; ...@@ -1011,20 +1011,20 @@ import java.io.IOException;
return; return;
} }
int playingPeriodIndex = playbackInfo.periodId.periodIndex;
MediaPeriodHolder periodHolder = playingPeriodHolder != null ? playingPeriodHolder MediaPeriodHolder periodHolder = playingPeriodHolder != null ? playingPeriodHolder
: loadingPeriodHolder; : loadingPeriodHolder;
if (periodHolder == null) { if (periodHolder == null && playingPeriodIndex >= oldTimeline.getPeriodCount()) {
// We don't have any period holders, so we're done.
notifySourceInfoRefresh(manifest, processedInitialSeekCount); notifySourceInfoRefresh(manifest, processedInitialSeekCount);
return; return;
} }
Object playingPeriodUid = periodHolder == null
int periodIndex = timeline.getIndexOfPeriod(periodHolder.uid); ? oldTimeline.getPeriod(playingPeriodIndex, period, true).uid : periodHolder.uid;
int periodIndex = timeline.getIndexOfPeriod(playingPeriodUid);
if (periodIndex == C.INDEX_UNSET) { if (periodIndex == C.INDEX_UNSET) {
// We didn't find the current period in the new timeline. Attempt to resolve a subsequent // We didn't find the current period in the new timeline. Attempt to resolve a subsequent
// period whose window we can restart from. // period whose window we can restart from.
int newPeriodIndex = resolveSubsequentPeriod(periodHolder.info.id.periodIndex, oldTimeline, int newPeriodIndex = resolveSubsequentPeriod(playingPeriodIndex, oldTimeline, timeline);
timeline);
if (newPeriodIndex == C.INDEX_UNSET) { if (newPeriodIndex == C.INDEX_UNSET) {
// We failed to resolve a suitable restart position. // We failed to resolve a suitable restart position.
handleSourceInfoRefreshEndedPlayback(manifest, processedInitialSeekCount); handleSourceInfoRefreshEndedPlayback(manifest, processedInitialSeekCount);
...@@ -1036,17 +1036,19 @@ import java.io.IOException; ...@@ -1036,17 +1036,19 @@ import java.io.IOException;
newPeriodIndex = defaultPosition.first; newPeriodIndex = defaultPosition.first;
long newPositionUs = defaultPosition.second; long newPositionUs = defaultPosition.second;
timeline.getPeriod(newPeriodIndex, period, true); timeline.getPeriod(newPeriodIndex, period, true);
// Clear the index of each holder that doesn't contain the default position. If a holder if (periodHolder != null) {
// contains the default position then update its index so it can be re-used when seeking. // Clear the index of each holder that doesn't contain the default position. If a holder
Object newPeriodUid = period.uid; // contains the default position then update its index so it can be re-used when seeking.
periodHolder.info = periodHolder.info.copyWithPeriodIndex(C.INDEX_UNSET); Object newPeriodUid = period.uid;
while (periodHolder.next != null) { periodHolder.info = periodHolder.info.copyWithPeriodIndex(C.INDEX_UNSET);
periodHolder = periodHolder.next; while (periodHolder.next != null) {
if (periodHolder.uid.equals(newPeriodUid)) { periodHolder = periodHolder.next;
periodHolder.info = mediaPeriodInfoSequence.getUpdatedMediaPeriodInfo(periodHolder.info, if (periodHolder.uid.equals(newPeriodUid)) {
newPeriodIndex); periodHolder.info = mediaPeriodInfoSequence.getUpdatedMediaPeriodInfo(periodHolder.info,
} else { newPeriodIndex);
periodHolder.info = periodHolder.info.copyWithPeriodIndex(C.INDEX_UNSET); } else {
periodHolder.info = periodHolder.info.copyWithPeriodIndex(C.INDEX_UNSET);
}
} }
} }
// Actually do the seek. // Actually do the seek.
...@@ -1057,8 +1059,13 @@ import java.io.IOException; ...@@ -1057,8 +1059,13 @@ import java.io.IOException;
return; return;
} }
// If playing an ad, check that it hasn't been marked as played. If it has, skip forward. // The current period is in the new timeline. Update the playback info.
if (periodIndex != playingPeriodIndex) {
playbackInfo = playbackInfo.copyWithPeriodIndex(periodIndex);
}
if (playbackInfo.periodId.isAd()) { if (playbackInfo.periodId.isAd()) {
// Check that the playing ad hasn't been marked as played. If it has, skip forward.
MediaPeriodId periodId = mediaPeriodInfoSequence.resolvePeriodPositionForAds(periodIndex, MediaPeriodId periodId = mediaPeriodInfoSequence.resolvePeriodPositionForAds(periodIndex,
playbackInfo.contentPositionUs); playbackInfo.contentPositionUs);
if (!periodId.isAd() || periodId.adIndexInAdGroup != playbackInfo.periodId.adIndexInAdGroup) { if (!periodId.isAd() || periodId.adIndexInAdGroup != playbackInfo.periodId.adIndexInAdGroup) {
...@@ -1070,14 +1077,15 @@ import java.io.IOException; ...@@ -1070,14 +1077,15 @@ import java.io.IOException;
} }
} }
// The current period is in the new timeline. Update the holder and playbackInfo. if (periodHolder == null) {
periodHolder = updatePeriodInfo(periodHolder, periodIndex); // We don't have any period holders, so we're done.
if (periodIndex != playbackInfo.periodId.periodIndex) { notifySourceInfoRefresh(manifest, processedInitialSeekCount);
playbackInfo = playbackInfo.copyWithPeriodIndex(periodIndex); return;
} }
// If there are subsequent holders, update the index for each of them. If we find a holder // Update the holder indices. If we find a subsequent holder that's inconsistent with the new
// that's inconsistent with the new timeline then take appropriate action. // timeline then take appropriate action.
periodHolder = updatePeriodInfo(periodHolder, periodIndex);
while (periodHolder.next != null) { while (periodHolder.next != null) {
MediaPeriodHolder previousPeriodHolder = periodHolder; MediaPeriodHolder previousPeriodHolder = periodHolder;
periodHolder = periodHolder.next; periodHolder = periodHolder.next;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment