Chromium Code Reviews| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 | 284 |
| 285 class AudioInputStreamTraits { | 285 class AudioInputStreamTraits { |
| 286 public: | 286 public: |
| 287 typedef AudioInputStream StreamType; | 287 typedef AudioInputStream StreamType; |
| 288 | 288 |
| 289 static int HardwareSampleRate() { | 289 static int HardwareSampleRate() { |
| 290 return static_cast<int>(media::GetAudioInputHardwareSampleRate( | 290 return static_cast<int>(media::GetAudioInputHardwareSampleRate( |
| 291 AudioManagerBase::kDefaultDeviceId)); | 291 AudioManagerBase::kDefaultDeviceId)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // TODO(henrika): add support for GetAudioInputHardwareBufferSize in media. | |
| 295 // Using same buffer size as for the output side for now. | |
|
tommi (sloooow) - chröme
2012/11/09 13:20:39
nit: move this line into the implementation since
henrika (OOO until Aug 14)
2012/11/09 13:30:57
Done.
| |
| 296 static int HardwareBufferSize() { | |
| 297 return static_cast<int>(media::GetAudioHardwareBufferSize()); | |
| 298 } | |
| 299 | |
| 294 static StreamType* CreateStream(AudioManager* audio_manager, | 300 static StreamType* CreateStream(AudioManager* audio_manager, |
| 295 const AudioParameters& params) { | 301 const AudioParameters& params) { |
| 296 return audio_manager->MakeAudioInputStream(params, | 302 return audio_manager->MakeAudioInputStream(params, |
| 297 AudioManagerBase::kDefaultDeviceId); | 303 AudioManagerBase::kDefaultDeviceId); |
| 298 } | 304 } |
| 299 }; | 305 }; |
| 300 | 306 |
| 301 class AudioOutputStreamTraits { | 307 class AudioOutputStreamTraits { |
| 302 public: | 308 public: |
| 303 typedef AudioOutputStream StreamType; | 309 typedef AudioOutputStream StreamType; |
| 304 | 310 |
| 305 static int HardwareSampleRate() { | 311 static int HardwareSampleRate() { |
| 306 return static_cast<int>(media::GetAudioHardwareSampleRate()); | 312 return static_cast<int>(media::GetAudioHardwareSampleRate()); |
| 307 } | 313 } |
| 308 | 314 |
| 315 static int HardwareBufferSize() { | |
| 316 return static_cast<int>(media::GetAudioHardwareBufferSize()); | |
| 317 } | |
| 318 | |
| 309 static StreamType* CreateStream(AudioManager* audio_manager, | 319 static StreamType* CreateStream(AudioManager* audio_manager, |
| 310 const AudioParameters& params) { | 320 const AudioParameters& params) { |
| 311 return audio_manager->MakeAudioOutputStream(params); | 321 return audio_manager->MakeAudioOutputStream(params); |
| 312 } | 322 } |
| 313 }; | 323 }; |
| 314 | 324 |
| 315 // Traits template holding a trait of StreamType. It encapsulates | 325 // Traits template holding a trait of StreamType. It encapsulates |
| 316 // AudioInputStream and AudioOutputStream stream types. | 326 // AudioInputStream and AudioOutputStream stream types. |
| 317 template <typename StreamTraits> | 327 template <typename StreamTraits> |
| 318 class StreamWrapper { | 328 class StreamWrapper { |
| 319 public: | 329 public: |
| 320 typedef typename StreamTraits::StreamType StreamType; | 330 typedef typename StreamTraits::StreamType StreamType; |
| 321 | 331 |
| 322 explicit StreamWrapper(AudioManager* audio_manager) | 332 explicit StreamWrapper(AudioManager* audio_manager) |
| 323 : | 333 : |
| 324 #if defined(OS_WIN) | 334 #if defined(OS_WIN) |
| 325 com_init_(base::win::ScopedCOMInitializer::kMTA), | 335 com_init_(base::win::ScopedCOMInitializer::kMTA), |
| 326 #endif | 336 #endif |
| 327 audio_manager_(audio_manager), | 337 audio_manager_(audio_manager), |
| 328 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), | 338 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), |
| 329 #if defined(OS_ANDROID) | 339 #if defined(OS_ANDROID) |
| 330 channel_layout_(CHANNEL_LAYOUT_MONO), | 340 channel_layout_(CHANNEL_LAYOUT_MONO), |
| 331 #else | 341 #else |
| 332 channel_layout_(CHANNEL_LAYOUT_STEREO), | 342 channel_layout_(CHANNEL_LAYOUT_STEREO), |
| 333 #endif | 343 #endif |
| 334 bits_per_sample_(16) { | 344 bits_per_sample_(16) { |
| 335 // Use native/mixing sample rate and N*10ms frame size as default, | 345 // Use the preferred sample rate and buffer size. |
| 336 // where N is platform dependent. | |
| 337 sample_rate_ = StreamTraits::HardwareSampleRate(); | 346 sample_rate_ = StreamTraits::HardwareSampleRate(); |
| 338 #if defined(OS_MACOSX) | 347 samples_per_packet_ = StreamTraits::HardwareBufferSize(); |
| 339 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. | |
| 340 samples_per_packet_ = (sample_rate_ / 100); | |
| 341 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 342 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. | |
| 343 samples_per_packet_ = (sample_rate_ / 100); | |
| 344 #elif defined(OS_WIN) | |
| 345 if (media::IsWASAPISupported()) { | |
| 346 // WASAPI is supported for Windows Vista and higher. | |
| 347 if (sample_rate_ == 44100) { | |
| 348 // Tests have shown that the shared mode WASAPI implementation | |
| 349 // works bests for a period size of ~10.15873 ms when the sample | |
| 350 // rate is 44.1kHz. | |
| 351 samples_per_packet_ = 448; | |
| 352 } else { | |
| 353 // 10ms buffer size works well for 48, 96 and 192kHz. | |
| 354 samples_per_packet_ = (sample_rate_ / 100); | |
| 355 } | |
| 356 } else { | |
| 357 // Low-latency Wave implementation needs 30ms buffer size to | |
| 358 // ensure glitch-free output audio. | |
| 359 samples_per_packet_ = 3 * (sample_rate_ / 100); | |
| 360 } | |
| 361 #elif defined(OS_ANDROID) | |
| 362 samples_per_packet_ = (sample_rate_ / 100); | |
| 363 #endif | |
| 364 } | 348 } |
| 365 | 349 |
| 366 virtual ~StreamWrapper() {} | 350 virtual ~StreamWrapper() {} |
| 367 | 351 |
| 368 // Creates an Audio[Input|Output]Stream stream object using default | 352 // Creates an Audio[Input|Output]Stream stream object using default |
| 369 // parameters. | 353 // parameters. |
| 370 StreamType* Create() { | 354 StreamType* Create() { |
| 371 return CreateStream(); | 355 return CreateStream(); |
| 372 } | 356 } |
| 373 | 357 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 | 452 |
| 469 // All Close() operations that run on the mocked audio thread, | 453 // All Close() operations that run on the mocked audio thread, |
| 470 // should be synchronous and not post additional close tasks to | 454 // should be synchronous and not post additional close tasks to |
| 471 // mocked the audio thread. Hence, there is no need to call | 455 // mocked the audio thread. Hence, there is no need to call |
| 472 // message_loop()->RunAllPending() after the Close() methods. | 456 // message_loop()->RunAllPending() after the Close() methods. |
| 473 aos->Close(); | 457 aos->Close(); |
| 474 ais->Close(); | 458 ais->Close(); |
| 475 } | 459 } |
| 476 | 460 |
| 477 } // namespace media | 461 } // namespace media |
| OLD | NEW |