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

Changeset 278306 in webkit


Ignore:
Timestamp:
Jun 1, 2021, 7:56:04 AM (5 years ago)
Author:
Chris Dumez
Message:

Fix thread safety issues in MediaElementAudioSourceNode
https://bugs.webkit.org/show_bug.cgi?id=226475

Reviewed by Youenn Fablet.

Adopt thread safety analysis annotations in MediaElementAudioSourceNode and fix
bugs found by clang. In particular, the following issues were fixed:

  • setFormat() was modifying m_muted / m_sourceNumberOfChannels / m_sourceSampleRate on the main thread without locking, even though those data members are accessed from the rendering thread.
  • process() was accessing m_muted / m_sourceNumberOfChannels / m_sourceSampleRate on the rendering thread *before* locking.
  • Modules/webaudio/MediaElementAudioSourceNode.cpp:

(WebCore::MediaElementAudioSourceNode::setFormat):
(WebCore::MediaElementAudioSourceNode::process):

  • Modules/webaudio/MediaElementAudioSourceNode.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278305 r278306  
     12021-06-01  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix thread safety issues in MediaElementAudioSourceNode
     4        https://bugs.webkit.org/show_bug.cgi?id=226475
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Adopt thread safety analysis annotations in MediaElementAudioSourceNode and fix
     9        bugs found by clang. In particular, the following issues were fixed:
     10        - setFormat() was modifying m_muted / m_sourceNumberOfChannels / m_sourceSampleRate
     11          on the main thread without locking, even though those data members are accessed
     12          from the rendering thread.
     13        - process() was accessing  m_muted / m_sourceNumberOfChannels / m_sourceSampleRate
     14          on the rendering thread *before* locking.
     15
     16        * Modules/webaudio/MediaElementAudioSourceNode.cpp:
     17        (WebCore::MediaElementAudioSourceNode::setFormat):
     18        (WebCore::MediaElementAudioSourceNode::process):
     19        * Modules/webaudio/MediaElementAudioSourceNode.h:
     20
    1212021-06-01  Antti Koivisto  <antti@apple.com>
    222
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp

    r277932 r278306  
    8484{
    8585    auto protectedThis = makeRef(*this);
     86
     87    // Synchronize with process().
     88    Locker locker { m_processLock };
     89
    8690    m_muted = wouldTaintOrigin();
    8791
     
    97101        m_sourceNumberOfChannels = numberOfChannels;
    98102        m_sourceSampleRate = sourceSampleRate;
    99 
    100         // Synchronize with process().
    101         Locker locker { m_processLock };
    102103
    103104        if (sourceSampleRate != sampleRate()) {
     
    151152    AudioBus* outputBus = output(0)->bus();
    152153
    153     if (m_muted || !m_sourceNumberOfChannels || !m_sourceSampleRate) {
    154         outputBus->zero();
    155         return;
    156     }
    157 
    158154    // Use tryLock() to avoid contention in the real-time audio thread.
    159155    // If we fail to acquire the lock then the HTMLMediaElement must be in the middle of
     
    166162
    167163    Locker locker { AdoptLock, m_processLock };
    168     if (m_sourceNumberOfChannels != outputBus->numberOfChannels()) {
     164
     165    if (m_muted || !m_sourceNumberOfChannels || !m_sourceSampleRate || m_sourceNumberOfChannels != outputBus->numberOfChannels()) {
    169166        outputBus->zero();
    170167        return;
  • trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h

    r278077 r278306  
    7373    Lock m_processLock;
    7474
    75     unsigned m_sourceNumberOfChannels { 0 };
    76     double m_sourceSampleRate { 0 };
    77     bool m_muted { false };
     75    unsigned m_sourceNumberOfChannels WTF_GUARDED_BY_LOCK(m_processLock) { 0 };
     76    double m_sourceSampleRate WTF_GUARDED_BY_LOCK(m_processLock) { 0 };
     77    bool m_muted WTF_GUARDED_BY_LOCK(m_processLock) { false };
    7878
    79     std::unique_ptr<MultiChannelResampler> m_multiChannelResampler;
     79    std::unique_ptr<MultiChannelResampler> m_multiChannelResampler WTF_GUARDED_BY_LOCK(m_processLock);
    8080};
    8181
Note: See TracChangeset for help on using the changeset viewer.