| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cras/audio_manager_cras.h" | 5 #include "media/audio/cras/audio_manager_cras.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Define bounds for the output buffer size. | 43 // Define bounds for the output buffer size. |
| 44 const int kMinimumOutputBufferSize = 512; | 44 const int kMinimumOutputBufferSize = 512; |
| 45 const int kMaximumOutputBufferSize = 8192; | 45 const int kMaximumOutputBufferSize = 8192; |
| 46 | 46 |
| 47 // Default input buffer size. | 47 // Default input buffer size. |
| 48 const int kDefaultInputBufferSize = 1024; | 48 const int kDefaultInputBufferSize = 1024; |
| 49 | 49 |
| 50 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; | 50 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
| 51 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; | 51 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
| 52 | 52 |
| 53 const char kInternalInputDevice[] = "Built-in mic"; | 53 const char kInternalInputVirtualDevice[] = "Built-in mic"; |
| 54 const char kInternalOutputDevice[] = "Built-in speaker"; | 54 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; |
| 55 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; |
| 55 | 56 |
| 56 enum CrosBeamformingDeviceState { | 57 enum CrosBeamformingDeviceState { |
| 57 BEAMFORMING_DEFAULT_ENABLED = 0, | 58 BEAMFORMING_DEFAULT_ENABLED = 0, |
| 58 BEAMFORMING_USER_ENABLED, | 59 BEAMFORMING_USER_ENABLED, |
| 59 BEAMFORMING_DEFAULT_DISABLED, | 60 BEAMFORMING_DEFAULT_DISABLED, |
| 60 BEAMFORMING_USER_DISABLED, | 61 BEAMFORMING_USER_DISABLED, |
| 61 BEAMFORMING_STATE_MAX = BEAMFORMING_USER_DISABLED | 62 BEAMFORMING_STATE_MAX = BEAMFORMING_USER_DISABLED |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 void RecordBeamformingDeviceState(CrosBeamformingDeviceState state) { | 65 void RecordBeamformingDeviceState(CrosBeamformingDeviceState state) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 81 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| 81 for (const auto& device : devices) { | 82 for (const auto& device : devices) { |
| 82 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { | 83 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { |
| 83 // There should be only one internal mic device. | 84 // There should be only one internal mic device. |
| 84 return device.mic_positions; | 85 return device.mic_positions; |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 return ""; | 88 return ""; |
| 88 } | 89 } |
| 89 | 90 |
| 91 // Process |device_list| that two shares the same dev_index by creating a |
| 92 // virtual device name for them. |
| 93 void ProcessVirtualDeviceName(AudioDeviceNames* device_names, |
| 94 const chromeos::AudioDeviceList& device_list) { |
| 95 DCHECK_EQ(2, device_list.size()); |
| 96 if (device_list[0].type == chromeos::AUDIO_TYPE_LINEOUT || |
| 97 device_list[1].type == chromeos::AUDIO_TYPE_LINEOUT) { |
| 98 device_names->emplace_back(kHeadphoneLineOutVirtualDevice, |
| 99 base::Uint64ToString(device_list[0].id)); |
| 100 } else if (device_list[0].type == chromeos::AUDIO_TYPE_INTERNAL_SPEAKER || |
| 101 device_list[1].type == chromeos::AUDIO_TYPE_INTERNAL_SPEAKER) { |
| 102 device_names->emplace_back(kInternalOutputVirtualDevice, |
| 103 base::Uint64ToString(device_list[0].id)); |
| 104 } else { |
| 105 DCHECK(device_list[0].type == chromeos::AUDIO_TYPE_INTERNAL_MIC || |
| 106 device_list[1].type == chromeos::AUDIO_TYPE_INTERNAL_MIC); |
| 107 device_names->emplace_back(kInternalInputVirtualDevice, |
| 108 base::Uint64ToString(device_list[0].id)); |
| 109 } |
| 110 } |
| 111 |
| 90 } // namespace | 112 } // namespace |
| 91 | 113 |
| 92 // Adds the beamforming on and off devices to |device_names|. | 114 // Adds the beamforming on and off devices to |device_names|. |
| 93 void AudioManagerCras::AddBeamformingDevices(AudioDeviceNames* device_names) { | 115 void AudioManagerCras::AddBeamformingDevices(AudioDeviceNames* device_names) { |
| 94 DCHECK(device_names->empty()); | 116 DCHECK(device_names->empty()); |
| 95 const std::string beamforming_on_name = | 117 const std::string beamforming_on_name = |
| 96 GetLocalizedStringUTF8(BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME); | 118 GetLocalizedStringUTF8(BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME); |
| 97 const std::string beamforming_off_name = | 119 const std::string beamforming_off_name = |
| 98 GetLocalizedStringUTF8(BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME); | 120 GetLocalizedStringUTF8(BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME); |
| 99 | 121 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // queried through GetInputStreamParameters, provide the cached mic positions. | 184 // queried through GetInputStreamParameters, provide the cached mic positions. |
| 163 if (is_input && mic_positions_.size() > 1) | 185 if (is_input && mic_positions_.size() > 1) |
| 164 AddBeamformingDevices(device_names); | 186 AddBeamformingDevices(device_names); |
| 165 else | 187 else |
| 166 device_names->push_back(AudioDeviceName::CreateDefault()); | 188 device_names->push_back(AudioDeviceName::CreateDefault()); |
| 167 | 189 |
| 168 if (base::FeatureList::IsEnabled(features::kEnumerateAudioDevices)) { | 190 if (base::FeatureList::IsEnabled(features::kEnumerateAudioDevices)) { |
| 169 chromeos::AudioDeviceList devices; | 191 chromeos::AudioDeviceList devices; |
| 170 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 192 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| 171 | 193 |
| 172 int internal_input_dev_index = 0; | 194 // |dev_idx_map| is a map of dev_index and their audio devices. |
| 173 int internal_output_dev_index = 0; | 195 std::map<int, chromeos::AudioDeviceList> dev_idx_map; |
| 174 for (const auto& device : devices) { | 196 for (const auto& device : devices) { |
| 175 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) | 197 if (device.is_input != is_input || !device.is_for_simple_usage()) |
| 176 internal_input_dev_index = dev_index_of(device.id); | 198 continue; |
| 177 else if (device.type == chromeos::AUDIO_TYPE_INTERNAL_SPEAKER) | 199 |
| 178 internal_output_dev_index = dev_index_of(device.id); | 200 dev_idx_map[dev_index_of(device.id)].push_back(device); |
| 179 } | 201 } |
| 180 | 202 |
| 181 bool has_internal_input = false; | 203 for (const auto& item : dev_idx_map) { |
| 182 bool has_internal_output = false; | 204 if (1 == item.second.size()) { |
| 183 for (const auto& device : devices) { | 205 const chromeos::AudioDevice& device = item.second.front(); |
| 184 if (device.is_input == is_input && device.is_for_simple_usage()) { | 206 device_names->emplace_back(device.display_name, |
| 185 int dev_index = dev_index_of(device.id); | 207 base::Uint64ToString(device.id)); |
| 186 if (dev_index == internal_input_dev_index) { | 208 } else { |
| 187 if (!has_internal_input) { | 209 // Create virtual device name for audio nodes that share the same device |
| 188 device_names->emplace_back(kInternalInputDevice, | 210 // index. |
| 189 base::Uint64ToString(device.id)); | 211 ProcessVirtualDeviceName(device_names, item.second); |
| 190 has_internal_input = true; | |
| 191 } | |
| 192 } else if (dev_index == internal_output_dev_index) { | |
| 193 if (!has_internal_output) { | |
| 194 device_names->emplace_back(kInternalOutputDevice, | |
| 195 base::Uint64ToString(device.id)); | |
| 196 has_internal_output = true; | |
| 197 } | |
| 198 } else { | |
| 199 device_names->emplace_back(device.display_name, | |
| 200 base::Uint64ToString(device.id)); | |
| 201 } | |
| 202 } | 212 } |
| 203 } | 213 } |
| 204 } | 214 } |
| 205 } | 215 } |
| 206 | 216 |
| 207 void AudioManagerCras::GetAudioInputDeviceNames( | 217 void AudioManagerCras::GetAudioInputDeviceNames( |
| 208 AudioDeviceNames* device_names) { | 218 AudioDeviceNames* device_names) { |
| 209 mic_positions_ = ParsePointsFromString(MicPositions()); | 219 mic_positions_ = ParsePointsFromString(MicPositions()); |
| 210 GetAudioDeviceNamesImpl(true, device_names); | 220 GetAudioDeviceNamesImpl(true, device_names); |
| 211 } | 221 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 369 |
| 360 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | 370 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
| 361 AudioDeviceNames device_names; | 371 AudioDeviceNames device_names; |
| 362 GetAudioDeviceNamesImpl(is_input, &device_names); | 372 GetAudioDeviceNamesImpl(is_input, &device_names); |
| 363 DCHECK(!device_names.empty()); | 373 DCHECK(!device_names.empty()); |
| 364 const AudioDeviceName& device_name = device_names.front(); | 374 const AudioDeviceName& device_name = device_names.front(); |
| 365 return device_name.unique_id == device_id; | 375 return device_name.unique_id == device_id; |
| 366 } | 376 } |
| 367 | 377 |
| 368 } // namespace media | 378 } // namespace media |
| OLD | NEW |