| 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 // TODO(xians): query the native channel layout for the specific device. | 415 // TODO(xians): query the native channel layout for the specific device. |
| 416 return AudioParameters( | 416 return AudioParameters( |
| 417 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 417 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 418 AUAudioInputStream::HardwareSampleRate(), 16, | 418 AUAudioInputStream::HardwareSampleRate(), 16, |
| 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, std::string()); |
| 425 } | 425 } |
| 426 | 426 |
| 427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( | 427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( |
| 428 const AudioParameters& params) { | 428 const AudioParameters& params, const std::string& input_device_id) { |
| 429 // Handle basic output with no input channels. | 429 // Handle basic output with no input channels. |
| 430 if (params.input_channels() == 0) { | 430 if (params.input_channels() == 0) { |
| 431 AudioDeviceID device = kAudioObjectUnknown; | 431 AudioDeviceID device = kAudioObjectUnknown; |
| 432 GetDefaultOutputDevice(&device); | 432 GetDefaultOutputDevice(&device); |
| 433 return new AUHALStream(this, params, device); | 433 return new AUHALStream(this, params, device); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // TODO(crogers): support more than stereo input. | 436 // TODO(crogers): support more than stereo input. |
| 437 if (params.input_channels() != 2) { | 437 if (params.input_channels() != 2) { |
| 438 // WebAudio is currently hard-coded to 2 channels so we should not | 438 // WebAudio is currently hard-coded to 2 channels so we should not |
| (...skipping 16 matching lines...) Expand all Loading... |
| 455 // "Built-in Line Input" | 455 // "Built-in Line Input" |
| 456 // "Built-in Output" | 456 // "Built-in Output" |
| 457 // We would like to use an "aggregate" device for these situations, since | 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" | 458 // CoreAudio will make the most efficient use of the shared "clock domain" |
| 459 // so we get the lowest latency and use fewer threads. | 459 // so we get the lowest latency and use fewer threads. |
| 460 device = aggregate_device_manager_.GetDefaultAggregateDevice(); | 460 device = aggregate_device_manager_.GetDefaultAggregateDevice(); |
| 461 if (device != kAudioObjectUnknown) | 461 if (device != kAudioObjectUnknown) |
| 462 LOG(INFO) << "Using AGGREGATE audio device"; | 462 LOG(INFO) << "Using AGGREGATE audio device"; |
| 463 } | 463 } |
| 464 | 464 |
| 465 if (device != kAudioObjectUnknown) | 465 if (device != kAudioObjectUnknown && |
| 466 input_device_id == AudioManagerBase::kDefaultDeviceId) |
| 466 return new AUHALStream(this, params, device); | 467 return new AUHALStream(this, params, device); |
| 467 | 468 |
| 468 // Fallback to AudioSynchronizedStream which will handle completely | 469 // Fallback to AudioSynchronizedStream which will handle completely |
| 469 // different and arbitrary combinations of input and output devices | 470 // different and arbitrary combinations of input and output devices |
| 470 // even running at different sample-rates. | 471 // even running at different sample-rates. |
| 471 // kAudioDeviceUnknown translates to "use default" here. | 472 // kAudioDeviceUnknown translates to "use default" here. |
| 472 // TODO(crogers): consider tracking UMA stats on AUHALStream | 473 // TODO(crogers): consider tracking UMA stats on AUHALStream |
| 473 // versus AudioSynchronizedStream. | 474 // versus AudioSynchronizedStream. |
| 475 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, input_device_id); |
| 476 if (audio_device_id == kAudioObjectUnknown) |
| 477 return NULL; |
| 478 |
| 474 return new AudioSynchronizedStream(this, | 479 return new AudioSynchronizedStream(this, |
| 475 params, | 480 params, |
| 476 kAudioDeviceUnknown, | 481 audio_device_id, |
| 477 kAudioDeviceUnknown); | 482 kAudioDeviceUnknown); |
| 478 } | 483 } |
| 479 | 484 |
| 480 AudioInputStream* AudioManagerMac::MakeLinearInputStream( | 485 AudioInputStream* AudioManagerMac::MakeLinearInputStream( |
| 481 const AudioParameters& params, const std::string& device_id) { | 486 const AudioParameters& params, const std::string& device_id) { |
| 482 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 487 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 483 return new PCMQueueInAudioInputStream(this, params); | 488 return new PCMQueueInAudioInputStream(this, params); |
| 484 } | 489 } |
| 485 | 490 |
| 486 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( | 491 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 current_sample_rate_ = new_sample_rate; | 573 current_sample_rate_ = new_sample_rate; |
| 569 current_output_device_ = new_output_device; | 574 current_output_device_ = new_output_device; |
| 570 NotifyAllOutputDeviceChangeListeners(); | 575 NotifyAllOutputDeviceChangeListeners(); |
| 571 } | 576 } |
| 572 | 577 |
| 573 AudioManager* CreateAudioManager() { | 578 AudioManager* CreateAudioManager() { |
| 574 return new AudioManagerMac(); | 579 return new AudioManagerMac(); |
| 575 } | 580 } |
| 576 | 581 |
| 577 } // namespace media | 582 } // namespace media |
| OLD | NEW |