Title: [262113] trunk/Source/WebCore
Revision
262113
Author
[email protected]
Date
2020-05-24 23:28:03 -0700 (Sun, 24 May 2020)

Log Message

Do not allocate a WebAudioBufferList in the AudioContext rendering thread
https://bugs.webkit.org/show_bug.cgi?id=212132

Reviewed by Eric Carlson.

Instead of allocating the buffer in the rendering thread, we do that in the audio sample producer thread.
Also, we do it only once versus one for each rendering call previously.
Covered by existing tests.

* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::provideInput):
(WebCore::WebAudioSourceProviderAVFObjC::prepare):
(WebCore::WebAudioSourceProviderAVFObjC::unprepare):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (262112 => 262113)


--- trunk/Source/WebCore/ChangeLog	2020-05-25 06:25:08 UTC (rev 262112)
+++ trunk/Source/WebCore/ChangeLog	2020-05-25 06:28:03 UTC (rev 262113)
@@ -1,3 +1,20 @@
+2020-05-24  Youenn Fablet  <[email protected]>
+
+        Do not allocate a WebAudioBufferList in the AudioContext rendering thread
+        https://bugs.webkit.org/show_bug.cgi?id=212132
+
+        Reviewed by Eric Carlson.
+
+        Instead of allocating the buffer in the rendering thread, we do that in the audio sample producer thread.
+        Also, we do it only once versus one for each rendering call previously.
+        Covered by existing tests.
+
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::provideInput):
+        (WebCore::WebAudioSourceProviderAVFObjC::prepare):
+        (WebCore::WebAudioSourceProviderAVFObjC::unprepare):
+
 2020-05-24  Wenson Hsieh  <[email protected]>
 
         Add some missing includes due to unified sources

Modified: trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h (262112 => 262113)


--- trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h	2020-05-25 06:25:08 UTC (rev 262112)
+++ trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.h	2020-05-25 06:28:03 UTC (rev 262113)
@@ -45,6 +45,7 @@
 
 class AudioSampleDataSource;
 class CAAudioStreamDescription;
+class WebAudioBufferList;
 
 class WEBCORE_EXPORT WebAudioSourceProviderAVFObjC final
     : public WebAudioSourceProvider
@@ -76,6 +77,7 @@
     size_t m_listBufferSize { 0 };
     Optional<CAAudioStreamDescription> m_inputDescription;
     Optional<CAAudioStreamDescription> m_outputDescription;
+    std::unique_ptr<WebAudioBufferList> m_audioBufferList;
     RefPtr<AudioSampleDataSource> m_dataSource;
 
     uint64_t m_writeCount { 0 };

Modified: trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm (262112 => 262113)


--- trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm	2020-05-25 06:25:08 UTC (rev 262112)
+++ trunk/Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm	2020-05-25 06:28:03 UTC (rev 262113)
@@ -73,7 +73,7 @@
 void WebAudioSourceProviderAVFObjC::provideInput(AudioBus* bus, size_t framesToProcess)
 {
     std::unique_lock<Lock> lock(m_mutex, std::try_to_lock);
-    if (!lock.owns_lock() || !m_dataSource) {
+    if (!lock.owns_lock() || !m_dataSource || !m_audioBufferList) {
         bus->zero();
         return;
     }
@@ -83,8 +83,7 @@
         return;
     }
 
-    WebAudioBufferList list { m_outputDescription.value() };
-    if (bus->numberOfChannels() < list.bufferCount()) {
+    if (bus->numberOfChannels() < m_audioBufferList->bufferCount()) {
         bus->zero();
         return;
     }
@@ -91,11 +90,11 @@
 
     for (unsigned i = 0; i < bus->numberOfChannels(); ++i) {
         auto& channel = *bus->channel(i);
-        if (i >= list.bufferCount()) {
+        if (i >= m_audioBufferList->bufferCount()) {
             channel.zero();
             continue;
         }
-        auto* buffer = list.buffer(i);
+        auto* buffer = m_audioBufferList->buffer(i);
         buffer->mNumberChannels = 1;
         buffer->mData = channel.mutableData();
         buffer->mDataByteSize = channel.length() * sizeof(float);
@@ -102,7 +101,7 @@
     }
 
     ASSERT(framesToProcess <= bus->length());
-    m_dataSource->pullSamples(*list.list(), framesToProcess, m_readCount, 0, AudioSampleDataSource::Copy);
+    m_dataSource->pullSamples(*m_audioBufferList->list(), framesToProcess, m_readCount, 0, AudioSampleDataSource::Copy);
     m_readCount += framesToProcess;
 }
 
@@ -144,6 +143,7 @@
     AudioStreamBasicDescription outputDescription { };
     FillOutASBDForLPCM(outputDescription, sampleRate, numberOfChannels, bitsPerByte * bytesPerFloat, bitsPerByte * bytesPerFloat, isFloat, isBigEndian, isNonInterleaved);
     m_outputDescription = CAAudioStreamDescription(outputDescription);
+    m_audioBufferList = makeUnique<WebAudioBufferList>(m_outputDescription.value());
 
     if (!m_dataSource)
         m_dataSource = AudioSampleDataSource::create(kRingBufferDuration * sampleRate, *m_captureSource);
@@ -162,6 +162,7 @@
 
     m_inputDescription = WTF::nullopt;
     m_outputDescription = WTF::nullopt;
+    m_audioBufferList = nullptr;
     m_dataSource = nullptr;
     m_listBufferSize = 0;
     if (m_captureSource) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to