Title: [274871] trunk/Source
Revision
274871
Author
[email protected]
Date
2021-03-23 08:33:36 -0700 (Tue, 23 Mar 2021)

Log Message

Add assertions to guard against heap allocations on the audio thread
https://bugs.webkit.org/show_bug.cgi?id=223226

Reviewed by Darin Adler.

Source/WebCore:

Add assertions to guard against heap allocations on the audio thread during
audio processing, since those are bad for performance. I fixed any of the
issues found by these assertions in dependency bugs. Some issues remain
and are protected by DisableMallocRestrictionsForCurrentThreadScope to avoid
tripping the new assertions.

Right now, the assertions only protect audio processing, not pre/post quantum
rendering casts. Ideally, we'd expand the scope of these assertions to cover
everything that's done on the audio thread but this will require more fixes.

* Modules/webaudio/AudioDestinationNode.cpp:
(WebCore::AudioDestinationNode::render):
* Modules/webaudio/AudioScheduledSourceNode.cpp:
(WebCore::AudioScheduledSourceNode::finish):
* Modules/webaudio/AudioWorkletNode.cpp:
(WebCore::AudioWorkletNode::fireProcessorErrorOnMainThread):
* Modules/webaudio/AudioWorkletProcessor.cpp:
(WebCore::AudioWorkletProcessor::process):
* Modules/webaudio/MediaStreamAudioSourceCocoa.cpp:
(WebCore::MediaStreamAudioSource::consumeAudio):
* Modules/webaudio/ScriptProcessorNode.cpp:
(WebCore::ScriptProcessorNode::process):

Source/WTF:

Add ForbidMallocUseForCurrentThreadScope to FastMalloc.h to enable assertions guarding against
doing heap allocations on the current thread (during the lifetime of the Scope object).

Also add a DisableMallocRestrictionsForCurrentThreadScope to temporarily disable those checks
to allow for some very specific assertions (either because they are required, or simply because
they are not fixed yet).

* wtf/FastMalloc.cpp:
(WTF::ForbidMallocUseForCurrentThreadScope::ForbidMallocUseForCurrentThreadScope):
(WTF::ForbidMallocUseForCurrentThreadScope::~ForbidMallocUseForCurrentThreadScope):
(WTF::DisableMallocRestrictionsForCurrentThreadScope::DisableMallocRestrictionsForCurrentThreadScope):
(WTF::DisableMallocRestrictionsForCurrentThreadScope::~DisableMallocRestrictionsForCurrentThreadScope):
(WTF::tryFastMalloc):
(WTF::fastMalloc):
(WTF::tryFastCalloc):
(WTF::fastCalloc):
(WTF::fastRealloc):
(WTF::tryFastRealloc):
(WTF::fastAlignedMalloc):
(WTF::tryFastAlignedMalloc):
* wtf/FastMalloc.h:
(WTF::ForbidMallocUseForCurrentThreadScope::~ForbidMallocUseForCurrentThreadScope):
(WTF::DisableMallocRestrictionsForCurrentThreadScope::~DisableMallocRestrictionsForCurrentThreadScope):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (274870 => 274871)


