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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // enough to handle the current sample test scenario. | 211 // enough to handle the current sample test scenario. |
212 buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); | 212 buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); |
213 buffer_->Clear(); | 213 buffer_->Clear(); |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 virtual void OnClose(AudioInputStream* stream) OVERRIDE {} | 217 virtual void OnClose(AudioInputStream* stream) OVERRIDE {} |
218 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE {} | 218 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE {} |
219 | 219 |
220 // AudioOutputStream::AudioSourceCallback. | 220 // AudioOutputStream::AudioSourceCallback. |
221 virtual uint32 OnMoreData(uint8* dest, | 221 virtual int OnMoreData(AudioBus* audio_bus, |
222 uint32 max_size, | 222 AudioBuffersState buffers_state) OVERRIDE { |
223 AudioBuffersState buffers_state) OVERRIDE { | |
224 base::AutoLock lock(lock_); | 223 base::AutoLock lock(lock_); |
225 | 224 |
226 // Update one component in the AudioDelayState for the packet | 225 // Update one component in the AudioDelayState for the packet |
227 // which is about to be played out. | 226 // which is about to be played out. |
228 if (output_elements_to_write_ < kMaxDelayMeasurements) { | 227 if (output_elements_to_write_ < kMaxDelayMeasurements) { |
229 int output_delay_bytes = buffers_state.hardware_delay_bytes; | 228 int output_delay_bytes = buffers_state.hardware_delay_bytes; |
230 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
231 // Special fix for Windows in combination with Wave where the | 230 // Special fix for Windows in combination with Wave where the |
232 // pending bytes field of the audio buffer state is used to | 231 // pending bytes field of the audio buffer state is used to |
233 // report the delay. | 232 // report the delay. |
234 if (!media::IsWASAPISupported()) { | 233 if (!media::IsWASAPISupported()) { |
235 output_delay_bytes = buffers_state.pending_bytes; | 234 output_delay_bytes = buffers_state.pending_bytes; |
236 } | 235 } |
237 #endif | 236 #endif |
238 delay_states_[output_elements_to_write_].output_delay_ms = | 237 delay_states_[output_elements_to_write_].output_delay_ms = |
239 BytesToMilliseconds(output_delay_bytes); | 238 BytesToMilliseconds(output_delay_bytes); |
240 ++output_elements_to_write_; | 239 ++output_elements_to_write_; |
241 } | 240 } |
242 | 241 |
| 242 int size; |
| 243 const uint8* source; |
243 // Read the data from the seekable media buffer which contains | 244 // Read the data from the seekable media buffer which contains |
244 // captured data at the same size and sample rate as the output side. | 245 // captured data at the same size and sample rate as the output side. |
245 return buffer_->Read(dest, max_size); | 246 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) { |
| 247 EXPECT_EQ(channels_, audio_bus->channels()); |
| 248 size = std::min(audio_bus->frames() * frame_size_, size); |
| 249 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*audio_bus->channel(0)), 0U); |
| 250 audio_bus->FromInterleaved( |
| 251 source, size / frame_size_, frame_size_ / channels_); |
| 252 buffer_->Seek(size); |
| 253 return size / frame_size_; |
| 254 } |
| 255 |
| 256 return 0; |
246 } | 257 } |
247 | 258 |
248 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE {} | 259 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE {} |
249 virtual void WaitTillDataReady() OVERRIDE {} | 260 virtual void WaitTillDataReady() OVERRIDE {} |
250 | 261 |
251 protected: | 262 protected: |
252 // Converts from bytes to milliseconds taking the sample rate and size | 263 // Converts from bytes to milliseconds taking the sample rate and size |
253 // of an audio frame into account. | 264 // of an audio frame into account. |
254 int BytesToMilliseconds(uint32 delay_bytes) const { | 265 int BytesToMilliseconds(uint32 delay_bytes) const { |
255 return static_cast<int>((delay_bytes / frame_size_) * frames_to_ms_ + 0.5); | 266 return static_cast<int>((delay_bytes / frame_size_) * frames_to_ms_ + 0.5); |
256 } | 267 } |
257 | 268 |
258 private: | 269 private: |
259 base::Lock lock_; | 270 base::Lock lock_; |
260 scoped_ptr<media::SeekableBuffer> buffer_; | 271 scoped_ptr<media::SeekableBuffer> buffer_; |
261 int sample_rate_; | 272 int sample_rate_; |
262 int samples_per_packet_; | 273 int samples_per_packet_; |
263 int channels_; | 274 int channels_; |
264 size_t frame_size_; | 275 int frame_size_; |
265 double frames_to_ms_; | 276 double frames_to_ms_; |
266 scoped_array<AudioDelayState> delay_states_; | 277 scoped_array<AudioDelayState> delay_states_; |
267 size_t input_elements_to_write_; | 278 size_t input_elements_to_write_; |
268 size_t output_elements_to_write_; | 279 size_t output_elements_to_write_; |
269 base::Time previous_write_time_; | 280 base::Time previous_write_time_; |
270 }; | 281 }; |
271 | 282 |
272 class AudioInputStreamTraits { | 283 class AudioInputStreamTraits { |
273 public: | 284 public: |
274 typedef AudioInputStream StreamType; | 285 typedef AudioInputStream StreamType; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 460 |
450 // All Close() operations that run on the mocked audio thread, | 461 // All Close() operations that run on the mocked audio thread, |
451 // should be synchronous and not post additional close tasks to | 462 // should be synchronous and not post additional close tasks to |
452 // mocked the audio thread. Hence, there is no need to call | 463 // mocked the audio thread. Hence, there is no need to call |
453 // message_loop()->RunAllPending() after the Close() methods. | 464 // message_loop()->RunAllPending() after the Close() methods. |
454 aos->Close(); | 465 aos->Close(); |
455 ais->Close(); | 466 ais->Close(); |
456 } | 467 } |
457 | 468 |
458 } // namespace media | 469 } // namespace media |
OLD | NEW |