commit a9b9b8afa4c6fb3e01abe714033d6be1e2d1b169
parent 405c2bb5382aa6536eb44886f69bc352c1a90f5a
Author: Karl Tomlinson <karlt+@karlt.net>
Date: Wed, 8 Oct 2025 02:22:46 +0000
Bug 1992922 Return TimeDuration from IterationDuration() r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D267735
Diffstat:
5 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp
@@ -267,20 +267,19 @@ void ThreadedDriver::WaitForNextIteration() {
mWaitHelper.WaitForNextIterationAtLeast(WaitInterval());
}
+TimeDuration ThreadedDriver::IterationDuration() {
+ return TimeDuration::FromMilliseconds(MEDIA_GRAPH_TARGET_PERIOD_MS);
+}
+
TimeDuration SystemClockDriver::WaitInterval() {
MOZ_ASSERT(mThread);
MOZ_ASSERT(OnThread());
TimeStamp now = TimeStamp::Now();
- int64_t timeoutMS =
- IterationDuration() - int64_t((now - mCurrentTimeStamp).ToMilliseconds());
- // Make sure timeoutMS doesn't overflow 32 bits by waking up at
- // least once a minute, if we need to wake up at all
- timeoutMS = std::max<int64_t>(0, std::min<int64_t>(timeoutMS, 60 * 1000));
+ TimeDuration timeout = IterationDuration() - (now - mCurrentTimeStamp);
LOG(LogLevel::Verbose,
("%p: Waiting for next iteration; at %f, timeout=%f", Graph(),
- (now - mInitialTimeStamp).ToSeconds(), timeoutMS / 1000.0));
-
- return TimeDuration::FromMilliseconds(timeoutMS);
+ (now - mInitialTimeStamp).ToSeconds(), timeout.ToSeconds()));
+ return timeout;
}
OfflineClockDriver::OfflineClockDriver(GraphInterface* aGraphInterface,
@@ -1243,11 +1242,11 @@ void AudioCallbackDriver::DeviceChangedCallback() {
#endif
}
-uint32_t AudioCallbackDriver::IterationDuration() {
+TimeDuration AudioCallbackDriver::IterationDuration() {
MOZ_ASSERT(InIteration());
// The real fix would be to have an API in cubeb to give us the number. Short
// of that, we approximate it here. bug 1019507
- return mIterationDurationMS;
+ return TimeDuration::FromMilliseconds(mIterationDurationMS);
}
void AudioCallbackDriver::EnsureNextIteration() {
diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h
@@ -282,7 +282,7 @@ class GraphDriver {
* it can be indirectly set by the latency of the audio backend, and the
* number of buffers of this audio backend: say we have four buffers, and 40ms
* latency, we will get a callback approximately every 10ms. */
- virtual uint32_t IterationDuration() = 0;
+ virtual TimeDuration IterationDuration() = 0;
/*
* Signaled by the graph when it needs another iteration. Goes unhandled for
* GraphDrivers that are not able to sleep indefinitely (i.e., all drivers but
@@ -436,7 +436,7 @@ class ThreadedDriver : public GraphDriver {
*/
virtual void RunThread();
friend class MediaTrackGraphInitThreadRunnable;
- uint32_t IterationDuration() override { return MEDIA_GRAPH_TARGET_PERIOD_MS; }
+ TimeDuration IterationDuration() override;
nsIThread* Thread() const { return mThread; }
@@ -589,7 +589,7 @@ class AudioCallbackDriver final : public GraphDriver,
void StateCallback(cubeb_state aState);
/* This is an approximation of the number of millisecond there are between two
* iterations of the graph. */
- uint32_t IterationDuration() override;
+ TimeDuration IterationDuration() override;
/* If the audio stream has started, this does nothing. There will be another
* iteration. If there is an active fallback driver, we forward the call so it
* can wake up. */
diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp
@@ -1200,8 +1200,7 @@ bool MediaTrackGraphImpl::ShouldUpdateMainThread() {
TimeStamp now = TimeStamp::Now();
// For offline graphs, update now if it has been long enough since the last
// update, or if it has reached the end.
- if ((now - mLastMainThreadUpdate).ToMilliseconds() >
- CurrentDriver()->IterationDuration() ||
+ if (now - mLastMainThreadUpdate > CurrentDriver()->IterationDuration() ||
mStateComputedTime >= mEndTime) {
mLastMainThreadUpdate = now;
return true;
diff --git a/dom/media/gtest/TestAudioDecoderInputTrack.cpp b/dom/media/gtest/TestAudioDecoderInputTrack.cpp
@@ -59,7 +59,7 @@ class MockTestGraph : public MediaTrackGraphImpl {
MOCK_METHOD0(Start, void());
MOCK_METHOD0(Shutdown, void());
- MOCK_METHOD0(IterationDuration, uint32_t());
+ MOCK_METHOD0(IterationDuration, TimeDuration());
MOCK_METHOD0(EnsureNextIteration, void());
MOCK_CONST_METHOD0(OnThread, bool());
MOCK_CONST_METHOD0(ThreadRunning, bool());
diff --git a/dom/media/gtest/TestDeviceInputTrack.cpp b/dom/media/gtest/TestDeviceInputTrack.cpp
@@ -55,7 +55,7 @@ class MockGraphImpl : public MediaTrackGraphImpl {
MOCK_METHOD0(Start, void());
MOCK_METHOD0(Shutdown, void());
- MOCK_METHOD0(IterationDuration, uint32_t());
+ MOCK_METHOD0(IterationDuration, TimeDuration());
MOCK_METHOD0(EnsureNextIteration, void());
MOCK_CONST_METHOD0(OnThread, bool());
MOCK_CONST_METHOD0(ThreadRunning, bool());