Title: [270924] trunk/Source/WebCore
Revision
270924
Author
[email protected]
Date
2020-12-16 19:16:23 -0800 (Wed, 16 Dec 2020)

Log Message

Flaky crash under AudioBuffer::channelData() when running layout tests
https://bugs.webkit.org/show_bug.cgi?id=219914

Reviewed by Geoffrey Garen.

The issue was that AudioBuffer::channelData() returns a RefPtr<Float32Array>,
Float32Array not being ThreadSafeRefCounted. The AudioBuffers in ScriptProcessorNode
are constructed on the main thread but ScriptProcessorNode::process() was calling
AudioBuffer::channelData() on the audio rendering thread. This would do some
non-thread-safe refcounting churn which would cause the crashes.

To address the issue, I introduced AudioBuffer::rawChannelData() which returns
the data as a float*, without any refcounting. I ported ScriptProcessorNode::process()
to use AudioBuffer::rawChannelData() instead of AudioBuffer::channelData().

No new tests, covered by existing layout tests that are flakily crashing.

* Modules/webaudio/AudioBuffer.cpp:
(WebCore::AudioBuffer::rawChannelData):
* Modules/webaudio/AudioBuffer.h:
* Modules/webaudio/ScriptProcessorNode.cpp:
(WebCore::ScriptProcessorNode::process):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270923 => 270924)


--- trunk/Source/WebCore/ChangeLog	2020-12-17 02:46:48 UTC (rev 270923)
+++ trunk/Source/WebCore/ChangeLog	2020-12-17 03:16:23 UTC (rev 270924)
@@ -1,3 +1,28 @@
+2020-12-16  Chris Dumez  <[email protected]>
+
+        Flaky crash under AudioBuffer::channelData() when running layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=219914
+
+        Reviewed by Geoffrey Garen.
+
+        The issue was that AudioBuffer::channelData() returns a RefPtr<Float32Array>,
+        Float32Array not being ThreadSafeRefCounted. The AudioBuffers in ScriptProcessorNode
+        are constructed on the main thread but ScriptProcessorNode::process() was calling
+        AudioBuffer::channelData() on the audio rendering thread. This would do some
+        non-thread-safe refcounting churn which would cause the crashes.
+
+        To address the issue, I introduced AudioBuffer::rawChannelData() which returns
+        the data as a float*, without any refcounting. I ported ScriptProcessorNode::process()
+        to use AudioBuffer::rawChannelData() instead of AudioBuffer::channelData().
+
+        No new tests, covered by existing layout tests that are flakily crashing.
+
+        * Modules/webaudio/AudioBuffer.cpp:
+        (WebCore::AudioBuffer::rawChannelData):
+        * Modules/webaudio/AudioBuffer.h:
+        * Modules/webaudio/ScriptProcessorNode.cpp:
+        (WebCore::ScriptProcessorNode::process):
+
 2020-12-15  Yusuke Suzuki  <[email protected]>
 
         [JSC] Accept arbitrary module namespace identifier names

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp (270923 => 270924)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2020-12-17 02:46:48 UTC (rev 270923)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2020-12-17 03:16:23 UTC (rev 270924)
@@ -169,6 +169,15 @@
     return m_channels[channelIndex].copyRef();
 }
 
+float* AudioBuffer::rawChannelData(unsigned channelIndex)
+{
+    if (channelIndex >= m_channels.size())
+        return nullptr;
+    if (hasDetachedChannelBuffer())
+        return nullptr;
+    return m_channels[channelIndex]->data();
+}
+
 ExceptionOr<void> AudioBuffer::copyFromChannel(Ref<Float32Array>&& destination, unsigned channelNumber, unsigned bufferOffset)
 {
     if (destination->isShared())

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h (270923 => 270924)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2020-12-17 02:46:48 UTC (rev 270923)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2020-12-17 03:16:23 UTC (rev 270924)
@@ -65,6 +65,7 @@
 
     // Native channel data access.
     RefPtr<Float32Array> channelData(unsigned channelIndex);
+    float* rawChannelData(unsigned channelIndex);
     void zero();
 
     // Because an AudioBuffer has a _javascript_ wrapper, which will be garbage collected, it may take a while for this object to be deleted.

Modified: trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp (270923 => 270924)


--- trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2020-12-17 02:46:48 UTC (rev 270923)
+++ trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2020-12-17 03:16:23 UTC (rev 270924)
@@ -167,7 +167,7 @@
         return;
 
     for (unsigned i = 0; i < numberOfInputChannels; i++)
-        m_internalInputBus->setChannelMemory(i, inputBuffer->channelData(i)->data() + m_bufferReadWriteIndex, framesToProcess);
+        m_internalInputBus->setChannelMemory(i, inputBuffer->rawChannelData(i) + m_bufferReadWriteIndex, framesToProcess);
 
     if (numberOfInputChannels)
         m_internalInputBus->copyFrom(*inputBus);
@@ -174,7 +174,7 @@
 
     // Copy from the output buffer to the output. 
     for (unsigned i = 0; i < numberOfOutputChannels; ++i)
-        memcpy(outputBus->channel(i)->mutableData(), outputBuffer->channelData(i)->data() + m_bufferReadWriteIndex, sizeof(float) * framesToProcess);
+        memcpy(outputBus->channel(i)->mutableData(), outputBuffer->rawChannelData(i) + m_bufferReadWriteIndex, sizeof(float) * framesToProcess);
 
     // Update the buffering index.
     m_bufferReadWriteIndex = (m_bufferReadWriteIndex + framesToProcess) % bufferSize();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to