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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 394 } |
395 | 395 |
396 void AudioManagerMac::GetAudioOutputDeviceNames( | 396 void AudioManagerMac::GetAudioOutputDeviceNames( |
397 media::AudioDeviceNames* device_names) { | 397 media::AudioDeviceNames* device_names) { |
398 DCHECK(device_names->empty()); | 398 DCHECK(device_names->empty()); |
399 GetAudioDeviceInfo(false, device_names); | 399 GetAudioDeviceInfo(false, device_names); |
400 } | 400 } |
401 | 401 |
402 AudioParameters AudioManagerMac::GetInputStreamParameters( | 402 AudioParameters AudioManagerMac::GetInputStreamParameters( |
403 const std::string& device_id) { | 403 const std::string& device_id) { |
404 // Due to the sharing of the input and output buffer sizes, we need to choose | |
405 // the input buffer size based on the output sample rate. See | |
406 // http://crbug.com/154352. | |
407 const int buffer_size = ChooseBufferSize( | |
408 AUAudioOutputStream::HardwareSampleRate()); | |
409 | |
410 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); | 404 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); |
411 if (device == kAudioObjectUnknown) { | 405 if (device == kAudioObjectUnknown) { |
412 DLOG(ERROR) << "Invalid device " << device_id; | 406 DLOG(ERROR) << "Invalid device " << device_id; |
413 return AudioParameters(); | 407 return AudioParameters( |
| 408 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 409 kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate)); |
414 } | 410 } |
415 | 411 |
416 int channels = 0; | 412 int channels = 0; |
417 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 413 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
418 if (GetDeviceChannels(device, kAudioDevicePropertyScopeInput, &channels) && | 414 if (GetDeviceChannels(device, kAudioDevicePropertyScopeInput, &channels) && |
419 channels <= 2) { | 415 channels <= 2) { |
420 channel_layout = GuessChannelLayout(channels); | 416 channel_layout = GuessChannelLayout(channels); |
421 } else { | 417 } else { |
422 DLOG(ERROR) << "Failed to get the device channels, use stereo as default " | 418 DLOG(ERROR) << "Failed to get the device channels, use stereo as default " |
423 << "for device " << device_id; | 419 << "for device " << device_id; |
424 } | 420 } |
425 | 421 |
426 int sample_rate = HardwareSampleRateForDevice(device); | 422 int sample_rate = HardwareSampleRateForDevice(device); |
427 if (!sample_rate) | 423 if (!sample_rate) |
428 sample_rate = kFallbackSampleRate; | 424 sample_rate = kFallbackSampleRate; |
429 | 425 |
| 426 // Due to the sharing of the input and output buffer sizes, we need to choose |
| 427 // the input buffer size based on the output sample rate. See |
| 428 // http://crbug.com/154352. |
| 429 const int buffer_size = ChooseBufferSize(sample_rate); |
| 430 |
430 // TODO(xians): query the native channel layout for the specific device. | 431 // TODO(xians): query the native channel layout for the specific device. |
431 return AudioParameters( | 432 return AudioParameters( |
432 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 433 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
433 sample_rate, 16, buffer_size); | 434 sample_rate, 16, buffer_size); |
434 } | 435 } |
435 | 436 |
436 std::string AudioManagerMac::GetAssociatedOutputDeviceID( | 437 std::string AudioManagerMac::GetAssociatedOutputDeviceID( |
437 const std::string& input_device_id) { | 438 const std::string& input_device_id) { |
438 AudioDeviceID device = GetAudioDeviceIdByUId(true, input_device_id); | 439 AudioDeviceID device = GetAudioDeviceIdByUId(true, input_device_id); |
439 if (device == kAudioObjectUnknown) | 440 if (device == kAudioObjectUnknown) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 640 |
640 return stream; | 641 return stream; |
641 } | 642 } |
642 | 643 |
643 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( | 644 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( |
644 const std::string& output_device_id, | 645 const std::string& output_device_id, |
645 const AudioParameters& input_params) { | 646 const AudioParameters& input_params) { |
646 AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id); | 647 AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id); |
647 if (device == kAudioObjectUnknown) { | 648 if (device == kAudioObjectUnknown) { |
648 DLOG(ERROR) << "Invalid output device " << output_device_id; | 649 DLOG(ERROR) << "Invalid output device " << output_device_id; |
649 return AudioParameters(); | 650 return input_params.IsValid() ? input_params : AudioParameters( |
| 651 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 652 kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate)); |
650 } | 653 } |
651 | 654 |
652 int hardware_channels = 2; | 655 int hardware_channels = 2; |
653 if (!GetDeviceChannels(device, kAudioDevicePropertyScopeOutput, | 656 if (!GetDeviceChannels(device, kAudioDevicePropertyScopeOutput, |
654 &hardware_channels)) { | 657 &hardware_channels)) { |
655 // Fallback to stereo. | 658 // Fallback to stereo. |
656 hardware_channels = 2; | 659 hardware_channels = 2; |
657 } | 660 } |
658 | 661 |
659 ChannelLayout channel_layout = GuessChannelLayout(hardware_channels); | 662 ChannelLayout channel_layout = GuessChannelLayout(hardware_channels); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } | 748 } |
746 | 749 |
747 return buffer_size; | 750 return buffer_size; |
748 } | 751 } |
749 | 752 |
750 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 753 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
751 return new AudioManagerMac(audio_log_factory); | 754 return new AudioManagerMac(audio_log_factory); |
752 } | 755 } |
753 | 756 |
754 } // namespace media | 757 } // namespace media |
OLD | NEW |