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" |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 28 | #include <AudioPolicyManagerObserver.h> |
| 29 | #include <AudioPort.h> |
| 30 | #include <IOProfile.h> |
| 31 | #include <policy.h> |
| 32 | #include <utils/String8.h> |
| 33 | #include <utils/Log.h> |
| 34 | |
| 35 | namespace android |
| 36 | { |
| 37 | namespace audio_policy |
| 38 | { |
| 39 | |
| 40 | Engine::Engine() |
| 41 | : mManagerInterface(this), |
| 42 | mPhoneState(AUDIO_MODE_NORMAL), |
| 43 | mApmObserver(NULL) |
| 44 | { |
| 45 | for (int i = 0; i < AUDIO_POLICY_FORCE_USE_CNT; i++) { |
| 46 | mForceUse[i] = AUDIO_POLICY_FORCE_NONE; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | Engine::~Engine() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | void Engine::setObserver(AudioPolicyManagerObserver *observer) |
| 55 | { |
| 56 | ALOG_ASSERT(observer != NULL, "Invalid Audio Policy Manager observer"); |
| 57 | mApmObserver = observer; |
| 58 | } |
| 59 | |
| 60 | status_t Engine::initCheck() |
| 61 | { |
| 62 | return (mApmObserver != NULL) ? NO_ERROR : NO_INIT; |
| 63 | } |
| 64 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 65 | status_t Engine::setPhoneState(audio_mode_t state) |
| 66 | { |
| 67 | ALOGV("setPhoneState() state %d", state); |
| 68 | |
| 69 | if (state < 0 || state >= AUDIO_MODE_CNT) { |
| 70 | ALOGW("setPhoneState() invalid state %d", state); |
| 71 | return BAD_VALUE; |
| 72 | } |
| 73 | |
| 74 | if (state == mPhoneState ) { |
| 75 | ALOGW("setPhoneState() setting same state %d", state); |
| 76 | return BAD_VALUE; |
| 77 | } |
| 78 | |
| 79 | // store previous phone state for management of sonification strategy below |
| 80 | int oldState = mPhoneState; |
| 81 | mPhoneState = state; |
François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 82 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 83 | if (!is_state_in_call(oldState) && is_state_in_call(state)) { |
| 84 | ALOGV(" Entering call in setPhoneState()"); |
François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 85 | mApmObserver->getVolumeCurves().switchVolumeCurve(AUDIO_STREAM_VOICE_CALL, |
| 86 | AUDIO_STREAM_DTMF); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 87 | } else if (is_state_in_call(oldState) && !is_state_in_call(state)) { |
| 88 | ALOGV(" Exiting call in setPhoneState()"); |
François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 89 | mApmObserver->getVolumeCurves().restoreOriginVolumeCurve(AUDIO_STREAM_DTMF); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 90 | } |
| 91 | return NO_ERROR; |
| 92 | } |
| 93 | |
| 94 | status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
| 95 | { |
| 96 | switch(usage) { |
| 97 | case AUDIO_POLICY_FORCE_FOR_COMMUNICATION: |
| 98 | if (config != AUDIO_POLICY_FORCE_SPEAKER && config != AUDIO_POLICY_FORCE_BT_SCO && |
| 99 | config != AUDIO_POLICY_FORCE_NONE) { |
| 100 | ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config); |
| 101 | return BAD_VALUE; |
| 102 | } |
| 103 | mForceUse[usage] = config; |
| 104 | break; |
| 105 | case AUDIO_POLICY_FORCE_FOR_MEDIA: |
| 106 | if (config != AUDIO_POLICY_FORCE_HEADPHONES && config != AUDIO_POLICY_FORCE_BT_A2DP && |
| 107 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 108 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 109 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK && config != AUDIO_POLICY_FORCE_NONE && |
| 110 | config != AUDIO_POLICY_FORCE_NO_BT_A2DP && config != AUDIO_POLICY_FORCE_SPEAKER ) { |
| 111 | ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config); |
| 112 | return BAD_VALUE; |
| 113 | } |
| 114 | mForceUse[usage] = config; |
| 115 | break; |
| 116 | case AUDIO_POLICY_FORCE_FOR_RECORD: |
| 117 | if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 118 | config != AUDIO_POLICY_FORCE_NONE) { |
| 119 | ALOGW("setForceUse() invalid config %d for FOR_RECORD", config); |
| 120 | return BAD_VALUE; |
| 121 | } |
| 122 | mForceUse[usage] = config; |
| 123 | break; |
| 124 | case AUDIO_POLICY_FORCE_FOR_DOCK: |
| 125 | if (config != AUDIO_POLICY_FORCE_NONE && config != AUDIO_POLICY_FORCE_BT_CAR_DOCK && |
| 126 | config != AUDIO_POLICY_FORCE_BT_DESK_DOCK && |
| 127 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 128 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 129 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK) { |
| 130 | ALOGW("setForceUse() invalid config %d for FOR_DOCK", config); |
| 131 | } |
| 132 | mForceUse[usage] = config; |
| 133 | break; |
| 134 | case AUDIO_POLICY_FORCE_FOR_SYSTEM: |
| 135 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 136 | config != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) { |
| 137 | ALOGW("setForceUse() invalid config %d for FOR_SYSTEM", config); |
| 138 | } |
| 139 | mForceUse[usage] = config; |
| 140 | break; |
| 141 | case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO: |
| 142 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 143 | config != AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED) { |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 144 | ALOGW("setForceUse() invalid config %d for HDMI_SYSTEM_AUDIO", config); |
| 145 | } |
| 146 | mForceUse[usage] = config; |
| 147 | break; |
| 148 | case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND: |
| 149 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 150 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER && |
| 151 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS) { |
| 152 | ALOGW("setForceUse() invalid config %d for ENCODED_SURROUND", config); |
| 153 | return BAD_VALUE; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 154 | } |
| 155 | mForceUse[usage] = config; |
| 156 | break; |
| 157 | default: |
| 158 | ALOGW("setForceUse() invalid usage %d", usage); |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 159 | break; // TODO return BAD_VALUE? |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 160 | } |
| 161 | return NO_ERROR; |
| 162 | } |
| 163 | |
| 164 | routing_strategy Engine::getStrategyForStream(audio_stream_type_t stream) |
| 165 | { |
| 166 | // stream to strategy mapping |
| 167 | switch (stream) { |
| 168 | case AUDIO_STREAM_VOICE_CALL: |
| 169 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 170 | return STRATEGY_PHONE; |
| 171 | case AUDIO_STREAM_RING: |
| 172 | case AUDIO_STREAM_ALARM: |
| 173 | return STRATEGY_SONIFICATION; |
| 174 | case AUDIO_STREAM_NOTIFICATION: |
| 175 | return STRATEGY_SONIFICATION_RESPECTFUL; |
| 176 | case AUDIO_STREAM_DTMF: |
| 177 | return STRATEGY_DTMF; |
| 178 | default: |
| 179 | ALOGE("unknown stream type %d", stream); |
| 180 | case AUDIO_STREAM_SYSTEM: |
| 181 | // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs |
| 182 | // while key clicks are played produces a poor result |
| 183 | case AUDIO_STREAM_MUSIC: |
| 184 | return STRATEGY_MEDIA; |
| 185 | case AUDIO_STREAM_ENFORCED_AUDIBLE: |
| 186 | return STRATEGY_ENFORCED_AUDIBLE; |
| 187 | case AUDIO_STREAM_TTS: |
| 188 | return STRATEGY_TRANSMITTED_THROUGH_SPEAKER; |
| 189 | case AUDIO_STREAM_ACCESSIBILITY: |
| 190 | return STRATEGY_ACCESSIBILITY; |
| 191 | case AUDIO_STREAM_REROUTING: |
| 192 | return STRATEGY_REROUTING; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | routing_strategy Engine::getStrategyForUsage(audio_usage_t usage) |
| 197 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 198 | // usage to strategy mapping |
| 199 | switch (usage) { |
| 200 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 201 | return STRATEGY_ACCESSIBILITY; |
| 202 | |
| 203 | case AUDIO_USAGE_MEDIA: |
| 204 | case AUDIO_USAGE_GAME: |
| 205 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 206 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 207 | return STRATEGY_MEDIA; |
| 208 | |
| 209 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 210 | return STRATEGY_PHONE; |
| 211 | |
| 212 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 213 | return STRATEGY_DTMF; |
| 214 | |
| 215 | case AUDIO_USAGE_ALARM: |
| 216 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 217 | return STRATEGY_SONIFICATION; |
| 218 | |
| 219 | case AUDIO_USAGE_NOTIFICATION: |
| 220 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 221 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 222 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 223 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 224 | return STRATEGY_SONIFICATION_RESPECTFUL; |
| 225 | |
| 226 | case AUDIO_USAGE_UNKNOWN: |
| 227 | default: |
| 228 | return STRATEGY_MEDIA; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | audio_devices_t Engine::getDeviceForStrategy(routing_strategy strategy) const |
| 233 | { |
Eric Laurent | 0f928fa | 2016-03-21 12:06:20 -0700 | [diff] [blame] | 234 | DeviceVector availableOutputDevices = mApmObserver->getAvailableOutputDevices(); |
| 235 | DeviceVector availableInputDevices = mApmObserver->getAvailableInputDevices(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 236 | |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 237 | const SwAudioOutputCollection &outputs = mApmObserver->getOutputs(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 238 | |
Eric Laurent | 0f928fa | 2016-03-21 12:06:20 -0700 | [diff] [blame] | 239 | return getDeviceForStrategyInt(strategy, availableOutputDevices, |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 240 | availableInputDevices, outputs); |
| 241 | } |
| 242 | |
| 243 | |
| 244 | |
| 245 | audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy, |
Eric Laurent | 0f928fa | 2016-03-21 12:06:20 -0700 | [diff] [blame] | 246 | DeviceVector availableOutputDevices, |
| 247 | DeviceVector availableInputDevices, |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 248 | const SwAudioOutputCollection &outputs) const |
| 249 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 250 | uint32_t device = AUDIO_DEVICE_NONE; |
| 251 | uint32_t availableOutputDevicesType = availableOutputDevices.types(); |
| 252 | |
| 253 | switch (strategy) { |
| 254 | |
| 255 | case STRATEGY_TRANSMITTED_THROUGH_SPEAKER: |
| 256 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 257 | break; |
| 258 | |
| 259 | case STRATEGY_SONIFICATION_RESPECTFUL: |
| 260 | if (isInCall()) { |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 261 | device = getDeviceForStrategyInt( |
| 262 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 263 | } else if (outputs.isStreamActiveRemotely(AUDIO_STREAM_MUSIC, |
| 264 | SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)) { |
| 265 | // while media is playing on a remote device, use the the sonification behavior. |
| 266 | // Note that we test this usecase before testing if media is playing because |
| 267 | // the isStreamActive() method only informs about the activity of a stream, not |
| 268 | // if it's for local playback. Note also that we use the same delay between both tests |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 269 | device = getDeviceForStrategyInt( |
| 270 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 271 | //user "safe" speaker if available instead of normal speaker to avoid triggering |
| 272 | //other acoustic safety mechanisms for notification |
Eric Laurent | 9a7d922 | 2015-07-02 15:30:23 -0700 | [diff] [blame] | 273 | if ((device & AUDIO_DEVICE_OUT_SPEAKER) && |
| 274 | (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 275 | device |= AUDIO_DEVICE_OUT_SPEAKER_SAFE; |
| 276 | device &= ~AUDIO_DEVICE_OUT_SPEAKER; |
| 277 | } |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 278 | } else if (outputs.isStreamActive( |
| 279 | AUDIO_STREAM_MUSIC, SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 280 | // while media is playing (or has recently played), use the same device |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 281 | device = getDeviceForStrategyInt( |
| 282 | STRATEGY_MEDIA, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 283 | } else { |
| 284 | // when media is not playing anymore, fall back on the sonification behavior |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 285 | device = getDeviceForStrategyInt( |
| 286 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 287 | //user "safe" speaker if available instead of normal speaker to avoid triggering |
| 288 | //other acoustic safety mechanisms for notification |
Eric Laurent | 9a7d922 | 2015-07-02 15:30:23 -0700 | [diff] [blame] | 289 | if ((device & AUDIO_DEVICE_OUT_SPEAKER) && |
| 290 | (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 291 | device |= AUDIO_DEVICE_OUT_SPEAKER_SAFE; |
| 292 | device &= ~AUDIO_DEVICE_OUT_SPEAKER; |
| 293 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 294 | } |
| 295 | break; |
| 296 | |
| 297 | case STRATEGY_DTMF: |
| 298 | if (!isInCall()) { |
| 299 | // when off call, DTMF strategy follows the same rules as MEDIA strategy |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 300 | device = getDeviceForStrategyInt( |
| 301 | STRATEGY_MEDIA, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | // when in call, DTMF and PHONE strategies follow the same rules |
| 305 | // FALL THROUGH |
| 306 | |
| 307 | case STRATEGY_PHONE: |
| 308 | // Force use of only devices on primary output if: |
| 309 | // - in call AND |
| 310 | // - cannot route from voice call RX OR |
| 311 | // - audio HAL version is < 3.0 and TX device is on the primary HW module |
| 312 | if (getPhoneState() == AUDIO_MODE_IN_CALL) { |
| 313 | audio_devices_t txDevice = getDeviceForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); |
| 314 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
| 315 | audio_devices_t availPrimaryInputDevices = |
| 316 | availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()); |
| 317 | audio_devices_t availPrimaryOutputDevices = |
| 318 | primaryOutput->supportedDevices() & availableOutputDevices.types(); |
| 319 | |
| 320 | if (((availableInputDevices.types() & |
| 321 | AUDIO_DEVICE_IN_TELEPHONY_RX & ~AUDIO_DEVICE_BIT_IN) == 0) || |
| 322 | (((txDevice & availPrimaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) && |
Eric Laurent | 322b4d2 | 2015-04-03 15:57:54 -0700 | [diff] [blame] | 323 | (primaryOutput->getAudioPort()->getModuleVersion() < |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 324 | AUDIO_DEVICE_API_VERSION_3_0))) { |
| 325 | availableOutputDevicesType = availPrimaryOutputDevices; |
| 326 | } |
| 327 | } |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 328 | // for phone strategy, we first consider the forced use and then the available devices by |
| 329 | // order of priority |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 330 | switch (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION]) { |
| 331 | case AUDIO_POLICY_FORCE_BT_SCO: |
| 332 | if (!isInCall() || strategy != STRATEGY_DTMF) { |
| 333 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT; |
| 334 | if (device) break; |
| 335 | } |
| 336 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET; |
| 337 | if (device) break; |
| 338 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO; |
| 339 | if (device) break; |
| 340 | // if SCO device is requested but no SCO device is available, fall back to default case |
| 341 | // FALL THROUGH |
| 342 | |
| 343 | default: // FORCE_NONE |
| 344 | // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP |
| 345 | if (!isInCall() && |
| 346 | (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) && |
| 347 | (outputs.getA2dpOutput() != 0)) { |
| 348 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP; |
| 349 | if (device) break; |
| 350 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES; |
| 351 | if (device) break; |
| 352 | } |
| 353 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; |
| 354 | if (device) break; |
| 355 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADSET; |
| 356 | if (device) break; |
Eric Laurent | a0b18ce | 2016-03-08 11:05:00 -0800 | [diff] [blame] | 357 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_LINE; |
| 358 | if (device) break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 359 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE; |
| 360 | if (device) break; |
| 361 | if (!isInCall()) { |
| 362 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY; |
| 363 | if (device) break; |
| 364 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET; |
| 365 | if (device) break; |
| 366 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 367 | if (device) break; |
| 368 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET; |
| 369 | if (device) break; |
| 370 | } |
| 371 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_EARPIECE; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 372 | break; |
| 373 | |
| 374 | case AUDIO_POLICY_FORCE_SPEAKER: |
| 375 | // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to |
| 376 | // A2DP speaker when forcing to speaker output |
| 377 | if (!isInCall() && |
| 378 | (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) && |
| 379 | (outputs.getA2dpOutput() != 0)) { |
| 380 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER; |
| 381 | if (device) break; |
| 382 | } |
| 383 | if (!isInCall()) { |
| 384 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY; |
| 385 | if (device) break; |
| 386 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE; |
| 387 | if (device) break; |
| 388 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET; |
| 389 | if (device) break; |
| 390 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 391 | if (device) break; |
| 392 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET; |
| 393 | if (device) break; |
| 394 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 395 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 396 | break; |
| 397 | } |
| 398 | break; |
| 399 | |
| 400 | case STRATEGY_SONIFICATION: |
| 401 | |
| 402 | // If incall, just select the STRATEGY_PHONE device: The rest of the behavior is handled by |
| 403 | // handleIncallSonification(). |
| 404 | if (isInCall()) { |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 405 | device = getDeviceForStrategyInt( |
| 406 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | // FALL THROUGH |
| 410 | |
| 411 | case STRATEGY_ENFORCED_AUDIBLE: |
| 412 | // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION |
| 413 | // except: |
| 414 | // - when in call where it doesn't default to STRATEGY_PHONE behavior |
| 415 | // - in countries where not enforced in which case it follows STRATEGY_MEDIA |
| 416 | |
| 417 | if ((strategy == STRATEGY_SONIFICATION) || |
| 418 | (mForceUse[AUDIO_POLICY_FORCE_FOR_SYSTEM] == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)) { |
| 419 | device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 420 | } |
Eric Laurent | a8e0f02 | 2017-01-27 17:41:53 -0800 | [diff] [blame^] | 421 | |
| 422 | // if SCO headset is connected and we are told to use it, play ringtone over |
| 423 | // speaker and BT SCO |
| 424 | if (((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) && |
| 425 | (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO)) { |
| 426 | uint32_t device2 = AUDIO_DEVICE_NONE; |
| 427 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT; |
| 428 | if (device2 == AUDIO_DEVICE_NONE) { |
| 429 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET; |
| 430 | } |
| 431 | if (device2 == AUDIO_DEVICE_NONE) { |
| 432 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO; |
| 433 | } |
| 434 | |
| 435 | if (device2 != AUDIO_DEVICE_NONE) { |
| 436 | device |= device2; |
| 437 | break; |
| 438 | } |
| 439 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 440 | // The second device used for sonification is the same as the device used by media strategy |
| 441 | // FALL THROUGH |
| 442 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 443 | case STRATEGY_ACCESSIBILITY: |
| 444 | if (strategy == STRATEGY_ACCESSIBILITY) { |
| 445 | // do not route accessibility prompts to a digital output currently configured with a |
| 446 | // compressed format as they would likely not be mixed and dropped. |
| 447 | for (size_t i = 0; i < outputs.size(); i++) { |
| 448 | sp<AudioOutputDescriptor> desc = outputs.valueAt(i); |
| 449 | audio_devices_t devices = desc->device() & |
| 450 | (AUDIO_DEVICE_OUT_HDMI | AUDIO_DEVICE_OUT_SPDIF | AUDIO_DEVICE_OUT_HDMI_ARC); |
| 451 | if (desc->isActive() && !audio_is_linear_pcm(desc->mFormat) && |
| 452 | devices != AUDIO_DEVICE_NONE) { |
| 453 | availableOutputDevicesType = availableOutputDevices.types() & ~devices; |
| 454 | } |
| 455 | } |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 456 | availableOutputDevices = |
| 457 | availableOutputDevices.getDevicesFromType(availableOutputDevicesType); |
| 458 | if (outputs.isStreamActive(AUDIO_STREAM_RING) || |
| 459 | outputs.isStreamActive(AUDIO_STREAM_ALARM)) { |
| 460 | return getDeviceForStrategyInt( |
| 461 | STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs); |
| 462 | } |
| 463 | if (isInCall()) { |
| 464 | return getDeviceForStrategyInt( |
| 465 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
| 466 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 467 | } |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 468 | // For other cases, STRATEGY_ACCESSIBILITY behaves like STRATEGY_MEDIA |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 469 | // FALL THROUGH |
| 470 | |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 471 | // FIXME: STRATEGY_REROUTING follow STRATEGY_MEDIA for now |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 472 | case STRATEGY_REROUTING: |
| 473 | case STRATEGY_MEDIA: { |
| 474 | uint32_t device2 = AUDIO_DEVICE_NONE; |
| 475 | if (strategy != STRATEGY_SONIFICATION) { |
| 476 | // no sonification on remote submix (e.g. WFD) |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 477 | if (availableOutputDevices.getDevice(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 478 | String8("0")) != 0) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 479 | device2 = availableOutputDevices.types() & AUDIO_DEVICE_OUT_REMOTE_SUBMIX; |
| 480 | } |
| 481 | } |
Eric Laurent | a20d4fa | 2015-06-04 18:39:28 -0700 | [diff] [blame] | 482 | if (isInCall() && (strategy == STRATEGY_MEDIA)) { |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 483 | device = getDeviceForStrategyInt( |
| 484 | STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs); |
Eric Laurent | a20d4fa | 2015-06-04 18:39:28 -0700 | [diff] [blame] | 485 | break; |
| 486 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 487 | if ((device2 == AUDIO_DEVICE_NONE) && |
| 488 | (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) && |
| 489 | (outputs.getA2dpOutput() != 0)) { |
| 490 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP; |
| 491 | if (device2 == AUDIO_DEVICE_NONE) { |
| 492 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES; |
| 493 | } |
| 494 | if (device2 == AUDIO_DEVICE_NONE) { |
| 495 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER; |
| 496 | } |
| 497 | } |
| 498 | if ((device2 == AUDIO_DEVICE_NONE) && |
| 499 | (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] == AUDIO_POLICY_FORCE_SPEAKER)) { |
| 500 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER; |
| 501 | } |
| 502 | if (device2 == AUDIO_DEVICE_NONE) { |
| 503 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; |
| 504 | } |
Jean-Michel Trivi | 5c233f8 | 2015-04-03 09:21:24 -0700 | [diff] [blame] | 505 | if (device2 == AUDIO_DEVICE_NONE) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 506 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_LINE; |
| 507 | } |
| 508 | if (device2 == AUDIO_DEVICE_NONE) { |
| 509 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADSET; |
| 510 | } |
| 511 | if (device2 == AUDIO_DEVICE_NONE) { |
| 512 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY; |
| 513 | } |
| 514 | if (device2 == AUDIO_DEVICE_NONE) { |
| 515 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE; |
| 516 | } |
| 517 | if (device2 == AUDIO_DEVICE_NONE) { |
| 518 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET; |
| 519 | } |
| 520 | if ((device2 == AUDIO_DEVICE_NONE) && (strategy != STRATEGY_SONIFICATION)) { |
| 521 | // no sonification on aux digital (e.g. HDMI) |
| 522 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 523 | } |
| 524 | if ((device2 == AUDIO_DEVICE_NONE) && |
| 525 | (mForceUse[AUDIO_POLICY_FORCE_FOR_DOCK] == AUDIO_POLICY_FORCE_ANALOG_DOCK)) { |
| 526 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET; |
| 527 | } |
| 528 | if (device2 == AUDIO_DEVICE_NONE) { |
| 529 | device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER; |
| 530 | } |
| 531 | int device3 = AUDIO_DEVICE_NONE; |
| 532 | if (strategy == STRATEGY_MEDIA) { |
| 533 | // ARC, SPDIF and AUX_LINE can co-exist with others. |
| 534 | device3 = availableOutputDevicesType & AUDIO_DEVICE_OUT_HDMI_ARC; |
| 535 | device3 |= (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPDIF); |
| 536 | device3 |= (availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_LINE); |
| 537 | } |
| 538 | |
| 539 | device2 |= device3; |
| 540 | // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or |
| 541 | // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise |
| 542 | device |= device2; |
| 543 | |
| 544 | // If hdmi system audio mode is on, remove speaker out of output list. |
| 545 | if ((strategy == STRATEGY_MEDIA) && |
| 546 | (mForceUse[AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] == |
| 547 | AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED)) { |
| 548 | device &= ~AUDIO_DEVICE_OUT_SPEAKER; |
| 549 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 550 | } break; |
| 551 | |
| 552 | default: |
| 553 | ALOGW("getDeviceForStrategy() unknown strategy: %d", strategy); |
| 554 | break; |
| 555 | } |
| 556 | |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 557 | if (device == AUDIO_DEVICE_NONE) { |
| 558 | ALOGV("getDeviceForStrategy() no device found for strategy %d", strategy); |
| 559 | device = mApmObserver->getDefaultOutputDevice()->type(); |
| 560 | ALOGE_IF(device == AUDIO_DEVICE_NONE, |
| 561 | "getDeviceForStrategy() no default device defined"); |
| 562 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 563 | ALOGVV("getDeviceForStrategy() strategy %d, device %x", strategy, device); |
| 564 | return device; |
| 565 | } |
| 566 | |
| 567 | |
| 568 | audio_devices_t Engine::getDeviceForInputSource(audio_source_t inputSource) const |
| 569 | { |
| 570 | const DeviceVector &availableOutputDevices = mApmObserver->getAvailableOutputDevices(); |
| 571 | const DeviceVector &availableInputDevices = mApmObserver->getAvailableInputDevices(); |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 572 | const SwAudioOutputCollection &outputs = mApmObserver->getOutputs(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 573 | audio_devices_t availableDeviceTypes = availableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN; |
| 574 | |
| 575 | uint32_t device = AUDIO_DEVICE_NONE; |
| 576 | |
| 577 | switch (inputSource) { |
| 578 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 579 | if (availableDeviceTypes & AUDIO_DEVICE_IN_VOICE_CALL) { |
| 580 | device = AUDIO_DEVICE_IN_VOICE_CALL; |
| 581 | break; |
| 582 | } |
| 583 | break; |
| 584 | |
| 585 | case AUDIO_SOURCE_DEFAULT: |
| 586 | case AUDIO_SOURCE_MIC: |
| 587 | if (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) { |
| 588 | device = AUDIO_DEVICE_IN_BLUETOOTH_A2DP; |
| 589 | } else if ((mForceUse[AUDIO_POLICY_FORCE_FOR_RECORD] == AUDIO_POLICY_FORCE_BT_SCO) && |
| 590 | (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)) { |
| 591 | device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET; |
| 592 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 593 | device = AUDIO_DEVICE_IN_WIRED_HEADSET; |
| 594 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) { |
| 595 | device = AUDIO_DEVICE_IN_USB_DEVICE; |
| 596 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 597 | device = AUDIO_DEVICE_IN_BUILTIN_MIC; |
| 598 | } |
| 599 | break; |
| 600 | |
| 601 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 602 | // Allow only use of devices on primary input if in call and HAL does not support routing |
| 603 | // to voice call path. |
| 604 | if ((getPhoneState() == AUDIO_MODE_IN_CALL) && |
| 605 | (availableOutputDevices.types() & AUDIO_DEVICE_OUT_TELEPHONY_TX) == 0) { |
| 606 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
| 607 | availableDeviceTypes = |
| 608 | availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()) |
| 609 | & ~AUDIO_DEVICE_BIT_IN; |
| 610 | } |
| 611 | |
| 612 | switch (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION]) { |
| 613 | case AUDIO_POLICY_FORCE_BT_SCO: |
| 614 | // if SCO device is requested but no SCO device is available, fall back to default case |
| 615 | if (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 616 | device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET; |
| 617 | break; |
| 618 | } |
| 619 | // FALL THROUGH |
| 620 | |
| 621 | default: // FORCE_NONE |
| 622 | if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 623 | device = AUDIO_DEVICE_IN_WIRED_HEADSET; |
| 624 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) { |
| 625 | device = AUDIO_DEVICE_IN_USB_DEVICE; |
| 626 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 627 | device = AUDIO_DEVICE_IN_BUILTIN_MIC; |
| 628 | } |
| 629 | break; |
| 630 | |
| 631 | case AUDIO_POLICY_FORCE_SPEAKER: |
| 632 | if (availableDeviceTypes & AUDIO_DEVICE_IN_BACK_MIC) { |
| 633 | device = AUDIO_DEVICE_IN_BACK_MIC; |
| 634 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 635 | device = AUDIO_DEVICE_IN_BUILTIN_MIC; |
| 636 | } |
| 637 | break; |
| 638 | } |
| 639 | break; |
| 640 | |
| 641 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
rago | 8a397d5 | 2015-12-02 11:27:57 -0800 | [diff] [blame] | 642 | case AUDIO_SOURCE_UNPROCESSED: |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 643 | case AUDIO_SOURCE_HOTWORD: |
| 644 | if (mForceUse[AUDIO_POLICY_FORCE_FOR_RECORD] == AUDIO_POLICY_FORCE_BT_SCO && |
| 645 | availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 646 | device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET; |
| 647 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 648 | device = AUDIO_DEVICE_IN_WIRED_HEADSET; |
| 649 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) { |
| 650 | device = AUDIO_DEVICE_IN_USB_DEVICE; |
| 651 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 652 | device = AUDIO_DEVICE_IN_BUILTIN_MIC; |
| 653 | } |
| 654 | break; |
| 655 | case AUDIO_SOURCE_CAMCORDER: |
| 656 | if (availableDeviceTypes & AUDIO_DEVICE_IN_BACK_MIC) { |
| 657 | device = AUDIO_DEVICE_IN_BACK_MIC; |
| 658 | } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 659 | device = AUDIO_DEVICE_IN_BUILTIN_MIC; |
| 660 | } |
| 661 | break; |
| 662 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 663 | case AUDIO_SOURCE_VOICE_CALL: |
| 664 | if (availableDeviceTypes & AUDIO_DEVICE_IN_VOICE_CALL) { |
| 665 | device = AUDIO_DEVICE_IN_VOICE_CALL; |
| 666 | } |
| 667 | break; |
| 668 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 669 | if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX) { |
| 670 | device = AUDIO_DEVICE_IN_REMOTE_SUBMIX; |
| 671 | } |
| 672 | break; |
| 673 | case AUDIO_SOURCE_FM_TUNER: |
| 674 | if (availableDeviceTypes & AUDIO_DEVICE_IN_FM_TUNER) { |
| 675 | device = AUDIO_DEVICE_IN_FM_TUNER; |
| 676 | } |
| 677 | break; |
| 678 | default: |
| 679 | ALOGW("getDeviceForInputSource() invalid input source %d", inputSource); |
| 680 | break; |
| 681 | } |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 682 | if (device == AUDIO_DEVICE_NONE) { |
| 683 | ALOGV("getDeviceForInputSource() no device found for source %d", inputSource); |
| 684 | if (availableDeviceTypes & AUDIO_DEVICE_IN_STUB) { |
| 685 | device = AUDIO_DEVICE_IN_STUB; |
| 686 | } |
| 687 | ALOGE_IF(device == AUDIO_DEVICE_NONE, |
| 688 | "getDeviceForInputSource() no default device defined"); |
| 689 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 690 | ALOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device); |
| 691 | return device; |
| 692 | } |
| 693 | |
| 694 | template <> |
| 695 | AudioPolicyManagerInterface *Engine::queryInterface() |
| 696 | { |
| 697 | return &mManagerInterface; |
| 698 | } |
| 699 | |
| 700 | } // namespace audio_policy |
| 701 | } // namespace android |
| 702 | |
| 703 | |