⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267505 in webkit


Ignore:
Timestamp:
Sep 23, 2020, 4:06:16 PM (6 years ago)
Author:
Chris Dumez
Message:

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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r267504 r267505  
     12020-09-23  Chris Dumez  <cdumez@apple.com>
     2
     3        Use less explicit ref() / deref() calls in WebAudio code
     4        https://bugs.webkit.org/show_bug.cgi?id=216894
     5
     6        Reviewed by Darin Adler.
     7
     8        * Modules/webaudio/BaseAudioContext.cpp:
     9        (WebCore::BaseAudioContext::clearPendingActivity):
     10        (WebCore::BaseAudioContext::makePendingActivity):
     11        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
     12        (WebCore::MediaElementAudioSourceNode::setFormat):
     13        (WebCore::MediaElementAudioSourceNode::process):
     14        * Modules/webaudio/MediaElementAudioSourceNode.h:
     15        * Modules/webaudio/OfflineAudioDestinationNode.cpp:
     16        (WebCore::OfflineAudioDestinationNode::startRendering):
     17        * html/HTMLMediaElement.cpp:
     18        (WebCore::HTMLMediaElement::mediaEngineWasUpdated):
     19        (WebCore::HTMLMediaElement::createMediaPlayer):
     20
    1212020-09-23  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp

    r267147 r267505  
    13041304void BaseAudioContext::clearPendingActivity()
    13051305{
     1306    m_pendingActivity = nullptr;
     1307}
     1308
     1309void BaseAudioContext::makePendingActivity()
     1310{
    13061311    if (!m_pendingActivity)
    1307         return;
    1308     m_pendingActivity = nullptr;
    1309     // FIXME: Remove this specific deref() and ref() call in makePendingActivity().
    1310     deref();
    1311 }
    1312 
    1313 void BaseAudioContext::makePendingActivity()
    1314 {
    1315     if (m_pendingActivity)
    1316         return;
    1317     m_pendingActivity = ActiveDOMObject::makePendingActivity(*this);
    1318     ref();
     1312        m_pendingActivity = ActiveDOMObject::makePendingActivity(*this);
    13191313}
    13201314
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp

    r265375 r267505  
    8686void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourceSampleRate)
    8787{
     88    auto protectedThis = makeRef(*this);
    8889    m_muted = wouldTaintOrigin();
    8990
     
    101102
    102103        // Synchronize with process().
    103         auto locker = holdLock(*this);
     104        auto locker = holdLock(m_processLock);
    104105
    105106        if (sourceSampleRate != sampleRate()) {
     
    147148    // If we fail to acquire the lock then the HTMLMediaElement must be in the middle of
    148149    // reconfiguring its playback engine, so we output silence in this case.
    149     std::unique_lock<Lock> lock(m_processMutex, std::try_to_lock);
     150    std::unique_lock<Lock> lock(m_processLock, std::try_to_lock);
    150151    if (!lock.owns_lock()) {
    151152        // We failed to acquire the lock.
     
    178179}
    179180
    180 void MediaElementAudioSourceNode::lock()
    181 {
    182     ref();
    183     m_processMutex.lock();
    184 }
    185 
    186 void MediaElementAudioSourceNode::unlock()
    187 {
    188     m_processMutex.unlock();
    189     deref();
    190 }
    191 
    192181} // namespace WebCore
    193182
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h

    r266417 r267505  
    5656    void setFormat(size_t numberOfChannels, float sampleRate) override;
    5757
    58     void lock();
    59     void unlock();
     58    Lock& processLock() { return m_processLock; }
    6059
    6160private:
     
    7271
    7372    Ref<HTMLMediaElement> m_mediaElement;
    74     Lock m_processMutex;
     73    Lock m_processLock;
    7574
    7675    unsigned m_sourceNumberOfChannels { 0 };
  • trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp

    r267147 r267505  
    9696
    9797    m_startedRendering = true;
    98     ref();
     98    auto protectedThis = makeRef(*this);
     99
    99100    // FIXME: Should we call lazyInitialize here?
    100101    // FIXME: We should probably limit the number of threads we create for offline audio.
    101     m_renderThread = Thread::create("offline renderer", [this] {
     102    m_renderThread = Thread::create("offline renderer", [this, protectedThis = WTFMove(protectedThis)]() mutable {
    102103        auto result = offlineRender();
    103         callOnMainThread([this, result, currentSampleFrame = m_currentSampleFrame] {
     104        callOnMainThread([this, result, currentSampleFrame = m_currentSampleFrame, protectedThis = WTFMove(protectedThis)] {
    104105            m_startedRendering = false;
    105106            switch (result) {
     
    114115                break;
    115116            }
    116             deref();
    117117        });
    118118    }, ThreadType::Audio);
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r267472 r267505  
    50355035#if ENABLE(WEB_AUDIO)
    50365036    if (m_audioSourceNode && audioSourceProvider()) {
    5037         m_audioSourceNode->lock();
     5037        auto locker = holdLock(m_audioSourceNode->processLock());
    50385038        audioSourceProvider()->setClient(m_audioSourceNode);
    5039         m_audioSourceNode->unlock();
    50405039    }
    50415040#endif
     
    65846583
    65856584#if ENABLE(WEB_AUDIO)
    6586     if (m_audioSourceNode)
    6587         m_audioSourceNode->lock();
     6585    auto protectedAudioSourceNode = makeRefPtr(m_audioSourceNode);
     6586    Locker<Lock> audioSourceNodeLocker(m_audioSourceNode ? &m_audioSourceNode->processLock() : nullptr);
    65886587#endif
    65896588
     
    66106609        if (audioSourceProvider())
    66116610            audioSourceProvider()->setClient(m_audioSourceNode);
    6612 
    6613         m_audioSourceNode->unlock();
    66146611    }
    66156612#endif
Note: See TracChangeset for help on using the changeset viewer.