Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 17 | #define LOG_TAG "APM::AudioPolicyManager" |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 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 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 27 | #include <inttypes.h> |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 28 | #include <math.h> |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 29 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 30 | #include <AudioPolicyManagerInterface.h> |
| 31 | #include <AudioPolicyEngineInstance.h> |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 32 | #include <cutils/properties.h> |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 33 | #include <utils/Log.h> |
| 34 | #include <hardware/audio.h> |
| 35 | #include <hardware/audio_effect.h> |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 36 | #include <media/AudioParameter.h> |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 37 | #include <media/AudioPolicyHelper.h> |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 38 | #include <soundtrigger/SoundTrigger.h> |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 39 | #include "AudioPolicyManager.h" |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 40 | #include "audio_policy_conf.h" |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 41 | #include <ConfigParsingUtils.h> |
| 42 | #include <policy.h> |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 43 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 44 | namespace android { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 45 | |
| 46 | // ---------------------------------------------------------------------------- |
| 47 | // AudioPolicyInterface implementation |
| 48 | // ---------------------------------------------------------------------------- |
| 49 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 50 | status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 51 | audio_policy_dev_state_t state, |
| 52 | const char *device_address, |
| 53 | const char *device_name) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 54 | { |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 55 | return setDeviceConnectionStateInt(device, state, device_address, device_name); |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device, |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 59 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 60 | const char *device_address, |
| 61 | const char *device_name) |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 62 | { |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 63 | ALOGV("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s", |
| 64 | - device, state, device_address, device_name); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 65 | |
| 66 | // connect/disconnect only 1 device at a time |
| 67 | if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE; |
| 68 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 69 | sp<DeviceDescriptor> devDesc = |
| 70 | mHwModules.getDeviceDescriptor(device, device_address, device_name); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 71 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 72 | // handle output devices |
| 73 | if (audio_is_output_device(device)) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 74 | SortedVector <audio_io_handle_t> outputs; |
| 75 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 76 | ssize_t index = mAvailableOutputDevices.indexOf(devDesc); |
| 77 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 78 | // save a copy of the opened output descriptors before any output is opened or closed |
| 79 | // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies() |
| 80 | mPreviousOutputs = mOutputs; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 81 | switch (state) |
| 82 | { |
| 83 | // handle output device connection |
Eric Laurent | 3ae5f31 | 2015-02-03 17:12:08 -0800 | [diff] [blame] | 84 | case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 85 | if (index >= 0) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 86 | ALOGW("setDeviceConnectionState() device already connected: %x", device); |
| 87 | return INVALID_OPERATION; |
| 88 | } |
| 89 | ALOGV("setDeviceConnectionState() connecting device %x", device); |
| 90 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 91 | // register new device as available |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 92 | index = mAvailableOutputDevices.add(devDesc); |
| 93 | if (index >= 0) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 94 | sp<HwModule> module = mHwModules.getModuleForDevice(device); |
Eric Laurent | cf817a2 | 2014-08-04 20:36:31 -0700 | [diff] [blame] | 95 | if (module == 0) { |
| 96 | ALOGD("setDeviceConnectionState() could not find HW module for device %08x", |
| 97 | device); |
| 98 | mAvailableOutputDevices.remove(devDesc); |
| 99 | return INVALID_OPERATION; |
| 100 | } |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 101 | mAvailableOutputDevices[index]->attach(module); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 102 | } else { |
| 103 | return NO_MEMORY; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 106 | if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) { |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 107 | mAvailableOutputDevices.remove(devDesc); |
| 108 | return INVALID_OPERATION; |
| 109 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 110 | // Propagate device availability to Engine |
| 111 | mEngine->setDeviceConnectionState(devDesc, state); |
| 112 | |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 113 | // outputs should never be empty here |
| 114 | ALOG_ASSERT(outputs.size() != 0, "setDeviceConnectionState():" |
| 115 | "checkOutputsForDevice() returned no outputs but status OK"); |
| 116 | ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %zu outputs", |
| 117 | outputs.size()); |
Eric Laurent | 3ae5f31 | 2015-02-03 17:12:08 -0800 | [diff] [blame] | 118 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 119 | // Send connect to HALs |
Eric Laurent | 3ae5f31 | 2015-02-03 17:12:08 -0800 | [diff] [blame] | 120 | AudioParameter param = AudioParameter(devDesc->mAddress); |
| 121 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device); |
| 122 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 123 | |
| 124 | } break; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 125 | // handle output device disconnection |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 126 | case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 127 | if (index < 0) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 128 | ALOGW("setDeviceConnectionState() device not connected: %x", device); |
| 129 | return INVALID_OPERATION; |
| 130 | } |
| 131 | |
Paul McLean | 5c477aa | 2014-08-20 16:47:57 -0700 | [diff] [blame] | 132 | ALOGV("setDeviceConnectionState() disconnecting output device %x", device); |
| 133 | |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 134 | // Send Disconnect to HALs |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 135 | AudioParameter param = AudioParameter(devDesc->mAddress); |
Paul McLean | 5c477aa | 2014-08-20 16:47:57 -0700 | [diff] [blame] | 136 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device); |
| 137 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 138 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 139 | // remove device from available output devices |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 140 | mAvailableOutputDevices.remove(devDesc); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 141 | |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 142 | checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 143 | |
| 144 | // Propagate device availability to Engine |
| 145 | mEngine->setDeviceConnectionState(devDesc, state); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 146 | } break; |
| 147 | |
| 148 | default: |
| 149 | ALOGE("setDeviceConnectionState() invalid state: %x", state); |
| 150 | return BAD_VALUE; |
| 151 | } |
| 152 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 153 | // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP |
| 154 | // output is suspended before any tracks are moved to it |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 155 | checkA2dpSuspend(); |
| 156 | checkOutputForAllStrategies(); |
| 157 | // outputs must be closed after checkOutputForAllStrategies() is executed |
| 158 | if (!outputs.isEmpty()) { |
| 159 | for (size_t i = 0; i < outputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 160 | sp<AudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 161 | // close unused outputs after device disconnection or direct outputs that have been |
| 162 | // opened by checkOutputsForDevice() to query dynamic parameters |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 163 | if ((state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) || |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 164 | (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) && |
| 165 | (desc->mDirectOpenCount == 0))) { |
| 166 | closeOutput(outputs[i]); |
| 167 | } |
| 168 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 169 | // check again after closing A2DP output to reset mA2dpSuspended if needed |
| 170 | checkA2dpSuspend(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | updateDevicesAndOutputs(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 174 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 175 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 176 | updateCallRouting(newDevice); |
| 177 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 178 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 179 | audio_io_handle_t output = mOutputs.keyAt(i); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 180 | if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (output != mPrimaryOutput)) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 181 | audio_devices_t newDevice = getNewOutputDevice(mOutputs.keyAt(i), |
| 182 | true /*fromCache*/); |
| 183 | // do not force device change on duplicated output because if device is 0, it will |
| 184 | // also force a device 0 for the two outputs it is duplicated to which may override |
| 185 | // a valid device selection on those outputs. |
| 186 | bool force = !mOutputs.valueAt(i)->isDuplicated() |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 187 | && (!device_distinguishes_on_address(device) |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 188 | // always force when disconnecting (a non-duplicated device) |
| 189 | || (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
| 190 | setOutputDevice(output, newDevice, force, 0); |
| 191 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Eric Laurent | 72aa32f | 2014-05-30 18:51:48 -0700 | [diff] [blame] | 194 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | b71e58b | 2014-05-29 16:08:11 -0700 | [diff] [blame] | 195 | return NO_ERROR; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 196 | } // end if is output device |
| 197 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 198 | // handle input devices |
| 199 | if (audio_is_input_device(device)) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 200 | SortedVector <audio_io_handle_t> inputs; |
| 201 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 202 | ssize_t index = mAvailableInputDevices.indexOf(devDesc); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 203 | switch (state) |
| 204 | { |
| 205 | // handle input device connection |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 206 | case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 207 | if (index >= 0) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 208 | ALOGW("setDeviceConnectionState() device already connected: %d", device); |
| 209 | return INVALID_OPERATION; |
| 210 | } |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 211 | sp<HwModule> module = mHwModules.getModuleForDevice(device); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 212 | if (module == NULL) { |
| 213 | ALOGW("setDeviceConnectionState(): could not find HW module for device %08x", |
| 214 | device); |
| 215 | return INVALID_OPERATION; |
| 216 | } |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 217 | if (checkInputsForDevice(device, state, inputs, devDesc->mAddress) != NO_ERROR) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 218 | return INVALID_OPERATION; |
| 219 | } |
| 220 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 221 | index = mAvailableInputDevices.add(devDesc); |
| 222 | if (index >= 0) { |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 223 | mAvailableInputDevices[index]->attach(module); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 224 | } else { |
| 225 | return NO_MEMORY; |
| 226 | } |
Eric Laurent | 3ae5f31 | 2015-02-03 17:12:08 -0800 | [diff] [blame] | 227 | |
| 228 | // Set connect to HALs |
| 229 | AudioParameter param = AudioParameter(devDesc->mAddress); |
| 230 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device); |
| 231 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 232 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 233 | // Propagate device availability to Engine |
| 234 | mEngine->setDeviceConnectionState(devDesc, state); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 235 | } break; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 236 | |
| 237 | // handle input device disconnection |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 238 | case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 239 | if (index < 0) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 240 | ALOGW("setDeviceConnectionState() device not connected: %d", device); |
| 241 | return INVALID_OPERATION; |
| 242 | } |
Paul McLean | 5c477aa | 2014-08-20 16:47:57 -0700 | [diff] [blame] | 243 | |
| 244 | ALOGV("setDeviceConnectionState() disconnecting input device %x", device); |
| 245 | |
| 246 | // Set Disconnect to HALs |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 247 | AudioParameter param = AudioParameter(devDesc->mAddress); |
Paul McLean | 5c477aa | 2014-08-20 16:47:57 -0700 | [diff] [blame] | 248 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device); |
| 249 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 250 | |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 251 | checkInputsForDevice(device, state, inputs, devDesc->mAddress); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 252 | mAvailableInputDevices.remove(devDesc); |
Paul McLean | 5c477aa | 2014-08-20 16:47:57 -0700 | [diff] [blame] | 253 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 254 | // Propagate device availability to Engine |
| 255 | mEngine->setDeviceConnectionState(devDesc, state); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 256 | } break; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 257 | |
| 258 | default: |
| 259 | ALOGE("setDeviceConnectionState() invalid state: %x", state); |
| 260 | return BAD_VALUE; |
| 261 | } |
| 262 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 263 | closeAllInputs(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 264 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 265 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 266 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 267 | updateCallRouting(newDevice); |
| 268 | } |
| 269 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 270 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 271 | return NO_ERROR; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 272 | } // end if is input device |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 273 | |
| 274 | ALOGW("setDeviceConnectionState() invalid device: %x", device); |
| 275 | return BAD_VALUE; |
| 276 | } |
| 277 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 278 | audio_policy_dev_state_t AudioPolicyManager::getDeviceConnectionState(audio_devices_t device, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 279 | const char *device_address) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 280 | { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 281 | sp<DeviceDescriptor> devDesc = mHwModules.getDeviceDescriptor(device, device_address, ""); |
| 282 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 283 | DeviceVector *deviceVector; |
| 284 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 285 | if (audio_is_output_device(device)) { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 286 | deviceVector = &mAvailableOutputDevices; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 287 | } else if (audio_is_input_device(device)) { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 288 | deviceVector = &mAvailableInputDevices; |
| 289 | } else { |
| 290 | ALOGW("getDeviceConnectionState() invalid device type %08x", device); |
| 291 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 292 | } |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 293 | return deviceVector->getDeviceConnectionState(devDesc); |
Eric Laurent | a1d525f | 2015-01-29 13:36:45 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 296 | void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs) |
| 297 | { |
| 298 | bool createTxPatch = false; |
| 299 | struct audio_patch patch; |
| 300 | patch.num_sources = 1; |
| 301 | patch.num_sinks = 1; |
| 302 | status_t status; |
| 303 | audio_patch_handle_t afPatchHandle; |
| 304 | DeviceVector deviceList; |
| 305 | |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 306 | audio_devices_t txDevice = getDeviceAndMixForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 307 | ALOGV("updateCallRouting device rxDevice %08x txDevice %08x", rxDevice, txDevice); |
| 308 | |
| 309 | // release existing RX patch if any |
| 310 | if (mCallRxPatch != 0) { |
| 311 | mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0); |
| 312 | mCallRxPatch.clear(); |
| 313 | } |
| 314 | // release TX patch if any |
| 315 | if (mCallTxPatch != 0) { |
| 316 | mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0); |
| 317 | mCallTxPatch.clear(); |
| 318 | } |
| 319 | |
| 320 | // If the RX device is on the primary HW module, then use legacy routing method for voice calls |
| 321 | // via setOutputDevice() on primary output. |
| 322 | // Otherwise, create two audio patches for TX and RX path. |
| 323 | if (availablePrimaryOutputDevices() & rxDevice) { |
| 324 | setOutputDevice(mPrimaryOutput, rxDevice, true, delayMs); |
| 325 | // If the TX device is also on the primary HW module, setOutputDevice() will take care |
| 326 | // of it due to legacy implementation. If not, create a patch. |
| 327 | if ((availablePrimaryInputDevices() & txDevice & ~AUDIO_DEVICE_BIT_IN) |
| 328 | == AUDIO_DEVICE_NONE) { |
| 329 | createTxPatch = true; |
| 330 | } |
| 331 | } else { |
| 332 | // create RX path audio patch |
| 333 | deviceList = mAvailableOutputDevices.getDevicesFromType(rxDevice); |
| 334 | ALOG_ASSERT(!deviceList.isEmpty(), |
| 335 | "updateCallRouting() selected device not in output device list"); |
| 336 | sp<DeviceDescriptor> rxSinkDeviceDesc = deviceList.itemAt(0); |
| 337 | deviceList = mAvailableInputDevices.getDevicesFromType(AUDIO_DEVICE_IN_TELEPHONY_RX); |
| 338 | ALOG_ASSERT(!deviceList.isEmpty(), |
| 339 | "updateCallRouting() no telephony RX device"); |
| 340 | sp<DeviceDescriptor> rxSourceDeviceDesc = deviceList.itemAt(0); |
| 341 | |
| 342 | rxSourceDeviceDesc->toAudioPortConfig(&patch.sources[0]); |
| 343 | rxSinkDeviceDesc->toAudioPortConfig(&patch.sinks[0]); |
| 344 | |
| 345 | // request to reuse existing output stream if one is already opened to reach the RX device |
| 346 | SortedVector<audio_io_handle_t> outputs = |
| 347 | getOutputsForDevice(rxDevice, mOutputs); |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 348 | audio_io_handle_t output = selectOutput(outputs, |
| 349 | AUDIO_OUTPUT_FLAG_NONE, |
| 350 | AUDIO_FORMAT_INVALID); |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 351 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 352 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
| 353 | ALOG_ASSERT(!outputDesc->isDuplicated(), |
| 354 | "updateCallRouting() RX device output is duplicated"); |
| 355 | outputDesc->toAudioPortConfig(&patch.sources[1]); |
| 356 | patch.num_sources = 2; |
| 357 | } |
| 358 | |
| 359 | afPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 360 | status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); |
| 361 | ALOGW_IF(status != NO_ERROR, "updateCallRouting() error %d creating RX audio patch", |
| 362 | status); |
| 363 | if (status == NO_ERROR) { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 364 | mCallRxPatch = new AudioPatch(&patch, mUidCached); |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 365 | mCallRxPatch->mAfPatchHandle = afPatchHandle; |
| 366 | mCallRxPatch->mUid = mUidCached; |
| 367 | } |
| 368 | createTxPatch = true; |
| 369 | } |
| 370 | if (createTxPatch) { |
| 371 | |
| 372 | struct audio_patch patch; |
| 373 | patch.num_sources = 1; |
| 374 | patch.num_sinks = 1; |
| 375 | deviceList = mAvailableInputDevices.getDevicesFromType(txDevice); |
| 376 | ALOG_ASSERT(!deviceList.isEmpty(), |
| 377 | "updateCallRouting() selected device not in input device list"); |
| 378 | sp<DeviceDescriptor> txSourceDeviceDesc = deviceList.itemAt(0); |
| 379 | txSourceDeviceDesc->toAudioPortConfig(&patch.sources[0]); |
| 380 | deviceList = mAvailableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_TELEPHONY_TX); |
| 381 | ALOG_ASSERT(!deviceList.isEmpty(), |
| 382 | "updateCallRouting() no telephony TX device"); |
| 383 | sp<DeviceDescriptor> txSinkDeviceDesc = deviceList.itemAt(0); |
| 384 | txSinkDeviceDesc->toAudioPortConfig(&patch.sinks[0]); |
| 385 | |
| 386 | SortedVector<audio_io_handle_t> outputs = |
| 387 | getOutputsForDevice(AUDIO_DEVICE_OUT_TELEPHONY_TX, mOutputs); |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 388 | audio_io_handle_t output = selectOutput(outputs, |
| 389 | AUDIO_OUTPUT_FLAG_NONE, |
| 390 | AUDIO_FORMAT_INVALID); |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 391 | // request to reuse existing output stream if one is already opened to reach the TX |
| 392 | // path output device |
| 393 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 394 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
| 395 | ALOG_ASSERT(!outputDesc->isDuplicated(), |
| 396 | "updateCallRouting() RX device output is duplicated"); |
| 397 | outputDesc->toAudioPortConfig(&patch.sources[1]); |
| 398 | patch.num_sources = 2; |
| 399 | } |
| 400 | |
| 401 | afPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 402 | status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); |
| 403 | ALOGW_IF(status != NO_ERROR, "setPhoneState() error %d creating TX audio patch", |
| 404 | status); |
| 405 | if (status == NO_ERROR) { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 406 | mCallTxPatch = new AudioPatch(&patch, mUidCached); |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 407 | mCallTxPatch->mAfPatchHandle = afPatchHandle; |
| 408 | mCallTxPatch->mUid = mUidCached; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 413 | void AudioPolicyManager::setPhoneState(audio_mode_t state) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 414 | { |
| 415 | ALOGV("setPhoneState() state %d", state); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 416 | // store previous phone state for management of sonification strategy below |
| 417 | int oldState = mEngine->getPhoneState(); |
| 418 | |
| 419 | if (mEngine->setPhoneState(state) != NO_ERROR) { |
| 420 | ALOGW("setPhoneState() invalid or same state %d", state); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 421 | return; |
| 422 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 423 | /// Opens: can these line be executed after the switch of volume curves??? |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 424 | // if leaving call state, handle special case of active streams |
| 425 | // pertaining to sonification strategy see handleIncallSonification() |
| 426 | if (isInCall()) { |
| 427 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 428 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 429 | if (stream == AUDIO_STREAM_PATCH) { |
| 430 | continue; |
| 431 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 432 | handleIncallSonification((audio_stream_type_t)stream, false, true); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 433 | } |
Eric Laurent | 2cbe89a | 2014-12-19 11:49:08 -0800 | [diff] [blame] | 434 | |
| 435 | // force reevaluating accessibility routing when call starts |
| 436 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 437 | } |
| 438 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 439 | /** |
| 440 | * Switching to or from incall state or switching between telephony and VoIP lead to force |
| 441 | * routing command. |
| 442 | */ |
| 443 | bool force = ((is_state_in_call(oldState) != is_state_in_call(state)) |
| 444 | || (is_state_in_call(state) && (state != oldState))); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 445 | |
| 446 | // check for device and output changes triggered by new phone state |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 447 | checkA2dpSuspend(); |
| 448 | checkOutputForAllStrategies(); |
| 449 | updateDevicesAndOutputs(); |
| 450 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 451 | sp<AudioOutputDescriptor> hwOutputDesc = mOutputs.valueFor(mPrimaryOutput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 452 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 453 | int delayMs = 0; |
| 454 | if (isStateInCall(state)) { |
| 455 | nsecs_t sysTime = systemTime(); |
| 456 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 457 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 458 | // mute media and sonification strategies and delay device switch by the largest |
| 459 | // latency of any output where either strategy is active. |
| 460 | // This avoid sending the ring tone or music tail into the earpiece or headset. |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 461 | if ((isStrategyActive(desc, STRATEGY_MEDIA, |
| 462 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 463 | sysTime) || |
| 464 | isStrategyActive(desc, STRATEGY_SONIFICATION, |
| 465 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 466 | sysTime)) && |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 467 | (delayMs < (int)desc->mLatency*2)) { |
| 468 | delayMs = desc->mLatency*2; |
| 469 | } |
| 470 | setStrategyMute(STRATEGY_MEDIA, true, mOutputs.keyAt(i)); |
| 471 | setStrategyMute(STRATEGY_MEDIA, false, mOutputs.keyAt(i), MUTE_TIME_MS, |
| 472 | getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/)); |
| 473 | setStrategyMute(STRATEGY_SONIFICATION, true, mOutputs.keyAt(i)); |
| 474 | setStrategyMute(STRATEGY_SONIFICATION, false, mOutputs.keyAt(i), MUTE_TIME_MS, |
| 475 | getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/)); |
| 476 | } |
| 477 | } |
| 478 | |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 479 | // Note that despite the fact that getNewOutputDevice() is called on the primary output, |
| 480 | // the device returned is not necessarily reachable via this output |
| 481 | audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 482 | // force routing command to audio hardware when ending call |
| 483 | // even if no device change is needed |
| 484 | if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) { |
| 485 | rxDevice = hwOutputDesc->device(); |
| 486 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 487 | |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 488 | if (state == AUDIO_MODE_IN_CALL) { |
| 489 | updateCallRouting(rxDevice, delayMs); |
| 490 | } else if (oldState == AUDIO_MODE_IN_CALL) { |
| 491 | if (mCallRxPatch != 0) { |
| 492 | mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0); |
| 493 | mCallRxPatch.clear(); |
| 494 | } |
| 495 | if (mCallTxPatch != 0) { |
| 496 | mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0); |
| 497 | mCallTxPatch.clear(); |
| 498 | } |
| 499 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
| 500 | } else { |
| 501 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
| 502 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 503 | // if entering in call state, handle special case of active streams |
| 504 | // pertaining to sonification strategy see handleIncallSonification() |
| 505 | if (isStateInCall(state)) { |
| 506 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 507 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 508 | if (stream == AUDIO_STREAM_PATCH) { |
| 509 | continue; |
| 510 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 511 | handleIncallSonification((audio_stream_type_t)stream, true, true); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 516 | if (state == AUDIO_MODE_RINGTONE && |
| 517 | isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 518 | mLimitRingtoneVolume = true; |
| 519 | } else { |
| 520 | mLimitRingtoneVolume = false; |
| 521 | } |
| 522 | } |
| 523 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 524 | void AudioPolicyManager::setForceUse(audio_policy_force_use_t usage, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 525 | audio_policy_forced_cfg_t config) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 526 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 527 | ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState()); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 528 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 529 | if (mEngine->setForceUse(usage, config) != NO_ERROR) { |
| 530 | ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage); |
| 531 | return; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 532 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 533 | bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) || |
| 534 | (usage == AUDIO_POLICY_FORCE_FOR_DOCK) || |
| 535 | (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 536 | |
| 537 | // check for device and output changes triggered by new force usage |
| 538 | checkA2dpSuspend(); |
| 539 | checkOutputForAllStrategies(); |
| 540 | updateDevicesAndOutputs(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 541 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 542 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/); |
| 543 | updateCallRouting(newDevice); |
| 544 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 545 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 546 | audio_io_handle_t output = mOutputs.keyAt(i); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 547 | audio_devices_t newDevice = getNewOutputDevice(output, true /*fromCache*/); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 548 | if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (output != mPrimaryOutput)) { |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 549 | setOutputDevice(output, newDevice, (newDevice != AUDIO_DEVICE_NONE)); |
| 550 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 551 | if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { |
| 552 | applyStreamVolumes(output, newDevice, 0, true); |
| 553 | } |
| 554 | } |
| 555 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 556 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 557 | if (activeInput != 0) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 558 | setInputDevice(activeInput, getNewInputDevice(activeInput)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | } |
| 562 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 563 | void AudioPolicyManager::setSystemProperty(const char* property, const char* value) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 564 | { |
| 565 | ALOGV("setSystemProperty() property %s, value %s", property, value); |
| 566 | } |
| 567 | |
| 568 | // Find a direct output profile compatible with the parameters passed, even if the input flags do |
| 569 | // not explicitly request a direct output |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 570 | sp<IOProfile> AudioPolicyManager::getProfileForDirectOutput( |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 571 | audio_devices_t device, |
| 572 | uint32_t samplingRate, |
| 573 | audio_format_t format, |
| 574 | audio_channel_mask_t channelMask, |
| 575 | audio_output_flags_t flags) |
| 576 | { |
| 577 | for (size_t i = 0; i < mHwModules.size(); i++) { |
| 578 | if (mHwModules[i]->mHandle == 0) { |
| 579 | continue; |
| 580 | } |
| 581 | for (size_t j = 0; j < mHwModules[i]->mOutputProfiles.size(); j++) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 582 | sp<IOProfile> profile = mHwModules[i]->mOutputProfiles[j]; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 583 | bool found = profile->isCompatibleProfile(device, String8(""), samplingRate, |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 584 | NULL /*updatedSamplingRate*/, format, channelMask, |
| 585 | flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD ? |
| 586 | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD : AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 587 | if (found && (mAvailableOutputDevices.types() & profile->mSupportedDevices.types())) { |
| 588 | return profile; |
| 589 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 595 | audio_io_handle_t AudioPolicyManager::getOutput(audio_stream_type_t stream, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 596 | uint32_t samplingRate, |
| 597 | audio_format_t format, |
| 598 | audio_channel_mask_t channelMask, |
| 599 | audio_output_flags_t flags, |
| 600 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 601 | { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 602 | routing_strategy strategy = getStrategy(stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 603 | audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/); |
| 604 | ALOGV("getOutput() device %d, stream %d, samplingRate %d, format %x, channelMask %x, flags %x", |
| 605 | device, stream, samplingRate, format, channelMask, flags); |
| 606 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 607 | return getOutputForDevice(device, AUDIO_SESSION_ALLOCATE, |
| 608 | stream, samplingRate,format, channelMask, |
| 609 | flags, offloadInfo); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 612 | status_t AudioPolicyManager::getOutputForAttr(const audio_attributes_t *attr, |
| 613 | audio_io_handle_t *output, |
| 614 | audio_session_t session, |
| 615 | audio_stream_type_t *stream, |
| 616 | uint32_t samplingRate, |
| 617 | audio_format_t format, |
| 618 | audio_channel_mask_t channelMask, |
| 619 | audio_output_flags_t flags, |
| 620 | const audio_offload_info_t *offloadInfo) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 621 | { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 622 | audio_attributes_t attributes; |
| 623 | if (attr != NULL) { |
| 624 | if (!isValidAttributes(attr)) { |
| 625 | ALOGE("getOutputForAttr() invalid attributes: usage=%d content=%d flags=0x%x tags=[%s]", |
| 626 | attr->usage, attr->content_type, attr->flags, |
| 627 | attr->tags); |
| 628 | return BAD_VALUE; |
| 629 | } |
| 630 | attributes = *attr; |
| 631 | } else { |
| 632 | if (*stream < AUDIO_STREAM_MIN || *stream >= AUDIO_STREAM_PUBLIC_CNT) { |
| 633 | ALOGE("getOutputForAttr(): invalid stream type"); |
| 634 | return BAD_VALUE; |
| 635 | } |
| 636 | stream_type_to_audio_attributes(*stream, &attributes); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 637 | } |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 638 | sp<AudioOutputDescriptor> desc; |
| 639 | if (mPolicyMixes.getOutputForAttr(attributes, desc) == NO_ERROR) { |
| 640 | ALOG_ASSERT(desc != 0, "Invalid desc returned by getOutputForAttr"); |
| 641 | if (!audio_is_linear_pcm(format)) { |
| 642 | return BAD_VALUE; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 643 | } |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 644 | *stream = streamTypefromAttributesInt(&attributes); |
| 645 | *output = desc->mIoHandle; |
| 646 | ALOGV("getOutputForAttr() returns output %d", *output); |
| 647 | return NO_ERROR; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 648 | } |
| 649 | if (attributes.usage == AUDIO_USAGE_VIRTUAL_SOURCE) { |
| 650 | ALOGW("getOutputForAttr() no policy mix found for usage AUDIO_USAGE_VIRTUAL_SOURCE"); |
| 651 | return BAD_VALUE; |
| 652 | } |
| 653 | |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 654 | ALOGV("getOutputForAttr() usage=%d, content=%d, tag=%s flags=%08x", |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 655 | attributes.usage, attributes.content_type, attributes.tags, attributes.flags); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 656 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 657 | routing_strategy strategy = (routing_strategy) getStrategyForAttr(&attributes); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 658 | audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/); |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 659 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 660 | if ((attributes.flags & AUDIO_FLAG_HW_AV_SYNC) != 0) { |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 661 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_HW_AV_SYNC); |
| 662 | } |
| 663 | |
Jean-Michel Trivi | fd4c148 | 2014-08-06 16:02:28 -0700 | [diff] [blame] | 664 | ALOGV("getOutputForAttr() device 0x%x, samplingRate %d, format %x, channelMask %x, flags %x", |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 665 | device, samplingRate, format, channelMask, flags); |
| 666 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 667 | *stream = streamTypefromAttributesInt(&attributes); |
| 668 | *output = getOutputForDevice(device, session, *stream, |
| 669 | samplingRate, format, channelMask, |
| 670 | flags, offloadInfo); |
| 671 | if (*output == AUDIO_IO_HANDLE_NONE) { |
| 672 | return INVALID_OPERATION; |
| 673 | } |
| 674 | return NO_ERROR; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | audio_io_handle_t AudioPolicyManager::getOutputForDevice( |
| 678 | audio_devices_t device, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 679 | audio_session_t session __unused, |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 680 | audio_stream_type_t stream, |
| 681 | uint32_t samplingRate, |
| 682 | audio_format_t format, |
| 683 | audio_channel_mask_t channelMask, |
| 684 | audio_output_flags_t flags, |
| 685 | const audio_offload_info_t *offloadInfo) |
| 686 | { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 687 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 688 | uint32_t latency = 0; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 689 | status_t status; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 690 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 691 | #ifdef AUDIO_POLICY_TEST |
| 692 | if (mCurOutput != 0) { |
| 693 | ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d", |
| 694 | mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput); |
| 695 | |
| 696 | if (mTestOutputs[mCurOutput] == 0) { |
| 697 | ALOGV("getOutput() opening test output"); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 698 | sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(NULL); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 699 | outputDesc->mDevice = mTestDevice; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 700 | outputDesc->mLatency = mTestLatencyMs; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 701 | outputDesc->mFlags = |
| 702 | (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 703 | outputDesc->mRefCount[stream] = 0; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 704 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 705 | config.sample_rate = mTestSamplingRate; |
| 706 | config.channel_mask = mTestChannels; |
| 707 | config.format = mTestFormat; |
Phil Burk | 77cce80 | 2014-08-04 16:18:15 -0700 | [diff] [blame] | 708 | if (offloadInfo != NULL) { |
| 709 | config.offload_info = *offloadInfo; |
| 710 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 711 | status = mpClientInterface->openOutput(0, |
| 712 | &mTestOutputs[mCurOutput], |
| 713 | &config, |
| 714 | &outputDesc->mDevice, |
| 715 | String8(""), |
| 716 | &outputDesc->mLatency, |
| 717 | outputDesc->mFlags); |
| 718 | if (status == NO_ERROR) { |
| 719 | outputDesc->mSamplingRate = config.sample_rate; |
| 720 | outputDesc->mFormat = config.format; |
| 721 | outputDesc->mChannelMask = config.channel_mask; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 722 | AudioParameter outputCmd = AudioParameter(); |
| 723 | outputCmd.addInt(String8("set_id"),mCurOutput); |
| 724 | mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString()); |
| 725 | addOutput(mTestOutputs[mCurOutput], outputDesc); |
| 726 | } |
| 727 | } |
| 728 | return mTestOutputs[mCurOutput]; |
| 729 | } |
| 730 | #endif //AUDIO_POLICY_TEST |
| 731 | |
| 732 | // open a direct output if required by specified parameters |
| 733 | //force direct flag if offload flag is set: offloading implies a direct output stream |
| 734 | // and all common behaviors are driven by checking only the direct flag |
| 735 | // this should normally be set appropriately in the policy configuration file |
| 736 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 737 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 738 | } |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 739 | if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) { |
| 740 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
| 741 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 742 | // only allow deep buffering for music stream type |
| 743 | if (stream != AUDIO_STREAM_MUSIC) { |
| 744 | flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
| 745 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 746 | |
Eric Laurent | b732cf5 | 2014-09-24 19:08:21 -0700 | [diff] [blame] | 747 | sp<IOProfile> profile; |
| 748 | |
| 749 | // skip direct output selection if the request can obviously be attached to a mixed output |
Eric Laurent | c260784 | 2014-09-29 09:43:03 -0700 | [diff] [blame] | 750 | // and not explicitly requested |
| 751 | if (((flags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) && |
| 752 | audio_is_linear_pcm(format) && samplingRate <= MAX_MIXER_SAMPLING_RATE && |
Eric Laurent | b732cf5 | 2014-09-24 19:08:21 -0700 | [diff] [blame] | 753 | audio_channel_count_from_out_mask(channelMask) <= 2) { |
| 754 | goto non_direct_output; |
| 755 | } |
| 756 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 757 | // Do not allow offloading if one non offloadable effect is enabled. This prevents from |
| 758 | // creating an offloaded track and tearing it down immediately after start when audioflinger |
| 759 | // detects there is an active non offloadable effect. |
| 760 | // FIXME: We should check the audio session here but we do not have it in this context. |
| 761 | // This may prevent offloading in rare situations where effects are left active by apps |
| 762 | // in the background. |
Eric Laurent | b732cf5 | 2014-09-24 19:08:21 -0700 | [diff] [blame] | 763 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 764 | if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0) || |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 765 | !mEffects.isNonOffloadableEffectEnabled()) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 766 | profile = getProfileForDirectOutput(device, |
| 767 | samplingRate, |
| 768 | format, |
| 769 | channelMask, |
| 770 | (audio_output_flags_t)flags); |
| 771 | } |
| 772 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 773 | if (profile != 0) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 774 | sp<AudioOutputDescriptor> outputDesc = NULL; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 775 | |
| 776 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 777 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 778 | if (!desc->isDuplicated() && (profile == desc->mProfile)) { |
| 779 | outputDesc = desc; |
| 780 | // reuse direct output if currently open and configured with same parameters |
| 781 | if ((samplingRate == outputDesc->mSamplingRate) && |
| 782 | (format == outputDesc->mFormat) && |
| 783 | (channelMask == outputDesc->mChannelMask)) { |
| 784 | outputDesc->mDirectOpenCount++; |
| 785 | ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i)); |
| 786 | return mOutputs.keyAt(i); |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | // close direct output if currently open and configured with different parameters |
| 791 | if (outputDesc != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 792 | closeOutput(outputDesc->mIoHandle); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 793 | } |
| 794 | outputDesc = new AudioOutputDescriptor(profile); |
| 795 | outputDesc->mDevice = device; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 796 | outputDesc->mLatency = 0; |
| 797 | outputDesc->mFlags =(audio_output_flags_t) (outputDesc->mFlags | flags); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 798 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 799 | config.sample_rate = samplingRate; |
| 800 | config.channel_mask = channelMask; |
| 801 | config.format = format; |
Phil Burk | 77cce80 | 2014-08-04 16:18:15 -0700 | [diff] [blame] | 802 | if (offloadInfo != NULL) { |
| 803 | config.offload_info = *offloadInfo; |
| 804 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 805 | status = mpClientInterface->openOutput(profile->mModule->mHandle, |
| 806 | &output, |
| 807 | &config, |
| 808 | &outputDesc->mDevice, |
| 809 | String8(""), |
| 810 | &outputDesc->mLatency, |
| 811 | outputDesc->mFlags); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 812 | |
| 813 | // only accept an output with the requested parameters |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 814 | if (status != NO_ERROR || |
| 815 | (samplingRate != 0 && samplingRate != config.sample_rate) || |
| 816 | (format != AUDIO_FORMAT_DEFAULT && format != config.format) || |
| 817 | (channelMask != 0 && channelMask != config.channel_mask)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 818 | ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d," |
| 819 | "format %d %d, channelMask %04x %04x", output, samplingRate, |
| 820 | outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask, |
| 821 | outputDesc->mChannelMask); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 822 | if (output != AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 823 | mpClientInterface->closeOutput(output); |
| 824 | } |
Eric Laurent | a82797f | 2015-01-30 11:49:43 -0800 | [diff] [blame] | 825 | // fall back to mixer output if possible when the direct output could not be open |
| 826 | if (audio_is_linear_pcm(format) && samplingRate <= MAX_MIXER_SAMPLING_RATE) { |
| 827 | goto non_direct_output; |
| 828 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 829 | // fall back to mixer output if possible when the direct output could not be open |
| 830 | if (audio_is_linear_pcm(format) && samplingRate <= MAX_MIXER_SAMPLING_RATE) { |
| 831 | goto non_direct_output; |
| 832 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 833 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 834 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 835 | outputDesc->mSamplingRate = config.sample_rate; |
| 836 | outputDesc->mChannelMask = config.channel_mask; |
| 837 | outputDesc->mFormat = config.format; |
| 838 | outputDesc->mRefCount[stream] = 0; |
| 839 | outputDesc->mStopTime[stream] = 0; |
| 840 | outputDesc->mDirectOpenCount = 1; |
| 841 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 842 | audio_io_handle_t srcOutput = getOutputForEffect(); |
| 843 | addOutput(output, outputDesc); |
| 844 | audio_io_handle_t dstOutput = getOutputForEffect(); |
| 845 | if (dstOutput == output) { |
| 846 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput); |
| 847 | } |
| 848 | mPreviousOutputs = mOutputs; |
| 849 | ALOGV("getOutput() returns new direct output %d", output); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 850 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 851 | return output; |
| 852 | } |
| 853 | |
Eric Laurent | b732cf5 | 2014-09-24 19:08:21 -0700 | [diff] [blame] | 854 | non_direct_output: |
| 855 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 856 | // ignoring channel mask due to downmix capability in mixer |
| 857 | |
| 858 | // open a non direct output |
| 859 | |
| 860 | // for non direct outputs, only PCM is supported |
| 861 | if (audio_is_linear_pcm(format)) { |
| 862 | // get which output is suitable for the specified stream. The actual |
| 863 | // routing change will happen when startOutput() will be called |
| 864 | SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs); |
| 865 | |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 866 | // at this stage we should ignore the DIRECT flag as no direct output could be found earlier |
| 867 | flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT); |
| 868 | output = selectOutput(outputs, flags, format); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 869 | } |
| 870 | ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d," |
| 871 | "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags); |
| 872 | |
| 873 | ALOGV("getOutput() returns output %d", output); |
| 874 | |
| 875 | return output; |
| 876 | } |
| 877 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 878 | audio_io_handle_t AudioPolicyManager::selectOutput(const SortedVector<audio_io_handle_t>& outputs, |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 879 | audio_output_flags_t flags, |
| 880 | audio_format_t format) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 881 | { |
| 882 | // select one output among several that provide a path to a particular device or set of |
| 883 | // devices (the list was previously build by getOutputsForDevice()). |
| 884 | // The priority is as follows: |
| 885 | // 1: the output with the highest number of requested policy flags |
| 886 | // 2: the primary output |
| 887 | // 3: the first output in the list |
| 888 | |
| 889 | if (outputs.size() == 0) { |
| 890 | return 0; |
| 891 | } |
| 892 | if (outputs.size() == 1) { |
| 893 | return outputs[0]; |
| 894 | } |
| 895 | |
| 896 | int maxCommonFlags = 0; |
| 897 | audio_io_handle_t outputFlags = 0; |
| 898 | audio_io_handle_t outputPrimary = 0; |
| 899 | |
| 900 | for (size_t i = 0; i < outputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 901 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(outputs[i]); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 902 | if (!outputDesc->isDuplicated()) { |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 903 | // if a valid format is specified, skip output if not compatible |
| 904 | if (format != AUDIO_FORMAT_INVALID) { |
| 905 | if (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) { |
| 906 | if (format != outputDesc->mFormat) { |
| 907 | continue; |
| 908 | } |
| 909 | } else if (!audio_is_linear_pcm(format)) { |
| 910 | continue; |
| 911 | } |
| 912 | } |
| 913 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 914 | int commonFlags = popcount(outputDesc->mProfile->mFlags & flags); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 915 | if (commonFlags > maxCommonFlags) { |
| 916 | outputFlags = outputs[i]; |
| 917 | maxCommonFlags = commonFlags; |
| 918 | ALOGV("selectOutput() commonFlags for output %d, %04x", outputs[i], commonFlags); |
| 919 | } |
| 920 | if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 921 | outputPrimary = outputs[i]; |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if (outputFlags != 0) { |
| 927 | return outputFlags; |
| 928 | } |
| 929 | if (outputPrimary != 0) { |
| 930 | return outputPrimary; |
| 931 | } |
| 932 | |
| 933 | return outputs[0]; |
| 934 | } |
| 935 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 936 | status_t AudioPolicyManager::startOutput(audio_io_handle_t output, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 937 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 938 | audio_session_t session) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 939 | { |
| 940 | ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session); |
| 941 | ssize_t index = mOutputs.indexOfKey(output); |
| 942 | if (index < 0) { |
| 943 | ALOGW("startOutput() unknown output %d", output); |
| 944 | return BAD_VALUE; |
| 945 | } |
| 946 | |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 947 | // cannot start playback of STREAM_TTS if any other output is being used |
| 948 | uint32_t beaconMuteLatency = 0; |
| 949 | if (stream == AUDIO_STREAM_TTS) { |
| 950 | ALOGV("\t found BEACON stream"); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 951 | if (mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) { |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 952 | return INVALID_OPERATION; |
| 953 | } else { |
| 954 | beaconMuteLatency = handleEventForBeacon(STARTING_BEACON); |
| 955 | } |
| 956 | } else { |
| 957 | // some playback other than beacon starts |
| 958 | beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT); |
| 959 | } |
| 960 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 961 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueAt(index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 962 | |
| 963 | // increment usage count for this stream on the requested output: |
| 964 | // NOTE that the usage count is the same for duplicated output and hardware output which is |
| 965 | // necessary for a correct control of hardware output routing by startOutput() and stopOutput() |
| 966 | outputDesc->changeRefCount(stream, 1); |
| 967 | |
| 968 | if (outputDesc->mRefCount[stream] == 1) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 969 | // starting an output being rerouted? |
| 970 | audio_devices_t newDevice; |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 971 | if (outputDesc->mPolicyMix != NULL) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 972 | newDevice = AUDIO_DEVICE_OUT_REMOTE_SUBMIX; |
| 973 | } else { |
| 974 | newDevice = getNewOutputDevice(output, false /*fromCache*/); |
| 975 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 976 | routing_strategy strategy = getStrategy(stream); |
| 977 | bool shouldWait = (strategy == STRATEGY_SONIFICATION) || |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 978 | (strategy == STRATEGY_SONIFICATION_RESPECTFUL) || |
| 979 | (beaconMuteLatency > 0); |
| 980 | uint32_t waitMs = beaconMuteLatency; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 981 | bool force = false; |
| 982 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 983 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 984 | if (desc != outputDesc) { |
| 985 | // force a device change if any other output is managed by the same hw |
| 986 | // module and has a current device selection that differs from selected device. |
| 987 | // In this case, the audio HAL must receive the new device selection so that it can |
| 988 | // change the device currently selected by the other active output. |
| 989 | if (outputDesc->sharesHwModuleWith(desc) && |
| 990 | desc->device() != newDevice) { |
| 991 | force = true; |
| 992 | } |
| 993 | // wait for audio on other active outputs to be presented when starting |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 994 | // a notification so that audio focus effect can propagate, or that a mute/unmute |
| 995 | // event occurred for beacon |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 996 | uint32_t latency = desc->latency(); |
| 997 | if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) { |
| 998 | waitMs = latency; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | uint32_t muteWaitMs = setOutputDevice(output, newDevice, force); |
| 1003 | |
| 1004 | // handle special case for sonification while in call |
| 1005 | if (isInCall()) { |
| 1006 | handleIncallSonification(stream, true, false); |
| 1007 | } |
| 1008 | |
| 1009 | // apply volume rules for current stream and device if necessary |
| 1010 | checkAndSetVolume(stream, |
| 1011 | mStreams[stream].getVolumeIndex(newDevice), |
| 1012 | output, |
| 1013 | newDevice); |
| 1014 | |
| 1015 | // update the outputs if starting an output with a stream that can affect notification |
| 1016 | // routing |
| 1017 | handleNotificationRoutingForStream(stream); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1018 | |
| 1019 | // Automatically enable the remote submix input when output is started on a re routing mix |
| 1020 | // of type MIX_TYPE_RECORDERS |
| 1021 | if (audio_is_remote_submix_device(newDevice) && outputDesc->mPolicyMix != NULL && |
| 1022 | outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1023 | setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1024 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1025 | outputDesc->mPolicyMix->mRegistrationId, |
| 1026 | "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
Eric Laurent | 2cbe89a | 2014-12-19 11:49:08 -0800 | [diff] [blame] | 1029 | // force reevaluating accessibility routing when ringtone or alarm starts |
| 1030 | if (strategy == STRATEGY_SONIFICATION) { |
| 1031 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
| 1032 | } |
| 1033 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1034 | if (waitMs > muteWaitMs) { |
| 1035 | usleep((waitMs - muteWaitMs) * 2 * 1000); |
| 1036 | } |
| 1037 | } |
| 1038 | return NO_ERROR; |
| 1039 | } |
| 1040 | |
| 1041 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1042 | status_t AudioPolicyManager::stopOutput(audio_io_handle_t output, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 1043 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1044 | audio_session_t session) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1045 | { |
| 1046 | ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session); |
| 1047 | ssize_t index = mOutputs.indexOfKey(output); |
| 1048 | if (index < 0) { |
| 1049 | ALOGW("stopOutput() unknown output %d", output); |
| 1050 | return BAD_VALUE; |
| 1051 | } |
| 1052 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1053 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueAt(index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1054 | |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 1055 | // always handle stream stop, check which stream type is stopping |
| 1056 | handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT); |
| 1057 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1058 | // handle special case for sonification while in call |
| 1059 | if (isInCall()) { |
| 1060 | handleIncallSonification(stream, false, false); |
| 1061 | } |
| 1062 | |
| 1063 | if (outputDesc->mRefCount[stream] > 0) { |
| 1064 | // decrement usage count of this stream on the output |
| 1065 | outputDesc->changeRefCount(stream, -1); |
| 1066 | // store time at which the stream was stopped - see isStreamActive() |
| 1067 | if (outputDesc->mRefCount[stream] == 0) { |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1068 | // Automatically disable the remote submix input when output is stopped on a |
| 1069 | // re routing mix of type MIX_TYPE_RECORDERS |
| 1070 | if (audio_is_remote_submix_device(outputDesc->mDevice) && |
| 1071 | outputDesc->mPolicyMix != NULL && |
| 1072 | outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1073 | setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1074 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1075 | outputDesc->mPolicyMix->mRegistrationId, |
| 1076 | "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1079 | outputDesc->mStopTime[stream] = systemTime(); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1080 | audio_devices_t newDevice = getNewOutputDevice(output, false /*fromCache*/); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1081 | // delay the device switch by twice the latency because stopOutput() is executed when |
| 1082 | // the track stop() command is received and at that time the audio track buffer can |
| 1083 | // still contain data that needs to be drained. The latency only covers the audio HAL |
| 1084 | // and kernel buffers. Also the latency does not always include additional delay in the |
| 1085 | // audio path (audio DSP, CODEC ...) |
| 1086 | setOutputDevice(output, newDevice, false, outputDesc->mLatency*2); |
| 1087 | |
| 1088 | // force restoring the device selection on other active outputs if it differs from the |
| 1089 | // one being selected for this output |
| 1090 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1091 | audio_io_handle_t curOutput = mOutputs.keyAt(i); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1092 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1093 | if (curOutput != output && |
| 1094 | desc->isActive() && |
| 1095 | outputDesc->sharesHwModuleWith(desc) && |
| 1096 | (newDevice != desc->device())) { |
| 1097 | setOutputDevice(curOutput, |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1098 | getNewOutputDevice(curOutput, false /*fromCache*/), |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1099 | true, |
| 1100 | outputDesc->mLatency*2); |
| 1101 | } |
| 1102 | } |
| 1103 | // update the outputs if stopping one with a stream that can affect notification routing |
| 1104 | handleNotificationRoutingForStream(stream); |
| 1105 | } |
| 1106 | return NO_ERROR; |
| 1107 | } else { |
| 1108 | ALOGW("stopOutput() refcount is already 0 for output %d", output); |
| 1109 | return INVALID_OPERATION; |
| 1110 | } |
| 1111 | } |
| 1112 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1113 | void AudioPolicyManager::releaseOutput(audio_io_handle_t output, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1114 | audio_stream_type_t stream __unused, |
| 1115 | audio_session_t session __unused) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1116 | { |
| 1117 | ALOGV("releaseOutput() %d", output); |
| 1118 | ssize_t index = mOutputs.indexOfKey(output); |
| 1119 | if (index < 0) { |
| 1120 | ALOGW("releaseOutput() releasing unknown output %d", output); |
| 1121 | return; |
| 1122 | } |
| 1123 | |
| 1124 | #ifdef AUDIO_POLICY_TEST |
| 1125 | int testIndex = testOutputIndex(output); |
| 1126 | if (testIndex != 0) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1127 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueAt(index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1128 | if (outputDesc->isActive()) { |
| 1129 | mpClientInterface->closeOutput(output); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1130 | removeOutput(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1131 | mTestOutputs[testIndex] = 0; |
| 1132 | } |
| 1133 | return; |
| 1134 | } |
| 1135 | #endif //AUDIO_POLICY_TEST |
| 1136 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1137 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(index); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 1138 | if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1139 | if (desc->mDirectOpenCount <= 0) { |
| 1140 | ALOGW("releaseOutput() invalid open count %d for output %d", |
| 1141 | desc->mDirectOpenCount, output); |
| 1142 | return; |
| 1143 | } |
| 1144 | if (--desc->mDirectOpenCount == 0) { |
| 1145 | closeOutput(output); |
| 1146 | // If effects where present on the output, audioflinger moved them to the primary |
| 1147 | // output by default: move them back to the appropriate output. |
| 1148 | audio_io_handle_t dstOutput = getOutputForEffect(); |
| 1149 | if (dstOutput != mPrimaryOutput) { |
| 1150 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, mPrimaryOutput, dstOutput); |
| 1151 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1152 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1158 | status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr, |
| 1159 | audio_io_handle_t *input, |
| 1160 | audio_session_t session, |
| 1161 | uint32_t samplingRate, |
| 1162 | audio_format_t format, |
| 1163 | audio_channel_mask_t channelMask, |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 1164 | audio_input_flags_t flags, |
| 1165 | input_type_t *inputType) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1166 | { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1167 | ALOGV("getInputForAttr() source %d, samplingRate %d, format %d, channelMask %x," |
| 1168 | "session %d, flags %#x", |
| 1169 | attr->source, samplingRate, format, channelMask, session, flags); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1170 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1171 | *input = AUDIO_IO_HANDLE_NONE; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 1172 | *inputType = API_INPUT_INVALID; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1173 | audio_devices_t device; |
| 1174 | // handle legacy remote submix case where the address was not always specified |
| 1175 | String8 address = String8(""); |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1176 | bool isSoundTrigger = false; |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1177 | audio_source_t inputSource = attr->source; |
| 1178 | audio_source_t halInputSource; |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1179 | AudioMix *policyMix = NULL; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1180 | |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1181 | if (inputSource == AUDIO_SOURCE_DEFAULT) { |
| 1182 | inputSource = AUDIO_SOURCE_MIC; |
| 1183 | } |
| 1184 | halInputSource = inputSource; |
| 1185 | |
| 1186 | if (inputSource == AUDIO_SOURCE_REMOTE_SUBMIX && |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1187 | strncmp(attr->tags, "addr=", strlen("addr=")) == 0) { |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 1188 | status_t ret = mPolicyMixes.getInputMixForAttr(*attr, policyMix); |
| 1189 | if (ret != NO_ERROR) { |
| 1190 | return ret; |
| 1191 | } |
| 1192 | *inputType = API_INPUT_MIX_EXT_POLICY_REROUTE; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1193 | device = AUDIO_DEVICE_IN_REMOTE_SUBMIX; |
| 1194 | address = String8(attr->tags + strlen("addr=")); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1195 | } else { |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1196 | device = getDeviceAndMixForInputSource(inputSource, &policyMix); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1197 | if (device == AUDIO_DEVICE_NONE) { |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1198 | ALOGW("getInputForAttr() could not find device for source %d", inputSource); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1199 | return BAD_VALUE; |
| 1200 | } |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1201 | if (policyMix != NULL) { |
| 1202 | address = policyMix->mRegistrationId; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 1203 | if (policyMix->mMixType == MIX_TYPE_RECORDERS) { |
| 1204 | // there is an external policy, but this input is attached to a mix of recorders, |
| 1205 | // meaning it receives audio injected into the framework, so the recorder doesn't |
| 1206 | // know about it and is therefore considered "legacy" |
| 1207 | *inputType = API_INPUT_LEGACY; |
| 1208 | } else { |
| 1209 | // recording a mix of players defined by an external policy, we're rerouting for |
| 1210 | // an external policy |
| 1211 | *inputType = API_INPUT_MIX_EXT_POLICY_REROUTE; |
| 1212 | } |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1213 | } else if (audio_is_remote_submix_device(device)) { |
| 1214 | address = String8("0"); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 1215 | *inputType = API_INPUT_MIX_CAPTURE; |
| 1216 | } else { |
| 1217 | *inputType = API_INPUT_LEGACY; |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1218 | } |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1219 | // adapt channel selection to input source |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1220 | switch (inputSource) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1221 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 1222 | channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK; |
| 1223 | break; |
| 1224 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 1225 | channelMask = AUDIO_CHANNEL_IN_VOICE_DNLINK; |
| 1226 | break; |
| 1227 | case AUDIO_SOURCE_VOICE_CALL: |
| 1228 | channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK | AUDIO_CHANNEL_IN_VOICE_DNLINK; |
| 1229 | break; |
| 1230 | default: |
| 1231 | break; |
| 1232 | } |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1233 | if (inputSource == AUDIO_SOURCE_HOTWORD) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1234 | ssize_t index = mSoundTriggerSessions.indexOfKey(session); |
| 1235 | if (index >= 0) { |
| 1236 | *input = mSoundTriggerSessions.valueFor(session); |
| 1237 | isSoundTrigger = true; |
| 1238 | flags = (audio_input_flags_t)(flags | AUDIO_INPUT_FLAG_HW_HOTWORD); |
| 1239 | ALOGV("SoundTrigger capture on session %d input %d", session, *input); |
| 1240 | } else { |
| 1241 | halInputSource = AUDIO_SOURCE_VOICE_RECOGNITION; |
| 1242 | } |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1246 | sp<IOProfile> profile = getInputProfile(device, address, |
| 1247 | samplingRate, format, channelMask, |
| 1248 | flags); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1249 | if (profile == 0) { |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1250 | //retry without flags |
| 1251 | audio_input_flags_t log_flags = flags; |
| 1252 | flags = AUDIO_INPUT_FLAG_NONE; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1253 | profile = getInputProfile(device, address, |
| 1254 | samplingRate, format, channelMask, |
| 1255 | flags); |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1256 | if (profile == 0) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1257 | ALOGW("getInputForAttr() could not find profile for device 0x%X, samplingRate %u," |
| 1258 | "format %#x, channelMask 0x%X, flags %#x", |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1259 | device, samplingRate, format, channelMask, log_flags); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1260 | return BAD_VALUE; |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 1261 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | if (profile->mModule->mHandle == 0) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1265 | ALOGE("getInputForAttr(): HW module %s not opened", profile->mModule->mName); |
| 1266 | return NO_INIT; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 1270 | config.sample_rate = samplingRate; |
| 1271 | config.channel_mask = channelMask; |
| 1272 | config.format = format; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1273 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1274 | status_t status = mpClientInterface->openInput(profile->mModule->mHandle, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1275 | input, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1276 | &config, |
| 1277 | &device, |
Jean-Michel Trivi | fd4c148 | 2014-08-06 16:02:28 -0700 | [diff] [blame] | 1278 | address, |
Eric Laurent | 1c9c2cc | 2014-08-28 19:37:25 -0700 | [diff] [blame] | 1279 | halInputSource, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1280 | flags); |
| 1281 | |
| 1282 | // only accept input with the exact requested set of parameters |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1283 | if (status != NO_ERROR || *input == AUDIO_IO_HANDLE_NONE || |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1284 | (samplingRate != config.sample_rate) || |
| 1285 | (format != config.format) || |
| 1286 | (channelMask != config.channel_mask)) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1287 | ALOGW("getInputForAttr() failed opening input: samplingRate %d, format %d, channelMask %x", |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1288 | samplingRate, format, channelMask); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1289 | if (*input != AUDIO_IO_HANDLE_NONE) { |
| 1290 | mpClientInterface->closeInput(*input); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1291 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1292 | return BAD_VALUE; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1295 | sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(profile); |
Eric Laurent | c447ded | 2015-01-06 08:47:05 -0800 | [diff] [blame] | 1296 | inputDesc->mInputSource = inputSource; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1297 | inputDesc->mRefCount = 0; |
| 1298 | inputDesc->mOpenRefCount = 1; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1299 | inputDesc->mSamplingRate = samplingRate; |
| 1300 | inputDesc->mFormat = format; |
| 1301 | inputDesc->mChannelMask = channelMask; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1302 | inputDesc->mDevice = device; |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1303 | inputDesc->mSessions.add(session); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1304 | inputDesc->mIsSoundTrigger = isSoundTrigger; |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1305 | inputDesc->mPolicyMix = policyMix; |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1306 | |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 1307 | ALOGV("getInputForAttr() returns input type = %d", inputType); |
| 1308 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1309 | addInput(*input, inputDesc); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1310 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1311 | return NO_ERROR; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1314 | status_t AudioPolicyManager::startInput(audio_io_handle_t input, |
| 1315 | audio_session_t session) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1316 | { |
| 1317 | ALOGV("startInput() input %d", input); |
| 1318 | ssize_t index = mInputs.indexOfKey(input); |
| 1319 | if (index < 0) { |
| 1320 | ALOGW("startInput() unknown input %d", input); |
| 1321 | return BAD_VALUE; |
| 1322 | } |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1323 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1324 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1325 | index = inputDesc->mSessions.indexOf(session); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1326 | if (index < 0) { |
| 1327 | ALOGW("startInput() unknown session %d on input %d", session, input); |
| 1328 | return BAD_VALUE; |
| 1329 | } |
| 1330 | |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1331 | // virtual input devices are compatible with other input devices |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1332 | if (!is_virtual_input_device(inputDesc->mDevice)) { |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1333 | |
| 1334 | // for a non-virtual input device, check if there is another (non-virtual) active input |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1335 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1336 | if (activeInput != 0 && activeInput != input) { |
| 1337 | |
| 1338 | // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed, |
| 1339 | // otherwise the active input continues and the new input cannot be started. |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1340 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1341 | if (activeDesc->mInputSource == AUDIO_SOURCE_HOTWORD) { |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1342 | ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1343 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 1344 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1345 | } else { |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1346 | ALOGE("startInput(%d) failed: other input %d already started", input, activeInput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1347 | return INVALID_OPERATION; |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1352 | if (inputDesc->mRefCount == 0) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1353 | if (mInputs.activeInputsCount() == 0) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1354 | SoundTrigger::setCaptureState(true); |
| 1355 | } |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1356 | setInputDevice(input, getNewInputDevice(input), true /* force */); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1357 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1358 | // automatically enable the remote submix output when input is started if not |
| 1359 | // used by a policy mix of type MIX_TYPE_RECORDERS |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1360 | // For remote submix (a virtual device), we open only one input per capture request. |
| 1361 | if (audio_is_remote_submix_device(inputDesc->mDevice)) { |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1362 | String8 address = String8(""); |
| 1363 | if (inputDesc->mPolicyMix == NULL) { |
| 1364 | address = String8("0"); |
| 1365 | } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { |
| 1366 | address = inputDesc->mPolicyMix->mRegistrationId; |
| 1367 | } |
| 1368 | if (address != "") { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1369 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1370 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1371 | address, "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1372 | } |
Glenn Kasten | 74a8e25 | 2014-07-24 14:09:55 -0700 | [diff] [blame] | 1373 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1376 | ALOGV("AudioPolicyManager::startInput() input source = %d", inputDesc->mInputSource); |
| 1377 | |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1378 | inputDesc->mRefCount++; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1379 | return NO_ERROR; |
| 1380 | } |
| 1381 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1382 | status_t AudioPolicyManager::stopInput(audio_io_handle_t input, |
| 1383 | audio_session_t session) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1384 | { |
| 1385 | ALOGV("stopInput() input %d", input); |
| 1386 | ssize_t index = mInputs.indexOfKey(input); |
| 1387 | if (index < 0) { |
| 1388 | ALOGW("stopInput() unknown input %d", input); |
| 1389 | return BAD_VALUE; |
| 1390 | } |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1391 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1392 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1393 | index = inputDesc->mSessions.indexOf(session); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1394 | if (index < 0) { |
| 1395 | ALOGW("stopInput() unknown session %d on input %d", session, input); |
| 1396 | return BAD_VALUE; |
| 1397 | } |
| 1398 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1399 | if (inputDesc->mRefCount == 0) { |
| 1400 | ALOGW("stopInput() input %d already stopped", input); |
| 1401 | return INVALID_OPERATION; |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | inputDesc->mRefCount--; |
| 1405 | if (inputDesc->mRefCount == 0) { |
| 1406 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1407 | // automatically disable the remote submix output when input is stopped if not |
| 1408 | // used by a policy mix of type MIX_TYPE_RECORDERS |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1409 | if (audio_is_remote_submix_device(inputDesc->mDevice)) { |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1410 | String8 address = String8(""); |
| 1411 | if (inputDesc->mPolicyMix == NULL) { |
| 1412 | address = String8("0"); |
| 1413 | } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { |
| 1414 | address = inputDesc->mPolicyMix->mRegistrationId; |
| 1415 | } |
| 1416 | if (address != "") { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1417 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1418 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1419 | address, "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1420 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1423 | resetInputDevice(input); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1424 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1425 | if (mInputs.activeInputsCount() == 0) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1426 | SoundTrigger::setCaptureState(false); |
| 1427 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1428 | } |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1429 | return NO_ERROR; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1432 | void AudioPolicyManager::releaseInput(audio_io_handle_t input, |
| 1433 | audio_session_t session) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1434 | { |
| 1435 | ALOGV("releaseInput() %d", input); |
| 1436 | ssize_t index = mInputs.indexOfKey(input); |
| 1437 | if (index < 0) { |
| 1438 | ALOGW("releaseInput() releasing unknown input %d", input); |
| 1439 | return; |
| 1440 | } |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1441 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index); |
| 1442 | ALOG_ASSERT(inputDesc != 0); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1443 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1444 | index = inputDesc->mSessions.indexOf(session); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1445 | if (index < 0) { |
| 1446 | ALOGW("releaseInput() unknown session %d on input %d", session, input); |
| 1447 | return; |
| 1448 | } |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1449 | inputDesc->mSessions.remove(session); |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 1450 | if (inputDesc->mOpenRefCount == 0) { |
| 1451 | ALOGW("releaseInput() invalid open ref count %d", inputDesc->mOpenRefCount); |
| 1452 | return; |
| 1453 | } |
| 1454 | inputDesc->mOpenRefCount--; |
| 1455 | if (inputDesc->mOpenRefCount > 0) { |
| 1456 | ALOGV("releaseInput() exit > 0"); |
| 1457 | return; |
| 1458 | } |
| 1459 | |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 1460 | closeInput(input); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1461 | mpClientInterface->onAudioPortListUpdate(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1462 | ALOGV("releaseInput() exit"); |
| 1463 | } |
| 1464 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1465 | void AudioPolicyManager::closeAllInputs() { |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 1466 | bool patchRemoved = false; |
| 1467 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1468 | for(size_t input_index = 0; input_index < mInputs.size(); input_index++) { |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 1469 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index); |
| 1470 | ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->mPatchHandle); |
| 1471 | if (patch_index >= 0) { |
| 1472 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index); |
| 1473 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
| 1474 | mAudioPatches.removeItemsAt(patch_index); |
| 1475 | patchRemoved = true; |
| 1476 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1477 | mpClientInterface->closeInput(mInputs.keyAt(input_index)); |
| 1478 | } |
| 1479 | mInputs.clear(); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1480 | nextAudioPortGeneration(); |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 1481 | |
| 1482 | if (patchRemoved) { |
| 1483 | mpClientInterface->onAudioPatchListUpdate(); |
| 1484 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1487 | void AudioPolicyManager::initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1488 | int indexMin, |
| 1489 | int indexMax) |
| 1490 | { |
| 1491 | ALOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1492 | mEngine->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1493 | //FIXME: AUDIO_STREAM_ACCESSIBILITY volume follows AUDIO_STREAM_MUSIC for now |
| 1494 | if (stream == AUDIO_STREAM_MUSIC) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1495 | mEngine->initStreamVolume(AUDIO_STREAM_ACCESSIBILITY, indexMin, indexMax); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1496 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1499 | status_t AudioPolicyManager::setStreamVolumeIndex(audio_stream_type_t stream, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1500 | int index, |
| 1501 | audio_devices_t device) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1502 | { |
| 1503 | |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1504 | if ((index < mStreams[stream].getVolumeIndexMin()) || |
| 1505 | (index > mStreams[stream].getVolumeIndexMax())) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1506 | return BAD_VALUE; |
| 1507 | } |
| 1508 | if (!audio_is_output_device(device)) { |
| 1509 | return BAD_VALUE; |
| 1510 | } |
| 1511 | |
| 1512 | // Force max volume if stream cannot be muted |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1513 | if (!mStreams.canBeMuted(stream)) index = mStreams[stream].getVolumeIndexMax(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1514 | |
| 1515 | ALOGV("setStreamVolumeIndex() stream %d, device %04x, index %d", |
| 1516 | stream, device, index); |
| 1517 | |
| 1518 | // if device is AUDIO_DEVICE_OUT_DEFAULT set default value and |
| 1519 | // clear all device specific values |
| 1520 | if (device == AUDIO_DEVICE_OUT_DEFAULT) { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1521 | mStreams.clearCurrentVolumeIndex(stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1522 | } |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1523 | mStreams.addCurrentVolumeIndex(stream, device, index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1524 | |
Eric Laurent | 31551f8 | 2014-10-10 18:21:56 -0700 | [diff] [blame] | 1525 | // update volume on all outputs whose current device is also selected by the same |
| 1526 | // strategy as the device specified by the caller |
| 1527 | audio_devices_t strategyDevice = getDeviceForStrategy(getStrategy(stream), true /*fromCache*/); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1528 | |
| 1529 | |
| 1530 | //FIXME: AUDIO_STREAM_ACCESSIBILITY volume follows AUDIO_STREAM_MUSIC for now |
| 1531 | audio_devices_t accessibilityDevice = AUDIO_DEVICE_NONE; |
| 1532 | if (stream == AUDIO_STREAM_MUSIC) { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1533 | mStreams.addCurrentVolumeIndex(AUDIO_STREAM_ACCESSIBILITY, device, index); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1534 | accessibilityDevice = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, true /*fromCache*/); |
| 1535 | } |
| 1536 | if ((device != AUDIO_DEVICE_OUT_DEFAULT) && |
| 1537 | (device & (strategyDevice | accessibilityDevice)) == 0) { |
Eric Laurent | 31551f8 | 2014-10-10 18:21:56 -0700 | [diff] [blame] | 1538 | return NO_ERROR; |
| 1539 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1540 | status_t status = NO_ERROR; |
| 1541 | for (size_t i = 0; i < mOutputs.size(); i++) { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1542 | audio_devices_t curDevice = Volume::getDeviceForVolume(mOutputs.valueAt(i)->device()); |
Eric Laurent | 31551f8 | 2014-10-10 18:21:56 -0700 | [diff] [blame] | 1543 | if ((device == AUDIO_DEVICE_OUT_DEFAULT) || ((curDevice & strategyDevice) != 0)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1544 | status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), curDevice); |
| 1545 | if (volStatus != NO_ERROR) { |
| 1546 | status = volStatus; |
| 1547 | } |
| 1548 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1549 | if ((device == AUDIO_DEVICE_OUT_DEFAULT) || ((curDevice & accessibilityDevice) != 0)) { |
| 1550 | status_t volStatus = checkAndSetVolume(AUDIO_STREAM_ACCESSIBILITY, |
| 1551 | index, mOutputs.keyAt(i), curDevice); |
| 1552 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1553 | } |
| 1554 | return status; |
| 1555 | } |
| 1556 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1557 | status_t AudioPolicyManager::getStreamVolumeIndex(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1558 | int *index, |
| 1559 | audio_devices_t device) |
| 1560 | { |
| 1561 | if (index == NULL) { |
| 1562 | return BAD_VALUE; |
| 1563 | } |
| 1564 | if (!audio_is_output_device(device)) { |
| 1565 | return BAD_VALUE; |
| 1566 | } |
| 1567 | // if device is AUDIO_DEVICE_OUT_DEFAULT, return volume for device corresponding to |
| 1568 | // the strategy the stream belongs to. |
| 1569 | if (device == AUDIO_DEVICE_OUT_DEFAULT) { |
| 1570 | device = getDeviceForStrategy(getStrategy(stream), true /*fromCache*/); |
| 1571 | } |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1572 | device = Volume::getDeviceForVolume(device); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1573 | |
| 1574 | *index = mStreams[stream].getVolumeIndex(device); |
| 1575 | ALOGV("getStreamVolumeIndex() stream %d device %08x index %d", stream, device, *index); |
| 1576 | return NO_ERROR; |
| 1577 | } |
| 1578 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1579 | audio_io_handle_t AudioPolicyManager::selectOutputForEffects( |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1580 | const SortedVector<audio_io_handle_t>& outputs) |
| 1581 | { |
| 1582 | // select one output among several suitable for global effects. |
| 1583 | // The priority is as follows: |
| 1584 | // 1: An offloaded output. If the effect ends up not being offloadable, |
| 1585 | // AudioFlinger will invalidate the track and the offloaded output |
| 1586 | // will be closed causing the effect to be moved to a PCM output. |
| 1587 | // 2: A deep buffer output |
| 1588 | // 3: the first output in the list |
| 1589 | |
| 1590 | if (outputs.size() == 0) { |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | audio_io_handle_t outputOffloaded = 0; |
| 1595 | audio_io_handle_t outputDeepBuffer = 0; |
| 1596 | |
| 1597 | for (size_t i = 0; i < outputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1598 | sp<AudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1599 | ALOGV("selectOutputForEffects outputs[%zu] flags %x", i, desc->mFlags); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1600 | if ((desc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) { |
| 1601 | outputOffloaded = outputs[i]; |
| 1602 | } |
| 1603 | if ((desc->mFlags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) != 0) { |
| 1604 | outputDeepBuffer = outputs[i]; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | ALOGV("selectOutputForEffects outputOffloaded %d outputDeepBuffer %d", |
| 1609 | outputOffloaded, outputDeepBuffer); |
| 1610 | if (outputOffloaded != 0) { |
| 1611 | return outputOffloaded; |
| 1612 | } |
| 1613 | if (outputDeepBuffer != 0) { |
| 1614 | return outputDeepBuffer; |
| 1615 | } |
| 1616 | |
| 1617 | return outputs[0]; |
| 1618 | } |
| 1619 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1620 | audio_io_handle_t AudioPolicyManager::getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1621 | { |
| 1622 | // apply simple rule where global effects are attached to the same output as MUSIC streams |
| 1623 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 1624 | routing_strategy strategy = getStrategy(AUDIO_STREAM_MUSIC); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1625 | audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/); |
| 1626 | SortedVector<audio_io_handle_t> dstOutputs = getOutputsForDevice(device, mOutputs); |
| 1627 | |
| 1628 | audio_io_handle_t output = selectOutputForEffects(dstOutputs); |
| 1629 | ALOGV("getOutputForEffect() got output %d for fx %s flags %x", |
| 1630 | output, (desc == NULL) ? "unspecified" : desc->name, (desc == NULL) ? 0 : desc->flags); |
| 1631 | |
| 1632 | return output; |
| 1633 | } |
| 1634 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1635 | status_t AudioPolicyManager::registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1636 | audio_io_handle_t io, |
| 1637 | uint32_t strategy, |
| 1638 | int session, |
| 1639 | int id) |
| 1640 | { |
| 1641 | ssize_t index = mOutputs.indexOfKey(io); |
| 1642 | if (index < 0) { |
| 1643 | index = mInputs.indexOfKey(io); |
| 1644 | if (index < 0) { |
| 1645 | ALOGW("registerEffect() unknown io %d", io); |
| 1646 | return INVALID_OPERATION; |
| 1647 | } |
| 1648 | } |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 1649 | return mEffects.registerEffect(desc, io, strategy, session, id); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1652 | bool AudioPolicyManager::isSourceActive(audio_source_t source) const |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1653 | { |
| 1654 | for (size_t i = 0; i < mInputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 1655 | const sp<AudioInputDescriptor> inputDescriptor = mInputs.valueAt(i); |
Eric Laurent | a34c9ce | 2014-12-19 11:16:32 -0800 | [diff] [blame] | 1656 | if (inputDescriptor->mRefCount == 0) { |
| 1657 | continue; |
| 1658 | } |
| 1659 | if (inputDescriptor->mInputSource == (int)source) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1660 | return true; |
| 1661 | } |
Eric Laurent | a34c9ce | 2014-12-19 11:16:32 -0800 | [diff] [blame] | 1662 | // AUDIO_SOURCE_HOTWORD is equivalent to AUDIO_SOURCE_VOICE_RECOGNITION only if it |
| 1663 | // corresponds to an active capture triggered by a hardware hotword recognition |
| 1664 | if ((source == AUDIO_SOURCE_VOICE_RECOGNITION) && |
| 1665 | (inputDescriptor->mInputSource == AUDIO_SOURCE_HOTWORD)) { |
| 1666 | // FIXME: we should not assume that the first session is the active one and keep |
| 1667 | // activity count per session. Same in startInput(). |
| 1668 | ssize_t index = mSoundTriggerSessions.indexOfKey(inputDescriptor->mSessions.itemAt(0)); |
| 1669 | if (index >= 0) { |
| 1670 | return true; |
| 1671 | } |
| 1672 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1673 | } |
| 1674 | return false; |
| 1675 | } |
| 1676 | |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1677 | // Register a list of custom mixes with their attributes and format. |
| 1678 | // When a mix is registered, corresponding input and output profiles are |
| 1679 | // added to the remote submix hw module. The profile contains only the |
| 1680 | // parameters (sampling rate, format...) specified by the mix. |
| 1681 | // The corresponding input remote submix device is also connected. |
| 1682 | // |
| 1683 | // When a remote submix device is connected, the address is checked to select the |
| 1684 | // appropriate profile and the corresponding input or output stream is opened. |
| 1685 | // |
| 1686 | // When capture starts, getInputForAttr() will: |
| 1687 | // - 1 look for a mix matching the address passed in attribtutes tags if any |
| 1688 | // - 2 if none found, getDeviceForInputSource() will: |
| 1689 | // - 2.1 look for a mix matching the attributes source |
| 1690 | // - 2.2 if none found, default to device selection by policy rules |
| 1691 | // At this time, the corresponding output remote submix device is also connected |
| 1692 | // and active playback use cases can be transferred to this mix if needed when reconnecting |
| 1693 | // after AudioTracks are invalidated |
| 1694 | // |
| 1695 | // When playback starts, getOutputForAttr() will: |
| 1696 | // - 1 look for a mix matching the address passed in attribtutes tags if any |
| 1697 | // - 2 if none found, look for a mix matching the attributes usage |
| 1698 | // - 3 if none found, default to device and output selection by policy rules. |
| 1699 | |
| 1700 | status_t AudioPolicyManager::registerPolicyMixes(Vector<AudioMix> mixes) |
| 1701 | { |
| 1702 | sp<HwModule> module; |
| 1703 | for (size_t i = 0; i < mHwModules.size(); i++) { |
| 1704 | if (strcmp(AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX, mHwModules[i]->mName) == 0 && |
| 1705 | mHwModules[i]->mHandle != 0) { |
| 1706 | module = mHwModules[i]; |
| 1707 | break; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | if (module == 0) { |
| 1712 | return INVALID_OPERATION; |
| 1713 | } |
| 1714 | |
| 1715 | ALOGV("registerPolicyMixes() num mixes %d", mixes.size()); |
| 1716 | |
| 1717 | for (size_t i = 0; i < mixes.size(); i++) { |
| 1718 | String8 address = mixes[i].mRegistrationId; |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 1719 | |
| 1720 | if (mPolicyMixes.registerMix(address, mixes[i]) != NO_ERROR) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1721 | continue; |
| 1722 | } |
| 1723 | audio_config_t outputConfig = mixes[i].mFormat; |
| 1724 | audio_config_t inputConfig = mixes[i].mFormat; |
| 1725 | // NOTE: audio flinger mixer does not support mono output: configure remote submix HAL in |
| 1726 | // stereo and let audio flinger do the channel conversion if needed. |
| 1727 | outputConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1728 | inputConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 1729 | module->addOutputProfile(address, &outputConfig, |
| 1730 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address); |
| 1731 | module->addInputProfile(address, &inputConfig, |
| 1732 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, address); |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 1733 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1734 | if (mixes[i].mMixType == MIX_TYPE_PLAYERS) { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1735 | setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1736 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1737 | address.string(), "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1738 | } else { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1739 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1740 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1741 | address.string(), "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1742 | } |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1743 | } |
| 1744 | return NO_ERROR; |
| 1745 | } |
| 1746 | |
| 1747 | status_t AudioPolicyManager::unregisterPolicyMixes(Vector<AudioMix> mixes) |
| 1748 | { |
| 1749 | sp<HwModule> module; |
| 1750 | for (size_t i = 0; i < mHwModules.size(); i++) { |
| 1751 | if (strcmp(AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX, mHwModules[i]->mName) == 0 && |
| 1752 | mHwModules[i]->mHandle != 0) { |
| 1753 | module = mHwModules[i]; |
| 1754 | break; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | if (module == 0) { |
| 1759 | return INVALID_OPERATION; |
| 1760 | } |
| 1761 | |
| 1762 | ALOGV("unregisterPolicyMixes() num mixes %d", mixes.size()); |
| 1763 | |
| 1764 | for (size_t i = 0; i < mixes.size(); i++) { |
| 1765 | String8 address = mixes[i].mRegistrationId; |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 1766 | |
| 1767 | if (mPolicyMixes.unregisterMix(address) != NO_ERROR) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1768 | continue; |
| 1769 | } |
| 1770 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1771 | if (getDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, address.string()) == |
| 1772 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE) |
| 1773 | { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1774 | setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1775 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1776 | address.string(), "remote-submix"); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 1777 | } |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1778 | |
| 1779 | if (getDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address.string()) == |
| 1780 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE) |
| 1781 | { |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 1782 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1783 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1784 | address.string(), "remote-submix"); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1785 | } |
| 1786 | module->removeOutputProfile(address); |
| 1787 | module->removeInputProfile(address); |
| 1788 | } |
| 1789 | return NO_ERROR; |
| 1790 | } |
| 1791 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1792 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1793 | status_t AudioPolicyManager::dump(int fd) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1794 | { |
| 1795 | const size_t SIZE = 256; |
| 1796 | char buffer[SIZE]; |
| 1797 | String8 result; |
| 1798 | |
| 1799 | snprintf(buffer, SIZE, "\nAudioPolicyManager Dump: %p\n", this); |
| 1800 | result.append(buffer); |
| 1801 | |
| 1802 | snprintf(buffer, SIZE, " Primary Output: %d\n", mPrimaryOutput); |
| 1803 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1804 | snprintf(buffer, SIZE, " Phone state: %d\n", mEngine->getPhoneState()); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1805 | result.append(buffer); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 1806 | snprintf(buffer, SIZE, " Force use for communications %d\n", |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1807 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1808 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1809 | snprintf(buffer, SIZE, " Force use for media %d\n", mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1810 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1811 | snprintf(buffer, SIZE, " Force use for record %d\n", mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_RECORD)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1812 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1813 | snprintf(buffer, SIZE, " Force use for dock %d\n", mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_DOCK)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1814 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1815 | snprintf(buffer, SIZE, " Force use for system %d\n", mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1816 | result.append(buffer); |
Jungshik Jang | 7b24ee3 | 2014-07-15 19:38:42 +0900 | [diff] [blame] | 1817 | snprintf(buffer, SIZE, " Force use for hdmi system audio %d\n", |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1818 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO)); |
Jungshik Jang | 7b24ee3 | 2014-07-15 19:38:42 +0900 | [diff] [blame] | 1819 | result.append(buffer); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 1820 | write(fd, result.string(), result.size()); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1821 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1822 | mAvailableOutputDevices.dump(fd, String8("output")); |
| 1823 | mAvailableInputDevices.dump(fd, String8("input")); |
| 1824 | mHwModules.dump(fd); |
| 1825 | mOutputs.dump(fd); |
| 1826 | mInputs.dump(fd); |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1827 | mStreams.dump(fd); |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 1828 | mEffects.dump(fd); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1829 | mAudioPatches.dump(fd); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1830 | |
| 1831 | return NO_ERROR; |
| 1832 | } |
| 1833 | |
| 1834 | // This function checks for the parameters which can be offloaded. |
| 1835 | // This can be enhanced depending on the capability of the DSP and policy |
| 1836 | // of the system. |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 1837 | bool AudioPolicyManager::isOffloadSupported(const audio_offload_info_t& offloadInfo) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1838 | { |
| 1839 | ALOGV("isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d," |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 1840 | " BitRate=%u, duration=%" PRId64 " us, has_video=%d", |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1841 | offloadInfo.sample_rate, offloadInfo.channel_mask, |
| 1842 | offloadInfo.format, |
| 1843 | offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us, |
| 1844 | offloadInfo.has_video); |
| 1845 | |
| 1846 | // Check if offload has been disabled |
| 1847 | char propValue[PROPERTY_VALUE_MAX]; |
| 1848 | if (property_get("audio.offload.disable", propValue, "0")) { |
| 1849 | if (atoi(propValue) != 0) { |
| 1850 | ALOGV("offload disabled by audio.offload.disable=%s", propValue ); |
| 1851 | return false; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | // Check if stream type is music, then only allow offload as of now. |
| 1856 | if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC) |
| 1857 | { |
| 1858 | ALOGV("isOffloadSupported: stream_type != MUSIC, returning false"); |
| 1859 | return false; |
| 1860 | } |
| 1861 | |
| 1862 | //TODO: enable audio offloading with video when ready |
| 1863 | if (offloadInfo.has_video) |
| 1864 | { |
| 1865 | ALOGV("isOffloadSupported: has_video == true, returning false"); |
| 1866 | return false; |
| 1867 | } |
| 1868 | |
| 1869 | //If duration is less than minimum value defined in property, return false |
| 1870 | if (property_get("audio.offload.min.duration.secs", propValue, NULL)) { |
| 1871 | if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) { |
| 1872 | ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue); |
| 1873 | return false; |
| 1874 | } |
| 1875 | } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) { |
| 1876 | ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS); |
| 1877 | return false; |
| 1878 | } |
| 1879 | |
| 1880 | // Do not allow offloading if one non offloadable effect is enabled. This prevents from |
| 1881 | // creating an offloaded track and tearing it down immediately after start when audioflinger |
| 1882 | // detects there is an active non offloadable effect. |
| 1883 | // FIXME: We should check the audio session here but we do not have it in this context. |
| 1884 | // This may prevent offloading in rare situations where effects are left active by apps |
| 1885 | // in the background. |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 1886 | if (mEffects.isNonOffloadableEffectEnabled()) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1887 | return false; |
| 1888 | } |
| 1889 | |
| 1890 | // See if there is a profile to support this. |
| 1891 | // AUDIO_DEVICE_NONE |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1892 | sp<IOProfile> profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1893 | offloadInfo.sample_rate, |
| 1894 | offloadInfo.format, |
| 1895 | offloadInfo.channel_mask, |
| 1896 | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1897 | ALOGV("isOffloadSupported() profile %sfound", profile != 0 ? "" : "NOT "); |
| 1898 | return (profile != 0); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1901 | status_t AudioPolicyManager::listAudioPorts(audio_port_role_t role, |
| 1902 | audio_port_type_t type, |
| 1903 | unsigned int *num_ports, |
| 1904 | struct audio_port *ports, |
| 1905 | unsigned int *generation) |
| 1906 | { |
| 1907 | if (num_ports == NULL || (*num_ports != 0 && ports == NULL) || |
| 1908 | generation == NULL) { |
| 1909 | return BAD_VALUE; |
| 1910 | } |
| 1911 | ALOGV("listAudioPorts() role %d type %d num_ports %d ports %p", role, type, *num_ports, ports); |
| 1912 | if (ports == NULL) { |
| 1913 | *num_ports = 0; |
| 1914 | } |
| 1915 | |
| 1916 | size_t portsWritten = 0; |
| 1917 | size_t portsMax = *num_ports; |
| 1918 | *num_ports = 0; |
| 1919 | if (type == AUDIO_PORT_TYPE_NONE || type == AUDIO_PORT_TYPE_DEVICE) { |
| 1920 | if (role == AUDIO_PORT_ROLE_SINK || role == AUDIO_PORT_ROLE_NONE) { |
| 1921 | for (size_t i = 0; |
| 1922 | i < mAvailableOutputDevices.size() && portsWritten < portsMax; i++) { |
| 1923 | mAvailableOutputDevices[i]->toAudioPort(&ports[portsWritten++]); |
| 1924 | } |
| 1925 | *num_ports += mAvailableOutputDevices.size(); |
| 1926 | } |
| 1927 | if (role == AUDIO_PORT_ROLE_SOURCE || role == AUDIO_PORT_ROLE_NONE) { |
| 1928 | for (size_t i = 0; |
| 1929 | i < mAvailableInputDevices.size() && portsWritten < portsMax; i++) { |
| 1930 | mAvailableInputDevices[i]->toAudioPort(&ports[portsWritten++]); |
| 1931 | } |
| 1932 | *num_ports += mAvailableInputDevices.size(); |
| 1933 | } |
| 1934 | } |
| 1935 | if (type == AUDIO_PORT_TYPE_NONE || type == AUDIO_PORT_TYPE_MIX) { |
| 1936 | if (role == AUDIO_PORT_ROLE_SINK || role == AUDIO_PORT_ROLE_NONE) { |
| 1937 | for (size_t i = 0; i < mInputs.size() && portsWritten < portsMax; i++) { |
| 1938 | mInputs[i]->toAudioPort(&ports[portsWritten++]); |
| 1939 | } |
| 1940 | *num_ports += mInputs.size(); |
| 1941 | } |
| 1942 | if (role == AUDIO_PORT_ROLE_SOURCE || role == AUDIO_PORT_ROLE_NONE) { |
Eric Laurent | 84c7024 | 2014-06-23 08:46:27 -0700 | [diff] [blame] | 1943 | size_t numOutputs = 0; |
| 1944 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1945 | if (!mOutputs[i]->isDuplicated()) { |
| 1946 | numOutputs++; |
| 1947 | if (portsWritten < portsMax) { |
| 1948 | mOutputs[i]->toAudioPort(&ports[portsWritten++]); |
| 1949 | } |
| 1950 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1951 | } |
Eric Laurent | 84c7024 | 2014-06-23 08:46:27 -0700 | [diff] [blame] | 1952 | *num_ports += numOutputs; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1953 | } |
| 1954 | } |
| 1955 | *generation = curAudioPortGeneration(); |
Mark Salyzyn | beb9e30 | 2014-06-18 16:33:15 -0700 | [diff] [blame] | 1956 | ALOGV("listAudioPorts() got %zu ports needed %d", portsWritten, *num_ports); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1957 | return NO_ERROR; |
| 1958 | } |
| 1959 | |
| 1960 | status_t AudioPolicyManager::getAudioPort(struct audio_port *port __unused) |
| 1961 | { |
| 1962 | return NO_ERROR; |
| 1963 | } |
| 1964 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1965 | status_t AudioPolicyManager::createAudioPatch(const struct audio_patch *patch, |
| 1966 | audio_patch_handle_t *handle, |
| 1967 | uid_t uid) |
| 1968 | { |
| 1969 | ALOGV("createAudioPatch()"); |
| 1970 | |
| 1971 | if (handle == NULL || patch == NULL) { |
| 1972 | return BAD_VALUE; |
| 1973 | } |
| 1974 | ALOGV("createAudioPatch() num sources %d num sinks %d", patch->num_sources, patch->num_sinks); |
| 1975 | |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 1976 | if (patch->num_sources == 0 || patch->num_sources > AUDIO_PATCH_PORTS_MAX || |
| 1977 | patch->num_sinks == 0 || patch->num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1978 | return BAD_VALUE; |
| 1979 | } |
| 1980 | // only one source per audio patch supported for now |
| 1981 | if (patch->num_sources > 1) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1982 | return INVALID_OPERATION; |
| 1983 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 1984 | |
| 1985 | if (patch->sources[0].role != AUDIO_PORT_ROLE_SOURCE) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1986 | return INVALID_OPERATION; |
| 1987 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 1988 | for (size_t i = 0; i < patch->num_sinks; i++) { |
| 1989 | if (patch->sinks[i].role != AUDIO_PORT_ROLE_SINK) { |
| 1990 | return INVALID_OPERATION; |
| 1991 | } |
| 1992 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1993 | |
| 1994 | sp<AudioPatch> patchDesc; |
| 1995 | ssize_t index = mAudioPatches.indexOfKey(*handle); |
| 1996 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1997 | ALOGV("createAudioPatch source id %d role %d type %d", patch->sources[0].id, |
| 1998 | patch->sources[0].role, |
| 1999 | patch->sources[0].type); |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2000 | #if LOG_NDEBUG == 0 |
| 2001 | for (size_t i = 0; i < patch->num_sinks; i++) { |
| 2002 | ALOGV("createAudioPatch sink %d: id %d role %d type %d", i, patch->sinks[i].id, |
| 2003 | patch->sinks[i].role, |
| 2004 | patch->sinks[i].type); |
| 2005 | } |
| 2006 | #endif |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2007 | |
| 2008 | if (index >= 0) { |
| 2009 | patchDesc = mAudioPatches.valueAt(index); |
| 2010 | ALOGV("createAudioPatch() mUidCached %d patchDesc->mUid %d uid %d", |
| 2011 | mUidCached, patchDesc->mUid, uid); |
| 2012 | if (patchDesc->mUid != mUidCached && uid != patchDesc->mUid) { |
| 2013 | return INVALID_OPERATION; |
| 2014 | } |
| 2015 | } else { |
| 2016 | *handle = 0; |
| 2017 | } |
| 2018 | |
| 2019 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2020 | sp<AudioOutputDescriptor> outputDesc = mOutputs.getOutputFromId(patch->sources[0].id); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2021 | if (outputDesc == NULL) { |
| 2022 | ALOGV("createAudioPatch() output not found for id %d", patch->sources[0].id); |
| 2023 | return BAD_VALUE; |
| 2024 | } |
Eric Laurent | 84c7024 | 2014-06-23 08:46:27 -0700 | [diff] [blame] | 2025 | ALOG_ASSERT(!outputDesc->isDuplicated(),"duplicated output %d in source in ports", |
| 2026 | outputDesc->mIoHandle); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2027 | if (patchDesc != 0) { |
| 2028 | if (patchDesc->mPatch.sources[0].id != patch->sources[0].id) { |
| 2029 | ALOGV("createAudioPatch() source id differs for patch current id %d new id %d", |
| 2030 | patchDesc->mPatch.sources[0].id, patch->sources[0].id); |
| 2031 | return BAD_VALUE; |
| 2032 | } |
| 2033 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2034 | DeviceVector devices; |
| 2035 | for (size_t i = 0; i < patch->num_sinks; i++) { |
| 2036 | // Only support mix to devices connection |
| 2037 | // TODO add support for mix to mix connection |
| 2038 | if (patch->sinks[i].type != AUDIO_PORT_TYPE_DEVICE) { |
| 2039 | ALOGV("createAudioPatch() source mix but sink is not a device"); |
| 2040 | return INVALID_OPERATION; |
| 2041 | } |
| 2042 | sp<DeviceDescriptor> devDesc = |
| 2043 | mAvailableOutputDevices.getDeviceFromId(patch->sinks[i].id); |
| 2044 | if (devDesc == 0) { |
| 2045 | ALOGV("createAudioPatch() out device not found for id %d", patch->sinks[i].id); |
| 2046 | return BAD_VALUE; |
| 2047 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2048 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2049 | if (!outputDesc->mProfile->isCompatibleProfile(devDesc->type(), |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 2050 | devDesc->mAddress, |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2051 | patch->sources[0].sample_rate, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2052 | NULL, // updatedSamplingRate |
| 2053 | patch->sources[0].format, |
| 2054 | patch->sources[0].channel_mask, |
| 2055 | AUDIO_OUTPUT_FLAG_NONE /*FIXME*/)) { |
| 2056 | ALOGV("createAudioPatch() profile not supported for device %08x", devDesc->type()); |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2057 | return INVALID_OPERATION; |
| 2058 | } |
| 2059 | devices.add(devDesc); |
| 2060 | } |
| 2061 | if (devices.size() == 0) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2062 | return INVALID_OPERATION; |
| 2063 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2064 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2065 | // TODO: reconfigure output format and channels here |
| 2066 | ALOGV("createAudioPatch() setting device %08x on output %d", |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2067 | devices.types(), outputDesc->mIoHandle); |
| 2068 | setOutputDevice(outputDesc->mIoHandle, devices.types(), true, 0, handle); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2069 | index = mAudioPatches.indexOfKey(*handle); |
| 2070 | if (index >= 0) { |
| 2071 | if (patchDesc != 0 && patchDesc != mAudioPatches.valueAt(index)) { |
| 2072 | ALOGW("createAudioPatch() setOutputDevice() did not reuse the patch provided"); |
| 2073 | } |
| 2074 | patchDesc = mAudioPatches.valueAt(index); |
| 2075 | patchDesc->mUid = uid; |
| 2076 | ALOGV("createAudioPatch() success"); |
| 2077 | } else { |
| 2078 | ALOGW("createAudioPatch() setOutputDevice() failed to create a patch"); |
| 2079 | return INVALID_OPERATION; |
| 2080 | } |
| 2081 | } else if (patch->sources[0].type == AUDIO_PORT_TYPE_DEVICE) { |
| 2082 | if (patch->sinks[0].type == AUDIO_PORT_TYPE_MIX) { |
| 2083 | // input device to input mix connection |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2084 | // only one sink supported when connecting an input device to a mix |
| 2085 | if (patch->num_sinks > 1) { |
| 2086 | return INVALID_OPERATION; |
| 2087 | } |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2088 | sp<AudioInputDescriptor> inputDesc = mInputs.getInputFromId(patch->sinks[0].id); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2089 | if (inputDesc == NULL) { |
| 2090 | return BAD_VALUE; |
| 2091 | } |
| 2092 | if (patchDesc != 0) { |
| 2093 | if (patchDesc->mPatch.sinks[0].id != patch->sinks[0].id) { |
| 2094 | return BAD_VALUE; |
| 2095 | } |
| 2096 | } |
| 2097 | sp<DeviceDescriptor> devDesc = |
| 2098 | mAvailableInputDevices.getDeviceFromId(patch->sources[0].id); |
| 2099 | if (devDesc == 0) { |
| 2100 | return BAD_VALUE; |
| 2101 | } |
| 2102 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2103 | if (!inputDesc->mProfile->isCompatibleProfile(devDesc->type(), |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 2104 | devDesc->mAddress, |
| 2105 | patch->sinks[0].sample_rate, |
| 2106 | NULL, /*updatedSampleRate*/ |
| 2107 | patch->sinks[0].format, |
| 2108 | patch->sinks[0].channel_mask, |
| 2109 | // FIXME for the parameter type, |
| 2110 | // and the NONE |
| 2111 | (audio_output_flags_t) |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 2112 | AUDIO_INPUT_FLAG_NONE)) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2113 | return INVALID_OPERATION; |
| 2114 | } |
| 2115 | // TODO: reconfigure output format and channels here |
| 2116 | ALOGV("createAudioPatch() setting device %08x on output %d", |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2117 | devDesc->type(), inputDesc->mIoHandle); |
| 2118 | setInputDevice(inputDesc->mIoHandle, devDesc->type(), true, handle); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2119 | index = mAudioPatches.indexOfKey(*handle); |
| 2120 | if (index >= 0) { |
| 2121 | if (patchDesc != 0 && patchDesc != mAudioPatches.valueAt(index)) { |
| 2122 | ALOGW("createAudioPatch() setInputDevice() did not reuse the patch provided"); |
| 2123 | } |
| 2124 | patchDesc = mAudioPatches.valueAt(index); |
| 2125 | patchDesc->mUid = uid; |
| 2126 | ALOGV("createAudioPatch() success"); |
| 2127 | } else { |
| 2128 | ALOGW("createAudioPatch() setInputDevice() failed to create a patch"); |
| 2129 | return INVALID_OPERATION; |
| 2130 | } |
| 2131 | } else if (patch->sinks[0].type == AUDIO_PORT_TYPE_DEVICE) { |
| 2132 | // device to device connection |
| 2133 | if (patchDesc != 0) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2134 | if (patchDesc->mPatch.sources[0].id != patch->sources[0].id) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2135 | return BAD_VALUE; |
| 2136 | } |
| 2137 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2138 | sp<DeviceDescriptor> srcDeviceDesc = |
| 2139 | mAvailableInputDevices.getDeviceFromId(patch->sources[0].id); |
Eric Laurent | 58f8eb7 | 2014-09-12 16:19:41 -0700 | [diff] [blame] | 2140 | if (srcDeviceDesc == 0) { |
| 2141 | return BAD_VALUE; |
| 2142 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2143 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2144 | //update source and sink with our own data as the data passed in the patch may |
| 2145 | // be incomplete. |
| 2146 | struct audio_patch newPatch = *patch; |
| 2147 | srcDeviceDesc->toAudioPortConfig(&newPatch.sources[0], &patch->sources[0]); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2148 | |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2149 | for (size_t i = 0; i < patch->num_sinks; i++) { |
| 2150 | if (patch->sinks[i].type != AUDIO_PORT_TYPE_DEVICE) { |
| 2151 | ALOGV("createAudioPatch() source device but one sink is not a device"); |
| 2152 | return INVALID_OPERATION; |
| 2153 | } |
| 2154 | |
| 2155 | sp<DeviceDescriptor> sinkDeviceDesc = |
| 2156 | mAvailableOutputDevices.getDeviceFromId(patch->sinks[i].id); |
| 2157 | if (sinkDeviceDesc == 0) { |
| 2158 | return BAD_VALUE; |
| 2159 | } |
| 2160 | sinkDeviceDesc->toAudioPortConfig(&newPatch.sinks[i], &patch->sinks[i]); |
| 2161 | |
| 2162 | if (srcDeviceDesc->mModule != sinkDeviceDesc->mModule) { |
| 2163 | // only one sink supported when connected devices across HW modules |
| 2164 | if (patch->num_sinks > 1) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2165 | return INVALID_OPERATION; |
| 2166 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2167 | SortedVector<audio_io_handle_t> outputs = |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2168 | getOutputsForDevice(sinkDeviceDesc->type(), mOutputs); |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2169 | // if the sink device is reachable via an opened output stream, request to go via |
| 2170 | // this output stream by adding a second source to the patch description |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 2171 | audio_io_handle_t output = selectOutput(outputs, |
| 2172 | AUDIO_OUTPUT_FLAG_NONE, |
| 2173 | AUDIO_FORMAT_INVALID); |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 2174 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 2175 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
| 2176 | if (outputDesc->isDuplicated()) { |
| 2177 | return INVALID_OPERATION; |
| 2178 | } |
| 2179 | outputDesc->toAudioPortConfig(&newPatch.sources[1], &patch->sources[0]); |
| 2180 | newPatch.num_sources = 2; |
| 2181 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2182 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2183 | } |
| 2184 | // TODO: check from routing capabilities in config file and other conflicting patches |
| 2185 | |
| 2186 | audio_patch_handle_t afPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 2187 | if (index >= 0) { |
| 2188 | afPatchHandle = patchDesc->mAfPatchHandle; |
| 2189 | } |
| 2190 | |
| 2191 | status_t status = mpClientInterface->createAudioPatch(&newPatch, |
| 2192 | &afPatchHandle, |
| 2193 | 0); |
| 2194 | ALOGV("createAudioPatch() patch panel returned %d patchHandle %d", |
| 2195 | status, afPatchHandle); |
| 2196 | if (status == NO_ERROR) { |
| 2197 | if (index < 0) { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 2198 | patchDesc = new AudioPatch(&newPatch, uid); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2199 | addAudioPatch(patchDesc->mHandle, patchDesc); |
| 2200 | } else { |
| 2201 | patchDesc->mPatch = newPatch; |
| 2202 | } |
| 2203 | patchDesc->mAfPatchHandle = afPatchHandle; |
| 2204 | *handle = patchDesc->mHandle; |
| 2205 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2206 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2207 | } else { |
| 2208 | ALOGW("createAudioPatch() patch panel could not connect device patch, error %d", |
| 2209 | status); |
| 2210 | return INVALID_OPERATION; |
| 2211 | } |
| 2212 | } else { |
| 2213 | return BAD_VALUE; |
| 2214 | } |
| 2215 | } else { |
| 2216 | return BAD_VALUE; |
| 2217 | } |
| 2218 | return NO_ERROR; |
| 2219 | } |
| 2220 | |
| 2221 | status_t AudioPolicyManager::releaseAudioPatch(audio_patch_handle_t handle, |
| 2222 | uid_t uid) |
| 2223 | { |
| 2224 | ALOGV("releaseAudioPatch() patch %d", handle); |
| 2225 | |
| 2226 | ssize_t index = mAudioPatches.indexOfKey(handle); |
| 2227 | |
| 2228 | if (index < 0) { |
| 2229 | return BAD_VALUE; |
| 2230 | } |
| 2231 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 2232 | ALOGV("releaseAudioPatch() mUidCached %d patchDesc->mUid %d uid %d", |
| 2233 | mUidCached, patchDesc->mUid, uid); |
| 2234 | if (patchDesc->mUid != mUidCached && uid != patchDesc->mUid) { |
| 2235 | return INVALID_OPERATION; |
| 2236 | } |
| 2237 | |
| 2238 | struct audio_patch *patch = &patchDesc->mPatch; |
| 2239 | patchDesc->mUid = mUidCached; |
| 2240 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2241 | sp<AudioOutputDescriptor> outputDesc = mOutputs.getOutputFromId(patch->sources[0].id); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2242 | if (outputDesc == NULL) { |
| 2243 | ALOGV("releaseAudioPatch() output not found for id %d", patch->sources[0].id); |
| 2244 | return BAD_VALUE; |
| 2245 | } |
| 2246 | |
| 2247 | setOutputDevice(outputDesc->mIoHandle, |
| 2248 | getNewOutputDevice(outputDesc->mIoHandle, true /*fromCache*/), |
| 2249 | true, |
| 2250 | 0, |
| 2251 | NULL); |
| 2252 | } else if (patch->sources[0].type == AUDIO_PORT_TYPE_DEVICE) { |
| 2253 | if (patch->sinks[0].type == AUDIO_PORT_TYPE_MIX) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2254 | sp<AudioInputDescriptor> inputDesc = mInputs.getInputFromId(patch->sinks[0].id); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2255 | if (inputDesc == NULL) { |
| 2256 | ALOGV("releaseAudioPatch() input not found for id %d", patch->sinks[0].id); |
| 2257 | return BAD_VALUE; |
| 2258 | } |
| 2259 | setInputDevice(inputDesc->mIoHandle, |
| 2260 | getNewInputDevice(inputDesc->mIoHandle), |
| 2261 | true, |
| 2262 | NULL); |
| 2263 | } else if (patch->sinks[0].type == AUDIO_PORT_TYPE_DEVICE) { |
| 2264 | audio_patch_handle_t afPatchHandle = patchDesc->mAfPatchHandle; |
| 2265 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
| 2266 | ALOGV("releaseAudioPatch() patch panel returned %d patchHandle %d", |
| 2267 | status, patchDesc->mAfPatchHandle); |
| 2268 | removeAudioPatch(patchDesc->mHandle); |
| 2269 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2270 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2271 | } else { |
| 2272 | return BAD_VALUE; |
| 2273 | } |
| 2274 | } else { |
| 2275 | return BAD_VALUE; |
| 2276 | } |
| 2277 | return NO_ERROR; |
| 2278 | } |
| 2279 | |
| 2280 | status_t AudioPolicyManager::listAudioPatches(unsigned int *num_patches, |
| 2281 | struct audio_patch *patches, |
| 2282 | unsigned int *generation) |
| 2283 | { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2284 | if (generation == NULL) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2285 | return BAD_VALUE; |
| 2286 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2287 | *generation = curAudioPortGeneration(); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2288 | return mAudioPatches.listAudioPatches(num_patches, patches); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2291 | status_t AudioPolicyManager::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2292 | { |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2293 | ALOGV("setAudioPortConfig()"); |
| 2294 | |
| 2295 | if (config == NULL) { |
| 2296 | return BAD_VALUE; |
| 2297 | } |
| 2298 | ALOGV("setAudioPortConfig() on port handle %d", config->id); |
| 2299 | // Only support gain configuration for now |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2300 | if (config->config_mask != AUDIO_PORT_CONFIG_GAIN) { |
| 2301 | return INVALID_OPERATION; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2304 | sp<AudioPortConfig> audioPortConfig; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2305 | if (config->type == AUDIO_PORT_TYPE_MIX) { |
| 2306 | if (config->role == AUDIO_PORT_ROLE_SOURCE) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2307 | sp<AudioOutputDescriptor> outputDesc = mOutputs.getOutputFromId(config->id); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2308 | if (outputDesc == NULL) { |
| 2309 | return BAD_VALUE; |
| 2310 | } |
Eric Laurent | 84c7024 | 2014-06-23 08:46:27 -0700 | [diff] [blame] | 2311 | ALOG_ASSERT(!outputDesc->isDuplicated(), |
| 2312 | "setAudioPortConfig() called on duplicated output %d", |
| 2313 | outputDesc->mIoHandle); |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2314 | audioPortConfig = outputDesc; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2315 | } else if (config->role == AUDIO_PORT_ROLE_SINK) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2316 | sp<AudioInputDescriptor> inputDesc = mInputs.getInputFromId(config->id); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2317 | if (inputDesc == NULL) { |
| 2318 | return BAD_VALUE; |
| 2319 | } |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2320 | audioPortConfig = inputDesc; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2321 | } else { |
| 2322 | return BAD_VALUE; |
| 2323 | } |
| 2324 | } else if (config->type == AUDIO_PORT_TYPE_DEVICE) { |
| 2325 | sp<DeviceDescriptor> deviceDesc; |
| 2326 | if (config->role == AUDIO_PORT_ROLE_SOURCE) { |
| 2327 | deviceDesc = mAvailableInputDevices.getDeviceFromId(config->id); |
| 2328 | } else if (config->role == AUDIO_PORT_ROLE_SINK) { |
| 2329 | deviceDesc = mAvailableOutputDevices.getDeviceFromId(config->id); |
| 2330 | } else { |
| 2331 | return BAD_VALUE; |
| 2332 | } |
| 2333 | if (deviceDesc == NULL) { |
| 2334 | return BAD_VALUE; |
| 2335 | } |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2336 | audioPortConfig = deviceDesc; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2337 | } else { |
| 2338 | return BAD_VALUE; |
| 2339 | } |
| 2340 | |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2341 | struct audio_port_config backupConfig; |
| 2342 | status_t status = audioPortConfig->applyAudioPortConfig(config, &backupConfig); |
| 2343 | if (status == NO_ERROR) { |
| 2344 | struct audio_port_config newConfig; |
| 2345 | audioPortConfig->toAudioPortConfig(&newConfig, config); |
| 2346 | status = mpClientInterface->setAudioPortConfig(&newConfig, 0); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2347 | } |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 2348 | if (status != NO_ERROR) { |
| 2349 | audioPortConfig->applyAudioPortConfig(&backupConfig); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2350 | } |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2351 | |
| 2352 | return status; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | void AudioPolicyManager::clearAudioPatches(uid_t uid) |
| 2356 | { |
Eric Laurent | 0add0fd | 2014-12-04 18:58:14 -0800 | [diff] [blame] | 2357 | for (ssize_t i = (ssize_t)mAudioPatches.size() - 1; i >= 0; i--) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2358 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(i); |
| 2359 | if (patchDesc->mUid == uid) { |
Eric Laurent | 0add0fd | 2014-12-04 18:58:14 -0800 | [diff] [blame] | 2360 | releaseAudioPatch(mAudioPatches.keyAt(i), uid); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2365 | status_t AudioPolicyManager::acquireSoundTriggerSession(audio_session_t *session, |
| 2366 | audio_io_handle_t *ioHandle, |
| 2367 | audio_devices_t *device) |
| 2368 | { |
| 2369 | *session = (audio_session_t)mpClientInterface->newAudioUniqueId(); |
| 2370 | *ioHandle = (audio_io_handle_t)mpClientInterface->newAudioUniqueId(); |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 2371 | *device = getDeviceAndMixForInputSource(AUDIO_SOURCE_HOTWORD); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2372 | |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 2373 | return mSoundTriggerSessions.acquireSession(*session, *ioHandle); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2376 | // ---------------------------------------------------------------------------- |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2377 | // AudioPolicyManager |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2378 | // ---------------------------------------------------------------------------- |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2379 | uint32_t AudioPolicyManager::nextAudioPortGeneration() |
| 2380 | { |
| 2381 | return android_atomic_inc(&mAudioPortGeneration); |
| 2382 | } |
| 2383 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2384 | AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterface) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2385 | : |
| 2386 | #ifdef AUDIO_POLICY_TEST |
| 2387 | Thread(false), |
| 2388 | #endif //AUDIO_POLICY_TEST |
| 2389 | mPrimaryOutput((audio_io_handle_t)0), |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2390 | mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f), |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2391 | mA2dpSuspended(false), |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2392 | mSpeakerDrcEnabled(false), |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 2393 | mAudioPortGeneration(1), |
| 2394 | mBeaconMuteRefCount(0), |
| 2395 | mBeaconPlayingRefCount(0), |
| 2396 | mBeaconMuted(false) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2397 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 2398 | audio_policy::EngineInstance *engineInstance = audio_policy::EngineInstance::getInstance(); |
| 2399 | if (!engineInstance) { |
| 2400 | ALOGE("%s: Could not get an instance of policy engine", __FUNCTION__); |
| 2401 | return; |
| 2402 | } |
| 2403 | // Retrieve the Policy Manager Interface |
| 2404 | mEngine = engineInstance->queryInterface<AudioPolicyManagerInterface>(); |
| 2405 | if (mEngine == NULL) { |
| 2406 | ALOGE("%s: Failed to get Policy Engine Interface", __FUNCTION__); |
| 2407 | return; |
| 2408 | } |
| 2409 | mEngine->setObserver(this); |
| 2410 | status_t status = mEngine->initCheck(); |
| 2411 | ALOG_ASSERT(status == NO_ERROR, "Policy engine not initialized(err=%d)", status); |
| 2412 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2413 | mUidCached = getuid(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2414 | mpClientInterface = clientInterface; |
| 2415 | |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2416 | mDefaultOutputDevice = new DeviceDescriptor(String8("Speaker"), AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2417 | if (ConfigParsingUtils::loadAudioPolicyConfig(AUDIO_POLICY_VENDOR_CONFIG_FILE, |
| 2418 | mHwModules, mAvailableInputDevices, mAvailableOutputDevices, |
| 2419 | mDefaultOutputDevice, mSpeakerDrcEnabled) != NO_ERROR) { |
| 2420 | if (ConfigParsingUtils::loadAudioPolicyConfig(AUDIO_POLICY_CONFIG_FILE, |
| 2421 | mHwModules, mAvailableInputDevices, mAvailableOutputDevices, |
| 2422 | mDefaultOutputDevice, mSpeakerDrcEnabled) != NO_ERROR) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2423 | ALOGE("could not load audio policy configuration file, setting defaults"); |
| 2424 | defaultAudioPolicyConfig(); |
| 2425 | } |
| 2426 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2427 | // mAvailableOutputDevices and mAvailableInputDevices now contain all attached devices |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2428 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 2429 | // must be done after reading the policy (since conditionned by Speaker Drc Enabling) |
| 2430 | mEngine->initializeVolumeCurves(mSpeakerDrcEnabled); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2431 | |
| 2432 | // open all output streams needed to access attached devices |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2433 | audio_devices_t outputDeviceTypes = mAvailableOutputDevices.types(); |
| 2434 | audio_devices_t inputDeviceTypes = mAvailableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2435 | for (size_t i = 0; i < mHwModules.size(); i++) { |
| 2436 | mHwModules[i]->mHandle = mpClientInterface->loadHwModule(mHwModules[i]->mName); |
| 2437 | if (mHwModules[i]->mHandle == 0) { |
| 2438 | ALOGW("could not open HW module %s", mHwModules[i]->mName); |
| 2439 | continue; |
| 2440 | } |
| 2441 | // open all output streams needed to access attached devices |
| 2442 | // except for direct output streams that are only opened when they are actually |
| 2443 | // required by an app. |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2444 | // This also validates mAvailableOutputDevices list |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2445 | for (size_t j = 0; j < mHwModules[i]->mOutputProfiles.size(); j++) |
| 2446 | { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2447 | const sp<IOProfile> outProfile = mHwModules[i]->mOutputProfiles[j]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2448 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2449 | if (outProfile->mSupportedDevices.isEmpty()) { |
| 2450 | ALOGW("Output profile contains no device on module %s", mHwModules[i]->mName); |
| 2451 | continue; |
| 2452 | } |
| 2453 | |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2454 | if ((outProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) { |
| 2455 | continue; |
| 2456 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2457 | audio_devices_t profileType = outProfile->mSupportedDevices.types(); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2458 | if ((profileType & mDefaultOutputDevice->type()) != AUDIO_DEVICE_NONE) { |
| 2459 | profileType = mDefaultOutputDevice->type(); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2460 | } else { |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2461 | // chose first device present in mSupportedDevices also part of |
| 2462 | // outputDeviceTypes |
| 2463 | for (size_t k = 0; k < outProfile->mSupportedDevices.size(); k++) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2464 | profileType = outProfile->mSupportedDevices[k]->type(); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2465 | if ((profileType & outputDeviceTypes) != 0) { |
| 2466 | break; |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2467 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2468 | } |
| 2469 | } |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2470 | if ((profileType & outputDeviceTypes) == 0) { |
| 2471 | continue; |
| 2472 | } |
| 2473 | sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(outProfile); |
| 2474 | |
| 2475 | outputDesc->mDevice = profileType; |
| 2476 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 2477 | config.sample_rate = outputDesc->mSamplingRate; |
| 2478 | config.channel_mask = outputDesc->mChannelMask; |
| 2479 | config.format = outputDesc->mFormat; |
| 2480 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
| 2481 | status_t status = mpClientInterface->openOutput(outProfile->mModule->mHandle, |
| 2482 | &output, |
| 2483 | &config, |
| 2484 | &outputDesc->mDevice, |
| 2485 | String8(""), |
| 2486 | &outputDesc->mLatency, |
| 2487 | outputDesc->mFlags); |
| 2488 | |
| 2489 | if (status != NO_ERROR) { |
| 2490 | ALOGW("Cannot open output stream for device %08x on hw module %s", |
| 2491 | outputDesc->mDevice, |
| 2492 | mHwModules[i]->mName); |
| 2493 | } else { |
| 2494 | outputDesc->mSamplingRate = config.sample_rate; |
| 2495 | outputDesc->mChannelMask = config.channel_mask; |
| 2496 | outputDesc->mFormat = config.format; |
| 2497 | |
| 2498 | for (size_t k = 0; k < outProfile->mSupportedDevices.size(); k++) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2499 | audio_devices_t type = outProfile->mSupportedDevices[k]->type(); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2500 | ssize_t index = |
| 2501 | mAvailableOutputDevices.indexOf(outProfile->mSupportedDevices[k]); |
| 2502 | // give a valid ID to an attached device once confirmed it is reachable |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2503 | if (index >= 0 && !mAvailableOutputDevices[index]->isAttached()) { |
| 2504 | mAvailableOutputDevices[index]->attach(mHwModules[i]); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | if (mPrimaryOutput == 0 && |
| 2508 | outProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 2509 | mPrimaryOutput = output; |
| 2510 | } |
| 2511 | addOutput(output, outputDesc); |
| 2512 | setOutputDevice(output, |
| 2513 | outputDesc->mDevice, |
| 2514 | true); |
| 2515 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2516 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2517 | // open input streams needed to access attached devices to validate |
| 2518 | // mAvailableInputDevices list |
| 2519 | for (size_t j = 0; j < mHwModules[i]->mInputProfiles.size(); j++) |
| 2520 | { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2521 | const sp<IOProfile> inProfile = mHwModules[i]->mInputProfiles[j]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2522 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2523 | if (inProfile->mSupportedDevices.isEmpty()) { |
| 2524 | ALOGW("Input profile contains no device on module %s", mHwModules[i]->mName); |
| 2525 | continue; |
| 2526 | } |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2527 | // chose first device present in mSupportedDevices also part of |
| 2528 | // inputDeviceTypes |
| 2529 | audio_devices_t profileType = AUDIO_DEVICE_NONE; |
| 2530 | for (size_t k = 0; k < inProfile->mSupportedDevices.size(); k++) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2531 | profileType = inProfile->mSupportedDevices[k]->type(); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2532 | if (profileType & inputDeviceTypes) { |
| 2533 | break; |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2534 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2535 | } |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2536 | if ((profileType & inputDeviceTypes) == 0) { |
| 2537 | continue; |
| 2538 | } |
| 2539 | sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(inProfile); |
| 2540 | |
| 2541 | inputDesc->mInputSource = AUDIO_SOURCE_MIC; |
| 2542 | inputDesc->mDevice = profileType; |
| 2543 | |
Jean-Michel Trivi | fd4c148 | 2014-08-06 16:02:28 -0700 | [diff] [blame] | 2544 | // find the address |
| 2545 | DeviceVector inputDevices = mAvailableInputDevices.getDevicesFromType(profileType); |
| 2546 | // the inputs vector must be of size 1, but we don't want to crash here |
| 2547 | String8 address = inputDevices.size() > 0 ? inputDevices.itemAt(0)->mAddress |
| 2548 | : String8(""); |
| 2549 | ALOGV(" for input device 0x%x using address %s", profileType, address.string()); |
| 2550 | ALOGE_IF(inputDevices.size() == 0, "Input device list is empty!"); |
| 2551 | |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2552 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 2553 | config.sample_rate = inputDesc->mSamplingRate; |
| 2554 | config.channel_mask = inputDesc->mChannelMask; |
| 2555 | config.format = inputDesc->mFormat; |
| 2556 | audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; |
| 2557 | status_t status = mpClientInterface->openInput(inProfile->mModule->mHandle, |
| 2558 | &input, |
| 2559 | &config, |
| 2560 | &inputDesc->mDevice, |
Jean-Michel Trivi | fd4c148 | 2014-08-06 16:02:28 -0700 | [diff] [blame] | 2561 | address, |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2562 | AUDIO_SOURCE_MIC, |
| 2563 | AUDIO_INPUT_FLAG_NONE); |
| 2564 | |
| 2565 | if (status == NO_ERROR) { |
| 2566 | for (size_t k = 0; k < inProfile->mSupportedDevices.size(); k++) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2567 | audio_devices_t type = inProfile->mSupportedDevices[k]->type(); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2568 | ssize_t index = |
| 2569 | mAvailableInputDevices.indexOf(inProfile->mSupportedDevices[k]); |
| 2570 | // give a valid ID to an attached device once confirmed it is reachable |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2571 | if (index >= 0 && !mAvailableInputDevices[index]->isAttached()) { |
| 2572 | mAvailableInputDevices[index]->attach(mHwModules[i]); |
Eric Laurent | d78f153 | 2014-09-16 16:38:20 -0700 | [diff] [blame] | 2573 | } |
| 2574 | } |
| 2575 | mpClientInterface->closeInput(input); |
| 2576 | } else { |
| 2577 | ALOGW("Cannot open input stream for device %08x on hw module %s", |
| 2578 | inputDesc->mDevice, |
| 2579 | mHwModules[i]->mName); |
| 2580 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | // make sure all attached devices have been allocated a unique ID |
| 2584 | for (size_t i = 0; i < mAvailableOutputDevices.size();) { |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2585 | if (!mAvailableOutputDevices[i]->isAttached()) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2586 | ALOGW("Input device %08x unreachable", mAvailableOutputDevices[i]->type()); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2587 | mAvailableOutputDevices.remove(mAvailableOutputDevices[i]); |
| 2588 | continue; |
| 2589 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 2590 | // The device is now validated and can be appended to the available devices of the engine |
| 2591 | mEngine->setDeviceConnectionState(mAvailableOutputDevices[i], |
| 2592 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2593 | i++; |
| 2594 | } |
| 2595 | for (size_t i = 0; i < mAvailableInputDevices.size();) { |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 2596 | if (!mAvailableInputDevices[i]->isAttached()) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2597 | ALOGW("Input device %08x unreachable", mAvailableInputDevices[i]->type()); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2598 | mAvailableInputDevices.remove(mAvailableInputDevices[i]); |
| 2599 | continue; |
| 2600 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 2601 | // The device is now validated and can be appended to the available devices of the engine |
| 2602 | mEngine->setDeviceConnectionState(mAvailableInputDevices[i], |
| 2603 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2604 | i++; |
| 2605 | } |
| 2606 | // make sure default device is reachable |
| 2607 | if (mAvailableOutputDevices.indexOf(mDefaultOutputDevice) < 0) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2608 | ALOGE("Default device %08x is unreachable", mDefaultOutputDevice->type()); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2609 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2610 | |
| 2611 | ALOGE_IF((mPrimaryOutput == 0), "Failed to open primary output"); |
| 2612 | |
| 2613 | updateDevicesAndOutputs(); |
| 2614 | |
| 2615 | #ifdef AUDIO_POLICY_TEST |
| 2616 | if (mPrimaryOutput != 0) { |
| 2617 | AudioParameter outputCmd = AudioParameter(); |
| 2618 | outputCmd.addInt(String8("set_id"), 0); |
| 2619 | mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString()); |
| 2620 | |
| 2621 | mTestDevice = AUDIO_DEVICE_OUT_SPEAKER; |
| 2622 | mTestSamplingRate = 44100; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2623 | mTestFormat = AUDIO_FORMAT_PCM_16_BIT; |
| 2624 | mTestChannels = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2625 | mTestLatencyMs = 0; |
| 2626 | mCurOutput = 0; |
| 2627 | mDirectOutput = false; |
| 2628 | for (int i = 0; i < NUM_TEST_OUTPUTS; i++) { |
| 2629 | mTestOutputs[i] = 0; |
| 2630 | } |
| 2631 | |
| 2632 | const size_t SIZE = 256; |
| 2633 | char buffer[SIZE]; |
| 2634 | snprintf(buffer, SIZE, "AudioPolicyManagerTest"); |
| 2635 | run(buffer, ANDROID_PRIORITY_AUDIO); |
| 2636 | } |
| 2637 | #endif //AUDIO_POLICY_TEST |
| 2638 | } |
| 2639 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2640 | AudioPolicyManager::~AudioPolicyManager() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2641 | { |
| 2642 | #ifdef AUDIO_POLICY_TEST |
| 2643 | exit(); |
| 2644 | #endif //AUDIO_POLICY_TEST |
| 2645 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 2646 | mpClientInterface->closeOutput(mOutputs.keyAt(i)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2647 | } |
| 2648 | for (size_t i = 0; i < mInputs.size(); i++) { |
| 2649 | mpClientInterface->closeInput(mInputs.keyAt(i)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2650 | } |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2651 | mAvailableOutputDevices.clear(); |
| 2652 | mAvailableInputDevices.clear(); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2653 | mOutputs.clear(); |
| 2654 | mInputs.clear(); |
| 2655 | mHwModules.clear(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2658 | status_t AudioPolicyManager::initCheck() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2659 | { |
| 2660 | return (mPrimaryOutput == 0) ? NO_INIT : NO_ERROR; |
| 2661 | } |
| 2662 | |
| 2663 | #ifdef AUDIO_POLICY_TEST |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2664 | bool AudioPolicyManager::threadLoop() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2665 | { |
| 2666 | ALOGV("entering threadLoop()"); |
| 2667 | while (!exitPending()) |
| 2668 | { |
| 2669 | String8 command; |
| 2670 | int valueInt; |
| 2671 | String8 value; |
| 2672 | |
| 2673 | Mutex::Autolock _l(mLock); |
| 2674 | mWaitWorkCV.waitRelative(mLock, milliseconds(50)); |
| 2675 | |
| 2676 | command = mpClientInterface->getParameters(0, String8("test_cmd_policy")); |
| 2677 | AudioParameter param = AudioParameter(command); |
| 2678 | |
| 2679 | if (param.getInt(String8("test_cmd_policy"), valueInt) == NO_ERROR && |
| 2680 | valueInt != 0) { |
| 2681 | ALOGV("Test command %s received", command.string()); |
| 2682 | String8 target; |
| 2683 | if (param.get(String8("target"), target) != NO_ERROR) { |
| 2684 | target = "Manager"; |
| 2685 | } |
| 2686 | if (param.getInt(String8("test_cmd_policy_output"), valueInt) == NO_ERROR) { |
| 2687 | param.remove(String8("test_cmd_policy_output")); |
| 2688 | mCurOutput = valueInt; |
| 2689 | } |
| 2690 | if (param.get(String8("test_cmd_policy_direct"), value) == NO_ERROR) { |
| 2691 | param.remove(String8("test_cmd_policy_direct")); |
| 2692 | if (value == "false") { |
| 2693 | mDirectOutput = false; |
| 2694 | } else if (value == "true") { |
| 2695 | mDirectOutput = true; |
| 2696 | } |
| 2697 | } |
| 2698 | if (param.getInt(String8("test_cmd_policy_input"), valueInt) == NO_ERROR) { |
| 2699 | param.remove(String8("test_cmd_policy_input")); |
| 2700 | mTestInput = valueInt; |
| 2701 | } |
| 2702 | |
| 2703 | if (param.get(String8("test_cmd_policy_format"), value) == NO_ERROR) { |
| 2704 | param.remove(String8("test_cmd_policy_format")); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2705 | int format = AUDIO_FORMAT_INVALID; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2706 | if (value == "PCM 16 bits") { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2707 | format = AUDIO_FORMAT_PCM_16_BIT; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2708 | } else if (value == "PCM 8 bits") { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2709 | format = AUDIO_FORMAT_PCM_8_BIT; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2710 | } else if (value == "Compressed MP3") { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2711 | format = AUDIO_FORMAT_MP3; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2712 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2713 | if (format != AUDIO_FORMAT_INVALID) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2714 | if (target == "Manager") { |
| 2715 | mTestFormat = format; |
| 2716 | } else if (mTestOutputs[mCurOutput] != 0) { |
| 2717 | AudioParameter outputParam = AudioParameter(); |
| 2718 | outputParam.addInt(String8("format"), format); |
| 2719 | mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString()); |
| 2720 | } |
| 2721 | } |
| 2722 | } |
| 2723 | if (param.get(String8("test_cmd_policy_channels"), value) == NO_ERROR) { |
| 2724 | param.remove(String8("test_cmd_policy_channels")); |
| 2725 | int channels = 0; |
| 2726 | |
| 2727 | if (value == "Channels Stereo") { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2728 | channels = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2729 | } else if (value == "Channels Mono") { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2730 | channels = AUDIO_CHANNEL_OUT_MONO; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2731 | } |
| 2732 | if (channels != 0) { |
| 2733 | if (target == "Manager") { |
| 2734 | mTestChannels = channels; |
| 2735 | } else if (mTestOutputs[mCurOutput] != 0) { |
| 2736 | AudioParameter outputParam = AudioParameter(); |
| 2737 | outputParam.addInt(String8("channels"), channels); |
| 2738 | mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString()); |
| 2739 | } |
| 2740 | } |
| 2741 | } |
| 2742 | if (param.getInt(String8("test_cmd_policy_sampleRate"), valueInt) == NO_ERROR) { |
| 2743 | param.remove(String8("test_cmd_policy_sampleRate")); |
| 2744 | if (valueInt >= 0 && valueInt <= 96000) { |
| 2745 | int samplingRate = valueInt; |
| 2746 | if (target == "Manager") { |
| 2747 | mTestSamplingRate = samplingRate; |
| 2748 | } else if (mTestOutputs[mCurOutput] != 0) { |
| 2749 | AudioParameter outputParam = AudioParameter(); |
| 2750 | outputParam.addInt(String8("sampling_rate"), samplingRate); |
| 2751 | mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString()); |
| 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | if (param.get(String8("test_cmd_policy_reopen"), value) == NO_ERROR) { |
| 2757 | param.remove(String8("test_cmd_policy_reopen")); |
| 2758 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2759 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(mPrimaryOutput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2760 | mpClientInterface->closeOutput(mPrimaryOutput); |
| 2761 | |
| 2762 | audio_module_handle_t moduleHandle = outputDesc->mModule->mHandle; |
| 2763 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2764 | removeOutput(mPrimaryOutput); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2765 | sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(NULL); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2766 | outputDesc->mDevice = AUDIO_DEVICE_OUT_SPEAKER; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2767 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 2768 | config.sample_rate = outputDesc->mSamplingRate; |
| 2769 | config.channel_mask = outputDesc->mChannelMask; |
| 2770 | config.format = outputDesc->mFormat; |
| 2771 | status_t status = mpClientInterface->openOutput(moduleHandle, |
| 2772 | &mPrimaryOutput, |
| 2773 | &config, |
| 2774 | &outputDesc->mDevice, |
| 2775 | String8(""), |
| 2776 | &outputDesc->mLatency, |
| 2777 | outputDesc->mFlags); |
| 2778 | if (status != NO_ERROR) { |
| 2779 | ALOGE("Failed to reopen hardware output stream, " |
| 2780 | "samplingRate: %d, format %d, channels %d", |
| 2781 | outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannelMask); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2782 | } else { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2783 | outputDesc->mSamplingRate = config.sample_rate; |
| 2784 | outputDesc->mChannelMask = config.channel_mask; |
| 2785 | outputDesc->mFormat = config.format; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2786 | AudioParameter outputCmd = AudioParameter(); |
| 2787 | outputCmd.addInt(String8("set_id"), 0); |
| 2788 | mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString()); |
| 2789 | addOutput(mPrimaryOutput, outputDesc); |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | |
| 2794 | mpClientInterface->setParameters(0, String8("test_cmd_policy=")); |
| 2795 | } |
| 2796 | } |
| 2797 | return false; |
| 2798 | } |
| 2799 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2800 | void AudioPolicyManager::exit() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2801 | { |
| 2802 | { |
| 2803 | AutoMutex _l(mLock); |
| 2804 | requestExit(); |
| 2805 | mWaitWorkCV.signal(); |
| 2806 | } |
| 2807 | requestExitAndWait(); |
| 2808 | } |
| 2809 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 2810 | int AudioPolicyManager::testOutputIndex(audio_io_handle_t output) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2811 | { |
| 2812 | for (int i = 0; i < NUM_TEST_OUTPUTS; i++) { |
| 2813 | if (output == mTestOutputs[i]) return i; |
| 2814 | } |
| 2815 | return 0; |
| 2816 | } |
| 2817 | #endif //AUDIO_POLICY_TEST |
| 2818 | |
| 2819 | // --- |
| 2820 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2821 | void AudioPolicyManager::addOutput(audio_io_handle_t output, sp<AudioOutputDescriptor> outputDesc) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2822 | { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 2823 | outputDesc->setIoHandle(output); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2824 | mOutputs.add(output, outputDesc); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2825 | nextAudioPortGeneration(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2828 | void AudioPolicyManager::removeOutput(audio_io_handle_t output) |
| 2829 | { |
| 2830 | mOutputs.removeItem(output); |
| 2831 | } |
| 2832 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2833 | void AudioPolicyManager::addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc) |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2834 | { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 2835 | inputDesc->setIoHandle(input); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2836 | mInputs.add(input, inputDesc); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 2837 | nextAudioPortGeneration(); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2838 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2839 | |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2840 | void AudioPolicyManager::findIoHandlesByAddress(sp<AudioOutputDescriptor> desc /*in*/, |
keunyoung | 3190e67 | 2014-12-30 13:00:52 -0800 | [diff] [blame] | 2841 | const audio_devices_t device /*in*/, |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2842 | const String8 address /*in*/, |
| 2843 | SortedVector<audio_io_handle_t>& outputs /*out*/) { |
keunyoung | 3190e67 | 2014-12-30 13:00:52 -0800 | [diff] [blame] | 2844 | sp<DeviceDescriptor> devDesc = |
| 2845 | desc->mProfile->mSupportedDevices.getDevice(device, address); |
| 2846 | if (devDesc != 0) { |
| 2847 | ALOGV("findIoHandlesByAddress(): adding opened output %d on same address %s", |
| 2848 | desc->mIoHandle, address.string()); |
| 2849 | outputs.add(desc->mIoHandle); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 2853 | status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor> devDesc, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2854 | audio_policy_dev_state_t state, |
| 2855 | SortedVector<audio_io_handle_t>& outputs, |
| 2856 | const String8 address) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2857 | { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2858 | audio_devices_t device = devDesc->type(); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 2859 | sp<AudioOutputDescriptor> desc; |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 2860 | // erase all current sample rates, formats and channel masks |
| 2861 | devDesc->clearCapabilities(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2862 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 2863 | if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2864 | // first list already open outputs that can be routed to this device |
| 2865 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 2866 | desc = mOutputs.valueAt(i); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2867 | if (!desc->isDuplicated() && (desc->mProfile->mSupportedDevices.types() & device)) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2868 | if (!device_distinguishes_on_address(device)) { |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2869 | ALOGV("checkOutputsForDevice(): adding opened output %d", mOutputs.keyAt(i)); |
| 2870 | outputs.add(mOutputs.keyAt(i)); |
| 2871 | } else { |
| 2872 | ALOGV(" checking address match due to device 0x%x", device); |
keunyoung | 3190e67 | 2014-12-30 13:00:52 -0800 | [diff] [blame] | 2873 | findIoHandlesByAddress(desc, device, address, outputs); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2874 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | // then look for output profiles that can be routed to this device |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2878 | SortedVector< sp<IOProfile> > profiles; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2879 | for (size_t i = 0; i < mHwModules.size(); i++) |
| 2880 | { |
| 2881 | if (mHwModules[i]->mHandle == 0) { |
| 2882 | continue; |
| 2883 | } |
| 2884 | for (size_t j = 0; j < mHwModules[i]->mOutputProfiles.size(); j++) |
| 2885 | { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 2886 | sp<IOProfile> profile = mHwModules[i]->mOutputProfiles[j]; |
| 2887 | if (profile->mSupportedDevices.types() & device) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 2888 | if (!device_distinguishes_on_address(device) || |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 2889 | address == profile->mSupportedDevices[0]->mAddress) { |
| 2890 | profiles.add(profile); |
| 2891 | ALOGV("checkOutputsForDevice(): adding profile %zu from module %zu", j, i); |
| 2892 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2893 | } |
| 2894 | } |
| 2895 | } |
| 2896 | |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2897 | ALOGV(" found %d profiles, %d outputs", profiles.size(), outputs.size()); |
| 2898 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2899 | if (profiles.isEmpty() && outputs.isEmpty()) { |
| 2900 | ALOGW("checkOutputsForDevice(): No output available for device %04x", device); |
| 2901 | return BAD_VALUE; |
| 2902 | } |
| 2903 | |
| 2904 | // open outputs for matching profiles if needed. Direct outputs are also opened to |
| 2905 | // query for dynamic parameters and will be closed later by setDeviceConnectionState() |
| 2906 | for (ssize_t profile_index = 0; profile_index < (ssize_t)profiles.size(); profile_index++) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2907 | sp<IOProfile> profile = profiles[profile_index]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2908 | |
| 2909 | // nothing to do if one output is already opened for this profile |
| 2910 | size_t j; |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2911 | for (j = 0; j < outputs.size(); j++) { |
| 2912 | desc = mOutputs.valueFor(outputs.itemAt(j)); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2913 | if (!desc->isDuplicated() && desc->mProfile == profile) { |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 2914 | // matching profile: save the sample rates, format and channel masks supported |
| 2915 | // by the profile in our device descriptor |
| 2916 | devDesc->importAudioPort(profile); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2917 | break; |
| 2918 | } |
| 2919 | } |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2920 | if (j != outputs.size()) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2921 | continue; |
| 2922 | } |
| 2923 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2924 | ALOGV("opening output for device %08x with params %s profile %p", |
| 2925 | device, address.string(), profile.get()); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2926 | desc = new AudioOutputDescriptor(profile); |
| 2927 | desc->mDevice = device; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2928 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 2929 | config.sample_rate = desc->mSamplingRate; |
| 2930 | config.channel_mask = desc->mChannelMask; |
| 2931 | config.format = desc->mFormat; |
| 2932 | config.offload_info.sample_rate = desc->mSamplingRate; |
| 2933 | config.offload_info.channel_mask = desc->mChannelMask; |
| 2934 | config.offload_info.format = desc->mFormat; |
| 2935 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
| 2936 | status_t status = mpClientInterface->openOutput(profile->mModule->mHandle, |
| 2937 | &output, |
| 2938 | &config, |
| 2939 | &desc->mDevice, |
| 2940 | address, |
| 2941 | &desc->mLatency, |
| 2942 | desc->mFlags); |
| 2943 | if (status == NO_ERROR) { |
| 2944 | desc->mSamplingRate = config.sample_rate; |
| 2945 | desc->mChannelMask = config.channel_mask; |
| 2946 | desc->mFormat = config.format; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2947 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2948 | // Here is where the out_set_parameters() for card & device gets called |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 2949 | if (!address.isEmpty()) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2950 | char *param = audio_device_address_to_parameter(device, address); |
| 2951 | mpClientInterface->setParameters(output, String8(param)); |
| 2952 | free(param); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2955 | // Here is where we step through and resolve any "dynamic" fields |
| 2956 | String8 reply; |
| 2957 | char *value; |
| 2958 | if (profile->mSamplingRates[0] == 0) { |
| 2959 | reply = mpClientInterface->getParameters(output, |
| 2960 | String8(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2961 | ALOGV("checkOutputsForDevice() supported sampling rates %s", |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2962 | reply.string()); |
| 2963 | value = strpbrk((char *)reply.string(), "="); |
| 2964 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2965 | profile->loadSamplingRates(value + 1); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2966 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2967 | } |
| 2968 | if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { |
| 2969 | reply = mpClientInterface->getParameters(output, |
| 2970 | String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS)); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2971 | ALOGV("checkOutputsForDevice() supported formats %s", |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2972 | reply.string()); |
| 2973 | value = strpbrk((char *)reply.string(), "="); |
| 2974 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2975 | profile->loadFormats(value + 1); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2976 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2977 | } |
| 2978 | if (profile->mChannelMasks[0] == 0) { |
| 2979 | reply = mpClientInterface->getParameters(output, |
| 2980 | String8(AUDIO_PARAMETER_STREAM_SUP_CHANNELS)); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2981 | ALOGV("checkOutputsForDevice() supported channel masks %s", |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2982 | reply.string()); |
| 2983 | value = strpbrk((char *)reply.string(), "="); |
| 2984 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2985 | profile->loadOutChannels(value + 1); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 2986 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2987 | } |
| 2988 | if (((profile->mSamplingRates[0] == 0) && |
| 2989 | (profile->mSamplingRates.size() < 2)) || |
| 2990 | ((profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) && |
| 2991 | (profile->mFormats.size() < 2)) || |
| 2992 | ((profile->mChannelMasks[0] == 0) && |
| 2993 | (profile->mChannelMasks.size() < 2))) { |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 2994 | ALOGW("checkOutputsForDevice() missing param"); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2995 | mpClientInterface->closeOutput(output); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2996 | output = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 2997 | } else if (profile->mSamplingRates[0] == 0 || profile->mFormats[0] == 0 || |
| 2998 | profile->mChannelMasks[0] == 0) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 2999 | mpClientInterface->closeOutput(output); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3000 | config.sample_rate = profile->pickSamplingRate(); |
| 3001 | config.channel_mask = profile->pickChannelMask(); |
| 3002 | config.format = profile->pickFormat(); |
| 3003 | config.offload_info.sample_rate = config.sample_rate; |
| 3004 | config.offload_info.channel_mask = config.channel_mask; |
| 3005 | config.offload_info.format = config.format; |
| 3006 | status = mpClientInterface->openOutput(profile->mModule->mHandle, |
| 3007 | &output, |
| 3008 | &config, |
| 3009 | &desc->mDevice, |
| 3010 | address, |
| 3011 | &desc->mLatency, |
| 3012 | desc->mFlags); |
| 3013 | if (status == NO_ERROR) { |
| 3014 | desc->mSamplingRate = config.sample_rate; |
| 3015 | desc->mChannelMask = config.channel_mask; |
| 3016 | desc->mFormat = config.format; |
| 3017 | } else { |
| 3018 | output = AUDIO_IO_HANDLE_NONE; |
| 3019 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3022 | if (output != AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3023 | addOutput(output, desc); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3024 | if (device_distinguishes_on_address(device) && address != "0") { |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 3025 | sp<AudioPolicyMix> policyMix; |
| 3026 | if (mPolicyMixes.getAudioPolicyMix(address, policyMix) != NO_ERROR) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3027 | ALOGE("checkOutputsForDevice() cannot find policy for address %s", |
| 3028 | address.string()); |
| 3029 | } |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 3030 | policyMix->setOutput(desc); |
| 3031 | desc->mPolicyMix = &(policyMix->getMix()); |
| 3032 | |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 3033 | } else if ((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) { |
| 3034 | // no duplicated output for direct outputs and |
| 3035 | // outputs used by dynamic policy mixes |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3036 | audio_io_handle_t duplicatedOutput = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3037 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3038 | // set initial stream volume for device |
| 3039 | applyStreamVolumes(output, device, 0, true); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3040 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3041 | //TODO: configure audio effect output stage here |
| 3042 | |
| 3043 | // open a duplicating output thread for the new output and the primary output |
| 3044 | duplicatedOutput = mpClientInterface->openDuplicateOutput(output, |
| 3045 | mPrimaryOutput); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3046 | if (duplicatedOutput != AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3047 | // add duplicated output descriptor |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3048 | sp<AudioOutputDescriptor> dupOutputDesc = |
| 3049 | new AudioOutputDescriptor(NULL); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3050 | dupOutputDesc->mOutput1 = mOutputs.valueFor(mPrimaryOutput); |
| 3051 | dupOutputDesc->mOutput2 = mOutputs.valueFor(output); |
| 3052 | dupOutputDesc->mSamplingRate = desc->mSamplingRate; |
| 3053 | dupOutputDesc->mFormat = desc->mFormat; |
| 3054 | dupOutputDesc->mChannelMask = desc->mChannelMask; |
| 3055 | dupOutputDesc->mLatency = desc->mLatency; |
| 3056 | addOutput(duplicatedOutput, dupOutputDesc); |
| 3057 | applyStreamVolumes(duplicatedOutput, device, 0, true); |
| 3058 | } else { |
| 3059 | ALOGW("checkOutputsForDevice() could not open dup output for %d and %d", |
| 3060 | mPrimaryOutput, output); |
| 3061 | mpClientInterface->closeOutput(output); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3062 | removeOutput(output); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3063 | nextAudioPortGeneration(); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3064 | output = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3065 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3066 | } |
| 3067 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3068 | } else { |
| 3069 | output = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3070 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3071 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3072 | ALOGW("checkOutputsForDevice() could not open output for device %x", device); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3073 | profiles.removeAt(profile_index); |
| 3074 | profile_index--; |
| 3075 | } else { |
| 3076 | outputs.add(output); |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 3077 | devDesc->importAudioPort(profile); |
| 3078 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3079 | if (device_distinguishes_on_address(device)) { |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3080 | ALOGV("checkOutputsForDevice(): setOutputDevice(dev=0x%x, addr=%s)", |
| 3081 | device, address.string()); |
| 3082 | setOutputDevice(output, device, true/*force*/, 0/*delay*/, |
| 3083 | NULL/*patch handle*/, address.string()); |
| 3084 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3085 | ALOGV("checkOutputsForDevice(): adding output %d", output); |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | if (profiles.isEmpty()) { |
| 3090 | ALOGW("checkOutputsForDevice(): No output available for device %04x", device); |
| 3091 | return BAD_VALUE; |
| 3092 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3093 | } else { // Disconnect |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3094 | // check if one opened output is not needed any more after disconnecting one device |
| 3095 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 3096 | desc = mOutputs.valueAt(i); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3097 | if (!desc->isDuplicated()) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3098 | // exact match on device |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3099 | if (device_distinguishes_on_address(device) && |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3100 | (desc->mProfile->mSupportedDevices.types() == device)) { |
keunyoung | 3190e67 | 2014-12-30 13:00:52 -0800 | [diff] [blame] | 3101 | findIoHandlesByAddress(desc, device, address, outputs); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3102 | } else if (!(desc->mProfile->mSupportedDevices.types() |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3103 | & mAvailableOutputDevices.types())) { |
| 3104 | ALOGV("checkOutputsForDevice(): disconnecting adding output %d", |
| 3105 | mOutputs.keyAt(i)); |
| 3106 | outputs.add(mOutputs.keyAt(i)); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3107 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3108 | } |
| 3109 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3110 | // Clear any profiles associated with the disconnected device. |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3111 | for (size_t i = 0; i < mHwModules.size(); i++) |
| 3112 | { |
| 3113 | if (mHwModules[i]->mHandle == 0) { |
| 3114 | continue; |
| 3115 | } |
| 3116 | for (size_t j = 0; j < mHwModules[i]->mOutputProfiles.size(); j++) |
| 3117 | { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3118 | sp<IOProfile> profile = mHwModules[i]->mOutputProfiles[j]; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3119 | if (profile->mSupportedDevices.types() & device) { |
| 3120 | ALOGV("checkOutputsForDevice(): " |
| 3121 | "clearing direct output profile %zu on module %zu", j, i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3122 | if (profile->mSamplingRates[0] == 0) { |
| 3123 | profile->mSamplingRates.clear(); |
| 3124 | profile->mSamplingRates.add(0); |
| 3125 | } |
| 3126 | if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { |
| 3127 | profile->mFormats.clear(); |
| 3128 | profile->mFormats.add(AUDIO_FORMAT_DEFAULT); |
| 3129 | } |
| 3130 | if (profile->mChannelMasks[0] == 0) { |
| 3131 | profile->mChannelMasks.clear(); |
| 3132 | profile->mChannelMasks.add(0); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | return NO_ERROR; |
| 3139 | } |
| 3140 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3141 | status_t AudioPolicyManager::checkInputsForDevice(audio_devices_t device, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3142 | audio_policy_dev_state_t state, |
| 3143 | SortedVector<audio_io_handle_t>& inputs, |
| 3144 | const String8 address) |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3145 | { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3146 | sp<AudioInputDescriptor> desc; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3147 | if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { |
| 3148 | // first list already open inputs that can be routed to this device |
| 3149 | for (size_t input_index = 0; input_index < mInputs.size(); input_index++) { |
| 3150 | desc = mInputs.valueAt(input_index); |
| 3151 | if (desc->mProfile->mSupportedDevices.types() & (device & ~AUDIO_DEVICE_BIT_IN)) { |
| 3152 | ALOGV("checkInputsForDevice(): adding opened input %d", mInputs.keyAt(input_index)); |
| 3153 | inputs.add(mInputs.keyAt(input_index)); |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | // then look for input profiles that can be routed to this device |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3158 | SortedVector< sp<IOProfile> > profiles; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3159 | for (size_t module_idx = 0; module_idx < mHwModules.size(); module_idx++) |
| 3160 | { |
| 3161 | if (mHwModules[module_idx]->mHandle == 0) { |
| 3162 | continue; |
| 3163 | } |
| 3164 | for (size_t profile_index = 0; |
| 3165 | profile_index < mHwModules[module_idx]->mInputProfiles.size(); |
| 3166 | profile_index++) |
| 3167 | { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3168 | sp<IOProfile> profile = mHwModules[module_idx]->mInputProfiles[profile_index]; |
| 3169 | |
| 3170 | if (profile->mSupportedDevices.types() & (device & ~AUDIO_DEVICE_BIT_IN)) { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3171 | if (!device_distinguishes_on_address(device) || |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3172 | address == profile->mSupportedDevices[0]->mAddress) { |
| 3173 | profiles.add(profile); |
| 3174 | ALOGV("checkInputsForDevice(): adding profile %zu from module %zu", |
| 3175 | profile_index, module_idx); |
| 3176 | } |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | if (profiles.isEmpty() && inputs.isEmpty()) { |
| 3182 | ALOGW("checkInputsForDevice(): No input available for device 0x%X", device); |
| 3183 | return BAD_VALUE; |
| 3184 | } |
| 3185 | |
| 3186 | // open inputs for matching profiles if needed. Direct inputs are also opened to |
| 3187 | // query for dynamic parameters and will be closed later by setDeviceConnectionState() |
| 3188 | for (ssize_t profile_index = 0; profile_index < (ssize_t)profiles.size(); profile_index++) { |
| 3189 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3190 | sp<IOProfile> profile = profiles[profile_index]; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3191 | // nothing to do if one input is already opened for this profile |
| 3192 | size_t input_index; |
| 3193 | for (input_index = 0; input_index < mInputs.size(); input_index++) { |
| 3194 | desc = mInputs.valueAt(input_index); |
| 3195 | if (desc->mProfile == profile) { |
| 3196 | break; |
| 3197 | } |
| 3198 | } |
| 3199 | if (input_index != mInputs.size()) { |
| 3200 | continue; |
| 3201 | } |
| 3202 | |
| 3203 | ALOGV("opening input for device 0x%X with params %s", device, address.string()); |
| 3204 | desc = new AudioInputDescriptor(profile); |
| 3205 | desc->mDevice = device; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3206 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 3207 | config.sample_rate = desc->mSamplingRate; |
| 3208 | config.channel_mask = desc->mChannelMask; |
| 3209 | config.format = desc->mFormat; |
| 3210 | audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; |
| 3211 | status_t status = mpClientInterface->openInput(profile->mModule->mHandle, |
| 3212 | &input, |
| 3213 | &config, |
| 3214 | &desc->mDevice, |
| 3215 | address, |
| 3216 | AUDIO_SOURCE_MIC, |
| 3217 | AUDIO_INPUT_FLAG_NONE /*FIXME*/); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3218 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3219 | if (status == NO_ERROR) { |
| 3220 | desc->mSamplingRate = config.sample_rate; |
| 3221 | desc->mChannelMask = config.channel_mask; |
| 3222 | desc->mFormat = config.format; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3223 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3224 | if (!address.isEmpty()) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3225 | char *param = audio_device_address_to_parameter(device, address); |
| 3226 | mpClientInterface->setParameters(input, String8(param)); |
| 3227 | free(param); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | // Here is where we step through and resolve any "dynamic" fields |
| 3231 | String8 reply; |
| 3232 | char *value; |
| 3233 | if (profile->mSamplingRates[0] == 0) { |
| 3234 | reply = mpClientInterface->getParameters(input, |
| 3235 | String8(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)); |
| 3236 | ALOGV("checkInputsForDevice() direct input sup sampling rates %s", |
| 3237 | reply.string()); |
| 3238 | value = strpbrk((char *)reply.string(), "="); |
| 3239 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3240 | profile->loadSamplingRates(value + 1); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { |
| 3244 | reply = mpClientInterface->getParameters(input, |
| 3245 | String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS)); |
| 3246 | ALOGV("checkInputsForDevice() direct input sup formats %s", reply.string()); |
| 3247 | value = strpbrk((char *)reply.string(), "="); |
| 3248 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3249 | profile->loadFormats(value + 1); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3250 | } |
| 3251 | } |
| 3252 | if (profile->mChannelMasks[0] == 0) { |
| 3253 | reply = mpClientInterface->getParameters(input, |
| 3254 | String8(AUDIO_PARAMETER_STREAM_SUP_CHANNELS)); |
| 3255 | ALOGV("checkInputsForDevice() direct input sup channel masks %s", |
| 3256 | reply.string()); |
| 3257 | value = strpbrk((char *)reply.string(), "="); |
| 3258 | if (value != NULL) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3259 | profile->loadInChannels(value + 1); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3260 | } |
| 3261 | } |
| 3262 | if (((profile->mSamplingRates[0] == 0) && (profile->mSamplingRates.size() < 2)) || |
| 3263 | ((profile->mFormats[0] == 0) && (profile->mFormats.size() < 2)) || |
| 3264 | ((profile->mChannelMasks[0] == 0) && (profile->mChannelMasks.size() < 2))) { |
| 3265 | ALOGW("checkInputsForDevice() direct input missing param"); |
| 3266 | mpClientInterface->closeInput(input); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3267 | input = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | if (input != 0) { |
| 3271 | addInput(input, desc); |
| 3272 | } |
| 3273 | } // endif input != 0 |
| 3274 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 3275 | if (input == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3276 | ALOGW("checkInputsForDevice() could not open input for device 0x%X", device); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3277 | profiles.removeAt(profile_index); |
| 3278 | profile_index--; |
| 3279 | } else { |
| 3280 | inputs.add(input); |
| 3281 | ALOGV("checkInputsForDevice(): adding input %d", input); |
| 3282 | } |
| 3283 | } // end scan profiles |
| 3284 | |
| 3285 | if (profiles.isEmpty()) { |
| 3286 | ALOGW("checkInputsForDevice(): No input available for device 0x%X", device); |
| 3287 | return BAD_VALUE; |
| 3288 | } |
| 3289 | } else { |
| 3290 | // Disconnect |
| 3291 | // check if one opened input is not needed any more after disconnecting one device |
| 3292 | for (size_t input_index = 0; input_index < mInputs.size(); input_index++) { |
| 3293 | desc = mInputs.valueAt(input_index); |
Eric Laurent | ddbc665 | 2014-11-13 15:13:44 -0800 | [diff] [blame] | 3294 | if (!(desc->mProfile->mSupportedDevices.types() & mAvailableInputDevices.types() & |
| 3295 | ~AUDIO_DEVICE_BIT_IN)) { |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3296 | ALOGV("checkInputsForDevice(): disconnecting adding input %d", |
| 3297 | mInputs.keyAt(input_index)); |
| 3298 | inputs.add(mInputs.keyAt(input_index)); |
| 3299 | } |
| 3300 | } |
| 3301 | // Clear any profiles associated with the disconnected device. |
| 3302 | for (size_t module_index = 0; module_index < mHwModules.size(); module_index++) { |
| 3303 | if (mHwModules[module_index]->mHandle == 0) { |
| 3304 | continue; |
| 3305 | } |
| 3306 | for (size_t profile_index = 0; |
| 3307 | profile_index < mHwModules[module_index]->mInputProfiles.size(); |
| 3308 | profile_index++) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3309 | sp<IOProfile> profile = mHwModules[module_index]->mInputProfiles[profile_index]; |
Eric Laurent | ddbc665 | 2014-11-13 15:13:44 -0800 | [diff] [blame] | 3310 | if (profile->mSupportedDevices.types() & device & ~AUDIO_DEVICE_BIT_IN) { |
Mark Salyzyn | beb9e30 | 2014-06-18 16:33:15 -0700 | [diff] [blame] | 3311 | ALOGV("checkInputsForDevice(): clearing direct input profile %zu on module %zu", |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 3312 | profile_index, module_index); |
| 3313 | if (profile->mSamplingRates[0] == 0) { |
| 3314 | profile->mSamplingRates.clear(); |
| 3315 | profile->mSamplingRates.add(0); |
| 3316 | } |
| 3317 | if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { |
| 3318 | profile->mFormats.clear(); |
| 3319 | profile->mFormats.add(AUDIO_FORMAT_DEFAULT); |
| 3320 | } |
| 3321 | if (profile->mChannelMasks[0] == 0) { |
| 3322 | profile->mChannelMasks.clear(); |
| 3323 | profile->mChannelMasks.add(0); |
| 3324 | } |
| 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | } // end disconnect |
| 3329 | |
| 3330 | return NO_ERROR; |
| 3331 | } |
| 3332 | |
| 3333 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3334 | void AudioPolicyManager::closeOutput(audio_io_handle_t output) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3335 | { |
| 3336 | ALOGV("closeOutput(%d)", output); |
| 3337 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3338 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3339 | if (outputDesc == NULL) { |
| 3340 | ALOGW("closeOutput() unknown output %d", output); |
| 3341 | return; |
| 3342 | } |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 3343 | mPolicyMixes.closeOutput(outputDesc); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 3344 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3345 | // look for duplicated outputs connected to the output being removed. |
| 3346 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3347 | sp<AudioOutputDescriptor> dupOutputDesc = mOutputs.valueAt(i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3348 | if (dupOutputDesc->isDuplicated() && |
| 3349 | (dupOutputDesc->mOutput1 == outputDesc || |
| 3350 | dupOutputDesc->mOutput2 == outputDesc)) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3351 | sp<AudioOutputDescriptor> outputDesc2; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3352 | if (dupOutputDesc->mOutput1 == outputDesc) { |
| 3353 | outputDesc2 = dupOutputDesc->mOutput2; |
| 3354 | } else { |
| 3355 | outputDesc2 = dupOutputDesc->mOutput1; |
| 3356 | } |
| 3357 | // As all active tracks on duplicated output will be deleted, |
| 3358 | // and as they were also referenced on the other output, the reference |
| 3359 | // count for their stream type must be adjusted accordingly on |
| 3360 | // the other output. |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3361 | for (int j = 0; j < AUDIO_STREAM_CNT; j++) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3362 | int refCount = dupOutputDesc->mRefCount[j]; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3363 | outputDesc2->changeRefCount((audio_stream_type_t)j,-refCount); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3364 | } |
| 3365 | audio_io_handle_t duplicatedOutput = mOutputs.keyAt(i); |
| 3366 | ALOGV("closeOutput() closing also duplicated output %d", duplicatedOutput); |
| 3367 | |
| 3368 | mpClientInterface->closeOutput(duplicatedOutput); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3369 | removeOutput(duplicatedOutput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3370 | } |
| 3371 | } |
| 3372 | |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 3373 | nextAudioPortGeneration(); |
| 3374 | |
| 3375 | ssize_t index = mAudioPatches.indexOfKey(outputDesc->mPatchHandle); |
| 3376 | if (index >= 0) { |
| 3377 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 3378 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
| 3379 | mAudioPatches.removeItemsAt(index); |
| 3380 | mpClientInterface->onAudioPatchListUpdate(); |
| 3381 | } |
| 3382 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3383 | AudioParameter param; |
| 3384 | param.add(String8("closing"), String8("true")); |
| 3385 | mpClientInterface->setParameters(output, param.toString()); |
| 3386 | |
| 3387 | mpClientInterface->closeOutput(output); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3388 | removeOutput(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3389 | mPreviousOutputs = mOutputs; |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | void AudioPolicyManager::closeInput(audio_io_handle_t input) |
| 3393 | { |
| 3394 | ALOGV("closeInput(%d)", input); |
| 3395 | |
| 3396 | sp<AudioInputDescriptor> inputDesc = mInputs.valueFor(input); |
| 3397 | if (inputDesc == NULL) { |
| 3398 | ALOGW("closeInput() unknown input %d", input); |
| 3399 | return; |
| 3400 | } |
| 3401 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3402 | nextAudioPortGeneration(); |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 3403 | |
| 3404 | ssize_t index = mAudioPatches.indexOfKey(inputDesc->mPatchHandle); |
| 3405 | if (index >= 0) { |
| 3406 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 3407 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
| 3408 | mAudioPatches.removeItemsAt(index); |
| 3409 | mpClientInterface->onAudioPatchListUpdate(); |
| 3410 | } |
| 3411 | |
| 3412 | mpClientInterface->closeInput(input); |
| 3413 | mInputs.removeItem(input); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3416 | SortedVector<audio_io_handle_t> AudioPolicyManager::getOutputsForDevice(audio_devices_t device, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3417 | AudioOutputCollection openOutputs) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3418 | { |
| 3419 | SortedVector<audio_io_handle_t> outputs; |
| 3420 | |
| 3421 | ALOGVV("getOutputsForDevice() device %04x", device); |
| 3422 | for (size_t i = 0; i < openOutputs.size(); i++) { |
| 3423 | ALOGVV("output %d isDuplicated=%d device=%04x", |
| 3424 | i, openOutputs.valueAt(i)->isDuplicated(), openOutputs.valueAt(i)->supportedDevices()); |
| 3425 | if ((device & openOutputs.valueAt(i)->supportedDevices()) == device) { |
| 3426 | ALOGVV("getOutputsForDevice() found output %d", openOutputs.keyAt(i)); |
| 3427 | outputs.add(openOutputs.keyAt(i)); |
| 3428 | } |
| 3429 | } |
| 3430 | return outputs; |
| 3431 | } |
| 3432 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3433 | bool AudioPolicyManager::vectorsEqual(SortedVector<audio_io_handle_t>& outputs1, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3434 | SortedVector<audio_io_handle_t>& outputs2) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3435 | { |
| 3436 | if (outputs1.size() != outputs2.size()) { |
| 3437 | return false; |
| 3438 | } |
| 3439 | for (size_t i = 0; i < outputs1.size(); i++) { |
| 3440 | if (outputs1[i] != outputs2[i]) { |
| 3441 | return false; |
| 3442 | } |
| 3443 | } |
| 3444 | return true; |
| 3445 | } |
| 3446 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3447 | void AudioPolicyManager::checkOutputForStrategy(routing_strategy strategy) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3448 | { |
| 3449 | audio_devices_t oldDevice = getDeviceForStrategy(strategy, true /*fromCache*/); |
| 3450 | audio_devices_t newDevice = getDeviceForStrategy(strategy, false /*fromCache*/); |
| 3451 | SortedVector<audio_io_handle_t> srcOutputs = getOutputsForDevice(oldDevice, mPreviousOutputs); |
| 3452 | SortedVector<audio_io_handle_t> dstOutputs = getOutputsForDevice(newDevice, mOutputs); |
| 3453 | |
Jean-Michel Trivi | fe472e2 | 2014-12-16 14:23:13 -0800 | [diff] [blame] | 3454 | // also take into account external policy-related changes: add all outputs which are |
| 3455 | // associated with policies in the "before" and "after" output vectors |
| 3456 | ALOGVV("checkOutputForStrategy(): policy related outputs"); |
| 3457 | for (size_t i = 0 ; i < mPreviousOutputs.size() ; i++) { |
| 3458 | const sp<AudioOutputDescriptor> desc = mPreviousOutputs.valueAt(i); |
| 3459 | if (desc != 0 && desc->mPolicyMix != NULL) { |
| 3460 | srcOutputs.add(desc->mIoHandle); |
| 3461 | ALOGVV(" previous outputs: adding %d", desc->mIoHandle); |
| 3462 | } |
| 3463 | } |
| 3464 | for (size_t i = 0 ; i < mOutputs.size() ; i++) { |
| 3465 | const sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 3466 | if (desc != 0 && desc->mPolicyMix != NULL) { |
| 3467 | dstOutputs.add(desc->mIoHandle); |
| 3468 | ALOGVV(" new outputs: adding %d", desc->mIoHandle); |
| 3469 | } |
| 3470 | } |
| 3471 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3472 | if (!vectorsEqual(srcOutputs,dstOutputs)) { |
| 3473 | ALOGV("checkOutputForStrategy() strategy %d, moving from output %d to output %d", |
| 3474 | strategy, srcOutputs[0], dstOutputs[0]); |
| 3475 | // mute strategy while moving tracks from one output to another |
| 3476 | for (size_t i = 0; i < srcOutputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3477 | sp<AudioOutputDescriptor> desc = mOutputs.valueFor(srcOutputs[i]); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3478 | if (isStrategyActive(desc, strategy)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3479 | setStrategyMute(strategy, true, srcOutputs[i]); |
| 3480 | setStrategyMute(strategy, false, srcOutputs[i], MUTE_TIME_MS, newDevice); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | // Move effects associated to this strategy from previous output to new output |
| 3485 | if (strategy == STRATEGY_MEDIA) { |
| 3486 | audio_io_handle_t fxOutput = selectOutputForEffects(dstOutputs); |
| 3487 | SortedVector<audio_io_handle_t> moved; |
| 3488 | for (size_t i = 0; i < mEffects.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3489 | sp<EffectDescriptor> effectDesc = mEffects.valueAt(i); |
| 3490 | if (effectDesc->mSession == AUDIO_SESSION_OUTPUT_MIX && |
| 3491 | effectDesc->mIo != fxOutput) { |
| 3492 | if (moved.indexOf(effectDesc->mIo) < 0) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3493 | ALOGV("checkOutputForStrategy() moving effect %d to output %d", |
| 3494 | mEffects.keyAt(i), fxOutput); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3495 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, effectDesc->mIo, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3496 | fxOutput); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3497 | moved.add(effectDesc->mIo); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3498 | } |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3499 | effectDesc->mIo = fxOutput; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | // Move tracks associated to this strategy from previous output to new output |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3504 | for (int i = 0; i < AUDIO_STREAM_CNT; i++) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3505 | if (i == AUDIO_STREAM_PATCH) { |
| 3506 | continue; |
| 3507 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3508 | if (getStrategy((audio_stream_type_t)i) == strategy) { |
| 3509 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3515 | void AudioPolicyManager::checkOutputForAllStrategies() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3516 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3517 | if (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3518 | checkOutputForStrategy(STRATEGY_ENFORCED_AUDIBLE); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3519 | checkOutputForStrategy(STRATEGY_PHONE); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3520 | if (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3521 | checkOutputForStrategy(STRATEGY_ENFORCED_AUDIBLE); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3522 | checkOutputForStrategy(STRATEGY_SONIFICATION); |
| 3523 | checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3524 | checkOutputForStrategy(STRATEGY_ACCESSIBILITY); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3525 | checkOutputForStrategy(STRATEGY_MEDIA); |
| 3526 | checkOutputForStrategy(STRATEGY_DTMF); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3527 | checkOutputForStrategy(STRATEGY_REROUTING); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3528 | } |
| 3529 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3530 | void AudioPolicyManager::checkA2dpSuspend() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3531 | { |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3532 | audio_io_handle_t a2dpOutput = mOutputs.getA2dpOutput(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3533 | if (a2dpOutput == 0) { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3534 | mA2dpSuspended = false; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3535 | return; |
| 3536 | } |
| 3537 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3538 | bool isScoConnected = |
Eric Laurent | ddbc665 | 2014-11-13 15:13:44 -0800 | [diff] [blame] | 3539 | ((mAvailableInputDevices.types() & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET & |
| 3540 | ~AUDIO_DEVICE_BIT_IN) != 0) || |
| 3541 | ((mAvailableOutputDevices.types() & AUDIO_DEVICE_OUT_ALL_SCO) != 0); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3542 | // suspend A2DP output if: |
| 3543 | // (NOT already suspended) && |
| 3544 | // ((SCO device is connected && |
| 3545 | // (forced usage for communication || for record is SCO))) || |
| 3546 | // (phone state is ringing || in call) |
| 3547 | // |
| 3548 | // restore A2DP output if: |
| 3549 | // (Already suspended) && |
| 3550 | // ((SCO device is NOT connected || |
| 3551 | // (forced usage NOT for communication && NOT for record is SCO))) && |
| 3552 | // (phone state is NOT ringing && NOT in call) |
| 3553 | // |
| 3554 | if (mA2dpSuspended) { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3555 | if ((!isScoConnected || |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3556 | ((mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION) != AUDIO_POLICY_FORCE_BT_SCO) && |
| 3557 | (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_RECORD) != AUDIO_POLICY_FORCE_BT_SCO))) && |
| 3558 | ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) && |
| 3559 | (mEngine->getPhoneState() != AUDIO_MODE_RINGTONE))) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3560 | |
| 3561 | mpClientInterface->restoreOutput(a2dpOutput); |
| 3562 | mA2dpSuspended = false; |
| 3563 | } |
| 3564 | } else { |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3565 | if ((isScoConnected && |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3566 | ((mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION) == AUDIO_POLICY_FORCE_BT_SCO) || |
| 3567 | (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_RECORD) == AUDIO_POLICY_FORCE_BT_SCO))) || |
| 3568 | ((mEngine->getPhoneState() == AUDIO_MODE_IN_CALL) || |
| 3569 | (mEngine->getPhoneState() == AUDIO_MODE_RINGTONE))) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3570 | |
| 3571 | mpClientInterface->suspendOutput(a2dpOutput); |
| 3572 | mA2dpSuspended = true; |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3577 | audio_devices_t AudioPolicyManager::getNewOutputDevice(audio_io_handle_t output, bool fromCache) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3578 | { |
| 3579 | audio_devices_t device = AUDIO_DEVICE_NONE; |
| 3580 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3581 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3582 | |
| 3583 | ssize_t index = mAudioPatches.indexOfKey(outputDesc->mPatchHandle); |
| 3584 | if (index >= 0) { |
| 3585 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 3586 | if (patchDesc->mUid != mUidCached) { |
| 3587 | ALOGV("getNewOutputDevice() device %08x forced by patch %d", |
| 3588 | outputDesc->device(), outputDesc->mPatchHandle); |
| 3589 | return outputDesc->device(); |
| 3590 | } |
| 3591 | } |
| 3592 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3593 | // check the following by order of priority to request a routing change if necessary: |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3594 | // 1: the strategy enforced audible is active and enforced on the output: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3595 | // use device for strategy enforced audible |
| 3596 | // 2: we are in call or the strategy phone is active on the output: |
| 3597 | // use device for strategy phone |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3598 | // 3: the strategy for enforced audible is active but not enforced on the output: |
| 3599 | // use the device for strategy enforced audible |
| 3600 | // 4: the strategy sonification is active on the output: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3601 | // use device for strategy sonification |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3602 | // 5: the strategy "respectful" sonification is active on the output: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3603 | // use device for strategy "respectful" sonification |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3604 | // 6: the strategy accessibility is active on the output: |
| 3605 | // use device for strategy accessibility |
| 3606 | // 7: the strategy media is active on the output: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3607 | // use device for strategy media |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3608 | // 8: the strategy DTMF is active on the output: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3609 | // use device for strategy DTMF |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3610 | // 9: the strategy for beacon, a.k.a. "transmitted through speaker" is active on the output: |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 3611 | // use device for strategy t-t-s |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3612 | if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE) && |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3613 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3614 | device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache); |
| 3615 | } else if (isInCall() || |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3616 | isStrategyActive(outputDesc, STRATEGY_PHONE)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3617 | device = getDeviceForStrategy(STRATEGY_PHONE, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3618 | } else if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE)) { |
Jon Eklund | 966095e | 2014-09-09 15:39:49 -0500 | [diff] [blame] | 3619 | device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3620 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3621 | device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3622 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3623 | device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3624 | } else if (isStrategyActive(outputDesc, STRATEGY_ACCESSIBILITY)) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3625 | device = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3626 | } else if (isStrategyActive(outputDesc, STRATEGY_MEDIA)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3627 | device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3628 | } else if (isStrategyActive(outputDesc, STRATEGY_DTMF)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3629 | device = getDeviceForStrategy(STRATEGY_DTMF, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3630 | } else if (isStrategyActive(outputDesc, STRATEGY_TRANSMITTED_THROUGH_SPEAKER)) { |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 3631 | device = getDeviceForStrategy(STRATEGY_TRANSMITTED_THROUGH_SPEAKER, fromCache); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3632 | } else if (isStrategyActive(outputDesc, STRATEGY_REROUTING)) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3633 | device = getDeviceForStrategy(STRATEGY_REROUTING, fromCache); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3636 | ALOGV("getNewOutputDevice() selected device %x", device); |
| 3637 | return device; |
| 3638 | } |
| 3639 | |
| 3640 | audio_devices_t AudioPolicyManager::getNewInputDevice(audio_io_handle_t input) |
| 3641 | { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3642 | sp<AudioInputDescriptor> inputDesc = mInputs.valueFor(input); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3643 | |
| 3644 | ssize_t index = mAudioPatches.indexOfKey(inputDesc->mPatchHandle); |
| 3645 | if (index >= 0) { |
| 3646 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 3647 | if (patchDesc->mUid != mUidCached) { |
| 3648 | ALOGV("getNewInputDevice() device %08x forced by patch %d", |
| 3649 | inputDesc->mDevice, inputDesc->mPatchHandle); |
| 3650 | return inputDesc->mDevice; |
| 3651 | } |
| 3652 | } |
| 3653 | |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 3654 | audio_devices_t device = getDeviceAndMixForInputSource(inputDesc->mInputSource); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3655 | |
| 3656 | ALOGV("getNewInputDevice() selected device %x", device); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3657 | return device; |
| 3658 | } |
| 3659 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3660 | uint32_t AudioPolicyManager::getStrategyForStream(audio_stream_type_t stream) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3661 | return (uint32_t)getStrategy(stream); |
| 3662 | } |
| 3663 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3664 | audio_devices_t AudioPolicyManager::getDevicesForStream(audio_stream_type_t stream) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3665 | // By checking the range of stream before calling getStrategy, we avoid |
| 3666 | // getStrategy's behavior for invalid streams. getStrategy would do a ALOGE |
| 3667 | // and then return STRATEGY_MEDIA, but we want to return the empty set. |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3668 | if (stream < (audio_stream_type_t) 0 || stream >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3669 | return AUDIO_DEVICE_NONE; |
| 3670 | } |
| 3671 | audio_devices_t devices; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 3672 | routing_strategy strategy = getStrategy(stream); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3673 | devices = getDeviceForStrategy(strategy, true /*fromCache*/); |
| 3674 | SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(devices, mOutputs); |
| 3675 | for (size_t i = 0; i < outputs.size(); i++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3676 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(outputs[i]); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3677 | if (isStrategyActive(outputDesc, strategy)) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3678 | devices = outputDesc->device(); |
| 3679 | break; |
| 3680 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3681 | } |
Jon Eklund | 11c9fb1 | 2014-06-23 14:47:03 -0500 | [diff] [blame] | 3682 | |
| 3683 | /*Filter SPEAKER_SAFE out of results, as AudioService doesn't know about it |
| 3684 | and doesn't really need to.*/ |
| 3685 | if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) { |
| 3686 | devices |= AUDIO_DEVICE_OUT_SPEAKER; |
| 3687 | devices &= ~AUDIO_DEVICE_OUT_SPEAKER_SAFE; |
| 3688 | } |
| 3689 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3690 | return devices; |
| 3691 | } |
| 3692 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3693 | routing_strategy AudioPolicyManager::getStrategy(audio_stream_type_t stream) const |
| 3694 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 3695 | ALOG_ASSERT(stream != AUDIO_STREAM_PATCH,"getStrategy() called for AUDIO_STREAM_PATCH"); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3696 | return mEngine->getStrategyForStream(stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 3699 | uint32_t AudioPolicyManager::getStrategyForAttr(const audio_attributes_t *attr) { |
| 3700 | // flags to strategy mapping |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 3701 | if ((attr->flags & AUDIO_FLAG_BEACON) == AUDIO_FLAG_BEACON) { |
| 3702 | return (uint32_t) STRATEGY_TRANSMITTED_THROUGH_SPEAKER; |
| 3703 | } |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 3704 | if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) { |
| 3705 | return (uint32_t) STRATEGY_ENFORCED_AUDIBLE; |
| 3706 | } |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 3707 | // usage to strategy mapping |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3708 | return static_cast<uint32_t>(mEngine->getStrategyForUsage(attr->usage)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3711 | void AudioPolicyManager::handleNotificationRoutingForStream(audio_stream_type_t stream) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3712 | switch(stream) { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3713 | case AUDIO_STREAM_MUSIC: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3714 | checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL); |
| 3715 | updateDevicesAndOutputs(); |
| 3716 | break; |
| 3717 | default: |
| 3718 | break; |
| 3719 | } |
| 3720 | } |
| 3721 | |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 3722 | uint32_t AudioPolicyManager::handleEventForBeacon(int event) { |
| 3723 | switch(event) { |
| 3724 | case STARTING_OUTPUT: |
| 3725 | mBeaconMuteRefCount++; |
| 3726 | break; |
| 3727 | case STOPPING_OUTPUT: |
| 3728 | if (mBeaconMuteRefCount > 0) { |
| 3729 | mBeaconMuteRefCount--; |
| 3730 | } |
| 3731 | break; |
| 3732 | case STARTING_BEACON: |
| 3733 | mBeaconPlayingRefCount++; |
| 3734 | break; |
| 3735 | case STOPPING_BEACON: |
| 3736 | if (mBeaconPlayingRefCount > 0) { |
| 3737 | mBeaconPlayingRefCount--; |
| 3738 | } |
| 3739 | break; |
| 3740 | } |
| 3741 | |
| 3742 | if (mBeaconMuteRefCount > 0) { |
| 3743 | // any playback causes beacon to be muted |
| 3744 | return setBeaconMute(true); |
| 3745 | } else { |
| 3746 | // no other playback: unmute when beacon starts playing, mute when it stops |
| 3747 | return setBeaconMute(mBeaconPlayingRefCount == 0); |
| 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | uint32_t AudioPolicyManager::setBeaconMute(bool mute) { |
| 3752 | ALOGV("setBeaconMute(%d) mBeaconMuteRefCount=%d mBeaconPlayingRefCount=%d", |
| 3753 | mute, mBeaconMuteRefCount, mBeaconPlayingRefCount); |
| 3754 | // keep track of muted state to avoid repeating mute/unmute operations |
| 3755 | if (mBeaconMuted != mute) { |
| 3756 | // mute/unmute AUDIO_STREAM_TTS on all outputs |
| 3757 | ALOGV("\t muting %d", mute); |
| 3758 | uint32_t maxLatency = 0; |
| 3759 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 3760 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 3761 | setStreamMute(AUDIO_STREAM_TTS, mute/*on*/, |
| 3762 | desc->mIoHandle, |
| 3763 | 0 /*delay*/, AUDIO_DEVICE_NONE); |
| 3764 | const uint32_t latency = desc->latency() * 2; |
| 3765 | if (latency > maxLatency) { |
| 3766 | maxLatency = latency; |
| 3767 | } |
| 3768 | } |
| 3769 | mBeaconMuted = mute; |
| 3770 | return maxLatency; |
| 3771 | } |
| 3772 | return 0; |
| 3773 | } |
| 3774 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3775 | audio_devices_t AudioPolicyManager::getDeviceForStrategy(routing_strategy strategy, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3776 | bool fromCache) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3777 | { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3778 | if (fromCache) { |
| 3779 | ALOGVV("getDeviceForStrategy() from cache strategy %d, device %x", |
| 3780 | strategy, mDeviceForStrategy[strategy]); |
| 3781 | return mDeviceForStrategy[strategy]; |
| 3782 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 3783 | return mEngine->getDeviceForStrategy(strategy); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3786 | void AudioPolicyManager::updateDevicesAndOutputs() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3787 | { |
| 3788 | for (int i = 0; i < NUM_STRATEGIES; i++) { |
| 3789 | mDeviceForStrategy[i] = getDeviceForStrategy((routing_strategy)i, false /*fromCache*/); |
| 3790 | } |
| 3791 | mPreviousOutputs = mOutputs; |
| 3792 | } |
| 3793 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3794 | uint32_t AudioPolicyManager::checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3795 | audio_devices_t prevDevice, |
| 3796 | uint32_t delayMs) |
| 3797 | { |
| 3798 | // mute/unmute strategies using an incompatible device combination |
| 3799 | // if muting, wait for the audio in pcm buffer to be drained before proceeding |
| 3800 | // if unmuting, unmute only after the specified delay |
| 3801 | if (outputDesc->isDuplicated()) { |
| 3802 | return 0; |
| 3803 | } |
| 3804 | |
| 3805 | uint32_t muteWaitMs = 0; |
| 3806 | audio_devices_t device = outputDesc->device(); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 3807 | bool shouldMute = outputDesc->isActive() && (popcount(device) >= 2); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3808 | |
| 3809 | for (size_t i = 0; i < NUM_STRATEGIES; i++) { |
| 3810 | audio_devices_t curDevice = getDeviceForStrategy((routing_strategy)i, false /*fromCache*/); |
Eric Laurent | 31551f8 | 2014-10-10 18:21:56 -0700 | [diff] [blame] | 3811 | curDevice = curDevice & outputDesc->mProfile->mSupportedDevices.types(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3812 | bool mute = shouldMute && (curDevice & device) && (curDevice != device); |
| 3813 | bool doMute = false; |
| 3814 | |
| 3815 | if (mute && !outputDesc->mStrategyMutedByDevice[i]) { |
| 3816 | doMute = true; |
| 3817 | outputDesc->mStrategyMutedByDevice[i] = true; |
| 3818 | } else if (!mute && outputDesc->mStrategyMutedByDevice[i]){ |
| 3819 | doMute = true; |
| 3820 | outputDesc->mStrategyMutedByDevice[i] = false; |
| 3821 | } |
Eric Laurent | 9940113 | 2014-05-07 19:48:15 -0700 | [diff] [blame] | 3822 | if (doMute) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3823 | for (size_t j = 0; j < mOutputs.size(); j++) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3824 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(j); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3825 | // skip output if it does not share any device with current output |
| 3826 | if ((desc->supportedDevices() & outputDesc->supportedDevices()) |
| 3827 | == AUDIO_DEVICE_NONE) { |
| 3828 | continue; |
| 3829 | } |
| 3830 | audio_io_handle_t curOutput = mOutputs.keyAt(j); |
| 3831 | ALOGVV("checkDeviceMuteStrategies() %s strategy %d (curDevice %04x) on output %d", |
| 3832 | mute ? "muting" : "unmuting", i, curDevice, curOutput); |
| 3833 | setStrategyMute((routing_strategy)i, mute, curOutput, mute ? 0 : delayMs); |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3834 | if (isStrategyActive(desc, (routing_strategy)i)) { |
Eric Laurent | 9940113 | 2014-05-07 19:48:15 -0700 | [diff] [blame] | 3835 | if (mute) { |
| 3836 | // FIXME: should not need to double latency if volume could be applied |
| 3837 | // immediately by the audioflinger mixer. We must account for the delay |
| 3838 | // between now and the next time the audioflinger thread for this output |
| 3839 | // will process a buffer (which corresponds to one buffer size, |
| 3840 | // usually 1/2 or 1/4 of the latency). |
| 3841 | if (muteWaitMs < desc->latency() * 2) { |
| 3842 | muteWaitMs = desc->latency() * 2; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | |
Eric Laurent | 9940113 | 2014-05-07 19:48:15 -0700 | [diff] [blame] | 3850 | // temporary mute output if device selection changes to avoid volume bursts due to |
| 3851 | // different per device volumes |
| 3852 | if (outputDesc->isActive() && (device != prevDevice)) { |
| 3853 | if (muteWaitMs < outputDesc->latency() * 2) { |
| 3854 | muteWaitMs = outputDesc->latency() * 2; |
| 3855 | } |
| 3856 | for (size_t i = 0; i < NUM_STRATEGIES; i++) { |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 3857 | if (isStrategyActive(outputDesc, (routing_strategy)i)) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3858 | setStrategyMute((routing_strategy)i, true, outputDesc->mIoHandle); |
Eric Laurent | 9940113 | 2014-05-07 19:48:15 -0700 | [diff] [blame] | 3859 | // do tempMute unmute after twice the mute wait time |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3860 | setStrategyMute((routing_strategy)i, false, outputDesc->mIoHandle, |
Eric Laurent | 9940113 | 2014-05-07 19:48:15 -0700 | [diff] [blame] | 3861 | muteWaitMs *2, device); |
| 3862 | } |
| 3863 | } |
| 3864 | } |
| 3865 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3866 | // wait for the PCM output buffers to empty before proceeding with the rest of the command |
| 3867 | if (muteWaitMs > delayMs) { |
| 3868 | muteWaitMs -= delayMs; |
| 3869 | usleep(muteWaitMs * 1000); |
| 3870 | return muteWaitMs; |
| 3871 | } |
| 3872 | return 0; |
| 3873 | } |
| 3874 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 3875 | uint32_t AudioPolicyManager::setOutputDevice(audio_io_handle_t output, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3876 | audio_devices_t device, |
| 3877 | bool force, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3878 | int delayMs, |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3879 | audio_patch_handle_t *patchHandle, |
| 3880 | const char* address) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3881 | { |
| 3882 | ALOGV("setOutputDevice() output %d device %04x delayMs %d", output, device, delayMs); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 3883 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3884 | AudioParameter param; |
| 3885 | uint32_t muteWaitMs; |
| 3886 | |
| 3887 | if (outputDesc->isDuplicated()) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3888 | muteWaitMs = setOutputDevice(outputDesc->mOutput1->mIoHandle, device, force, delayMs); |
| 3889 | muteWaitMs += setOutputDevice(outputDesc->mOutput2->mIoHandle, device, force, delayMs); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3890 | return muteWaitMs; |
| 3891 | } |
| 3892 | // no need to proceed if new device is not AUDIO_DEVICE_NONE and not supported by current |
| 3893 | // output profile |
| 3894 | if ((device != AUDIO_DEVICE_NONE) && |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3895 | ((device & outputDesc->mProfile->mSupportedDevices.types()) == 0)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3896 | return 0; |
| 3897 | } |
| 3898 | |
| 3899 | // filter devices according to output selected |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 3900 | device = (audio_devices_t)(device & outputDesc->mProfile->mSupportedDevices.types()); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3901 | |
| 3902 | audio_devices_t prevDevice = outputDesc->mDevice; |
| 3903 | |
| 3904 | ALOGV("setOutputDevice() prevDevice %04x", prevDevice); |
| 3905 | |
| 3906 | if (device != AUDIO_DEVICE_NONE) { |
| 3907 | outputDesc->mDevice = device; |
| 3908 | } |
| 3909 | muteWaitMs = checkDeviceMuteStrategies(outputDesc, prevDevice, delayMs); |
| 3910 | |
| 3911 | // Do not change the routing if: |
Eric Laurent | b80a2a8 | 2014-10-27 16:07:59 -0700 | [diff] [blame] | 3912 | // the requested device is AUDIO_DEVICE_NONE |
| 3913 | // OR the requested device is the same as current device |
| 3914 | // AND force is not specified |
| 3915 | // AND the output is connected by a valid audio patch. |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3916 | // Doing this check here allows the caller to call setOutputDevice() without conditions |
Eric Laurent | b80a2a8 | 2014-10-27 16:07:59 -0700 | [diff] [blame] | 3917 | if ((device == AUDIO_DEVICE_NONE || device == prevDevice) && !force && |
| 3918 | outputDesc->mPatchHandle != 0) { |
| 3919 | ALOGV("setOutputDevice() setting same device %04x or null device for output %d", |
| 3920 | device, output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3921 | return muteWaitMs; |
| 3922 | } |
| 3923 | |
| 3924 | ALOGV("setOutputDevice() changing device"); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3925 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3926 | // do the routing |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3927 | if (device == AUDIO_DEVICE_NONE) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3928 | resetOutputDevice(output, delayMs, NULL); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3929 | } else { |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 3930 | DeviceVector deviceList = (address == NULL) ? |
| 3931 | mAvailableOutputDevices.getDevicesFromType(device) |
| 3932 | : mAvailableOutputDevices.getDevicesFromTypeAddr(device, String8(address)); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3933 | if (!deviceList.isEmpty()) { |
| 3934 | struct audio_patch patch; |
| 3935 | outputDesc->toAudioPortConfig(&patch.sources[0]); |
| 3936 | patch.num_sources = 1; |
| 3937 | patch.num_sinks = 0; |
| 3938 | for (size_t i = 0; i < deviceList.size() && i < AUDIO_PATCH_PORTS_MAX; i++) { |
| 3939 | deviceList.itemAt(i)->toAudioPortConfig(&patch.sinks[i]); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3940 | patch.num_sinks++; |
| 3941 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3942 | ssize_t index; |
| 3943 | if (patchHandle && *patchHandle != AUDIO_PATCH_HANDLE_NONE) { |
| 3944 | index = mAudioPatches.indexOfKey(*patchHandle); |
| 3945 | } else { |
| 3946 | index = mAudioPatches.indexOfKey(outputDesc->mPatchHandle); |
| 3947 | } |
| 3948 | sp< AudioPatch> patchDesc; |
| 3949 | audio_patch_handle_t afPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 3950 | if (index >= 0) { |
| 3951 | patchDesc = mAudioPatches.valueAt(index); |
| 3952 | afPatchHandle = patchDesc->mAfPatchHandle; |
| 3953 | } |
| 3954 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3955 | status_t status = mpClientInterface->createAudioPatch(&patch, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3956 | &afPatchHandle, |
| 3957 | delayMs); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3958 | ALOGV("setOutputDevice() createAudioPatch returned %d patchHandle %d" |
| 3959 | "num_sources %d num_sinks %d", |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3960 | status, afPatchHandle, patch.num_sources, patch.num_sinks); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3961 | if (status == NO_ERROR) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3962 | if (index < 0) { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 3963 | patchDesc = new AudioPatch(&patch, mUidCached); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 3964 | addAudioPatch(patchDesc->mHandle, patchDesc); |
| 3965 | } else { |
| 3966 | patchDesc->mPatch = patch; |
| 3967 | } |
| 3968 | patchDesc->mAfPatchHandle = afPatchHandle; |
| 3969 | patchDesc->mUid = mUidCached; |
| 3970 | if (patchHandle) { |
| 3971 | *patchHandle = patchDesc->mHandle; |
| 3972 | } |
| 3973 | outputDesc->mPatchHandle = patchDesc->mHandle; |
| 3974 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 3975 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3976 | } |
| 3977 | } |
bryant_liu | f5e7e79 | 2014-08-19 20:07:05 +0800 | [diff] [blame] | 3978 | |
| 3979 | // inform all input as well |
| 3980 | for (size_t i = 0; i < mInputs.size(); i++) { |
| 3981 | const sp<AudioInputDescriptor> inputDescriptor = mInputs.valueAt(i); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 3982 | if (!is_virtual_input_device(inputDescriptor->mDevice)) { |
bryant_liu | f5e7e79 | 2014-08-19 20:07:05 +0800 | [diff] [blame] | 3983 | AudioParameter inputCmd = AudioParameter(); |
| 3984 | ALOGV("%s: inform input %d of device:%d", __func__, |
| 3985 | inputDescriptor->mIoHandle, device); |
| 3986 | inputCmd.addInt(String8(AudioParameter::keyRouting),device); |
| 3987 | mpClientInterface->setParameters(inputDescriptor->mIoHandle, |
| 3988 | inputCmd.toString(), |
| 3989 | delayMs); |
| 3990 | } |
| 3991 | } |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 3992 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 3993 | |
| 3994 | // update stream volumes according to new device |
| 3995 | applyStreamVolumes(output, device, delayMs); |
| 3996 | |
| 3997 | return muteWaitMs; |
| 3998 | } |
| 3999 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4000 | status_t AudioPolicyManager::resetOutputDevice(audio_io_handle_t output, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4001 | int delayMs, |
| 4002 | audio_patch_handle_t *patchHandle) |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4003 | { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4004 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4005 | ssize_t index; |
| 4006 | if (patchHandle) { |
| 4007 | index = mAudioPatches.indexOfKey(*patchHandle); |
| 4008 | } else { |
| 4009 | index = mAudioPatches.indexOfKey(outputDesc->mPatchHandle); |
| 4010 | } |
| 4011 | if (index < 0) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4012 | return INVALID_OPERATION; |
| 4013 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4014 | sp< AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 4015 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, delayMs); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4016 | ALOGV("resetOutputDevice() releaseAudioPatch returned %d", status); |
| 4017 | outputDesc->mPatchHandle = 0; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4018 | removeAudioPatch(patchDesc->mHandle); |
| 4019 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 4020 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4021 | return status; |
| 4022 | } |
| 4023 | |
| 4024 | status_t AudioPolicyManager::setInputDevice(audio_io_handle_t input, |
| 4025 | audio_devices_t device, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4026 | bool force, |
| 4027 | audio_patch_handle_t *patchHandle) |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4028 | { |
| 4029 | status_t status = NO_ERROR; |
| 4030 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4031 | sp<AudioInputDescriptor> inputDesc = mInputs.valueFor(input); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4032 | if ((device != AUDIO_DEVICE_NONE) && ((device != inputDesc->mDevice) || force)) { |
| 4033 | inputDesc->mDevice = device; |
| 4034 | |
| 4035 | DeviceVector deviceList = mAvailableInputDevices.getDevicesFromType(device); |
| 4036 | if (!deviceList.isEmpty()) { |
| 4037 | struct audio_patch patch; |
| 4038 | inputDesc->toAudioPortConfig(&patch.sinks[0]); |
Eric Laurent | daf92cc | 2014-07-22 15:36:10 -0700 | [diff] [blame] | 4039 | // AUDIO_SOURCE_HOTWORD is for internal use only: |
| 4040 | // handled as AUDIO_SOURCE_VOICE_RECOGNITION by the audio HAL |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 4041 | if (patch.sinks[0].ext.mix.usecase.source == AUDIO_SOURCE_HOTWORD && |
| 4042 | !inputDesc->mIsSoundTrigger) { |
Eric Laurent | daf92cc | 2014-07-22 15:36:10 -0700 | [diff] [blame] | 4043 | patch.sinks[0].ext.mix.usecase.source = AUDIO_SOURCE_VOICE_RECOGNITION; |
| 4044 | } |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4045 | patch.num_sinks = 1; |
| 4046 | //only one input device for now |
| 4047 | deviceList.itemAt(0)->toAudioPortConfig(&patch.sources[0]); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4048 | patch.num_sources = 1; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4049 | ssize_t index; |
| 4050 | if (patchHandle && *patchHandle != AUDIO_PATCH_HANDLE_NONE) { |
| 4051 | index = mAudioPatches.indexOfKey(*patchHandle); |
| 4052 | } else { |
| 4053 | index = mAudioPatches.indexOfKey(inputDesc->mPatchHandle); |
| 4054 | } |
| 4055 | sp< AudioPatch> patchDesc; |
| 4056 | audio_patch_handle_t afPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 4057 | if (index >= 0) { |
| 4058 | patchDesc = mAudioPatches.valueAt(index); |
| 4059 | afPatchHandle = patchDesc->mAfPatchHandle; |
| 4060 | } |
| 4061 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4062 | status_t status = mpClientInterface->createAudioPatch(&patch, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4063 | &afPatchHandle, |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4064 | 0); |
| 4065 | ALOGV("setInputDevice() createAudioPatch returned %d patchHandle %d", |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4066 | status, afPatchHandle); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4067 | if (status == NO_ERROR) { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4068 | if (index < 0) { |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 4069 | patchDesc = new AudioPatch(&patch, mUidCached); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4070 | addAudioPatch(patchDesc->mHandle, patchDesc); |
| 4071 | } else { |
| 4072 | patchDesc->mPatch = patch; |
| 4073 | } |
| 4074 | patchDesc->mAfPatchHandle = afPatchHandle; |
| 4075 | patchDesc->mUid = mUidCached; |
| 4076 | if (patchHandle) { |
| 4077 | *patchHandle = patchDesc->mHandle; |
| 4078 | } |
| 4079 | inputDesc->mPatchHandle = patchDesc->mHandle; |
| 4080 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 4081 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4082 | } |
| 4083 | } |
| 4084 | } |
| 4085 | return status; |
| 4086 | } |
| 4087 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4088 | status_t AudioPolicyManager::resetInputDevice(audio_io_handle_t input, |
| 4089 | audio_patch_handle_t *patchHandle) |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4090 | { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4091 | sp<AudioInputDescriptor> inputDesc = mInputs.valueFor(input); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4092 | ssize_t index; |
| 4093 | if (patchHandle) { |
| 4094 | index = mAudioPatches.indexOfKey(*patchHandle); |
| 4095 | } else { |
| 4096 | index = mAudioPatches.indexOfKey(inputDesc->mPatchHandle); |
| 4097 | } |
| 4098 | if (index < 0) { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4099 | return INVALID_OPERATION; |
| 4100 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4101 | sp< AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 4102 | status_t status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4103 | ALOGV("resetInputDevice() releaseAudioPatch returned %d", status); |
| 4104 | inputDesc->mPatchHandle = 0; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 4105 | removeAudioPatch(patchDesc->mHandle); |
| 4106 | nextAudioPortGeneration(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 4107 | mpClientInterface->onAudioPatchListUpdate(); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4108 | return status; |
| 4109 | } |
| 4110 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 4111 | sp<IOProfile> AudioPolicyManager::getInputProfile(audio_devices_t device, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4112 | String8 address, |
| 4113 | uint32_t& samplingRate, |
| 4114 | audio_format_t format, |
| 4115 | audio_channel_mask_t channelMask, |
| 4116 | audio_input_flags_t flags) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4117 | { |
| 4118 | // Choose an input profile based on the requested capture parameters: select the first available |
| 4119 | // profile supporting all requested parameters. |
| 4120 | |
| 4121 | for (size_t i = 0; i < mHwModules.size(); i++) |
| 4122 | { |
| 4123 | if (mHwModules[i]->mHandle == 0) { |
| 4124 | continue; |
| 4125 | } |
| 4126 | for (size_t j = 0; j < mHwModules[i]->mInputProfiles.size(); j++) |
| 4127 | { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4128 | sp<IOProfile> profile = mHwModules[i]->mInputProfiles[j]; |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 4129 | // profile->log(); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4130 | if (profile->isCompatibleProfile(device, address, samplingRate, |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 4131 | &samplingRate /*updatedSamplingRate*/, |
| 4132 | format, channelMask, (audio_output_flags_t) flags)) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4133 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4134 | return profile; |
| 4135 | } |
| 4136 | } |
| 4137 | } |
| 4138 | return NULL; |
| 4139 | } |
| 4140 | |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 4141 | |
| 4142 | audio_devices_t AudioPolicyManager::getDeviceAndMixForInputSource(audio_source_t inputSource, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4143 | AudioMix **policyMix) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4144 | { |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 4145 | audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN; |
| 4146 | audio_devices_t selectedDeviceFromMix = |
| 4147 | mPolicyMixes.getDeviceAndMixForInputSource(inputSource, availableDeviceTypes, policyMix); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4148 | |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 4149 | if (selectedDeviceFromMix != AUDIO_DEVICE_NONE) { |
| 4150 | return selectedDeviceFromMix; |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4151 | } |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 4152 | return getDeviceForInputSource(inputSource); |
| 4153 | } |
| 4154 | |
| 4155 | audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource) |
| 4156 | { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4157 | return mEngine->getDeviceForInputSource(inputSource); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4160 | float AudioPolicyManager::computeVolume(audio_stream_type_t stream, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4161 | int index, |
| 4162 | audio_io_handle_t output, |
| 4163 | audio_devices_t device) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4164 | { |
| 4165 | float volume = 1.0; |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4166 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4167 | |
| 4168 | if (device == AUDIO_DEVICE_NONE) { |
| 4169 | device = outputDesc->device(); |
| 4170 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4171 | volume = mEngine->volIndexToAmpl(Volume::getDeviceCategory(device), stream, index); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4172 | |
| 4173 | // if a headset is connected, apply the following rules to ring tones and notifications |
| 4174 | // to avoid sound level bursts in user's ears: |
| 4175 | // - always attenuate ring tones and notifications volume by 6dB |
| 4176 | // - if music is playing, always limit the volume to current music volume, |
| 4177 | // with a minimum threshold at -36dB so that notification is always perceived. |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4178 | const routing_strategy stream_strategy = getStrategy(stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4179 | if ((device & (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
| 4180 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 4181 | AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 4182 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE)) && |
| 4183 | ((stream_strategy == STRATEGY_SONIFICATION) |
| 4184 | || (stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL) |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4185 | || (stream == AUDIO_STREAM_SYSTEM) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4186 | || ((stream_strategy == STRATEGY_ENFORCED_AUDIBLE) && |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4187 | (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_NONE))) && |
| 4188 | mStreams.canBeMuted(stream)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4189 | volume *= SONIFICATION_HEADSET_VOLUME_FACTOR; |
| 4190 | // when the phone is ringing we must consider that music could have been paused just before |
| 4191 | // by the music application and behave as if music was active if the last music track was |
| 4192 | // just stopped |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4193 | if (isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY) || |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4194 | mLimitRingtoneVolume) { |
| 4195 | audio_devices_t musicDevice = getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4196 | float musicVol = computeVolume(AUDIO_STREAM_MUSIC, |
| 4197 | mStreams[AUDIO_STREAM_MUSIC].getVolumeIndex(musicDevice), |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4198 | output, |
| 4199 | musicDevice); |
| 4200 | float minVol = (musicVol > SONIFICATION_HEADSET_VOLUME_MIN) ? |
| 4201 | musicVol : SONIFICATION_HEADSET_VOLUME_MIN; |
| 4202 | if (volume > minVol) { |
| 4203 | volume = minVol; |
| 4204 | ALOGV("computeVolume limiting volume to %f musicVol %f", minVol, musicVol); |
| 4205 | } |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | return volume; |
| 4210 | } |
| 4211 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4212 | status_t AudioPolicyManager::checkAndSetVolume(audio_stream_type_t stream, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4213 | int index, |
| 4214 | audio_io_handle_t output, |
| 4215 | audio_devices_t device, |
| 4216 | int delayMs, |
| 4217 | bool force) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4218 | { |
| 4219 | |
| 4220 | // do not change actual stream volume if the stream is muted |
| 4221 | if (mOutputs.valueFor(output)->mMuteCount[stream] != 0) { |
| 4222 | ALOGVV("checkAndSetVolume() stream %d muted count %d", |
| 4223 | stream, mOutputs.valueFor(output)->mMuteCount[stream]); |
| 4224 | return NO_ERROR; |
| 4225 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4226 | audio_policy_forced_cfg_t forceUseForComm = |
| 4227 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4228 | // do not change in call volume if bluetooth is connected and vice versa |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4229 | if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) || |
| 4230 | (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4231 | ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm", |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4232 | stream, forceUseForComm); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4233 | return INVALID_OPERATION; |
| 4234 | } |
| 4235 | |
| 4236 | float volume = computeVolume(stream, index, output, device); |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4237 | // unit gain if rerouting to external policy |
| 4238 | if (device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX) { |
| 4239 | ssize_t index = mOutputs.indexOfKey(output); |
| 4240 | if (index >= 0) { |
| 4241 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueAt(index); |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 4242 | if (outputDesc->mPolicyMix != NULL) { |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4243 | ALOGV("max gain when rerouting for output=%d", output); |
| 4244 | volume = 1.0f; |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | } |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4249 | // We actually change the volume if: |
| 4250 | // - the float value returned by computeVolume() changed |
| 4251 | // - the force flag is set |
| 4252 | if (volume != mOutputs.valueFor(output)->mCurVolume[stream] || |
| 4253 | force) { |
| 4254 | mOutputs.valueFor(output)->mCurVolume[stream] = volume; |
| 4255 | ALOGVV("checkAndSetVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs); |
| 4256 | // Force VOICE_CALL to track BLUETOOTH_SCO stream volume when bluetooth audio is |
| 4257 | // enabled |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4258 | if (stream == AUDIO_STREAM_BLUETOOTH_SCO) { |
| 4259 | mpClientInterface->setStreamVolume(AUDIO_STREAM_VOICE_CALL, volume, output, delayMs); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4260 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4261 | mpClientInterface->setStreamVolume(stream, volume, output, delayMs); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4264 | if (stream == AUDIO_STREAM_VOICE_CALL || |
| 4265 | stream == AUDIO_STREAM_BLUETOOTH_SCO) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4266 | float voiceVolume; |
| 4267 | // Force voice volume to max for bluetooth SCO as volume is managed by the headset |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4268 | if (stream == AUDIO_STREAM_VOICE_CALL) { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 4269 | voiceVolume = (float)index/(float)mStreams[stream].getVolumeIndexMax(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4270 | } else { |
| 4271 | voiceVolume = 1.0; |
| 4272 | } |
| 4273 | |
| 4274 | if (voiceVolume != mLastVoiceVolume && output == mPrimaryOutput) { |
| 4275 | mpClientInterface->setVoiceVolume(voiceVolume, delayMs); |
| 4276 | mLastVoiceVolume = voiceVolume; |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | return NO_ERROR; |
| 4281 | } |
| 4282 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4283 | void AudioPolicyManager::applyStreamVolumes(audio_io_handle_t output, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4284 | audio_devices_t device, |
| 4285 | int delayMs, |
| 4286 | bool force) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4287 | { |
| 4288 | ALOGVV("applyStreamVolumes() for output %d and device %x", output, device); |
| 4289 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4290 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 4291 | if (stream == AUDIO_STREAM_PATCH) { |
| 4292 | continue; |
| 4293 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4294 | checkAndSetVolume((audio_stream_type_t)stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4295 | mStreams[stream].getVolumeIndex(device), |
| 4296 | output, |
| 4297 | device, |
| 4298 | delayMs, |
| 4299 | force); |
| 4300 | } |
| 4301 | } |
| 4302 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4303 | void AudioPolicyManager::setStrategyMute(routing_strategy strategy, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4304 | bool on, |
| 4305 | audio_io_handle_t output, |
| 4306 | int delayMs, |
| 4307 | audio_devices_t device) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4308 | { |
| 4309 | ALOGVV("setStrategyMute() strategy %d, mute %d, output %d", strategy, on, output); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4310 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 4311 | if (stream == AUDIO_STREAM_PATCH) { |
| 4312 | continue; |
| 4313 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4314 | if (getStrategy((audio_stream_type_t)stream) == strategy) { |
| 4315 | setStreamMute((audio_stream_type_t)stream, on, output, delayMs, device); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | } |
| 4319 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4320 | void AudioPolicyManager::setStreamMute(audio_stream_type_t stream, |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4321 | bool on, |
| 4322 | audio_io_handle_t output, |
| 4323 | int delayMs, |
| 4324 | audio_devices_t device) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4325 | { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 4326 | const StreamDescriptor &streamDesc = mStreams[stream]; |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4327 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4328 | if (device == AUDIO_DEVICE_NONE) { |
| 4329 | device = outputDesc->device(); |
| 4330 | } |
| 4331 | |
| 4332 | ALOGVV("setStreamMute() stream %d, mute %d, output %d, mMuteCount %d device %04x", |
| 4333 | stream, on, output, outputDesc->mMuteCount[stream], device); |
| 4334 | |
| 4335 | if (on) { |
| 4336 | if (outputDesc->mMuteCount[stream] == 0) { |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 4337 | if (streamDesc.canBeMuted() && |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4338 | ((stream != AUDIO_STREAM_ENFORCED_AUDIBLE) || |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4339 | (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_NONE))) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4340 | checkAndSetVolume(stream, 0, output, device, delayMs); |
| 4341 | } |
| 4342 | } |
| 4343 | // increment mMuteCount after calling checkAndSetVolume() so that volume change is not ignored |
| 4344 | outputDesc->mMuteCount[stream]++; |
| 4345 | } else { |
| 4346 | if (outputDesc->mMuteCount[stream] == 0) { |
| 4347 | ALOGV("setStreamMute() unmuting non muted stream!"); |
| 4348 | return; |
| 4349 | } |
| 4350 | if (--outputDesc->mMuteCount[stream] == 0) { |
| 4351 | checkAndSetVolume(stream, |
| 4352 | streamDesc.getVolumeIndex(device), |
| 4353 | output, |
| 4354 | device, |
| 4355 | delayMs); |
| 4356 | } |
| 4357 | } |
| 4358 | } |
| 4359 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4360 | void AudioPolicyManager::handleIncallSonification(audio_stream_type_t stream, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4361 | bool starting, bool stateChange) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4362 | { |
| 4363 | // if the stream pertains to sonification strategy and we are in call we must |
| 4364 | // mute the stream if it is low visibility. If it is high visibility, we must play a tone |
| 4365 | // in the device used for phone strategy and play the tone if the selected device does not |
| 4366 | // interfere with the device used for phone strategy |
| 4367 | // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as |
| 4368 | // many times as there are active tracks on the output |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4369 | const routing_strategy stream_strategy = getStrategy(stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4370 | if ((stream_strategy == STRATEGY_SONIFICATION) || |
| 4371 | ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4372 | sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(mPrimaryOutput); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4373 | ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d", |
| 4374 | stream, starting, outputDesc->mDevice, stateChange); |
| 4375 | if (outputDesc->mRefCount[stream]) { |
| 4376 | int muteCount = 1; |
| 4377 | if (stateChange) { |
| 4378 | muteCount = outputDesc->mRefCount[stream]; |
| 4379 | } |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4380 | if (audio_is_low_visibility(stream)) { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4381 | ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount); |
| 4382 | for (int i = 0; i < muteCount; i++) { |
| 4383 | setStreamMute(stream, starting, mPrimaryOutput); |
| 4384 | } |
| 4385 | } else { |
| 4386 | ALOGV("handleIncallSonification() high visibility"); |
| 4387 | if (outputDesc->device() & |
| 4388 | getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) { |
| 4389 | ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount); |
| 4390 | for (int i = 0; i < muteCount; i++) { |
| 4391 | setStreamMute(stream, starting, mPrimaryOutput); |
| 4392 | } |
| 4393 | } |
| 4394 | if (starting) { |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 4395 | mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION, |
| 4396 | AUDIO_STREAM_VOICE_CALL); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4397 | } else { |
| 4398 | mpClientInterface->stopTone(); |
| 4399 | } |
| 4400 | } |
| 4401 | } |
| 4402 | } |
| 4403 | } |
| 4404 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 4405 | void AudioPolicyManager::defaultAudioPolicyConfig(void) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4406 | { |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 4407 | sp<HwModule> module; |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 4408 | sp<IOProfile> profile; |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 4409 | sp<DeviceDescriptor> defaultInputDevice = |
| 4410 | new DeviceDescriptor(String8("builtin-mic"), AUDIO_DEVICE_IN_BUILTIN_MIC); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 4411 | mAvailableOutputDevices.add(mDefaultOutputDevice); |
| 4412 | mAvailableInputDevices.add(defaultInputDevice); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4413 | |
| 4414 | module = new HwModule("primary"); |
| 4415 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 4416 | profile = new IOProfile(String8("primary"), AUDIO_PORT_ROLE_SOURCE, module); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4417 | profile->mSamplingRates.add(44100); |
| 4418 | profile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT); |
| 4419 | profile->mChannelMasks.add(AUDIO_CHANNEL_OUT_STEREO); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 4420 | profile->mSupportedDevices.add(mDefaultOutputDevice); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4421 | profile->mFlags = AUDIO_OUTPUT_FLAG_PRIMARY; |
| 4422 | module->mOutputProfiles.add(profile); |
| 4423 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 4424 | profile = new IOProfile(String8("primary"), AUDIO_PORT_ROLE_SINK, module); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4425 | profile->mSamplingRates.add(8000); |
| 4426 | profile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT); |
| 4427 | profile->mChannelMasks.add(AUDIO_CHANNEL_IN_MONO); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 4428 | profile->mSupportedDevices.add(defaultInputDevice); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4429 | module->mInputProfiles.add(profile); |
| 4430 | |
| 4431 | mHwModules.add(module); |
| 4432 | } |
| 4433 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 4434 | audio_stream_type_t AudioPolicyManager::streamTypefromAttributesInt(const audio_attributes_t *attr) |
| 4435 | { |
| 4436 | // flags to stream type mapping |
| 4437 | if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) { |
| 4438 | return AUDIO_STREAM_ENFORCED_AUDIBLE; |
| 4439 | } |
| 4440 | if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) { |
| 4441 | return AUDIO_STREAM_BLUETOOTH_SCO; |
| 4442 | } |
Jean-Michel Trivi | 79ad438 | 2015-01-29 10:49:39 -0800 | [diff] [blame] | 4443 | if ((attr->flags & AUDIO_FLAG_BEACON) == AUDIO_FLAG_BEACON) { |
| 4444 | return AUDIO_STREAM_TTS; |
| 4445 | } |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 4446 | |
| 4447 | // usage to stream type mapping |
| 4448 | switch (attr->usage) { |
| 4449 | case AUDIO_USAGE_MEDIA: |
| 4450 | case AUDIO_USAGE_GAME: |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 4451 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 4452 | return AUDIO_STREAM_MUSIC; |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 4453 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 4454 | if (isStreamActive(AUDIO_STREAM_ALARM)) { |
| 4455 | return AUDIO_STREAM_ALARM; |
| 4456 | } |
| 4457 | if (isStreamActive(AUDIO_STREAM_RING)) { |
| 4458 | return AUDIO_STREAM_RING; |
| 4459 | } |
| 4460 | if (isInCall()) { |
| 4461 | return AUDIO_STREAM_VOICE_CALL; |
| 4462 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 4463 | return AUDIO_STREAM_ACCESSIBILITY; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 4464 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 4465 | return AUDIO_STREAM_SYSTEM; |
| 4466 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 4467 | return AUDIO_STREAM_VOICE_CALL; |
| 4468 | |
| 4469 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 4470 | return AUDIO_STREAM_DTMF; |
| 4471 | |
| 4472 | case AUDIO_USAGE_ALARM: |
| 4473 | return AUDIO_STREAM_ALARM; |
| 4474 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 4475 | return AUDIO_STREAM_RING; |
| 4476 | |
| 4477 | case AUDIO_USAGE_NOTIFICATION: |
| 4478 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 4479 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 4480 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 4481 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 4482 | return AUDIO_STREAM_NOTIFICATION; |
| 4483 | |
| 4484 | case AUDIO_USAGE_UNKNOWN: |
| 4485 | default: |
| 4486 | return AUDIO_STREAM_MUSIC; |
| 4487 | } |
| 4488 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 4489 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 4490 | bool AudioPolicyManager::isValidAttributes(const audio_attributes_t *paa) |
| 4491 | { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 4492 | // has flags that map to a strategy? |
| 4493 | if ((paa->flags & (AUDIO_FLAG_AUDIBILITY_ENFORCED | AUDIO_FLAG_SCO | AUDIO_FLAG_BEACON)) != 0) { |
| 4494 | return true; |
| 4495 | } |
| 4496 | |
| 4497 | // has known usage? |
| 4498 | switch (paa->usage) { |
| 4499 | case AUDIO_USAGE_UNKNOWN: |
| 4500 | case AUDIO_USAGE_MEDIA: |
| 4501 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 4502 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 4503 | case AUDIO_USAGE_ALARM: |
| 4504 | case AUDIO_USAGE_NOTIFICATION: |
| 4505 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 4506 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 4507 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 4508 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 4509 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 4510 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
| 4511 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 4512 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 4513 | case AUDIO_USAGE_GAME: |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 4514 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 4515 | break; |
| 4516 | default: |
| 4517 | return false; |
| 4518 | } |
| 4519 | return true; |
| 4520 | } |
| 4521 | |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 4522 | bool AudioPolicyManager::isStrategyActive(const sp<AudioOutputDescriptor> outputDesc, |
| 4523 | routing_strategy strategy, uint32_t inPastMs, |
| 4524 | nsecs_t sysTime) const |
| 4525 | { |
| 4526 | if ((sysTime == 0) && (inPastMs != 0)) { |
| 4527 | sysTime = systemTime(); |
| 4528 | } |
| 4529 | for (int i = 0; i < (int)AUDIO_STREAM_CNT; i++) { |
| 4530 | if (i == AUDIO_STREAM_PATCH) { |
| 4531 | continue; |
| 4532 | } |
| 4533 | if (((getStrategy((audio_stream_type_t)i) == strategy) || |
| 4534 | (NUM_STRATEGIES == strategy)) && |
| 4535 | outputDesc->isStreamActive((audio_stream_type_t)i, inPastMs, sysTime)) { |
| 4536 | return true; |
| 4537 | } |
| 4538 | } |
| 4539 | return false; |
| 4540 | } |
| 4541 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame^] | 4542 | audio_policy_forced_cfg_t AudioPolicyManager::getForceUse(audio_policy_force_use_t usage) |
| 4543 | { |
| 4544 | return mEngine->getForceUse(usage); |
| 4545 | } |
| 4546 | |
| 4547 | bool AudioPolicyManager::isInCall() |
| 4548 | { |
| 4549 | return isStateInCall(mEngine->getPhoneState()); |
| 4550 | } |
| 4551 | |
| 4552 | bool AudioPolicyManager::isStateInCall(int state) |
| 4553 | { |
| 4554 | return is_state_in_call(state); |
| 4555 | } |
| 4556 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 4557 | }; // namespace android |