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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 public AudioOutputStream::AudioSourceCallback { | 129 public AudioOutputStream::AudioSourceCallback { |
130 public: | 130 public: |
131 FullDuplexAudioSinkSource(int sample_rate, | 131 FullDuplexAudioSinkSource(int sample_rate, |
132 int samples_per_packet, | 132 int samples_per_packet, |
133 int channels) | 133 int channels) |
134 : sample_rate_(sample_rate), | 134 : sample_rate_(sample_rate), |
135 samples_per_packet_(samples_per_packet), | 135 samples_per_packet_(samples_per_packet), |
136 channels_(channels), | 136 channels_(channels), |
137 input_elements_to_write_(0), | 137 input_elements_to_write_(0), |
138 output_elements_to_write_(0), | 138 output_elements_to_write_(0), |
139 previous_write_time_(base::Time::Now()) { | 139 previous_write_time_(base::TimeTicks::Now()) { |
140 // Size in bytes of each audio frame (4 bytes for 16-bit stereo PCM). | 140 // Size in bytes of each audio frame (4 bytes for 16-bit stereo PCM). |
141 frame_size_ = (16 / 8) * channels_; | 141 frame_size_ = (16 / 8) * channels_; |
142 | 142 |
143 // Start with the smallest possible buffer size. It will be increased | 143 // Start with the smallest possible buffer size. It will be increased |
144 // dynamically during the test if required. | 144 // dynamically during the test if required. |
145 buffer_.reset( | 145 buffer_.reset( |
146 new media::SeekableBuffer(0, samples_per_packet_ * frame_size_)); | 146 new media::SeekableBuffer(0, samples_per_packet_ * frame_size_)); |
147 | 147 |
148 frames_to_ms_ = static_cast<double>(1000.0 / sample_rate_); | 148 frames_to_ms_ = static_cast<double>(1000.0 / sample_rate_); |
149 delay_states_.reset(new AudioDelayState[kMaxDelayMeasurements]); | 149 delay_states_.reset(new AudioDelayState[kMaxDelayMeasurements]); |
(...skipping 29 matching lines...) Expand all Loading... |
179 | 179 |
180 // AudioInputStream::AudioInputCallback. | 180 // AudioInputStream::AudioInputCallback. |
181 virtual void OnData(AudioInputStream* stream, | 181 virtual void OnData(AudioInputStream* stream, |
182 const uint8* src, uint32 size, | 182 const uint8* src, uint32 size, |
183 uint32 hardware_delay_bytes, | 183 uint32 hardware_delay_bytes, |
184 double volume) OVERRIDE { | 184 double volume) OVERRIDE { |
185 base::AutoLock lock(lock_); | 185 base::AutoLock lock(lock_); |
186 | 186 |
187 // Update three components in the AudioDelayState for this recorded | 187 // Update three components in the AudioDelayState for this recorded |
188 // audio packet. | 188 // audio packet. |
189 base::Time now_time = base::Time::Now(); | 189 const base::TimeTicks now_time = base::TimeTicks::Now(); |
190 int diff = (now_time - previous_write_time_).InMilliseconds(); | 190 const int diff = (now_time - previous_write_time_).InMilliseconds(); |
191 previous_write_time_ = now_time; | 191 previous_write_time_ = now_time; |
192 if (input_elements_to_write_ < kMaxDelayMeasurements) { | 192 if (input_elements_to_write_ < kMaxDelayMeasurements) { |
193 delay_states_[input_elements_to_write_].delta_time_ms = diff; | 193 delay_states_[input_elements_to_write_].delta_time_ms = diff; |
194 delay_states_[input_elements_to_write_].buffer_delay_ms = | 194 delay_states_[input_elements_to_write_].buffer_delay_ms = |
195 BytesToMilliseconds(buffer_->forward_bytes()); | 195 BytesToMilliseconds(buffer_->forward_bytes()); |
196 delay_states_[input_elements_to_write_].input_delay_ms = | 196 delay_states_[input_elements_to_write_].input_delay_ms = |
197 BytesToMilliseconds(hardware_delay_bytes); | 197 BytesToMilliseconds(hardware_delay_bytes); |
198 ++input_elements_to_write_; | 198 ++input_elements_to_write_; |
199 } | 199 } |
200 | 200 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 base::Lock lock_; | 270 base::Lock lock_; |
271 scoped_ptr<media::SeekableBuffer> buffer_; | 271 scoped_ptr<media::SeekableBuffer> buffer_; |
272 int sample_rate_; | 272 int sample_rate_; |
273 int samples_per_packet_; | 273 int samples_per_packet_; |
274 int channels_; | 274 int channels_; |
275 int frame_size_; | 275 int frame_size_; |
276 double frames_to_ms_; | 276 double frames_to_ms_; |
277 scoped_ptr<AudioDelayState[]> delay_states_; | 277 scoped_ptr<AudioDelayState[]> delay_states_; |
278 size_t input_elements_to_write_; | 278 size_t input_elements_to_write_; |
279 size_t output_elements_to_write_; | 279 size_t output_elements_to_write_; |
280 base::Time previous_write_time_; | 280 base::TimeTicks previous_write_time_; |
281 }; | 281 }; |
282 | 282 |
283 class AudioInputStreamTraits { | 283 class AudioInputStreamTraits { |
284 public: | 284 public: |
285 typedef AudioInputStream StreamType; | 285 typedef AudioInputStream StreamType; |
286 | 286 |
287 static AudioParameters GetDefaultAudioStreamParameters( | 287 static AudioParameters GetDefaultAudioStreamParameters( |
288 AudioManager* audio_manager) { | 288 AudioManager* audio_manager) { |
289 return audio_manager->GetInputStreamParameters( | 289 return audio_manager->GetInputStreamParameters( |
290 AudioManagerBase::kDefaultDeviceId); | 290 AudioManagerBase::kDefaultDeviceId); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 440 |
441 // All Close() operations that run on the mocked audio thread, | 441 // All Close() operations that run on the mocked audio thread, |
442 // should be synchronous and not post additional close tasks to | 442 // should be synchronous and not post additional close tasks to |
443 // mocked the audio thread. Hence, there is no need to call | 443 // mocked the audio thread. Hence, there is no need to call |
444 // message_loop()->RunUntilIdle() after the Close() methods. | 444 // message_loop()->RunUntilIdle() after the Close() methods. |
445 aos->Close(); | 445 aos->Close(); |
446 ais->Close(); | 446 ais->Close(); |
447 } | 447 } |
448 | 448 |
449 } // namespace media | 449 } // namespace media |
OLD | NEW |