Swap reading and playing media period updates.
Both periods are rarely updated in the same iteration. If they are, advancing the reading period first seems more logical and also more efficient as it may avoid one extra doSomeWork iteration. PiperOrigin-RevId: 260463735
This commit is contained in:
parent
846e0666df
commit
7703676c87
@ -1491,8 +1491,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
maybeUpdateLoadingPeriod();
|
maybeUpdateLoadingPeriod();
|
||||||
maybeUpdatePlayingPeriod();
|
|
||||||
maybeUpdateReadingPeriod();
|
maybeUpdateReadingPeriod();
|
||||||
|
maybeUpdatePlayingPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeUpdateLoadingPeriod() throws IOException {
|
private void maybeUpdateLoadingPeriod() throws IOException {
|
||||||
@ -1518,32 +1518,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeUpdatePlayingPeriod() throws ExoPlaybackException {
|
|
||||||
boolean advancedPlayingPeriod = false;
|
|
||||||
while (shouldAdvancePlayingPeriod()) {
|
|
||||||
if (advancedPlayingPeriod) {
|
|
||||||
// If we advance more than one period at a time, notify listeners after each update.
|
|
||||||
maybeNotifyPlaybackInfoChanged();
|
|
||||||
}
|
|
||||||
MediaPeriodHolder oldPlayingPeriodHolder = queue.getPlayingPeriod();
|
|
||||||
MediaPeriodHolder newPlayingPeriodHolder = queue.advancePlayingPeriod();
|
|
||||||
updatePlayingPeriodRenderers(oldPlayingPeriodHolder);
|
|
||||||
playbackInfo =
|
|
||||||
playbackInfo.copyWithNewPosition(
|
|
||||||
newPlayingPeriodHolder.info.id,
|
|
||||||
newPlayingPeriodHolder.info.startPositionUs,
|
|
||||||
newPlayingPeriodHolder.info.contentPositionUs,
|
|
||||||
getTotalBufferedDurationUs());
|
|
||||||
int discontinuityReason =
|
|
||||||
oldPlayingPeriodHolder.info.isLastInTimelinePeriod
|
|
||||||
? Player.DISCONTINUITY_REASON_PERIOD_TRANSITION
|
|
||||||
: Player.DISCONTINUITY_REASON_AD_INSERTION;
|
|
||||||
playbackInfoUpdate.setPositionDiscontinuity(discontinuityReason);
|
|
||||||
updatePlaybackPositions();
|
|
||||||
advancedPlayingPeriod = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void maybeUpdateReadingPeriod() throws ExoPlaybackException, IOException {
|
private void maybeUpdateReadingPeriod() throws ExoPlaybackException, IOException {
|
||||||
MediaPeriodHolder readingPeriodHolder = queue.getReadingPeriod();
|
MediaPeriodHolder readingPeriodHolder = queue.getReadingPeriod();
|
||||||
if (readingPeriodHolder == null) {
|
if (readingPeriodHolder == null) {
|
||||||
@ -1621,6 +1595,32 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maybeUpdatePlayingPeriod() throws ExoPlaybackException {
|
||||||
|
boolean advancedPlayingPeriod = false;
|
||||||
|
while (shouldAdvancePlayingPeriod()) {
|
||||||
|
if (advancedPlayingPeriod) {
|
||||||
|
// If we advance more than one period at a time, notify listeners after each update.
|
||||||
|
maybeNotifyPlaybackInfoChanged();
|
||||||
|
}
|
||||||
|
MediaPeriodHolder oldPlayingPeriodHolder = queue.getPlayingPeriod();
|
||||||
|
MediaPeriodHolder newPlayingPeriodHolder = queue.advancePlayingPeriod();
|
||||||
|
updatePlayingPeriodRenderers(oldPlayingPeriodHolder);
|
||||||
|
playbackInfo =
|
||||||
|
playbackInfo.copyWithNewPosition(
|
||||||
|
newPlayingPeriodHolder.info.id,
|
||||||
|
newPlayingPeriodHolder.info.startPositionUs,
|
||||||
|
newPlayingPeriodHolder.info.contentPositionUs,
|
||||||
|
getTotalBufferedDurationUs());
|
||||||
|
int discontinuityReason =
|
||||||
|
oldPlayingPeriodHolder.info.isLastInTimelinePeriod
|
||||||
|
? Player.DISCONTINUITY_REASON_PERIOD_TRANSITION
|
||||||
|
: Player.DISCONTINUITY_REASON_AD_INSERTION;
|
||||||
|
playbackInfoUpdate.setPositionDiscontinuity(discontinuityReason);
|
||||||
|
updatePlaybackPositions();
|
||||||
|
advancedPlayingPeriod = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldAdvancePlayingPeriod() {
|
private boolean shouldAdvancePlayingPeriod() {
|
||||||
if (!playWhenReady) {
|
if (!playWhenReady) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user