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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 DCHECK(device_names->empty()); | 425 DCHECK(device_names->empty()); |
426 GetAudioDeviceInfo(true, device_names); | 426 GetAudioDeviceInfo(true, device_names); |
427 } | 427 } |
428 | 428 |
429 void AudioManagerMac::GetAudioOutputDeviceNames( | 429 void AudioManagerMac::GetAudioOutputDeviceNames( |
430 media::AudioDeviceNames* device_names) { | 430 media::AudioDeviceNames* device_names) { |
431 DCHECK(device_names->empty()); | 431 DCHECK(device_names->empty()); |
432 GetAudioDeviceInfo(false, device_names); | 432 GetAudioDeviceInfo(false, device_names); |
433 } | 433 } |
434 | 434 |
435 AudioParameters AudioManagerMac::GetInputStreamParameters( | 435 AudioParameters AudioManagerMac::GetPreferredInputStreamParameters( |
436 const std::string& device_id) { | 436 const std::string& input_device_id, |
| 437 const AudioParameters& input_params) { |
437 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); | 438 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); |
438 if (device == kAudioObjectUnknown) { | 439 if (device == kAudioObjectUnknown) { |
439 DLOG(ERROR) << "Invalid device " << device_id; | 440 DLOG(ERROR) << "Invalid device " << device_id; |
440 return AudioParameters( | 441 return AudioParameters( |
441 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 442 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
442 kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate)); | 443 kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate)); |
443 } | 444 } |
444 | 445 |
| 446 const bool has_valid_input_params = input_params.IsValid(); |
| 447 |
445 int channels = 0; | 448 int channels = 0; |
446 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 449 ChannelLayout channel_layout = has_valid_input_params ? |
| 450 input_params.channel_layout() : CHANNEL_LAYOUT_STEREO; |
447 if (GetDeviceChannels(device, kAudioDevicePropertyScopeInput, &channels) && | 451 if (GetDeviceChannels(device, kAudioDevicePropertyScopeInput, &channels) && |
448 channels <= 2) { | 452 channels <= 2) { |
| 453 // Use the native channel layout of the device. |
449 channel_layout = GuessChannelLayout(channels); | 454 channel_layout = GuessChannelLayout(channels); |
450 } else { | 455 } else { |
451 DLOG(ERROR) << "Failed to get the device channels, use stereo as default " | 456 DLOG(ERROR) << "Failed to get the device channels, use stereo as default " |
452 << "for device " << device_id; | 457 << "for device " << device_id; |
453 } | 458 } |
454 | 459 |
| 460 // Use the native sample rate of the device if it can. |
455 int sample_rate = HardwareSampleRateForDevice(device); | 461 int sample_rate = HardwareSampleRateForDevice(device); |
456 if (!sample_rate) | 462 if (!sample_rate) { |
457 sample_rate = kFallbackSampleRate; | 463 sample_rate = has_valid_input_params ? |
| 464 input_params.sample_rate() : kFallbackSampleRate; |
| 465 } |
458 | 466 |
459 // Due to the sharing of the input and output buffer sizes, we need to choose | 467 int buffer_size = ChooseBufferSize(sample_rate); |
460 // the input buffer size based on the output sample rate. See | |
461 // http://crbug.com/154352. | |
462 const int buffer_size = ChooseBufferSize(sample_rate); | |
463 | 468 |
464 // TODO(xians): query the native channel layout for the specific device. | 469 if (has_valid_input_params) { |
| 470 buffer_size = |
| 471 std::min(kMaximumInputOutputBufferSize, |
| 472 std::max(input_params.frames_per_buffer(), buffer_size)); |
| 473 } |
| 474 |
| 475 const int bits_per_sample = has_valid_input_params ? |
| 476 input_params.bits_per_sample() : 16; |
| 477 |
465 return AudioParameters( | 478 return AudioParameters( |
466 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 479 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
467 sample_rate, 16, buffer_size); | 480 sample_rate, bits_per_sample, buffer_size); |
468 } | 481 } |
469 | 482 |
470 std::string AudioManagerMac::GetAssociatedOutputDeviceID( | 483 std::string AudioManagerMac::GetAssociatedOutputDeviceID( |
471 const std::string& input_device_id) { | 484 const std::string& input_device_id) { |
472 AudioDeviceID device = GetAudioDeviceIdByUId(true, input_device_id); | 485 AudioDeviceID device = GetAudioDeviceIdByUId(true, input_device_id); |
473 if (device == kAudioObjectUnknown) | 486 if (device == kAudioObjectUnknown) |
474 return std::string(); | 487 return std::string(); |
475 | 488 |
476 UInt32 size = 0; | 489 UInt32 size = 0; |
477 AudioObjectPropertyAddress pa = { | 490 AudioObjectPropertyAddress pa = { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { | 782 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { |
770 input_streams_.remove(stream); | 783 input_streams_.remove(stream); |
771 AudioManagerBase::ReleaseInputStream(stream); | 784 AudioManagerBase::ReleaseInputStream(stream); |
772 } | 785 } |
773 | 786 |
774 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 787 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
775 return new AudioManagerMac(audio_log_factory); | 788 return new AudioManagerMac(audio_log_factory); |
776 } | 789 } |
777 | 790 |
778 } // namespace media | 791 } // namespace media |
OLD | NEW |