Chromium Code Reviews| Index: media/audio/cras/audio_manager_cras.cc |
| diff --git a/media/audio/cras/audio_manager_cras.cc b/media/audio/cras/audio_manager_cras.cc |
| index 86d12fc39e5d504808b002083b85f9fb15a4b802..d74a20045de7b970cf1047757a3e757e69fb18a5 100644 |
| --- a/media/audio/cras/audio_manager_cras.cc |
| +++ b/media/audio/cras/audio_manager_cras.cc |
| @@ -23,28 +23,56 @@ |
| #undef max |
| namespace media { |
| +namespace { |
| -static void AddDefaultDevice(AudioDeviceNames* device_names) { |
| - DCHECK(device_names->empty()); |
| +// Maximum number of output streams that can be open simultaneously. |
| +const int kMaxOutputStreams = 50; |
| + |
| +// Default sample rate for input and output streams. |
| +const int kDefaultSampleRate = 48000; |
| + |
| +// Define bounds for the output buffer size. |
| +const int kMinimumOutputBufferSize = 512; |
| +const int kMaximumOutputBufferSize = 8192; |
| +// Default input buffer size. |
| +const int kDefaultInputBufferSize = 1024; |
| + |
| +void AddDefaultDevice(AudioDeviceNames* device_names) { |
| // Cras will route audio from a proper physical device automatically. |
| device_names->push_back( |
| AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
| AudioManagerBase::kDefaultDeviceId)); |
| } |
| -// Maximum number of output streams that can be open simultaneously. |
| -static const int kMaxOutputStreams = 50; |
| +// Returns a mic positions string if the machine has a beamforming capable |
| +// internal mic and otherwise an empty string. |
| +std::string MicPositions() { |
| + // Get the list of devices from CRAS. An internal mic with a non-empty |
| + // positions field indicates the machine has a beamforming capable mic array. |
| + chromeos::AudioDeviceList devices; |
| + chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| + for (const auto& device : devices) { |
| + if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { |
| + // There should be only one internal mic device. |
| + return device.mic_positions; |
| + } |
| + } |
| + return ""; |
| +} |
| -// Default sample rate for input and output streams. |
| -static const int kDefaultSampleRate = 48000; |
| +// Returns the name and ID of the virtual beamforming device. |
| +AudioDeviceName BeamformingDeviceName() { |
| + static const char kBeamformingDeviceNameSuffix[] = " with beamforming"; |
| + static const char kBeamformingDeviceIdSuffix[] = "-beamforming"; |
| -// Define bounds for the output buffer size. |
| -static const int kMinimumOutputBufferSize = 512; |
| -static const int kMaximumOutputBufferSize = 8192; |
| + return AudioDeviceName(std::string(AudioManagerBase::kDefaultDeviceName) + |
| + kBeamformingDeviceNameSuffix, |
| + std::string(AudioManagerBase::kDefaultDeviceId) + |
| + kBeamformingDeviceIdSuffix); |
| +} |
| -// Default input buffer size. |
| -static const int kDefaultInputBufferSize = 1024; |
| +} // namespace |
| bool AudioManagerCras::HasAudioOutputDevices() { |
| return true; |
| @@ -62,7 +90,8 @@ bool AudioManagerCras::HasAudioInputDevices() { |
| AudioManagerCras::AudioManagerCras(AudioLogFactory* audio_log_factory) |
| : AudioManagerBase(audio_log_factory), |
| - has_keyboard_mic_(false) { |
| + has_keyboard_mic_(false), |
| + beamforming_device_name_(BeamformingDeviceName()) { |
|
ajm
2015/09/03 01:38:42
Alex, I reverted to storing this as a const member
|
| SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| } |
| @@ -76,6 +105,13 @@ void AudioManagerCras::ShowAudioInputSettings() { |
| void AudioManagerCras::GetAudioInputDeviceNames( |
| AudioDeviceNames* device_names) { |
| + mic_positions_ = ParsePointsFromString(MicPositions()); |
| + // At least two mic positions indicates we have a beamforming capable mic |
| + // array. Add the virtual beamforming device to the list. When this device is |
| + // queried through GetInputStreamParameters, provide the cached mic positions. |
| + if (mic_positions_.size() > 1) |
| + device_names->push_back(beamforming_device_name_); |
| + |
| AddDefaultDevice(device_names); |
| } |
| @@ -95,11 +131,16 @@ AudioParameters AudioManagerCras::GetInputStreamParameters( |
| has_keyboard_mic_ ? AudioParameters::KEYBOARD_MIC |
| : AudioParameters::NO_EFFECTS; |
| + // Return the cached mic positions in the case of the beamforming device. |
| + const std::vector<Point>& mic_positions = |
| + device_id == beamforming_device_name_.unique_id ? mic_positions_ |
| + : std::vector<Point>(); |
| + |
| // TODO(hshi): Fine-tune audio parameters based on |device_id|. The optimal |
| // parameters for the loopback stream may differ from the default. |
| - return AudioParameters( |
| - AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| - kDefaultSampleRate, 16, buffer_size, effects); |
| + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| + CHANNEL_LAYOUT_STEREO, kDefaultSampleRate, 16, |
| + buffer_size, mic_positions, effects); |
| } |
| void AudioManagerCras::SetHasKeyboardMic() { |
| @@ -156,9 +197,8 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
| if (user_buffer_size) |
| buffer_size = user_buffer_size; |
| - return AudioParameters( |
| - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); |
| + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| + sample_rate, bits_per_sample, buffer_size); |
| } |
| AudioOutputStream* AudioManagerCras::MakeOutputStream( |