Bug 1228226 - Fix clicks with new playing AudioContext; r?padenot draft
authorDan Minor <dminor@mozilla.com>
Mon, 26 Sep 2016 14:04:56 -0400
changeset 417726 8d02257e19f43b383cd3718ddc56981b54c42c1e
parent 415108 fd0564234eca242b7fb753a110312679020f8059
child 532151 ee6eddf386e1ef65e87cc525980734778c78b87a
push id30469
push userdminor@mozilla.com
push dateMon, 26 Sep 2016 18:09:50 +0000
reviewerspadenot
bugs1228226
milestone52.0a1
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
dom/media/MediaStreamGraph.cpp
--- 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;