Changeset 247381 in webkit


Ignore:
Timestamp:
Jul 11, 2019 9:22:36 PM (5 years ago)
Author:
youenn@apple.com
Message:

Protect CoreAudioSharedUnit::m_clients for accessing in different threads simultaneously
https://bugs.webkit.org/show_bug.cgi?id=199717

Reviewed by Eric Carlson.

Add a lock whenever accessing to m_clients.
Manual tests show that audio capture still works.

  • platform/mediastream/mac/CoreAudioCaptureSource.cpp:

(WebCore::CoreAudioSharedUnit::addClient):
(WebCore::CoreAudioSharedUnit::removeClient):
(WebCore::CoreAudioSharedUnit::forEachClient const):
(WebCore::CoreAudioSharedUnit::processMicrophoneSamples):
(WebCore::CoreAudioSharedUnit::captureFailed):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247380 r247381  
     12019-07-11  Youenn Fablet  <youenn@apple.com>
     2
     3        Protect CoreAudioSharedUnit::m_clients for accessing in different threads simultaneously
     4        https://bugs.webkit.org/show_bug.cgi?id=199717
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add a lock whenever accessing to m_clients.
     9        Manual tests show that audio capture still works.
     10
     11        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
     12        (WebCore::CoreAudioSharedUnit::addClient):
     13        (WebCore::CoreAudioSharedUnit::removeClient):
     14        (WebCore::CoreAudioSharedUnit::forEachClient const):
     15        (WebCore::CoreAudioSharedUnit::processMicrophoneSamples):
     16        (WebCore::CoreAudioSharedUnit::captureFailed):
     17
    1182019-07-11  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp

    r243033 r247381  
    129129    void captureFailed();
    130130
    131     Vector<std::reference_wrapper<CoreAudioCaptureSource>> m_clients;
     131    void forEachClient(const Function<void(CoreAudioCaptureSource&)>& apply) const;
     132
     133    HashSet<CoreAudioCaptureSource*> m_clients;
     134    mutable RecursiveLock m_clientsLock;
    132135
    133136    AudioUnit m_ioUnit { nullptr };
     
    197200void CoreAudioSharedUnit::addClient(CoreAudioCaptureSource& client)
    198201{
    199     m_clients.append(client);
     202    auto locker = holdLock(m_clientsLock);
     203    m_clients.add(&client);
    200204}
    201205
    202206void CoreAudioSharedUnit::removeClient(CoreAudioCaptureSource& client)
    203207{
    204     m_clients.removeAllMatching([&](const auto& item) {
    205         return &client == &item.get();
    206     });
     208    auto locker = holdLock(m_clientsLock);
     209    m_clients.remove(&client);
     210}
     211
     212void CoreAudioSharedUnit::forEachClient(const Function<void(CoreAudioCaptureSource&)>& apply) const
     213{
     214    Vector<CoreAudioCaptureSource*> clientsCopy;
     215    {
     216        auto locker = holdLock(m_clientsLock);
     217        clientsCopy = copyToVector(m_clients);
     218    }
     219    for (auto* client : clientsCopy) {
     220        auto locker = holdLock(m_clientsLock);
     221        // Make sure the client has not been destroyed.
     222        if (!m_clients.contains(client))
     223            continue;
     224        apply(*client);
     225    }
    207226}
    208227
     
    510529        m_microphoneSampleBuffer->applyGain(m_volume);
    511530
    512     for (CoreAudioCaptureSource& client : m_clients) {
     531    forEachClient([&](auto& client) {
    513532        if (client.isProducingData())
    514533            client.audioSamplesAvailable(MediaTime(sampleTime, m_microphoneProcFormat.sampleRate()), m_microphoneSampleBuffer->bufferList(), m_microphoneProcFormat, inNumberFrames);
    515     }
     534    });
    516535    return noErr;
    517536}
     
    657676{
    658677    RELEASE_LOG_ERROR(WebRTC, "CoreAudioSharedUnit::captureFailed - capture failed");
    659     for (CoreAudioCaptureSource& client : m_clients)
     678    forEachClient([](auto& client) {
    660679        client.captureFailed();
     680    });
    661681
    662682    m_producingCount = 0;
    663     m_clients.clear();
     683
     684    {
     685        auto locker = holdLock(m_clientsLock);
     686        m_clients.clear();
     687    }
     688
    664689    stopInternal();
    665690    cleanupAudioUnit();
Note: See TracChangeset for help on using the changeset viewer.