Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 1 | /* |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 3 | * Not a contribution. |
| 4 | * |
| 5 | * Copyright (C) 2009 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 18 | * |
| 19 | * This file was modified by Dolby Laboratories, Inc. The portions of the |
| 20 | * code that are surrounded by "DOLBY..." are copyrighted and |
| 21 | * licensed separately, as follows: |
| 22 | * |
| 23 | * (C) 2015 Dolby Laboratories, Inc. |
| 24 | * |
| 25 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 26 | * you may not use this file except in compliance with the License. |
| 27 | * You may obtain a copy of the License at |
| 28 | * |
| 29 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 30 | * |
| 31 | * Unless required by applicable law or agreed to in writing, software |
| 32 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 34 | * See the License for the specific language governing permissions and |
| 35 | * limitations under the License. |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 38 | #define LOG_TAG "AudioPolicyManagerCustom" |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 39 | //#define LOG_NDEBUG 0 |
| 40 | |
| 41 | //#define VERY_VERBOSE_LOGGING |
| 42 | #ifdef VERY_VERBOSE_LOGGING |
| 43 | #define ALOGVV ALOGV |
| 44 | #else |
| 45 | #define ALOGVV(a...) do { } while(0) |
| 46 | #endif |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 47 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 48 | // A device mask for all audio output devices that are considered "remote" when evaluating |
| 49 | // active output devices in isStreamActiveRemotely() |
| 50 | #define APM_AUDIO_OUT_DEVICE_REMOTE_ALL AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 51 | // A device mask for all audio input and output devices where matching inputs/outputs on device |
| 52 | // type alone is not enough: the address must match too |
| 53 | #define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \ |
| 54 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX) |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 55 | #define SAMPLE_RATE_8000 8000 |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 56 | #include <inttypes.h> |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 57 | #include <math.h> |
Mingming Yin | 0670f16 | 2014-06-12 16:05:49 -0700 | [diff] [blame] | 58 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 59 | #include <cutils/properties.h> |
| 60 | #include <utils/Log.h> |
| 61 | #include <hardware/audio.h> |
| 62 | #include <hardware/audio_effect.h> |
| 63 | #include <media/AudioParameter.h> |
| 64 | #include <soundtrigger/SoundTrigger.h> |
| 65 | #include "AudioPolicyManager.h" |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 66 | #include <policy.h> |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 67 | #ifdef DOLBY_ENABLE |
| 68 | #include "DolbyAudioPolicy_impl.h" |
| 69 | #endif // DOLBY_END |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 70 | |
| 71 | namespace android { |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 72 | /*audio policy: workaround for truncated touch sounds*/ |
| 73 | //FIXME: workaround for truncated touch sounds |
| 74 | // to be removed when the problem is handled by system UI |
| 75 | #define TOUCH_SOUND_FIXED_DELAY_MS 100 |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 76 | #ifdef VOICE_CONCURRENCY |
| 77 | audio_output_flags_t AudioPolicyManagerCustom::getFallBackPath() |
| 78 | { |
| 79 | audio_output_flags_t flag = AUDIO_OUTPUT_FLAG_FAST; |
| 80 | char propValue[PROPERTY_VALUE_MAX]; |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 81 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 82 | if (property_get("voice.conc.fallbackpath", propValue, NULL)) { |
| 83 | if (!strncmp(propValue, "deep-buffer", 11)) { |
| 84 | flag = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 85 | } |
| 86 | else if (!strncmp(propValue, "fast", 4)) { |
| 87 | flag = AUDIO_OUTPUT_FLAG_FAST; |
| 88 | } |
| 89 | else { |
| 90 | ALOGD("voice_conc:not a recognised path(%s) in prop voice.conc.fallbackpath", |
| 91 | propValue); |
| 92 | } |
| 93 | } |
| 94 | else { |
| 95 | ALOGD("voice_conc:prop voice.conc.fallbackpath not set"); |
| 96 | } |
| 97 | |
| 98 | ALOGD("voice_conc:picked up flag(0x%x) from prop voice.conc.fallbackpath", |
| 99 | flag); |
| 100 | |
| 101 | return flag; |
| 102 | } |
| 103 | #endif /*VOICE_CONCURRENCY*/ |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 104 | |
| 105 | void AudioPolicyManagerCustom::moveGlobalEffect() |
| 106 | { |
| 107 | audio_io_handle_t dstOutput = getOutputForEffect(); |
| 108 | if (hasPrimaryOutput() && dstOutput != mPrimaryOutput->mIoHandle) { |
| 109 | #ifdef DOLBY_ENABLE |
| 110 | status_t status = |
| 111 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, |
| 112 | mPrimaryOutput->mIoHandle, |
| 113 | dstOutput); |
| 114 | if (status == NO_ERROR) { |
| 115 | for (size_t i = 0; i < mEffects.size(); i++) { |
| 116 | sp<EffectDescriptor> desc = mEffects.valueAt(i); |
| 117 | if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) { |
| 118 | // update the mIo member of EffectDescriptor |
| 119 | // for the global effect |
| 120 | ALOGV("%s updating mIo", __FUNCTION__); |
| 121 | desc->mIo = dstOutput; |
| 122 | } |
| 123 | } |
| 124 | } else { |
| 125 | ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, |
| 126 | mPrimaryOutput->mIoHandle, dstOutput); |
| 127 | } |
| 128 | #else // DOLBY_END |
| 129 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, |
| 130 | mPrimaryOutput->mIoHandle, dstOutput); |
| 131 | #endif |
| 132 | } |
| 133 | } |
| 134 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 135 | // ---------------------------------------------------------------------------- |
| 136 | // AudioPolicyInterface implementation |
| 137 | // ---------------------------------------------------------------------------- |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 138 | extern "C" AudioPolicyInterface* createAudioPolicyManager( |
| 139 | AudioPolicyClientInterface *clientInterface) |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 140 | { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 141 | return new AudioPolicyManagerCustom(clientInterface); |
| 142 | } |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 143 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 144 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface) |
| 145 | { |
| 146 | delete interface; |
| 147 | } |
| 148 | |
| 149 | status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t device, |
| 150 | audio_policy_dev_state_t state, |
| 151 | const char *device_address, |
| 152 | const char *device_name) |
| 153 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 154 | ALOGD("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s", |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 155 | device, state, device_address, device_name); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 156 | |
| 157 | // connect/disconnect only 1 device at a time |
| 158 | if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE; |
| 159 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 160 | sp<DeviceDescriptor> devDesc = |
| 161 | mHwModules.getDeviceDescriptor(device, device_address, device_name); |
| 162 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 163 | // handle output devices |
| 164 | if (audio_is_output_device(device)) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 165 | SortedVector <audio_io_handle_t> outputs; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 166 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 167 | ssize_t index = mAvailableOutputDevices.indexOf(devDesc); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 168 | |
| 169 | // save a copy of the opened output descriptors before any output is opened or closed |
| 170 | // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies() |
| 171 | mPreviousOutputs = mOutputs; |
| 172 | switch (state) |
| 173 | { |
| 174 | // handle output device connection |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 175 | case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 176 | if (index >= 0) { |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 177 | #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED |
| 178 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 179 | if (!strncmp(device_address, "hdmi_spkr", 9)) { |
| 180 | mHdmiAudioDisabled = false; |
| 181 | } else { |
| 182 | mHdmiAudioEvent = true; |
| 183 | } |
| 184 | } |
| 185 | #endif |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 186 | ALOGW("setDeviceConnectionState() device already connected: %x", device); |
| 187 | return INVALID_OPERATION; |
| 188 | } |
| 189 | ALOGV("setDeviceConnectionState() connecting device %x", device); |
| 190 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 191 | // register new device as available |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 192 | index = mAvailableOutputDevices.add(devDesc); |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 193 | #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED |
| 194 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 195 | if (!strncmp(device_address, "hdmi_spkr", 9)) { |
| 196 | mHdmiAudioDisabled = false; |
| 197 | } else { |
| 198 | mHdmiAudioEvent = true; |
| 199 | } |
| 200 | if (mHdmiAudioDisabled || !mHdmiAudioEvent) { |
| 201 | mAvailableOutputDevices.remove(devDesc); |
| 202 | ALOGW("HDMI sink not connected, do not route audio to HDMI out"); |
| 203 | return INVALID_OPERATION; |
| 204 | } |
| 205 | } |
| 206 | #endif |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 207 | if (index >= 0) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 208 | sp<HwModule> module = mHwModules.getModuleForDevice(device); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 209 | if (module == 0) { |
| 210 | ALOGD("setDeviceConnectionState() could not find HW module for device %08x", |
| 211 | device); |
| 212 | mAvailableOutputDevices.remove(devDesc); |
| 213 | return INVALID_OPERATION; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 214 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 215 | mAvailableOutputDevices[index]->attach(module); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 216 | } else { |
| 217 | return NO_MEMORY; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 218 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 219 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 220 | if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 221 | mAvailableOutputDevices.remove(devDesc); |
| 222 | return INVALID_OPERATION; |
| 223 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 224 | // Propagate device availability to Engine |
| 225 | mEngine->setDeviceConnectionState(devDesc, state); |
| 226 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 227 | // outputs should never be empty here |
| 228 | ALOG_ASSERT(outputs.size() != 0, "setDeviceConnectionState():" |
| 229 | "checkOutputsForDevice() returned no outputs but status OK"); |
| 230 | ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %zu outputs", |
| 231 | outputs.size()); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 232 | |
| 233 | // Send connect to HALs |
| 234 | AudioParameter param = AudioParameter(devDesc->mAddress); |
| 235 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device); |
| 236 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 237 | |
| 238 | } break; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 239 | // handle output device disconnection |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 240 | case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { |
| 241 | if (index < 0) { |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 242 | #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED |
| 243 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 244 | if (!strncmp(device_address, "hdmi_spkr", 9)) { |
| 245 | mHdmiAudioDisabled = true; |
| 246 | } else { |
| 247 | mHdmiAudioEvent = false; |
| 248 | } |
| 249 | } |
| 250 | #endif |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 251 | ALOGW("setDeviceConnectionState() device not connected: %x", device); |
| 252 | return INVALID_OPERATION; |
| 253 | } |
| 254 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 255 | ALOGV("setDeviceConnectionState() disconnecting output device %x", device); |
| 256 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 257 | // Send Disconnect to HALs |
| 258 | AudioParameter param = AudioParameter(devDesc->mAddress); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 259 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device); |
| 260 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 261 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 262 | // remove device from available output devices |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 263 | mAvailableOutputDevices.remove(devDesc); |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 264 | #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED |
| 265 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 266 | if (!strncmp(device_address, "hdmi_spkr", 9)) { |
| 267 | mHdmiAudioDisabled = true; |
| 268 | } else { |
| 269 | mHdmiAudioEvent = false; |
| 270 | } |
| 271 | } |
| 272 | #endif |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 273 | checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress); |
| 274 | |
| 275 | // Propagate device availability to Engine |
| 276 | mEngine->setDeviceConnectionState(devDesc, state); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 277 | } break; |
| 278 | |
| 279 | default: |
| 280 | ALOGE("setDeviceConnectionState() invalid state: %x", state); |
| 281 | return BAD_VALUE; |
| 282 | } |
| 283 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 284 | // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP |
| 285 | // output is suspended before any tracks are moved to it |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 286 | checkA2dpSuspend(); |
| 287 | checkOutputForAllStrategies(); |
| 288 | // outputs must be closed after checkOutputForAllStrategies() is executed |
| 289 | if (!outputs.isEmpty()) { |
| 290 | for (size_t i = 0; i < outputs.size(); i++) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 291 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 292 | // close unused outputs after device disconnection or direct outputs that have been |
| 293 | // opened by checkOutputsForDevice() to query dynamic parameters |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 294 | if ((state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) || |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 295 | (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) && |
| 296 | (desc->mDirectOpenCount == 0))) { |
| 297 | closeOutput(outputs[i]); |
| 298 | } |
| 299 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 300 | // check again after closing A2DP output to reset mA2dpSuspended if needed |
| 301 | checkA2dpSuspend(); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 304 | #ifdef FM_POWER_OPT |
| 305 | // handle FM device connection state to trigger FM AFE loopback |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 306 | if (device == AUDIO_DEVICE_OUT_FM && hasPrimaryOutput()) { |
Mingming Yin | 2dd77c2 | 2016-01-06 18:02:42 -0800 | [diff] [blame] | 307 | audio_devices_t newDevice = AUDIO_DEVICE_NONE; |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 308 | if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { |
| 309 | mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, 1); |
Mingming Yin | 2dd77c2 | 2016-01-06 18:02:42 -0800 | [diff] [blame] | 310 | newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false)|AUDIO_DEVICE_OUT_FM); |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 311 | mFMIsActive = true; |
Zhou Song | bd0264e | 2016-06-21 11:01:06 +0800 | [diff] [blame] | 312 | mPrimaryOutput->mDevice = newDevice & ~AUDIO_DEVICE_OUT_FM; |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 313 | } else { |
Mingming Yin | 2dd77c2 | 2016-01-06 18:02:42 -0800 | [diff] [blame] | 314 | newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false)); |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 315 | mFMIsActive = false; |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 316 | mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, -1); |
| 317 | } |
| 318 | AudioParameter param = AudioParameter(); |
| 319 | param.addInt(String8("handle_fm"), (int)newDevice); |
| 320 | mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString()); |
| 321 | } |
| 322 | #endif /* FM_POWER_OPT end */ |
| 323 | |
Zhou Song | bd0264e | 2016-06-21 11:01:06 +0800 | [diff] [blame] | 324 | updateDevicesAndOutputs(); |
| 325 | #ifdef DOLBY_ENABLE |
| 326 | // Before closing the opened outputs, update endpoint property with device capabilities |
| 327 | audio_devices_t audioOutputDevice = getDeviceForStrategy(getStrategy(AUDIO_STREAM_MUSIC), true); |
| 328 | mDolbyAudioPolicy.setEndpointSystemProperty(audioOutputDevice, mHwModules); |
| 329 | #endif // DOLBY_END |
| 330 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { |
| 331 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 332 | updateCallRouting(newDevice); |
| 333 | } |
| 334 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 335 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 336 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 337 | if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (desc != mPrimaryOutput)) { |
| 338 | audio_devices_t newDevice = getNewOutputDevice(desc, true /*fromCache*/); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 339 | // do not force device change on duplicated output because if device is 0, it will |
| 340 | // also force a device 0 for the two outputs it is duplicated to which may override |
| 341 | // a valid device selection on those outputs. |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 342 | bool force = !desc->isDuplicated() |
| 343 | && (!device_distinguishes_on_address(device) |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 344 | // always force when disconnecting (a non-duplicated device) |
| 345 | || (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 346 | setOutputDevice(desc, newDevice, force, 0); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 347 | } |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 350 | if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 351 | cleanUpForDevice(devDesc); |
| 352 | } |
| 353 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 354 | mpClientInterface->onAudioPortListUpdate(); |
| 355 | return NO_ERROR; |
| 356 | } // end if is output device |
| 357 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 358 | // handle input devices |
| 359 | if (audio_is_input_device(device)) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 360 | SortedVector <audio_io_handle_t> inputs; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 361 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 362 | ssize_t index = mAvailableInputDevices.indexOf(devDesc); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 363 | switch (state) |
| 364 | { |
| 365 | // handle input device connection |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 366 | case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { |
| 367 | if (index >= 0) { |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 368 | ALOGW("setDeviceConnectionState() device already connected: %d", device); |
| 369 | return INVALID_OPERATION; |
| 370 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 371 | sp<HwModule> module = mHwModules.getModuleForDevice(device); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 372 | if (module == NULL) { |
| 373 | ALOGW("setDeviceConnectionState(): could not find HW module for device %08x", |
| 374 | device); |
| 375 | return INVALID_OPERATION; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 376 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 377 | if (checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress) != NO_ERROR) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 378 | return INVALID_OPERATION; |
| 379 | } |
| 380 | |
| 381 | index = mAvailableInputDevices.add(devDesc); |
| 382 | if (index >= 0) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 383 | mAvailableInputDevices[index]->attach(module); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 384 | } else { |
| 385 | return NO_MEMORY; |
| 386 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 387 | |
| 388 | // Set connect to HALs |
| 389 | AudioParameter param = AudioParameter(devDesc->mAddress); |
| 390 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device); |
| 391 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 392 | |
| 393 | // Propagate device availability to Engine |
| 394 | mEngine->setDeviceConnectionState(devDesc, state); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 395 | } break; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 396 | |
| 397 | // handle input device disconnection |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 398 | case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { |
| 399 | if (index < 0) { |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 400 | ALOGW("setDeviceConnectionState() device not connected: %d", device); |
| 401 | return INVALID_OPERATION; |
| 402 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 403 | |
| 404 | ALOGV("setDeviceConnectionState() disconnecting input device %x", device); |
| 405 | |
| 406 | // Set Disconnect to HALs |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 407 | AudioParameter param = AudioParameter(devDesc->mAddress); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 408 | param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device); |
| 409 | mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString()); |
| 410 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 411 | checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 412 | mAvailableInputDevices.remove(devDesc); |
| 413 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 414 | // Propagate device availability to Engine |
| 415 | mEngine->setDeviceConnectionState(devDesc, state); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 416 | } break; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 417 | |
| 418 | default: |
| 419 | ALOGE("setDeviceConnectionState() invalid state: %x", state); |
| 420 | return BAD_VALUE; |
| 421 | } |
| 422 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 423 | closeAllInputs(); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 424 | /*audio policy: fix call volume over USB*/ |
| 425 | // As the input device list can impact the output device selection, update |
| 426 | // getDeviceForStrategy() cache |
| 427 | updateDevicesAndOutputs(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 428 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 429 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 430 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 431 | updateCallRouting(newDevice); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 432 | } |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 433 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 434 | if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 435 | cleanUpForDevice(devDesc); |
| 436 | } |
| 437 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 438 | mpClientInterface->onAudioPortListUpdate(); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 439 | return NO_ERROR; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 440 | } // end if is input device |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 441 | |
| 442 | ALOGW("setDeviceConnectionState() invalid device: %x", device); |
| 443 | return BAD_VALUE; |
| 444 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 445 | |
Preetam Singh Ranawat | 3db94ec | 2016-10-13 18:35:12 +0530 | [diff] [blame] | 446 | bool AudioPolicyManagerCustom::isInvalidationOfMusicStreamNeeded(routing_strategy strategy) |
| 447 | { |
| 448 | if (strategy == STRATEGY_MEDIA) { |
| 449 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 450 | sp<SwAudioOutputDescriptor> newOutputDesc = mOutputs.valueAt(i); |
| 451 | if (newOutputDesc->mFormat == AUDIO_FORMAT_DSD) |
| 452 | return false; |
| 453 | } |
| 454 | } |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | void AudioPolicyManagerCustom::checkOutputForStrategy(routing_strategy strategy) |
| 459 | { |
| 460 | audio_devices_t oldDevice = getDeviceForStrategy(strategy, true /*fromCache*/); |
| 461 | audio_devices_t newDevice = getDeviceForStrategy(strategy, false /*fromCache*/); |
| 462 | SortedVector<audio_io_handle_t> srcOutputs = getOutputsForDevice(oldDevice, mOutputs); |
| 463 | SortedVector<audio_io_handle_t> dstOutputs = getOutputsForDevice(newDevice, mOutputs); |
| 464 | |
| 465 | // also take into account external policy-related changes: add all outputs which are |
| 466 | // associated with policies in the "before" and "after" output vectors |
| 467 | ALOGV("checkOutputForStrategy(): policy related outputs"); |
| 468 | for (size_t i = 0 ; i < mPreviousOutputs.size() ; i++) { |
| 469 | const sp<SwAudioOutputDescriptor> desc = mPreviousOutputs.valueAt(i); |
| 470 | if (desc != 0 && desc->mPolicyMix != NULL) { |
| 471 | srcOutputs.add(desc->mIoHandle); |
| 472 | ALOGV(" previous outputs: adding %d", desc->mIoHandle); |
| 473 | } |
| 474 | } |
| 475 | for (size_t i = 0 ; i < mOutputs.size() ; i++) { |
| 476 | const sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 477 | if (desc != 0 && desc->mPolicyMix != NULL) { |
| 478 | dstOutputs.add(desc->mIoHandle); |
| 479 | ALOGV(" new outputs: adding %d", desc->mIoHandle); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if (!vectorsEqual(srcOutputs,dstOutputs) && isInvalidationOfMusicStreamNeeded(strategy)) { |
| 484 | AudioPolicyManager::checkOutputForStrategy(strategy); |
| 485 | } |
| 486 | } |
| 487 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 488 | // This function checks for the parameters which can be offloaded. |
| 489 | // This can be enhanced depending on the capability of the DSP and policy |
| 490 | // of the system. |
| 491 | bool AudioPolicyManagerCustom::isOffloadSupported(const audio_offload_info_t& offloadInfo) |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 492 | { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 493 | ALOGV("isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d," |
| 494 | " BitRate=%u, duration=%" PRId64 " us, has_video=%d", |
| 495 | offloadInfo.sample_rate, offloadInfo.channel_mask, |
| 496 | offloadInfo.format, |
| 497 | offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us, |
| 498 | offloadInfo.has_video); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 499 | |
| 500 | if (mMasterMono) { |
| 501 | return false; // no offloading if mono is set. |
| 502 | } |
| 503 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 504 | #ifdef VOICE_CONCURRENCY |
| 505 | char concpropValue[PROPERTY_VALUE_MAX]; |
| 506 | if (property_get("voice.playback.conc.disabled", concpropValue, NULL)) { |
| 507 | bool propenabled = atoi(concpropValue) || !strncmp("true", concpropValue, 4); |
| 508 | if (propenabled) { |
| 509 | if (isInCall()) |
| 510 | { |
| 511 | ALOGD("\n copl: blocking compress offload on call mode\n"); |
| 512 | return false; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | #endif |
Preetam Singh Ranawat | 96afc16 | 2016-08-25 14:35:02 +0530 | [diff] [blame] | 517 | if (property_get_bool("voice.dsd.playback.conc.disabled", true) && |
| 518 | isInCall() && (offloadInfo.format == AUDIO_FORMAT_DSD)) { |
| 519 | ALOGD("blocking DSD compress offload on call mode"); |
| 520 | return false; |
| 521 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 522 | #ifdef RECORD_PLAY_CONCURRENCY |
| 523 | char recConcPropValue[PROPERTY_VALUE_MAX]; |
| 524 | bool prop_rec_play_enabled = false; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 525 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 526 | if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) { |
| 527 | prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4); |
| 528 | } |
| 529 | |
| 530 | if ((prop_rec_play_enabled) && |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 531 | ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 532 | ALOGD("copl: blocking compress offload for record concurrency"); |
| 533 | return false; |
| 534 | } |
| 535 | #endif |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 536 | // Check if stream type is music, then only allow offload as of now. |
| 537 | if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC) |
| 538 | { |
| 539 | ALOGV("isOffloadSupported: stream_type != MUSIC, returning false"); |
| 540 | return false; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 541 | } |
Preetam Singh Ranawat | 8152ab4 | 2015-07-21 19:30:09 +0530 | [diff] [blame] | 542 | |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 543 | // Check if offload has been disabled |
| 544 | bool offloadDisabled = property_get_bool("audio.offload.disable", false); |
| 545 | if (offloadDisabled) { |
| 546 | ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled); |
| 547 | return false; |
| 548 | } |
| 549 | |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 550 | //check if it's multi-channel AAC (includes sub formats) and FLAC format |
| 551 | if ((popcount(offloadInfo.channel_mask) > 2) && |
| 552 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) || |
| 553 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS))) { |
| 554 | ALOGD("offload disabled for multi-channel AAC,FLAC and VORBIS format"); |
| 555 | return false; |
Preetam Singh Ranawat | 8152ab4 | 2015-07-21 19:30:09 +0530 | [diff] [blame] | 556 | } |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 557 | |
Preetam Singh Ranawat | 8152ab4 | 2015-07-21 19:30:09 +0530 | [diff] [blame] | 558 | #ifdef AUDIO_EXTN_FORMATS_ENABLED |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 559 | //check if it's multi-channel FLAC/ALAC/WMA format with sample rate > 48k |
| 560 | if ((popcount(offloadInfo.channel_mask) > 2) && |
| 561 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) || |
| 562 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) && (offloadInfo.sample_rate > 48000)) || |
| 563 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) && (offloadInfo.sample_rate > 48000)) || |
| 564 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.sample_rate > 48000)) || |
| 565 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS))) { |
| 566 | ALOGD("offload disabled for multi-channel FLAC/ALAC/WMA/AAC_ADTS clips with sample rate > 48kHz"); |
| 567 | return false; |
| 568 | } |
yidongh | ae28e3a | 2016-08-19 11:31:15 +0800 | [diff] [blame] | 569 | |
| 570 | if ((((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) && (offloadInfo.bit_rate > MAX_BITRATE_WMA)) || |
| 571 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.bit_rate > MAX_BITRATE_WMA_PRO)) || |
| 572 | (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.bit_rate > MAX_BITRATE_WMA_LOSSLESS))){ |
| 573 | //Safely choose the min bitrate as threshold and leave the restriction to NT decoder as we can't distinguish wma pro and wma lossless here. |
| 574 | ALOGD("offload disabled for WMA/WMA_PRO/WMA_LOSSLESS clips with bit rate over maximum supported value"); |
| 575 | return false; |
| 576 | } |
Preetam Singh Ranawat | 8152ab4 | 2015-07-21 19:30:09 +0530 | [diff] [blame] | 577 | #endif |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 578 | //TODO: enable audio offloading with video when ready |
| 579 | const bool allowOffloadWithVideo = |
| 580 | property_get_bool("audio.offload.video", false /* default_value */); |
| 581 | if (offloadInfo.has_video && !allowOffloadWithVideo) { |
| 582 | ALOGV("isOffloadSupported: has_video == true, returning false"); |
| 583 | return false; |
| 584 | } |
Manish Dewangan | f3cd0f8 | 2015-10-13 14:04:36 +0530 | [diff] [blame] | 585 | |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 586 | const bool allowOffloadStreamingWithVideo = property_get_bool("av.streaming.offload.enable", |
| 587 | false /*default value*/); |
| 588 | if (offloadInfo.has_video && offloadInfo.is_streaming && !allowOffloadStreamingWithVideo) { |
| 589 | ALOGW("offload disabled by av.streaming.offload.enable %d",allowOffloadStreamingWithVideo); |
| 590 | return false; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | //If duration is less than minimum value defined in property, return false |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 594 | char propValue[PROPERTY_VALUE_MAX]; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 595 | if (property_get("audio.offload.min.duration.secs", propValue, NULL)) { |
| 596 | if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) { |
| 597 | ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue); |
| 598 | return false; |
| 599 | } |
| 600 | } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) { |
| 601 | ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS); |
| 602 | //duration checks only valid for MP3/AAC/ formats, |
| 603 | //do not check duration for other audio formats, e.g. dolby AAC/AC3 and amrwb+ formats |
| 604 | if ((offloadInfo.format == AUDIO_FORMAT_MP3) || |
| 605 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) || |
| 606 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) || |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 607 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS)) |
| 608 | return false; |
| 609 | |
| 610 | #ifdef AUDIO_EXTN_FORMATS_ENABLED |
| 611 | if (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) || |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 612 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) || |
| 613 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) || |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 614 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_APE) || |
Preetam Singh Ranawat | 191eb77 | 2016-09-09 17:10:19 +0530 | [diff] [blame] | 615 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_DSD) || |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 616 | ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS)) |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 617 | return false; |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 618 | #endif |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | // Do not allow offloading if one non offloadable effect is enabled. This prevents from |
| 622 | // creating an offloaded track and tearing it down immediately after start when audioflinger |
| 623 | // detects there is an active non offloadable effect. |
| 624 | // FIXME: We should check the audio session here but we do not have it in this context. |
| 625 | // This may prevent offloading in rare situations where effects are left active by apps |
| 626 | // in the background. |
| 627 | if (mEffects.isNonOffloadableEffectEnabled()) { |
| 628 | return false; |
| 629 | } |
Dhananjay Kumar | cf558ba | 2016-07-29 19:33:13 +0530 | [diff] [blame] | 630 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 631 | // See if there is a profile to support this. |
| 632 | // AUDIO_DEVICE_NONE |
| 633 | sp<IOProfile> profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */, |
| 634 | offloadInfo.sample_rate, |
| 635 | offloadInfo.format, |
| 636 | offloadInfo.channel_mask, |
| 637 | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD); |
| 638 | ALOGV("isOffloadSupported() profile %sfound", profile != 0 ? "" : "NOT "); |
| 639 | return (profile != 0); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 640 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 641 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 642 | audio_devices_t AudioPolicyManagerCustom::getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
| 643 | bool fromCache) |
| 644 | { |
| 645 | audio_devices_t device = AUDIO_DEVICE_NONE; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 646 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 647 | ssize_t index = mAudioPatches.indexOfKey(outputDesc->getPatchHandle()); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 648 | if (index >= 0) { |
| 649 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index); |
| 650 | if (patchDesc->mUid != mUidCached) { |
| 651 | ALOGV("getNewOutputDevice() device %08x forced by patch %d", |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 652 | outputDesc->device(), outputDesc->getPatchHandle()); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 653 | return outputDesc->device(); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | // check the following by order of priority to request a routing change if necessary: |
| 658 | // 1: the strategy enforced audible is active and enforced on the output: |
| 659 | // use device for strategy enforced audible |
| 660 | // 2: we are in call or the strategy phone is active on the output: |
| 661 | // use device for strategy phone |
| 662 | // 3: the strategy for enforced audible is active but not enforced on the output: |
| 663 | // use the device for strategy enforced audible |
| 664 | // 4: the strategy sonification is active on the output: |
| 665 | // use device for strategy sonification |
| 666 | // 5: the strategy "respectful" sonification is active on the output: |
| 667 | // use device for strategy "respectful" sonification |
| 668 | // 6: the strategy accessibility is active on the output: |
| 669 | // use device for strategy accessibility |
| 670 | // 7: the strategy media is active on the output: |
| 671 | // use device for strategy media |
| 672 | // 8: the strategy DTMF is active on the output: |
| 673 | // use device for strategy DTMF |
| 674 | // 9: the strategy for beacon, a.k.a. "transmitted through speaker" is active on the output: |
| 675 | // use device for strategy t-t-s |
| 676 | if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE) && |
| 677 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) { |
| 678 | device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache); |
| 679 | } else if (isInCall() || |
| 680 | isStrategyActive(outputDesc, STRATEGY_PHONE)|| |
| 681 | isStrategyActive(mPrimaryOutput, STRATEGY_PHONE)) { |
| 682 | device = getDeviceForStrategy(STRATEGY_PHONE, fromCache); |
| 683 | } else if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE)) { |
| 684 | device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache); |
| 685 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION)|| |
| 686 | (isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION) |
| 687 | && (!isStrategyActive(mPrimaryOutput,STRATEGY_MEDIA)))) { |
| 688 | device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache); |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 689 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL) || |
| 690 | isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION_RESPECTFUL)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 691 | device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache); |
| 692 | } else if (isStrategyActive(outputDesc, STRATEGY_ACCESSIBILITY)) { |
| 693 | device = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, fromCache); |
| 694 | } else if (isStrategyActive(outputDesc, STRATEGY_MEDIA)) { |
| 695 | device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache); |
| 696 | } else if (isStrategyActive(outputDesc, STRATEGY_DTMF)) { |
| 697 | device = getDeviceForStrategy(STRATEGY_DTMF, fromCache); |
| 698 | } else if (isStrategyActive(outputDesc, STRATEGY_TRANSMITTED_THROUGH_SPEAKER)) { |
| 699 | device = getDeviceForStrategy(STRATEGY_TRANSMITTED_THROUGH_SPEAKER, fromCache); |
| 700 | } else if (isStrategyActive(outputDesc, STRATEGY_REROUTING)) { |
| 701 | device = getDeviceForStrategy(STRATEGY_REROUTING, fromCache); |
| 702 | } |
| 703 | |
| 704 | ALOGV("getNewOutputDevice() selected device %x", device); |
| 705 | return device; |
| 706 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 707 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 708 | void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) |
| 709 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 710 | ALOGD("setPhoneState() state %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 711 | // store previous phone state for management of sonification strategy below |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 712 | audio_devices_t newDevice = AUDIO_DEVICE_NONE; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 713 | int oldState = mEngine->getPhoneState(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 714 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 715 | if (mEngine->setPhoneState(state) != NO_ERROR) { |
| 716 | ALOGW("setPhoneState() invalid or same state %d", state); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 717 | return; |
| 718 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 719 | /// Opens: can these line be executed after the switch of volume curves??? |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 720 | // if leaving call state, handle special case of active streams |
| 721 | // pertaining to sonification strategy see handleIncallSonification() |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 722 | if (isStateInCall(oldState)) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 723 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 724 | for (size_t j = 0; j < mOutputs.size(); j++) { |
| 725 | audio_io_handle_t curOutput = mOutputs.keyAt(j); |
| 726 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
| 727 | if (stream == AUDIO_STREAM_PATCH) { |
| 728 | continue; |
| 729 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 730 | handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 731 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 732 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 733 | |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 734 | // force reevaluating accessibility routing when call stops |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 735 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 738 | /** |
| 739 | * Switching to or from incall state or switching between telephony and VoIP lead to force |
| 740 | * routing command. |
| 741 | */ |
| 742 | bool force = ((is_state_in_call(oldState) != is_state_in_call(state)) |
| 743 | || (is_state_in_call(state) && (state != oldState))); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 744 | |
| 745 | // check for device and output changes triggered by new phone state |
| 746 | checkA2dpSuspend(); |
| 747 | checkOutputForAllStrategies(); |
| 748 | updateDevicesAndOutputs(); |
| 749 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 750 | sp<SwAudioOutputDescriptor> hwOutputDesc = mPrimaryOutput; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 751 | #ifdef VOICE_CONCURRENCY |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 752 | char propValue[PROPERTY_VALUE_MAX]; |
| 753 | bool prop_playback_enabled = false, prop_rec_enabled=false, prop_voip_enabled = false; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 754 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 755 | if(property_get("voice.playback.conc.disabled", propValue, NULL)) { |
| 756 | prop_playback_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 757 | } |
| 758 | |
| 759 | if(property_get("voice.record.conc.disabled", propValue, NULL)) { |
| 760 | prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 761 | } |
| 762 | |
| 763 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 764 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 765 | } |
| 766 | |
Dhananjay Kumar | 9125b2a | 2015-12-01 16:24:09 +0530 | [diff] [blame] | 767 | if ((AUDIO_MODE_IN_CALL != oldState) && (AUDIO_MODE_IN_CALL == state)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 768 | ALOGD("voice_conc:Entering to call mode oldState :: %d state::%d ", |
| 769 | oldState, state); |
Dhananjay Kumar | 9125b2a | 2015-12-01 16:24:09 +0530 | [diff] [blame] | 770 | mvoice_call_state = state; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 771 | if (prop_rec_enabled) { |
| 772 | //Close all active inputs |
| 773 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 774 | if (activeInput != 0) { |
| 775 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 776 | switch(activeDesc->mInputSource) { |
| 777 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 778 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 779 | case AUDIO_SOURCE_VOICE_CALL: |
| 780 | ALOGD("voice_conc:FOUND active input during call active: %d",activeDesc->mInputSource); |
| 781 | break; |
| 782 | |
| 783 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 784 | if(prop_voip_enabled) { |
| 785 | ALOGD("voice_conc:CLOSING VoIP input source on call setup :%d ",activeDesc->mInputSource); |
| 786 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 787 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 788 | } |
| 789 | break; |
| 790 | |
| 791 | default: |
| 792 | ALOGD("voice_conc:CLOSING input on call setup for inputSource: %d",activeDesc->mInputSource); |
| 793 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 794 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | } else if (prop_voip_enabled) { |
| 799 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 800 | if (activeInput != 0) { |
| 801 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 802 | if (AUDIO_SOURCE_VOICE_COMMUNICATION == activeDesc->mInputSource) { |
| 803 | ALOGD("voice_conc:CLOSING VoIP on call setup : %d",activeDesc->mInputSource); |
| 804 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 805 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | if (prop_playback_enabled) { |
| 810 | // Move tracks associated to this strategy from previous output to new output |
| 811 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 812 | ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i); |
| 813 | if (i == AUDIO_STREAM_PATCH) { |
| 814 | ALOGV("voice_conc:not calling invalidate for AUDIO_STREAM_PATCH"); |
| 815 | continue; |
| 816 | } |
| 817 | if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
| 818 | if ((AUDIO_STREAM_MUSIC == i) || |
| 819 | (AUDIO_STREAM_VOICE_CALL == i) ) { |
| 820 | ALOGD("voice_conc:Invalidate stream type %d", i); |
| 821 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 822 | } |
| 823 | } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 824 | ALOGD("voice_conc:Invalidate stream type %d", i); |
| 825 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 831 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 832 | if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 833 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 834 | continue; |
| 835 | } |
| 836 | |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 837 | bool isFastFallBackNeeded = |
| 838 | ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & outputDesc->mProfile->mFlags); |
| 839 | |
| 840 | if ((AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) && isFastFallBackNeeded) { |
| 841 | if (((!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY)) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 842 | && prop_playback_enabled) { |
| 843 | ALOGD("voice_conc:calling suspendOutput on call mode for primary output"); |
| 844 | mpClientInterface->suspendOutput(mOutputs.keyAt(i)); |
| 845 | } //Close compress all sessions |
| 846 | else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) |
| 847 | && prop_playback_enabled) { |
| 848 | ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output"); |
| 849 | closeOutput(mOutputs.keyAt(i)); |
| 850 | } |
| 851 | else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) |
| 852 | && prop_voip_enabled) { |
| 853 | ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output"); |
| 854 | closeOutput(mOutputs.keyAt(i)); |
| 855 | } |
| 856 | } else if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
kunleiz | 0b55ec7 | 2016-11-10 16:23:58 +0800 | [diff] [blame] | 857 | if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) { |
| 858 | if (prop_voip_enabled) { |
| 859 | ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output"); |
| 860 | closeOutput(mOutputs.keyAt(i)); |
| 861 | } |
| 862 | } |
| 863 | else if (prop_playback_enabled |
| 864 | && (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 865 | ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output"); |
| 866 | closeOutput(mOutputs.keyAt(i)); |
| 867 | } |
| 868 | } |
| 869 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 870 | // If effects where present on any of the above closed outputs, |
| 871 | // audioflinger moved them to the primary output by default |
| 872 | // move them back to the appropriate output. |
| 873 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | if ((AUDIO_MODE_IN_CALL == oldState || AUDIO_MODE_IN_COMMUNICATION == oldState) && |
| 877 | (AUDIO_MODE_NORMAL == state) && prop_playback_enabled && mvoice_call_state) { |
| 878 | ALOGD("voice_conc:EXITING from call mode oldState :: %d state::%d \n",oldState, state); |
| 879 | mvoice_call_state = 0; |
| 880 | if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 881 | //restore PCM (deep-buffer) output after call termination |
| 882 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 883 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 884 | if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 885 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 886 | continue; |
| 887 | } |
| 888 | if (!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 889 | ALOGD("voice_conc:calling restoreOutput after call mode for primary output"); |
| 890 | mpClientInterface->restoreOutput(mOutputs.keyAt(i)); |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL |
| 895 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 896 | ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i); |
| 897 | if (i == AUDIO_STREAM_PATCH) { |
| 898 | ALOGV("voice_conc:not calling invalidate for AUDIO_STREAM_PATCH"); |
| 899 | continue; |
| 900 | } |
| 901 | if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
| 902 | if ((AUDIO_STREAM_MUSIC == i) || |
| 903 | (AUDIO_STREAM_VOICE_CALL == i) ) { |
| 904 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 905 | } |
| 906 | } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 907 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | #endif |
Preetam Singh Ranawat | 96afc16 | 2016-08-25 14:35:02 +0530 | [diff] [blame] | 913 | |
| 914 | sp<SwAudioOutputDescriptor> outputDesc = NULL; |
| 915 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 916 | outputDesc = mOutputs.valueAt(i); |
| 917 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 918 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 919 | continue; |
| 920 | } |
| 921 | |
| 922 | if (property_get_bool("voice.dsd.playback.conc.disabled", true) && |
| 923 | (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 924 | (outputDesc->mFormat == AUDIO_FORMAT_DSD)) { |
| 925 | ALOGD("voice_conc:calling closeOutput on call mode for DSD COMPRESS output"); |
| 926 | closeOutput(mOutputs.keyAt(i)); |
| 927 | // call invalidate for music, so that DSD compress will fallback to deep-buffer. |
| 928 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 929 | } |
| 930 | |
| 931 | } |
| 932 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 933 | #ifdef RECORD_PLAY_CONCURRENCY |
| 934 | char recConcPropValue[PROPERTY_VALUE_MAX]; |
| 935 | bool prop_rec_play_enabled = false; |
| 936 | |
| 937 | if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) { |
| 938 | prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4); |
| 939 | } |
| 940 | if (prop_rec_play_enabled) { |
| 941 | if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) { |
| 942 | ALOGD("phone state changed to MODE_IN_COMM invlaidating music and voice streams"); |
| 943 | // call invalidate for voice streams, so that it can use deepbuffer with VoIP out device from HAL |
| 944 | mpClientInterface->invalidateStream(AUDIO_STREAM_VOICE_CALL); |
| 945 | // call invalidate for music, so that compress will fallback to deep-buffer with VoIP out device |
| 946 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 947 | |
| 948 | // close compress output to make sure session will be closed before timeout(60sec) |
| 949 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 950 | |
| 951 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 952 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 953 | ALOGD("ouput desc / profile is NULL"); |
| 954 | continue; |
| 955 | } |
| 956 | |
| 957 | if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 958 | ALOGD("calling closeOutput on call mode for COMPRESS output"); |
| 959 | closeOutput(mOutputs.keyAt(i)); |
| 960 | } |
| 961 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 962 | // If effects where present on any of the above closed outputs, |
| 963 | // audioflinger moved them to the primary output by default |
| 964 | // move them back to the appropriate output. |
| 965 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 966 | } else if ((oldState == AUDIO_MODE_IN_COMMUNICATION) && |
| 967 | (mEngine->getPhoneState() == AUDIO_MODE_NORMAL)) { |
| 968 | // call invalidate for music so that music can fallback to compress |
| 969 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 970 | } |
| 971 | } |
| 972 | #endif |
| 973 | mPrevPhoneState = oldState; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 974 | int delayMs = 0; |
| 975 | if (isStateInCall(state)) { |
| 976 | nsecs_t sysTime = systemTime(); |
| 977 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 978 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 979 | // mute media and sonification strategies and delay device switch by the largest |
| 980 | // latency of any output where either strategy is active. |
| 981 | // This avoid sending the ring tone or music tail into the earpiece or headset. |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 982 | if ((isStrategyActive(desc, STRATEGY_MEDIA, |
| 983 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 984 | sysTime) || |
| 985 | isStrategyActive(desc, STRATEGY_SONIFICATION, |
| 986 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 987 | sysTime)) && |
| 988 | (delayMs < (int)desc->latency()*2)) { |
| 989 | delayMs = desc->latency()*2; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 990 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 991 | setStrategyMute(STRATEGY_MEDIA, true, desc); |
| 992 | setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 993 | getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/)); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 994 | setStrategyMute(STRATEGY_SONIFICATION, true, desc); |
| 995 | setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 996 | getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/)); |
| 997 | } |
| 998 | } |
| 999 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1000 | if (hasPrimaryOutput()) { |
| 1001 | // Note that despite the fact that getNewOutputDevice() is called on the primary output, |
| 1002 | // the device returned is not necessarily reachable via this output |
| 1003 | audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 1004 | // force routing command to audio hardware when ending call |
| 1005 | // even if no device change is needed |
| 1006 | if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) { |
| 1007 | rxDevice = mPrimaryOutput->device(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1008 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1009 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1010 | if (state == AUDIO_MODE_IN_CALL) { |
| 1011 | updateCallRouting(rxDevice, delayMs); |
| 1012 | } else if (oldState == AUDIO_MODE_IN_CALL) { |
| 1013 | if (mCallRxPatch != 0) { |
| 1014 | mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0); |
| 1015 | mCallRxPatch.clear(); |
| 1016 | } |
| 1017 | if (mCallTxPatch != 0) { |
| 1018 | mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0); |
| 1019 | mCallTxPatch.clear(); |
| 1020 | } |
| 1021 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
| 1022 | } else { |
| 1023 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1024 | } |
| 1025 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1026 | //update device for all non-primary outputs |
| 1027 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1028 | audio_io_handle_t output = mOutputs.keyAt(i); |
| 1029 | if (output != mPrimaryOutput->mIoHandle) { |
| 1030 | newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/); |
| 1031 | setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE)); |
| 1032 | } |
| 1033 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1034 | // if entering in call state, handle special case of active streams |
| 1035 | // pertaining to sonification strategy see handleIncallSonification() |
| 1036 | if (isStateInCall(state)) { |
| 1037 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1038 | for (size_t j = 0; j < mOutputs.size(); j++) { |
| 1039 | audio_io_handle_t curOutput = mOutputs.keyAt(j); |
| 1040 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
| 1041 | if (stream == AUDIO_STREAM_PATCH) { |
| 1042 | continue; |
| 1043 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1044 | handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1045 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1046 | } |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 1047 | |
| 1048 | // force reevaluating accessibility routing when call starts |
| 1049 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE |
| 1053 | if (state == AUDIO_MODE_RINGTONE && |
| 1054 | isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) { |
| 1055 | mLimitRingtoneVolume = true; |
| 1056 | } else { |
| 1057 | mLimitRingtoneVolume = false; |
| 1058 | } |
| 1059 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1060 | |
| 1061 | void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage, |
| 1062 | audio_policy_forced_cfg_t config) |
| 1063 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1064 | ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState()); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1065 | |
| 1066 | if (mEngine->setForceUse(usage, config) != NO_ERROR) { |
| 1067 | ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage); |
| 1068 | return; |
| 1069 | } |
| 1070 | bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) || |
| 1071 | (usage == AUDIO_POLICY_FORCE_FOR_DOCK) || |
| 1072 | (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM); |
| 1073 | |
| 1074 | // check for device and output changes triggered by new force usage |
| 1075 | checkA2dpSuspend(); |
| 1076 | checkOutputForAllStrategies(); |
| 1077 | updateDevicesAndOutputs(); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1078 | |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1079 | /*audio policy: workaround for truncated touch sounds*/ |
| 1080 | //FIXME: workaround for truncated touch sounds |
| 1081 | // to be removed when the problem is handled by system UI |
| 1082 | uint32_t delayMs = 0; |
| 1083 | uint32_t waitMs = 0; |
| 1084 | if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) { |
| 1085 | delayMs = TOUCH_SOUND_FIXED_DELAY_MS; |
| 1086 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1087 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { |
| 1088 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1089 | waitMs = updateCallRouting(newDevice, delayMs); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1090 | } |
| 1091 | // Use reverse loop to make sure any low latency usecases (generally tones) |
| 1092 | // are not routed before non LL usecases (generally music). |
| 1093 | // We can safely assume that LL output would always have lower index, |
| 1094 | // and use this work-around to avoid routing of output with music stream |
| 1095 | // from the context of short lived LL output. |
| 1096 | // Note: in case output's share backend(HAL sharing is implicit) all outputs |
| 1097 | // gets routing update while processing first output itself. |
| 1098 | for (size_t i = mOutputs.size(); i > 0; i--) { |
| 1099 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1); |
| 1100 | audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1101 | if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) { |
| 1102 | waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE), |
| 1103 | delayMs); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1104 | } |
| 1105 | if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1106 | applyStreamVolumes(outputDesc, newDevice, waitMs, true); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 1111 | if (activeInput != 0) { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1112 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 1113 | audio_devices_t newDevice = getNewInputDevice(activeInput); |
| 1114 | // Force new input selection if the new device can not be reached via current input |
| 1115 | if (activeDesc->mProfile->getSupportedDevices().types() & (newDevice & ~AUDIO_DEVICE_BIT_IN)) { |
| 1116 | setInputDevice(activeInput, newDevice); |
| 1117 | } else { |
| 1118 | closeInput(activeInput); |
| 1119 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1120 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1121 | } |
| 1122 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1123 | status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1124 | audio_stream_type_t stream, |
| 1125 | bool forceDeviceUpdate) |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1126 | { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1127 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1128 | ALOGW("stopSource() invalid stream %d", stream); |
| 1129 | return INVALID_OPERATION; |
| 1130 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1131 | // always handle stream stop, check which stream type is stopping |
| 1132 | handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 1133 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1134 | // handle special case for sonification while in call |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1135 | if (isInCall()) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1136 | if (outputDesc->isDuplicated()) { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1137 | handleIncallSonification(stream, false, false, outputDesc->subOutput1()->mIoHandle); |
| 1138 | handleIncallSonification(stream, false, false, outputDesc->subOutput2()->mIoHandle); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1139 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1140 | handleIncallSonification(stream, false, false, outputDesc->mIoHandle); |
| 1141 | } |
| 1142 | |
| 1143 | if (outputDesc->mRefCount[stream] > 0) { |
| 1144 | // decrement usage count of this stream on the output |
| 1145 | outputDesc->changeRefCount(stream, -1); |
| 1146 | |
| 1147 | // store time at which the stream was stopped - see isStreamActive() |
| 1148 | if (outputDesc->mRefCount[stream] == 0 || forceDeviceUpdate) { |
| 1149 | outputDesc->mStopTime[stream] = systemTime(); |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1150 | audio_devices_t prevDevice = outputDesc->device(); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1151 | audio_devices_t newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/); |
| 1152 | // delay the device switch by twice the latency because stopOutput() is executed when |
| 1153 | // the track stop() command is received and at that time the audio track buffer can |
| 1154 | // still contain data that needs to be drained. The latency only covers the audio HAL |
| 1155 | // and kernel buffers. Also the latency does not always include additional delay in the |
| 1156 | // audio path (audio DSP, CODEC ...) |
| 1157 | setOutputDevice(outputDesc, newDevice, false, outputDesc->latency()*2); |
| 1158 | |
| 1159 | // force restoring the device selection on other active outputs if it differs from the |
| 1160 | // one being selected for this output |
| 1161 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1162 | audio_io_handle_t curOutput = mOutputs.keyAt(i); |
| 1163 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1164 | if (desc != outputDesc && |
| 1165 | desc->isActive() && |
| 1166 | outputDesc->sharesHwModuleWith(desc) && |
| 1167 | (newDevice != desc->device())) { |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1168 | audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/); |
Naresh Tanniru | 1139370 | 2016-09-14 11:25:37 +0530 | [diff] [blame] | 1169 | bool force = desc->device() != dev; |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1170 | uint32_t delayMs; |
| 1171 | if (dev == prevDevice) { |
| 1172 | delayMs = 0; |
| 1173 | } else { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1174 | delayMs = outputDesc->latency()*2; |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1175 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1176 | setOutputDevice(desc, |
| 1177 | dev, |
Naresh Tanniru | 1139370 | 2016-09-14 11:25:37 +0530 | [diff] [blame] | 1178 | force, |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1179 | delayMs); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1180 | /*audio policy: fix media volume after ringtone*/ |
| 1181 | // re-apply device specific volume if not done by setOutputDevice() |
| 1182 | if (!force) { |
| 1183 | applyStreamVolumes(desc, dev, delayMs); |
| 1184 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | // update the outputs if stopping one with a stream that can affect notification routing |
| 1188 | handleNotificationRoutingForStream(stream); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1189 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1190 | return NO_ERROR; |
| 1191 | } else { |
| 1192 | ALOGW("stopOutput() refcount is already 0"); |
| 1193 | return INVALID_OPERATION; |
| 1194 | } |
| 1195 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1196 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1197 | status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1198 | audio_stream_type_t stream, |
| 1199 | audio_devices_t device, |
Lalit Kansara | f803ac5 | 2016-05-09 19:12:01 +0530 | [diff] [blame] | 1200 | const char *address, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1201 | uint32_t *delayMs) |
| 1202 | { |
| 1203 | // cannot start playback of STREAM_TTS if any other output is being used |
| 1204 | uint32_t beaconMuteLatency = 0; |
| 1205 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1206 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1207 | ALOGW("startSource() invalid stream %d", stream); |
| 1208 | return INVALID_OPERATION; |
| 1209 | } |
| 1210 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1211 | *delayMs = 0; |
| 1212 | if (stream == AUDIO_STREAM_TTS) { |
| 1213 | ALOGV("\t found BEACON stream"); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1214 | if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1215 | return INVALID_OPERATION; |
| 1216 | } else { |
| 1217 | beaconMuteLatency = handleEventForBeacon(STARTING_BEACON); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1218 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1219 | } else { |
| 1220 | // some playback other than beacon starts |
| 1221 | beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT); |
| 1222 | } |
| 1223 | |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1224 | // force device change if the output is inactive and no audio patch is already present. |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1225 | // check active before incrementing usage count |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1226 | bool force = !outputDesc->isActive() && |
| 1227 | (outputDesc->getPatchHandle() == AUDIO_PATCH_HANDLE_NONE); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1228 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1229 | // increment usage count for this stream on the requested output: |
| 1230 | // NOTE that the usage count is the same for duplicated output and hardware output which is |
| 1231 | // necessary for a correct control of hardware output routing by startOutput() and stopOutput() |
| 1232 | outputDesc->changeRefCount(stream, 1); |
| 1233 | |
| 1234 | if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) { |
| 1235 | // starting an output being rerouted? |
| 1236 | if (device == AUDIO_DEVICE_NONE) { |
| 1237 | device = getNewOutputDevice(outputDesc, false /*fromCache*/); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1238 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1239 | routing_strategy strategy = getStrategy(stream); |
| 1240 | bool shouldWait = (strategy == STRATEGY_SONIFICATION) || |
| 1241 | (strategy == STRATEGY_SONIFICATION_RESPECTFUL) || |
| 1242 | (beaconMuteLatency > 0); |
| 1243 | uint32_t waitMs = beaconMuteLatency; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1244 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1245 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1246 | if (desc != outputDesc) { |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1247 | // force a device change if any other output is: |
| 1248 | // - managed by the same hw module |
| 1249 | // - has a current device selection that differs from selected device. |
| 1250 | // - supports currently selected device |
| 1251 | // - has an active audio patch |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1252 | // In this case, the audio HAL must receive the new device selection so that it can |
| 1253 | // change the device currently selected by the other active output. |
| 1254 | if (outputDesc->sharesHwModuleWith(desc) && |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1255 | desc->device() != device && |
| 1256 | desc->supportedDevices() & device && |
| 1257 | desc->getPatchHandle() != AUDIO_PATCH_HANDLE_NONE) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1258 | force = true; |
| 1259 | } |
| 1260 | // wait for audio on other active outputs to be presented when starting |
| 1261 | // a notification so that audio focus effect can propagate, or that a mute/unmute |
| 1262 | // event occurred for beacon |
| 1263 | uint32_t latency = desc->latency(); |
| 1264 | if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) { |
| 1265 | waitMs = latency; |
| 1266 | } |
| 1267 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1268 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1269 | uint32_t muteWaitMs; |
Lalit Kansara | f803ac5 | 2016-05-09 19:12:01 +0530 | [diff] [blame] | 1270 | muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1271 | |
| 1272 | // handle special case for sonification while in call |
| 1273 | if (isInCall()) { |
| 1274 | handleIncallSonification(stream, true, false, outputDesc->mIoHandle); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1275 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1276 | |
| 1277 | // apply volume rules for current stream and device if necessary |
| 1278 | checkAndSetVolume(stream, |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1279 | mVolumeCurves->getVolumeIndex(stream, device), |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1280 | outputDesc, |
| 1281 | device); |
| 1282 | |
| 1283 | // update the outputs if starting an output with a stream that can affect notification |
| 1284 | // routing |
| 1285 | handleNotificationRoutingForStream(stream); |
| 1286 | |
| 1287 | // force reevaluating accessibility routing when ringtone or alarm starts |
| 1288 | if (strategy == STRATEGY_SONIFICATION) { |
| 1289 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
| 1290 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1291 | if (waitMs > muteWaitMs) { |
| 1292 | *delayMs = waitMs - muteWaitMs; |
| 1293 | } |
| 1294 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1295 | } |
| 1296 | else { |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1297 | // handle special case for sonification while in call |
| 1298 | if (isInCall()) { |
| 1299 | handleIncallSonification(stream, true, false, outputDesc->mIoHandle); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1300 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1301 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1302 | return NO_ERROR; |
| 1303 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1304 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1305 | void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream, |
| 1306 | bool starting, bool stateChange, |
| 1307 | audio_io_handle_t output) |
| 1308 | { |
| 1309 | if(!hasPrimaryOutput()) { |
| 1310 | return; |
| 1311 | } |
| 1312 | // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks |
| 1313 | if (stream == AUDIO_STREAM_PATCH) { |
| 1314 | return; |
| 1315 | } |
| 1316 | // if the stream pertains to sonification strategy and we are in call we must |
| 1317 | // mute the stream if it is low visibility. If it is high visibility, we must play a tone |
| 1318 | // in the device used for phone strategy and play the tone if the selected device does not |
| 1319 | // interfere with the device used for phone strategy |
| 1320 | // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as |
| 1321 | // many times as there are active tracks on the output |
| 1322 | const routing_strategy stream_strategy = getStrategy(stream); |
| 1323 | if ((stream_strategy == STRATEGY_SONIFICATION) || |
| 1324 | ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) { |
| 1325 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
| 1326 | ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d", |
| 1327 | stream, starting, outputDesc->mDevice, stateChange); |
| 1328 | if (outputDesc->mRefCount[stream]) { |
| 1329 | int muteCount = 1; |
| 1330 | if (stateChange) { |
| 1331 | muteCount = outputDesc->mRefCount[stream]; |
| 1332 | } |
| 1333 | if (audio_is_low_visibility(stream)) { |
| 1334 | ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount); |
| 1335 | for (int i = 0; i < muteCount; i++) { |
| 1336 | setStreamMute(stream, starting, outputDesc); |
| 1337 | } |
| 1338 | } else { |
| 1339 | ALOGV("handleIncallSonification() high visibility"); |
| 1340 | if (outputDesc->device() & |
| 1341 | getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) { |
| 1342 | ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount); |
| 1343 | for (int i = 0; i < muteCount; i++) { |
| 1344 | setStreamMute(stream, starting, outputDesc); |
| 1345 | } |
| 1346 | } |
| 1347 | if (starting) { |
| 1348 | mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION, |
| 1349 | AUDIO_STREAM_VOICE_CALL); |
| 1350 | } else { |
| 1351 | mpClientInterface->stopTone(); |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1357 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1358 | void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) { |
| 1359 | switch(stream) { |
| 1360 | case AUDIO_STREAM_MUSIC: |
| 1361 | checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL); |
| 1362 | updateDevicesAndOutputs(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1363 | break; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1364 | default: |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1365 | break; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 1366 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1367 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1368 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1369 | status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream, |
| 1370 | int index, |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1371 | const sp<AudioOutputDescriptor>& outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1372 | audio_devices_t device, |
| 1373 | int delayMs, bool force) |
| 1374 | { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1375 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1376 | ALOGW("checkAndSetVolume() invalid stream %d", stream); |
| 1377 | return INVALID_OPERATION; |
| 1378 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1379 | // do not change actual stream volume if the stream is muted |
| 1380 | if (outputDesc->mMuteCount[stream] != 0) { |
| 1381 | ALOGVV("checkAndSetVolume() stream %d muted count %d", |
| 1382 | stream, outputDesc->mMuteCount[stream]); |
| 1383 | return NO_ERROR; |
| 1384 | } |
| 1385 | audio_policy_forced_cfg_t forceUseForComm = |
| 1386 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION); |
| 1387 | // do not change in call volume if bluetooth is connected and vice versa |
| 1388 | if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) || |
| 1389 | (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) { |
| 1390 | ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm", |
| 1391 | stream, forceUseForComm); |
| 1392 | return INVALID_OPERATION; |
| 1393 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1394 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1395 | if (device == AUDIO_DEVICE_NONE) { |
| 1396 | device = outputDesc->device(); |
| 1397 | } |
| 1398 | |
| 1399 | float volumeDb = computeVolume(stream, index, device); |
| 1400 | if (outputDesc->isFixedVolume(device)) { |
| 1401 | volumeDb = 0.0f; |
| 1402 | } |
| 1403 | |
| 1404 | outputDesc->setVolume(volumeDb, stream, device, delayMs, force); |
| 1405 | |
| 1406 | if (stream == AUDIO_STREAM_VOICE_CALL || |
| 1407 | stream == AUDIO_STREAM_BLUETOOTH_SCO) { |
| 1408 | float voiceVolume; |
| 1409 | // Force voice volume to max for bluetooth SCO as volume is managed by the headset |
| 1410 | if (stream == AUDIO_STREAM_VOICE_CALL) { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1411 | voiceVolume = (float)index/(float)mVolumeCurves->getVolumeIndexMax(stream); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1412 | } else { |
| 1413 | voiceVolume = 1.0; |
| 1414 | } |
| 1415 | |
| 1416 | if (voiceVolume != mLastVoiceVolume && ((outputDesc == mPrimaryOutput) || |
| 1417 | isDirectOutput(outputDesc->mIoHandle) || device & AUDIO_DEVICE_OUT_ALL_USB)) { |
| 1418 | mpClientInterface->setVoiceVolume(voiceVolume, delayMs); |
| 1419 | mLastVoiceVolume = voiceVolume; |
| 1420 | } |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 1421 | #ifdef FM_POWER_OPT |
| 1422 | } else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() && |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 1423 | outputDesc == mPrimaryOutput && mFMIsActive) { |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 1424 | /* Avoid unnecessary set_parameter calls as it puts the primary |
| 1425 | outputs FastMixer in HOT_IDLE leading to breaks in audio */ |
| 1426 | if (volumeDb != mPrevFMVolumeDb) { |
| 1427 | mPrevFMVolumeDb = volumeDb; |
| 1428 | AudioParameter param = AudioParameter(); |
| 1429 | param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb)); |
Mingming Yin | 1433cc6 | 2016-01-04 14:58:00 -0800 | [diff] [blame] | 1430 | //Double delayMs to avoid sound burst while device switch. |
| 1431 | mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs*2); |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 1432 | } |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 1433 | #endif /* FM_POWER_OPT end */ |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | return NO_ERROR; |
| 1437 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1438 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1439 | bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) { |
| 1440 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1441 | audio_io_handle_t curOutput = mOutputs.keyAt(i); |
| 1442 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1443 | if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
| 1444 | return true; |
| 1445 | } |
| 1446 | } |
| 1447 | return false; |
| 1448 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1449 | |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1450 | bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate) |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1451 | { |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1452 | bool playerDirectPCM = false; // Output request for Track created by mediaplayer |
| 1453 | bool trackDirectPCM = false; // Output request for track created by other apps |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1454 | bool offloadDisabled = property_get_bool("audio.offload.disable", false); |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1455 | |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1456 | // Direct PCM is allowed only if |
| 1457 | // In case of mediaPlayer playback |
| 1458 | // 16 bit direct pcm or 24bit direct PCM property is set and |
| 1459 | // the FLAG requested is DIRECT_PCM ( NuPlayer case) or |
| 1460 | // In case of AudioTracks created by apps |
| 1461 | // track offload is enabled and FLAG requested is FLAG_NONE. |
| 1462 | |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1463 | if (offloadDisabled) { |
| 1464 | ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled); |
| 1465 | } |
| 1466 | |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1467 | if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 1468 | if (bitWidth == 24 || bitWidth == 32) |
| 1469 | playerDirectPCM = |
| 1470 | property_get_bool("audio.offload.pcm.24bit.enable", false); |
| 1471 | else |
| 1472 | playerDirectPCM = |
| 1473 | property_get_bool("audio.offload.pcm.16bit.enable", false); |
| 1474 | // Reset flag to NONE so that we can still reuse direct pcm criteria check |
| 1475 | // in getOutputforDevice |
| 1476 | *flags = AUDIO_OUTPUT_FLAG_NONE; |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1477 | } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) { |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1478 | trackDirectPCM = property_get_bool("audio.offload.track.enable", true); |
| 1479 | } |
| 1480 | |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1481 | ALOGI("Direct PCM %s for this request", |
| 1482 | (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled"); |
| 1483 | |
| 1484 | return (!offloadDisabled && (trackDirectPCM || playerDirectPCM)); |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1485 | } |
| 1486 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1487 | status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, |
| 1488 | audio_io_handle_t *output, |
| 1489 | audio_session_t session, |
| 1490 | audio_stream_type_t *stream, |
| 1491 | uid_t uid, |
| 1492 | uint32_t samplingRate, |
| 1493 | audio_format_t format, |
| 1494 | audio_channel_mask_t channelMask, |
| 1495 | audio_output_flags_t flags, |
| 1496 | audio_port_handle_t selectedDeviceId, |
| 1497 | const audio_offload_info_t *offloadInfo) |
| 1498 | { |
| 1499 | audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; |
| 1500 | |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1501 | uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1502 | |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1503 | |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1504 | if (tryForDirectPCM(bitWidth, &flags, samplingRate) && |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1505 | (offloadInfo == NULL)) { |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1506 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1507 | tOffloadInfo.sample_rate = samplingRate; |
| 1508 | tOffloadInfo.channel_mask = channelMask; |
| 1509 | tOffloadInfo.format = format; |
| 1510 | tOffloadInfo.stream_type = *stream; |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1511 | tOffloadInfo.bit_width = bitWidth; |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1512 | if (attr != NULL) { |
| 1513 | ALOGV("found attribute .. setting usage %d ", attr->usage); |
| 1514 | tOffloadInfo.usage = attr->usage; |
| 1515 | } else { |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1516 | ALOGI("%s:: attribute is NULL .. no usage set", __func__); |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1517 | } |
| 1518 | offloadInfo = &tOffloadInfo; |
| 1519 | } |
| 1520 | |
| 1521 | return AudioPolicyManager::getOutputForAttr(attr, output, session, stream, |
| 1522 | (uid_t)uid, (uint32_t)samplingRate, |
| 1523 | format, (audio_channel_mask_t)channelMask, |
| 1524 | flags, (audio_port_handle_t)selectedDeviceId, |
| 1525 | offloadInfo); |
| 1526 | } |
| 1527 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1528 | audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( |
| 1529 | audio_devices_t device, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1530 | audio_session_t session __unused, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1531 | audio_stream_type_t stream, |
| 1532 | uint32_t samplingRate, |
| 1533 | audio_format_t format, |
| 1534 | audio_channel_mask_t channelMask, |
| 1535 | audio_output_flags_t flags, |
| 1536 | const audio_offload_info_t *offloadInfo) |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1537 | { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1538 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1539 | status_t status; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1540 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1541 | #ifdef AUDIO_POLICY_TEST |
| 1542 | if (mCurOutput != 0) { |
| 1543 | ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d", |
| 1544 | mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput); |
| 1545 | |
| 1546 | if (mTestOutputs[mCurOutput] == 0) { |
| 1547 | ALOGV("getOutput() opening test output"); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1548 | sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL, |
| 1549 | mpClientInterface); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1550 | outputDesc->mDevice = mTestDevice; |
| 1551 | outputDesc->mLatency = mTestLatencyMs; |
| 1552 | outputDesc->mFlags = |
| 1553 | (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0); |
| 1554 | outputDesc->mRefCount[stream] = 0; |
| 1555 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 1556 | config.sample_rate = mTestSamplingRate; |
| 1557 | config.channel_mask = mTestChannels; |
| 1558 | config.format = mTestFormat; |
| 1559 | if (offloadInfo != NULL) { |
| 1560 | config.offload_info = *offloadInfo; |
| 1561 | } |
| 1562 | status = mpClientInterface->openOutput(0, |
| 1563 | &mTestOutputs[mCurOutput], |
| 1564 | &config, |
| 1565 | &outputDesc->mDevice, |
| 1566 | String8(""), |
| 1567 | &outputDesc->mLatency, |
| 1568 | outputDesc->mFlags); |
| 1569 | if (status == NO_ERROR) { |
| 1570 | outputDesc->mSamplingRate = config.sample_rate; |
| 1571 | outputDesc->mFormat = config.format; |
| 1572 | outputDesc->mChannelMask = config.channel_mask; |
| 1573 | AudioParameter outputCmd = AudioParameter(); |
| 1574 | outputCmd.addInt(String8("set_id"),mCurOutput); |
| 1575 | mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString()); |
| 1576 | addOutput(mTestOutputs[mCurOutput], outputDesc); |
| 1577 | } |
| 1578 | } |
| 1579 | return mTestOutputs[mCurOutput]; |
| 1580 | } |
| 1581 | #endif //AUDIO_POLICY_TEST |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1582 | if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) && |
| 1583 | (stream != AUDIO_STREAM_MUSIC)) { |
| 1584 | // compress should not be used for non-music streams |
| 1585 | ALOGE("Offloading only allowed with music stream"); |
| 1586 | return 0; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1587 | } |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1588 | |
| 1589 | if ((stream == AUDIO_STREAM_VOICE_CALL) && |
| 1590 | (channelMask == 1) && |
Shiv Maliyappanahalli | d77d3b3 | 2016-02-02 13:45:50 -0800 | [diff] [blame] | 1591 | (samplingRate == 8000 || samplingRate == 16000 || |
| 1592 | samplingRate == 32000 || samplingRate == 48000)) { |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1593 | // Allow Voip direct output only if: |
| 1594 | // audio mode is MODE_IN_COMMUNCATION; AND |
| 1595 | // voip output is not opened already; AND |
| 1596 | // requested sample rate matches with that of voip input stream (if opened already) |
| 1597 | int value = 0; |
| 1598 | uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1; |
| 1599 | String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1600 | String8("audio_mode")); |
| 1601 | AudioParameter result = AudioParameter(valueStr); |
| 1602 | if (result.getInt(String8("audio_mode"), value) == NO_ERROR) { |
| 1603 | mode = value; |
| 1604 | } |
| 1605 | |
| 1606 | valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1607 | String8("voip_out_stream_count")); |
| 1608 | result = AudioParameter(valueStr); |
| 1609 | if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) { |
| 1610 | voipOutCount = value; |
| 1611 | } |
| 1612 | |
| 1613 | valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1614 | String8("voip_sample_rate")); |
| 1615 | result = AudioParameter(valueStr); |
| 1616 | if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) { |
| 1617 | voipSampleRate = value; |
| 1618 | } |
| 1619 | |
| 1620 | if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) && |
| 1621 | ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) { |
| 1622 | if (audio_is_linear_pcm(format)) { |
| 1623 | char propValue[PROPERTY_VALUE_MAX] = {0}; |
| 1624 | property_get("use.voice.path.for.pcm.voip", propValue, "0"); |
| 1625 | bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true")); |
| 1626 | if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) { |
Karthik Reddy Katta | 3fb9be7 | 2015-11-25 11:18:27 +0530 | [diff] [blame] | 1627 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_VOIP_RX | |
| 1628 | AUDIO_OUTPUT_FLAG_DIRECT); |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1629 | ALOGD("Set VoIP and Direct output flags for PCM format"); |
| 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1635 | #ifdef VOICE_CONCURRENCY |
| 1636 | char propValue[PROPERTY_VALUE_MAX]; |
| 1637 | bool prop_play_enabled=false, prop_voip_enabled = false; |
| 1638 | |
| 1639 | if(property_get("voice.playback.conc.disabled", propValue, NULL)) { |
| 1640 | prop_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1641 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1642 | |
| 1643 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 1644 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 1645 | } |
| 1646 | |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1647 | bool isDeepBufferFallBackNeeded = |
| 1648 | ((AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags); |
| 1649 | bool isFastFallBackNeeded = |
| 1650 | ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags); |
| 1651 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1652 | if (prop_play_enabled && mvoice_call_state) { |
| 1653 | //check if voice call is active / running in background |
| 1654 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 1655 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) |
| 1656 | && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 1657 | { |
| 1658 | if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1659 | if(prop_voip_enabled) { |
| 1660 | ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x", |
| 1661 | flags ); |
| 1662 | return 0; |
| 1663 | } |
| 1664 | } |
| 1665 | else { |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1666 | if (isFastFallBackNeeded && |
| 1667 | (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1668 | ALOGD("voice_conc:IN call mode adding ULL flags .. flags: %x ", flags ); |
| 1669 | flags = AUDIO_OUTPUT_FLAG_FAST; |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1670 | } else if (isDeepBufferFallBackNeeded && |
| 1671 | (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1672 | if (AUDIO_STREAM_MUSIC == stream) { |
| 1673 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1674 | ALOGD("voice_conc:IN call mode adding deep-buffer flags %x ", flags ); |
| 1675 | } |
| 1676 | else { |
| 1677 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1678 | ALOGD("voice_conc:IN call mode adding fast flags %x ", flags ); |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | } else if (prop_voip_enabled && mvoice_call_state) { |
| 1684 | //check if voice call is active / running in background |
| 1685 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 1686 | //return only ULL ouput |
| 1687 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 1688 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) |
| 1689 | && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 1690 | { |
| 1691 | if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1692 | ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x", |
| 1693 | flags ); |
| 1694 | return 0; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | #endif |
| 1699 | #ifdef RECORD_PLAY_CONCURRENCY |
| 1700 | char recConcPropValue[PROPERTY_VALUE_MAX]; |
| 1701 | bool prop_rec_play_enabled = false; |
| 1702 | |
| 1703 | if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) { |
| 1704 | prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4); |
| 1705 | } |
| 1706 | if ((prop_rec_play_enabled) && |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 1707 | ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1708 | if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) { |
| 1709 | if (AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1710 | // allow VoIP using voice path |
| 1711 | // Do nothing |
| 1712 | } else if((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) { |
| 1713 | ALOGD("voice_conc:MODE_IN_COMM is setforcing deep buffer output for non ULL... flags: %x", flags); |
| 1714 | // use deep buffer path for all non ULL outputs |
| 1715 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1716 | } |
| 1717 | } else if ((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) { |
| 1718 | ALOGD("voice_conc:Record mode is on forcing deep buffer output for non ULL... flags: %x ", flags); |
| 1719 | // use deep buffer path for all non ULL outputs |
| 1720 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1721 | } |
| 1722 | } |
| 1723 | if (prop_rec_play_enabled && |
| 1724 | (stream == AUDIO_STREAM_ENFORCED_AUDIBLE)) { |
| 1725 | ALOGD("Record conc is on forcing ULL output for ENFORCED_AUDIBLE"); |
| 1726 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1727 | } |
| 1728 | #endif |
| 1729 | |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1730 | #ifdef AUDIO_EXTN_AFE_PROXY_ENABLED |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1731 | /* |
| 1732 | * WFD audio routes back to target speaker when starting a ringtone playback. |
| 1733 | * This is because primary output is reused for ringtone, so output device is |
| 1734 | * updated based on SONIFICATION strategy for both ringtone and music playback. |
| 1735 | * The same issue is not seen on remoted_submix HAL based WFD audio because |
| 1736 | * primary output is not reused and a new output is created for ringtone playback. |
| 1737 | * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is |
| 1738 | * a non-music stream playback on WFD, so primary output is not reused for ringtone. |
| 1739 | */ |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1740 | audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types(); |
| 1741 | if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY) |
| 1742 | && (stream != AUDIO_STREAM_MUSIC)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1743 | ALOGD("WFD audio: use OUTPUT_FLAG_FAST for non music stream. flags:%x", flags ); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1744 | //For voip paths |
| 1745 | if(flags & AUDIO_OUTPUT_FLAG_DIRECT) |
| 1746 | flags = AUDIO_OUTPUT_FLAG_DIRECT; |
| 1747 | else //route every thing else to ULL path |
| 1748 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1749 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1750 | #endif |
| 1751 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1752 | // open a direct output if required by specified parameters |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1753 | // force direct flag if offload flag is set: offloading implies a direct output stream |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1754 | // and all common behaviors are driven by checking only the direct flag |
| 1755 | // this should normally be set appropriately in the policy configuration file |
| 1756 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) { |
| 1757 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
| 1758 | } |
| 1759 | if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) { |
| 1760 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
| 1761 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1762 | |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1763 | bool forced_deep = false; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1764 | // only allow deep buffering for music stream type |
| 1765 | if (stream != AUDIO_STREAM_MUSIC) { |
| 1766 | flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
Sharad Sangle | 497aef8 | 2015-08-03 17:55:48 +0530 | [diff] [blame] | 1767 | } else if (/* stream == AUDIO_STREAM_MUSIC && */ |
| 1768 | flags == AUDIO_OUTPUT_FLAG_NONE && |
| 1769 | property_get_bool("audio.deep_buffer.media", false /* default_value */)) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1770 | forced_deep = true; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1771 | } |
Sharad Sangle | 497aef8 | 2015-08-03 17:55:48 +0530 | [diff] [blame] | 1772 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1773 | if (stream == AUDIO_STREAM_TTS) { |
| 1774 | flags = AUDIO_OUTPUT_FLAG_TTS; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Zhou Song | 2b3d155 | 2016-03-21 17:21:04 +0800 | [diff] [blame] | 1777 | // check if direct output for track offload already exits |
| 1778 | bool is_track_offload_active = false; |
| 1779 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1780 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1781 | if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 1782 | is_track_offload_active = true; |
| 1783 | ALOGD("Track offload already active"); |
| 1784 | break; |
| 1785 | } |
| 1786 | } |
| 1787 | |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1788 | // Do offload magic here |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1789 | if ((flags == AUDIO_OUTPUT_FLAG_NONE) && |
| 1790 | (stream == AUDIO_STREAM_MUSIC) && |
Zhou Song | 2b3d155 | 2016-03-21 17:21:04 +0800 | [diff] [blame] | 1791 | (offloadInfo != NULL) && !is_track_offload_active && |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1792 | ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1793 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM); |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1794 | ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1795 | } |
| 1796 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1797 | sp<IOProfile> profile; |
| 1798 | |
| 1799 | // skip direct output selection if the request can obviously be attached to a mixed output |
| 1800 | // and not explicitly requested |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1801 | if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1802 | audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX && |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1803 | audio_channel_count_from_out_mask(channelMask) <= 2) { |
| 1804 | goto non_direct_output; |
| 1805 | } |
| 1806 | |
| 1807 | // Do not allow offloading if one non offloadable effect is enabled. This prevents from |
| 1808 | // creating an offloaded track and tearing it down immediately after start when audioflinger |
| 1809 | // detects there is an active non offloadable effect. |
| 1810 | // FIXME: We should check the audio session here but we do not have it in this context. |
| 1811 | // This may prevent offloading in rare situations where effects are left active by apps |
| 1812 | // in the background. |
Weiyin Jiang | 6bba320 | 2016-03-03 14:49:36 +0800 | [diff] [blame] | 1813 | // |
| 1814 | // Supplementary annotation: |
| 1815 | // For sake of track offload introduced, we need a rollback for both compress offload |
| 1816 | // and track offload use cases. |
| 1817 | if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) && |
| 1818 | (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) { |
| 1819 | ALOGD("non offloadable effect is enabled, try with non direct output"); |
| 1820 | goto non_direct_output; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Weiyin Jiang | 6bba320 | 2016-03-03 14:49:36 +0800 | [diff] [blame] | 1823 | profile = getProfileForDirectOutput(device, |
| 1824 | samplingRate, |
| 1825 | format, |
| 1826 | channelMask, |
| 1827 | (audio_output_flags_t)flags); |
| 1828 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1829 | if (profile != 0) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1830 | |
| 1831 | if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1832 | (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1833 | ALOGI("got Direct_PCM without requesting ... reject "); |
| 1834 | profile = NULL; |
| 1835 | goto non_direct_output; |
| 1836 | } |
| 1837 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1838 | sp<SwAudioOutputDescriptor> outputDesc = NULL; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1839 | |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1840 | // if multiple concurrent offload decode is supported |
| 1841 | // do no check for reuse and also don't close previous output if its offload |
| 1842 | // previous output will be closed during track destruction |
| 1843 | if (!(property_get_bool("audio.offload.multiple.enabled", false) && |
| 1844 | ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) { |
| 1845 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1846 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1847 | if (!desc->isDuplicated() && (profile == desc->mProfile)) { |
| 1848 | outputDesc = desc; |
| 1849 | // reuse direct output if currently open and configured with same parameters |
| 1850 | if ((samplingRate == outputDesc->mSamplingRate) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1851 | audio_formats_match(format, outputDesc->mFormat) && |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1852 | (channelMask == outputDesc->mChannelMask)) { |
| 1853 | outputDesc->mDirectOpenCount++; |
| 1854 | ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i)); |
| 1855 | return mOutputs.keyAt(i); |
| 1856 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1857 | } |
| 1858 | } |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1859 | // close direct output if currently open and configured with different parameters |
| 1860 | if (outputDesc != NULL) { |
| 1861 | closeOutput(outputDesc->mIoHandle); |
| 1862 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1863 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1864 | |
| 1865 | // if the selected profile is offloaded and no offload info was specified, |
| 1866 | // create a default one |
| 1867 | audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER; |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1868 | if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1869 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD); |
| 1870 | defaultOffloadInfo.sample_rate = samplingRate; |
| 1871 | defaultOffloadInfo.channel_mask = channelMask; |
| 1872 | defaultOffloadInfo.format = format; |
| 1873 | defaultOffloadInfo.stream_type = stream; |
| 1874 | defaultOffloadInfo.bit_rate = 0; |
| 1875 | defaultOffloadInfo.duration_us = -1; |
| 1876 | defaultOffloadInfo.has_video = true; // conservative |
| 1877 | defaultOffloadInfo.is_streaming = true; // likely |
| 1878 | offloadInfo = &defaultOffloadInfo; |
| 1879 | } |
| 1880 | |
| 1881 | outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1882 | outputDesc->mDevice = device; |
| 1883 | outputDesc->mLatency = 0; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1884 | outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1885 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 1886 | config.sample_rate = samplingRate; |
| 1887 | config.channel_mask = channelMask; |
| 1888 | config.format = format; |
| 1889 | if (offloadInfo != NULL) { |
| 1890 | config.offload_info = *offloadInfo; |
| 1891 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1892 | status = mpClientInterface->openOutput(profile->getModuleHandle(), |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1893 | &output, |
| 1894 | &config, |
| 1895 | &outputDesc->mDevice, |
| 1896 | String8(""), |
| 1897 | &outputDesc->mLatency, |
| 1898 | outputDesc->mFlags); |
| 1899 | |
| 1900 | // only accept an output with the requested parameters |
| 1901 | if (status != NO_ERROR || |
| 1902 | (samplingRate != 0 && samplingRate != config.sample_rate) || |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1903 | (format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) || |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1904 | (channelMask != 0 && channelMask != config.channel_mask)) { |
| 1905 | ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d," |
| 1906 | "format %d %d, channelMask %04x %04x", output, samplingRate, |
| 1907 | outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask, |
| 1908 | outputDesc->mChannelMask); |
| 1909 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 1910 | mpClientInterface->closeOutput(output); |
| 1911 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1912 | // fall back to mixer output if possible when the direct output could not be open |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1913 | if (audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1914 | goto non_direct_output; |
| 1915 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1916 | return AUDIO_IO_HANDLE_NONE; |
| 1917 | } |
| 1918 | outputDesc->mSamplingRate = config.sample_rate; |
| 1919 | outputDesc->mChannelMask = config.channel_mask; |
| 1920 | outputDesc->mFormat = config.format; |
| 1921 | outputDesc->mRefCount[stream] = 0; |
| 1922 | outputDesc->mStopTime[stream] = 0; |
| 1923 | outputDesc->mDirectOpenCount = 1; |
| 1924 | |
| 1925 | audio_io_handle_t srcOutput = getOutputForEffect(); |
| 1926 | addOutput(output, outputDesc); |
| 1927 | audio_io_handle_t dstOutput = getOutputForEffect(); |
| 1928 | if (dstOutput == output) { |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 1929 | #ifdef DOLBY_ENABLE |
| 1930 | status_t status = mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput); |
| 1931 | if (status == NO_ERROR) { |
| 1932 | for (size_t i = 0; i < mEffects.size(); i++) { |
| 1933 | sp<EffectDescriptor> desc = mEffects.valueAt(i); |
| 1934 | if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) { |
| 1935 | // update the mIo member of EffectDescriptor for the global effect |
| 1936 | ALOGV("%s updating mIo", __FUNCTION__); |
| 1937 | desc->mIo = dstOutput; |
| 1938 | } |
| 1939 | } |
| 1940 | } else { |
| 1941 | ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, srcOutput, dstOutput); |
| 1942 | } |
| 1943 | #else // DOLBY_END |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1944 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput); |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 1945 | #endif // LINE_ADDED_BY_DOLBY |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1946 | } |
| 1947 | mPreviousOutputs = mOutputs; |
| 1948 | ALOGV("getOutput() returns new direct output %d", output); |
| 1949 | mpClientInterface->onAudioPortListUpdate(); |
| 1950 | return output; |
| 1951 | } |
| 1952 | |
| 1953 | non_direct_output: |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 1954 | |
| 1955 | // A request for HW A/V sync cannot fallback to a mixed output because time |
| 1956 | // stamps are embedded in audio data |
| 1957 | if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) { |
| 1958 | return AUDIO_IO_HANDLE_NONE; |
| 1959 | } |
| 1960 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1961 | // ignoring channel mask due to downmix capability in mixer |
| 1962 | |
| 1963 | // open a non direct output |
| 1964 | |
| 1965 | // for non direct outputs, only PCM is supported |
| 1966 | if (audio_is_linear_pcm(format)) { |
| 1967 | // get which output is suitable for the specified stream. The actual |
| 1968 | // routing change will happen when startOutput() will be called |
| 1969 | SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs); |
| 1970 | |
| 1971 | // at this stage we should ignore the DIRECT flag as no direct output could be found earlier |
| 1972 | flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT); |
Ashish Jain | 660d311 | 2016-06-20 10:16:51 +0530 | [diff] [blame] | 1973 | |
| 1974 | if (forced_deep) { |
| 1975 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
| 1976 | ALOGI("setting force DEEP buffer now "); |
| 1977 | } else if(flags == AUDIO_OUTPUT_FLAG_NONE) { |
| 1978 | // no deep buffer playback is requested hence fallback to primary |
| 1979 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_PRIMARY); |
| 1980 | ALOGI("FLAG None hence request for a primary output"); |
| 1981 | } |
| 1982 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1983 | output = selectOutput(outputs, flags, format); |
| 1984 | } |
| 1985 | ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d," |
| 1986 | "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags); |
| 1987 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1988 | ALOGV("getOutputForDevice() returns output %d", output); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1989 | |
| 1990 | return output; |
| 1991 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1992 | |
| 1993 | status_t AudioPolicyManagerCustom::getInputForAttr(const audio_attributes_t *attr, |
| 1994 | audio_io_handle_t *input, |
| 1995 | audio_session_t session, |
| 1996 | uid_t uid, |
| 1997 | uint32_t samplingRate, |
| 1998 | audio_format_t format, |
| 1999 | audio_channel_mask_t channelMask, |
| 2000 | audio_input_flags_t flags, |
| 2001 | audio_port_handle_t selectedDeviceId, |
| 2002 | input_type_t *inputType) |
| 2003 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2004 | audio_source_t inputSource; |
| 2005 | inputSource = attr->source; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2006 | #ifdef VOICE_CONCURRENCY |
| 2007 | |
| 2008 | char propValue[PROPERTY_VALUE_MAX]; |
| 2009 | bool prop_rec_enabled=false, prop_voip_enabled = false; |
| 2010 | |
| 2011 | if(property_get("voice.record.conc.disabled", propValue, NULL)) { |
| 2012 | prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2013 | } |
| 2014 | |
| 2015 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 2016 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2017 | } |
| 2018 | |
| 2019 | if (prop_rec_enabled && mvoice_call_state) { |
| 2020 | //check if voice call is active / running in background |
| 2021 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 2022 | //Need to block input request |
| 2023 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 2024 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) && |
| 2025 | (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 2026 | { |
| 2027 | switch(inputSource) { |
| 2028 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 2029 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 2030 | case AUDIO_SOURCE_VOICE_CALL: |
| 2031 | ALOGD("voice_conc:Creating input during incall mode for inputSource: %d", |
| 2032 | inputSource); |
| 2033 | break; |
| 2034 | |
| 2035 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 2036 | if(prop_voip_enabled) { |
| 2037 | ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d", |
| 2038 | inputSource); |
| 2039 | return NO_INIT; |
| 2040 | } |
| 2041 | break; |
| 2042 | default: |
| 2043 | ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d", |
| 2044 | inputSource); |
| 2045 | return NO_INIT; |
| 2046 | } |
| 2047 | } |
| 2048 | }//check for VoIP flag |
| 2049 | else if(prop_voip_enabled && mvoice_call_state) { |
| 2050 | //check if voice call is active / running in background |
| 2051 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 2052 | //Need to block input request |
| 2053 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 2054 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) && |
| 2055 | (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 2056 | { |
| 2057 | if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 2058 | ALOGD("BLOCKING VoIP request during incall mode for inputSource: %d ",inputSource); |
| 2059 | return NO_INIT; |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | #endif |
| 2065 | |
| 2066 | return AudioPolicyManager::getInputForAttr(attr, |
| 2067 | input, |
| 2068 | session, |
| 2069 | uid, |
| 2070 | samplingRate, |
| 2071 | format, |
| 2072 | channelMask, |
| 2073 | flags, |
| 2074 | selectedDeviceId, |
| 2075 | inputType); |
| 2076 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 2077 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2078 | status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input, |
| 2079 | audio_session_t session) |
| 2080 | { |
| 2081 | ALOGV("startInput() input %d", input); |
| 2082 | ssize_t index = mInputs.indexOfKey(input); |
| 2083 | if (index < 0) { |
| 2084 | ALOGW("startInput() unknown input %d", input); |
| 2085 | return BAD_VALUE; |
| 2086 | } |
| 2087 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index); |
| 2088 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2089 | sp<AudioSession> audioSession = inputDesc->getAudioSession(session); |
| 2090 | if (audioSession == 0) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2091 | ALOGW("startInput() unknown session %d on input %d", session, input); |
| 2092 | return BAD_VALUE; |
| 2093 | } |
| 2094 | |
| 2095 | // virtual input devices are compatible with other input devices |
| 2096 | if (!is_virtual_input_device(inputDesc->mDevice)) { |
| 2097 | |
| 2098 | // for a non-virtual input device, check if there is another (non-virtual) active input |
| 2099 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 2100 | if (activeInput != 0 && activeInput != input) { |
| 2101 | |
| 2102 | // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed, |
| 2103 | // otherwise the active input continues and the new input cannot be started. |
| 2104 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2105 | if ((activeDesc->inputSource() == AUDIO_SOURCE_HOTWORD) && |
| 2106 | !activeDesc->hasPreemptedSession(session)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2107 | ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2108 | //FIXME: consider all active sessions |
| 2109 | AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions(); |
| 2110 | audio_session_t activeSession = activeSessions.keyAt(0); |
| 2111 | SortedVector<audio_session_t> sessions = |
| 2112 | activeDesc->getPreemptedSessions(); |
| 2113 | sessions.add(activeSession); |
| 2114 | inputDesc->setPreemptedSessions(sessions); |
| 2115 | stopInput(activeInput, activeSession); |
| 2116 | releaseInput(activeInput, activeSession); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2117 | } else { |
| 2118 | ALOGE("startInput(%d) failed: other input %d already started", input, activeInput); |
| 2119 | return INVALID_OPERATION; |
| 2120 | } |
| 2121 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2122 | // Do not allow capture if an active voice call is using a software patch and |
| 2123 | // the call TX source device is on the same HW module. |
| 2124 | // FIXME: would be better to refine to only inputs whose profile connects to the |
| 2125 | // call TX device but this information is not in the audio patch |
| 2126 | if (mCallTxPatch != 0 && |
| 2127 | inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) { |
| 2128 | return INVALID_OPERATION; |
| 2129 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | // Routing? |
| 2133 | mInputRoutes.incRouteActivity(session); |
| 2134 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2135 | mIsInputRequestOnProgress = true; |
| 2136 | |
| 2137 | char getPropValue[PROPERTY_VALUE_MAX]; |
| 2138 | bool prop_rec_play_enabled = false; |
| 2139 | |
| 2140 | if (property_get("rec.playback.conc.disabled", getPropValue, NULL)) { |
| 2141 | prop_rec_play_enabled = atoi(getPropValue) || !strncmp("true", getPropValue, 4); |
| 2142 | } |
| 2143 | |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 2144 | if ((prop_rec_play_enabled) &&(mInputs.activeInputsCountOnDevices() == 0)){ |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2145 | // send update to HAL on record playback concurrency |
| 2146 | AudioParameter param = AudioParameter(); |
| 2147 | param.add(String8("rec_play_conc_on"), String8("true")); |
| 2148 | ALOGD("startInput() setParameters rec_play_conc is setting to ON "); |
| 2149 | mpClientInterface->setParameters(0, param.toString()); |
| 2150 | |
| 2151 | // Call invalidate to reset all opened non ULL audio tracks |
| 2152 | // Move tracks associated to this strategy from previous output to new output |
| 2153 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 2154 | // Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder) |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 2155 | if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH))) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2156 | ALOGD("Invalidate on releaseInput for stream :: %d ", i); |
| 2157 | //FIXME see fixme on name change |
| 2158 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 2159 | } |
| 2160 | } |
| 2161 | // close compress tracks |
| 2162 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 2163 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 2164 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 2165 | ALOGD("ouput desc / profile is NULL"); |
| 2166 | continue; |
| 2167 | } |
| 2168 | if (outputDesc->mProfile->mFlags |
| 2169 | & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 2170 | // close compress sessions |
| 2171 | ALOGD("calling closeOutput on record conc for COMPRESS output"); |
| 2172 | closeOutput(mOutputs.keyAt(i)); |
| 2173 | } |
| 2174 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 2175 | // If effects where present on any of the above closed outputs, |
| 2176 | // audioflinger moved them to the primary output by default |
| 2177 | // move them back to the appropriate output. |
| 2178 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2179 | } |
| 2180 | #endif |
| 2181 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2182 | if (!inputDesc->isActive() || mInputRoutes.hasRouteChanged(session)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2183 | // if input maps to a dynamic policy with an activity listener, notify of state change |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2184 | if ((inputDesc->mPolicyMix != NULL) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2185 | && ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) { |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 2186 | mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress, |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2187 | MIX_STATE_MIXING); |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2188 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 2189 | /*audio policy: fix capture indication to sound trigger service*/ |
| 2190 | // indicate active capture to sound trigger service if starting capture from a mic on |
| 2191 | // primary HW module |
| 2192 | audio_devices_t device = getNewInputDevice(input); |
| 2193 | audio_devices_t primaryInputDevices = availablePrimaryInputDevices(); |
| 2194 | if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) && |
| 2195 | mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2196 | SoundTrigger::setCaptureState(true); |
| 2197 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 2198 | setInputDevice(input, device, true /* force */); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2199 | |
| 2200 | // automatically enable the remote submix output when input is started if not |
| 2201 | // used by a policy mix of type MIX_TYPE_RECORDERS |
| 2202 | // For remote submix (a virtual device), we open only one input per capture request. |
| 2203 | if (audio_is_remote_submix_device(inputDesc->mDevice)) { |
| 2204 | String8 address = String8(""); |
| 2205 | if (inputDesc->mPolicyMix == NULL) { |
| 2206 | address = String8("0"); |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2207 | } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 2208 | address = inputDesc->mPolicyMix->mDeviceAddress; |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2209 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2210 | if (address != "") { |
| 2211 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 2212 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2213 | address, "remote-submix"); |
| 2214 | } |
| 2215 | } |
| 2216 | } |
| 2217 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2218 | ALOGV("AudioPolicyManager::startInput() input source = %d", audioSession->inputSource()); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2219 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2220 | audioSession->changeActiveCount(1); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2221 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2222 | mIsInputRequestOnProgress = false; |
| 2223 | #endif |
| 2224 | return NO_ERROR; |
| 2225 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 2226 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2227 | status_t AudioPolicyManagerCustom::stopInput(audio_io_handle_t input, |
| 2228 | audio_session_t session) |
| 2229 | { |
| 2230 | status_t status; |
| 2231 | status = AudioPolicyManager::stopInput(input, session); |
| 2232 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2233 | char propValue[PROPERTY_VALUE_MAX]; |
| 2234 | bool prop_rec_play_enabled = false; |
| 2235 | |
| 2236 | if (property_get("rec.playback.conc.disabled", propValue, NULL)) { |
| 2237 | prop_rec_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2238 | } |
| 2239 | |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 2240 | if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2241 | |
| 2242 | //send update to HAL on record playback concurrency |
| 2243 | AudioParameter param = AudioParameter(); |
| 2244 | param.add(String8("rec_play_conc_on"), String8("false")); |
| 2245 | ALOGD("stopInput() setParameters rec_play_conc is setting to OFF "); |
| 2246 | mpClientInterface->setParameters(0, param.toString()); |
| 2247 | |
| 2248 | //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL |
| 2249 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 2250 | //Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder stop tone) |
| 2251 | if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE) && (i != AUDIO_STREAM_PATCH)) { |
| 2252 | ALOGD(" Invalidate on stopInput for stream :: %d ", i); |
| 2253 | //FIXME see fixme on name change |
| 2254 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | #endif |
| 2259 | return status; |
| 2260 | } |
| 2261 | |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2262 | void AudioPolicyManagerCustom::closeAllInputs() { |
| 2263 | bool patchRemoved = false; |
| 2264 | |
Dhanalakshmi Siddani | bfeca7f | 2015-10-08 15:17:11 +0530 | [diff] [blame] | 2265 | for(size_t input_index = mInputs.size(); input_index > 0; input_index--) { |
| 2266 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index-1); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2267 | ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->getPatchHandle()); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2268 | if (patch_index >= 0) { |
| 2269 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2270 | status_t status; |
| 2271 | status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2272 | mAudioPatches.removeItemsAt(patch_index); |
| 2273 | patchRemoved = true; |
| 2274 | } |
Haynes Mathew George | 2e4655a | 2017-01-05 15:01:53 -0800 | [diff] [blame] | 2275 | mpClientInterface->closeInput(mInputs.keyAt(input_index-1)); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2276 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2277 | mInputs.clear(); |
| 2278 | SoundTrigger::setCaptureState(false); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2279 | nextAudioPortGeneration(); |
| 2280 | |
| 2281 | if (patchRemoved) { |
| 2282 | mpClientInterface->onAudioPatchListUpdate(); |
| 2283 | } |
| 2284 | } |
| 2285 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2286 | AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface) |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 2287 | : AudioPolicyManager(clientInterface), |
| 2288 | mHdmiAudioDisabled(false), |
| 2289 | mHdmiAudioEvent(false), |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 2290 | mPrevPhoneState(0), |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 2291 | mPrevFMVolumeDb(0.0f), |
| 2292 | mFMIsActive(false) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2293 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2294 | |
Satya Krishna Pindiproli | 8f83f10 | 2016-06-21 17:56:14 +0530 | [diff] [blame] | 2295 | #ifdef USE_XML_AUDIO_POLICY_CONF |
| 2296 | ALOGD("USE_XML_AUDIO_POLICY_CONF is TRUE"); |
| 2297 | #else |
| 2298 | ALOGD("USE_XML_AUDIO_POLICY_CONF is FALSE"); |
| 2299 | #endif |
| 2300 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2301 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2302 | mIsInputRequestOnProgress = false; |
| 2303 | #endif |
| 2304 | |
| 2305 | |
| 2306 | #ifdef VOICE_CONCURRENCY |
| 2307 | mFallBackflag = getFallBackPath(); |
| 2308 | #endif |
| 2309 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 2310 | } |