OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/environment.h" | 6 #include "base/environment.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 state.input_delay_ms, | 177 state.input_delay_ms, |
178 state.output_delay_ms); | 178 state.output_delay_ms); |
179 ++elements_written; | 179 ++elements_written; |
180 } | 180 } |
181 | 181 |
182 base::CloseFile(text_file); | 182 base::CloseFile(text_file); |
183 } | 183 } |
184 | 184 |
185 // AudioInputStream::AudioInputCallback. | 185 // AudioInputStream::AudioInputCallback. |
186 virtual void OnData(AudioInputStream* stream, | 186 virtual void OnData(AudioInputStream* stream, |
187 const uint8* src, uint32 size, | 187 const AudioBus* src, |
188 uint32 hardware_delay_bytes, | 188 uint32 hardware_delay_bytes, |
189 double volume) OVERRIDE { | 189 double volume) OVERRIDE { |
190 base::AutoLock lock(lock_); | 190 base::AutoLock lock(lock_); |
191 | 191 |
192 // Update three components in the AudioDelayState for this recorded | 192 // Update three components in the AudioDelayState for this recorded |
193 // audio packet. | 193 // audio packet. |
194 const base::TimeTicks now_time = base::TimeTicks::Now(); | 194 const base::TimeTicks now_time = base::TimeTicks::Now(); |
195 const int diff = (now_time - previous_write_time_).InMilliseconds(); | 195 const int diff = (now_time - previous_write_time_).InMilliseconds(); |
196 previous_write_time_ = now_time; | 196 previous_write_time_ = now_time; |
197 if (input_elements_to_write_ < kMaxDelayMeasurements) { | 197 if (input_elements_to_write_ < kMaxDelayMeasurements) { |
198 delay_states_[input_elements_to_write_].delta_time_ms = diff; | 198 delay_states_[input_elements_to_write_].delta_time_ms = diff; |
199 delay_states_[input_elements_to_write_].buffer_delay_ms = | 199 delay_states_[input_elements_to_write_].buffer_delay_ms = |
200 BytesToMilliseconds(buffer_->forward_bytes()); | 200 BytesToMilliseconds(buffer_->forward_bytes()); |
201 delay_states_[input_elements_to_write_].input_delay_ms = | 201 delay_states_[input_elements_to_write_].input_delay_ms = |
202 BytesToMilliseconds(hardware_delay_bytes); | 202 BytesToMilliseconds(hardware_delay_bytes); |
203 ++input_elements_to_write_; | 203 ++input_elements_to_write_; |
204 } | 204 } |
205 | 205 |
| 206 // TODO(henrika): fix this and use AudioFifo instead. |
206 // Store the captured audio packet in a seekable media buffer. | 207 // Store the captured audio packet in a seekable media buffer. |
207 if (!buffer_->Append(src, size)) { | 208 // if (!buffer_->Append(src, size)) { |
208 // An attempt to write outside the buffer limits has been made. | 209 // An attempt to write outside the buffer limits has been made. |
209 // Double the buffer capacity to ensure that we have a buffer large | 210 // Double the buffer capacity to ensure that we have a buffer large |
210 // enough to handle the current sample test scenario. | 211 // enough to handle the current sample test scenario. |
211 buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); | 212 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); |
212 buffer_->Clear(); | 213 // buffer_->Clear(); |
213 } | 214 // } |
214 } | 215 } |
215 | 216 |
216 virtual void OnError(AudioInputStream* stream) OVERRIDE {} | 217 virtual void OnError(AudioInputStream* stream) OVERRIDE {} |
217 | 218 |
218 // AudioOutputStream::AudioSourceCallback. | 219 // AudioOutputStream::AudioSourceCallback. |
219 virtual int OnMoreData(AudioBus* audio_bus, | 220 virtual int OnMoreData(AudioBus* audio_bus, |
220 AudioBuffersState buffers_state) OVERRIDE { | 221 AudioBuffersState buffers_state) OVERRIDE { |
221 base::AutoLock lock(lock_); | 222 base::AutoLock lock(lock_); |
222 | 223 |
223 // Update one component in the AudioDelayState for the packet | 224 // Update one component in the AudioDelayState for the packet |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 438 |
438 // All Close() operations that run on the mocked audio thread, | 439 // All Close() operations that run on the mocked audio thread, |
439 // should be synchronous and not post additional close tasks to | 440 // should be synchronous and not post additional close tasks to |
440 // mocked the audio thread. Hence, there is no need to call | 441 // mocked the audio thread. Hence, there is no need to call |
441 // message_loop()->RunUntilIdle() after the Close() methods. | 442 // message_loop()->RunUntilIdle() after the Close() methods. |
442 aos->Close(); | 443 aos->Close(); |
443 ais->Close(); | 444 ais->Close(); |
444 } | 445 } |
445 | 446 |
446 } // namespace media | 447 } // namespace media |
OLD | NEW |