Diff
Modified: trunk/Source/WebCore/ChangeLog (267504 => 267505)
--- trunk/Source/WebCore/ChangeLog 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/ChangeLog 2020-09-23 23:06:16 UTC (rev 267505)
@@ -1,5 +1,25 @@
2020-09-23 Chris Dumez <[email protected]>
+ Use less explicit ref() / deref() calls in WebAudio code
+ https://bugs.webkit.org/show_bug.cgi?id=216894
+
+ Reviewed by Darin Adler.
+
+ * Modules/webaudio/BaseAudioContext.cpp:
+ (WebCore::BaseAudioContext::clearPendingActivity):
+ (WebCore::BaseAudioContext::makePendingActivity):
+ * Modules/webaudio/MediaElementAudioSourceNode.cpp:
+ (WebCore::MediaElementAudioSourceNode::setFormat):
+ (WebCore::MediaElementAudioSourceNode::process):
+ * Modules/webaudio/MediaElementAudioSourceNode.h:
+ * Modules/webaudio/OfflineAudioDestinationNode.cpp:
+ (WebCore::OfflineAudioDestinationNode::startRendering):
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::mediaEngineWasUpdated):
+ (WebCore::HTMLMediaElement::createMediaPlayer):
+
+2020-09-23 Chris Dumez <[email protected]>
+
Turn off the legacy prefixed WebAudio API
https://bugs.webkit.org/show_bug.cgi?id=216886
Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (267504 => 267505)
--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp 2020-09-23 23:06:16 UTC (rev 267505)
@@ -1303,19 +1303,13 @@
void BaseAudioContext::clearPendingActivity()
{
- if (!m_pendingActivity)
- return;
m_pendingActivity = nullptr;
- // FIXME: Remove this specific deref() and ref() call in makePendingActivity().
- deref();
}
void BaseAudioContext::makePendingActivity()
{
- if (m_pendingActivity)
- return;
- m_pendingActivity = ActiveDOMObject::makePendingActivity(*this);
- ref();
+ if (!m_pendingActivity)
+ m_pendingActivity = ActiveDOMObject::makePendingActivity(*this);
}
PeriodicWave& BaseAudioContext::periodicWave(OscillatorType type)
Modified: trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp (267504 => 267505)
--- trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp 2020-09-23 23:06:16 UTC (rev 267505)
@@ -85,6 +85,7 @@
void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourceSampleRate)
{
+ auto protectedThis = makeRef(*this);
m_muted = wouldTaintOrigin();
if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_sourceSampleRate) {
@@ -100,7 +101,7 @@
m_sourceSampleRate = sourceSampleRate;
// Synchronize with process().
- auto locker = holdLock(*this);
+ auto locker = holdLock(m_processLock);
if (sourceSampleRate != sampleRate()) {
double scaleFactor = sourceSampleRate / sampleRate();
@@ -146,7 +147,7 @@
// Use a std::try_to_lock to avoid contention in the real-time audio thread.
// If we fail to acquire the lock then the HTMLMediaElement must be in the middle of
// reconfiguring its playback engine, so we output silence in this case.
- std::unique_lock<Lock> lock(m_processMutex, std::try_to_lock);
+ std::unique_lock<Lock> lock(m_processLock, std::try_to_lock);
if (!lock.owns_lock()) {
// We failed to acquire the lock.
outputBus->zero();
@@ -177,18 +178,6 @@
{
}
-void MediaElementAudioSourceNode::lock()
-{
- ref();
- m_processMutex.lock();
-}
-
-void MediaElementAudioSourceNode::unlock()
-{
- m_processMutex.unlock();
- deref();
-}
-
} // namespace WebCore
#endif // ENABLE(WEB_AUDIO)
Modified: trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h (267504 => 267505)
--- trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h 2020-09-23 23:06:16 UTC (rev 267505)
@@ -55,8 +55,7 @@
// AudioSourceProviderClient
void setFormat(size_t numberOfChannels, float sampleRate) override;
- void lock();
- void unlock();
+ Lock& processLock() { return m_processLock; }
private:
MediaElementAudioSourceNode(BaseAudioContext&, Ref<HTMLMediaElement>&&);
@@ -71,7 +70,7 @@
bool wouldTaintOrigin();
Ref<HTMLMediaElement> m_mediaElement;
- Lock m_processMutex;
+ Lock m_processLock;
unsigned m_sourceNumberOfChannels { 0 };
double m_sourceSampleRate { 0 };
Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp (267504 => 267505)
--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp 2020-09-23 23:06:16 UTC (rev 267505)
@@ -95,12 +95,13 @@
return Exception { InvalidStateError, "Already started rendering"_s };
m_startedRendering = true;
- ref();
+ auto protectedThis = makeRef(*this);
+
// FIXME: Should we call lazyInitialize here?
// FIXME: We should probably limit the number of threads we create for offline audio.
- m_renderThread = Thread::create("offline renderer", [this] {
+ m_renderThread = Thread::create("offline renderer", [this, protectedThis = WTFMove(protectedThis)]() mutable {
auto result = offlineRender();
- callOnMainThread([this, result, currentSampleFrame = m_currentSampleFrame] {
+ callOnMainThread([this, result, currentSampleFrame = m_currentSampleFrame, protectedThis = WTFMove(protectedThis)] {
m_startedRendering = false;
switch (result) {
case OfflineRenderResult::Failure:
@@ -113,7 +114,6 @@
context().didSuspendRendering(currentSampleFrame);
break;
}
- deref();
});
}, ThreadType::Audio);
return { };
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (267504 => 267505)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2020-09-23 22:48:05 UTC (rev 267504)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2020-09-23 23:06:16 UTC (rev 267505)
@@ -5034,9 +5034,8 @@
#if ENABLE(WEB_AUDIO)
if (m_audioSourceNode && audioSourceProvider()) {
- m_audioSourceNode->lock();
+ auto locker = holdLock(m_audioSourceNode->processLock());
audioSourceProvider()->setClient(m_audioSourceNode);
- m_audioSourceNode->unlock();
}
#endif
@@ -6583,8 +6582,8 @@
INFO_LOG(LOGIDENTIFIER);
#if ENABLE(WEB_AUDIO)
- if (m_audioSourceNode)
- m_audioSourceNode->lock();
+ auto protectedAudioSourceNode = makeRefPtr(m_audioSourceNode);
+ Locker<Lock> audioSourceNodeLocker(m_audioSourceNode ? &m_audioSourceNode->processLock() : nullptr);
#endif
#if ENABLE(MEDIA_SOURCE)
@@ -6609,8 +6608,6 @@
// When creating the player, make sure its AudioSourceProvider knows about the MediaElementAudioSourceNode.
if (audioSourceProvider())
audioSourceProvider()->setClient(m_audioSourceNode);
-
- m_audioSourceNode->unlock();
}
#endif