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); |
Garmond Leung | 20e9ad5 | 2017-02-03 10:28:32 -0800 | [diff] [blame] | 685 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 686 | device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache); |
Garmond Leung | 20e9ad5 | 2017-02-03 10:28:32 -0800 | [diff] [blame] | 687 | } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 688 | device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache); |
| 689 | } else if (isStrategyActive(outputDesc, STRATEGY_ACCESSIBILITY)) { |
| 690 | device = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, fromCache); |
| 691 | } else if (isStrategyActive(outputDesc, STRATEGY_MEDIA)) { |
| 692 | device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache); |
| 693 | } else if (isStrategyActive(outputDesc, STRATEGY_DTMF)) { |
| 694 | device = getDeviceForStrategy(STRATEGY_DTMF, fromCache); |
| 695 | } else if (isStrategyActive(outputDesc, STRATEGY_TRANSMITTED_THROUGH_SPEAKER)) { |
| 696 | device = getDeviceForStrategy(STRATEGY_TRANSMITTED_THROUGH_SPEAKER, fromCache); |
| 697 | } else if (isStrategyActive(outputDesc, STRATEGY_REROUTING)) { |
| 698 | device = getDeviceForStrategy(STRATEGY_REROUTING, fromCache); |
| 699 | } |
| 700 | |
| 701 | ALOGV("getNewOutputDevice() selected device %x", device); |
| 702 | return device; |
| 703 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 704 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 705 | void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) |
| 706 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 707 | ALOGD("setPhoneState() state %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 708 | // store previous phone state for management of sonification strategy below |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 709 | audio_devices_t newDevice = AUDIO_DEVICE_NONE; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 710 | int oldState = mEngine->getPhoneState(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 711 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 712 | if (mEngine->setPhoneState(state) != NO_ERROR) { |
| 713 | ALOGW("setPhoneState() invalid or same state %d", state); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 714 | return; |
| 715 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 716 | /// 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] | 717 | // if leaving call state, handle special case of active streams |
| 718 | // pertaining to sonification strategy see handleIncallSonification() |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 719 | if (isStateInCall(oldState)) { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 720 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 721 | for (size_t j = 0; j < mOutputs.size(); j++) { |
| 722 | audio_io_handle_t curOutput = mOutputs.keyAt(j); |
| 723 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
| 724 | if (stream == AUDIO_STREAM_PATCH) { |
| 725 | continue; |
| 726 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 727 | handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 728 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 729 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 730 | |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 731 | // force reevaluating accessibility routing when call stops |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 732 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 735 | /** |
| 736 | * Switching to or from incall state or switching between telephony and VoIP lead to force |
| 737 | * routing command. |
| 738 | */ |
| 739 | bool force = ((is_state_in_call(oldState) != is_state_in_call(state)) |
| 740 | || (is_state_in_call(state) && (state != oldState))); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 741 | |
| 742 | // check for device and output changes triggered by new phone state |
| 743 | checkA2dpSuspend(); |
| 744 | checkOutputForAllStrategies(); |
| 745 | updateDevicesAndOutputs(); |
| 746 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 747 | sp<SwAudioOutputDescriptor> hwOutputDesc = mPrimaryOutput; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 748 | #ifdef VOICE_CONCURRENCY |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 749 | char propValue[PROPERTY_VALUE_MAX]; |
| 750 | 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] | 751 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 752 | if(property_get("voice.playback.conc.disabled", propValue, NULL)) { |
| 753 | prop_playback_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 754 | } |
| 755 | |
| 756 | if(property_get("voice.record.conc.disabled", propValue, NULL)) { |
| 757 | prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 758 | } |
| 759 | |
| 760 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 761 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 762 | } |
| 763 | |
Dhananjay Kumar | 9125b2a | 2015-12-01 16:24:09 +0530 | [diff] [blame] | 764 | if ((AUDIO_MODE_IN_CALL != oldState) && (AUDIO_MODE_IN_CALL == state)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 765 | ALOGD("voice_conc:Entering to call mode oldState :: %d state::%d ", |
| 766 | oldState, state); |
Dhananjay Kumar | 9125b2a | 2015-12-01 16:24:09 +0530 | [diff] [blame] | 767 | mvoice_call_state = state; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 768 | if (prop_rec_enabled) { |
| 769 | //Close all active inputs |
| 770 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 771 | if (activeInput != 0) { |
| 772 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 773 | switch(activeDesc->mInputSource) { |
| 774 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 775 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 776 | case AUDIO_SOURCE_VOICE_CALL: |
| 777 | ALOGD("voice_conc:FOUND active input during call active: %d",activeDesc->mInputSource); |
| 778 | break; |
| 779 | |
| 780 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 781 | if(prop_voip_enabled) { |
| 782 | ALOGD("voice_conc:CLOSING VoIP input source on call setup :%d ",activeDesc->mInputSource); |
| 783 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 784 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 785 | } |
| 786 | break; |
| 787 | |
| 788 | default: |
| 789 | ALOGD("voice_conc:CLOSING input on call setup for inputSource: %d",activeDesc->mInputSource); |
| 790 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 791 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } else if (prop_voip_enabled) { |
| 796 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 797 | if (activeInput != 0) { |
| 798 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 799 | if (AUDIO_SOURCE_VOICE_COMMUNICATION == activeDesc->mInputSource) { |
| 800 | ALOGD("voice_conc:CLOSING VoIP on call setup : %d",activeDesc->mInputSource); |
| 801 | stopInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 802 | releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | if (prop_playback_enabled) { |
| 807 | // Move tracks associated to this strategy from previous output to new output |
| 808 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 809 | ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i); |
| 810 | if (i == AUDIO_STREAM_PATCH) { |
| 811 | ALOGV("voice_conc:not calling invalidate for AUDIO_STREAM_PATCH"); |
| 812 | continue; |
| 813 | } |
| 814 | if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
| 815 | if ((AUDIO_STREAM_MUSIC == i) || |
| 816 | (AUDIO_STREAM_VOICE_CALL == i) ) { |
| 817 | ALOGD("voice_conc:Invalidate stream type %d", i); |
| 818 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 819 | } |
| 820 | } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 821 | ALOGD("voice_conc:Invalidate stream type %d", i); |
| 822 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 828 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 829 | if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 830 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 831 | continue; |
| 832 | } |
| 833 | |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 834 | bool isFastFallBackNeeded = |
| 835 | ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & outputDesc->mProfile->mFlags); |
| 836 | |
| 837 | if ((AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) && isFastFallBackNeeded) { |
| 838 | if (((!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY)) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 839 | && prop_playback_enabled) { |
| 840 | ALOGD("voice_conc:calling suspendOutput on call mode for primary output"); |
| 841 | mpClientInterface->suspendOutput(mOutputs.keyAt(i)); |
| 842 | } //Close compress all sessions |
| 843 | else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) |
| 844 | && prop_playback_enabled) { |
| 845 | ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output"); |
| 846 | closeOutput(mOutputs.keyAt(i)); |
| 847 | } |
| 848 | else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) |
| 849 | && prop_voip_enabled) { |
| 850 | ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output"); |
| 851 | closeOutput(mOutputs.keyAt(i)); |
| 852 | } |
| 853 | } else if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
kunleiz | 0b55ec7 | 2016-11-10 16:23:58 +0800 | [diff] [blame] | 854 | if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) { |
| 855 | if (prop_voip_enabled) { |
| 856 | ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output"); |
| 857 | closeOutput(mOutputs.keyAt(i)); |
| 858 | } |
| 859 | } |
| 860 | else if (prop_playback_enabled |
| 861 | && (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 862 | ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output"); |
| 863 | closeOutput(mOutputs.keyAt(i)); |
| 864 | } |
| 865 | } |
| 866 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 867 | // If effects where present on any of the above closed outputs, |
| 868 | // audioflinger moved them to the primary output by default |
| 869 | // move them back to the appropriate output. |
| 870 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | if ((AUDIO_MODE_IN_CALL == oldState || AUDIO_MODE_IN_COMMUNICATION == oldState) && |
| 874 | (AUDIO_MODE_NORMAL == state) && prop_playback_enabled && mvoice_call_state) { |
| 875 | ALOGD("voice_conc:EXITING from call mode oldState :: %d state::%d \n",oldState, state); |
| 876 | mvoice_call_state = 0; |
| 877 | if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 878 | //restore PCM (deep-buffer) output after call termination |
| 879 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 880 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 881 | if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 882 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 883 | continue; |
| 884 | } |
| 885 | if (!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 886 | ALOGD("voice_conc:calling restoreOutput after call mode for primary output"); |
| 887 | mpClientInterface->restoreOutput(mOutputs.keyAt(i)); |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL |
| 892 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 893 | ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i); |
| 894 | if (i == AUDIO_STREAM_PATCH) { |
| 895 | ALOGV("voice_conc:not calling invalidate for AUDIO_STREAM_PATCH"); |
| 896 | continue; |
| 897 | } |
| 898 | if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) { |
| 899 | if ((AUDIO_STREAM_MUSIC == i) || |
| 900 | (AUDIO_STREAM_VOICE_CALL == i) ) { |
| 901 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 902 | } |
| 903 | } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) { |
| 904 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | #endif |
Preetam Singh Ranawat | 96afc16 | 2016-08-25 14:35:02 +0530 | [diff] [blame] | 910 | |
| 911 | sp<SwAudioOutputDescriptor> outputDesc = NULL; |
| 912 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 913 | outputDesc = mOutputs.valueAt(i); |
| 914 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 915 | ALOGD("voice_conc:ouput desc / profile is NULL"); |
| 916 | continue; |
| 917 | } |
| 918 | |
| 919 | if (property_get_bool("voice.dsd.playback.conc.disabled", true) && |
| 920 | (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 921 | (outputDesc->mFormat == AUDIO_FORMAT_DSD)) { |
| 922 | ALOGD("voice_conc:calling closeOutput on call mode for DSD COMPRESS output"); |
| 923 | closeOutput(mOutputs.keyAt(i)); |
| 924 | // call invalidate for music, so that DSD compress will fallback to deep-buffer. |
| 925 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 926 | } |
| 927 | |
| 928 | } |
| 929 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 930 | #ifdef RECORD_PLAY_CONCURRENCY |
| 931 | char recConcPropValue[PROPERTY_VALUE_MAX]; |
| 932 | bool prop_rec_play_enabled = false; |
| 933 | |
| 934 | if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) { |
| 935 | prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4); |
| 936 | } |
| 937 | if (prop_rec_play_enabled) { |
| 938 | if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) { |
| 939 | ALOGD("phone state changed to MODE_IN_COMM invlaidating music and voice streams"); |
| 940 | // call invalidate for voice streams, so that it can use deepbuffer with VoIP out device from HAL |
| 941 | mpClientInterface->invalidateStream(AUDIO_STREAM_VOICE_CALL); |
| 942 | // call invalidate for music, so that compress will fallback to deep-buffer with VoIP out device |
| 943 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 944 | |
| 945 | // close compress output to make sure session will be closed before timeout(60sec) |
| 946 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 947 | |
| 948 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 949 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 950 | ALOGD("ouput desc / profile is NULL"); |
| 951 | continue; |
| 952 | } |
| 953 | |
| 954 | if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 955 | ALOGD("calling closeOutput on call mode for COMPRESS output"); |
| 956 | closeOutput(mOutputs.keyAt(i)); |
| 957 | } |
| 958 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 959 | // If effects where present on any of the above closed outputs, |
| 960 | // audioflinger moved them to the primary output by default |
| 961 | // move them back to the appropriate output. |
| 962 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 963 | } else if ((oldState == AUDIO_MODE_IN_COMMUNICATION) && |
| 964 | (mEngine->getPhoneState() == AUDIO_MODE_NORMAL)) { |
| 965 | // call invalidate for music so that music can fallback to compress |
| 966 | mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC); |
| 967 | } |
| 968 | } |
| 969 | #endif |
| 970 | mPrevPhoneState = oldState; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 971 | int delayMs = 0; |
| 972 | if (isStateInCall(state)) { |
| 973 | nsecs_t sysTime = systemTime(); |
| 974 | for (size_t i = 0; i < mOutputs.size(); i++) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 975 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 976 | // mute media and sonification strategies and delay device switch by the largest |
| 977 | // latency of any output where either strategy is active. |
| 978 | // 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] | 979 | if ((isStrategyActive(desc, STRATEGY_MEDIA, |
| 980 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 981 | sysTime) || |
| 982 | isStrategyActive(desc, STRATEGY_SONIFICATION, |
| 983 | SONIFICATION_HEADSET_MUSIC_DELAY, |
| 984 | sysTime)) && |
| 985 | (delayMs < (int)desc->latency()*2)) { |
| 986 | delayMs = desc->latency()*2; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 987 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 988 | setStrategyMute(STRATEGY_MEDIA, true, desc); |
| 989 | setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 990 | getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/)); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 991 | setStrategyMute(STRATEGY_SONIFICATION, true, desc); |
| 992 | setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 993 | getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/)); |
| 994 | } |
| 995 | } |
| 996 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 997 | if (hasPrimaryOutput()) { |
| 998 | // Note that despite the fact that getNewOutputDevice() is called on the primary output, |
| 999 | // the device returned is not necessarily reachable via this output |
| 1000 | audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/); |
| 1001 | // force routing command to audio hardware when ending call |
| 1002 | // even if no device change is needed |
| 1003 | if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) { |
| 1004 | rxDevice = mPrimaryOutput->device(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1005 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1006 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1007 | if (state == AUDIO_MODE_IN_CALL) { |
| 1008 | updateCallRouting(rxDevice, delayMs); |
| 1009 | } else if (oldState == AUDIO_MODE_IN_CALL) { |
| 1010 | if (mCallRxPatch != 0) { |
| 1011 | mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0); |
| 1012 | mCallRxPatch.clear(); |
| 1013 | } |
| 1014 | if (mCallTxPatch != 0) { |
| 1015 | mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0); |
| 1016 | mCallTxPatch.clear(); |
| 1017 | } |
| 1018 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
| 1019 | } else { |
| 1020 | setOutputDevice(mPrimaryOutput, rxDevice, force, 0); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1021 | } |
| 1022 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1023 | //update device for all non-primary outputs |
| 1024 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1025 | audio_io_handle_t output = mOutputs.keyAt(i); |
| 1026 | if (output != mPrimaryOutput->mIoHandle) { |
| 1027 | newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/); |
| 1028 | setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE)); |
| 1029 | } |
| 1030 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1031 | // if entering in call state, handle special case of active streams |
| 1032 | // pertaining to sonification strategy see handleIncallSonification() |
| 1033 | if (isStateInCall(state)) { |
| 1034 | ALOGV("setPhoneState() in call state management: new state is %d", state); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1035 | for (size_t j = 0; j < mOutputs.size(); j++) { |
| 1036 | audio_io_handle_t curOutput = mOutputs.keyAt(j); |
| 1037 | for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) { |
| 1038 | if (stream == AUDIO_STREAM_PATCH) { |
| 1039 | continue; |
| 1040 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1041 | handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1042 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1043 | } |
Zhou Song | 58081b6 | 2016-02-24 13:10:55 +0800 | [diff] [blame] | 1044 | |
| 1045 | // force reevaluating accessibility routing when call starts |
| 1046 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE |
| 1050 | if (state == AUDIO_MODE_RINGTONE && |
| 1051 | isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) { |
| 1052 | mLimitRingtoneVolume = true; |
| 1053 | } else { |
| 1054 | mLimitRingtoneVolume = false; |
| 1055 | } |
| 1056 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1057 | |
| 1058 | void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage, |
| 1059 | audio_policy_forced_cfg_t config) |
| 1060 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1061 | ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState()); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1062 | |
| 1063 | if (mEngine->setForceUse(usage, config) != NO_ERROR) { |
| 1064 | ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage); |
| 1065 | return; |
| 1066 | } |
| 1067 | bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) || |
| 1068 | (usage == AUDIO_POLICY_FORCE_FOR_DOCK) || |
| 1069 | (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM); |
| 1070 | |
| 1071 | // check for device and output changes triggered by new force usage |
| 1072 | checkA2dpSuspend(); |
| 1073 | checkOutputForAllStrategies(); |
| 1074 | updateDevicesAndOutputs(); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1075 | |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1076 | /*audio policy: workaround for truncated touch sounds*/ |
| 1077 | //FIXME: workaround for truncated touch sounds |
| 1078 | // to be removed when the problem is handled by system UI |
| 1079 | uint32_t delayMs = 0; |
| 1080 | uint32_t waitMs = 0; |
| 1081 | if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) { |
| 1082 | delayMs = TOUCH_SOUND_FIXED_DELAY_MS; |
| 1083 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1084 | if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { |
| 1085 | audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1086 | waitMs = updateCallRouting(newDevice, delayMs); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1087 | } |
| 1088 | // Use reverse loop to make sure any low latency usecases (generally tones) |
| 1089 | // are not routed before non LL usecases (generally music). |
| 1090 | // We can safely assume that LL output would always have lower index, |
| 1091 | // and use this work-around to avoid routing of output with music stream |
| 1092 | // from the context of short lived LL output. |
| 1093 | // Note: in case output's share backend(HAL sharing is implicit) all outputs |
| 1094 | // gets routing update while processing first output itself. |
| 1095 | for (size_t i = mOutputs.size(); i > 0; i--) { |
| 1096 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1); |
| 1097 | audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1098 | if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) { |
| 1099 | waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE), |
| 1100 | delayMs); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1101 | } |
| 1102 | if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1103 | applyStreamVolumes(outputDesc, newDevice, waitMs, true); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 1108 | if (activeInput != 0) { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1109 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
| 1110 | audio_devices_t newDevice = getNewInputDevice(activeInput); |
| 1111 | // Force new input selection if the new device can not be reached via current input |
| 1112 | if (activeDesc->mProfile->getSupportedDevices().types() & (newDevice & ~AUDIO_DEVICE_BIT_IN)) { |
| 1113 | setInputDevice(activeInput, newDevice); |
| 1114 | } else { |
| 1115 | closeInput(activeInput); |
| 1116 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1117 | } |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 1118 | } |
| 1119 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1120 | status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1121 | audio_stream_type_t stream, |
| 1122 | bool forceDeviceUpdate) |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1123 | { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1124 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1125 | ALOGW("stopSource() invalid stream %d", stream); |
| 1126 | return INVALID_OPERATION; |
| 1127 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1128 | // always handle stream stop, check which stream type is stopping |
| 1129 | handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 1130 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1131 | // handle special case for sonification while in call |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1132 | if (isInCall()) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1133 | if (outputDesc->isDuplicated()) { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1134 | handleIncallSonification(stream, false, false, outputDesc->subOutput1()->mIoHandle); |
| 1135 | handleIncallSonification(stream, false, false, outputDesc->subOutput2()->mIoHandle); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1136 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1137 | handleIncallSonification(stream, false, false, outputDesc->mIoHandle); |
| 1138 | } |
| 1139 | |
| 1140 | if (outputDesc->mRefCount[stream] > 0) { |
| 1141 | // decrement usage count of this stream on the output |
| 1142 | outputDesc->changeRefCount(stream, -1); |
| 1143 | |
| 1144 | // store time at which the stream was stopped - see isStreamActive() |
| 1145 | if (outputDesc->mRefCount[stream] == 0 || forceDeviceUpdate) { |
| 1146 | outputDesc->mStopTime[stream] = systemTime(); |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1147 | audio_devices_t prevDevice = outputDesc->device(); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1148 | audio_devices_t newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/); |
| 1149 | // delay the device switch by twice the latency because stopOutput() is executed when |
| 1150 | // the track stop() command is received and at that time the audio track buffer can |
| 1151 | // still contain data that needs to be drained. The latency only covers the audio HAL |
| 1152 | // and kernel buffers. Also the latency does not always include additional delay in the |
| 1153 | // audio path (audio DSP, CODEC ...) |
| 1154 | setOutputDevice(outputDesc, newDevice, false, outputDesc->latency()*2); |
| 1155 | |
| 1156 | // force restoring the device selection on other active outputs if it differs from the |
| 1157 | // one being selected for this output |
| 1158 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1159 | audio_io_handle_t curOutput = mOutputs.keyAt(i); |
| 1160 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1161 | if (desc != outputDesc && |
| 1162 | desc->isActive() && |
| 1163 | outputDesc->sharesHwModuleWith(desc) && |
| 1164 | (newDevice != desc->device())) { |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1165 | audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/); |
Naresh Tanniru | 1139370 | 2016-09-14 11:25:37 +0530 | [diff] [blame] | 1166 | bool force = desc->device() != dev; |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1167 | uint32_t delayMs; |
| 1168 | if (dev == prevDevice) { |
| 1169 | delayMs = 0; |
| 1170 | } else { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1171 | delayMs = outputDesc->latency()*2; |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1172 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1173 | setOutputDevice(desc, |
| 1174 | dev, |
Naresh Tanniru | 1139370 | 2016-09-14 11:25:37 +0530 | [diff] [blame] | 1175 | force, |
Zhou Song | 5dcddc9 | 2015-09-21 14:36:57 +0800 | [diff] [blame] | 1176 | delayMs); |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1177 | /*audio policy: fix media volume after ringtone*/ |
| 1178 | // re-apply device specific volume if not done by setOutputDevice() |
| 1179 | if (!force) { |
| 1180 | applyStreamVolumes(desc, dev, delayMs); |
| 1181 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | // update the outputs if stopping one with a stream that can affect notification routing |
| 1185 | handleNotificationRoutingForStream(stream); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1186 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1187 | return NO_ERROR; |
| 1188 | } else { |
| 1189 | ALOGW("stopOutput() refcount is already 0"); |
| 1190 | return INVALID_OPERATION; |
| 1191 | } |
| 1192 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1193 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1194 | status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1195 | audio_stream_type_t stream, |
| 1196 | audio_devices_t device, |
Lalit Kansara | f803ac5 | 2016-05-09 19:12:01 +0530 | [diff] [blame] | 1197 | const char *address, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1198 | uint32_t *delayMs) |
| 1199 | { |
| 1200 | // cannot start playback of STREAM_TTS if any other output is being used |
| 1201 | uint32_t beaconMuteLatency = 0; |
| 1202 | |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1203 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1204 | ALOGW("startSource() invalid stream %d", stream); |
| 1205 | return INVALID_OPERATION; |
| 1206 | } |
| 1207 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1208 | *delayMs = 0; |
| 1209 | if (stream == AUDIO_STREAM_TTS) { |
| 1210 | ALOGV("\t found BEACON stream"); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1211 | if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1212 | return INVALID_OPERATION; |
| 1213 | } else { |
| 1214 | beaconMuteLatency = handleEventForBeacon(STARTING_BEACON); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1215 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1216 | } else { |
| 1217 | // some playback other than beacon starts |
| 1218 | beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT); |
| 1219 | } |
| 1220 | |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1221 | // 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] | 1222 | // check active before incrementing usage count |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1223 | bool force = !outputDesc->isActive() && |
| 1224 | (outputDesc->getPatchHandle() == AUDIO_PATCH_HANDLE_NONE); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1225 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1226 | // increment usage count for this stream on the requested output: |
| 1227 | // NOTE that the usage count is the same for duplicated output and hardware output which is |
| 1228 | // necessary for a correct control of hardware output routing by startOutput() and stopOutput() |
| 1229 | outputDesc->changeRefCount(stream, 1); |
| 1230 | |
| 1231 | if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) { |
| 1232 | // starting an output being rerouted? |
| 1233 | if (device == AUDIO_DEVICE_NONE) { |
| 1234 | device = getNewOutputDevice(outputDesc, false /*fromCache*/); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1235 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1236 | routing_strategy strategy = getStrategy(stream); |
| 1237 | bool shouldWait = (strategy == STRATEGY_SONIFICATION) || |
| 1238 | (strategy == STRATEGY_SONIFICATION_RESPECTFUL) || |
| 1239 | (beaconMuteLatency > 0); |
| 1240 | uint32_t waitMs = beaconMuteLatency; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1241 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1242 | sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1243 | if (desc != outputDesc) { |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1244 | // force a device change if any other output is: |
| 1245 | // - managed by the same hw module |
| 1246 | // - has a current device selection that differs from selected device. |
| 1247 | // - supports currently selected device |
| 1248 | // - has an active audio patch |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1249 | // In this case, the audio HAL must receive the new device selection so that it can |
| 1250 | // change the device currently selected by the other active output. |
| 1251 | if (outputDesc->sharesHwModuleWith(desc) && |
Zhou Song | 63f0b85 | 2016-12-20 14:35:06 +0800 | [diff] [blame] | 1252 | desc->device() != device && |
| 1253 | desc->supportedDevices() & device && |
| 1254 | desc->getPatchHandle() != AUDIO_PATCH_HANDLE_NONE) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1255 | force = true; |
| 1256 | } |
| 1257 | // wait for audio on other active outputs to be presented when starting |
| 1258 | // a notification so that audio focus effect can propagate, or that a mute/unmute |
| 1259 | // event occurred for beacon |
| 1260 | uint32_t latency = desc->latency(); |
| 1261 | if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) { |
| 1262 | waitMs = latency; |
| 1263 | } |
| 1264 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1265 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1266 | uint32_t muteWaitMs; |
Lalit Kansara | f803ac5 | 2016-05-09 19:12:01 +0530 | [diff] [blame] | 1267 | muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1268 | |
| 1269 | // handle special case for sonification while in call |
| 1270 | if (isInCall()) { |
| 1271 | handleIncallSonification(stream, true, false, outputDesc->mIoHandle); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1272 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1273 | |
| 1274 | // apply volume rules for current stream and device if necessary |
| 1275 | checkAndSetVolume(stream, |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1276 | mVolumeCurves->getVolumeIndex(stream, device), |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1277 | outputDesc, |
| 1278 | device); |
| 1279 | |
| 1280 | // update the outputs if starting an output with a stream that can affect notification |
| 1281 | // routing |
| 1282 | handleNotificationRoutingForStream(stream); |
| 1283 | |
| 1284 | // force reevaluating accessibility routing when ringtone or alarm starts |
| 1285 | if (strategy == STRATEGY_SONIFICATION) { |
| 1286 | mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); |
| 1287 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 1288 | if (waitMs > muteWaitMs) { |
| 1289 | *delayMs = waitMs - muteWaitMs; |
| 1290 | } |
| 1291 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1292 | } |
| 1293 | else { |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1294 | // handle special case for sonification while in call |
| 1295 | if (isInCall()) { |
| 1296 | handleIncallSonification(stream, true, false, outputDesc->mIoHandle); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1297 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1298 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1299 | return NO_ERROR; |
| 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 | void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream, |
| 1303 | bool starting, bool stateChange, |
| 1304 | audio_io_handle_t output) |
| 1305 | { |
| 1306 | if(!hasPrimaryOutput()) { |
| 1307 | return; |
| 1308 | } |
| 1309 | // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks |
| 1310 | if (stream == AUDIO_STREAM_PATCH) { |
| 1311 | return; |
| 1312 | } |
| 1313 | // if the stream pertains to sonification strategy and we are in call we must |
| 1314 | // mute the stream if it is low visibility. If it is high visibility, we must play a tone |
| 1315 | // in the device used for phone strategy and play the tone if the selected device does not |
| 1316 | // interfere with the device used for phone strategy |
| 1317 | // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as |
| 1318 | // many times as there are active tracks on the output |
| 1319 | const routing_strategy stream_strategy = getStrategy(stream); |
| 1320 | if ((stream_strategy == STRATEGY_SONIFICATION) || |
| 1321 | ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) { |
| 1322 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output); |
| 1323 | ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d", |
| 1324 | stream, starting, outputDesc->mDevice, stateChange); |
| 1325 | if (outputDesc->mRefCount[stream]) { |
| 1326 | int muteCount = 1; |
| 1327 | if (stateChange) { |
| 1328 | muteCount = outputDesc->mRefCount[stream]; |
| 1329 | } |
| 1330 | if (audio_is_low_visibility(stream)) { |
| 1331 | ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount); |
| 1332 | for (int i = 0; i < muteCount; i++) { |
| 1333 | setStreamMute(stream, starting, outputDesc); |
| 1334 | } |
| 1335 | } else { |
| 1336 | ALOGV("handleIncallSonification() high visibility"); |
| 1337 | if (outputDesc->device() & |
| 1338 | getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) { |
| 1339 | ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount); |
| 1340 | for (int i = 0; i < muteCount; i++) { |
| 1341 | setStreamMute(stream, starting, outputDesc); |
| 1342 | } |
| 1343 | } |
| 1344 | if (starting) { |
| 1345 | mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION, |
| 1346 | AUDIO_STREAM_VOICE_CALL); |
| 1347 | } else { |
| 1348 | mpClientInterface->stopTone(); |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1354 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1355 | void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) { |
| 1356 | switch(stream) { |
| 1357 | case AUDIO_STREAM_MUSIC: |
| 1358 | checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL); |
| 1359 | updateDevicesAndOutputs(); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1360 | break; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1361 | default: |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1362 | break; |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 1363 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1364 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1365 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1366 | status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream, |
| 1367 | int index, |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1368 | const sp<AudioOutputDescriptor>& outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1369 | audio_devices_t device, |
| 1370 | int delayMs, bool force) |
| 1371 | { |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 1372 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
| 1373 | ALOGW("checkAndSetVolume() invalid stream %d", stream); |
| 1374 | return INVALID_OPERATION; |
| 1375 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1376 | // do not change actual stream volume if the stream is muted |
| 1377 | if (outputDesc->mMuteCount[stream] != 0) { |
| 1378 | ALOGVV("checkAndSetVolume() stream %d muted count %d", |
| 1379 | stream, outputDesc->mMuteCount[stream]); |
| 1380 | return NO_ERROR; |
| 1381 | } |
| 1382 | audio_policy_forced_cfg_t forceUseForComm = |
| 1383 | mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION); |
| 1384 | // do not change in call volume if bluetooth is connected and vice versa |
| 1385 | if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) || |
| 1386 | (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) { |
| 1387 | ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm", |
| 1388 | stream, forceUseForComm); |
| 1389 | return INVALID_OPERATION; |
| 1390 | } |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1391 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1392 | if (device == AUDIO_DEVICE_NONE) { |
| 1393 | device = outputDesc->device(); |
| 1394 | } |
| 1395 | |
| 1396 | float volumeDb = computeVolume(stream, index, device); |
| 1397 | if (outputDesc->isFixedVolume(device)) { |
| 1398 | volumeDb = 0.0f; |
| 1399 | } |
| 1400 | |
| 1401 | outputDesc->setVolume(volumeDb, stream, device, delayMs, force); |
| 1402 | |
| 1403 | if (stream == AUDIO_STREAM_VOICE_CALL || |
| 1404 | stream == AUDIO_STREAM_BLUETOOTH_SCO) { |
| 1405 | float voiceVolume; |
| 1406 | // Force voice volume to max for bluetooth SCO as volume is managed by the headset |
| 1407 | if (stream == AUDIO_STREAM_VOICE_CALL) { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1408 | voiceVolume = (float)index/(float)mVolumeCurves->getVolumeIndexMax(stream); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1409 | } else { |
| 1410 | voiceVolume = 1.0; |
| 1411 | } |
| 1412 | |
| 1413 | if (voiceVolume != mLastVoiceVolume && ((outputDesc == mPrimaryOutput) || |
| 1414 | isDirectOutput(outputDesc->mIoHandle) || device & AUDIO_DEVICE_OUT_ALL_USB)) { |
| 1415 | mpClientInterface->setVoiceVolume(voiceVolume, delayMs); |
| 1416 | mLastVoiceVolume = voiceVolume; |
| 1417 | } |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 1418 | #ifdef FM_POWER_OPT |
| 1419 | } else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() && |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 1420 | outputDesc == mPrimaryOutput && mFMIsActive) { |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 1421 | /* Avoid unnecessary set_parameter calls as it puts the primary |
| 1422 | outputs FastMixer in HOT_IDLE leading to breaks in audio */ |
| 1423 | if (volumeDb != mPrevFMVolumeDb) { |
| 1424 | mPrevFMVolumeDb = volumeDb; |
| 1425 | AudioParameter param = AudioParameter(); |
| 1426 | param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb)); |
Mingming Yin | 1433cc6 | 2016-01-04 14:58:00 -0800 | [diff] [blame] | 1427 | //Double delayMs to avoid sound burst while device switch. |
| 1428 | mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs*2); |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 1429 | } |
Dhananjay Kumar | 8ccb831 | 2015-10-21 12:36:19 +0530 | [diff] [blame] | 1430 | #endif /* FM_POWER_OPT end */ |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | return NO_ERROR; |
| 1434 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 1435 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1436 | bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) { |
| 1437 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1438 | audio_io_handle_t curOutput = mOutputs.keyAt(i); |
| 1439 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1440 | if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
| 1441 | return true; |
| 1442 | } |
| 1443 | } |
| 1444 | return false; |
| 1445 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1446 | |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1447 | 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] | 1448 | { |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1449 | bool playerDirectPCM = false; // Output request for Track created by mediaplayer |
| 1450 | bool trackDirectPCM = false; // Output request for track created by other apps |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1451 | bool offloadDisabled = property_get_bool("audio.offload.disable", false); |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1452 | |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1453 | // Direct PCM is allowed only if |
| 1454 | // In case of mediaPlayer playback |
| 1455 | // 16 bit direct pcm or 24bit direct PCM property is set and |
| 1456 | // the FLAG requested is DIRECT_PCM ( NuPlayer case) or |
| 1457 | // In case of AudioTracks created by apps |
| 1458 | // track offload is enabled and FLAG requested is FLAG_NONE. |
| 1459 | |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1460 | if (offloadDisabled) { |
| 1461 | ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled); |
| 1462 | } |
| 1463 | |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1464 | if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 1465 | if (bitWidth == 24 || bitWidth == 32) |
| 1466 | playerDirectPCM = |
| 1467 | property_get_bool("audio.offload.pcm.24bit.enable", false); |
| 1468 | else |
| 1469 | playerDirectPCM = |
| 1470 | property_get_bool("audio.offload.pcm.16bit.enable", false); |
| 1471 | // Reset flag to NONE so that we can still reuse direct pcm criteria check |
| 1472 | // in getOutputforDevice |
| 1473 | *flags = AUDIO_OUTPUT_FLAG_NONE; |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1474 | } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) { |
Ashish Jain | 771d02f | 2016-10-27 22:35:46 +0530 | [diff] [blame] | 1475 | trackDirectPCM = property_get_bool("audio.offload.track.enable", true); |
| 1476 | } |
| 1477 | |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1478 | ALOGI("Direct PCM %s for this request", |
| 1479 | (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled"); |
| 1480 | |
| 1481 | return (!offloadDisabled && (trackDirectPCM || playerDirectPCM)); |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1482 | } |
| 1483 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1484 | status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr, |
| 1485 | audio_io_handle_t *output, |
| 1486 | audio_session_t session, |
| 1487 | audio_stream_type_t *stream, |
| 1488 | uid_t uid, |
| 1489 | uint32_t samplingRate, |
| 1490 | audio_format_t format, |
| 1491 | audio_channel_mask_t channelMask, |
| 1492 | audio_output_flags_t flags, |
| 1493 | audio_port_handle_t selectedDeviceId, |
| 1494 | const audio_offload_info_t *offloadInfo) |
| 1495 | { |
| 1496 | audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER; |
| 1497 | |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1498 | uint32_t bitWidth = (audio_bytes_per_sample(format) * 8); |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1499 | |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1500 | |
Sharad Sangle | 7517072 | 2016-11-21 16:21:06 +0530 | [diff] [blame] | 1501 | if (tryForDirectPCM(bitWidth, &flags, samplingRate) && |
Ashish Jain | 2756431 | 2016-11-14 14:58:06 +0530 | [diff] [blame] | 1502 | (offloadInfo == NULL)) { |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1503 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1504 | tOffloadInfo.sample_rate = samplingRate; |
| 1505 | tOffloadInfo.channel_mask = channelMask; |
| 1506 | tOffloadInfo.format = format; |
| 1507 | tOffloadInfo.stream_type = *stream; |
Ashish Jain | ac510a7 | 2016-04-28 12:22:58 +0530 | [diff] [blame] | 1508 | tOffloadInfo.bit_width = bitWidth; |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1509 | if (attr != NULL) { |
| 1510 | ALOGV("found attribute .. setting usage %d ", attr->usage); |
| 1511 | tOffloadInfo.usage = attr->usage; |
| 1512 | } else { |
Alexy Joseph | 0ac0903 | 2015-10-16 15:57:53 -0700 | [diff] [blame] | 1513 | ALOGI("%s:: attribute is NULL .. no usage set", __func__); |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1514 | } |
| 1515 | offloadInfo = &tOffloadInfo; |
| 1516 | } |
| 1517 | |
| 1518 | return AudioPolicyManager::getOutputForAttr(attr, output, session, stream, |
| 1519 | (uid_t)uid, (uint32_t)samplingRate, |
| 1520 | format, (audio_channel_mask_t)channelMask, |
| 1521 | flags, (audio_port_handle_t)selectedDeviceId, |
| 1522 | offloadInfo); |
| 1523 | } |
| 1524 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1525 | audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( |
| 1526 | audio_devices_t device, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1527 | audio_session_t session __unused, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1528 | audio_stream_type_t stream, |
| 1529 | uint32_t samplingRate, |
| 1530 | audio_format_t format, |
| 1531 | audio_channel_mask_t channelMask, |
| 1532 | audio_output_flags_t flags, |
| 1533 | const audio_offload_info_t *offloadInfo) |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 1534 | { |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1535 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1536 | status_t status; |
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 | #ifdef AUDIO_POLICY_TEST |
| 1539 | if (mCurOutput != 0) { |
| 1540 | ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d", |
| 1541 | mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput); |
| 1542 | |
| 1543 | if (mTestOutputs[mCurOutput] == 0) { |
| 1544 | ALOGV("getOutput() opening test output"); |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1545 | sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL, |
| 1546 | mpClientInterface); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1547 | outputDesc->mDevice = mTestDevice; |
| 1548 | outputDesc->mLatency = mTestLatencyMs; |
| 1549 | outputDesc->mFlags = |
| 1550 | (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0); |
| 1551 | outputDesc->mRefCount[stream] = 0; |
| 1552 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 1553 | config.sample_rate = mTestSamplingRate; |
| 1554 | config.channel_mask = mTestChannels; |
| 1555 | config.format = mTestFormat; |
| 1556 | if (offloadInfo != NULL) { |
| 1557 | config.offload_info = *offloadInfo; |
| 1558 | } |
| 1559 | status = mpClientInterface->openOutput(0, |
| 1560 | &mTestOutputs[mCurOutput], |
| 1561 | &config, |
| 1562 | &outputDesc->mDevice, |
| 1563 | String8(""), |
| 1564 | &outputDesc->mLatency, |
| 1565 | outputDesc->mFlags); |
| 1566 | if (status == NO_ERROR) { |
| 1567 | outputDesc->mSamplingRate = config.sample_rate; |
| 1568 | outputDesc->mFormat = config.format; |
| 1569 | outputDesc->mChannelMask = config.channel_mask; |
| 1570 | AudioParameter outputCmd = AudioParameter(); |
| 1571 | outputCmd.addInt(String8("set_id"),mCurOutput); |
| 1572 | mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString()); |
| 1573 | addOutput(mTestOutputs[mCurOutput], outputDesc); |
| 1574 | } |
| 1575 | } |
| 1576 | return mTestOutputs[mCurOutput]; |
| 1577 | } |
| 1578 | #endif //AUDIO_POLICY_TEST |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1579 | if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) && |
| 1580 | (stream != AUDIO_STREAM_MUSIC)) { |
| 1581 | // compress should not be used for non-music streams |
| 1582 | ALOGE("Offloading only allowed with music stream"); |
| 1583 | return 0; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1584 | } |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1585 | |
| 1586 | if ((stream == AUDIO_STREAM_VOICE_CALL) && |
| 1587 | (channelMask == 1) && |
Shiv Maliyappanahalli | d77d3b3 | 2016-02-02 13:45:50 -0800 | [diff] [blame] | 1588 | (samplingRate == 8000 || samplingRate == 16000 || |
| 1589 | samplingRate == 32000 || samplingRate == 48000)) { |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1590 | // Allow Voip direct output only if: |
| 1591 | // audio mode is MODE_IN_COMMUNCATION; AND |
| 1592 | // voip output is not opened already; AND |
| 1593 | // requested sample rate matches with that of voip input stream (if opened already) |
| 1594 | int value = 0; |
| 1595 | uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1; |
Alexy Joseph | 9323d8b | 2017-02-17 10:30:07 -0800 | [diff] [blame] | 1596 | bool is_vr_mode_on = false; |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1597 | String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1598 | String8("audio_mode")); |
| 1599 | AudioParameter result = AudioParameter(valueStr); |
| 1600 | if (result.getInt(String8("audio_mode"), value) == NO_ERROR) { |
| 1601 | mode = value; |
| 1602 | } |
| 1603 | |
| 1604 | valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1605 | String8("voip_out_stream_count")); |
| 1606 | result = AudioParameter(valueStr); |
| 1607 | if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) { |
| 1608 | voipOutCount = value; |
| 1609 | } |
| 1610 | |
| 1611 | valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1612 | String8("voip_sample_rate")); |
| 1613 | result = AudioParameter(valueStr); |
| 1614 | if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) { |
| 1615 | voipSampleRate = value; |
| 1616 | } |
| 1617 | |
| 1618 | if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) && |
| 1619 | ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) { |
| 1620 | if (audio_is_linear_pcm(format)) { |
| 1621 | char propValue[PROPERTY_VALUE_MAX] = {0}; |
| 1622 | property_get("use.voice.path.for.pcm.voip", propValue, "0"); |
| 1623 | bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true")); |
| 1624 | if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) { |
Karthik Reddy Katta | 3fb9be7 | 2015-11-25 11:18:27 +0530 | [diff] [blame] | 1625 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_VOIP_RX | |
| 1626 | AUDIO_OUTPUT_FLAG_DIRECT); |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1627 | ALOGD("Set VoIP and Direct output flags for PCM format"); |
| 1628 | } |
| 1629 | } |
| 1630 | } |
Alexy Joseph | 9323d8b | 2017-02-17 10:30:07 -0800 | [diff] [blame] | 1631 | //IF VOIP is going to be started at the same time as when |
| 1632 | //vr is enabled, get VOIP to fallback to low latency |
| 1633 | String8 vr_value; |
| 1634 | valueStr = mpClientInterface->getParameters((audio_io_handle_t)0, |
| 1635 | String8("vr_audio_mode_on")); |
| 1636 | result = AudioParameter(valueStr); |
| 1637 | if (result.get(String8("vr_audio_mode_on"), vr_value) == NO_ERROR) { |
| 1638 | is_vr_mode_on = vr_value.contains("true"); |
| 1639 | ALOGI("VR mode is %d, switch to primary output if request is for fast|raw", |
| 1640 | is_vr_mode_on); |
| 1641 | } |
| 1642 | |
| 1643 | if (is_vr_mode_on) { |
| 1644 | //check the flags being requested for, and clear FAST|RAW |
| 1645 | flags = (audio_output_flags_t)(flags & |
| 1646 | (~(AUDIO_OUTPUT_FLAG_FAST|AUDIO_OUTPUT_FLAG_RAW))); |
| 1647 | |
| 1648 | } |
| 1649 | |
Karthik Reddy Katta | 7249d66 | 2015-07-14 16:05:18 +0530 | [diff] [blame] | 1650 | } |
| 1651 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1652 | #ifdef VOICE_CONCURRENCY |
| 1653 | char propValue[PROPERTY_VALUE_MAX]; |
| 1654 | bool prop_play_enabled=false, prop_voip_enabled = false; |
| 1655 | |
| 1656 | if(property_get("voice.playback.conc.disabled", propValue, NULL)) { |
| 1657 | prop_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1658 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1659 | |
| 1660 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 1661 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 1662 | } |
| 1663 | |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1664 | bool isDeepBufferFallBackNeeded = |
| 1665 | ((AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags); |
| 1666 | bool isFastFallBackNeeded = |
| 1667 | ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags); |
| 1668 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1669 | if (prop_play_enabled && mvoice_call_state) { |
| 1670 | //check if voice call is active / running in background |
| 1671 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 1672 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) |
| 1673 | && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 1674 | { |
| 1675 | if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1676 | if(prop_voip_enabled) { |
| 1677 | ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x", |
| 1678 | flags ); |
| 1679 | return 0; |
| 1680 | } |
| 1681 | } |
| 1682 | else { |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1683 | if (isFastFallBackNeeded && |
| 1684 | (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1685 | ALOGD("voice_conc:IN call mode adding ULL flags .. flags: %x ", flags ); |
| 1686 | flags = AUDIO_OUTPUT_FLAG_FAST; |
Sidipotu Ashok | 738f19e | 2016-12-07 15:16:01 +0530 | [diff] [blame] | 1687 | } else if (isDeepBufferFallBackNeeded && |
| 1688 | (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1689 | if (AUDIO_STREAM_MUSIC == stream) { |
| 1690 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1691 | ALOGD("voice_conc:IN call mode adding deep-buffer flags %x ", flags ); |
| 1692 | } |
| 1693 | else { |
| 1694 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1695 | ALOGD("voice_conc:IN call mode adding fast flags %x ", flags ); |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | } |
| 1700 | } else if (prop_voip_enabled && mvoice_call_state) { |
| 1701 | //check if voice call is active / running in background |
| 1702 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 1703 | //return only ULL ouput |
| 1704 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 1705 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) |
| 1706 | && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 1707 | { |
| 1708 | if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1709 | ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x", |
| 1710 | flags ); |
| 1711 | return 0; |
| 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | #endif |
| 1716 | #ifdef RECORD_PLAY_CONCURRENCY |
| 1717 | char recConcPropValue[PROPERTY_VALUE_MAX]; |
| 1718 | bool prop_rec_play_enabled = false; |
| 1719 | |
| 1720 | if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) { |
| 1721 | prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4); |
| 1722 | } |
| 1723 | if ((prop_rec_play_enabled) && |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 1724 | ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1725 | if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) { |
| 1726 | if (AUDIO_OUTPUT_FLAG_VOIP_RX & flags) { |
| 1727 | // allow VoIP using voice path |
| 1728 | // Do nothing |
| 1729 | } else if((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) { |
| 1730 | ALOGD("voice_conc:MODE_IN_COMM is setforcing deep buffer output for non ULL... flags: %x", flags); |
| 1731 | // use deep buffer path for all non ULL outputs |
| 1732 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1733 | } |
| 1734 | } else if ((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) { |
| 1735 | ALOGD("voice_conc:Record mode is on forcing deep buffer output for non ULL... flags: %x ", flags); |
| 1736 | // use deep buffer path for all non ULL outputs |
| 1737 | flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1738 | } |
| 1739 | } |
| 1740 | if (prop_rec_play_enabled && |
| 1741 | (stream == AUDIO_STREAM_ENFORCED_AUDIBLE)) { |
| 1742 | ALOGD("Record conc is on forcing ULL output for ENFORCED_AUDIBLE"); |
| 1743 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1744 | } |
| 1745 | #endif |
| 1746 | |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1747 | #ifdef AUDIO_EXTN_AFE_PROXY_ENABLED |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1748 | /* |
| 1749 | * WFD audio routes back to target speaker when starting a ringtone playback. |
| 1750 | * This is because primary output is reused for ringtone, so output device is |
| 1751 | * updated based on SONIFICATION strategy for both ringtone and music playback. |
| 1752 | * The same issue is not seen on remoted_submix HAL based WFD audio because |
| 1753 | * primary output is not reused and a new output is created for ringtone playback. |
| 1754 | * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is |
| 1755 | * a non-music stream playback on WFD, so primary output is not reused for ringtone. |
| 1756 | */ |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1757 | audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types(); |
| 1758 | if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY) |
| 1759 | && (stream != AUDIO_STREAM_MUSIC)) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1760 | 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] | 1761 | //For voip paths |
| 1762 | if(flags & AUDIO_OUTPUT_FLAG_DIRECT) |
| 1763 | flags = AUDIO_OUTPUT_FLAG_DIRECT; |
| 1764 | else //route every thing else to ULL path |
| 1765 | flags = AUDIO_OUTPUT_FLAG_FAST; |
| 1766 | } |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 1767 | #endif |
| 1768 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1769 | // open a direct output if required by specified parameters |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1770 | // 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] | 1771 | // and all common behaviors are driven by checking only the direct flag |
| 1772 | // this should normally be set appropriately in the policy configuration file |
| 1773 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) { |
| 1774 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
| 1775 | } |
| 1776 | if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) { |
| 1777 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT); |
| 1778 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 1779 | |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1780 | bool forced_deep = false; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1781 | // only allow deep buffering for music stream type |
| 1782 | if (stream != AUDIO_STREAM_MUSIC) { |
| 1783 | flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
Sharad Sangle | 497aef8 | 2015-08-03 17:55:48 +0530 | [diff] [blame] | 1784 | } else if (/* stream == AUDIO_STREAM_MUSIC && */ |
| 1785 | flags == AUDIO_OUTPUT_FLAG_NONE && |
| 1786 | property_get_bool("audio.deep_buffer.media", false /* default_value */)) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1787 | forced_deep = true; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1788 | } |
Sharad Sangle | 497aef8 | 2015-08-03 17:55:48 +0530 | [diff] [blame] | 1789 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1790 | if (stream == AUDIO_STREAM_TTS) { |
| 1791 | flags = AUDIO_OUTPUT_FLAG_TTS; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Zhou Song | 2b3d155 | 2016-03-21 17:21:04 +0800 | [diff] [blame] | 1794 | // check if direct output for track offload already exits |
| 1795 | bool is_track_offload_active = false; |
| 1796 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1797 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1798 | if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 1799 | is_track_offload_active = true; |
| 1800 | ALOGD("Track offload already active"); |
| 1801 | break; |
| 1802 | } |
| 1803 | } |
| 1804 | |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1805 | // Do offload magic here |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1806 | if ((flags == AUDIO_OUTPUT_FLAG_NONE) && |
| 1807 | (stream == AUDIO_STREAM_MUSIC) && |
Zhou Song | 2b3d155 | 2016-03-21 17:21:04 +0800 | [diff] [blame] | 1808 | (offloadInfo != NULL) && !is_track_offload_active && |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1809 | ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1810 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM); |
vivek mehta | 4b0d819 | 2015-10-16 00:25:59 -0700 | [diff] [blame] | 1811 | ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 1812 | } |
| 1813 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1814 | sp<IOProfile> profile; |
| 1815 | |
| 1816 | // skip direct output selection if the request can obviously be attached to a mixed output |
| 1817 | // and not explicitly requested |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1818 | if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1819 | audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX && |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1820 | audio_channel_count_from_out_mask(channelMask) <= 2) { |
| 1821 | goto non_direct_output; |
| 1822 | } |
| 1823 | |
| 1824 | // Do not allow offloading if one non offloadable effect is enabled. This prevents from |
| 1825 | // creating an offloaded track and tearing it down immediately after start when audioflinger |
| 1826 | // detects there is an active non offloadable effect. |
| 1827 | // FIXME: We should check the audio session here but we do not have it in this context. |
| 1828 | // This may prevent offloading in rare situations where effects are left active by apps |
| 1829 | // in the background. |
Weiyin Jiang | 6bba320 | 2016-03-03 14:49:36 +0800 | [diff] [blame] | 1830 | // |
| 1831 | // Supplementary annotation: |
| 1832 | // For sake of track offload introduced, we need a rollback for both compress offload |
| 1833 | // and track offload use cases. |
| 1834 | if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) && |
| 1835 | (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) { |
| 1836 | ALOGD("non offloadable effect is enabled, try with non direct output"); |
| 1837 | goto non_direct_output; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Weiyin Jiang | 6bba320 | 2016-03-03 14:49:36 +0800 | [diff] [blame] | 1840 | profile = getProfileForDirectOutput(device, |
| 1841 | samplingRate, |
| 1842 | format, |
| 1843 | channelMask, |
| 1844 | (audio_output_flags_t)flags); |
| 1845 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1846 | if (profile != 0) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1847 | |
| 1848 | if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1849 | (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) { |
vivek mehta | c984b99 | 2015-11-25 13:28:55 -0800 | [diff] [blame] | 1850 | ALOGI("got Direct_PCM without requesting ... reject "); |
| 1851 | profile = NULL; |
| 1852 | goto non_direct_output; |
| 1853 | } |
| 1854 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1855 | sp<SwAudioOutputDescriptor> outputDesc = NULL; |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1856 | |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1857 | // if multiple concurrent offload decode is supported |
| 1858 | // do no check for reuse and also don't close previous output if its offload |
| 1859 | // previous output will be closed during track destruction |
| 1860 | if (!(property_get_bool("audio.offload.multiple.enabled", false) && |
| 1861 | ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) { |
| 1862 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 1863 | sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i); |
| 1864 | if (!desc->isDuplicated() && (profile == desc->mProfile)) { |
| 1865 | outputDesc = desc; |
| 1866 | // reuse direct output if currently open and configured with same parameters |
| 1867 | if ((samplingRate == outputDesc->mSamplingRate) && |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1868 | audio_formats_match(format, outputDesc->mFormat) && |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1869 | (channelMask == outputDesc->mChannelMask)) { |
| 1870 | outputDesc->mDirectOpenCount++; |
| 1871 | ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i)); |
| 1872 | return mOutputs.keyAt(i); |
| 1873 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1874 | } |
| 1875 | } |
Mingming Yin | 4a4a8c8 | 2015-10-21 11:05:08 -0700 | [diff] [blame] | 1876 | // close direct output if currently open and configured with different parameters |
| 1877 | if (outputDesc != NULL) { |
| 1878 | closeOutput(outputDesc->mIoHandle); |
| 1879 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1880 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1881 | |
| 1882 | // if the selected profile is offloaded and no offload info was specified, |
| 1883 | // create a default one |
| 1884 | audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER; |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1885 | if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1886 | flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD); |
| 1887 | defaultOffloadInfo.sample_rate = samplingRate; |
| 1888 | defaultOffloadInfo.channel_mask = channelMask; |
| 1889 | defaultOffloadInfo.format = format; |
| 1890 | defaultOffloadInfo.stream_type = stream; |
| 1891 | defaultOffloadInfo.bit_rate = 0; |
| 1892 | defaultOffloadInfo.duration_us = -1; |
| 1893 | defaultOffloadInfo.has_video = true; // conservative |
| 1894 | defaultOffloadInfo.is_streaming = true; // likely |
| 1895 | offloadInfo = &defaultOffloadInfo; |
| 1896 | } |
| 1897 | |
| 1898 | outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1899 | outputDesc->mDevice = device; |
| 1900 | outputDesc->mLatency = 0; |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1901 | outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1902 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 1903 | config.sample_rate = samplingRate; |
| 1904 | config.channel_mask = channelMask; |
| 1905 | config.format = format; |
| 1906 | if (offloadInfo != NULL) { |
| 1907 | config.offload_info = *offloadInfo; |
| 1908 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1909 | status = mpClientInterface->openOutput(profile->getModuleHandle(), |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1910 | &output, |
| 1911 | &config, |
| 1912 | &outputDesc->mDevice, |
| 1913 | String8(""), |
| 1914 | &outputDesc->mLatency, |
| 1915 | outputDesc->mFlags); |
| 1916 | |
| 1917 | // only accept an output with the requested parameters |
| 1918 | if (status != NO_ERROR || |
| 1919 | (samplingRate != 0 && samplingRate != config.sample_rate) || |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 1920 | (format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) || |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1921 | (channelMask != 0 && channelMask != config.channel_mask)) { |
| 1922 | ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d," |
| 1923 | "format %d %d, channelMask %04x %04x", output, samplingRate, |
| 1924 | outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask, |
| 1925 | outputDesc->mChannelMask); |
| 1926 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 1927 | mpClientInterface->closeOutput(output); |
| 1928 | } |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1929 | // 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] | 1930 | if (audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX) { |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 1931 | goto non_direct_output; |
| 1932 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1933 | return AUDIO_IO_HANDLE_NONE; |
| 1934 | } |
| 1935 | outputDesc->mSamplingRate = config.sample_rate; |
| 1936 | outputDesc->mChannelMask = config.channel_mask; |
| 1937 | outputDesc->mFormat = config.format; |
| 1938 | outputDesc->mRefCount[stream] = 0; |
| 1939 | outputDesc->mStopTime[stream] = 0; |
| 1940 | outputDesc->mDirectOpenCount = 1; |
| 1941 | |
| 1942 | audio_io_handle_t srcOutput = getOutputForEffect(); |
| 1943 | addOutput(output, outputDesc); |
| 1944 | audio_io_handle_t dstOutput = getOutputForEffect(); |
| 1945 | if (dstOutput == output) { |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 1946 | #ifdef DOLBY_ENABLE |
| 1947 | status_t status = mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput); |
| 1948 | if (status == NO_ERROR) { |
| 1949 | for (size_t i = 0; i < mEffects.size(); i++) { |
| 1950 | sp<EffectDescriptor> desc = mEffects.valueAt(i); |
| 1951 | if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) { |
| 1952 | // update the mIo member of EffectDescriptor for the global effect |
| 1953 | ALOGV("%s updating mIo", __FUNCTION__); |
| 1954 | desc->mIo = dstOutput; |
| 1955 | } |
| 1956 | } |
| 1957 | } else { |
| 1958 | ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, srcOutput, dstOutput); |
| 1959 | } |
| 1960 | #else // DOLBY_END |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1961 | mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput); |
Gao Jie | db05783 | 2015-11-12 08:51:22 +0800 | [diff] [blame] | 1962 | #endif // LINE_ADDED_BY_DOLBY |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1963 | } |
| 1964 | mPreviousOutputs = mOutputs; |
| 1965 | ALOGV("getOutput() returns new direct output %d", output); |
| 1966 | mpClientInterface->onAudioPortListUpdate(); |
| 1967 | return output; |
| 1968 | } |
| 1969 | |
| 1970 | non_direct_output: |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 1971 | |
| 1972 | // A request for HW A/V sync cannot fallback to a mixed output because time |
| 1973 | // stamps are embedded in audio data |
| 1974 | if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) { |
| 1975 | return AUDIO_IO_HANDLE_NONE; |
| 1976 | } |
| 1977 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 1978 | // ignoring channel mask due to downmix capability in mixer |
| 1979 | |
| 1980 | // open a non direct output |
| 1981 | |
| 1982 | // for non direct outputs, only PCM is supported |
| 1983 | if (audio_is_linear_pcm(format)) { |
| 1984 | // get which output is suitable for the specified stream. The actual |
| 1985 | // routing change will happen when startOutput() will be called |
| 1986 | SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs); |
| 1987 | |
| 1988 | // at this stage we should ignore the DIRECT flag as no direct output could be found earlier |
| 1989 | flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT); |
Ashish Jain | 660d311 | 2016-06-20 10:16:51 +0530 | [diff] [blame] | 1990 | |
| 1991 | if (forced_deep) { |
| 1992 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
| 1993 | ALOGI("setting force DEEP buffer now "); |
| 1994 | } else if(flags == AUDIO_OUTPUT_FLAG_NONE) { |
| 1995 | // no deep buffer playback is requested hence fallback to primary |
| 1996 | flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_PRIMARY); |
| 1997 | ALOGI("FLAG None hence request for a primary output"); |
| 1998 | } |
| 1999 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 2000 | output = selectOutput(outputs, flags, format); |
| 2001 | } |
| 2002 | ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d," |
| 2003 | "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags); |
| 2004 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 2005 | ALOGV("getOutputForDevice() returns output %d", output); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 2006 | |
| 2007 | return output; |
| 2008 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2009 | |
| 2010 | status_t AudioPolicyManagerCustom::getInputForAttr(const audio_attributes_t *attr, |
| 2011 | audio_io_handle_t *input, |
| 2012 | audio_session_t session, |
| 2013 | uid_t uid, |
| 2014 | uint32_t samplingRate, |
| 2015 | audio_format_t format, |
| 2016 | audio_channel_mask_t channelMask, |
| 2017 | audio_input_flags_t flags, |
| 2018 | audio_port_handle_t selectedDeviceId, |
| 2019 | input_type_t *inputType) |
| 2020 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2021 | audio_source_t inputSource; |
| 2022 | inputSource = attr->source; |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2023 | #ifdef VOICE_CONCURRENCY |
| 2024 | |
| 2025 | char propValue[PROPERTY_VALUE_MAX]; |
| 2026 | bool prop_rec_enabled=false, prop_voip_enabled = false; |
| 2027 | |
| 2028 | if(property_get("voice.record.conc.disabled", propValue, NULL)) { |
| 2029 | prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2030 | } |
| 2031 | |
| 2032 | if(property_get("voice.voip.conc.disabled", propValue, NULL)) { |
| 2033 | prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2034 | } |
| 2035 | |
| 2036 | if (prop_rec_enabled && mvoice_call_state) { |
| 2037 | //check if voice call is active / running in background |
| 2038 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 2039 | //Need to block input request |
| 2040 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 2041 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) && |
| 2042 | (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 2043 | { |
| 2044 | switch(inputSource) { |
| 2045 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 2046 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 2047 | case AUDIO_SOURCE_VOICE_CALL: |
| 2048 | ALOGD("voice_conc:Creating input during incall mode for inputSource: %d", |
| 2049 | inputSource); |
| 2050 | break; |
| 2051 | |
| 2052 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 2053 | if(prop_voip_enabled) { |
| 2054 | ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d", |
| 2055 | inputSource); |
| 2056 | return NO_INIT; |
| 2057 | } |
| 2058 | break; |
| 2059 | default: |
| 2060 | ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d", |
| 2061 | inputSource); |
| 2062 | return NO_INIT; |
| 2063 | } |
| 2064 | } |
| 2065 | }//check for VoIP flag |
| 2066 | else if(prop_voip_enabled && mvoice_call_state) { |
| 2067 | //check if voice call is active / running in background |
| 2068 | //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress |
| 2069 | //Need to block input request |
| 2070 | if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) || |
| 2071 | ((AUDIO_MODE_IN_CALL == mPrevPhoneState) && |
| 2072 | (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()))) |
| 2073 | { |
| 2074 | if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 2075 | ALOGD("BLOCKING VoIP request during incall mode for inputSource: %d ",inputSource); |
| 2076 | return NO_INIT; |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | #endif |
| 2082 | |
| 2083 | return AudioPolicyManager::getInputForAttr(attr, |
| 2084 | input, |
| 2085 | session, |
| 2086 | uid, |
| 2087 | samplingRate, |
| 2088 | format, |
| 2089 | channelMask, |
| 2090 | flags, |
| 2091 | selectedDeviceId, |
| 2092 | inputType); |
| 2093 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 2094 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2095 | status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input, |
| 2096 | audio_session_t session) |
| 2097 | { |
| 2098 | ALOGV("startInput() input %d", input); |
| 2099 | ssize_t index = mInputs.indexOfKey(input); |
| 2100 | if (index < 0) { |
| 2101 | ALOGW("startInput() unknown input %d", input); |
| 2102 | return BAD_VALUE; |
| 2103 | } |
| 2104 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index); |
| 2105 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2106 | sp<AudioSession> audioSession = inputDesc->getAudioSession(session); |
| 2107 | if (audioSession == 0) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2108 | ALOGW("startInput() unknown session %d on input %d", session, input); |
| 2109 | return BAD_VALUE; |
| 2110 | } |
| 2111 | |
| 2112 | // virtual input devices are compatible with other input devices |
| 2113 | if (!is_virtual_input_device(inputDesc->mDevice)) { |
| 2114 | |
| 2115 | // for a non-virtual input device, check if there is another (non-virtual) active input |
| 2116 | audio_io_handle_t activeInput = mInputs.getActiveInput(); |
| 2117 | if (activeInput != 0 && activeInput != input) { |
| 2118 | |
| 2119 | // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed, |
| 2120 | // otherwise the active input continues and the new input cannot be started. |
| 2121 | sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2122 | if ((activeDesc->inputSource() == AUDIO_SOURCE_HOTWORD) && |
| 2123 | !activeDesc->hasPreemptedSession(session)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2124 | ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2125 | //FIXME: consider all active sessions |
| 2126 | AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions(); |
| 2127 | audio_session_t activeSession = activeSessions.keyAt(0); |
| 2128 | SortedVector<audio_session_t> sessions = |
| 2129 | activeDesc->getPreemptedSessions(); |
| 2130 | sessions.add(activeSession); |
| 2131 | inputDesc->setPreemptedSessions(sessions); |
| 2132 | stopInput(activeInput, activeSession); |
| 2133 | releaseInput(activeInput, activeSession); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2134 | } else { |
| 2135 | ALOGE("startInput(%d) failed: other input %d already started", input, activeInput); |
| 2136 | return INVALID_OPERATION; |
| 2137 | } |
| 2138 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2139 | // Do not allow capture if an active voice call is using a software patch and |
| 2140 | // the call TX source device is on the same HW module. |
| 2141 | // FIXME: would be better to refine to only inputs whose profile connects to the |
| 2142 | // call TX device but this information is not in the audio patch |
| 2143 | if (mCallTxPatch != 0 && |
| 2144 | inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) { |
| 2145 | return INVALID_OPERATION; |
| 2146 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | // Routing? |
| 2150 | mInputRoutes.incRouteActivity(session); |
| 2151 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2152 | mIsInputRequestOnProgress = true; |
| 2153 | |
| 2154 | char getPropValue[PROPERTY_VALUE_MAX]; |
| 2155 | bool prop_rec_play_enabled = false; |
| 2156 | |
| 2157 | if (property_get("rec.playback.conc.disabled", getPropValue, NULL)) { |
| 2158 | prop_rec_play_enabled = atoi(getPropValue) || !strncmp("true", getPropValue, 4); |
| 2159 | } |
| 2160 | |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 2161 | if ((prop_rec_play_enabled) &&(mInputs.activeInputsCountOnDevices() == 0)){ |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2162 | // send update to HAL on record playback concurrency |
| 2163 | AudioParameter param = AudioParameter(); |
| 2164 | param.add(String8("rec_play_conc_on"), String8("true")); |
| 2165 | ALOGD("startInput() setParameters rec_play_conc is setting to ON "); |
| 2166 | mpClientInterface->setParameters(0, param.toString()); |
| 2167 | |
| 2168 | // Call invalidate to reset all opened non ULL audio tracks |
| 2169 | // Move tracks associated to this strategy from previous output to new output |
| 2170 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 2171 | // 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] | 2172 | if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH))) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2173 | ALOGD("Invalidate on releaseInput for stream :: %d ", i); |
| 2174 | //FIXME see fixme on name change |
| 2175 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 2176 | } |
| 2177 | } |
| 2178 | // close compress tracks |
| 2179 | for (size_t i = 0; i < mOutputs.size(); i++) { |
| 2180 | sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); |
| 2181 | if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) { |
| 2182 | ALOGD("ouput desc / profile is NULL"); |
| 2183 | continue; |
| 2184 | } |
| 2185 | if (outputDesc->mProfile->mFlags |
| 2186 | & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 2187 | // close compress sessions |
| 2188 | ALOGD("calling closeOutput on record conc for COMPRESS output"); |
| 2189 | closeOutput(mOutputs.keyAt(i)); |
| 2190 | } |
| 2191 | } |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 2192 | // If effects where present on any of the above closed outputs, |
| 2193 | // audioflinger moved them to the primary output by default |
| 2194 | // move them back to the appropriate output. |
| 2195 | moveGlobalEffect(); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2196 | } |
| 2197 | #endif |
| 2198 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2199 | if (!inputDesc->isActive() || mInputRoutes.hasRouteChanged(session)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2200 | // 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] | 2201 | if ((inputDesc->mPolicyMix != NULL) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2202 | && ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) { |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 2203 | mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress, |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2204 | MIX_STATE_MIXING); |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2205 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 2206 | /*audio policy: fix capture indication to sound trigger service*/ |
| 2207 | // indicate active capture to sound trigger service if starting capture from a mic on |
| 2208 | // primary HW module |
| 2209 | audio_devices_t device = getNewInputDevice(input); |
| 2210 | audio_devices_t primaryInputDevices = availablePrimaryInputDevices(); |
| 2211 | if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) && |
| 2212 | mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2213 | SoundTrigger::setCaptureState(true); |
| 2214 | } |
Sharad Sangle | c66b9ca | 2016-12-21 18:40:54 +0530 | [diff] [blame] | 2215 | setInputDevice(input, device, true /* force */); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2216 | |
| 2217 | // automatically enable the remote submix output when input is started if not |
| 2218 | // used by a policy mix of type MIX_TYPE_RECORDERS |
| 2219 | // For remote submix (a virtual device), we open only one input per capture request. |
| 2220 | if (audio_is_remote_submix_device(inputDesc->mDevice)) { |
| 2221 | String8 address = String8(""); |
| 2222 | if (inputDesc->mPolicyMix == NULL) { |
| 2223 | address = String8("0"); |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2224 | } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { |
Ashish Jain | 5fe1241 | 2016-04-18 18:44:17 +0530 | [diff] [blame] | 2225 | address = inputDesc->mPolicyMix->mDeviceAddress; |
Ashish Jain | 630c5e1 | 2016-04-18 11:50:21 +0530 | [diff] [blame] | 2226 | } |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2227 | if (address != "") { |
| 2228 | setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 2229 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2230 | address, "remote-submix"); |
| 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2235 | ALOGV("AudioPolicyManager::startInput() input source = %d", audioSession->inputSource()); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2236 | |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2237 | audioSession->changeActiveCount(1); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2238 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2239 | mIsInputRequestOnProgress = false; |
| 2240 | #endif |
| 2241 | return NO_ERROR; |
| 2242 | } |
Weiyin Jiang | d211ef5 | 2016-02-16 15:55:11 +0800 | [diff] [blame] | 2243 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2244 | status_t AudioPolicyManagerCustom::stopInput(audio_io_handle_t input, |
| 2245 | audio_session_t session) |
| 2246 | { |
| 2247 | status_t status; |
| 2248 | status = AudioPolicyManager::stopInput(input, session); |
| 2249 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2250 | char propValue[PROPERTY_VALUE_MAX]; |
| 2251 | bool prop_rec_play_enabled = false; |
| 2252 | |
| 2253 | if (property_get("rec.playback.conc.disabled", propValue, NULL)) { |
| 2254 | prop_rec_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4); |
| 2255 | } |
| 2256 | |
Lalit Kansara | 3391809 | 2016-12-06 22:42:26 +0530 | [diff] [blame] | 2257 | if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)) { |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2258 | |
| 2259 | //send update to HAL on record playback concurrency |
| 2260 | AudioParameter param = AudioParameter(); |
| 2261 | param.add(String8("rec_play_conc_on"), String8("false")); |
| 2262 | ALOGD("stopInput() setParameters rec_play_conc is setting to OFF "); |
| 2263 | mpClientInterface->setParameters(0, param.toString()); |
| 2264 | |
| 2265 | //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL |
| 2266 | for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) { |
| 2267 | //Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder stop tone) |
| 2268 | if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE) && (i != AUDIO_STREAM_PATCH)) { |
| 2269 | ALOGD(" Invalidate on stopInput for stream :: %d ", i); |
| 2270 | //FIXME see fixme on name change |
| 2271 | mpClientInterface->invalidateStream((audio_stream_type_t)i); |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | #endif |
| 2276 | return status; |
| 2277 | } |
| 2278 | |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2279 | void AudioPolicyManagerCustom::closeAllInputs() { |
| 2280 | bool patchRemoved = false; |
| 2281 | |
Dhanalakshmi Siddani | bfeca7f | 2015-10-08 15:17:11 +0530 | [diff] [blame] | 2282 | for(size_t input_index = mInputs.size(); input_index > 0; input_index--) { |
| 2283 | sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index-1); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2284 | ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->getPatchHandle()); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2285 | if (patch_index >= 0) { |
| 2286 | sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index); |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2287 | status_t status; |
| 2288 | status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2289 | mAudioPatches.removeItemsAt(patch_index); |
| 2290 | patchRemoved = true; |
| 2291 | } |
Haynes Mathew George | 2e4655a | 2017-01-05 15:01:53 -0800 | [diff] [blame] | 2292 | mpClientInterface->closeInput(mInputs.keyAt(input_index-1)); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2293 | } |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2294 | mInputs.clear(); |
| 2295 | SoundTrigger::setCaptureState(false); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 2296 | nextAudioPortGeneration(); |
| 2297 | |
| 2298 | if (patchRemoved) { |
| 2299 | mpClientInterface->onAudioPatchListUpdate(); |
| 2300 | } |
| 2301 | } |
| 2302 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2303 | AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface) |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 2304 | : AudioPolicyManager(clientInterface), |
| 2305 | mHdmiAudioDisabled(false), |
| 2306 | mHdmiAudioEvent(false), |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 2307 | mPrevPhoneState(0), |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 2308 | mPrevFMVolumeDb(0.0f), |
| 2309 | mFMIsActive(false) |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2310 | { |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 2311 | |
Satya Krishna Pindiproli | 8f83f10 | 2016-06-21 17:56:14 +0530 | [diff] [blame] | 2312 | #ifdef USE_XML_AUDIO_POLICY_CONF |
| 2313 | ALOGD("USE_XML_AUDIO_POLICY_CONF is TRUE"); |
| 2314 | #else |
| 2315 | ALOGD("USE_XML_AUDIO_POLICY_CONF is FALSE"); |
| 2316 | #endif |
| 2317 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 2318 | #ifdef RECORD_PLAY_CONCURRENCY |
| 2319 | mIsInputRequestOnProgress = false; |
| 2320 | #endif |
| 2321 | |
| 2322 | |
| 2323 | #ifdef VOICE_CONCURRENCY |
| 2324 | mFallBackflag = getFallBackPath(); |
| 2325 | #endif |
| 2326 | } |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 2327 | } |