| 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..be2b550b1d1e9cd07a21bbd883e761217e3f06c9 100644
|
| --- a/media/audio/cras/audio_manager_cras.cc
|
| +++ b/media/audio/cras/audio_manager_cras.cc
|
| @@ -23,28 +23,46 @@
|
| #undef max
|
|
|
| namespace media {
|
| +namespace {
|
|
|
| -static void AddDefaultDevice(AudioDeviceNames* device_names) {
|
| - DCHECK(device_names->empty());
|
| -
|
| +void AddDefaultDevice(AudioDeviceNames* device_names) {
|
| // Cras will route audio from a proper physical device automatically.
|
| device_names->push_back(
|
| AudioDeviceName(AudioManagerBase::kDefaultDeviceName,
|
| AudioManagerBase::kDefaultDeviceId));
|
| }
|
|
|
| +std::string GetMicPositions() {
|
| + // 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 "";
|
| +}
|
| +
|
| // Maximum number of output streams that can be open simultaneously.
|
| -static const int kMaxOutputStreams = 50;
|
| +const int kMaxOutputStreams = 50;
|
|
|
| // Default sample rate for input and output streams.
|
| -static const int kDefaultSampleRate = 48000;
|
| +const int kDefaultSampleRate = 48000;
|
|
|
| // Define bounds for the output buffer size.
|
| -static const int kMinimumOutputBufferSize = 512;
|
| -static const int kMaximumOutputBufferSize = 8192;
|
| +const int kMinimumOutputBufferSize = 512;
|
| +const int kMaximumOutputBufferSize = 8192;
|
|
|
| // Default input buffer size.
|
| -static const int kDefaultInputBufferSize = 1024;
|
| +const int kDefaultInputBufferSize = 1024;
|
| +
|
| +const char kBeamformingDeviceNameSuffix[] = " with beamforming";
|
| +const char kBeamformingDeviceIdSuffix[] = "-beamforming";
|
| +
|
| +} // namespace
|
|
|
| bool AudioManagerCras::HasAudioOutputDevices() {
|
| return true;
|
| @@ -62,7 +80,13 @@ bool AudioManagerCras::HasAudioInputDevices() {
|
|
|
| AudioManagerCras::AudioManagerCras(AudioLogFactory* audio_log_factory)
|
| : AudioManagerBase(audio_log_factory),
|
| - has_keyboard_mic_(false) {
|
| + has_keyboard_mic_(false),
|
| + beamforming_device_name_(
|
| + std::string(AudioManagerBase::kDefaultDeviceName) +
|
| + kBeamformingDeviceNameSuffix,
|
| + std::string(AudioManagerBase::kDefaultDeviceId) +
|
| + kBeamformingDeviceIdSuffix),
|
| + mic_positions_(GetMicPositions()) {
|
| SetMaxOutputStreamsAllowed(kMaxOutputStreams);
|
| }
|
|
|
| @@ -76,6 +100,13 @@ void AudioManagerCras::ShowAudioInputSettings() {
|
|
|
| void AudioManagerCras::GetAudioInputDeviceNames(
|
| AudioDeviceNames* device_names) {
|
| + // A non-empty 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_.empty()) {
|
| + device_names->push_back(beamforming_device_name_);
|
| + }
|
| +
|
| AddDefaultDevice(device_names);
|
| }
|
|
|
| @@ -94,12 +125,15 @@ AudioParameters AudioManagerCras::GetInputStreamParameters(
|
| AudioParameters::PlatformEffectsMask effects =
|
| has_keyboard_mic_ ? AudioParameters::KEYBOARD_MIC
|
| : AudioParameters::NO_EFFECTS;
|
| + // Return the cached mic positions in the case of the beamforming device.
|
| + const std::string& mic_positions =
|
| + device_id == beamforming_device_name_.unique_id ? mic_positions_ : "";
|
|
|
| // 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 +190,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(
|
|
|