Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/audio/PushPullFIFO.h" | 5 #include "platform/audio/PushPullFIFO.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "platform/audio/AudioUtilities.h" | 8 #include "platform/audio/AudioUtilities.h" |
| 9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 m_underflowCount(0) { | 27 m_underflowCount(0) { |
| 28 CHECK_LE(m_fifoLength, kMaxFIFOLength); | 28 CHECK_LE(m_fifoLength, kMaxFIFOLength); |
| 29 m_fifoBus = AudioBus::create(numberOfChannels, m_fifoLength); | 29 m_fifoBus = AudioBus::create(numberOfChannels, m_fifoLength); |
| 30 } | 30 } |
| 31 | 31 |
| 32 PushPullFIFO::~PushPullFIFO() {} | 32 PushPullFIFO::~PushPullFIFO() {} |
| 33 | 33 |
| 34 // Push the data from |inputBus| to FIFO. The size of push is determined by | 34 // Push the data from |inputBus| to FIFO. The size of push is determined by |
| 35 // the length of |inputBus|. | 35 // the length of |inputBus|. |
| 36 void PushPullFIFO::push(const AudioBus* inputBus) { | 36 void PushPullFIFO::push(const AudioBus* inputBus) { |
| 37 MutexLocker lock(m_threadMutex); | |
| 38 | |
| 37 CHECK(inputBus); | 39 CHECK(inputBus); |
| 38 CHECK_EQ(inputBus->length(), AudioUtilities::kRenderQuantumFrames); | 40 CHECK_EQ(inputBus->length(), AudioUtilities::kRenderQuantumFrames); |
| 39 SECURITY_CHECK(inputBus->length() <= m_fifoLength); | 41 SECURITY_CHECK(inputBus->length() <= m_fifoLength); |
| 40 SECURITY_CHECK(m_indexWrite < m_fifoLength); | 42 SECURITY_CHECK(m_indexWrite < m_fifoLength); |
| 41 | 43 |
| 42 const size_t inputBusLength = inputBus->length(); | 44 const size_t inputBusLength = inputBus->length(); |
| 43 const size_t remainder = m_fifoLength - m_indexWrite; | 45 const size_t remainder = m_fifoLength - m_indexWrite; |
| 44 | 46 |
| 45 for (unsigned i = 0; i < m_fifoBus->numberOfChannels(); ++i) { | 47 for (unsigned i = 0; i < m_fifoBus->numberOfChannels(); ++i) { |
| 46 float* fifoBusChannel = m_fifoBus->channel(i)->mutableData(); | 48 float* fifoBusChannel = m_fifoBus->channel(i)->mutableData(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 76 | 78 |
| 77 // Update the number of frames available in FIFO. | 79 // Update the number of frames available in FIFO. |
| 78 m_framesAvailable = | 80 m_framesAvailable = |
| 79 std::min(m_framesAvailable + inputBusLength, m_fifoLength); | 81 std::min(m_framesAvailable + inputBusLength, m_fifoLength); |
| 80 DCHECK_EQ((m_indexRead + m_framesAvailable) % m_fifoLength, m_indexWrite); | 82 DCHECK_EQ((m_indexRead + m_framesAvailable) % m_fifoLength, m_indexWrite); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Pull the data out of FIFO to |outputBus|. If remaining frame in the FIFO | 85 // Pull the data out of FIFO to |outputBus|. If remaining frame in the FIFO |
| 84 // is less than the frames to pull, provides remaining frame plus the silence. | 86 // is less than the frames to pull, provides remaining frame plus the silence. |
| 85 void PushPullFIFO::pull(AudioBus* outputBus, size_t framesRequested) { | 87 void PushPullFIFO::pull(AudioBus* outputBus, size_t framesRequested) { |
| 88 MutexLocker lock(m_threadMutex); | |
| 89 | |
| 86 #if OS(ANDROID) | 90 #if OS(ANDROID) |
| 87 if (!outputBus) { | 91 if (!outputBus) { |
| 88 // Log when outputBus or FIFO object is invalid. (crbug.com/692423) | 92 // Log when outputBus or FIFO object is invalid. (crbug.com/692423) |
| 89 LOG(WARNING) << "[WebAudio/PushPullFIFO::pull <" << static_cast<void*>(this) | 93 LOG(WARNING) << "[WebAudio/PushPullFIFO::pull <" << static_cast<void*>(this) |
| 90 << ">] |outputBus| is invalid."; | 94 << ">] |outputBus| is invalid."; |
| 91 // Silently return to avoid crash. | 95 // Silently return to avoid crash. |
| 92 return; | 96 return; |
| 93 } | 97 } |
| 94 | 98 |
| 95 // The following checks are in place to catch the inexplicable crash. | 99 // The following checks are in place to catch the inexplicable crash. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 << ", requestedFrames=" << framesRequested | 161 << ", requestedFrames=" << framesRequested |
| 158 << ", fifoLength=" << m_fifoLength << ")"; | 162 << ", fifoLength=" << m_fifoLength << ")"; |
| 159 } | 163 } |
| 160 } | 164 } |
| 161 | 165 |
| 162 // Update the number of frames in FIFO. | 166 // Update the number of frames in FIFO. |
| 163 m_framesAvailable -= framesToFill; | 167 m_framesAvailable -= framesToFill; |
| 164 DCHECK_EQ((m_indexRead + m_framesAvailable) % m_fifoLength, m_indexWrite); | 168 DCHECK_EQ((m_indexRead + m_framesAvailable) % m_fifoLength, m_indexWrite); |
| 165 } | 169 } |
| 166 | 170 |
| 171 size_t PushPullFIFO::framesAvailable() const { | |
| 172 MutexLocker lock(m_threadMutex); | |
| 173 return m_framesAvailable; | |
|
o1ka
2017/03/30 13:17:05
This is correct but unfortunate to have a lock her
hongchan
2017/03/30 18:36:00
Acknowledged.
| |
| 174 } | |
| 175 | |
| 176 AudioBus* PushPullFIFO::getFIFOBusForTest() const { | |
| 177 MutexLocker lock(m_threadMutex); | |
| 178 return m_fifoBus.get(); | |
| 179 } | |
| 180 | |
| 167 const PushPullFIFOStateForTest PushPullFIFO::getStateForTest() const { | 181 const PushPullFIFOStateForTest PushPullFIFO::getStateForTest() const { |
| 182 MutexLocker lock(m_threadMutex); | |
| 168 return {length(), numberOfChannels(), framesAvailable(), m_indexRead, | 183 return {length(), numberOfChannels(), framesAvailable(), m_indexRead, |
| 169 m_indexWrite, m_overflowCount, m_underflowCount}; | 184 m_indexWrite, m_overflowCount, m_underflowCount}; |
| 170 } | 185 } |
| 171 | 186 |
| 172 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |