Bug 1228226 - Fix clicks with new playing AudioContext; r?padenot
When switching from the SystemClockDriver to another driver, for instance,
during a page reload or reopening a closed tab, the first iteration will
execute on the SystemClockDriver which can cause clicking when the switch
actually occurs if part of the ramp up is lost. This changes the iteration
time period so that no time advances when a switch from the SystemClockDriver
is in progress.
MozReview-Commit-ID: 8uEBsJc0vPR
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1250,18 +1250,16 @@ void
MediaStreamGraphImpl::UpdateGraph(GraphTime aEndBlockingDecisions)
{
MOZ_ASSERT(aEndBlockingDecisions >= mProcessedTime);
// The next state computed time can be the same as the previous: it
// means the driver would be have been blocking indefinitly, but the graph has
// been woken up right after having been to sleep.
MOZ_ASSERT(aEndBlockingDecisions >= mStateComputedTime);
- UpdateStreamOrder();
-
bool ensureNextIteration = false;
// Grab pending stream input and compute blocking time
for (MediaStream* stream : mStreams) {
if (SourceMediaStream* is = stream->AsSourceStream()) {
ExtractPendingInput(is, aEndBlockingDecisions, &ensureNextIteration);
}
@@ -1400,17 +1398,32 @@ MediaStreamGraphImpl::UpdateMainThreadSt
}
bool
MediaStreamGraphImpl::OneIteration(GraphTime aStateEnd)
{
// Process graph message from the main thread for this iteration.
RunMessagesInQueue();
+ UpdateStreamOrder();
+
+ bool switchingFromSystemClockDriver = false;
+ {
+ MonitorAutoLock mon(mMonitor);
+ switchingFromSystemClockDriver = CurrentDriver()->AsSystemClockDriver() && CurrentDriver()->Switching();
+ }
+
GraphTime stateEnd = std::min(aStateEnd, mEndTime);
+
+ // See Bug 1228226 - If we're switching from the SystemClockDriver, we
+ // don't want time to advance until after the switch.
+ if (switchingFromSystemClockDriver) {
+ stateEnd = mProcessedTime;
+ }
+
UpdateGraph(stateEnd);
mStateComputedTime = stateEnd;
Process();
GraphTime oldProcessedTime = mProcessedTime;
mProcessedTime = stateEnd;