blob: 0e9aeae05c82c32d83d94b7b44a5243b889ed694 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07003 * 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 Jiedb057832015-11-12 08:51:22 +080018 *
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 Alamanda89a81422013-10-08 23:47:55 -070036 */
37
Sharad Sangle36781612015-05-28 16:15:16 +053038#define LOG_TAG "AudioPolicyManagerCustom"
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070039//#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 Sangle36781612015-05-28 16:15:16 +053047
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070048// 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 Alamanda1cf2a592014-10-29 20:31:15 -070051// 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 Sangle75170722016-11-21 16:21:06 +053055#define SAMPLE_RATE_8000 8000
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070056#include <inttypes.h>
Mingming Yin0ae14ea2014-07-09 17:55:56 -070057#include <math.h>
Mingming Yin0670f162014-06-12 16:05:49 -070058
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070059#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 Sangle36781612015-05-28 16:15:16 +053066#include <policy.h>
Gao Jiedb057832015-11-12 08:51:22 +080067#ifdef DOLBY_ENABLE
68#include "DolbyAudioPolicy_impl.h"
69#endif // DOLBY_END
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070070
71namespace android {
Sharad Sanglec5766ff2015-06-04 20:24:10 +053072#ifdef VOICE_CONCURRENCY
73audio_output_flags_t AudioPolicyManagerCustom::getFallBackPath()
74{
75 audio_output_flags_t flag = AUDIO_OUTPUT_FLAG_FAST;
76 char propValue[PROPERTY_VALUE_MAX];
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070077
Sharad Sanglec5766ff2015-06-04 20:24:10 +053078 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 Jaine4a22d52016-06-22 11:55:08 +0530100
101void 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 Alamanda89a81422013-10-08 23:47:55 -0700131// ----------------------------------------------------------------------------
132// AudioPolicyInterface implementation
133// ----------------------------------------------------------------------------
Sharad Sangle36781612015-05-28 16:15:16 +0530134extern "C" AudioPolicyInterface* createAudioPolicyManager(
135 AudioPolicyClientInterface *clientInterface)
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700136{
Sharad Sangle36781612015-05-28 16:15:16 +0530137 return new AudioPolicyManagerCustom(clientInterface);
138}
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700139
Sharad Sangle36781612015-05-28 16:15:16 +0530140extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
141{
142 delete interface;
143}
144
145status_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 Jain40cab3a2016-03-23 11:14:14 +0530150 ALOGD("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s",
Sharad Sangle36781612015-05-28 16:15:16 +0530151 device, state, device_address, device_name);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700152
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 Sangle36781612015-05-28 16:15:16 +0530156 sp<DeviceDescriptor> devDesc =
157 mHwModules.getDeviceDescriptor(device, device_address, device_name);
158
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700159 // handle output devices
160 if (audio_is_output_device(device)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700161 SortedVector <audio_io_handle_t> outputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700162
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700163 ssize_t index = mAvailableOutputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700164
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 Sangle36781612015-05-28 16:15:16 +0530171 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700172 if (index >= 0) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530173#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 Alamanda88d28cb2013-10-15 16:59:57 -0700182 ALOGW("setDeviceConnectionState() device already connected: %x", device);
183 return INVALID_OPERATION;
184 }
185 ALOGV("setDeviceConnectionState() connecting device %x", device);
186
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700187 // register new device as available
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700188 index = mAvailableOutputDevices.add(devDesc);
Sharad Sangle4509cef2015-08-19 20:47:12 +0530189#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 Alamanda1cf2a592014-10-29 20:31:15 -0700203 if (index >= 0) {
Sharad Sangle36781612015-05-28 16:15:16 +0530204 sp<HwModule> module = mHwModules.getModuleForDevice(device);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700205 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 Yin0ae14ea2014-07-09 17:55:56 -0700210 }
Sharad Sangle36781612015-05-28 16:15:16 +0530211 mAvailableOutputDevices[index]->attach(module);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700212 } else {
213 return NO_MEMORY;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700214 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700215
Sharad Sangle36781612015-05-28 16:15:16 +0530216 if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700217 mAvailableOutputDevices.remove(devDesc);
218 return INVALID_OPERATION;
219 }
Sharad Sangle36781612015-05-28 16:15:16 +0530220 // Propagate device availability to Engine
221 mEngine->setDeviceConnectionState(devDesc, state);
222
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700223 // 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 Sangle36781612015-05-28 16:15:16 +0530228
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 Alamanda88d28cb2013-10-15 16:59:57 -0700235 // handle output device disconnection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700236 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
237 if (index < 0) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530238#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 Alamanda88d28cb2013-10-15 16:59:57 -0700247 ALOGW("setDeviceConnectionState() device not connected: %x", device);
248 return INVALID_OPERATION;
249 }
250
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700251 ALOGV("setDeviceConnectionState() disconnecting output device %x", device);
252
Sharad Sangle36781612015-05-28 16:15:16 +0530253 // Send Disconnect to HALs
254 AudioParameter param = AudioParameter(devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700255 param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
256 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
257
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700258 // remove device from available output devices
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700259 mAvailableOutputDevices.remove(devDesc);
Sharad Sangle4509cef2015-08-19 20:47:12 +0530260#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 Sangle36781612015-05-28 16:15:16 +0530269 checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress);
270
271 // Propagate device availability to Engine
272 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700273 } break;
274
275 default:
276 ALOGE("setDeviceConnectionState() invalid state: %x", state);
277 return BAD_VALUE;
278 }
279
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700280 // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP
281 // output is suspended before any tracks are moved to it
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700282 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 Sangle36781612015-05-28 16:15:16 +0530287 sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700288 // close unused outputs after device disconnection or direct outputs that have been
289 // opened by checkOutputsForDevice() to query dynamic parameters
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700290 if ((state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) ||
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700291 (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) &&
292 (desc->mDirectOpenCount == 0))) {
293 closeOutput(outputs[i]);
294 }
295 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700296 // check again after closing A2DP output to reset mA2dpSuspended if needed
297 checkA2dpSuspend();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700298 }
299
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530300#ifdef FM_POWER_OPT
301 // handle FM device connection state to trigger FM AFE loopback
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800302 if (device == AUDIO_DEVICE_OUT_FM && hasPrimaryOutput()) {
Mingming Yin2dd77c22016-01-06 18:02:42 -0800303 audio_devices_t newDevice = AUDIO_DEVICE_NONE;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530304 if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
305 mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, 1);
Mingming Yin2dd77c22016-01-06 18:02:42 -0800306 newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false)|AUDIO_DEVICE_OUT_FM);
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800307 mFMIsActive = true;
Zhou Songbd0264e2016-06-21 11:01:06 +0800308 mPrimaryOutput->mDevice = newDevice & ~AUDIO_DEVICE_OUT_FM;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530309 } else {
Mingming Yin2dd77c22016-01-06 18:02:42 -0800310 newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false));
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800311 mFMIsActive = false;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530312 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 Songbd0264e2016-06-21 11:01:06 +0800320 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 Alamanda88d28cb2013-10-15 16:59:57 -0700331 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530332 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 Alamanda1cf2a592014-10-29 20:31:15 -0700335 // 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 Sangle36781612015-05-28 16:15:16 +0530338 bool force = !desc->isDuplicated()
339 && (!device_distinguishes_on_address(device)
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700340 // always force when disconnecting (a non-duplicated device)
341 || (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
Sharad Sangle36781612015-05-28 16:15:16 +0530342 setOutputDevice(desc, newDevice, force, 0);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700343 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700344 }
345
Ashish Jain40cab3a2016-03-23 11:14:14 +0530346 if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
347 cleanUpForDevice(devDesc);
348 }
349
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700350 mpClientInterface->onAudioPortListUpdate();
351 return NO_ERROR;
352 } // end if is output device
353
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700354 // handle input devices
355 if (audio_is_input_device(device)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700356 SortedVector <audio_io_handle_t> inputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700357
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700358 ssize_t index = mAvailableInputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700359 switch (state)
360 {
361 // handle input device connection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700362 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
363 if (index >= 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700364 ALOGW("setDeviceConnectionState() device already connected: %d", device);
365 return INVALID_OPERATION;
366 }
Sharad Sangle36781612015-05-28 16:15:16 +0530367 sp<HwModule> module = mHwModules.getModuleForDevice(device);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700368 if (module == NULL) {
369 ALOGW("setDeviceConnectionState(): could not find HW module for device %08x",
370 device);
371 return INVALID_OPERATION;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700372 }
Sharad Sangle36781612015-05-28 16:15:16 +0530373 if (checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress) != NO_ERROR) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700374 return INVALID_OPERATION;
375 }
376
377 index = mAvailableInputDevices.add(devDesc);
378 if (index >= 0) {
Sharad Sangle36781612015-05-28 16:15:16 +0530379 mAvailableInputDevices[index]->attach(module);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700380 } else {
381 return NO_MEMORY;
382 }
Sharad Sangle36781612015-05-28 16:15:16 +0530383
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 Alamanda1cf2a592014-10-29 20:31:15 -0700391 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700392
393 // handle input device disconnection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700394 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
395 if (index < 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700396 ALOGW("setDeviceConnectionState() device not connected: %d", device);
397 return INVALID_OPERATION;
398 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700399
400 ALOGV("setDeviceConnectionState() disconnecting input device %x", device);
401
402 // Set Disconnect to HALs
Sharad Sangle36781612015-05-28 16:15:16 +0530403 AudioParameter param = AudioParameter(devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700404 param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
405 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
406
Sharad Sangle36781612015-05-28 16:15:16 +0530407 checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700408 mAvailableInputDevices.remove(devDesc);
409
Sharad Sangle36781612015-05-28 16:15:16 +0530410 // Propagate device availability to Engine
411 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700412 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700413
414 default:
415 ALOGE("setDeviceConnectionState() invalid state: %x", state);
416 return BAD_VALUE;
417 }
418
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700419 closeAllInputs();
420
Sharad Sangle36781612015-05-28 16:15:16 +0530421 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700422 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
423 updateCallRouting(newDevice);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700424 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700425
Ashish Jain40cab3a2016-03-23 11:14:14 +0530426 if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
427 cleanUpForDevice(devDesc);
428 }
429
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700430 mpClientInterface->onAudioPortListUpdate();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700431 return NO_ERROR;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700432 } // end if is input device
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700433
434 ALOGW("setDeviceConnectionState() invalid device: %x", device);
435 return BAD_VALUE;
436}
Weiyin Jiangd211ef52016-02-16 15:55:11 +0800437
Preetam Singh Ranawat3db94ec2016-10-13 18:35:12 +0530438bool 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
450void 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 Sangle36781612015-05-28 16:15:16 +0530480// 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.
483bool AudioPolicyManagerCustom::isOffloadSupported(const audio_offload_info_t& offloadInfo)
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700484{
Sharad Sangle36781612015-05-28 16:15:16 +0530485 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 Jain40cab3a2016-03-23 11:14:14 +0530491
492 if (mMasterMono) {
493 return false; // no offloading if mono is set.
494 }
495
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530496#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 Ranawat96afc162016-08-25 14:35:02 +0530509 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 Sanglec5766ff2015-06-04 20:24:10 +0530514#ifdef RECORD_PLAY_CONCURRENCY
515 char recConcPropValue[PROPERTY_VALUE_MAX];
516 bool prop_rec_play_enabled = false;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700517
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530518 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 Kansara33918092016-12-06 22:42:26 +0530523 ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530524 ALOGD("copl: blocking compress offload for record concurrency");
525 return false;
526 }
527#endif
Sharad Sangle36781612015-05-28 16:15:16 +0530528 // 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 Alamanda1cf2a592014-10-29 20:31:15 -0700533 }
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530534
Alexy Joseph0ac09032015-10-16 15:57:53 -0700535 // 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 Jainac510a72016-04-28 12:22:58 +0530542 //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 Ranawat8152ab42015-07-21 19:30:09 +0530548 }
Satya Krishna Pindiproli5d82d012015-08-12 18:21:25 +0530549
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530550#ifdef AUDIO_EXTN_FORMATS_ENABLED
Ashish Jainac510a72016-04-28 12:22:58 +0530551 //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 }
yidonghae28e3a2016-08-19 11:31:15 +0800561
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 Ranawat8152ab42015-07-21 19:30:09 +0530569#endif
Ashish Jainac510a72016-04-28 12:22:58 +0530570 //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 Dewanganf3cd0f82015-10-13 14:04:36 +0530577
Ashish Jainac510a72016-04-28 12:22:58 +0530578 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 Sangle36781612015-05-28 16:15:16 +0530583 }
584
585 //If duration is less than minimum value defined in property, return false
Ashish Jainac510a72016-04-28 12:22:58 +0530586 char propValue[PROPERTY_VALUE_MAX];
Sharad Sangle36781612015-05-28 16:15:16 +0530587 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 Jainac510a72016-04-28 12:22:58 +0530599 ((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 Sangle36781612015-05-28 16:15:16 +0530604 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) ||
605 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) ||
Satya Krishna Pindiproli5d82d012015-08-12 18:21:25 +0530606 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_APE) ||
Preetam Singh Ranawat191eb772016-09-09 17:10:19 +0530607 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_DSD) ||
Ashish Jainac510a72016-04-28 12:22:58 +0530608 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS))
Sharad Sangle36781612015-05-28 16:15:16 +0530609 return false;
Ashish Jainac510a72016-04-28 12:22:58 +0530610#endif
Sharad Sangle36781612015-05-28 16:15:16 +0530611 }
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 Kumarcf558ba2016-07-29 19:33:13 +0530622
Sharad Sangle36781612015-05-28 16:15:16 +0530623 // 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 Alamanda1cf2a592014-10-29 20:31:15 -0700632}
Weiyin Jiangd211ef52016-02-16 15:55:11 +0800633
Sharad Sangle36781612015-05-28 16:15:16 +0530634audio_devices_t AudioPolicyManagerCustom::getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
635 bool fromCache)
636{
637 audio_devices_t device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700638
Ashish Jain40cab3a2016-03-23 11:14:14 +0530639 ssize_t index = mAudioPatches.indexOfKey(outputDesc->getPatchHandle());
Sharad Sangle36781612015-05-28 16:15:16 +0530640 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 Jain40cab3a2016-03-23 11:14:14 +0530644 outputDesc->device(), outputDesc->getPatchHandle());
Sharad Sangle36781612015-05-28 16:15:16 +0530645 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 Sangle4509cef2015-08-19 20:47:12 +0530681 } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL) ||
682 isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION_RESPECTFUL)) {
Sharad Sangle36781612015-05-28 16:15:16 +0530683 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 Jiangd211ef52016-02-16 15:55:11 +0800699
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700700void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state)
701{
Ashish Jain40cab3a2016-03-23 11:14:14 +0530702 ALOGD("setPhoneState() state %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +0530703 // store previous phone state for management of sonification strategy below
Sharad Sangle4509cef2015-08-19 20:47:12 +0530704 audio_devices_t newDevice = AUDIO_DEVICE_NONE;
Sharad Sangle36781612015-05-28 16:15:16 +0530705 int oldState = mEngine->getPhoneState();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700706
Sharad Sangle36781612015-05-28 16:15:16 +0530707 if (mEngine->setPhoneState(state) != NO_ERROR) {
708 ALOGW("setPhoneState() invalid or same state %d", state);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700709 return;
710 }
Sharad Sangle36781612015-05-28 16:15:16 +0530711 /// Opens: can these line be executed after the switch of volume curves???
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700712 // if leaving call state, handle special case of active streams
713 // pertaining to sonification strategy see handleIncallSonification()
Zhou Song58081b62016-02-24 13:10:55 +0800714 if (isStateInCall(oldState)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700715 ALOGV("setPhoneState() in call state management: new state is %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +0530716 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 Sangle4509cef2015-08-19 20:47:12 +0530722 handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput);
Sharad Sangle36781612015-05-28 16:15:16 +0530723 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700724 }
Sharad Sangle36781612015-05-28 16:15:16 +0530725
Zhou Song58081b62016-02-24 13:10:55 +0800726 // force reevaluating accessibility routing when call stops
Sharad Sangle36781612015-05-28 16:15:16 +0530727 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700728 }
729
Sharad Sangle36781612015-05-28 16:15:16 +0530730 /**
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 Alamanda1cf2a592014-10-29 20:31:15 -0700736
737 // check for device and output changes triggered by new phone state
738 checkA2dpSuspend();
739 checkOutputForAllStrategies();
740 updateDevicesAndOutputs();
741
Sharad Sangle36781612015-05-28 16:15:16 +0530742 sp<SwAudioOutputDescriptor> hwOutputDesc = mPrimaryOutput;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530743#ifdef VOICE_CONCURRENCY
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530744 char propValue[PROPERTY_VALUE_MAX];
745 bool prop_playback_enabled = false, prop_rec_enabled=false, prop_voip_enabled = false;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700746
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530747 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 Kumar9125b2a2015-12-01 16:24:09 +0530759 if ((AUDIO_MODE_IN_CALL != oldState) && (AUDIO_MODE_IN_CALL == state)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530760 ALOGD("voice_conc:Entering to call mode oldState :: %d state::%d ",
761 oldState, state);
Dhananjay Kumar9125b2a2015-12-01 16:24:09 +0530762 mvoice_call_state = state;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530763 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) {
kunleiz0b55ec72016-11-10 16:23:58 +0800846 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 Sanglec5766ff2015-06-04 20:24:10 +0530854 ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output");
855 closeOutput(mOutputs.keyAt(i));
856 }
857 }
858 }
Ashish Jaine4a22d52016-06-22 11:55:08 +0530859 // 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 Sanglec5766ff2015-06-04 20:24:10 +0530863 }
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 Ranawat96afc162016-08-25 14:35:02 +0530902
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 Sanglec5766ff2015-06-04 20:24:10 +0530922#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 Jaine4a22d52016-06-22 11:55:08 +0530951 // 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 Sanglec5766ff2015-06-04 20:24:10 +0530955 } 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 Alamanda1cf2a592014-10-29 20:31:15 -0700963 int delayMs = 0;
964 if (isStateInCall(state)) {
965 nsecs_t sysTime = systemTime();
966 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530967 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700968 // 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 Sangle36781612015-05-28 16:15:16 +0530971 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 Alamanda1cf2a592014-10-29 20:31:15 -0700979 }
Sharad Sangle36781612015-05-28 16:15:16 +0530980 setStrategyMute(STRATEGY_MEDIA, true, desc);
981 setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700982 getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));
Sharad Sangle36781612015-05-28 16:15:16 +0530983 setStrategyMute(STRATEGY_SONIFICATION, true, desc);
984 setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700985 getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/));
986 }
987 }
988
Sharad Sangle36781612015-05-28 16:15:16 +0530989 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 Alamanda1cf2a592014-10-29 20:31:15 -0700997 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700998
Sharad Sangle36781612015-05-28 16:15:16 +0530999 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 Alamanda1cf2a592014-10-29 20:31:15 -07001013 }
1014 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301015 //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 Alamanda1cf2a592014-10-29 20:31:15 -07001023 // 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 Sangle36781612015-05-28 16:15:16 +05301027 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 Sangle4509cef2015-08-19 20:47:12 +05301033 handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
Sharad Sangle36781612015-05-28 16:15:16 +05301034 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001035 }
Zhou Song58081b62016-02-24 13:10:55 +08001036
1037 // force reevaluating accessibility routing when call starts
1038 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001039 }
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 Kumar87dea1b2015-09-16 19:44:33 +05301049
1050void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
1051 audio_policy_forced_cfg_t config)
1052{
Ashish Jain40cab3a2016-03-23 11:14:14 +05301053 ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState());
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301054
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 Jain40cab3a2016-03-23 11:14:14 +05301067
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301068 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 Jain40cab3a2016-03-23 11:14:14 +05301092 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 Kumar87dea1b2015-09-16 19:44:33 +05301100 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301101}
1102
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301103status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301104 audio_stream_type_t stream,
1105 bool forceDeviceUpdate)
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001106{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301107 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1108 ALOGW("stopSource() invalid stream %d", stream);
1109 return INVALID_OPERATION;
1110 }
Sharad Sangle36781612015-05-28 16:15:16 +05301111 // always handle stream stop, check which stream type is stopping
1112 handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001113
Sharad Sangle36781612015-05-28 16:15:16 +05301114 // handle special case for sonification while in call
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001115 if (isInCall()) {
Sharad Sangle36781612015-05-28 16:15:16 +05301116 if (outputDesc->isDuplicated()) {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301117 handleIncallSonification(stream, false, false, outputDesc->subOutput1()->mIoHandle);
1118 handleIncallSonification(stream, false, false, outputDesc->subOutput2()->mIoHandle);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001119 }
Sharad Sangle36781612015-05-28 16:15:16 +05301120 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 Song5dcddc92015-09-21 14:36:57 +08001130 audio_devices_t prevDevice = outputDesc->device();
Sharad Sangle36781612015-05-28 16:15:16 +05301131 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 Sangle4509cef2015-08-19 20:47:12 +05301148 audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/);
Naresh Tanniru11393702016-09-14 11:25:37 +05301149 bool force = desc->device() != dev;
Zhou Song5dcddc92015-09-21 14:36:57 +08001150 uint32_t delayMs;
1151 if (dev == prevDevice) {
1152 delayMs = 0;
1153 } else {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301154 delayMs = outputDesc->latency()*2;
Zhou Song5dcddc92015-09-21 14:36:57 +08001155 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301156 setOutputDevice(desc,
1157 dev,
Naresh Tanniru11393702016-09-14 11:25:37 +05301158 force,
Zhou Song5dcddc92015-09-21 14:36:57 +08001159 delayMs);
Sharad Sangle36781612015-05-28 16:15:16 +05301160 }
1161 }
1162 // update the outputs if stopping one with a stream that can affect notification routing
1163 handleNotificationRoutingForStream(stream);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001164 }
Sharad Sangle36781612015-05-28 16:15:16 +05301165 return NO_ERROR;
1166 } else {
1167 ALOGW("stopOutput() refcount is already 0");
1168 return INVALID_OPERATION;
1169 }
1170}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001171
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301172status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301173 audio_stream_type_t stream,
1174 audio_devices_t device,
Lalit Kansaraf803ac52016-05-09 19:12:01 +05301175 const char *address,
Sharad Sangle36781612015-05-28 16:15:16 +05301176 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 Kumar0ffa7112015-10-20 17:56:50 +05301181 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1182 ALOGW("startSource() invalid stream %d", stream);
1183 return INVALID_OPERATION;
1184 }
1185
Sharad Sangle36781612015-05-28 16:15:16 +05301186 *delayMs = 0;
1187 if (stream == AUDIO_STREAM_TTS) {
1188 ALOGV("\t found BEACON stream");
Ashish Jain40cab3a2016-03-23 11:14:14 +05301189 if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301190 return INVALID_OPERATION;
1191 } else {
1192 beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001193 }
Sharad Sangle36781612015-05-28 16:15:16 +05301194 } else {
1195 // some playback other than beacon starts
1196 beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT);
1197 }
1198
Zhou Song63f0b852016-12-20 14:35:06 +08001199 // force device change if the output is inactive and no audio patch is already present.
Ashish Jain40cab3a2016-03-23 11:14:14 +05301200 // check active before incrementing usage count
Zhou Song63f0b852016-12-20 14:35:06 +08001201 bool force = !outputDesc->isActive() &&
1202 (outputDesc->getPatchHandle() == AUDIO_PATCH_HANDLE_NONE);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301203
Sharad Sangle36781612015-05-28 16:15:16 +05301204 // increment usage count for this stream on the requested output:
1205 // NOTE that the usage count is the same for duplicated output and hardware output which is
1206 // necessary for a correct control of hardware output routing by startOutput() and stopOutput()
1207 outputDesc->changeRefCount(stream, 1);
1208
1209 if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) {
1210 // starting an output being rerouted?
1211 if (device == AUDIO_DEVICE_NONE) {
1212 device = getNewOutputDevice(outputDesc, false /*fromCache*/);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001213 }
Sharad Sangle36781612015-05-28 16:15:16 +05301214 routing_strategy strategy = getStrategy(stream);
1215 bool shouldWait = (strategy == STRATEGY_SONIFICATION) ||
1216 (strategy == STRATEGY_SONIFICATION_RESPECTFUL) ||
1217 (beaconMuteLatency > 0);
1218 uint32_t waitMs = beaconMuteLatency;
Sharad Sangle36781612015-05-28 16:15:16 +05301219 for (size_t i = 0; i < mOutputs.size(); i++) {
1220 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
1221 if (desc != outputDesc) {
Zhou Song63f0b852016-12-20 14:35:06 +08001222 // force a device change if any other output is:
1223 // - managed by the same hw module
1224 // - has a current device selection that differs from selected device.
1225 // - supports currently selected device
1226 // - has an active audio patch
Sharad Sangle36781612015-05-28 16:15:16 +05301227 // In this case, the audio HAL must receive the new device selection so that it can
1228 // change the device currently selected by the other active output.
1229 if (outputDesc->sharesHwModuleWith(desc) &&
Zhou Song63f0b852016-12-20 14:35:06 +08001230 desc->device() != device &&
1231 desc->supportedDevices() & device &&
1232 desc->getPatchHandle() != AUDIO_PATCH_HANDLE_NONE) {
Sharad Sangle36781612015-05-28 16:15:16 +05301233 force = true;
1234 }
1235 // wait for audio on other active outputs to be presented when starting
1236 // a notification so that audio focus effect can propagate, or that a mute/unmute
1237 // event occurred for beacon
1238 uint32_t latency = desc->latency();
1239 if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) {
1240 waitMs = latency;
1241 }
1242 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001243 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05301244 uint32_t muteWaitMs;
Lalit Kansaraf803ac52016-05-09 19:12:01 +05301245 muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address);
Sharad Sangle36781612015-05-28 16:15:16 +05301246
1247 // handle special case for sonification while in call
1248 if (isInCall()) {
1249 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001250 }
Sharad Sangle36781612015-05-28 16:15:16 +05301251
1252 // apply volume rules for current stream and device if necessary
1253 checkAndSetVolume(stream,
Ashish Jain40cab3a2016-03-23 11:14:14 +05301254 mVolumeCurves->getVolumeIndex(stream, device),
Sharad Sangle36781612015-05-28 16:15:16 +05301255 outputDesc,
1256 device);
1257
1258 // update the outputs if starting an output with a stream that can affect notification
1259 // routing
1260 handleNotificationRoutingForStream(stream);
1261
1262 // force reevaluating accessibility routing when ringtone or alarm starts
1263 if (strategy == STRATEGY_SONIFICATION) {
1264 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
1265 }
1266 }
1267 else {
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001268 // handle special case for sonification while in call
1269 if (isInCall()) {
1270 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Sharad Sangle36781612015-05-28 16:15:16 +05301271 }
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001272 }
Sharad Sangle36781612015-05-28 16:15:16 +05301273 return NO_ERROR;
1274}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001275
Sharad Sangle36781612015-05-28 16:15:16 +05301276void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream,
1277 bool starting, bool stateChange,
1278 audio_io_handle_t output)
1279{
1280 if(!hasPrimaryOutput()) {
1281 return;
1282 }
1283 // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks
1284 if (stream == AUDIO_STREAM_PATCH) {
1285 return;
1286 }
1287 // if the stream pertains to sonification strategy and we are in call we must
1288 // mute the stream if it is low visibility. If it is high visibility, we must play a tone
1289 // in the device used for phone strategy and play the tone if the selected device does not
1290 // interfere with the device used for phone strategy
1291 // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as
1292 // many times as there are active tracks on the output
1293 const routing_strategy stream_strategy = getStrategy(stream);
1294 if ((stream_strategy == STRATEGY_SONIFICATION) ||
1295 ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) {
1296 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
1297 ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
1298 stream, starting, outputDesc->mDevice, stateChange);
1299 if (outputDesc->mRefCount[stream]) {
1300 int muteCount = 1;
1301 if (stateChange) {
1302 muteCount = outputDesc->mRefCount[stream];
1303 }
1304 if (audio_is_low_visibility(stream)) {
1305 ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
1306 for (int i = 0; i < muteCount; i++) {
1307 setStreamMute(stream, starting, outputDesc);
1308 }
1309 } else {
1310 ALOGV("handleIncallSonification() high visibility");
1311 if (outputDesc->device() &
1312 getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) {
1313 ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
1314 for (int i = 0; i < muteCount; i++) {
1315 setStreamMute(stream, starting, outputDesc);
1316 }
1317 }
1318 if (starting) {
1319 mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION,
1320 AUDIO_STREAM_VOICE_CALL);
1321 } else {
1322 mpClientInterface->stopTone();
1323 }
1324 }
1325 }
1326 }
1327}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001328
Sharad Sangle36781612015-05-28 16:15:16 +05301329void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) {
1330 switch(stream) {
1331 case AUDIO_STREAM_MUSIC:
1332 checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL);
1333 updateDevicesAndOutputs();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001334 break;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001335 default:
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001336 break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001337 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001338}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001339
Sharad Sangle36781612015-05-28 16:15:16 +05301340status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream,
1341 int index,
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301342 const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301343 audio_devices_t device,
1344 int delayMs, bool force)
1345{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301346 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1347 ALOGW("checkAndSetVolume() invalid stream %d", stream);
1348 return INVALID_OPERATION;
1349 }
Sharad Sangle36781612015-05-28 16:15:16 +05301350 // do not change actual stream volume if the stream is muted
1351 if (outputDesc->mMuteCount[stream] != 0) {
1352 ALOGVV("checkAndSetVolume() stream %d muted count %d",
1353 stream, outputDesc->mMuteCount[stream]);
1354 return NO_ERROR;
1355 }
1356 audio_policy_forced_cfg_t forceUseForComm =
1357 mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION);
1358 // do not change in call volume if bluetooth is connected and vice versa
1359 if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) ||
1360 (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) {
1361 ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
1362 stream, forceUseForComm);
1363 return INVALID_OPERATION;
1364 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001365
Sharad Sangle36781612015-05-28 16:15:16 +05301366 if (device == AUDIO_DEVICE_NONE) {
1367 device = outputDesc->device();
1368 }
1369
1370 float volumeDb = computeVolume(stream, index, device);
1371 if (outputDesc->isFixedVolume(device)) {
1372 volumeDb = 0.0f;
1373 }
1374
1375 outputDesc->setVolume(volumeDb, stream, device, delayMs, force);
1376
1377 if (stream == AUDIO_STREAM_VOICE_CALL ||
1378 stream == AUDIO_STREAM_BLUETOOTH_SCO) {
1379 float voiceVolume;
1380 // Force voice volume to max for bluetooth SCO as volume is managed by the headset
1381 if (stream == AUDIO_STREAM_VOICE_CALL) {
Ashish Jain40cab3a2016-03-23 11:14:14 +05301382 voiceVolume = (float)index/(float)mVolumeCurves->getVolumeIndexMax(stream);
Sharad Sangle36781612015-05-28 16:15:16 +05301383 } else {
1384 voiceVolume = 1.0;
1385 }
1386
1387 if (voiceVolume != mLastVoiceVolume && ((outputDesc == mPrimaryOutput) ||
1388 isDirectOutput(outputDesc->mIoHandle) || device & AUDIO_DEVICE_OUT_ALL_USB)) {
1389 mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
1390 mLastVoiceVolume = voiceVolume;
1391 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301392#ifdef FM_POWER_OPT
1393 } else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() &&
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08001394 outputDesc == mPrimaryOutput && mFMIsActive) {
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001395 /* Avoid unnecessary set_parameter calls as it puts the primary
1396 outputs FastMixer in HOT_IDLE leading to breaks in audio */
1397 if (volumeDb != mPrevFMVolumeDb) {
1398 mPrevFMVolumeDb = volumeDb;
1399 AudioParameter param = AudioParameter();
1400 param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb));
Mingming Yin1433cc62016-01-04 14:58:00 -08001401 //Double delayMs to avoid sound burst while device switch.
1402 mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs*2);
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001403 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301404#endif /* FM_POWER_OPT end */
Sharad Sangle36781612015-05-28 16:15:16 +05301405 }
1406
1407 return NO_ERROR;
1408}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001409
Sharad Sangle36781612015-05-28 16:15:16 +05301410bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) {
1411 for (size_t i = 0; i < mOutputs.size(); i++) {
1412 audio_io_handle_t curOutput = mOutputs.keyAt(i);
1413 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1414 if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
1415 return true;
1416 }
1417 }
1418 return false;
1419}
vivek mehta0ea887a2015-08-26 14:01:20 -07001420
Sharad Sangle75170722016-11-21 16:21:06 +05301421bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate)
Ashish Jainac510a72016-04-28 12:22:58 +05301422{
Ashish Jain771d02f2016-10-27 22:35:46 +05301423 bool playerDirectPCM = false; // Output request for Track created by mediaplayer
1424 bool trackDirectPCM = false; // Output request for track created by other apps
Ashish Jain27564312016-11-14 14:58:06 +05301425 bool offloadDisabled = property_get_bool("audio.offload.disable", false);
Ashish Jainac510a72016-04-28 12:22:58 +05301426
Ashish Jain771d02f2016-10-27 22:35:46 +05301427 // Direct PCM is allowed only if
1428 // In case of mediaPlayer playback
1429 // 16 bit direct pcm or 24bit direct PCM property is set and
1430 // the FLAG requested is DIRECT_PCM ( NuPlayer case) or
1431 // In case of AudioTracks created by apps
1432 // track offload is enabled and FLAG requested is FLAG_NONE.
1433
Ashish Jain27564312016-11-14 14:58:06 +05301434 if (offloadDisabled) {
1435 ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled);
1436 }
1437
Ashish Jain771d02f2016-10-27 22:35:46 +05301438 if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
1439 if (bitWidth == 24 || bitWidth == 32)
1440 playerDirectPCM =
1441 property_get_bool("audio.offload.pcm.24bit.enable", false);
1442 else
1443 playerDirectPCM =
1444 property_get_bool("audio.offload.pcm.16bit.enable", false);
1445 // Reset flag to NONE so that we can still reuse direct pcm criteria check
1446 // in getOutputforDevice
1447 *flags = AUDIO_OUTPUT_FLAG_NONE;
Sharad Sangle75170722016-11-21 16:21:06 +05301448 } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) {
Ashish Jain771d02f2016-10-27 22:35:46 +05301449 trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
1450 }
1451
Ashish Jain27564312016-11-14 14:58:06 +05301452 ALOGI("Direct PCM %s for this request",
1453 (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled");
1454
1455 return (!offloadDisabled && (trackDirectPCM || playerDirectPCM));
Ashish Jainac510a72016-04-28 12:22:58 +05301456}
1457
vivek mehta0ea887a2015-08-26 14:01:20 -07001458status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
1459 audio_io_handle_t *output,
1460 audio_session_t session,
1461 audio_stream_type_t *stream,
1462 uid_t uid,
1463 uint32_t samplingRate,
1464 audio_format_t format,
1465 audio_channel_mask_t channelMask,
1466 audio_output_flags_t flags,
1467 audio_port_handle_t selectedDeviceId,
1468 const audio_offload_info_t *offloadInfo)
1469{
1470 audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
1471
Ashish Jainac510a72016-04-28 12:22:58 +05301472 uint32_t bitWidth = (audio_bytes_per_sample(format) * 8);
Alexy Joseph0ac09032015-10-16 15:57:53 -07001473
Alexy Joseph0ac09032015-10-16 15:57:53 -07001474
Sharad Sangle75170722016-11-21 16:21:06 +05301475 if (tryForDirectPCM(bitWidth, &flags, samplingRate) &&
Ashish Jain27564312016-11-14 14:58:06 +05301476 (offloadInfo == NULL)) {
vivek mehta0ea887a2015-08-26 14:01:20 -07001477
vivek mehta0ea887a2015-08-26 14:01:20 -07001478 tOffloadInfo.sample_rate = samplingRate;
1479 tOffloadInfo.channel_mask = channelMask;
1480 tOffloadInfo.format = format;
1481 tOffloadInfo.stream_type = *stream;
Ashish Jainac510a72016-04-28 12:22:58 +05301482 tOffloadInfo.bit_width = bitWidth;
vivek mehta0ea887a2015-08-26 14:01:20 -07001483 if (attr != NULL) {
1484 ALOGV("found attribute .. setting usage %d ", attr->usage);
1485 tOffloadInfo.usage = attr->usage;
1486 } else {
Alexy Joseph0ac09032015-10-16 15:57:53 -07001487 ALOGI("%s:: attribute is NULL .. no usage set", __func__);
vivek mehta0ea887a2015-08-26 14:01:20 -07001488 }
1489 offloadInfo = &tOffloadInfo;
1490 }
1491
1492 return AudioPolicyManager::getOutputForAttr(attr, output, session, stream,
1493 (uid_t)uid, (uint32_t)samplingRate,
1494 format, (audio_channel_mask_t)channelMask,
1495 flags, (audio_port_handle_t)selectedDeviceId,
1496 offloadInfo);
1497}
1498
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001499audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice(
1500 audio_devices_t device,
Sharad Sangle36781612015-05-28 16:15:16 +05301501 audio_session_t session __unused,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001502 audio_stream_type_t stream,
1503 uint32_t samplingRate,
1504 audio_format_t format,
1505 audio_channel_mask_t channelMask,
1506 audio_output_flags_t flags,
1507 const audio_offload_info_t *offloadInfo)
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001508{
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001509 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001510 status_t status;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001511
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001512#ifdef AUDIO_POLICY_TEST
1513 if (mCurOutput != 0) {
1514 ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d",
1515 mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
1516
1517 if (mTestOutputs[mCurOutput] == 0) {
1518 ALOGV("getOutput() opening test output");
Sharad Sangle36781612015-05-28 16:15:16 +05301519 sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL,
1520 mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001521 outputDesc->mDevice = mTestDevice;
1522 outputDesc->mLatency = mTestLatencyMs;
1523 outputDesc->mFlags =
1524 (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0);
1525 outputDesc->mRefCount[stream] = 0;
1526 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1527 config.sample_rate = mTestSamplingRate;
1528 config.channel_mask = mTestChannels;
1529 config.format = mTestFormat;
1530 if (offloadInfo != NULL) {
1531 config.offload_info = *offloadInfo;
1532 }
1533 status = mpClientInterface->openOutput(0,
1534 &mTestOutputs[mCurOutput],
1535 &config,
1536 &outputDesc->mDevice,
1537 String8(""),
1538 &outputDesc->mLatency,
1539 outputDesc->mFlags);
1540 if (status == NO_ERROR) {
1541 outputDesc->mSamplingRate = config.sample_rate;
1542 outputDesc->mFormat = config.format;
1543 outputDesc->mChannelMask = config.channel_mask;
1544 AudioParameter outputCmd = AudioParameter();
1545 outputCmd.addInt(String8("set_id"),mCurOutput);
1546 mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString());
1547 addOutput(mTestOutputs[mCurOutput], outputDesc);
1548 }
1549 }
1550 return mTestOutputs[mCurOutput];
1551 }
1552#endif //AUDIO_POLICY_TEST
Sharad Sangle36781612015-05-28 16:15:16 +05301553 if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) &&
1554 (stream != AUDIO_STREAM_MUSIC)) {
1555 // compress should not be used for non-music streams
1556 ALOGE("Offloading only allowed with music stream");
1557 return 0;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301558 }
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301559
1560 if ((stream == AUDIO_STREAM_VOICE_CALL) &&
1561 (channelMask == 1) &&
Shiv Maliyappanahallid77d3b32016-02-02 13:45:50 -08001562 (samplingRate == 8000 || samplingRate == 16000 ||
1563 samplingRate == 32000 || samplingRate == 48000)) {
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301564 // Allow Voip direct output only if:
1565 // audio mode is MODE_IN_COMMUNCATION; AND
1566 // voip output is not opened already; AND
1567 // requested sample rate matches with that of voip input stream (if opened already)
1568 int value = 0;
1569 uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1;
1570 String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1571 String8("audio_mode"));
1572 AudioParameter result = AudioParameter(valueStr);
1573 if (result.getInt(String8("audio_mode"), value) == NO_ERROR) {
1574 mode = value;
1575 }
1576
1577 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1578 String8("voip_out_stream_count"));
1579 result = AudioParameter(valueStr);
1580 if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) {
1581 voipOutCount = value;
1582 }
1583
1584 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1585 String8("voip_sample_rate"));
1586 result = AudioParameter(valueStr);
1587 if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) {
1588 voipSampleRate = value;
1589 }
1590
1591 if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) &&
1592 ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) {
1593 if (audio_is_linear_pcm(format)) {
1594 char propValue[PROPERTY_VALUE_MAX] = {0};
1595 property_get("use.voice.path.for.pcm.voip", propValue, "0");
1596 bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true"));
1597 if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) {
Karthik Reddy Katta3fb9be72015-11-25 11:18:27 +05301598 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_VOIP_RX |
1599 AUDIO_OUTPUT_FLAG_DIRECT);
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301600 ALOGD("Set VoIP and Direct output flags for PCM format");
1601 }
1602 }
1603 }
1604 }
1605
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301606#ifdef VOICE_CONCURRENCY
1607 char propValue[PROPERTY_VALUE_MAX];
1608 bool prop_play_enabled=false, prop_voip_enabled = false;
1609
1610 if(property_get("voice.playback.conc.disabled", propValue, NULL)) {
1611 prop_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001612 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301613
1614 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1615 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1616 }
1617
1618 if (prop_play_enabled && mvoice_call_state) {
1619 //check if voice call is active / running in background
1620 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1621 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1622 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1623 {
1624 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1625 if(prop_voip_enabled) {
1626 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1627 flags );
1628 return 0;
1629 }
1630 }
1631 else {
1632 if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
1633 ALOGD("voice_conc:IN call mode adding ULL flags .. flags: %x ", flags );
1634 flags = AUDIO_OUTPUT_FLAG_FAST;
1635 } else if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
1636 if (AUDIO_STREAM_MUSIC == stream) {
1637 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1638 ALOGD("voice_conc:IN call mode adding deep-buffer flags %x ", flags );
1639 }
1640 else {
1641 flags = AUDIO_OUTPUT_FLAG_FAST;
1642 ALOGD("voice_conc:IN call mode adding fast flags %x ", flags );
1643 }
1644 }
1645 }
1646 }
1647 } else if (prop_voip_enabled && mvoice_call_state) {
1648 //check if voice call is active / running in background
1649 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1650 //return only ULL ouput
1651 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1652 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1653 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1654 {
1655 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1656 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1657 flags );
1658 return 0;
1659 }
1660 }
1661 }
1662#endif
1663#ifdef RECORD_PLAY_CONCURRENCY
1664 char recConcPropValue[PROPERTY_VALUE_MAX];
1665 bool prop_rec_play_enabled = false;
1666
1667 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
1668 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
1669 }
1670 if ((prop_rec_play_enabled) &&
Lalit Kansara33918092016-12-06 22:42:26 +05301671 ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301672 if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) {
1673 if (AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1674 // allow VoIP using voice path
1675 // Do nothing
1676 } else if((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1677 ALOGD("voice_conc:MODE_IN_COMM is setforcing deep buffer output for non ULL... flags: %x", flags);
1678 // use deep buffer path for all non ULL outputs
1679 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1680 }
1681 } else if ((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1682 ALOGD("voice_conc:Record mode is on forcing deep buffer output for non ULL... flags: %x ", flags);
1683 // use deep buffer path for all non ULL outputs
1684 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1685 }
1686 }
1687 if (prop_rec_play_enabled &&
1688 (stream == AUDIO_STREAM_ENFORCED_AUDIBLE)) {
1689 ALOGD("Record conc is on forcing ULL output for ENFORCED_AUDIBLE");
1690 flags = AUDIO_OUTPUT_FLAG_FAST;
1691 }
1692#endif
1693
Sharad Sangle4509cef2015-08-19 20:47:12 +05301694#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
Sharad Sangle36781612015-05-28 16:15:16 +05301695 /*
1696 * WFD audio routes back to target speaker when starting a ringtone playback.
1697 * This is because primary output is reused for ringtone, so output device is
1698 * updated based on SONIFICATION strategy for both ringtone and music playback.
1699 * The same issue is not seen on remoted_submix HAL based WFD audio because
1700 * primary output is not reused and a new output is created for ringtone playback.
1701 * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is
1702 * a non-music stream playback on WFD, so primary output is not reused for ringtone.
1703 */
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001704 audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types();
1705 if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY)
1706 && (stream != AUDIO_STREAM_MUSIC)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301707 ALOGD("WFD audio: use OUTPUT_FLAG_FAST for non music stream. flags:%x", flags );
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001708 //For voip paths
1709 if(flags & AUDIO_OUTPUT_FLAG_DIRECT)
1710 flags = AUDIO_OUTPUT_FLAG_DIRECT;
1711 else //route every thing else to ULL path
1712 flags = AUDIO_OUTPUT_FLAG_FAST;
1713 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301714#endif
1715
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001716 // open a direct output if required by specified parameters
vivek mehta0ea887a2015-08-26 14:01:20 -07001717 // force direct flag if offload flag is set: offloading implies a direct output stream
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001718 // and all common behaviors are driven by checking only the direct flag
1719 // this should normally be set appropriately in the policy configuration file
1720 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
1721 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1722 }
1723 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1724 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1725 }
vivek mehta0ea887a2015-08-26 14:01:20 -07001726
vivek mehta4b0d8192015-10-16 00:25:59 -07001727 bool forced_deep = false;
Sharad Sangle36781612015-05-28 16:15:16 +05301728 // only allow deep buffering for music stream type
1729 if (stream != AUDIO_STREAM_MUSIC) {
1730 flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
Sharad Sangle497aef82015-08-03 17:55:48 +05301731 } else if (/* stream == AUDIO_STREAM_MUSIC && */
1732 flags == AUDIO_OUTPUT_FLAG_NONE &&
1733 property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
vivek mehtac984b992015-11-25 13:28:55 -08001734 forced_deep = true;
Sharad Sangle36781612015-05-28 16:15:16 +05301735 }
Sharad Sangle497aef82015-08-03 17:55:48 +05301736
Sharad Sangle36781612015-05-28 16:15:16 +05301737 if (stream == AUDIO_STREAM_TTS) {
1738 flags = AUDIO_OUTPUT_FLAG_TTS;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001739 }
1740
Zhou Song2b3d1552016-03-21 17:21:04 +08001741 // check if direct output for track offload already exits
1742 bool is_track_offload_active = false;
1743 for (size_t i = 0; i < mOutputs.size(); i++) {
1744 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1745 if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
1746 is_track_offload_active = true;
1747 ALOGD("Track offload already active");
1748 break;
1749 }
1750 }
1751
vivek mehta4b0d8192015-10-16 00:25:59 -07001752 // Do offload magic here
vivek mehtac984b992015-11-25 13:28:55 -08001753 if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
1754 (stream == AUDIO_STREAM_MUSIC) &&
Zhou Song2b3d1552016-03-21 17:21:04 +08001755 (offloadInfo != NULL) && !is_track_offload_active &&
vivek mehta4b0d8192015-10-16 00:25:59 -07001756 ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
vivek mehtac984b992015-11-25 13:28:55 -08001757 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM);
vivek mehta4b0d8192015-10-16 00:25:59 -07001758 ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301759 }
1760
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001761 sp<IOProfile> profile;
1762
1763 // skip direct output selection if the request can obviously be attached to a mixed output
1764 // and not explicitly requested
vivek mehtac984b992015-11-25 13:28:55 -08001765 if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301766 audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX &&
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001767 audio_channel_count_from_out_mask(channelMask) <= 2) {
1768 goto non_direct_output;
1769 }
1770
1771 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
1772 // creating an offloaded track and tearing it down immediately after start when audioflinger
1773 // detects there is an active non offloadable effect.
1774 // FIXME: We should check the audio session here but we do not have it in this context.
1775 // This may prevent offloading in rare situations where effects are left active by apps
1776 // in the background.
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001777 //
1778 // Supplementary annotation:
1779 // For sake of track offload introduced, we need a rollback for both compress offload
1780 // and track offload use cases.
1781 if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) &&
1782 (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) {
1783 ALOGD("non offloadable effect is enabled, try with non direct output");
1784 goto non_direct_output;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001785 }
1786
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001787 profile = getProfileForDirectOutput(device,
1788 samplingRate,
1789 format,
1790 channelMask,
1791 (audio_output_flags_t)flags);
1792
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001793 if (profile != 0) {
vivek mehtac984b992015-11-25 13:28:55 -08001794
1795 if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301796 (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
vivek mehtac984b992015-11-25 13:28:55 -08001797 ALOGI("got Direct_PCM without requesting ... reject ");
1798 profile = NULL;
1799 goto non_direct_output;
1800 }
1801
Sharad Sangle36781612015-05-28 16:15:16 +05301802 sp<SwAudioOutputDescriptor> outputDesc = NULL;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001803
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001804 // if multiple concurrent offload decode is supported
1805 // do no check for reuse and also don't close previous output if its offload
1806 // previous output will be closed during track destruction
1807 if (!(property_get_bool("audio.offload.multiple.enabled", false) &&
1808 ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) {
1809 for (size_t i = 0; i < mOutputs.size(); i++) {
1810 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1811 if (!desc->isDuplicated() && (profile == desc->mProfile)) {
1812 outputDesc = desc;
1813 // reuse direct output if currently open and configured with same parameters
1814 if ((samplingRate == outputDesc->mSamplingRate) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301815 audio_formats_match(format, outputDesc->mFormat) &&
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001816 (channelMask == outputDesc->mChannelMask)) {
1817 outputDesc->mDirectOpenCount++;
1818 ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
1819 return mOutputs.keyAt(i);
1820 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001821 }
1822 }
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001823 // close direct output if currently open and configured with different parameters
1824 if (outputDesc != NULL) {
1825 closeOutput(outputDesc->mIoHandle);
1826 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001827 }
Sharad Sangle36781612015-05-28 16:15:16 +05301828
1829 // if the selected profile is offloaded and no offload info was specified,
1830 // create a default one
1831 audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER;
Ashish Jain40cab3a2016-03-23 11:14:14 +05301832 if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) {
Sharad Sangle36781612015-05-28 16:15:16 +05301833 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
1834 defaultOffloadInfo.sample_rate = samplingRate;
1835 defaultOffloadInfo.channel_mask = channelMask;
1836 defaultOffloadInfo.format = format;
1837 defaultOffloadInfo.stream_type = stream;
1838 defaultOffloadInfo.bit_rate = 0;
1839 defaultOffloadInfo.duration_us = -1;
1840 defaultOffloadInfo.has_video = true; // conservative
1841 defaultOffloadInfo.is_streaming = true; // likely
1842 offloadInfo = &defaultOffloadInfo;
1843 }
1844
1845 outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001846 outputDesc->mDevice = device;
1847 outputDesc->mLatency = 0;
Sharad Sangle36781612015-05-28 16:15:16 +05301848 outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001849 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1850 config.sample_rate = samplingRate;
1851 config.channel_mask = channelMask;
1852 config.format = format;
1853 if (offloadInfo != NULL) {
1854 config.offload_info = *offloadInfo;
1855 }
Sharad Sangle36781612015-05-28 16:15:16 +05301856 status = mpClientInterface->openOutput(profile->getModuleHandle(),
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001857 &output,
1858 &config,
1859 &outputDesc->mDevice,
1860 String8(""),
1861 &outputDesc->mLatency,
1862 outputDesc->mFlags);
1863
1864 // only accept an output with the requested parameters
1865 if (status != NO_ERROR ||
1866 (samplingRate != 0 && samplingRate != config.sample_rate) ||
Ashish Jain40cab3a2016-03-23 11:14:14 +05301867 (format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) ||
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001868 (channelMask != 0 && channelMask != config.channel_mask)) {
1869 ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
1870 "format %d %d, channelMask %04x %04x", output, samplingRate,
1871 outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
1872 outputDesc->mChannelMask);
1873 if (output != AUDIO_IO_HANDLE_NONE) {
1874 mpClientInterface->closeOutput(output);
1875 }
Sharad Sangle36781612015-05-28 16:15:16 +05301876 // fall back to mixer output if possible when the direct output could not be open
Ashish Jain40cab3a2016-03-23 11:14:14 +05301877 if (audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX) {
Sharad Sangle36781612015-05-28 16:15:16 +05301878 goto non_direct_output;
1879 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001880 return AUDIO_IO_HANDLE_NONE;
1881 }
1882 outputDesc->mSamplingRate = config.sample_rate;
1883 outputDesc->mChannelMask = config.channel_mask;
1884 outputDesc->mFormat = config.format;
1885 outputDesc->mRefCount[stream] = 0;
1886 outputDesc->mStopTime[stream] = 0;
1887 outputDesc->mDirectOpenCount = 1;
1888
1889 audio_io_handle_t srcOutput = getOutputForEffect();
1890 addOutput(output, outputDesc);
1891 audio_io_handle_t dstOutput = getOutputForEffect();
1892 if (dstOutput == output) {
Gao Jiedb057832015-11-12 08:51:22 +08001893#ifdef DOLBY_ENABLE
1894 status_t status = mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
1895 if (status == NO_ERROR) {
1896 for (size_t i = 0; i < mEffects.size(); i++) {
1897 sp<EffectDescriptor> desc = mEffects.valueAt(i);
1898 if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) {
1899 // update the mIo member of EffectDescriptor for the global effect
1900 ALOGV("%s updating mIo", __FUNCTION__);
1901 desc->mIo = dstOutput;
1902 }
1903 }
1904 } else {
1905 ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, srcOutput, dstOutput);
1906 }
1907#else // DOLBY_END
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001908 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
Gao Jiedb057832015-11-12 08:51:22 +08001909#endif // LINE_ADDED_BY_DOLBY
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001910 }
1911 mPreviousOutputs = mOutputs;
1912 ALOGV("getOutput() returns new direct output %d", output);
1913 mpClientInterface->onAudioPortListUpdate();
1914 return output;
1915 }
1916
1917non_direct_output:
Ashish Jain5fe12412016-04-18 18:44:17 +05301918
1919 // A request for HW A/V sync cannot fallback to a mixed output because time
1920 // stamps are embedded in audio data
1921 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1922 return AUDIO_IO_HANDLE_NONE;
1923 }
1924
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001925 // ignoring channel mask due to downmix capability in mixer
1926
1927 // open a non direct output
1928
1929 // for non direct outputs, only PCM is supported
1930 if (audio_is_linear_pcm(format)) {
1931 // get which output is suitable for the specified stream. The actual
1932 // routing change will happen when startOutput() will be called
1933 SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
1934
1935 // at this stage we should ignore the DIRECT flag as no direct output could be found earlier
1936 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT);
Ashish Jain660d3112016-06-20 10:16:51 +05301937
1938 if (forced_deep) {
1939 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
1940 ALOGI("setting force DEEP buffer now ");
1941 } else if(flags == AUDIO_OUTPUT_FLAG_NONE) {
1942 // no deep buffer playback is requested hence fallback to primary
1943 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_PRIMARY);
1944 ALOGI("FLAG None hence request for a primary output");
1945 }
1946
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001947 output = selectOutput(outputs, flags, format);
1948 }
1949 ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d,"
1950 "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
1951
vivek mehta0ea887a2015-08-26 14:01:20 -07001952 ALOGV("getOutputForDevice() returns output %d", output);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001953
1954 return output;
1955}
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301956
1957status_t AudioPolicyManagerCustom::getInputForAttr(const audio_attributes_t *attr,
1958 audio_io_handle_t *input,
1959 audio_session_t session,
1960 uid_t uid,
1961 uint32_t samplingRate,
1962 audio_format_t format,
1963 audio_channel_mask_t channelMask,
1964 audio_input_flags_t flags,
1965 audio_port_handle_t selectedDeviceId,
1966 input_type_t *inputType)
1967{
Ashish Jain40cab3a2016-03-23 11:14:14 +05301968 audio_source_t inputSource;
1969 inputSource = attr->source;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301970#ifdef VOICE_CONCURRENCY
1971
1972 char propValue[PROPERTY_VALUE_MAX];
1973 bool prop_rec_enabled=false, prop_voip_enabled = false;
1974
1975 if(property_get("voice.record.conc.disabled", propValue, NULL)) {
1976 prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1977 }
1978
1979 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1980 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1981 }
1982
1983 if (prop_rec_enabled && mvoice_call_state) {
1984 //check if voice call is active / running in background
1985 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1986 //Need to block input request
1987 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1988 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
1989 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1990 {
1991 switch(inputSource) {
1992 case AUDIO_SOURCE_VOICE_UPLINK:
1993 case AUDIO_SOURCE_VOICE_DOWNLINK:
1994 case AUDIO_SOURCE_VOICE_CALL:
1995 ALOGD("voice_conc:Creating input during incall mode for inputSource: %d",
1996 inputSource);
1997 break;
1998
1999 case AUDIO_SOURCE_VOICE_COMMUNICATION:
2000 if(prop_voip_enabled) {
2001 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
2002 inputSource);
2003 return NO_INIT;
2004 }
2005 break;
2006 default:
2007 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
2008 inputSource);
2009 return NO_INIT;
2010 }
2011 }
2012 }//check for VoIP flag
2013 else if(prop_voip_enabled && mvoice_call_state) {
2014 //check if voice call is active / running in background
2015 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
2016 //Need to block input request
2017 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
2018 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
2019 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
2020 {
2021 if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) {
2022 ALOGD("BLOCKING VoIP request during incall mode for inputSource: %d ",inputSource);
2023 return NO_INIT;
2024 }
2025 }
2026 }
2027
2028#endif
2029
2030 return AudioPolicyManager::getInputForAttr(attr,
2031 input,
2032 session,
2033 uid,
2034 samplingRate,
2035 format,
2036 channelMask,
2037 flags,
2038 selectedDeviceId,
2039 inputType);
2040}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002041
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302042status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,
2043 audio_session_t session)
2044{
2045 ALOGV("startInput() input %d", input);
2046 ssize_t index = mInputs.indexOfKey(input);
2047 if (index < 0) {
2048 ALOGW("startInput() unknown input %d", input);
2049 return BAD_VALUE;
2050 }
2051 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index);
2052
Ashish Jain40cab3a2016-03-23 11:14:14 +05302053 sp<AudioSession> audioSession = inputDesc->getAudioSession(session);
2054 if (audioSession == 0) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302055 ALOGW("startInput() unknown session %d on input %d", session, input);
2056 return BAD_VALUE;
2057 }
2058
2059 // virtual input devices are compatible with other input devices
2060 if (!is_virtual_input_device(inputDesc->mDevice)) {
2061
2062 // for a non-virtual input device, check if there is another (non-virtual) active input
2063 audio_io_handle_t activeInput = mInputs.getActiveInput();
2064 if (activeInput != 0 && activeInput != input) {
2065
2066 // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed,
2067 // otherwise the active input continues and the new input cannot be started.
2068 sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302069 if ((activeDesc->inputSource() == AUDIO_SOURCE_HOTWORD) &&
2070 !activeDesc->hasPreemptedSession(session)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302071 ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302072 //FIXME: consider all active sessions
2073 AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
2074 audio_session_t activeSession = activeSessions.keyAt(0);
2075 SortedVector<audio_session_t> sessions =
2076 activeDesc->getPreemptedSessions();
2077 sessions.add(activeSession);
2078 inputDesc->setPreemptedSessions(sessions);
2079 stopInput(activeInput, activeSession);
2080 releaseInput(activeInput, activeSession);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302081 } else {
2082 ALOGE("startInput(%d) failed: other input %d already started", input, activeInput);
2083 return INVALID_OPERATION;
2084 }
2085 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05302086 // Do not allow capture if an active voice call is using a software patch and
2087 // the call TX source device is on the same HW module.
2088 // FIXME: would be better to refine to only inputs whose profile connects to the
2089 // call TX device but this information is not in the audio patch
2090 if (mCallTxPatch != 0 &&
2091 inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) {
2092 return INVALID_OPERATION;
2093 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302094 }
2095
2096 // Routing?
2097 mInputRoutes.incRouteActivity(session);
2098#ifdef RECORD_PLAY_CONCURRENCY
2099 mIsInputRequestOnProgress = true;
2100
2101 char getPropValue[PROPERTY_VALUE_MAX];
2102 bool prop_rec_play_enabled = false;
2103
2104 if (property_get("rec.playback.conc.disabled", getPropValue, NULL)) {
2105 prop_rec_play_enabled = atoi(getPropValue) || !strncmp("true", getPropValue, 4);
2106 }
2107
Lalit Kansara33918092016-12-06 22:42:26 +05302108 if ((prop_rec_play_enabled) &&(mInputs.activeInputsCountOnDevices() == 0)){
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302109 // send update to HAL on record playback concurrency
2110 AudioParameter param = AudioParameter();
2111 param.add(String8("rec_play_conc_on"), String8("true"));
2112 ALOGD("startInput() setParameters rec_play_conc is setting to ON ");
2113 mpClientInterface->setParameters(0, param.toString());
2114
2115 // Call invalidate to reset all opened non ULL audio tracks
2116 // Move tracks associated to this strategy from previous output to new output
2117 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
2118 // Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder)
Sharad Sangle4509cef2015-08-19 20:47:12 +05302119 if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302120 ALOGD("Invalidate on releaseInput for stream :: %d ", i);
2121 //FIXME see fixme on name change
2122 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2123 }
2124 }
2125 // close compress tracks
2126 for (size_t i = 0; i < mOutputs.size(); i++) {
2127 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
2128 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
2129 ALOGD("ouput desc / profile is NULL");
2130 continue;
2131 }
2132 if (outputDesc->mProfile->mFlags
2133 & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
2134 // close compress sessions
2135 ALOGD("calling closeOutput on record conc for COMPRESS output");
2136 closeOutput(mOutputs.keyAt(i));
2137 }
2138 }
Ashish Jaine4a22d52016-06-22 11:55:08 +05302139 // If effects where present on any of the above closed outputs,
2140 // audioflinger moved them to the primary output by default
2141 // move them back to the appropriate output.
2142 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302143 }
2144#endif
2145
Ashish Jain40cab3a2016-03-23 11:14:14 +05302146 if (!inputDesc->isActive() || mInputRoutes.hasRouteChanged(session)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302147 // if input maps to a dynamic policy with an activity listener, notify of state change
Ashish Jain630c5e12016-04-18 11:50:21 +05302148 if ((inputDesc->mPolicyMix != NULL)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302149 && ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) {
Ashish Jain5fe12412016-04-18 18:44:17 +05302150 mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress,
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302151 MIX_STATE_MIXING);
Ashish Jain630c5e12016-04-18 11:50:21 +05302152 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302153
Lalit Kansara33918092016-12-06 22:42:26 +05302154 if (mInputs.activeInputsCountOnDevices() == 0) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302155 SoundTrigger::setCaptureState(true);
2156 }
2157 setInputDevice(input, getNewInputDevice(input), true /* force */);
2158
2159 // automatically enable the remote submix output when input is started if not
2160 // used by a policy mix of type MIX_TYPE_RECORDERS
2161 // For remote submix (a virtual device), we open only one input per capture request.
2162 if (audio_is_remote_submix_device(inputDesc->mDevice)) {
2163 String8 address = String8("");
2164 if (inputDesc->mPolicyMix == NULL) {
2165 address = String8("0");
Ashish Jain630c5e12016-04-18 11:50:21 +05302166 } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) {
Ashish Jain5fe12412016-04-18 18:44:17 +05302167 address = inputDesc->mPolicyMix->mDeviceAddress;
Ashish Jain630c5e12016-04-18 11:50:21 +05302168 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302169 if (address != "") {
2170 setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
2171 AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
2172 address, "remote-submix");
2173 }
2174 }
2175 }
2176
Ashish Jain40cab3a2016-03-23 11:14:14 +05302177 ALOGV("AudioPolicyManager::startInput() input source = %d", audioSession->inputSource());
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302178
Ashish Jain40cab3a2016-03-23 11:14:14 +05302179 audioSession->changeActiveCount(1);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302180#ifdef RECORD_PLAY_CONCURRENCY
2181 mIsInputRequestOnProgress = false;
2182#endif
2183 return NO_ERROR;
2184}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002185
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302186status_t AudioPolicyManagerCustom::stopInput(audio_io_handle_t input,
2187 audio_session_t session)
2188{
2189 status_t status;
2190 status = AudioPolicyManager::stopInput(input, session);
2191#ifdef RECORD_PLAY_CONCURRENCY
2192 char propValue[PROPERTY_VALUE_MAX];
2193 bool prop_rec_play_enabled = false;
2194
2195 if (property_get("rec.playback.conc.disabled", propValue, NULL)) {
2196 prop_rec_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
2197 }
2198
Lalit Kansara33918092016-12-06 22:42:26 +05302199 if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302200
2201 //send update to HAL on record playback concurrency
2202 AudioParameter param = AudioParameter();
2203 param.add(String8("rec_play_conc_on"), String8("false"));
2204 ALOGD("stopInput() setParameters rec_play_conc is setting to OFF ");
2205 mpClientInterface->setParameters(0, param.toString());
2206
2207 //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL
2208 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
2209 //Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder stop tone)
2210 if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE) && (i != AUDIO_STREAM_PATCH)) {
2211 ALOGD(" Invalidate on stopInput for stream :: %d ", i);
2212 //FIXME see fixme on name change
2213 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2214 }
2215 }
2216 }
2217#endif
2218 return status;
2219}
2220
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302221void AudioPolicyManagerCustom::closeAllInputs() {
2222 bool patchRemoved = false;
2223
Dhanalakshmi Siddanibfeca7f2015-10-08 15:17:11 +05302224 for(size_t input_index = mInputs.size(); input_index > 0; input_index--) {
2225 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index-1);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302226 ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->getPatchHandle());
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302227 if (patch_index >= 0) {
2228 sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302229 status_t status;
2230 status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302231 mAudioPatches.removeItemsAt(patch_index);
2232 patchRemoved = true;
2233 }
Haynes Mathew George2e4655a2017-01-05 15:01:53 -08002234 mpClientInterface->closeInput(mInputs.keyAt(input_index-1));
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302235 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05302236 mInputs.clear();
2237 SoundTrigger::setCaptureState(false);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302238 nextAudioPortGeneration();
2239
2240 if (patchRemoved) {
2241 mpClientInterface->onAudioPatchListUpdate();
2242 }
2243}
2244
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302245AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
Sharad Sangle4509cef2015-08-19 20:47:12 +05302246 : AudioPolicyManager(clientInterface),
2247 mHdmiAudioDisabled(false),
2248 mHdmiAudioEvent(false),
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08002249 mPrevPhoneState(0),
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08002250 mPrevFMVolumeDb(0.0f),
2251 mFMIsActive(false)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302252{
Ashish Jain40cab3a2016-03-23 11:14:14 +05302253
Satya Krishna Pindiproli8f83f102016-06-21 17:56:14 +05302254#ifdef USE_XML_AUDIO_POLICY_CONF
2255 ALOGD("USE_XML_AUDIO_POLICY_CONF is TRUE");
2256#else
2257 ALOGD("USE_XML_AUDIO_POLICY_CONF is FALSE");
2258#endif
2259
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302260#ifdef RECORD_PLAY_CONCURRENCY
2261 mIsInputRequestOnProgress = false;
2262#endif
2263
2264
2265#ifdef VOICE_CONCURRENCY
2266 mFallBackflag = getFallBackPath();
2267#endif
2268}
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07002269}