| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 state.output_delay_ms); | 187 state.output_delay_ms); |
| 188 ++elements_written; | 188 ++elements_written; |
| 189 } | 189 } |
| 190 | 190 |
| 191 base::CloseFile(text_file); | 191 base::CloseFile(text_file); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // AudioInputStream::AudioInputCallback. | 194 // AudioInputStream::AudioInputCallback. |
| 195 void OnData(AudioInputStream* stream, | 195 void OnData(AudioInputStream* stream, |
| 196 const AudioBus* src, | 196 const AudioBus* src, |
| 197 uint32_t hardware_delay_bytes, | 197 base::TimeDelta delay, |
| 198 base::TimeTicks delay_timestamp, |
| 198 double volume) override { | 199 double volume) override { |
| 199 base::AutoLock lock(lock_); | 200 base::AutoLock lock(lock_); |
| 200 | 201 |
| 201 // Update three components in the AudioDelayState for this recorded | 202 // Update three components in the AudioDelayState for this recorded |
| 202 // audio packet. | 203 // audio packet. |
| 203 const base::TimeTicks now_time = base::TimeTicks::Now(); | 204 const base::TimeTicks now_time = base::TimeTicks::Now(); |
| 204 const int diff = (now_time - previous_write_time_).InMilliseconds(); | 205 const int diff = (now_time - previous_write_time_).InMilliseconds(); |
| 205 previous_write_time_ = now_time; | 206 previous_write_time_ = now_time; |
| 206 if (input_elements_to_write_ < kMaxDelayMeasurements) { | 207 if (input_elements_to_write_ < kMaxDelayMeasurements) { |
| 207 delay_states_[input_elements_to_write_].delta_time_ms = diff; | 208 delay_states_[input_elements_to_write_].delta_time_ms = diff; |
| 208 delay_states_[input_elements_to_write_].buffer_delay_ms = | 209 delay_states_[input_elements_to_write_].buffer_delay_ms = |
| 209 BytesToMilliseconds(buffer_->forward_bytes()); | 210 BytesToMilliseconds(buffer_->forward_bytes()); |
| 210 delay_states_[input_elements_to_write_].input_delay_ms = | 211 delay_states_[input_elements_to_write_].input_delay_ms = |
| 211 BytesToMilliseconds(hardware_delay_bytes); | 212 delay.InMilliseconds(); |
| 212 ++input_elements_to_write_; | 213 ++input_elements_to_write_; |
| 213 } | 214 } |
| 214 | 215 |
| 215 // TODO(henrika): fix this and use AudioFifo instead. | 216 // TODO(henrika): fix this and use AudioFifo instead. |
| 216 // Store the captured audio packet in a seekable media buffer. | 217 // Store the captured audio packet in a seekable media buffer. |
| 217 // if (!buffer_->Append(src, size)) { | 218 // if (!buffer_->Append(src, size)) { |
| 218 // An attempt to write outside the buffer limits has been made. | 219 // An attempt to write outside the buffer limits has been made. |
| 219 // Double the buffer capacity to ensure that we have a buffer large | 220 // Double the buffer capacity to ensure that we have a buffer large |
| 220 // enough to handle the current sample test scenario. | 221 // enough to handle the current sample test scenario. |
| 221 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); | 222 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 444 |
| 444 // All Close() operations that run on the mocked audio thread, | 445 // All Close() operations that run on the mocked audio thread, |
| 445 // should be synchronous and not post additional close tasks to | 446 // should be synchronous and not post additional close tasks to |
| 446 // mocked the audio thread. Hence, there is no need to call | 447 // mocked the audio thread. Hence, there is no need to call |
| 447 // message_loop()->RunUntilIdle() after the Close() methods. | 448 // message_loop()->RunUntilIdle() after the Close() methods. |
| 448 aos->Close(); | 449 aos->Close(); |
| 449 ais->Close(); | 450 ais->Close(); |
| 450 } | 451 } |
| 451 | 452 |
| 452 } // namespace media | 453 } // namespace media |
| OLD | NEW |