Title: [265052] trunk/Source/WebCore
Revision
265052
Author
[email protected]
Date
2020-07-29 13:24:46 -0700 (Wed, 29 Jul 2020)

Log Message

Calling AudioNode constructors should have identical behavior to using create*() function on BaseAudioContext
https://bugs.webkit.org/show_bug.cgi?id=214931

Reviewed by Eric Carlson.

Calling AudioNode constructors should have identical behavior to using create*() function on BaseAudioContext.
Otherwise, this leads to assertion hits on the bots like we saw for Bug 214851.

We need to make sure that the AudioContext gets initialized when an AudioNode constructor gets called. We also
need to make sure refNode() gets called if necessary.

* Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::createPanner):
(WebCore::BaseAudioContext::createOscillator):
(WebCore::BaseAudioContext::createPeriodicWave):
* Modules/webaudio/BaseAudioContext.h:
* Modules/webaudio/OscillatorNode.cpp:
(WebCore::OscillatorNode::create):
* Modules/webaudio/PannerNode.cpp:
(WebCore::PannerNode::create):
* Modules/webaudio/PeriodicWave.cpp:
(WebCore::PeriodicWave::create):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265051 => 265052)


--- trunk/Source/WebCore/ChangeLog	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/ChangeLog	2020-07-29 20:24:46 UTC (rev 265052)
@@ -1,3 +1,28 @@
+2020-07-29  Chris Dumez  <[email protected]>
+
+        Calling AudioNode constructors should have identical behavior to using create*() function on BaseAudioContext
+        https://bugs.webkit.org/show_bug.cgi?id=214931
+
+        Reviewed by Eric Carlson.
+
+        Calling AudioNode constructors should have identical behavior to using create*() function on BaseAudioContext.
+        Otherwise, this leads to assertion hits on the bots like we saw for Bug 214851.
+
+        We need to make sure that the AudioContext gets initialized when an AudioNode constructor gets called. We also
+        need to make sure refNode() gets called if necessary.
+
+        * Modules/webaudio/BaseAudioContext.cpp:
+        (WebCore::BaseAudioContext::createPanner):
+        (WebCore::BaseAudioContext::createOscillator):
+        (WebCore::BaseAudioContext::createPeriodicWave):
+        * Modules/webaudio/BaseAudioContext.h:
+        * Modules/webaudio/OscillatorNode.cpp:
+        (WebCore::OscillatorNode::create):
+        * Modules/webaudio/PannerNode.cpp:
+        (WebCore::PannerNode::create):
+        * Modules/webaudio/PeriodicWave.cpp:
+        (WebCore::PeriodicWave::create):
+
 2020-07-29  Simon Fraser  <[email protected]>
 
         REGRESSION: ASSERTION FAILED: !needsLayout() on tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html flakily

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (265051 => 265052)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-07-29 20:24:46 UTC (rev 265052)
@@ -518,10 +518,6 @@
     ALWAYS_LOG(LOGIDENTIFIER);
     
     ASSERT(isMainThread());
-    if (m_isStopScheduled)
-        return Exception { InvalidStateError };
-
-    lazyInitialize();
     return PannerNode::create(*this);
 }
 
@@ -620,20 +616,7 @@
     ALWAYS_LOG(LOGIDENTIFIER);
     
     ASSERT(isMainThread());
-    if (m_isStopScheduled)
-        return Exception { InvalidStateError };
-
-    lazyInitialize();
-
-    auto node = OscillatorNode::create(*this);
-    if (node.hasException())
-        return node.releaseException();
-
-    // Because this is an AudioScheduledSourceNode, the context keeps a reference until it has finished playing.
-    // When this happens, AudioScheduledSourceNode::finish() calls BaseAudioContext::notifyNodeFinishedProcessing().
-    auto nodeValue = node.releaseReturnValue();
-    refNode(nodeValue);
-    return nodeValue;
+    return OscillatorNode::create(*this);
 }
 
 ExceptionOr<Ref<PeriodicWave>> BaseAudioContext::createPeriodicWave(Vector<float>&& real, Vector<float>&& imaginary, const PeriodicWaveConstraints& constraints)
@@ -641,17 +624,11 @@
     ALWAYS_LOG(LOGIDENTIFIER);
     
     ASSERT(isMainThread());
