Changeset 278289 in webkit
- Timestamp:
- May 31, 2021, 5:09:42 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
Modules/webaudio/ConvolverNode.cpp (modified) (6 diffs)
-
Modules/webaudio/ConvolverNode.h (modified) (3 diffs)
-
Modules/webaudio/ConvolverNode.idl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r278288 r278289 1 2021-05-31 Chris Dumez <cdumez@apple.com> 2 3 Fix thread safety issues in ConvolverNode 4 https://bugs.webkit.org/show_bug.cgi?id=226449 5 6 Reviewed by Darin Adler. 7 8 Adopt thread safety annotations in ConvolverNode and fix bugs found by clang. 9 In particular, the following issues were found and fixed: 10 - tailTime() / latencyTime() were accessing m_reverb on the audio thread without 11 locking even though m_reverb gets modified on the main thread. 12 - checkNumberOfChannelsForInput() was accessing m_buffer on the audio thread 13 without locking even though m_buffer gets modified on the main thread. 14 15 * Modules/webaudio/ConvolverNode.cpp: 16 (WebCore::ConvolverNode::create): 17 (WebCore::ConvolverNode::setBufferForBindings): 18 (WebCore::ConvolverNode::setNormalizeForBindings): 19 (WebCore::ConvolverNode::tailTime const): 20 (WebCore::ConvolverNode::latencyTime const): 21 (WebCore::ConvolverNode::checkNumberOfChannelsForInput): 22 * Modules/webaudio/ConvolverNode.h: 23 * Modules/webaudio/ConvolverNode.idl: 24 1 25 2021-05-31 Chris Dumez <cdumez@apple.com> 2 26 -
trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp
r277932 r278289 64 64 return result.releaseException(); 65 65 66 node->setNormalize (!options.disableNormalization);67 68 result = node->setBuffer (WTFMove(options.buffer));66 node->setNormalizeForBindings(!options.disableNormalization); 67 68 result = node->setBufferForBindings(WTFMove(options.buffer)); 69 69 if (result.hasException()) 70 70 return result.releaseException(); … … 111 111 } 112 112 113 ExceptionOr<void> ConvolverNode::setBuffer (RefPtr<AudioBuffer>&& buffer)113 ExceptionOr<void> ConvolverNode::setBufferForBindings(RefPtr<AudioBuffer>&& buffer) 114 114 { 115 115 ASSERT(isMainThread()); … … 161 161 } 162 162 163 AudioBuffer* ConvolverNode::buffer ()163 AudioBuffer* ConvolverNode::bufferForBindings() WTF_IGNORES_THREAD_SAFETY_ANALYSIS 164 164 { 165 165 ASSERT(isMainThread()); … … 167 167 } 168 168 169 void ConvolverNode::setNormalizeForBindings(bool normalize) 170 { 171 ASSERT(isMainThread()); 172 m_normalize = normalize; 173 } 174 169 175 double ConvolverNode::tailTime() const 170 176 { 177 ASSERT(context().isAudioThread()); 178 if (!m_processLock.tryLock()) 179 return std::numeric_limits<double>::infinity(); 180 Locker locker { AdoptLock, m_processLock }; 171 181 return m_reverb ? m_reverb->impulseResponseLength() / static_cast<double>(sampleRate()) : 0; 172 182 } … … 174 184 double ConvolverNode::latencyTime() const 175 185 { 186 ASSERT(context().isAudioThread()); 187 if (!m_processLock.tryLock()) 188 return std::numeric_limits<double>::infinity(); 189 Locker locker { AdoptLock, m_processLock }; 176 190 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sampleRate()) : 0; 177 191 } … … 200 214 { 201 215 ASSERT(context().isAudioThread() && context().isGraphOwner()); 202 203 if (m_buffer) { 204 unsigned numberOfOutputChannels = computeNumberOfOutputChannels(input->numberOfChannels(), m_buffer->numberOfChannels()); 216 std::optional<unsigned> numberOfBufferChannels; 217 if (m_processLock.tryLock()) { 218 Locker locker { AdoptLock, m_processLock }; 219 if (m_buffer) 220 numberOfBufferChannels = m_buffer->numberOfChannels(); 221 } 222 223 if (numberOfBufferChannels) { 224 unsigned numberOfOutputChannels = computeNumberOfOutputChannels(input->numberOfChannels(), *numberOfBufferChannels); 205 225 206 226 if (isInitialized() && numberOfOutputChannels != output(0)->numberOfChannels()) { -
trunk/Source/WebCore/Modules/webaudio/ConvolverNode.h
r268001 r278289 42 42 virtual ~ConvolverNode(); 43 43 44 ExceptionOr<void> setBuffer (RefPtr<AudioBuffer>&&);45 AudioBuffer* buffer ();44 ExceptionOr<void> setBufferForBindings(RefPtr<AudioBuffer>&&); 45 AudioBuffer* bufferForBindings(); // Only safe to call on the main thread. 46 46 47 bool normalize () const {return m_normalize; }48 void setNormalize (bool normalize) { m_normalize = normalize; }47 bool normalizeForBindings() const WTF_IGNORES_THREAD_SAFETY_ANALYSIS { ASSERT(isMainThread()); return m_normalize; } 48 void setNormalizeForBindings(bool); 49 49 50 50 ExceptionOr<void> setChannelCount(unsigned) final; … … 61 61 void checkNumberOfChannelsForInput(AudioNodeInput*) final; 62 62 63 std::unique_ptr<Reverb> m_reverb ;64 RefPtr<AudioBuffer> m_buffer ;63 std::unique_ptr<Reverb> m_reverb WTF_GUARDED_BY_LOCK(m_processLock); // Only modified on the main thread but accessed on the audio thread. 64 RefPtr<AudioBuffer> m_buffer WTF_GUARDED_BY_LOCK(m_processLock); // Only modified on the main thread but accessed on the audio thread. 65 65 66 66 // This synchronizes dynamic changes to the convolution impulse response with process(). … … 68 68 69 69 // Normalize the impulse response or not. 70 bool m_normalize { true }; 70 bool m_normalize { true }; // Only used on the main thread. 71 71 }; 72 72 -
trunk/Source/WebCore/Modules/webaudio/ConvolverNode.idl
r276715 r278289 32 32 [EnabledBySetting=WebAudio] constructor (BaseAudioContext context, optional ConvolverOptions options); 33 33 34 attribute AudioBuffer? buffer;35 attribute boolean normalize;34 [ImplementedAs=bufferForBindings] attribute AudioBuffer? buffer; 35 [ImplementedAs=normalizeForBindings] attribute boolean normalize; 36 36 };
Note:
See TracChangeset
for help on using the changeset viewer.