diff options
author | Moonchild <moonchild@palemoon.org> | 2021-01-26 14:55:48 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-01-26 14:55:48 +0000 |
commit | 2836e514661df0ffd816cf957ecc35c968377fbe (patch) | |
tree | eee419d6ad543823ddb94b0f81d069db95a548f1 | |
parent | 3661ecee115e4810b9842a0a8e2f314434a841aa (diff) | |
download | uxp-2836e514661df0ffd816cf957ecc35c968377fbe.tar.gz |
[webaudio] Fix up ReverbInputBuffer's writeIndex.
-rw-r--r-- | dom/media/webaudio/blink/ReverbInputBuffer.cpp | 21 | ||||
-rw-r--r-- | dom/media/webaudio/blink/ReverbInputBuffer.h | 3 |
2 files changed, 13 insertions, 11 deletions
diff --git a/dom/media/webaudio/blink/ReverbInputBuffer.cpp b/dom/media/webaudio/blink/ReverbInputBuffer.cpp index 8221f8151d..6b8e642d27 100644 --- a/dom/media/webaudio/blink/ReverbInputBuffer.cpp +++ b/dom/media/webaudio/blink/ReverbInputBuffer.cpp @@ -42,19 +42,20 @@ ReverbInputBuffer::ReverbInputBuffer(size_t length) void ReverbInputBuffer::write(const float* sourceP, size_t numberOfFrames) { - size_t bufferLength = m_buffer.Length(); - bool isCopySafe = m_writeIndex + numberOfFrames <= bufferLength; - MOZ_ASSERT(isCopySafe); - if (!isCopySafe) - return; + // m_writeIndex is atomic and checked by other threads, so only touch + // it at the start and end. + size_t index = m_writeIndex; + + size_t bufferLength = m_buffer.Length(); + size_t newIndex = index + numberOfFrames; - memcpy(m_buffer.Elements() + m_writeIndex, sourceP, sizeof(float) * numberOfFrames); + MOZ_RELEASE_ASSERT(newIndex <= bufferLength); - m_writeIndex += numberOfFrames; - MOZ_ASSERT(m_writeIndex <= bufferLength); + memcpy(m_buffer.Elements() + index, sourceP, sizeof(float) * numberOfFrames); - if (m_writeIndex >= bufferLength) - m_writeIndex = 0; + if (newIndex >= bufferLength) { + m_writeIndex = 0; + } } float* ReverbInputBuffer::directReadFrom(int* readIndex, size_t numberOfFrames) diff --git a/dom/media/webaudio/blink/ReverbInputBuffer.h b/dom/media/webaudio/blink/ReverbInputBuffer.h index 906021c0d1..f51aa30916 100644 --- a/dom/media/webaudio/blink/ReverbInputBuffer.h +++ b/dom/media/webaudio/blink/ReverbInputBuffer.h @@ -30,6 +30,7 @@ #define ReverbInputBuffer_h #include "nsTArray.h" +#include "mozilla/Atomics.h" #include "mozilla/MemoryReporting.h" namespace WebCore { @@ -63,7 +64,7 @@ public: private: nsTArray<float> m_buffer; - size_t m_writeIndex; + mozilla::Atomic<size_t, mozilla::ReleaseAcquire> m_writeIndex; }; } // namespace WebCore |