--- trunk/Source/WTF/ChangeLog	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WTF/ChangeLog	2021-03-23 15:33:36 UTC (rev 274871)
@@ -1,3 +1,34 @@
+2021-03-23  Chris Dumez  <[email protected]>
+
+        Add assertions to guard against heap allocations on the audio thread
+        https://bugs.webkit.org/show_bug.cgi?id=223226
+
+        Reviewed by Darin Adler.
+
+        Add ForbidMallocUseForCurrentThreadScope to FastMalloc.h to enable assertions guarding against
+        doing heap allocations on the current thread (during the lifetime of the Scope object).
+
+        Also add a DisableMallocRestrictionsForCurrentThreadScope to temporarily disable those checks
+        to allow for some very specific assertions (either because they are required, or simply because
+        they are not fixed yet).
+
+        * wtf/FastMalloc.cpp:
+        (WTF::ForbidMallocUseForCurrentThreadScope::ForbidMallocUseForCurrentThreadScope):
+        (WTF::ForbidMallocUseForCurrentThreadScope::~ForbidMallocUseForCurrentThreadScope):
+        (WTF::DisableMallocRestrictionsForCurrentThreadScope::DisableMallocRestrictionsForCurrentThreadScope):
+        (WTF::DisableMallocRestrictionsForCurrentThreadScope::~DisableMallocRestrictionsForCurrentThreadScope):
+        (WTF::tryFastMalloc):
+        (WTF::fastMalloc):
+        (WTF::tryFastCalloc):
+        (WTF::fastCalloc):
+        (WTF::fastRealloc):
+        (WTF::tryFastRealloc):
+        (WTF::fastAlignedMalloc):
+        (WTF::tryFastAlignedMalloc):
+        * wtf/FastMalloc.h:
+        (WTF::ForbidMallocUseForCurrentThreadScope::~ForbidMallocUseForCurrentThreadScope):
+        (WTF::DisableMallocRestrictionsForCurrentThreadScope::~DisableMallocRestrictionsForCurrentThreadScope):
+
 2021-03-22  Devin Rousso  <[email protected]>
 
         Remove unused JS and CSS files of media controls

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (274870 => 274871)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -53,6 +53,33 @@
 
 namespace WTF {
 
+#if ASSERT_ENABLED
+thread_local static unsigned forbidMallocUseScopeCount;
+thread_local static unsigned disableMallocRestrictionScopeCount;
+
+ForbidMallocUseForCurrentThreadScope::ForbidMallocUseForCurrentThreadScope()
+{
+    ++forbidMallocUseScopeCount;
+}
+
+ForbidMallocUseForCurrentThreadScope::~ForbidMallocUseForCurrentThreadScope()
+{
+    ASSERT(forbidMallocUseScopeCount);
+    --forbidMallocUseScopeCount;
+}
+
+DisableMallocRestrictionsForCurrentThreadScope::DisableMallocRestrictionsForCurrentThreadScope()
+{
+    ++disableMallocRestrictionScopeCount;
+}
+
+DisableMallocRestrictionsForCurrentThreadScope::~DisableMallocRestrictionsForCurrentThreadScope()
+{
+    ASSERT(disableMallocRestrictionScopeCount);
+    --disableMallocRestrictionScopeCount;
+}
+#endif
+
 #if !defined(NDEBUG)
 namespace {
 // We do not use std::numeric_limits<size_t>::max() here due to the edge case in VC++.
@@ -194,6 +221,7 @@
 TryMallocReturnValue tryFastMalloc(size_t n) 
 {
     FAIL_IF_EXCEEDS_LIMIT(n);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     return malloc(n);
 }
 
@@ -200,6 +228,7 @@
 void* fastMalloc(size_t n) 
 {
     ASSERT_IS_WITHIN_LIMIT(n);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = malloc(n);
     if (!result)
         CRASH();
@@ -210,6 +239,7 @@
 TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size)
 {
     FAIL_IF_EXCEEDS_LIMIT(n_elements * element_size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     return calloc(n_elements, element_size);
 }
 
@@ -216,6 +246,7 @@
 void* fastCalloc(size_t n_elements, size_t element_size)
 {
     ASSERT_IS_WITHIN_LIMIT(n_elements * element_size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = calloc(n_elements, element_size);
     if (!result)
         CRASH();
@@ -231,6 +262,7 @@
 void* fastRealloc(void* p, size_t n)
 {
     ASSERT_IS_WITHIN_LIMIT(n);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = realloc(p, n);
     if (!result)
         CRASH();
@@ -240,6 +272,7 @@
 TryMallocReturnValue tryFastRealloc(void* p, size_t n)
 {
     FAIL_IF_EXCEEDS_LIMIT(n);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     return realloc(p, n);
 }
 
@@ -488,6 +521,7 @@
 void* fastMalloc(size_t size)
 {
     ASSERT_IS_WITHIN_LIMIT(size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = bmalloc::api::malloc(size);
 #if ENABLE(MALLOC_HEAP_BREAKDOWN) && TRACK_MALLOC_CALLSTACK
     if (!AvoidRecordingScope::avoidRecordingCount())
@@ -510,6 +544,7 @@
 void* fastRealloc(void* object, size_t size)
 {
     ASSERT_IS_WITHIN_LIMIT(size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = bmalloc::api::realloc(object, size);
 #if ENABLE(MALLOC_HEAP_BREAKDOWN) && TRACK_MALLOC_CALLSTACK
     if (!AvoidRecordingScope::avoidRecordingCount())
@@ -543,6 +578,7 @@
 void* fastAlignedMalloc(size_t alignment, size_t size)
 {
     ASSERT_IS_WITHIN_LIMIT(size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = bmalloc::api::memalign(alignment, size);
 #if ENABLE(MALLOC_HEAP_BREAKDOWN) && TRACK_MALLOC_CALLSTACK
     if (!AvoidRecordingScope::avoidRecordingCount())
@@ -554,6 +590,7 @@
 void* tryFastAlignedMalloc(size_t alignment, size_t size)
 {
     FAIL_IF_EXCEEDS_LIMIT(size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     void* result = bmalloc::api::tryMemalign(alignment, size);
 #if ENABLE(MALLOC_HEAP_BREAKDOWN) && TRACK_MALLOC_CALLSTACK
     if (!AvoidRecordingScope::avoidRecordingCount())
@@ -570,6 +607,7 @@
 TryMallocReturnValue tryFastMalloc(size_t size)
 {
     FAIL_IF_EXCEEDS_LIMIT(size);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     return bmalloc::api::tryMalloc(size);
 }
 
@@ -586,6 +624,7 @@
 TryMallocReturnValue tryFastRealloc(void* object, size_t newSize)
 {
     FAIL_IF_EXCEEDS_LIMIT(newSize);
+    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
     return bmalloc::api::tryRealloc(object, newSize);
 }
 

Modified: trunk/Source/WTF/wtf/FastMalloc.h (274870 => 274871)


--- trunk/Source/WTF/wtf/FastMalloc.h	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2021-03-23 15:33:36 UTC (rev 274871)
@@ -122,6 +122,38 @@
 
 WTF_EXPORT_PRIVATE void fastDisableScavenger();
 
+class ForbidMallocUseForCurrentThreadScope {
+public:
+#if ASSERT_ENABLED
+    WTF_EXPORT_PRIVATE ForbidMallocUseForCurrentThreadScope();
+    WTF_EXPORT_PRIVATE ~ForbidMallocUseForCurrentThreadScope();
+#else
+    ForbidMallocUseForCurrentThreadScope() = default;
+    ~ForbidMallocUseForCurrentThreadScope() { }
+#endif
+
+    ForbidMallocUseForCurrentThreadScope(const ForbidMallocUseForCurrentThreadScope&) = delete;
+    ForbidMallocUseForCurrentThreadScope(ForbidMallocUseForCurrentThreadScope&&) = delete;
+    ForbidMallocUseForCurrentThreadScope& operator=(const ForbidMallocUseForCurrentThreadScope&) = delete;
+    ForbidMallocUseForCurrentThreadScope& operator=(ForbidMallocUseForCurrentThreadScope&&) = delete;
+};
+
+class DisableMallocRestrictionsForCurrentThreadScope {
+public:
+#if ASSERT_ENABLED
+    WTF_EXPORT_PRIVATE DisableMallocRestrictionsForCurrentThreadScope();
+    WTF_EXPORT_PRIVATE ~DisableMallocRestrictionsForCurrentThreadScope();
+#else
+    DisableMallocRestrictionsForCurrentThreadScope() = default;
+    ~DisableMallocRestrictionsForCurrentThreadScope() { }
+#endif
+
+    DisableMallocRestrictionsForCurrentThreadScope(const DisableMallocRestrictionsForCurrentThreadScope&) = delete;
+    DisableMallocRestrictionsForCurrentThreadScope(DisableMallocRestrictionsForCurrentThreadScope&&) = delete;
+    DisableMallocRestrictionsForCurrentThreadScope& operator=(const DisableMallocRestrictionsForCurrentThreadScope&) = delete;
+    DisableMallocRestrictionsForCurrentThreadScope& operator=(DisableMallocRestrictionsForCurrentThreadScope&&) = delete;
+};
+
 struct FastMallocStatistics {
     size_t reservedVMBytes;
     size_t committedVMBytes;
@@ -300,9 +332,11 @@
 using WTF::fastSetMaxSingleAllocationSize;
 #endif
 
+using WTF::DisableMallocRestrictionsForCurrentThreadScope;
 using WTF::FastAllocator;
 using WTF::FastMalloc;
 using WTF::FastFree;
+using WTF::ForbidMallocUseForCurrentThreadScope;
 using WTF::isFastMallocEnabled;
 using WTF::fastCalloc;
 using WTF::fastFree;

Modified: trunk/Source/WebCore/ChangeLog (274870 => 274871)


--- trunk/Source/WebCore/ChangeLog	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/ChangeLog	2021-03-23 15:33:36 UTC (rev 274871)
@@ -1,3 +1,33 @@
+2021-03-23  Chris Dumez  <[email protected]>
+
+        Add assertions to guard against heap allocations on the audio thread
+        https://bugs.webkit.org/show_bug.cgi?id=223226
+
+        Reviewed by Darin Adler.
+
+        Add assertions to guard against heap allocations on the audio thread during
+        audio processing, since those are bad for performance. I fixed any of the
+        issues found by these assertions in dependency bugs. Some issues remain
+        and are protected by DisableMallocRestrictionsForCurrentThreadScope to avoid
+        tripping the new assertions.
+
+        Right now, the assertions only protect audio processing, not pre/post quantum
+        rendering casts. Ideally, we'd expand the scope of these assertions to cover
+        everything that's done on the audio thread but this will require more fixes.
+
+        * Modules/webaudio/AudioDestinationNode.cpp:
+        (WebCore::AudioDestinationNode::render):
+        * Modules/webaudio/AudioScheduledSourceNode.cpp:
+        (WebCore::AudioScheduledSourceNode::finish):
+        * Modules/webaudio/AudioWorkletNode.cpp:
+        (WebCore::AudioWorkletNode::fireProcessorErrorOnMainThread):
+        * Modules/webaudio/AudioWorkletProcessor.cpp:
+        (WebCore::AudioWorkletProcessor::process):
+        * Modules/webaudio/MediaStreamAudioSourceCocoa.cpp:
+        (WebCore::MediaStreamAudioSource::consumeAudio):
+        * Modules/webaudio/ScriptProcessorNode.cpp:
+        (WebCore::ScriptProcessorNode::process):
+
 2021-03-23  Philippe Normand  <[email protected]>
 
         [MSE][GStreamer] SIGSEV in webKitMediaSrcFreeStream

Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -86,20 +86,24 @@
     if (workletGlobalScope)
         workletGlobalScope->handlePreRenderTasks();
 
-    // This will cause the node(s) connected to us to process, which in turn will pull on their input(s),
-    // all the way backwards through the rendering graph.
-    AudioBus* renderedBus = input(0)->pull(destinationBus, numberOfFrames);
-    
-    if (!renderedBus)
-        destinationBus->zero();
-    else if (renderedBus != destinationBus) {
-        // in-place processing was not possible - so copy
-        destinationBus->copyFrom(*renderedBus);
+    {
+        ForbidMallocUseForCurrentThreadScope forbidMallocUse;
+
+        // This will cause the node(s) connected to us to process, which in turn will pull on their input(s),
+        // all the way backwards through the rendering graph.
+        AudioBus* renderedBus = input(0)->pull(destinationBus, numberOfFrames);
+
+        if (!renderedBus)
+            destinationBus->zero();
+        else if (renderedBus != destinationBus) {
+            // in-place processing was not possible - so copy
+            destinationBus->copyFrom(*renderedBus);
+        }
+
+        // Process nodes which need a little extra help because they are not connected to anything, but still need to process.
+        context().processAutomaticPullNodes(numberOfFrames);
     }
 
-    // Process nodes which need a little extra help because they are not connected to anything, but still need to process.
-    context().processAutomaticPullNodes(numberOfFrames);
-
     // Let the context take care of any business at the end of each render quantum.
     context().handlePostRenderTasks();
     

Modified: trunk/Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -197,6 +197,8 @@
     m_playbackState = FINISHED_STATE;
     context().decrementActiveSourceCount();
 
+    // Dispatching a Function to the main thread requires heap allocations.
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     callOnMainThread([this, protectedThis = makeRef(*this)] {
         auto release = makeScopeExit([&] () {
             AudioContext::AutoLocker locker(context());

Modified: trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -276,6 +276,8 @@
 {
     ASSERT(!isMainThread());
 
+    // Dispatching a Function to the main thread requires heap allocations.
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     callOnMainThread([this, protectedThis = makeRef(*this), error]() mutable {
         String errorMessage;
         switch (error) {

Modified: trunk/Source/WebCore/Modules/webaudio/AudioWorkletProcessor.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/AudioWorkletProcessor.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/AudioWorkletProcessor.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -231,6 +231,7 @@
 
 bool AudioWorkletProcessor::process(const Vector<RefPtr<AudioBus>>& inputs, Vector<Ref<AudioBus>>& outputs, const HashMap<String, std::unique_ptr<AudioFloatArray>>& paramValuesMap, bool& threwException)
 {
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     ASSERT(m_processCallback);
     auto& globalObject = *m_processCallback->globalObject();
     ASSERT(globalObject.scriptExecutionContext());

Modified: trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceCocoa.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceCocoa.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/MediaStreamAudioSourceCocoa.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -79,6 +79,8 @@
 
     auto description = streamDescription(m_currentSettings.sampleRate(), bus.numberOfChannels());
     if (!audioBuffer || audioBuffer->channelCount() != bus.numberOfChannels()) {
+        // FIXME: We should avoid this WebAudioBufferList allocation on the audio thread.
+        DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
         m_audioBuffer = makeUnique<WebAudioBufferList>(description, WTF::safeCast<uint32_t>(numberOfFrames));
         audioBuffer = &downcast<WebAudioBufferList>(*m_audioBuffer);
     } else

Modified: trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp (274870 => 274871)


--- trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -210,6 +210,9 @@
     // m_bufferReadWriteIndex will wrap back around to 0 when the current input and output buffers are full.
     // When this happens, fire an event and swap buffers.
     if (!m_bufferReadWriteIndex) {
+        // Dispatching a Function to the main thread requires heap allocations.
+        DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
+
         // Reference ourself so we don't accidentally get deleted before fireProcessEvent() gets called.
         // We only wait for script code execution when the context is an offline one for performance reasons.
         if (context().isOfflineContext()) {

Modified: trunk/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm (274870 => 274871)


--- trunk/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm	2021-03-23 15:33:36 UTC (rev 274871)
@@ -111,8 +111,12 @@
 
     m_outputDescription = CAAudioStreamDescription { format };
 
-    m_ringBuffer->allocate(format, static_cast<size_t>(m_maximumSampleCount));
-    m_scratchBuffer = AudioSampleBufferList::create(m_outputDescription->streamDescription(), m_maximumSampleCount);
+    {
+        // FIXME: This does heap allocations on the audio thread.
+        DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
+        m_ringBuffer->allocate(format, static_cast<size_t>(m_maximumSampleCount));
+        m_scratchBuffer = AudioSampleBufferList::create(m_outputDescription->streamDescription(), m_maximumSampleCount);
+    }
 
     return setupConverter();
 }

Modified: trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp (274870 => 274871)


--- trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -77,6 +77,7 @@
 
 void MediaRecorderPrivateMock::audioSamplesAvailable(const WTF::MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t)
 {
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     auto locker = holdLock(m_bufferLock);
     m_buffer.append("Audio Track ID: ");
     m_buffer.append(m_audioTrackID);

Modified: trunk/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm (274870 => 274871)


--- trunk/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm	2021-03-23 15:33:36 UTC (rev 274871)
@@ -509,6 +509,7 @@
 
 void AudioSampleBufferCompressor::addSampleBuffer(CMSampleBufferRef buffer)
 {
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     m_serialDispatchQueue->dispatchSync([this, buffer] {
         if (m_isEncoding)
             processSampleBuffer(buffer);

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (274870 => 274871)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -175,6 +175,8 @@
     if (m_hasStartedProducingData)
         return;
 
+    // Dispatching a Function to the main thread requires heap allocations.
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     callOnMainThread([protectedThis = makeRef(*this)] {
         if (protectedThis->m_hasStartedProducingData)
             return;

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp (274870 => 274871)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSourceCocoa.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -118,6 +118,7 @@
     if (!hasBufferedEnoughData())
         return;
 
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
     LibWebRTCProvider::callOnWebRTCSignalingThread([protectedThis = makeRef(*this)] {
         protectedThis->pullAudioData();
     });

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp (274870 => 274871)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp	2021-03-23 15:32:27 UTC (rev 274870)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp	2021-03-23 15:33:36 UTC (rev 274871)
@@ -118,6 +118,9 @@
 
 void MediaRecorderPrivate::audioSamplesAvailable(const MediaTime& time, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t numberOfFrames)
 {
+    // FIXME: This does heap allocations on the audio thread.
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
+
     if (m_description != description) {
         ASSERT(description.platformDescription().type == PlatformDescription::CAAudioStreamBasicType);
         m_description = *WTF::get<const AudioStreamBasicDescription*>(description.platformDescription().description);
@@ -144,6 +147,9 @@
 
 void MediaRecorderPrivate::storageChanged(SharedMemory* storage, const WebCore::CAAudioStreamDescription& format, size_t frameCount)
 {
+    // FIXME: This does heap allocations on the audio thread.
+    DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
+
     SharedMemory::Handle handle;
     if (storage)
         storage->createHandle(handle, SharedMemory::Protection::ReadOnly);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to