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