Bug 1513733 - part4 : do not call suspendInternal() when constructing AudioContext r=karlt
authoralwu <alwu@mozilla.com>
Fri, 11 Jan 2019 18:54:43 +0000
changeset 453534 8699d4c48838e4ecae4460a24fbcd3dc67b29ed4
parent 453533 22ce92cbdf648501a5324bf525ee9e570dbb174c
child 453535 c083f11eb58d510309b4e85578609dc8c2c7c902
push id35360
push usernbeleuzu@mozilla.com
push dateSat, 12 Jan 2019 09:39:47 +0000
treeherdermozilla-central@cb35977ae7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1513733, 1285290
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513733 - part4 : do not call suspendInternal() when constructing AudioContext r=karlt As setting `mSuspendCalled` is enough to prevent the stream from starting, we have no need to apply unnessary audio context operation to MSG. In addition, it can avoid incorrect AudioContext's state because of out of order resume/suspend operation (https://bugzilla.mozilla.org/show_bug.cgi?id=1285290). Differential Revision: https://phabricator.services.mozilla.com/D15679
dom/media/webaudio/AudioContext.cpp
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -156,33 +156,32 @@ AudioContext::AudioContext(nsPIDOMWindow
       mWasEverAllowedToStart(false),
       mWasEverBlockedToStart(false),
       mWouldBeAllowedToStart(true) {
   bool mute = aWindow->AddAudioContext(this);
 
   // Note: AudioDestinationNode needs an AudioContext that must already be
   // bound to the window.
   const bool allowedToStart = AutoplayPolicy::IsAllowedToPlay(*this);
+  // If an AudioContext is not allowed to start, we would postpone its state
+  // transition from `suspended` to `running` until sites explicitly call
+  // AudioContext.resume() or AudioScheduledSourceNode.start().
+  if (!allowedToStart) {
+    AUTOPLAY_LOG("AudioContext %p is not allowed to start", this);
+    mSuspendCalled = true;
+    ReportBlocked();
+  }
   mDestination = new AudioDestinationNode(this, aIsOffline, allowedToStart,
                                           aNumberOfChannels, aLength);
 
   // The context can't be muted until it has a destination.
   if (mute) {
     Mute();
   }
 
-  // If an AudioContext is not allowed to start, we would postpone its state
-  // transition from `suspended` to `running` until sites explicitly call
-  // AudioContext.resume() or AudioScheduledSourceNode.start().
-  if (!allowedToStart) {
-    AUTOPLAY_LOG("AudioContext %p is not allowed to start", this);
-    SuspendInternal(nullptr);
-    ReportBlocked();
-  }
-
   UpdateAutoplayAssumptionStatus();
 
   FFTBlock::MainThreadInit();
 }
 
 void AudioContext::StartBlockedAudioContextIfAllowed() {
   MOZ_ASSERT(NS_IsMainThread());
   MaybeUpdateAutoplayTelemetry();