| 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 AudioBus* src, | 187 const uint8* src, uint32 size, |
| 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. | |
| 207 // Store the captured audio packet in a seekable media buffer. | 206 // Store the captured audio packet in a seekable media buffer. |
| 208 // if (!buffer_->Append(src, size)) { | 207 if (!buffer_->Append(src, size)) { |
| 209 // An attempt to write outside the buffer limits has been made. | 208 // An attempt to write outside the buffer limits has been made. |
| 210 // Double the buffer capacity to ensure that we have a buffer large | 209 // Double the buffer capacity to ensure that we have a buffer large |
| 211 // enough to handle the current sample test scenario. | 210 // enough to handle the current sample test scenario. |
| 212 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); | 211 buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); |
| 213 // buffer_->Clear(); | 212 buffer_->Clear(); |
| 214 // } | 213 } |
| 215 } | 214 } |
| 216 | 215 |
| 217 virtual void OnError(AudioInputStream* stream) OVERRIDE {} | 216 virtual void OnError(AudioInputStream* stream) OVERRIDE {} |
| 218 | 217 |
| 219 // AudioOutputStream::AudioSourceCallback. | 218 // AudioOutputStream::AudioSourceCallback. |
| 220 virtual int OnMoreData(AudioBus* audio_bus, | 219 virtual int OnMoreData(AudioBus* audio_bus, |
| 221 AudioBuffersState buffers_state) OVERRIDE { | 220 AudioBuffersState buffers_state) OVERRIDE { |
| 222 base::AutoLock lock(lock_); | 221 base::AutoLock lock(lock_); |
| 223 | 222 |
| 224 // Update one component in the AudioDelayState for the packet | 223 // Update one component in the AudioDelayState for the packet |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 437 |
| 439 // All Close() operations that run on the mocked audio thread, | 438 // All Close() operations that run on the mocked audio thread, |
| 440 // should be synchronous and not post additional close tasks to | 439 // should be synchronous and not post additional close tasks to |
| 441 // mocked the audio thread. Hence, there is no need to call | 440 // mocked the audio thread. Hence, there is no need to call |
| 442 // message_loop()->RunUntilIdle() after the Close() methods. | 441 // message_loop()->RunUntilIdle() after the Close() methods. |
| 443 aos->Close(); | 442 aos->Close(); |
| 444 ais->Close(); | 443 ais->Close(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 } // namespace media | 446 } // namespace media |
| OLD | NEW |