Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp

Issue 2777903005: Add WebThread in AudioDestination to support AudioWorkletThread (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 locker(m_lock);
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
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 locker(m_lock);
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
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
167 const PushPullFIFOStateForTest PushPullFIFO::getStateForTest() const { 171 const PushPullFIFOStateForTest PushPullFIFO::getStateForTest() const {
o1ka 2017/03/29 09:05:11 Not thread safe any more
hongchan 2017/03/29 19:39:58 Added a lock.
168 return {length(), numberOfChannels(), framesAvailable(), m_indexRead, 172 return {length(), numberOfChannels(), framesAvailable(), m_indexRead,
169 m_indexWrite, m_overflowCount, m_underflowCount}; 173 m_indexWrite, m_overflowCount, m_underflowCount};
170 } 174 }
171 175
172 } // namespace blink 176 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698