Commit 9716b03f by andrewlewis Committed by Oliver Woodman

Fix isLastPeriod to take into account the played ad count

A content period just before a postroll ad group with all ads played
was not being marked as the last media period in the timeline period.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162471919
parent 4658e619
...@@ -323,18 +323,25 @@ import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; ...@@ -323,18 +323,25 @@ import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
if (adGroupCount == 0) { if (adGroupCount == 0) {
return true; return true;
} }
int lastAdGroupIndex = adGroupCount - 1; int lastAdGroupIndex = adGroupCount - 1;
boolean periodHasPostrollAd = period.getAdGroupTimeUs(lastAdGroupIndex) == C.TIME_END_OF_SOURCE; boolean isAd = id.isAd();
if (!id.isAd()) { if (period.getAdGroupTimeUs(lastAdGroupIndex) != C.TIME_END_OF_SOURCE) {
return !periodHasPostrollAd && endPositionUs == C.TIME_END_OF_SOURCE; // There's no postroll ad.
} else if (periodHasPostrollAd && id.adGroupIndex == lastAdGroupIndex) { return !isAd && endPositionUs == C.TIME_END_OF_SOURCE;
int adCountInLastAdGroup = period.getAdCountInAdGroup(lastAdGroupIndex);
return adCountInLastAdGroup != C.LENGTH_UNSET
&& id.adIndexInAdGroup == adCountInLastAdGroup - 1;
} }
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; return false;
} }
boolean isLastAd = isAd && id.adGroupIndex == lastAdGroupIndex
&& id.adIndexInAdGroup == postrollAdCount - 1;
return isLastAd || (!isAd && period.getPlayedAdCount(lastAdGroupIndex) == postrollAdCount);
}
private boolean isLastInTimeline(MediaPeriodId id, boolean isLastMediaPeriodInPeriod) { private boolean isLastInTimeline(MediaPeriodId id, boolean isLastMediaPeriodInPeriod) {
int windowIndex = timeline.getPeriod(id.periodIndex, period).windowIndex; int windowIndex = timeline.getPeriod(id.periodIndex, period).windowIndex;
return !timeline.getWindow(windowIndex, window).isDynamic return !timeline.getWindow(windowIndex, window).isDynamic
......
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