commit ed5ff27d216e350a643938b194d4107fe76bb256
parent 6c6bf22d0f4dbc52e07bfc254b8dfc19a5c72f9b
Author: Karl Tomlinson <karlt+@karlt.net>
Date: Mon, 3 Nov 2025 21:24:22 +0000
Bug 1996520 Increase SystemClockDriver underrun bankruptcy threshold r=pehrsons
so that rendered time can remain close to clock time even on systems where
thread wake-up is 30ms late.
Differential Revision: https://phabricator.services.mozilla.com/D270451
Diffstat:
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp
@@ -245,10 +245,10 @@ TimeDuration SystemClockDriver::NextIterationWaitDuration() {
mTargetIterationTimeStamp += IterationDuration();
}
TimeDuration timeout = mTargetIterationTimeStamp - now;
- if (timeout < TimeDuration::FromMilliseconds(-MEDIA_GRAPH_TARGET_PERIOD_MS)) {
- // Rendering has fallen so far behind that the entire next rendering
- // period has already passed. Don't try to catch up again, but instead
- // try to render at consistent time intervals from now.
+ if (timeout <
+ TimeDuration::FromMilliseconds(-SYSTEM_CLOCK_BANKRUPTCY_THRESHOLD_MS)) {
+ // Don't try to catch up because rendering has fallen so far behind.
+ // Instead try to render at consistent time intervals from now.
LOG(LogLevel::Warning, ("%p: Global underrun detected", Graph()));
mTargetIterationTimeStamp = now;
}
diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h
@@ -36,7 +36,19 @@ namespace mozilla {
* We try to run the control loop at this rate.
*/
static const int MEDIA_GRAPH_TARGET_PERIOD_MS = 10;
-
+/**
+ * The SystemClockDriver does not necessarily wake up as precisely as an
+ * AudioCallbackDriver. SleepConditionVariableSRW() has been observed to wake
+ * almost 30ms late on Windows 10 2009 systems, which implies a lower timer
+ * resolution than the 15.6ms default system-wide timer resolution in Windows.
+ * https://download.microsoft.com/download/3/0/2/3027d574-c433-412a-a8b6-5e0a75d5b237/timer-resolution.docx
+ *
+ * Allow a SystemClockDriver to try to catch up when rendering is up to this
+ * many milliseconds late, so that rendered time is close to clock time. When
+ * later than this threshold, SystemClockDriver will declare bankruptcy and
+ * re-sync target render time with a new clock time.
+ */
+static const int SYSTEM_CLOCK_BANKRUPTCY_THRESHOLD_MS = 30;
/**
* After starting a fallback driver, wait this long before attempting to re-init
* the audio stream the first time.