commit 23646486fcef58b80fc17c4da540f58795821aa3
parent b1f784aebbf90355fb6d522828211c7da836fbab
Author: Karl Tomlinson <karlt+@karlt.net>
Date: Wed, 8 Oct 2025 04:50:53 +0000
Bug 1992922 wait for target time before, rather than after, each ThreadedDriver iteration r=padenot
When switching from AudioCallbackDriver, this will allow, in a subsequent
patch, the SystemClockDriver to time its first iteration appropriately.
When switching to AudioCallbackDriver, this allows the audio thread to be
started up to 10ms faster.
Differential Revision: https://phabricator.services.mozilla.com/D267737
Diffstat:
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp
@@ -187,6 +187,8 @@ SystemClockDriver::~SystemClockDriver() = default;
void ThreadedDriver::RunThread() {
mThreadRunning = true;
while (true) {
+ WaitForNextIteration();
+
MediaTime interval = GetIntervalForIteration();
auto iterationStart = mIterationEnd;
mIterationEnd += interval;
@@ -212,7 +214,6 @@ void ThreadedDriver::RunThread() {
result.Stopped();
break;
}
- WaitForNextIteration();
if (GraphDriver* nextDriver = result.NextDriver()) {
LOG(LogLevel::Debug, ("%p: Switching to AudioCallbackDriver", Graph()));
result.Switched();
diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h
@@ -367,7 +367,12 @@ class ThreadedDriver : public GraphDriver {
class IterationWaitHelper {
Monitor mMonitor MOZ_UNANNOTATED;
// The below members are guarded by mMonitor.
- bool mNeedAnotherIteration = false;
+
+ // Whether another iteration is required either to process control
+ // messages or to render.
+ // Drivers do not pass on this state when switching to another driver,
+ // so always perform at least one iteration.
+ bool mNeedAnotherIteration = true;
TimeStamp mWakeTime;
public: