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 "platform/wtf/PtrUtil.h" | 9 #include "platform/wtf/PtrUtil.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Suppress the warning log if over/underflow happens more than 100 times. | 15 // Suppress the warning log if over/underflow happens more than 100 times. |
16 const unsigned kMaxMessagesToLog = 100; | 16 const unsigned kMaxMessagesToLog = 100; |
17 } | 17 } // namespace |
18 | 18 |
19 const size_t PushPullFIFO::kMaxFIFOLength = 65536; | 19 const size_t PushPullFIFO::kMaxFIFOLength = 65536; |
20 | 20 |
21 PushPullFIFO::PushPullFIFO(unsigned number_of_channels, size_t fifo_length) | 21 PushPullFIFO::PushPullFIFO(unsigned number_of_channels, size_t fifo_length) |
22 : fifo_length_(fifo_length) { | 22 : fifo_length_(fifo_length) { |
23 CHECK_LE(fifo_length_, kMaxFIFOLength); | 23 CHECK_LE(fifo_length_, kMaxFIFOLength); |
24 fifo_bus_ = AudioBus::Create(number_of_channels, fifo_length_); | 24 fifo_bus_ = AudioBus::Create(number_of_channels, fifo_length_); |
25 } | 25 } |
26 | 26 |
27 PushPullFIFO::~PushPullFIFO() {} | 27 PushPullFIFO::~PushPullFIFO() {} |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 // Update the number of frames in FIFO. | 162 // Update the number of frames in FIFO. |
163 frames_available_ -= frames_to_fill; | 163 frames_available_ -= frames_to_fill; |
164 DCHECK_EQ((index_read_ + frames_available_) % fifo_length_, index_write_); | 164 DCHECK_EQ((index_read_ + frames_available_) % fifo_length_, index_write_); |
165 | 165 |
166 // |frames_requested > frames_available_| means the frames in FIFO is not | 166 // |frames_requested > frames_available_| means the frames in FIFO is not |
167 // enough to fulfill the requested frames from the audio device. | 167 // enough to fulfill the requested frames from the audio device. |
168 return frames_requested > frames_available_ | 168 return frames_requested > frames_available_ |
169 ? frames_requested - frames_available_ | 169 ? frames_requested - frames_available_ |
170 : 0; | 170 : 0; |
171 } | 171 } |
172 | 172 |
173 const PushPullFIFOStateForTest PushPullFIFO::GetStateForTest() const { | 173 const PushPullFIFOStateForTest PushPullFIFO::GetStateForTest() const { |
174 return {length(), NumberOfChannels(), frames_available_, index_read_, | 174 return {length(), NumberOfChannels(), frames_available_, index_read_, |
175 index_write_, overflow_count_, underflow_count_}; | 175 index_write_, overflow_count_, underflow_count_}; |
176 } | 176 } |
177 | 177 |
178 } // namespace blink | 178 } // namespace blink |
OLD | NEW |