-    if (m_isStopScheduled)
-        return Exception { InvalidStateError };
     
-    if (real.size() != imaginary.size())
-        return Exception { IndexSizeError, "real and imaginary must have the same length"_s };
-    
     PeriodicWaveOptions options;
     options.real = WTFMove(real);
     options.imag = WTFMove(imaginary);
     options.disableNormalization = constraints.disableNormalization;
-    lazyInitialize();
     return PeriodicWave::create(*this, WTFMove(options));
 }
 

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h (265051 => 265052)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-07-29 20:24:46 UTC (rev 265052)
@@ -285,6 +285,15 @@
         bool m_mustReleaseLock;
     };
 
+    // The context itself keeps a reference to all source nodes. The source nodes, then reference all nodes they're connected to.
+    // In turn, these nodes reference all nodes they're connected to. All nodes are ultimately connected to the AudioDestinationNode.
+    // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is
+    // uniquely connected to. See the AudioNode::ref() and AudioNode::deref() methods for more details.
+    void refNode(AudioNode&);
+    void derefNode(AudioNode&);
+
+    void lazyInitialize();
+
 protected:
     explicit BaseAudioContext(Document&, const AudioContextOptions& = { });
     BaseAudioContext(Document&, AudioBuffer* renderTarget);
@@ -295,7 +304,6 @@
 
     AudioDestinationNode* destinationNode() const { return m_destinationNode.get(); }
 
-    void lazyInitialize();
     void uninitialize();
 
 #if !RELEASE_LOG_DISABLED
@@ -302,13 +310,6 @@
     const char* logClassName() const final { return "BaseAudioContext"; }
 #endif
 
-    // The context itself keeps a reference to all source nodes.  The source nodes, then reference all nodes they're connected to.
-    // In turn, these nodes reference all nodes they're connected to.  All nodes are ultimately connected to the AudioDestinationNode.
-    // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is
-    // uniquely connected to.  See the AudioNode::ref() and AudioNode::deref() methods for more details.
-    void refNode(AudioNode&);
-    void derefNode(AudioNode&);
-
     void addReaction(State, DOMPromiseDeferred<void>&&);
     void setState(State);
 

Modified: trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp (265051 => 265052)


--- trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2020-07-29 20:24:46 UTC (rev 265052)
@@ -47,6 +47,11 @@
 
 ExceptionOr<Ref<OscillatorNode>> OscillatorNode::create(BaseAudioContext& context, const OscillatorOptions& options)
 {
+    if (context.isStopped())
+        return Exception { InvalidStateError };
+
+    context.lazyInitialize();
+
     if (options.type == OscillatorType::Custom && !options.periodicWave)
         return Exception { InvalidStateError, "Must provide periodicWave when using custom type."_s };
     
@@ -71,7 +76,11 @@
         if (result.hasException())
             return result.releaseException();
     }
-    
+
+    // Because this is an AudioScheduledSourceNode, the context keeps a reference until it has finished playing.
+    // When this happens, AudioScheduledSourceNode::finish() calls BaseAudioContext::notifyNodeFinishedProcessing().
+    context.refNode(oscillator);
+
     return oscillator;
 }
 

Modified: trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp (265051 => 265052)


--- trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/Modules/webaudio/PannerNode.cpp	2020-07-29 20:24:46 UTC (rev 265052)
@@ -62,6 +62,11 @@
 
 ExceptionOr<Ref<PannerNode>> PannerNode::create(BaseAudioContext& context, const PannerOptions& options)
 {
+    if (context.isStopped())
+        return Exception { InvalidStateError };
+
+    context.lazyInitialize();
+
     auto panner = adoptRef(*new PannerNode(context, options));
 
     auto result = panner->setMaxDistance(options.maxDistance);

Modified: trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp (265051 => 265052)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp	2020-07-29 20:00:48 UTC (rev 265051)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp	2020-07-29 20:24:46 UTC (rev 265052)
@@ -56,6 +56,11 @@
 
 ExceptionOr<Ref<PeriodicWave>> PeriodicWave::create(BaseAudioContext& context, PeriodicWaveOptions&& options)
 {
+    if (context.isStopped())
+        return Exception { InvalidStateError };
+
+    context.lazyInitialize();
+
     Vector<float> real;
     Vector<float> imag;
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to