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