Get updated buffered position when calling shouldStartPlayback

The buffered position was last updated before the beginning of
the renderer loop in doSomeWork. As the loading happens on a
background thread, it may have progressed further already
depending on how long it took to run the renderer loop.

It's slightly more correct to pass in an updated value to
shouldStartPlayback so that playback can start quicker if the
buffering is particularly fast.

PiperOrigin-RevId: 679203465
This commit is contained in:
tonihei 2024-09-26 10:30:42 -07:00 committed by Copybara-Service
parent 2dde824bde
commit 138a8d65ca

View File

@ -1076,7 +1076,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
&& playbackInfo.playbackParameters.speed == 1f) {
float adjustedSpeed =
livePlaybackSpeedControl.getAdjustedPlaybackSpeed(
getCurrentLiveOffsetUs(), getTotalBufferedDurationUs());
getCurrentLiveOffsetUs(), playbackInfo.totalBufferedDurationUs);
if (mediaClock.getPlaybackParameters().speed != adjustedSpeed) {
setMediaClockPlaybackParameters(playbackInfo.playbackParameters.withSpeed(adjustedSpeed));
handlePlaybackParameters(
@ -2015,19 +2015,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
// it is possible for playback to be stuck buffering waiting for this. Therefore, we start
// playback regardless of buffered duration if we are waiting for an ad media period to prepare.
boolean isAdPendingPreparation = loadingHolder.info.id.isAd() && !loadingHolder.prepared;
return isBufferedToEnd
|| isAdPendingPreparation
|| loadControl.shouldStartPlayback(
new LoadControl.Parameters(
playerId,
playbackInfo.timeline,
playingPeriodHolder.info.id,
playingPeriodHolder.toPeriodTime(rendererPositionUs),
getTotalBufferedDurationUs(),
mediaClock.getPlaybackParameters().speed,
playbackInfo.playWhenReady,
isRebuffering,
targetLiveOffsetUs));
if (isBufferedToEnd || isAdPendingPreparation) {
return true;
}
// Get updated buffered duration as it may have changed since the start of the renderer loop.
long bufferedDurationUs = getTotalBufferedDurationUs(loadingHolder.getBufferedPositionUs());
return loadControl.shouldStartPlayback(
new LoadControl.Parameters(
playerId,
playbackInfo.timeline,
playingPeriodHolder.info.id,
playingPeriodHolder.toPeriodTime(rendererPositionUs),
bufferedDurationUs,
mediaClock.getPlaybackParameters().speed,
playbackInfo.playWhenReady,
isRebuffering,
targetLiveOffsetUs));
}
private boolean isTimelineReady() {