Diff
Modified: trunk/Source/WebCore/ChangeLog (274678 => 274679)
--- trunk/Source/WebCore/ChangeLog 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/ChangeLog 2021-03-18 22:53:51 UTC (rev 274679)
@@ -1,3 +1,29 @@
+2021-03-18 Chris Dumez <cdu...@apple.com>
+
+ Avoid heap allocation under PannerNode::processSampleAccurateValues()
+ https://bugs.webkit.org/show_bug.cgi?id=223466
+
+ Reviewed by Darin Adler.
+
+ Make sure BaseAudioContext::m_listener gets initialized in the constructor
+ (on the main thread) instead of doing it lazily in the listener() getter
+ (which may get called on the audio thread).
+
+ * Modules/webaudio/AudioContext.cpp:
+ (WebCore::AudioContext::create):
+ (WebCore::AudioContext::AudioContext):
+ * Modules/webaudio/AudioContext.h:
+ (WebCore::AudioContext::AudioContext):
+ * Modules/webaudio/BaseAudioContext.cpp:
+ (WebCore::BaseAudioContext::BaseAudioContext):
+ (WebCore::WebCore::BaseAudioContext::listener):
+ * Modules/webaudio/BaseAudioContext.h:
+ (WebCore::BaseAudioContext::BaseAudioContext):
+ * Modules/webaudio/OfflineAudioContext.cpp:
+ (WebCore::OfflineAudioContext::OfflineAudioContext):
+ * Modules/webaudio/WebKitAudioContext.cpp:
+ (WebCore::WebKitAudioContext::WebKitAudioContext):
+
2021-03-18 Timothy Hatcher <timo...@apple.com>
SpeechSynthesis should honor audioPlaybackRequiresUserGesture setting on iOS.
Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp 2021-03-18 22:53:51 UTC (rev 274679)
@@ -100,14 +100,14 @@
if (contextOptions.sampleRate.hasValue() && !isSupportedSampleRate(contextOptions.sampleRate.value()))
return Exception { SyntaxError, "sampleRate is not in range"_s };
- auto audioContext = adoptRef(*new AudioContext(document, contextOptions));
+ auto audioContext = adoptRef(*new AudioContext(document, IsLegacyWebKitAudioContext::No, contextOptions));
audioContext->suspendIfNeeded();
return audioContext;
}
// Constructor for rendering to the audio hardware.
-AudioContext::AudioContext(Document& document, const AudioContextOptions& contextOptions)
- : BaseAudioContext(document, contextOptions)
+AudioContext::AudioContext(Document& document, IsLegacyWebKitAudioContext isLegacyWebKitAudioContext, const AudioContextOptions& contextOptions)
+ : BaseAudioContext(document, isLegacyWebKitAudioContext, contextOptions)
, m_mediaSession(PlatformMediaSession::create(PlatformMediaSessionManager::sharedManager(), *this))
{
constructCommon();
@@ -120,8 +120,8 @@
}
// Only needed for WebKitOfflineAudioContext.
-AudioContext::AudioContext(Document& document, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget)
- : BaseAudioContext(document, numberOfChannels, sampleRate, WTFMove(renderTarget))
+AudioContext::AudioContext(Document& document, IsLegacyWebKitAudioContext isLegacyWebKitAudioContext, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget)
+ : BaseAudioContext(document, isLegacyWebKitAudioContext, numberOfChannels, sampleRate, WTFMove(renderTarget))
, m_mediaSession(PlatformMediaSession::create(PlatformMediaSessionManager::sharedManager(), *this))
{
constructCommon();
Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h 2021-03-18 22:53:51 UTC (rev 274679)
@@ -88,8 +88,8 @@
void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
protected:
- explicit AudioContext(Document&, const AudioContextOptions& = { });
- AudioContext(Document&, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget);
+ explicit AudioContext(Document&, IsLegacyWebKitAudioContext, const AudioContextOptions& = { });
+ AudioContext(Document&, IsLegacyWebKitAudioContext, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget);
bool willBeginPlayback();
Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp 2021-03-18 22:53:51 UTC (rev 274679)
@@ -118,7 +118,7 @@
unsigned BaseAudioContext::s_hardwareContextCount = 0;
// Constructor for rendering to the audio hardware.
-BaseAudioContext::BaseAudioContext(Document& document, const AudioContextOptions& contextOptions)
+BaseAudioContext::BaseAudioContext(Document& document, IsLegacyWebKitAudioContext isLegacyWebKitAudioContext, const AudioContextOptions& contextOptions)
: ActiveDOMObject(document)
#if !RELEASE_LOG_DISABLED
, m_logger(document.logger())
@@ -125,6 +125,7 @@
, m_logIdentifier(uniqueLogIdentifier())
#endif
, m_worklet(AudioWorklet::create(*this))
+ , m_listener(isLegacyWebKitAudioContext == IsLegacyWebKitAudioContext::Yes ? Ref<AudioListener>(WebKitAudioListener::create(*this)) : AudioListener::create(*this))
{
// According to spec AudioContext must die only after page navigate.
// Lets mark it as ActiveDOMObject with pending activity and unmark it in clear method.
@@ -146,7 +147,7 @@
}
// Constructor for offline (non-realtime) rendering.
-BaseAudioContext::BaseAudioContext(Document& document, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget)
+BaseAudioContext::BaseAudioContext(Document& document, IsLegacyWebKitAudioContext isLegacyWebKitAudioContext, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget)
: ActiveDOMObject(document)
#if !RELEASE_LOG_DISABLED
, m_logger(document.logger())
@@ -155,6 +156,7 @@
, m_worklet(AudioWorklet::create(*this))
, m_isOfflineContext(true)
, m_renderTarget(WTFMove(renderTarget))
+ , m_listener(isLegacyWebKitAudioContext == IsLegacyWebKitAudioContext::Yes ? Ref<AudioListener>(WebKitAudioListener::create(*this)) : AudioListener::create(*this))
{
FFTFrame::initialize();
@@ -365,13 +367,7 @@
AudioListener& WebCore::BaseAudioContext::listener()
{
- if (!m_listener) {
- if (isWebKitAudioContext())
- m_listener = WebKitAudioListener::create(*this);
- else
- m_listener = AudioListener::create(*this);
- }
- return *m_listener;
+ return m_listener;
}
ExceptionOr<Ref<AudioBufferSourceNode>> BaseAudioContext::createBufferSource()
Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h 2021-03-18 22:53:51 UTC (rev 274679)
@@ -291,8 +291,9 @@
const HashMap<String, Vector<AudioParamDescriptor>>& parameterDescriptorMap() const { return m_parameterDescriptorMap; }
protected:
- explicit BaseAudioContext(Document&, const AudioContextOptions& = { });
- BaseAudioContext(Document&, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget);
+ enum class IsLegacyWebKitAudioContext : bool { No, Yes };
+ explicit BaseAudioContext(Document&, IsLegacyWebKitAudioContext, const AudioContextOptions& = { });
+ BaseAudioContext(Document&, IsLegacyWebKitAudioContext, unsigned numberOfChannels, float sampleRate, RefPtr<AudioBuffer>&& renderTarget);
void clearPendingActivity();
void makePendingActivity();
@@ -383,7 +384,7 @@
RefPtr<AudioBuffer> m_renderTarget;
RefPtr<AudioDestinationNode> m_destinationNode;
- RefPtr<AudioListener> m_listener;
+ Ref<AudioListener> m_listener;
unsigned m_connectionCount { 0 };
Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp 2021-03-18 22:53:51 UTC (rev 274679)
@@ -39,7 +39,7 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(OfflineAudioContext);
inline OfflineAudioContext::OfflineAudioContext(Document& document, unsigned numberOfChannels, unsigned length, float sampleRate, RefPtr<AudioBuffer>&& renderTarget)
- : BaseAudioContext(document, numberOfChannels, sampleRate, WTFMove(renderTarget))
+ : BaseAudioContext(document, IsLegacyWebKitAudioContext::No, numberOfChannels, sampleRate, WTFMove(renderTarget))
, m_length(length)
{
}
Modified: trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp (274678 => 274679)
--- trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp 2021-03-18 22:52:48 UTC (rev 274678)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp 2021-03-18 22:53:51 UTC (rev 274679)
@@ -79,13 +79,13 @@
// Constructor for rendering to the audio hardware.
WebKitAudioContext::WebKitAudioContext(Document& document)
- : AudioContext(document)
+ : AudioContext(document, IsLegacyWebKitAudioContext::Yes)
{
}
// Constructor for offline (non-realtime) rendering.
WebKitAudioContext::WebKitAudioContext(Document& document, float sampleRate, Ref<AudioBuffer>&& renderTarget)
- : AudioContext(document, renderTarget->numberOfChannels(), sampleRate, WTFMove(renderTarget))
+ : AudioContext(document, IsLegacyWebKitAudioContext::Yes, renderTarget->numberOfChannels(), sampleRate, WTFMove(renderTarget))
{
}