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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // AudioInputStream and AudioOutputStream stream types. | 304 // AudioInputStream and AudioOutputStream stream types. |
305 template <typename StreamTraits> | 305 template <typename StreamTraits> |
306 class StreamWrapper { | 306 class StreamWrapper { |
307 public: | 307 public: |
308 typedef typename StreamTraits::StreamType StreamType; | 308 typedef typename StreamTraits::StreamType StreamType; |
309 | 309 |
310 explicit StreamWrapper(AudioManager* audio_manager) | 310 explicit StreamWrapper(AudioManager* audio_manager) |
311 : com_init_(ScopedCOMInitializer::kMTA), | 311 : com_init_(ScopedCOMInitializer::kMTA), |
312 audio_manager_(audio_manager), | 312 audio_manager_(audio_manager), |
313 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), | 313 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), |
| 314 #if defined(OS_ANDROID) |
| 315 channel_layout_(CHANNEL_LAYOUT_MONO), |
| 316 #else |
314 channel_layout_(CHANNEL_LAYOUT_STEREO), | 317 channel_layout_(CHANNEL_LAYOUT_STEREO), |
| 318 #endif |
315 bits_per_sample_(16) { | 319 bits_per_sample_(16) { |
316 // Use native/mixing sample rate and N*10ms frame size as default, | 320 // Use native/mixing sample rate and N*10ms frame size as default, |
317 // where N is platform dependent. | 321 // where N is platform dependent. |
318 sample_rate_ = StreamTraits::HardwareSampleRate(); | 322 sample_rate_ = StreamTraits::HardwareSampleRate(); |
319 #if defined(OS_MACOSX) | 323 #if defined(OS_MACOSX) |
320 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. | 324 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. |
321 samples_per_packet_ = (sample_rate_ / 100); | 325 samples_per_packet_ = (sample_rate_ / 100); |
322 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | 326 #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
323 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. | 327 // 10ms buffer size works well for 44.1, 48, 96 and 192kHz. |
324 samples_per_packet_ = (sample_rate_ / 100); | 328 samples_per_packet_ = (sample_rate_ / 100); |
325 #elif defined(OS_WIN) | 329 #elif defined(OS_WIN) |
326 if (media::IsWASAPISupported()) { | 330 if (media::IsWASAPISupported()) { |
327 // WASAPI is supported for Windows Vista and higher. | 331 // WASAPI is supported for Windows Vista and higher. |
328 if (sample_rate_ == 44100) { | 332 if (sample_rate_ == 44100) { |
329 // Tests have shown that the shared mode WASAPI implementation | 333 // Tests have shown that the shared mode WASAPI implementation |
330 // works bests for a period size of ~10.15873 ms when the sample | 334 // works bests for a period size of ~10.15873 ms when the sample |
331 // rate is 44.1kHz. | 335 // rate is 44.1kHz. |
332 samples_per_packet_ = 448; | 336 samples_per_packet_ = 448; |
333 } else { | 337 } else { |
334 // 10ms buffer size works well for 48, 96 and 192kHz. | 338 // 10ms buffer size works well for 48, 96 and 192kHz. |
335 samples_per_packet_ = (sample_rate_ / 100); | 339 samples_per_packet_ = (sample_rate_ / 100); |
336 } | 340 } |
337 } else { | 341 } else { |
338 // Low-latency Wave implementation needs 30ms buffer size to | 342 // Low-latency Wave implementation needs 30ms buffer size to |
339 // ensure glitch-free output audio. | 343 // ensure glitch-free output audio. |
340 samples_per_packet_ = 3 * (sample_rate_ / 100); | 344 samples_per_packet_ = 3 * (sample_rate_ / 100); |
341 } | 345 } |
| 346 #elif defined(OS_ANDROID) |
| 347 samples_per_packet_ = (sample_rate_ / 100); |
342 #endif | 348 #endif |
343 } | 349 } |
344 | 350 |
345 virtual ~StreamWrapper() {} | 351 virtual ~StreamWrapper() {} |
346 | 352 |
347 // Creates an Audio[Input|Output]Stream stream object using default | 353 // Creates an Audio[Input|Output]Stream stream object using default |
348 // parameters. | 354 // parameters. |
349 StreamType* Create() { | 355 StreamType* Create() { |
350 return CreateStream(); | 356 return CreateStream(); |
351 } | 357 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 aos->Stop(); | 456 aos->Stop(); |
451 ais->Stop(); | 457 ais->Stop(); |
452 | 458 |
453 // All Close() operations that run on the mocked audio thread, | 459 // All Close() operations that run on the mocked audio thread, |
454 // should be synchronous and not post additional close tasks to | 460 // should be synchronous and not post additional close tasks to |
455 // mocked the audio thread. Hence, there is no need to call | 461 // mocked the audio thread. Hence, there is no need to call |
456 // message_loop()->RunAllPending() after the Close() methods. | 462 // message_loop()->RunAllPending() after the Close() methods. |
457 aos->Close(); | 463 aos->Close(); |
458 ais->Close(); | 464 ais->Close(); |
459 } | 465 } |
OLD | NEW |