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" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
16 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
17 #include "media/audio/audio_util.h" | |
18 #include "media/base/seekable_buffer.h" | 17 #include "media/base/seekable_buffer.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 21 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
23 #include "media/audio/linux/audio_manager_linux.h" | 22 #include "media/audio/linux/audio_manager_linux.h" |
24 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
25 #include "media/audio/mac/audio_manager_mac.h" | 24 #include "media/audio/mac/audio_manager_mac.h" |
26 #elif defined(OS_WIN) | 25 #elif defined(OS_WIN) |
27 #include "media/audio/win/audio_manager_win.h" | 26 #include "media/audio/win/audio_manager_win.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 scoped_array<AudioDelayState> delay_states_; | 278 scoped_array<AudioDelayState> delay_states_; |
280 size_t input_elements_to_write_; | 279 size_t input_elements_to_write_; |
281 size_t output_elements_to_write_; | 280 size_t output_elements_to_write_; |
282 base::Time previous_write_time_; | 281 base::Time previous_write_time_; |
283 }; | 282 }; |
284 | 283 |
285 class AudioInputStreamTraits { | 284 class AudioInputStreamTraits { |
286 public: | 285 public: |
287 typedef AudioInputStream StreamType; | 286 typedef AudioInputStream StreamType; |
288 | 287 |
289 static int HardwareSampleRate() { | 288 static AudioParameters GetDefaultAudioStreamParameters( |
290 return static_cast<int>(media::GetAudioInputHardwareSampleRate( | 289 AudioManager* audio_manager) { |
291 AudioManagerBase::kDefaultDeviceId)); | 290 return audio_manager->GetInputStreamParameters( |
292 } | 291 AudioManagerBase::kDefaultDeviceId); |
293 | |
294 // TODO(henrika): add support for GetAudioInputHardwareBufferSize in media. | |
295 static int HardwareBufferSize() { | |
296 return static_cast<int>(media::GetAudioHardwareBufferSize()); | |
297 } | 292 } |
298 | 293 |
299 static StreamType* CreateStream(AudioManager* audio_manager, | 294 static StreamType* CreateStream(AudioManager* audio_manager, |
300 const AudioParameters& params) { | 295 const AudioParameters& params) { |
301 return audio_manager->MakeAudioInputStream(params, | 296 return audio_manager->MakeAudioInputStream(params, |
302 AudioManagerBase::kDefaultDeviceId); | 297 AudioManagerBase::kDefaultDeviceId); |
303 } | 298 } |
304 }; | 299 }; |
305 | 300 |
306 class AudioOutputStreamTraits { | 301 class AudioOutputStreamTraits { |
307 public: | 302 public: |
308 typedef AudioOutputStream StreamType; | 303 typedef AudioOutputStream StreamType; |
309 | 304 |
310 static int HardwareSampleRate() { | 305 static AudioParameters GetDefaultAudioStreamParameters( |
311 return static_cast<int>(media::GetAudioHardwareSampleRate()); | 306 AudioManager* audio_manager) { |
312 } | 307 return audio_manager->GetDefaultOutputStreamParameters( |
313 | 308 AudioParameters()); |
314 static int HardwareBufferSize() { | |
315 return static_cast<int>(media::GetAudioHardwareBufferSize()); | |
316 } | 309 } |
317 | 310 |
318 static StreamType* CreateStream(AudioManager* audio_manager, | 311 static StreamType* CreateStream(AudioManager* audio_manager, |
319 const AudioParameters& params) { | 312 const AudioParameters& params) { |
320 return audio_manager->MakeAudioOutputStream(params); | 313 return audio_manager->MakeAudioOutputStream(params); |
321 } | 314 } |
322 }; | 315 }; |
323 | 316 |
324 // Traits template holding a trait of StreamType. It encapsulates | 317 // Traits template holding a trait of StreamType. It encapsulates |
325 // AudioInputStream and AudioOutputStream stream types. | 318 // AudioInputStream and AudioOutputStream stream types. |
326 template <typename StreamTraits> | 319 template <typename StreamTraits> |
327 class StreamWrapper { | 320 class StreamWrapper { |
328 public: | 321 public: |
329 typedef typename StreamTraits::StreamType StreamType; | 322 typedef typename StreamTraits::StreamType StreamType; |
330 | 323 |
331 explicit StreamWrapper(AudioManager* audio_manager) | 324 explicit StreamWrapper(AudioManager* audio_manager) |
332 : | 325 : |
333 audio_manager_(audio_manager), | 326 audio_manager_(audio_manager), |
334 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), | 327 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), |
335 #if defined(OS_ANDROID) | 328 #if defined(OS_ANDROID) |
336 channel_layout_(CHANNEL_LAYOUT_MONO), | 329 channel_layout_(CHANNEL_LAYOUT_MONO), |
337 #else | 330 #else |
338 channel_layout_(CHANNEL_LAYOUT_STEREO), | 331 channel_layout_(CHANNEL_LAYOUT_STEREO), |
339 #endif | 332 #endif |
340 bits_per_sample_(16) { | 333 bits_per_sample_(16) { |
341 // Use the preferred sample rate. | 334 // Use the preferred sample rate. |
342 sample_rate_ = StreamTraits::HardwareSampleRate(); | 335 const AudioParameters& params = |
| 336 StreamTraits::GetDefaultAudioStreamParameters(audio_manager_); |
| 337 sample_rate_ = params.sample_rate(); |
343 | 338 |
344 // Use the preferred buffer size. Note that the input side uses the same | 339 // Use the preferred buffer size. Note that the input side uses the same |
345 // size as the output side in this implementation. | 340 // size as the output side in this implementation. |
346 samples_per_packet_ = StreamTraits::HardwareBufferSize(); | 341 samples_per_packet_ = params.frames_per_buffer(); |
347 } | 342 } |
348 | 343 |
349 virtual ~StreamWrapper() {} | 344 virtual ~StreamWrapper() {} |
350 | 345 |
351 // Creates an Audio[Input|Output]Stream stream object using default | 346 // Creates an Audio[Input|Output]Stream stream object using default |
352 // parameters. | 347 // parameters. |
353 StreamType* Create() { | 348 StreamType* Create() { |
354 return CreateStream(); | 349 return CreateStream(); |
355 } | 350 } |
356 | 351 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 442 |
448 // All Close() operations that run on the mocked audio thread, | 443 // All Close() operations that run on the mocked audio thread, |
449 // should be synchronous and not post additional close tasks to | 444 // should be synchronous and not post additional close tasks to |
450 // mocked the audio thread. Hence, there is no need to call | 445 // mocked the audio thread. Hence, there is no need to call |
451 // message_loop()->RunUntilIdle() after the Close() methods. | 446 // message_loop()->RunUntilIdle() after the Close() methods. |
452 aos->Close(); | 447 aos->Close(); |
453 ais->Close(); | 448 ais->Close(); |
454 } | 449 } |
455 | 450 |
456 } // namespace media | 451 } // namespace media |
OLD | NEW |