Skip to content

Commit

Permalink
Clear pending doSomeWork messages when sleeping for offload
Browse files Browse the repository at this point in the history
The offload sleeping stops as soon as a new DO_SOME_WORK message
is handled (because this indicates an expected change in rendering
and we want to stop sleeping until we know it's safe to do so).

Every exit path from doSomeWork needs to clear other pending
DO_SOME_WORK messages as these requests have already been handled by
the current method invocation. This currently doesn't happen from the
offload sleeping return path and a previously queued DO_SOME_WORK
message can immediately wake up the rendering loop again.

Fix this by moving the message removal to the beginning of the
doSomeWork method (as it prevents forgetting it in one of the
exit paths later).

PiperOrigin-RevId: 456259715
  • Loading branch information
tonihei authored and icbaker committed Jun 27, 2022
1 parent d86bc10 commit 251389d
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -952,12 +952,14 @@ private void notifyTrackSelectionRebuffer() {

private void doSomeWork() throws ExoPlaybackException, IOException {
long operationStartTimeMs = clock.uptimeMillis();
// Remove other pending DO_SOME_WORK requests that are handled by this invocation.
handler.removeMessages(MSG_DO_SOME_WORK);

updatePeriods();

if (playbackInfo.playbackState == Player.STATE_IDLE
|| playbackInfo.playbackState == Player.STATE_ENDED) {
// Remove all messages. Prepare (in case of IDLE) or seek (in case of ENDED) will resume.
handler.removeMessages(MSG_DO_SOME_WORK);
// Nothing to do. Prepare (in case of IDLE) or seek (in case of ENDED) will resume.
return;
}

Expand Down Expand Up @@ -1080,8 +1082,6 @@ && isLoadingPossible()) {
sleepingForOffload = !maybeScheduleWakeup(operationStartTimeMs, ACTIVE_INTERVAL_MS);
} else if (enabledRendererCount != 0 && playbackInfo.playbackState != Player.STATE_ENDED) {
scheduleNextWork(operationStartTimeMs, IDLE_INTERVAL_MS);
} else {
handler.removeMessages(MSG_DO_SOME_WORK);
}
if (playbackInfo.sleepingForOffload != sleepingForOffload) {
playbackInfo = playbackInfo.copyWithSleepingForOffload(sleepingForOffload);
Expand Down Expand Up @@ -1117,7 +1117,6 @@ private boolean shouldUseLivePlaybackSpeedControl(
}

private void scheduleNextWork(long thisOperationStartTimeMs, long intervalMs) {
handler.removeMessages(MSG_DO_SOME_WORK);
handler.sendEmptyMessageAtTime(MSG_DO_SOME_WORK, thisOperationStartTimeMs + intervalMs);
}

Expand Down

0 comments on commit 251389d

Please sign in to comment.