SincResampler does not need to create a new AudioBus for each consumeSource call
https://bugs.webkit.org/show_bug.cgi?id=202983
Reviewed by Eric Carlson.
Allocate an internal AudioBus once and for all.
No observable change of behavior.
* platform/audio/SincResampler.cpp:
(WebCore::SincResampler::consumeSource):
* platform/audio/SincResampler.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251249 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 4e2c80e..729b01e 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,17 @@
+2019-10-17 Youenn Fablet <youenn@apple.com>
+
+ SincResampler does not need to create a new AudioBus for each consumeSource call
+ https://bugs.webkit.org/show_bug.cgi?id=202983
+
+ Reviewed by Eric Carlson.
+
+ Allocate an internal AudioBus once and for all.
+ No observable change of behavior.
+
+ * platform/audio/SincResampler.cpp:
+ (WebCore::SincResampler::consumeSource):
+ * platform/audio/SincResampler.h:
+
2019-10-17 Chris Dumez <cdumez@apple.com>
Deprecate ActiveDOMObject::canSuspendForDocumentSuspension()
diff --git a/Source/WebCore/platform/audio/SincResampler.cpp b/Source/WebCore/platform/audio/SincResampler.cpp
index 5d08de5c..520527b 100644
--- a/Source/WebCore/platform/audio/SincResampler.cpp
+++ b/Source/WebCore/platform/audio/SincResampler.cpp
@@ -130,14 +130,15 @@
ASSERT(m_sourceProvider);
if (!m_sourceProvider)
return;
-
+
// Wrap the provided buffer by an AudioBus for use by the source provider.
- auto bus = AudioBus::create(1, numberOfSourceFrames, false);
+ if (!m_internalBus || m_internalBus->length() != numberOfSourceFrames)
+ m_internalBus = AudioBus::create(1, numberOfSourceFrames, false);
// FIXME: Find a way to make the following const-correct:
- bus->setChannelMemory(0, buffer, numberOfSourceFrames);
+ m_internalBus->setChannelMemory(0, buffer, numberOfSourceFrames);
- m_sourceProvider->provideInput(bus.get(), numberOfSourceFrames);
+ m_sourceProvider->provideInput(m_internalBus.get(), numberOfSourceFrames);
}
namespace {
diff --git a/Source/WebCore/platform/audio/SincResampler.h b/Source/WebCore/platform/audio/SincResampler.h
index c132f5d..b16eb51 100644
--- a/Source/WebCore/platform/audio/SincResampler.h
+++ b/Source/WebCore/platform/audio/SincResampler.h
@@ -31,6 +31,7 @@
#include "AudioArray.h"
#include "AudioSourceProvider.h"
+#include <wtf/RefPtr.h>
namespace WebCore {
@@ -80,6 +81,8 @@
// The buffer is primed once at the very beginning of processing.
bool m_isBufferPrimed;
+
+ RefPtr<AudioBus> m_internalBus;
};
} // namespace WebCore