François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "APM::AudioPolicyEngine" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | //#define VERY_VERBOSE_LOGGING |
| 21 | #ifdef VERY_VERBOSE_LOGGING |
| 22 | #define ALOGVV ALOGV |
| 23 | #else |
| 24 | #define ALOGVV(a...) do { } while(0) |
| 25 | #endif |
| 26 | |
| 27 | #include "Engine.h" |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 28 | #include <android-base/macros.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 29 | #include <AudioPolicyManagerObserver.h> |
jiabin | e128485 | 2019-09-11 10:15:46 -0700 | [diff] [blame] | 30 | #include <PolicyAudioPort.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 31 | #include <IOProfile.h> |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 32 | #include <AudioIODescriptorInterface.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 33 | #include <policy.h> |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 34 | #include <media/AudioContainers.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 35 | #include <utils/String8.h> |
| 36 | #include <utils/Log.h> |
| 37 | |
| 38 | namespace android |
| 39 | { |
| 40 | namespace audio_policy |
| 41 | { |
| 42 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 43 | struct legacy_strategy_map { const char *name; legacy_strategy id; }; |
Mikhail Naganov | f900362 | 2020-03-10 13:15:08 -0700 | [diff] [blame] | 44 | static const std::vector<legacy_strategy_map>& getLegacyStrategy() { |
| 45 | static const std::vector<legacy_strategy_map> legacyStrategy = { |
| 46 | { "STRATEGY_NONE", STRATEGY_NONE }, |
| 47 | { "STRATEGY_MEDIA", STRATEGY_MEDIA }, |
| 48 | { "STRATEGY_PHONE", STRATEGY_PHONE }, |
| 49 | { "STRATEGY_SONIFICATION", STRATEGY_SONIFICATION }, |
| 50 | { "STRATEGY_SONIFICATION_RESPECTFUL", STRATEGY_SONIFICATION_RESPECTFUL }, |
| 51 | { "STRATEGY_DTMF", STRATEGY_DTMF }, |
| 52 | { "STRATEGY_ENFORCED_AUDIBLE", STRATEGY_ENFORCED_AUDIBLE }, |
| 53 | { "STRATEGY_TRANSMITTED_THROUGH_SPEAKER", STRATEGY_TRANSMITTED_THROUGH_SPEAKER }, |
| 54 | { "STRATEGY_ACCESSIBILITY", STRATEGY_ACCESSIBILITY }, |
| 55 | { "STRATEGY_REROUTING", STRATEGY_REROUTING }, |
| 56 | { "STRATEGY_PATCH", STRATEGY_REROUTING }, // boiler to manage stream patch volume |
| 57 | { "STRATEGY_CALL_ASSISTANT", STRATEGY_CALL_ASSISTANT }, |
| 58 | }; |
| 59 | return legacyStrategy; |
| 60 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 61 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 62 | Engine::Engine() |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 63 | { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 64 | auto result = EngineBase::loadAudioPolicyEngineConfig(); |
| 65 | ALOGE_IF(result.nbSkippedElement != 0, |
| 66 | "Policy Engine configuration is partially invalid, skipped %zu elements", |
| 67 | result.nbSkippedElement); |
| 68 | |
Mikhail Naganov | f900362 | 2020-03-10 13:15:08 -0700 | [diff] [blame] | 69 | auto legacyStrategy = getLegacyStrategy(); |
| 70 | for (const auto &strategy : legacyStrategy) { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 71 | mLegacyStrategyMap[getProductStrategyByName(strategy.name)] = strategy.id; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 75 | status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
| 76 | { |
| 77 | switch(usage) { |
| 78 | case AUDIO_POLICY_FORCE_FOR_COMMUNICATION: |
| 79 | if (config != AUDIO_POLICY_FORCE_SPEAKER && config != AUDIO_POLICY_FORCE_BT_SCO && |
| 80 | config != AUDIO_POLICY_FORCE_NONE) { |
| 81 | ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config); |
| 82 | return BAD_VALUE; |
| 83 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 84 | break; |
| 85 | case AUDIO_POLICY_FORCE_FOR_MEDIA: |
| 86 | if (config != AUDIO_POLICY_FORCE_HEADPHONES && config != AUDIO_POLICY_FORCE_BT_A2DP && |
| 87 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 88 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 89 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK && config != AUDIO_POLICY_FORCE_NONE && |
| 90 | config != AUDIO_POLICY_FORCE_NO_BT_A2DP && config != AUDIO_POLICY_FORCE_SPEAKER ) { |
| 91 | ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config); |
| 92 | return BAD_VALUE; |
| 93 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 94 | break; |
| 95 | case AUDIO_POLICY_FORCE_FOR_RECORD: |
| 96 | if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 97 | config != AUDIO_POLICY_FORCE_NONE) { |
| 98 | ALOGW("setForceUse() invalid config %d for FOR_RECORD", config); |
| 99 | return BAD_VALUE; |
| 100 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 101 | break; |
| 102 | case AUDIO_POLICY_FORCE_FOR_DOCK: |
| 103 | if (config != AUDIO_POLICY_FORCE_NONE && config != AUDIO_POLICY_FORCE_BT_CAR_DOCK && |
| 104 | config != AUDIO_POLICY_FORCE_BT_DESK_DOCK && |
| 105 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 106 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 107 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK) { |
| 108 | ALOGW("setForceUse() invalid config %d for FOR_DOCK", config); |
| 109 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 110 | break; |
| 111 | case AUDIO_POLICY_FORCE_FOR_SYSTEM: |
| 112 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 113 | config != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) { |
| 114 | ALOGW("setForceUse() invalid config %d for FOR_SYSTEM", config); |
| 115 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 116 | break; |
| 117 | case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO: |
| 118 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 119 | config != AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED) { |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 120 | ALOGW("setForceUse() invalid config %d for HDMI_SYSTEM_AUDIO", config); |
| 121 | } |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 122 | break; |
| 123 | case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND: |
| 124 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 125 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER && |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 126 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS && |
| 127 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL) { |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 128 | ALOGW("setForceUse() invalid config %d for ENCODED_SURROUND", config); |
| 129 | return BAD_VALUE; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 130 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 131 | break; |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 132 | case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING: |
| 133 | if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_NONE) { |
| 134 | ALOGW("setForceUse() invalid config %d for FOR_VIBRATE_RINGING", config); |
| 135 | return BAD_VALUE; |
| 136 | } |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 137 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 138 | default: |
| 139 | ALOGW("setForceUse() invalid usage %d", usage); |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 140 | break; // TODO return BAD_VALUE? |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 141 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 142 | return EngineBase::setForceUse(usage, config); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 145 | void Engine::filterOutputDevicesForStrategy(legacy_strategy strategy, |
| 146 | DeviceVector& availableOutputDevices, |
| 147 | const DeviceVector availableInputDevices, |
| 148 | const SwAudioOutputCollection &outputs) const |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 149 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 150 | switch (strategy) { |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 151 | case STRATEGY_SONIFICATION_RESPECTFUL: { |
| 152 | if (!(isInCall() || outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL)))) { |
Jean-Michel Trivi | 6130952 | 2018-01-23 09:58:17 -0800 | [diff] [blame] | 153 | // routing is same as media without the "remote" device |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 154 | availableOutputDevices.remove(availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 155 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 156 | } |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 157 | } break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 158 | case STRATEGY_DTMF: |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 159 | case STRATEGY_PHONE: { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 160 | // Force use of only devices on primary output if: |
| 161 | // - in call AND |
| 162 | // - cannot route from voice call RX OR |
| 163 | // - audio HAL version is < 3.0 and TX device is on the primary HW module |
| 164 | if (getPhoneState() == AUDIO_MODE_IN_CALL) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 165 | audio_devices_t txDevice = getDeviceForInputSource( |
| 166 | AUDIO_SOURCE_VOICE_COMMUNICATION)->type(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 167 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 168 | LOG_ALWAYS_FATAL_IF(primaryOutput == nullptr, "Primary output not found"); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 169 | DeviceVector availPrimaryInputDevices = |
| 170 | availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()); |
Eric Laurent | 58a73fc | 2018-02-21 18:46:13 -0800 | [diff] [blame] | 171 | |
| 172 | // TODO: getPrimaryOutput return only devices from first module in |
| 173 | // audio_policy_configuration.xml, hearing aid is not there, but it's |
| 174 | // a primary device |
| 175 | // FIXME: this is not the right way of solving this problem |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 176 | DeviceVector availPrimaryOutputDevices = availableOutputDevices.getDevicesFromTypes( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 177 | primaryOutput->supportedDevices().types()); |
| 178 | availPrimaryOutputDevices.add( |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 179 | availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_HEARING_AID)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 180 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 181 | if ((availableInputDevices.getDevice(AUDIO_DEVICE_IN_TELEPHONY_RX, |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 182 | String8(""), AUDIO_FORMAT_DEFAULT) == nullptr) || |
| 183 | ((availPrimaryInputDevices.getDevice( |
| 184 | txDevice, String8(""), AUDIO_FORMAT_DEFAULT) != nullptr) && |
| 185 | (primaryOutput->getPolicyAudioPort()->getModuleVersionMajor() < 3))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 186 | availableOutputDevices = availPrimaryOutputDevices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 187 | } |
| 188 | } |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 189 | } break; |
| 190 | case STRATEGY_ACCESSIBILITY: { |
| 191 | // do not route accessibility prompts to a digital output currently configured with a |
| 192 | // compressed format as they would likely not be mixed and dropped. |
| 193 | for (size_t i = 0; i < outputs.size(); i++) { |
| 194 | sp<AudioOutputDescriptor> desc = outputs.valueAt(i); |
| 195 | if (desc->isActive() && !audio_is_linear_pcm(desc->getFormat())) { |
| 196 | availableOutputDevices.remove(desc->devices().getDevicesFromTypes({ |
| 197 | AUDIO_DEVICE_OUT_HDMI, AUDIO_DEVICE_OUT_SPDIF, |
| 198 | AUDIO_DEVICE_OUT_HDMI_ARC})); |
| 199 | } |
| 200 | } |
| 201 | } break; |
| 202 | default: |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy, |
| 208 | DeviceVector availableOutputDevices, |
| 209 | DeviceVector availableInputDevices, |
| 210 | const SwAudioOutputCollection &outputs) const |
| 211 | { |
| 212 | DeviceVector devices; |
| 213 | |
| 214 | switch (strategy) { |
| 215 | |
| 216 | case STRATEGY_TRANSMITTED_THROUGH_SPEAKER: |
| 217 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
| 218 | break; |
| 219 | |
| 220 | case STRATEGY_SONIFICATION_RESPECTFUL: |
| 221 | if (isInCall() || outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL))) { |
| 222 | devices = getDevicesForStrategyInt( |
| 223 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
| 224 | } else { |
| 225 | bool media_active_locally = |
| 226 | outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_MUSIC), |
| 227 | SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY) |
| 228 | || outputs.isActiveLocally( |
| 229 | toVolumeSource(AUDIO_STREAM_ACCESSIBILITY), |
| 230 | SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY); |
| 231 | devices = getDevicesForStrategyInt(STRATEGY_MEDIA, |
| 232 | availableOutputDevices, |
| 233 | availableInputDevices, outputs); |
| 234 | // if no media is playing on the device, check for mandatory use of "safe" speaker |
| 235 | // when media would have played on speaker, and the safe speaker path is available |
| 236 | if (!media_active_locally) { |
| 237 | devices.replaceDevicesByType( |
| 238 | AUDIO_DEVICE_OUT_SPEAKER, |
| 239 | availableOutputDevices.getDevicesFromType( |
| 240 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)); |
| 241 | } |
| 242 | } |
| 243 | break; |
| 244 | |
| 245 | case STRATEGY_DTMF: |
| 246 | case STRATEGY_PHONE: { |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 247 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_HEARING_AID); |
| 248 | if (!devices.isEmpty()) break; |
| 249 | devices = availableOutputDevices.getFirstDevicesFromTypes({ |
| 250 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE, |
| 251 | AUDIO_DEVICE_OUT_WIRED_HEADSET, |
| 252 | AUDIO_DEVICE_OUT_LINE, |
| 253 | AUDIO_DEVICE_OUT_USB_HEADSET, |
| 254 | AUDIO_DEVICE_OUT_USB_DEVICE}); |
| 255 | if (!devices.isEmpty()) break; |
| 256 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE); |
| 257 | } break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 258 | |
| 259 | case STRATEGY_SONIFICATION: |
| 260 | |
Eric Laurent | dcd4ab1 | 2018-06-29 17:45:13 -0700 | [diff] [blame] | 261 | // If incall, just select the STRATEGY_PHONE device |
François Gaffie | 1c87855 | 2018-11-22 16:53:21 +0100 | [diff] [blame] | 262 | if (isInCall() || |
Eric Laurent | 83d17c2 | 2019-04-02 17:10:01 -0700 | [diff] [blame] | 263 | outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 264 | devices = getDevicesForStrategyInt( |
| 265 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 266 | break; |
| 267 | } |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 268 | FALLTHROUGH_INTENDED; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 269 | |
| 270 | case STRATEGY_ENFORCED_AUDIBLE: |
| 271 | // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION |
| 272 | // except: |
| 273 | // - when in call where it doesn't default to STRATEGY_PHONE behavior |
| 274 | // - in countries where not enforced in which case it follows STRATEGY_MEDIA |
| 275 | |
| 276 | if ((strategy == STRATEGY_SONIFICATION) || |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 277 | (getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 278 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 279 | } |
Eric Laurent | a8e0f02 | 2017-01-27 17:41:53 -0800 | [diff] [blame] | 280 | |
| 281 | // if SCO headset is connected and we are told to use it, play ringtone over |
| 282 | // speaker and BT SCO |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 283 | if (!availableOutputDevices.getDevicesFromTypes(getAudioDeviceOutAllScoSet()).isEmpty()) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 284 | DeviceVector devices2; |
| 285 | devices2 = availableOutputDevices.getFirstDevicesFromTypes({ |
| 286 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, |
| 287 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO}); |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 288 | // Use ONLY Bluetooth SCO output when ringing in vibration mode |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 289 | if (!((getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 290 | && (strategy == STRATEGY_ENFORCED_AUDIBLE))) { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 291 | if (getForceUse(AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING) |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 292 | == AUDIO_POLICY_FORCE_BT_SCO) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 293 | if (!devices2.isEmpty()) { |
| 294 | devices = devices2; |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | // Use both Bluetooth SCO and phone default output when ringing in normal mode |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 300 | if (audio_is_bluetooth_out_sco_device(getPreferredDeviceTypeForLegacyStrategy( |
| 301 | availableOutputDevices, STRATEGY_PHONE))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 302 | if (strategy == STRATEGY_SONIFICATION) { |
| 303 | devices.replaceDevicesByType( |
| 304 | AUDIO_DEVICE_OUT_SPEAKER, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 305 | availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 306 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)); |
juyuchen | 5fa0aed | 2018-05-16 10:58:37 +0800 | [diff] [blame] | 307 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 308 | if (!devices2.isEmpty()) { |
| 309 | devices.add(devices2); |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 310 | break; |
| 311 | } |
Eric Laurent | a8e0f02 | 2017-01-27 17:41:53 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 314 | // The second device used for sonification is the same as the device used by media strategy |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 315 | FALLTHROUGH_INTENDED; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 316 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 317 | case STRATEGY_ACCESSIBILITY: |
| 318 | if (strategy == STRATEGY_ACCESSIBILITY) { |
Eric Laurent | 83d17c2 | 2019-04-02 17:10:01 -0700 | [diff] [blame] | 319 | if (outputs.isActive(toVolumeSource(AUDIO_STREAM_RING)) || |
| 320 | outputs.isActive(toVolumeSource(AUDIO_STREAM_ALARM))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 321 | return getDevicesForStrategyInt( |
| 322 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 323 | } |
| 324 | if (isInCall()) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 325 | return getDevicesForStrategyInt( |
| 326 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 327 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 328 | } |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 329 | // For other cases, STRATEGY_ACCESSIBILITY behaves like STRATEGY_MEDIA |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 330 | FALLTHROUGH_INTENDED; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 331 | |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 332 | // FIXME: STRATEGY_REROUTING follow STRATEGY_MEDIA for now |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 333 | case STRATEGY_REROUTING: |
| 334 | case STRATEGY_MEDIA: { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 335 | DeviceVector devices2; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 336 | if (strategy != STRATEGY_SONIFICATION) { |
| 337 | // no sonification on remote submix (e.g. WFD) |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 338 | sp<DeviceDescriptor> remoteSubmix; |
| 339 | if ((remoteSubmix = availableOutputDevices.getDevice( |
| 340 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, String8("0"), |
| 341 | AUDIO_FORMAT_DEFAULT)) != nullptr) { |
| 342 | devices2.add(remoteSubmix); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 343 | } |
| 344 | } |
Eric Laurent | a20d4fa | 2015-06-04 18:39:28 -0700 | [diff] [blame] | 345 | if (isInCall() && (strategy == STRATEGY_MEDIA)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 346 | devices = getDevicesForStrategyInt( |
| 347 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
Eric Laurent | a20d4fa | 2015-06-04 18:39:28 -0700 | [diff] [blame] | 348 | break; |
| 349 | } |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 350 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 351 | if ((devices2.isEmpty()) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 352 | (getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA) == AUDIO_POLICY_FORCE_SPEAKER)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 353 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 354 | } |
Baekgyeong Kim | 0845152 | 2019-11-01 20:40:02 +0900 | [diff] [blame] | 355 | if (devices2.isEmpty() && (getLastRemovableMediaDevices().size() > 0)) { |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 356 | if ((getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA) != AUDIO_POLICY_FORCE_NO_BT_A2DP)) { |
Baekgyeong Kim | 0845152 | 2019-11-01 20:40:02 +0900 | [diff] [blame] | 357 | // Get the last connected device of wired and bluetooth a2dp |
| 358 | devices2 = availableOutputDevices.getFirstDevicesFromTypes( |
| 359 | getLastRemovableMediaDevices()); |
| 360 | } else { |
| 361 | // Get the last connected device of wired except bluetooth a2dp |
| 362 | devices2 = availableOutputDevices.getFirstDevicesFromTypes( |
| 363 | getLastRemovableMediaDevices(GROUP_WIRED)); |
| 364 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 365 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 366 | if ((devices2.isEmpty()) && (strategy != STRATEGY_SONIFICATION)) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 367 | // no sonification on aux digital (e.g. HDMI) |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 368 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_AUX_DIGITAL); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 369 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 370 | if ((devices2.isEmpty()) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 371 | (getForceUse(AUDIO_POLICY_FORCE_FOR_DOCK) == AUDIO_POLICY_FORCE_ANALOG_DOCK)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 372 | devices2 = availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 373 | AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 374 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 375 | if (devices2.isEmpty()) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 376 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 377 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 378 | DeviceVector devices3; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 379 | if (strategy == STRATEGY_MEDIA) { |
| 380 | // ARC, SPDIF and AUX_LINE can co-exist with others. |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 381 | devices3 = availableOutputDevices.getDevicesFromTypes({ |
| 382 | AUDIO_DEVICE_OUT_HDMI_ARC, AUDIO_DEVICE_OUT_SPDIF, AUDIO_DEVICE_OUT_AUX_LINE}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 383 | } |
| 384 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 385 | devices2.add(devices3); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 386 | // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or |
| 387 | // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 388 | devices.add(devices2); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 389 | |
| 390 | // If hdmi system audio mode is on, remove speaker out of output list. |
| 391 | if ((strategy == STRATEGY_MEDIA) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 392 | (getForceUse(AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO) == |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 393 | AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 394 | devices.remove(devices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 395 | } |
Jean-Michel Trivi | 654afa0 | 2017-05-11 14:12:33 -0700 | [diff] [blame] | 396 | |
| 397 | // for STRATEGY_SONIFICATION: |
| 398 | // if SPEAKER was selected, and SPEAKER_SAFE is available, use SPEAKER_SAFE instead |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 399 | if (strategy == STRATEGY_SONIFICATION) { |
| 400 | devices.replaceDevicesByType( |
| 401 | AUDIO_DEVICE_OUT_SPEAKER, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 402 | availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 403 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)); |
Jean-Michel Trivi | 654afa0 | 2017-05-11 14:12:33 -0700 | [diff] [blame] | 404 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 405 | } break; |
| 406 | |
Eric Laurent | 21777f8 | 2019-12-06 18:12:06 -0800 | [diff] [blame] | 407 | case STRATEGY_CALL_ASSISTANT: |
| 408 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_TELEPHONY_TX); |
| 409 | break; |
| 410 | |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 411 | case STRATEGY_NONE: |
| 412 | // Happens when internal strategies are processed ("rerouting", "patch"...) |
| 413 | break; |
| 414 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 415 | default: |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 416 | ALOGW("%s unknown strategy: %d", __func__, strategy); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 417 | break; |
| 418 | } |
| 419 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 420 | if (devices.isEmpty()) { |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 421 | ALOGV("%s no device found for strategy %d", __func__, strategy); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 422 | sp<DeviceDescriptor> defaultOutputDevice = getApmObserver()->getDefaultOutputDevice(); |
| 423 | if (defaultOutputDevice != nullptr) { |
| 424 | devices.add(defaultOutputDevice); |
| 425 | } |
| 426 | ALOGE_IF(devices.isEmpty(), |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 427 | "%s no default device defined", __func__); |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 428 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 429 | |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 430 | ALOGVV("%s strategy %d, device %s", __func__, |
jiabin | cd51052 | 2020-01-22 09:40:55 -0800 | [diff] [blame] | 431 | strategy, dumpDeviceTypes(devices.types()).c_str()); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 432 | return devices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 436 | sp<DeviceDescriptor> Engine::getDeviceForInputSource(audio_source_t inputSource) const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 437 | { |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 438 | const DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
| 439 | const DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 440 | const SwAudioOutputCollection &outputs = getApmObserver()->getOutputs(); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 441 | DeviceVector availableDevices = availableInputDevices; |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 442 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 443 | DeviceVector availablePrimaryDevices = primaryOutput == nullptr ? DeviceVector() |
| 444 | : availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 445 | sp<DeviceDescriptor> device; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 446 | |
Eric Laurent | dc95a25 | 2018-04-12 12:46:56 -0700 | [diff] [blame] | 447 | // when a call is active, force device selection to match source VOICE_COMMUNICATION |
| 448 | // for most other input sources to avoid rerouting call TX audio |
| 449 | if (isInCall()) { |
| 450 | switch (inputSource) { |
| 451 | case AUDIO_SOURCE_DEFAULT: |
| 452 | case AUDIO_SOURCE_MIC: |
| 453 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 454 | case AUDIO_SOURCE_UNPROCESSED: |
| 455 | case AUDIO_SOURCE_HOTWORD: |
| 456 | case AUDIO_SOURCE_CAMCORDER: |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 457 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
Eric Laurent | dc95a25 | 2018-04-12 12:46:56 -0700 | [diff] [blame] | 458 | inputSource = AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 459 | break; |
| 460 | default: |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 465 | audio_devices_t commDeviceType = |
| 466 | getPreferredDeviceTypeForLegacyStrategy(availableOutputDevices, STRATEGY_PHONE); |
| 467 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 468 | switch (inputSource) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 469 | case AUDIO_SOURCE_DEFAULT: |
| 470 | case AUDIO_SOURCE_MIC: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 471 | device = availableDevices.getDevice( |
| 472 | AUDIO_DEVICE_IN_BLUETOOTH_A2DP, String8(""), AUDIO_FORMAT_DEFAULT); |
| 473 | if (device != nullptr) break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 474 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 475 | device = availableDevices.getDevice( |
| 476 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 477 | if (device != nullptr) break; |
| 478 | } |
| 479 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 480 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 481 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 482 | AUDIO_DEVICE_IN_BLUETOOTH_BLE, AUDIO_DEVICE_IN_BUILTIN_MIC}); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 483 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 484 | |
| 485 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 486 | // Allow only use of devices on primary input if in call and HAL does not support routing |
| 487 | // to voice call path. |
| 488 | if ((getPhoneState() == AUDIO_MODE_IN_CALL) && |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 489 | (availableOutputDevices.getDevice(AUDIO_DEVICE_OUT_TELEPHONY_TX, |
| 490 | String8(""), AUDIO_FORMAT_DEFAULT)) == nullptr) { |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 491 | LOG_ALWAYS_FATAL_IF(availablePrimaryDevices.isEmpty(), "Primary devices not found"); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 492 | availableDevices = availablePrimaryDevices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 493 | } |
| 494 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 495 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 496 | // if SCO device is requested but no SCO device is available, fall back to default case |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 497 | device = availableDevices.getDevice( |
| 498 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 499 | if (device != nullptr) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 500 | break; |
| 501 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 502 | } |
| 503 | switch (commDeviceType) { |
| 504 | case AUDIO_DEVICE_OUT_BLE_HEADSET: |
| 505 | device = availableDevices.getDevice( |
| 506 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 507 | break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 508 | case AUDIO_DEVICE_OUT_SPEAKER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 509 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | 6435dd7 | 2020-12-02 14:42:42 +0100 | [diff] [blame] | 510 | AUDIO_DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC, |
| 511 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_USB_HEADSET}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 512 | break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 513 | default: // FORCE_NONE |
| 514 | device = availableDevices.getFirstExistingDevice({ |
| 515 | AUDIO_DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_USB_HEADSET, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 516 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_BLUETOOTH_BLE, |
| 517 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 518 | break; |
| 519 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 520 | } |
| 521 | break; |
| 522 | |
| 523 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
rago | 8a397d5 | 2015-12-02 11:27:57 -0800 | [diff] [blame] | 524 | case AUDIO_SOURCE_UNPROCESSED: |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 525 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
| 526 | device = availableDevices.getDevice( |
| 527 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 528 | if (device != nullptr) break; |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 529 | } |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 530 | // we need to make BLUETOOTH_BLE has higher priority than BUILTIN_MIC, |
| 531 | // because sometimes user want to do voice search by bt remote |
| 532 | // even if BUILDIN_MIC is available. |
| 533 | device = availableDevices.getFirstExistingDevice({ |
| 534 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 535 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
| 536 | AUDIO_DEVICE_IN_BLUETOOTH_BLE, AUDIO_DEVICE_IN_BUILTIN_MIC}); |
| 537 | |
| 538 | break; |
| 539 | case AUDIO_SOURCE_HOTWORD: |
| 540 | // We should not use primary output criteria for Hotword but rather limit |
| 541 | // to devices attached to the same HW module as the build in mic |
| 542 | LOG_ALWAYS_FATAL_IF(availablePrimaryDevices.isEmpty(), "Primary devices not found"); |
| 543 | availableDevices = availablePrimaryDevices; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 544 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 545 | device = availableDevices.getDevice( |
| 546 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 547 | if (device != nullptr) break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 548 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 549 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 550 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 551 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
| 552 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 553 | break; |
| 554 | case AUDIO_SOURCE_CAMCORDER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 555 | // For a device without built-in mic, adding usb device |
| 556 | device = availableDevices.getFirstExistingDevice({ |
| 557 | AUDIO_DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC, |
| 558 | AUDIO_DEVICE_IN_USB_DEVICE}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 559 | break; |
| 560 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 561 | case AUDIO_SOURCE_VOICE_CALL: |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 562 | case AUDIO_SOURCE_VOICE_UPLINK: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 563 | device = availableDevices.getDevice( |
| 564 | AUDIO_DEVICE_IN_VOICE_CALL, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 565 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 566 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 567 | device = availableDevices.getFirstExistingDevice({ |
| 568 | AUDIO_DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_USB_HEADSET, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 569 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_BLUETOOTH_BLE, |
| 570 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 571 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 572 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 573 | device = availableDevices.getDevice( |
| 574 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 575 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 576 | case AUDIO_SOURCE_FM_TUNER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 577 | device = availableDevices.getDevice( |
| 578 | AUDIO_DEVICE_IN_FM_TUNER, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 579 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 580 | case AUDIO_SOURCE_ECHO_REFERENCE: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 581 | device = availableDevices.getDevice( |
| 582 | AUDIO_DEVICE_IN_ECHO_REFERENCE, String8(""), AUDIO_FORMAT_DEFAULT); |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 583 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 584 | default: |
| 585 | ALOGW("getDeviceForInputSource() invalid input source %d", inputSource); |
| 586 | break; |
| 587 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 588 | if (device == nullptr) { |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 589 | ALOGV("getDeviceForInputSource() no device found for source %d", inputSource); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 590 | device = availableDevices.getDevice( |
| 591 | AUDIO_DEVICE_IN_STUB, String8(""), AUDIO_FORMAT_DEFAULT); |
| 592 | ALOGE_IF(device == nullptr, |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 593 | "getDeviceForInputSource() no default device defined"); |
| 594 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 595 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 596 | ALOGV_IF(device != nullptr, |
| 597 | "getDeviceForInputSource()input source %d, device %08x", |
| 598 | inputSource, device->type()); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 599 | return device; |
| 600 | } |
| 601 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 602 | void Engine::updateDeviceSelectionCache() |
| 603 | { |
| 604 | for (const auto &iter : getProductStrategies()) { |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 605 | const auto& strategy = iter.second; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 606 | auto devices = getDevicesForProductStrategy(strategy->getId()); |
| 607 | mDevicesForStrategies[strategy->getId()] = devices; |
| 608 | strategy->setDeviceTypes(devices.types()); |
| 609 | strategy->setDeviceAddress(devices.getFirstValidAddress().c_str()); |
| 610 | } |
| 611 | } |
| 612 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 613 | product_strategy_t Engine::getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const { |
| 614 | for (const auto& strategyMap : mLegacyStrategyMap) { |
| 615 | if (strategyMap.second == legacyStrategy) { |
| 616 | return strategyMap.first; |
| 617 | } |
| 618 | } |
| 619 | return PRODUCT_STRATEGY_NONE; |
| 620 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 621 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 622 | audio_devices_t Engine::getPreferredDeviceTypeForLegacyStrategy( |
| 623 | const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const { |
| 624 | product_strategy_t strategy = getProductStrategyFromLegacy(legacyStrategy); |
| 625 | DeviceVector devices = getPreferredAvailableDevicesForProductStrategy( |
| 626 | availableOutputDevices, strategy); |
| 627 | if (devices.size() > 0) { |
| 628 | return devices[0]->type(); |
| 629 | } |
| 630 | return AUDIO_DEVICE_NONE; |
| 631 | } |
| 632 | |
| 633 | DeviceVector Engine::getPreferredAvailableDevicesForProductStrategy( |
| 634 | const DeviceVector& availableOutputDevices, product_strategy_t strategy) const { |
| 635 | DeviceVector preferredAvailableDevVec = {}; |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 636 | AudioDeviceTypeAddrVector preferredStrategyDevices; |
| 637 | const status_t status = getDevicesForRoleAndStrategy( |
| 638 | strategy, DEVICE_ROLE_PREFERRED, preferredStrategyDevices); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 639 | if (status == NO_ERROR) { |
| 640 | // there is a preferred device, is it available? |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 641 | preferredAvailableDevVec = |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 642 | availableOutputDevices.getDevicesFromDeviceTypeAddrVec(preferredStrategyDevices); |
| 643 | if (preferredAvailableDevVec.size() == preferredAvailableDevVec.size()) { |
| 644 | ALOGVV("%s using pref device %s for strategy %u", |
| 645 | __func__, preferredAvailableDevVec.toString().c_str(), strategy); |
| 646 | return preferredAvailableDevVec; |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 649 | return preferredAvailableDevVec; |
| 650 | } |
| 651 | |
| 652 | DeviceVector Engine::getDevicesForProductStrategy(product_strategy_t strategy) const { |
| 653 | DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
| 654 | auto legacyStrategy = mLegacyStrategyMap.find(strategy) != end(mLegacyStrategyMap) ? |
| 655 | mLegacyStrategyMap.at(strategy) : STRATEGY_NONE; |
| 656 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 657 | // When not in call, STRATEGY_DTMF follows STRATEGY_MEDIA |
| 658 | if (!isInCall() && legacyStrategy == STRATEGY_DTMF) { |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 659 | legacyStrategy = STRATEGY_MEDIA; |
| 660 | strategy = getProductStrategyFromLegacy(STRATEGY_MEDIA); |
| 661 | } |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame^] | 662 | |
| 663 | DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
| 664 | const SwAudioOutputCollection& outputs = getApmObserver()->getOutputs(); |
| 665 | |
| 666 | filterOutputDevicesForStrategy(legacyStrategy, availableOutputDevices, |
| 667 | availableInputDevices, outputs); |
| 668 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 669 | // check if this strategy has a preferred device that is available, |
| 670 | // if yes, give priority to it. |
| 671 | DeviceVector preferredAvailableDevVec = |
| 672 | getPreferredAvailableDevicesForProductStrategy(availableOutputDevices, strategy); |
| 673 | if (!preferredAvailableDevVec.isEmpty()) { |
| 674 | return preferredAvailableDevVec; |
| 675 | } |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 676 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 677 | return getDevicesForStrategyInt(legacyStrategy, |
| 678 | availableOutputDevices, |
| 679 | availableInputDevices, outputs); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | DeviceVector Engine::getOutputDevicesForAttributes(const audio_attributes_t &attributes, |
| 683 | const sp<DeviceDescriptor> &preferredDevice, |
| 684 | bool fromCache) const |
| 685 | { |
| 686 | // First check for explict routing device |
| 687 | if (preferredDevice != nullptr) { |
| 688 | ALOGV("%s explicit Routing on device %s", __func__, preferredDevice->toString().c_str()); |
| 689 | return DeviceVector(preferredDevice); |
| 690 | } |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 691 | product_strategy_t strategy = getProductStrategyForAttributes(attributes); |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 692 | const DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 693 | const SwAudioOutputCollection &outputs = getApmObserver()->getOutputs(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 694 | // |
| 695 | // @TODO: what is the priority of explicit routing? Shall it be considered first as it used to |
| 696 | // be by APM? |
| 697 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 698 | // Honor explicit routing requests only if all active clients have a preferred route in which |
| 699 | // case the last active client route is used |
| 700 | sp<DeviceDescriptor> device = findPreferredDevice(outputs, strategy, availableOutputDevices); |
| 701 | if (device != nullptr) { |
| 702 | return DeviceVector(device); |
| 703 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 704 | |
| 705 | return fromCache? mDevicesForStrategies.at(strategy) : getDevicesForProductStrategy(strategy); |
| 706 | } |
| 707 | |
| 708 | DeviceVector Engine::getOutputDevicesForStream(audio_stream_type_t stream, bool fromCache) const |
| 709 | { |
| 710 | auto attributes = getAttributesForStreamType(stream); |
| 711 | return getOutputDevicesForAttributes(attributes, nullptr, fromCache); |
| 712 | } |
| 713 | |
| 714 | sp<DeviceDescriptor> Engine::getInputDeviceForAttributes(const audio_attributes_t &attr, |
Mikhail Naganov | bfac583 | 2019-03-05 16:55:28 -0800 | [diff] [blame] | 715 | sp<AudioPolicyMix> *mix) const |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 716 | { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 717 | const auto &policyMixes = getApmObserver()->getAudioPolicyMixCollection(); |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 718 | const auto availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 719 | const auto &inputs = getApmObserver()->getInputs(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 720 | std::string address; |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 721 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 722 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 723 | // Explicit Routing ??? what is the priority of explicit routing? Shall it be considered |
| 724 | // first as it used to be by APM? |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 725 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 726 | // Honor explicit routing requests only if all active clients have a preferred route in which |
| 727 | // case the last active client route is used |
| 728 | sp<DeviceDescriptor> device = |
| 729 | findPreferredDevice(inputs, attr.source, availableInputDevices); |
| 730 | if (device != nullptr) { |
| 731 | return device; |
| 732 | } |
| 733 | |
| 734 | device = policyMixes.getDeviceAndMixForInputSource(attr.source, availableInputDevices, mix); |
| 735 | if (device != nullptr) { |
| 736 | return device; |
| 737 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 738 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 739 | device = getDeviceForInputSource(attr.source); |
| 740 | if (device == nullptr || !audio_is_remote_submix_device(device->type())) { |
| 741 | // Return immediately if the device is null or it is not a remote submix device. |
| 742 | return device; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 743 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 744 | |
| 745 | // For remote submix device, try to find the device by address. |
| 746 | address = "0"; |
| 747 | std::size_t pos; |
| 748 | std::string tags { attr.tags }; |
| 749 | if ((pos = tags.find("addr=")) != std::string::npos) { |
| 750 | address = tags.substr(pos + std::strlen("addr=")); |
| 751 | } |
| 752 | return availableInputDevices.getDevice(device->type(), |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 753 | String8(address.c_str()), |
| 754 | AUDIO_FORMAT_DEFAULT); |
| 755 | } |
| 756 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 757 | } // namespace audio_policy |
| 758 | } // namespace android |
| 759 | |
| 760 | |