| 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 "media/audio/mac/audio_manager_mac.h" | 5 #include "media/audio/mac/audio_manager_mac.h" |
| 6 | 6 |
| 7 #include <CoreAudio/AudioHardware.h> | 7 #include <CoreAudio/AudioHardware.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 buffer_size); | 419 buffer_size); |
| 420 } | 420 } |
| 421 | 421 |
| 422 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( | 422 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( |
| 423 const AudioParameters& params) { | 423 const AudioParameters& params) { |
| 424 return MakeLowLatencyOutputStream(params); | 424 return MakeLowLatencyOutputStream(params); |
| 425 } | 425 } |
| 426 | 426 |
| 427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( | 427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( |
| 428 const AudioParameters& params) { | 428 const AudioParameters& params) { |
| 429 // Handle basic output with no input channels. |
| 430 if (params.input_channels() == 0) { |
| 431 AudioDeviceID device = kAudioObjectUnknown; |
| 432 GetDefaultOutputDevice(&device); |
| 433 return new AUHALStream(this, params, device); |
| 434 } |
| 435 |
| 429 // TODO(crogers): support more than stereo input. | 436 // TODO(crogers): support more than stereo input. |
| 430 if (params.input_channels() == 2) { | 437 if (params.input_channels() != 2) { |
| 431 if (HasUnifiedDefaultIO()) | 438 // WebAudio is currently hard-coded to 2 channels so we should not |
| 432 return new AudioHardwareUnifiedStream(this, params); | 439 // see this case. |
| 433 | 440 NOTREACHED() << "Only stereo input is currently supported!"; |
| 434 // TODO(crogers): use aggregate devices along with AUHALStream | 441 return NULL; |
| 435 // to get better performance for built-in hardware. | |
| 436 | |
| 437 // kAudioDeviceUnknown translates to "use default" here. | |
| 438 return new AudioSynchronizedStream(this, | |
| 439 params, | |
| 440 kAudioDeviceUnknown, | |
| 441 kAudioDeviceUnknown); | |
| 442 } | 442 } |
| 443 | 443 |
| 444 AudioDeviceID device = kAudioObjectUnknown; | 444 AudioDeviceID device = kAudioObjectUnknown; |
| 445 GetDefaultOutputDevice(&device); | 445 if (HasUnifiedDefaultIO()) { |
| 446 return new AUHALStream(this, params, device); | 446 // For I/O, the simplest case is when the default input and output |
| 447 // devices are the same. |
| 448 GetDefaultOutputDevice(&device); |
| 449 LOG(INFO) << "UNIFIED: default input and output devices are identical"; |
| 450 } else { |
| 451 // Some audio hardware is presented as separate input and output devices |
| 452 // even though they are really the same physical hardware and |
| 453 // share the same "clock domain" at the lowest levels of the driver. |
| 454 // A common of example of this is the "built-in" audio hardware: |
| 455 // "Built-in Line Input" |
| 456 // "Built-in Output" |
| 457 // We would like to use an "aggregate" device for these situations, since |
| 458 // CoreAudio will make the most efficient use of the shared "clock domain" |
| 459 // so we get the lowest latency and use fewer threads. |
| 460 device = aggregate_device_manager_.GetDefaultAggregateDevice(); |
| 461 if (device != kAudioObjectUnknown) |
| 462 LOG(INFO) << "Using AGGREGATE audio device"; |
| 463 } |
| 464 |
| 465 if (device != kAudioObjectUnknown) |
| 466 return new AUHALStream(this, params, device); |
| 467 |
| 468 // Fallback to AudioSynchronizedStream which will handle completely |
| 469 // different and arbitrary combinations of input and output devices |
| 470 // even running at different sample-rates. |
| 471 // kAudioDeviceUnknown translates to "use default" here. |
| 472 // TODO(crogers): consider tracking UMA stats on AUHALStream |
| 473 // versus AudioSynchronizedStream. |
| 474 return new AudioSynchronizedStream(this, |
| 475 params, |
| 476 kAudioDeviceUnknown, |
| 477 kAudioDeviceUnknown); |
| 447 } | 478 } |
| 448 | 479 |
| 449 AudioInputStream* AudioManagerMac::MakeLinearInputStream( | 480 AudioInputStream* AudioManagerMac::MakeLinearInputStream( |
| 450 const AudioParameters& params, const std::string& device_id) { | 481 const AudioParameters& params, const std::string& device_id) { |
| 451 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 482 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 452 return new PCMQueueInAudioInputStream(this, params); | 483 return new PCMQueueInAudioInputStream(this, params); |
| 453 } | 484 } |
| 454 | 485 |
| 455 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( | 486 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( |
| 456 const AudioParameters& params, const std::string& device_id) { | 487 const AudioParameters& params, const std::string& device_id) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 current_sample_rate_ = new_sample_rate; | 568 current_sample_rate_ = new_sample_rate; |
| 538 current_output_device_ = new_output_device; | 569 current_output_device_ = new_output_device; |
| 539 NotifyAllOutputDeviceChangeListeners(); | 570 NotifyAllOutputDeviceChangeListeners(); |
| 540 } | 571 } |
| 541 | 572 |
| 542 AudioManager* CreateAudioManager() { | 573 AudioManager* CreateAudioManager() { |
| 543 return new AudioManagerMac(); | 574 return new AudioManagerMac(); |
| 544 } | 575 } |
| 545 | 576 |
| 546 } // namespace media | 577 } // namespace media |
| OLD | NEW |