Make SSAI player logic more targeted.

There is a newly added condition to help advancing between SSAI ads
and content in case the ad group position or ad duration changed. The
condition currently doesn't check directly whether it's a SSAI
transition but relies on indrect signals. Making this more direct
helps to understand the purpose and avoid unintentional bugs where
this condition would apply in other cases too.

In addition, we need to exclude TextRenderer from the check because
its read position doesn't correspond to the actual decode position
since the decoding happens in the renderer itself (b/181312195).

PiperOrigin-RevId: 374835985
This commit is contained in:
tonihei 2021-05-20 11:33:38 +01:00 committed by Oliver Woodman
parent 5ff4211c5e
commit 8eb990e47a

View File

@ -2134,7 +2134,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
if (renderer.getStream() != sampleStream
|| (sampleStream != null
&& !renderer.hasReadStreamToEnd()
&& !hasFinishedReadingClippedContent(renderer, readingPeriodHolder))) {
&& !hasReachedServerSideInsertedAdsTransition(renderer, readingPeriodHolder))) {
// The current reading period is still being read by at least one renderer.
return false;
}
@ -2142,15 +2142,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
return true;
}
private boolean hasFinishedReadingClippedContent(Renderer renderer, MediaPeriodHolder reading) {
private boolean hasReachedServerSideInsertedAdsTransition(
Renderer renderer, MediaPeriodHolder reading) {
MediaPeriodHolder nextPeriod = reading.getNext();
// We can advance the reading period early once the clipped content has been read beyond its
// clipped end time because we know there won't be any further samples. This shortcut is helpful
// in case the clipped end time was reduced and renderers already read beyond the new end time.
// But wait until the next period is actually prepared to allow a seamless transition.
return reading.info.id.nextAdGroupIndex != C.INDEX_UNSET
// We can advance the reading period early once we read beyond the transition point in a
// server-side inserted ads stream because we know the samples are read from the same underlying
// stream. This shortcut is helpful in case the transition point moved and renderers already
// read beyond the new transition point. But wait until the next period is actually prepared to
// allow a seamless transition.
return reading.info.isFollowedByTransitionToSameStream
&& nextPeriod.prepared
&& renderer.getReadingPositionUs() >= nextPeriod.getStartPositionRendererTime();
&& (renderer instanceof TextRenderer // [internal: b/181312195]
|| renderer.getReadingPositionUs() >= nextPeriod.getStartPositionRendererTime());
}
private void setAllRendererStreamsFinal(long streamEndPositionUs) {