blob: 77cbf5adde8c44c4b6b583cd443d4cf864b7fa6c [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
Sidipotu Ashok738f19e2016-12-07 15:16:01 +0530829 bool isFastFallBackNeeded =
830 ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & outputDesc->mProfile->mFlags);
831
832 if ((AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) && isFastFallBackNeeded) {
833 if (((!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY))
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530834 && prop_playback_enabled) {
835 ALOGD("voice_conc:calling suspendOutput on call mode for primary output");
836 mpClientInterface->suspendOutput(mOutputs.keyAt(i));
837 } //Close compress all sessions
838 else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
839 && prop_playback_enabled) {
840 ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output");
841 closeOutput(mOutputs.keyAt(i));
842 }
843 else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX)
844 && prop_voip_enabled) {
845 ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output");
846 closeOutput(mOutputs.keyAt(i));
847 }
848 } else if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
kunleiz0b55ec72016-11-10 16:23:58 +0800849 if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) {
850 if (prop_voip_enabled) {
851 ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output");
852 closeOutput(mOutputs.keyAt(i));
853 }
854 }
855 else if (prop_playback_enabled
856 && (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530857 ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output");
858 closeOutput(mOutputs.keyAt(i));
859 }
860 }
861 }
Ashish Jaine4a22d52016-06-22 11:55:08 +0530862 // If effects where present on any of the above closed outputs,
863 // audioflinger moved them to the primary output by default
864 // move them back to the appropriate output.
865 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530866 }
867
868 if ((AUDIO_MODE_IN_CALL == oldState || AUDIO_MODE_IN_COMMUNICATION == oldState) &&
869 (AUDIO_MODE_NORMAL == state) && prop_playback_enabled && mvoice_call_state) {
870 ALOGD("voice_conc:EXITING from call mode oldState :: %d state::%d \n",oldState, state);
871 mvoice_call_state = 0;
872 if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
873 //restore PCM (deep-buffer) output after call termination
874 for (size_t i = 0; i < mOutputs.size(); i++) {
875 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
876 if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
877 ALOGD("voice_conc:ouput desc / profile is NULL");
878 continue;
879 }
880 if (!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) {
881 ALOGD("voice_conc:calling restoreOutput after call mode for primary output");
882 mpClientInterface->restoreOutput(mOutputs.keyAt(i));
883 }
884 }
885 }
886 //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL
887 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
888 ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i);
889 if (i == AUDIO_STREAM_PATCH) {
890 ALOGV("voice_conc:not calling invalidate for AUDIO_STREAM_PATCH");
891 continue;
892 }
893 if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
894 if ((AUDIO_STREAM_MUSIC == i) ||
895 (AUDIO_STREAM_VOICE_CALL == i) ) {
896 mpClientInterface->invalidateStream((audio_stream_type_t)i);
897 }
898 } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
899 mpClientInterface->invalidateStream((audio_stream_type_t)i);
900 }
901 }
902 }
903
904#endif
Preetam Singh Ranawat96afc162016-08-25 14:35:02 +0530905
906 sp<SwAudioOutputDescriptor> outputDesc = NULL;
907 for (size_t i = 0; i < mOutputs.size(); i++) {
908 outputDesc = mOutputs.valueAt(i);
909 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
910 ALOGD("voice_conc:ouput desc / profile is NULL");
911 continue;
912 }
913
914 if (property_get_bool("voice.dsd.playback.conc.disabled", true) &&
915 (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
916 (outputDesc->mFormat == AUDIO_FORMAT_DSD)) {
917 ALOGD("voice_conc:calling closeOutput on call mode for DSD COMPRESS output");
918 closeOutput(mOutputs.keyAt(i));
919 // call invalidate for music, so that DSD compress will fallback to deep-buffer.
920 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
921 }
922
923 }
924
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530925#ifdef RECORD_PLAY_CONCURRENCY
926 char recConcPropValue[PROPERTY_VALUE_MAX];
927 bool prop_rec_play_enabled = false;
928
929 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
930 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
931 }
932 if (prop_rec_play_enabled) {
933 if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) {
934 ALOGD("phone state changed to MODE_IN_COMM invlaidating music and voice streams");
935 // call invalidate for voice streams, so that it can use deepbuffer with VoIP out device from HAL
936 mpClientInterface->invalidateStream(AUDIO_STREAM_VOICE_CALL);
937 // call invalidate for music, so that compress will fallback to deep-buffer with VoIP out device
938 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
939
940 // close compress output to make sure session will be closed before timeout(60sec)
941 for (size_t i = 0; i < mOutputs.size(); i++) {
942
943 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
944 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
945 ALOGD("ouput desc / profile is NULL");
946 continue;
947 }
948
949 if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
950 ALOGD("calling closeOutput on call mode for COMPRESS output");
951 closeOutput(mOutputs.keyAt(i));
952 }
953 }
Ashish Jaine4a22d52016-06-22 11:55:08 +0530954 // If effects where present on any of the above closed outputs,
955 // audioflinger moved them to the primary output by default
956 // move them back to the appropriate output.
957 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530958 } else if ((oldState == AUDIO_MODE_IN_COMMUNICATION) &&
959 (mEngine->getPhoneState() == AUDIO_MODE_NORMAL)) {
960 // call invalidate for music so that music can fallback to compress
961 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
962 }
963 }
964#endif
965 mPrevPhoneState = oldState;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700966 int delayMs = 0;
967 if (isStateInCall(state)) {
968 nsecs_t sysTime = systemTime();
969 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530970 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700971 // mute media and sonification strategies and delay device switch by the largest
972 // latency of any output where either strategy is active.
973 // This avoid sending the ring tone or music tail into the earpiece or headset.
Sharad Sangle36781612015-05-28 16:15:16 +0530974 if ((isStrategyActive(desc, STRATEGY_MEDIA,
975 SONIFICATION_HEADSET_MUSIC_DELAY,
976 sysTime) ||
977 isStrategyActive(desc, STRATEGY_SONIFICATION,
978 SONIFICATION_HEADSET_MUSIC_DELAY,
979 sysTime)) &&
980 (delayMs < (int)desc->latency()*2)) {
981 delayMs = desc->latency()*2;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700982 }
Sharad Sangle36781612015-05-28 16:15:16 +0530983 setStrategyMute(STRATEGY_MEDIA, true, desc);
984 setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700985 getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));
Sharad Sangle36781612015-05-28 16:15:16 +0530986 setStrategyMute(STRATEGY_SONIFICATION, true, desc);
987 setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700988 getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/));
989 }
990 }
991
Sharad Sangle36781612015-05-28 16:15:16 +0530992 if (hasPrimaryOutput()) {
993 // Note that despite the fact that getNewOutputDevice() is called on the primary output,
994 // the device returned is not necessarily reachable via this output
995 audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
996 // force routing command to audio hardware when ending call
997 // even if no device change is needed
998 if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) {
999 rxDevice = mPrimaryOutput->device();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001000 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001001
Sharad Sangle36781612015-05-28 16:15:16 +05301002 if (state == AUDIO_MODE_IN_CALL) {
1003 updateCallRouting(rxDevice, delayMs);
1004 } else if (oldState == AUDIO_MODE_IN_CALL) {
1005 if (mCallRxPatch != 0) {
1006 mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0);
1007 mCallRxPatch.clear();
1008 }
1009 if (mCallTxPatch != 0) {
1010 mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0);
1011 mCallTxPatch.clear();
1012 }
1013 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
1014 } else {
1015 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001016 }
1017 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301018 //update device for all non-primary outputs
1019 for (size_t i = 0; i < mOutputs.size(); i++) {
1020 audio_io_handle_t output = mOutputs.keyAt(i);
1021 if (output != mPrimaryOutput->mIoHandle) {
1022 newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/);
1023 setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE));
1024 }
1025 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001026 // if entering in call state, handle special case of active streams
1027 // pertaining to sonification strategy see handleIncallSonification()
1028 if (isStateInCall(state)) {
1029 ALOGV("setPhoneState() in call state management: new state is %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +05301030 for (size_t j = 0; j < mOutputs.size(); j++) {
1031 audio_io_handle_t curOutput = mOutputs.keyAt(j);
1032 for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
1033 if (stream == AUDIO_STREAM_PATCH) {
1034 continue;
1035 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301036 handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
Sharad Sangle36781612015-05-28 16:15:16 +05301037 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001038 }
Zhou Song58081b62016-02-24 13:10:55 +08001039
1040 // force reevaluating accessibility routing when call starts
1041 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001042 }
1043
1044 // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE
1045 if (state == AUDIO_MODE_RINGTONE &&
1046 isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) {
1047 mLimitRingtoneVolume = true;
1048 } else {
1049 mLimitRingtoneVolume = false;
1050 }
1051}
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301052
1053void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
1054 audio_policy_forced_cfg_t config)
1055{
Ashish Jain40cab3a2016-03-23 11:14:14 +05301056 ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState());
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301057
1058 if (mEngine->setForceUse(usage, config) != NO_ERROR) {
1059 ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage);
1060 return;
1061 }
1062 bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) ||
1063 (usage == AUDIO_POLICY_FORCE_FOR_DOCK) ||
1064 (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM);
1065
1066 // check for device and output changes triggered by new force usage
1067 checkA2dpSuspend();
1068 checkOutputForAllStrategies();
1069 updateDevicesAndOutputs();
Ashish Jain40cab3a2016-03-23 11:14:14 +05301070
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301071 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
1072 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/);
1073 updateCallRouting(newDevice);
1074 }
1075 // Use reverse loop to make sure any low latency usecases (generally tones)
1076 // are not routed before non LL usecases (generally music).
1077 // We can safely assume that LL output would always have lower index,
1078 // and use this work-around to avoid routing of output with music stream
1079 // from the context of short lived LL output.
1080 // Note: in case output's share backend(HAL sharing is implicit) all outputs
1081 // gets routing update while processing first output itself.
1082 for (size_t i = mOutputs.size(); i > 0; i--) {
1083 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1);
1084 audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/);
1085 if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || outputDesc != mPrimaryOutput) {
1086 setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE));
1087 }
1088 if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
1089 applyStreamVolumes(outputDesc, newDevice, 0, true);
1090 }
1091 }
1092
1093 audio_io_handle_t activeInput = mInputs.getActiveInput();
1094 if (activeInput != 0) {
Ashish Jain40cab3a2016-03-23 11:14:14 +05301095 sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
1096 audio_devices_t newDevice = getNewInputDevice(activeInput);
1097 // Force new input selection if the new device can not be reached via current input
1098 if (activeDesc->mProfile->getSupportedDevices().types() & (newDevice & ~AUDIO_DEVICE_BIT_IN)) {
1099 setInputDevice(activeInput, newDevice);
1100 } else {
1101 closeInput(activeInput);
1102 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301103 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301104}
1105
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301106status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301107 audio_stream_type_t stream,
1108 bool forceDeviceUpdate)
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001109{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301110 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1111 ALOGW("stopSource() invalid stream %d", stream);
1112 return INVALID_OPERATION;
1113 }
Sharad Sangle36781612015-05-28 16:15:16 +05301114 // always handle stream stop, check which stream type is stopping
1115 handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001116
Sharad Sangle36781612015-05-28 16:15:16 +05301117 // handle special case for sonification while in call
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001118 if (isInCall()) {
Sharad Sangle36781612015-05-28 16:15:16 +05301119 if (outputDesc->isDuplicated()) {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301120 handleIncallSonification(stream, false, false, outputDesc->subOutput1()->mIoHandle);
1121 handleIncallSonification(stream, false, false, outputDesc->subOutput2()->mIoHandle);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001122 }
Sharad Sangle36781612015-05-28 16:15:16 +05301123 handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
1124 }
1125
1126 if (outputDesc->mRefCount[stream] > 0) {
1127 // decrement usage count of this stream on the output
1128 outputDesc->changeRefCount(stream, -1);
1129
1130 // store time at which the stream was stopped - see isStreamActive()
1131 if (outputDesc->mRefCount[stream] == 0 || forceDeviceUpdate) {
1132 outputDesc->mStopTime[stream] = systemTime();
Zhou Song5dcddc92015-09-21 14:36:57 +08001133 audio_devices_t prevDevice = outputDesc->device();
Sharad Sangle36781612015-05-28 16:15:16 +05301134 audio_devices_t newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/);
1135 // delay the device switch by twice the latency because stopOutput() is executed when
1136 // the track stop() command is received and at that time the audio track buffer can
1137 // still contain data that needs to be drained. The latency only covers the audio HAL
1138 // and kernel buffers. Also the latency does not always include additional delay in the
1139 // audio path (audio DSP, CODEC ...)
1140 setOutputDevice(outputDesc, newDevice, false, outputDesc->latency()*2);
1141
1142 // force restoring the device selection on other active outputs if it differs from the
1143 // one being selected for this output
1144 for (size_t i = 0; i < mOutputs.size(); i++) {
1145 audio_io_handle_t curOutput = mOutputs.keyAt(i);
1146 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
1147 if (desc != outputDesc &&
1148 desc->isActive() &&
1149 outputDesc->sharesHwModuleWith(desc) &&
1150 (newDevice != desc->device())) {
Sharad Sangle4509cef2015-08-19 20:47:12 +05301151 audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/);
Naresh Tanniru11393702016-09-14 11:25:37 +05301152 bool force = desc->device() != dev;
Zhou Song5dcddc92015-09-21 14:36:57 +08001153 uint32_t delayMs;
1154 if (dev == prevDevice) {
1155 delayMs = 0;
1156 } else {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301157 delayMs = outputDesc->latency()*2;
Zhou Song5dcddc92015-09-21 14:36:57 +08001158 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301159 setOutputDevice(desc,
1160 dev,
Naresh Tanniru11393702016-09-14 11:25:37 +05301161 force,
Zhou Song5dcddc92015-09-21 14:36:57 +08001162 delayMs);
Sharad Sangle36781612015-05-28 16:15:16 +05301163 }
1164 }
1165 // update the outputs if stopping one with a stream that can affect notification routing
1166 handleNotificationRoutingForStream(stream);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001167 }
Sharad Sangle36781612015-05-28 16:15:16 +05301168 return NO_ERROR;
1169 } else {
1170 ALOGW("stopOutput() refcount is already 0");
1171 return INVALID_OPERATION;
1172 }
1173}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001174
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301175status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301176 audio_stream_type_t stream,
1177 audio_devices_t device,
Lalit Kansaraf803ac52016-05-09 19:12:01 +05301178 const char *address,
Sharad Sangle36781612015-05-28 16:15:16 +05301179 uint32_t *delayMs)
1180{
1181 // cannot start playback of STREAM_TTS if any other output is being used
1182 uint32_t beaconMuteLatency = 0;
1183
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301184 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1185 ALOGW("startSource() invalid stream %d", stream);
1186 return INVALID_OPERATION;
1187 }
1188
Sharad Sangle36781612015-05-28 16:15:16 +05301189 *delayMs = 0;
1190 if (stream == AUDIO_STREAM_TTS) {
1191 ALOGV("\t found BEACON stream");
Ashish Jain40cab3a2016-03-23 11:14:14 +05301192 if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301193 return INVALID_OPERATION;
1194 } else {
1195 beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001196 }
Sharad Sangle36781612015-05-28 16:15:16 +05301197 } else {
1198 // some playback other than beacon starts
1199 beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT);
1200 }
1201
Zhou Song63f0b852016-12-20 14:35:06 +08001202 // force device change if the output is inactive and no audio patch is already present.
Ashish Jain40cab3a2016-03-23 11:14:14 +05301203 // check active before incrementing usage count
Zhou Song63f0b852016-12-20 14:35:06 +08001204 bool force = !outputDesc->isActive() &&
1205 (outputDesc->getPatchHandle() == AUDIO_PATCH_HANDLE_NONE);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301206
Sharad Sangle36781612015-05-28 16:15:16 +05301207 // increment usage count for this stream on the requested output:
1208 // NOTE that the usage count is the same for duplicated output and hardware output which is
1209 // necessary for a correct control of hardware output routing by startOutput() and stopOutput()
1210 outputDesc->changeRefCount(stream, 1);
1211
1212 if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) {
1213 // starting an output being rerouted?
1214 if (device == AUDIO_DEVICE_NONE) {
1215 device = getNewOutputDevice(outputDesc, false /*fromCache*/);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001216 }
Sharad Sangle36781612015-05-28 16:15:16 +05301217 routing_strategy strategy = getStrategy(stream);
1218 bool shouldWait = (strategy == STRATEGY_SONIFICATION) ||
1219 (strategy == STRATEGY_SONIFICATION_RESPECTFUL) ||
1220 (beaconMuteLatency > 0);
1221 uint32_t waitMs = beaconMuteLatency;
Sharad Sangle36781612015-05-28 16:15:16 +05301222 for (size_t i = 0; i < mOutputs.size(); i++) {
1223 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
1224 if (desc != outputDesc) {
Zhou Song63f0b852016-12-20 14:35:06 +08001225 // force a device change if any other output is:
1226 // - managed by the same hw module
1227 // - has a current device selection that differs from selected device.
1228 // - supports currently selected device
1229 // - has an active audio patch
Sharad Sangle36781612015-05-28 16:15:16 +05301230 // In this case, the audio HAL must receive the new device selection so that it can
1231 // change the device currently selected by the other active output.
1232 if (outputDesc->sharesHwModuleWith(desc) &&
Zhou Song63f0b852016-12-20 14:35:06 +08001233 desc->device() != device &&
1234 desc->supportedDevices() & device &&
1235 desc->getPatchHandle() != AUDIO_PATCH_HANDLE_NONE) {
Sharad Sangle36781612015-05-28 16:15:16 +05301236 force = true;
1237 }
1238 // wait for audio on other active outputs to be presented when starting
1239 // a notification so that audio focus effect can propagate, or that a mute/unmute
1240 // event occurred for beacon
1241 uint32_t latency = desc->latency();
1242 if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) {
1243 waitMs = latency;
1244 }
1245 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001246 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05301247 uint32_t muteWaitMs;
Lalit Kansaraf803ac52016-05-09 19:12:01 +05301248 muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address);
Sharad Sangle36781612015-05-28 16:15:16 +05301249
1250 // handle special case for sonification while in call
1251 if (isInCall()) {
1252 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001253 }
Sharad Sangle36781612015-05-28 16:15:16 +05301254
1255 // apply volume rules for current stream and device if necessary
1256 checkAndSetVolume(stream,
Ashish Jain40cab3a2016-03-23 11:14:14 +05301257 mVolumeCurves->getVolumeIndex(stream, device),
Sharad Sangle36781612015-05-28 16:15:16 +05301258 outputDesc,
1259 device);
1260
1261 // update the outputs if starting an output with a stream that can affect notification
1262 // routing
1263 handleNotificationRoutingForStream(stream);
1264
1265 // force reevaluating accessibility routing when ringtone or alarm starts
1266 if (strategy == STRATEGY_SONIFICATION) {
1267 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
1268 }
1269 }
1270 else {
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001271 // handle special case for sonification while in call
1272 if (isInCall()) {
1273 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Sharad Sangle36781612015-05-28 16:15:16 +05301274 }
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001275 }
Sharad Sangle36781612015-05-28 16:15:16 +05301276 return NO_ERROR;
1277}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001278
Sharad Sangle36781612015-05-28 16:15:16 +05301279void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream,
1280 bool starting, bool stateChange,
1281 audio_io_handle_t output)
1282{
1283 if(!hasPrimaryOutput()) {
1284 return;
1285 }
1286 // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks
1287 if (stream == AUDIO_STREAM_PATCH) {
1288 return;
1289 }
1290 // if the stream pertains to sonification strategy and we are in call we must
1291 // mute the stream if it is low visibility. If it is high visibility, we must play a tone
1292 // in the device used for phone strategy and play the tone if the selected device does not
1293 // interfere with the device used for phone strategy
1294 // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as
1295 // many times as there are active tracks on the output
1296 const routing_strategy stream_strategy = getStrategy(stream);
1297 if ((stream_strategy == STRATEGY_SONIFICATION) ||
1298 ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) {
1299 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
1300 ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
1301 stream, starting, outputDesc->mDevice, stateChange);
1302 if (outputDesc->mRefCount[stream]) {
1303 int muteCount = 1;
1304 if (stateChange) {
1305 muteCount = outputDesc->mRefCount[stream];
1306 }
1307 if (audio_is_low_visibility(stream)) {
1308 ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
1309 for (int i = 0; i < muteCount; i++) {
1310 setStreamMute(stream, starting, outputDesc);
1311 }
1312 } else {
1313 ALOGV("handleIncallSonification() high visibility");
1314 if (outputDesc->device() &
1315 getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) {
1316 ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
1317 for (int i = 0; i < muteCount; i++) {
1318 setStreamMute(stream, starting, outputDesc);
1319 }
1320 }
1321 if (starting) {
1322 mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION,
1323 AUDIO_STREAM_VOICE_CALL);
1324 } else {
1325 mpClientInterface->stopTone();
1326 }
1327 }
1328 }
1329 }
1330}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001331
Sharad Sangle36781612015-05-28 16:15:16 +05301332void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) {
1333 switch(stream) {
1334 case AUDIO_STREAM_MUSIC:
1335 checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL);
1336 updateDevicesAndOutputs();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001337 break;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001338 default:
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001339 break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001340 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001341}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001342
Sharad Sangle36781612015-05-28 16:15:16 +05301343status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream,
1344 int index,
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301345 const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301346 audio_devices_t device,
1347 int delayMs, bool force)
1348{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301349 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1350 ALOGW("checkAndSetVolume() invalid stream %d", stream);
1351 return INVALID_OPERATION;
1352 }
Sharad Sangle36781612015-05-28 16:15:16 +05301353 // do not change actual stream volume if the stream is muted
1354 if (outputDesc->mMuteCount[stream] != 0) {
1355 ALOGVV("checkAndSetVolume() stream %d muted count %d",
1356 stream, outputDesc->mMuteCount[stream]);
1357 return NO_ERROR;
1358 }
1359 audio_policy_forced_cfg_t forceUseForComm =
1360 mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION);
1361 // do not change in call volume if bluetooth is connected and vice versa
1362 if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) ||
1363 (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) {
1364 ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
1365 stream, forceUseForComm);
1366 return INVALID_OPERATION;
1367 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001368
Sharad Sangle36781612015-05-28 16:15:16 +05301369 if (device == AUDIO_DEVICE_NONE) {
1370 device = outputDesc->device();
1371 }
1372
1373 float volumeDb = computeVolume(stream, index, device);
1374 if (outputDesc->isFixedVolume(device)) {
1375 volumeDb = 0.0f;
1376 }
1377
1378 outputDesc->setVolume(volumeDb, stream, device, delayMs, force);
1379
1380 if (stream == AUDIO_STREAM_VOICE_CALL ||
1381 stream == AUDIO_STREAM_BLUETOOTH_SCO) {
1382 float voiceVolume;
1383 // Force voice volume to max for bluetooth SCO as volume is managed by the headset
1384 if (stream == AUDIO_STREAM_VOICE_CALL) {
Ashish Jain40cab3a2016-03-23 11:14:14 +05301385 voiceVolume = (float)index/(float)mVolumeCurves->getVolumeIndexMax(stream);
Sharad Sangle36781612015-05-28 16:15:16 +05301386 } else {
1387 voiceVolume = 1.0;
1388 }
1389
1390 if (voiceVolume != mLastVoiceVolume && ((outputDesc == mPrimaryOutput) ||
1391 isDirectOutput(outputDesc->mIoHandle) || device & AUDIO_DEVICE_OUT_ALL_USB)) {
1392 mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
1393 mLastVoiceVolume = voiceVolume;
1394 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301395#ifdef FM_POWER_OPT
1396 } else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() &&
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08001397 outputDesc == mPrimaryOutput && mFMIsActive) {
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001398 /* Avoid unnecessary set_parameter calls as it puts the primary
1399 outputs FastMixer in HOT_IDLE leading to breaks in audio */
1400 if (volumeDb != mPrevFMVolumeDb) {
1401 mPrevFMVolumeDb = volumeDb;
1402 AudioParameter param = AudioParameter();
1403 param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb));
Mingming Yin1433cc62016-01-04 14:58:00 -08001404 //Double delayMs to avoid sound burst while device switch.
1405 mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs*2);
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001406 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301407#endif /* FM_POWER_OPT end */
Sharad Sangle36781612015-05-28 16:15:16 +05301408 }
1409
1410 return NO_ERROR;
1411}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001412
Sharad Sangle36781612015-05-28 16:15:16 +05301413bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) {
1414 for (size_t i = 0; i < mOutputs.size(); i++) {
1415 audio_io_handle_t curOutput = mOutputs.keyAt(i);
1416 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1417 if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
1418 return true;
1419 }
1420 }
1421 return false;
1422}
vivek mehta0ea887a2015-08-26 14:01:20 -07001423
Sharad Sangle75170722016-11-21 16:21:06 +05301424bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate)
Ashish Jainac510a72016-04-28 12:22:58 +05301425{
Ashish Jain771d02f2016-10-27 22:35:46 +05301426 bool playerDirectPCM = false; // Output request for Track created by mediaplayer
1427 bool trackDirectPCM = false; // Output request for track created by other apps
Ashish Jain27564312016-11-14 14:58:06 +05301428 bool offloadDisabled = property_get_bool("audio.offload.disable", false);
Ashish Jainac510a72016-04-28 12:22:58 +05301429
Ashish Jain771d02f2016-10-27 22:35:46 +05301430 // Direct PCM is allowed only if
1431 // In case of mediaPlayer playback
1432 // 16 bit direct pcm or 24bit direct PCM property is set and
1433 // the FLAG requested is DIRECT_PCM ( NuPlayer case) or
1434 // In case of AudioTracks created by apps
1435 // track offload is enabled and FLAG requested is FLAG_NONE.
1436
Ashish Jain27564312016-11-14 14:58:06 +05301437 if (offloadDisabled) {
1438 ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled);
1439 }
1440
Ashish Jain771d02f2016-10-27 22:35:46 +05301441 if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
1442 if (bitWidth == 24 || bitWidth == 32)
1443 playerDirectPCM =
1444 property_get_bool("audio.offload.pcm.24bit.enable", false);
1445 else
1446 playerDirectPCM =
1447 property_get_bool("audio.offload.pcm.16bit.enable", false);
1448 // Reset flag to NONE so that we can still reuse direct pcm criteria check
1449 // in getOutputforDevice
1450 *flags = AUDIO_OUTPUT_FLAG_NONE;
Sharad Sangle75170722016-11-21 16:21:06 +05301451 } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) {
Ashish Jain771d02f2016-10-27 22:35:46 +05301452 trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
1453 }
1454
Ashish Jain27564312016-11-14 14:58:06 +05301455 ALOGI("Direct PCM %s for this request",
1456 (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled");
1457
1458 return (!offloadDisabled && (trackDirectPCM || playerDirectPCM));
Ashish Jainac510a72016-04-28 12:22:58 +05301459}
1460
vivek mehta0ea887a2015-08-26 14:01:20 -07001461status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
1462 audio_io_handle_t *output,
1463 audio_session_t session,
1464 audio_stream_type_t *stream,
1465 uid_t uid,
1466 uint32_t samplingRate,
1467 audio_format_t format,
1468 audio_channel_mask_t channelMask,
1469 audio_output_flags_t flags,
1470 audio_port_handle_t selectedDeviceId,
1471 const audio_offload_info_t *offloadInfo)
1472{
1473 audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
1474
Ashish Jainac510a72016-04-28 12:22:58 +05301475 uint32_t bitWidth = (audio_bytes_per_sample(format) * 8);
Alexy Joseph0ac09032015-10-16 15:57:53 -07001476
Alexy Joseph0ac09032015-10-16 15:57:53 -07001477
Sharad Sangle75170722016-11-21 16:21:06 +05301478 if (tryForDirectPCM(bitWidth, &flags, samplingRate) &&
Ashish Jain27564312016-11-14 14:58:06 +05301479 (offloadInfo == NULL)) {
vivek mehta0ea887a2015-08-26 14:01:20 -07001480
vivek mehta0ea887a2015-08-26 14:01:20 -07001481 tOffloadInfo.sample_rate = samplingRate;
1482 tOffloadInfo.channel_mask = channelMask;
1483 tOffloadInfo.format = format;
1484 tOffloadInfo.stream_type = *stream;
Ashish Jainac510a72016-04-28 12:22:58 +05301485 tOffloadInfo.bit_width = bitWidth;
vivek mehta0ea887a2015-08-26 14:01:20 -07001486 if (attr != NULL) {
1487 ALOGV("found attribute .. setting usage %d ", attr->usage);
1488 tOffloadInfo.usage = attr->usage;
1489 } else {
Alexy Joseph0ac09032015-10-16 15:57:53 -07001490 ALOGI("%s:: attribute is NULL .. no usage set", __func__);
vivek mehta0ea887a2015-08-26 14:01:20 -07001491 }
1492 offloadInfo = &tOffloadInfo;
1493 }
1494
1495 return AudioPolicyManager::getOutputForAttr(attr, output, session, stream,
1496 (uid_t)uid, (uint32_t)samplingRate,
1497 format, (audio_channel_mask_t)channelMask,
1498 flags, (audio_port_handle_t)selectedDeviceId,
1499 offloadInfo);
1500}
1501
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001502audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice(
1503 audio_devices_t device,
Sharad Sangle36781612015-05-28 16:15:16 +05301504 audio_session_t session __unused,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001505 audio_stream_type_t stream,
1506 uint32_t samplingRate,
1507 audio_format_t format,
1508 audio_channel_mask_t channelMask,
1509 audio_output_flags_t flags,
1510 const audio_offload_info_t *offloadInfo)
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001511{
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001512 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001513 status_t status;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001514
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001515#ifdef AUDIO_POLICY_TEST
1516 if (mCurOutput != 0) {
1517 ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d",
1518 mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
1519
1520 if (mTestOutputs[mCurOutput] == 0) {
1521 ALOGV("getOutput() opening test output");
Sharad Sangle36781612015-05-28 16:15:16 +05301522 sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL,
1523 mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001524 outputDesc->mDevice = mTestDevice;
1525 outputDesc->mLatency = mTestLatencyMs;
1526 outputDesc->mFlags =
1527 (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0);
1528 outputDesc->mRefCount[stream] = 0;
1529 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1530 config.sample_rate = mTestSamplingRate;
1531 config.channel_mask = mTestChannels;
1532 config.format = mTestFormat;
1533 if (offloadInfo != NULL) {
1534 config.offload_info = *offloadInfo;
1535 }
1536 status = mpClientInterface->openOutput(0,
1537 &mTestOutputs[mCurOutput],
1538 &config,
1539 &outputDesc->mDevice,
1540 String8(""),
1541 &outputDesc->mLatency,
1542 outputDesc->mFlags);
1543 if (status == NO_ERROR) {
1544 outputDesc->mSamplingRate = config.sample_rate;
1545 outputDesc->mFormat = config.format;
1546 outputDesc->mChannelMask = config.channel_mask;
1547 AudioParameter outputCmd = AudioParameter();
1548 outputCmd.addInt(String8("set_id"),mCurOutput);
1549 mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString());
1550 addOutput(mTestOutputs[mCurOutput], outputDesc);
1551 }
1552 }
1553 return mTestOutputs[mCurOutput];
1554 }
1555#endif //AUDIO_POLICY_TEST
Sharad Sangle36781612015-05-28 16:15:16 +05301556 if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) &&
1557 (stream != AUDIO_STREAM_MUSIC)) {
1558 // compress should not be used for non-music streams
1559 ALOGE("Offloading only allowed with music stream");
1560 return 0;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301561 }
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301562
1563 if ((stream == AUDIO_STREAM_VOICE_CALL) &&
1564 (channelMask == 1) &&
Shiv Maliyappanahallid77d3b32016-02-02 13:45:50 -08001565 (samplingRate == 8000 || samplingRate == 16000 ||
1566 samplingRate == 32000 || samplingRate == 48000)) {
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301567 // Allow Voip direct output only if:
1568 // audio mode is MODE_IN_COMMUNCATION; AND
1569 // voip output is not opened already; AND
1570 // requested sample rate matches with that of voip input stream (if opened already)
1571 int value = 0;
1572 uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1;
1573 String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1574 String8("audio_mode"));
1575 AudioParameter result = AudioParameter(valueStr);
1576 if (result.getInt(String8("audio_mode"), value) == NO_ERROR) {
1577 mode = value;
1578 }
1579
1580 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1581 String8("voip_out_stream_count"));
1582 result = AudioParameter(valueStr);
1583 if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) {
1584 voipOutCount = value;
1585 }
1586
1587 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1588 String8("voip_sample_rate"));
1589 result = AudioParameter(valueStr);
1590 if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) {
1591 voipSampleRate = value;
1592 }
1593
1594 if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) &&
1595 ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) {
1596 if (audio_is_linear_pcm(format)) {
1597 char propValue[PROPERTY_VALUE_MAX] = {0};
1598 property_get("use.voice.path.for.pcm.voip", propValue, "0");
1599 bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true"));
1600 if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) {
Karthik Reddy Katta3fb9be72015-11-25 11:18:27 +05301601 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_VOIP_RX |
1602 AUDIO_OUTPUT_FLAG_DIRECT);
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301603 ALOGD("Set VoIP and Direct output flags for PCM format");
1604 }
1605 }
1606 }
1607 }
1608
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301609#ifdef VOICE_CONCURRENCY
1610 char propValue[PROPERTY_VALUE_MAX];
1611 bool prop_play_enabled=false, prop_voip_enabled = false;
1612
1613 if(property_get("voice.playback.conc.disabled", propValue, NULL)) {
1614 prop_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001615 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301616
1617 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1618 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1619 }
1620
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301621 bool isDeepBufferFallBackNeeded =
1622 ((AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags);
1623 bool isFastFallBackNeeded =
1624 ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags);
1625
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301626 if (prop_play_enabled && mvoice_call_state) {
1627 //check if voice call is active / running in background
1628 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1629 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1630 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1631 {
1632 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1633 if(prop_voip_enabled) {
1634 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1635 flags );
1636 return 0;
1637 }
1638 }
1639 else {
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301640 if (isFastFallBackNeeded &&
1641 (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301642 ALOGD("voice_conc:IN call mode adding ULL flags .. flags: %x ", flags );
1643 flags = AUDIO_OUTPUT_FLAG_FAST;
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301644 } else if (isDeepBufferFallBackNeeded &&
1645 (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301646 if (AUDIO_STREAM_MUSIC == stream) {
1647 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1648 ALOGD("voice_conc:IN call mode adding deep-buffer flags %x ", flags );
1649 }
1650 else {
1651 flags = AUDIO_OUTPUT_FLAG_FAST;
1652 ALOGD("voice_conc:IN call mode adding fast flags %x ", flags );
1653 }
1654 }
1655 }
1656 }
1657 } else if (prop_voip_enabled && mvoice_call_state) {
1658 //check if voice call is active / running in background
1659 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1660 //return only ULL ouput
1661 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1662 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1663 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1664 {
1665 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1666 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1667 flags );
1668 return 0;
1669 }
1670 }
1671 }
1672#endif
1673#ifdef RECORD_PLAY_CONCURRENCY
1674 char recConcPropValue[PROPERTY_VALUE_MAX];
1675 bool prop_rec_play_enabled = false;
1676
1677 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
1678 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
1679 }
1680 if ((prop_rec_play_enabled) &&
Lalit Kansara33918092016-12-06 22:42:26 +05301681 ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301682 if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) {
1683 if (AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1684 // allow VoIP using voice path
1685 // Do nothing
1686 } else if((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1687 ALOGD("voice_conc:MODE_IN_COMM is setforcing deep buffer output for non ULL... flags: %x", flags);
1688 // use deep buffer path for all non ULL outputs
1689 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1690 }
1691 } else if ((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1692 ALOGD("voice_conc:Record mode is on forcing deep buffer output for non ULL... flags: %x ", flags);
1693 // use deep buffer path for all non ULL outputs
1694 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1695 }
1696 }
1697 if (prop_rec_play_enabled &&
1698 (stream == AUDIO_STREAM_ENFORCED_AUDIBLE)) {
1699 ALOGD("Record conc is on forcing ULL output for ENFORCED_AUDIBLE");
1700 flags = AUDIO_OUTPUT_FLAG_FAST;
1701 }
1702#endif
1703
Sharad Sangle4509cef2015-08-19 20:47:12 +05301704#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
Sharad Sangle36781612015-05-28 16:15:16 +05301705 /*
1706 * WFD audio routes back to target speaker when starting a ringtone playback.
1707 * This is because primary output is reused for ringtone, so output device is
1708 * updated based on SONIFICATION strategy for both ringtone and music playback.
1709 * The same issue is not seen on remoted_submix HAL based WFD audio because
1710 * primary output is not reused and a new output is created for ringtone playback.
1711 * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is
1712 * a non-music stream playback on WFD, so primary output is not reused for ringtone.
1713 */
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001714 audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types();
1715 if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY)
1716 && (stream != AUDIO_STREAM_MUSIC)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301717 ALOGD("WFD audio: use OUTPUT_FLAG_FAST for non music stream. flags:%x", flags );
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001718 //For voip paths
1719 if(flags & AUDIO_OUTPUT_FLAG_DIRECT)
1720 flags = AUDIO_OUTPUT_FLAG_DIRECT;
1721 else //route every thing else to ULL path
1722 flags = AUDIO_OUTPUT_FLAG_FAST;
1723 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301724#endif
1725
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001726 // open a direct output if required by specified parameters
vivek mehta0ea887a2015-08-26 14:01:20 -07001727 // force direct flag if offload flag is set: offloading implies a direct output stream
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001728 // and all common behaviors are driven by checking only the direct flag
1729 // this should normally be set appropriately in the policy configuration file
1730 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
1731 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1732 }
1733 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1734 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1735 }
vivek mehta0ea887a2015-08-26 14:01:20 -07001736
vivek mehta4b0d8192015-10-16 00:25:59 -07001737 bool forced_deep = false;
Sharad Sangle36781612015-05-28 16:15:16 +05301738 // only allow deep buffering for music stream type
1739 if (stream != AUDIO_STREAM_MUSIC) {
1740 flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
Sharad Sangle497aef82015-08-03 17:55:48 +05301741 } else if (/* stream == AUDIO_STREAM_MUSIC && */
1742 flags == AUDIO_OUTPUT_FLAG_NONE &&
1743 property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
vivek mehtac984b992015-11-25 13:28:55 -08001744 forced_deep = true;
Sharad Sangle36781612015-05-28 16:15:16 +05301745 }
Sharad Sangle497aef82015-08-03 17:55:48 +05301746
Sharad Sangle36781612015-05-28 16:15:16 +05301747 if (stream == AUDIO_STREAM_TTS) {
1748 flags = AUDIO_OUTPUT_FLAG_TTS;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001749 }
1750
Zhou Song2b3d1552016-03-21 17:21:04 +08001751 // check if direct output for track offload already exits
1752 bool is_track_offload_active = false;
1753 for (size_t i = 0; i < mOutputs.size(); i++) {
1754 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1755 if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
1756 is_track_offload_active = true;
1757 ALOGD("Track offload already active");
1758 break;
1759 }
1760 }
1761
vivek mehta4b0d8192015-10-16 00:25:59 -07001762 // Do offload magic here
vivek mehtac984b992015-11-25 13:28:55 -08001763 if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
1764 (stream == AUDIO_STREAM_MUSIC) &&
Zhou Song2b3d1552016-03-21 17:21:04 +08001765 (offloadInfo != NULL) && !is_track_offload_active &&
vivek mehta4b0d8192015-10-16 00:25:59 -07001766 ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
vivek mehtac984b992015-11-25 13:28:55 -08001767 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM);
vivek mehta4b0d8192015-10-16 00:25:59 -07001768 ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301769 }
1770
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001771 sp<IOProfile> profile;
1772
1773 // skip direct output selection if the request can obviously be attached to a mixed output
1774 // and not explicitly requested
vivek mehtac984b992015-11-25 13:28:55 -08001775 if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301776 audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX &&
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001777 audio_channel_count_from_out_mask(channelMask) <= 2) {
1778 goto non_direct_output;
1779 }
1780
1781 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
1782 // creating an offloaded track and tearing it down immediately after start when audioflinger
1783 // detects there is an active non offloadable effect.
1784 // FIXME: We should check the audio session here but we do not have it in this context.
1785 // This may prevent offloading in rare situations where effects are left active by apps
1786 // in the background.
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001787 //
1788 // Supplementary annotation:
1789 // For sake of track offload introduced, we need a rollback for both compress offload
1790 // and track offload use cases.
1791 if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) &&
1792 (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) {
1793 ALOGD("non offloadable effect is enabled, try with non direct output");
1794 goto non_direct_output;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001795 }
1796
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001797 profile = getProfileForDirectOutput(device,
1798 samplingRate,
1799 format,
1800 channelMask,
1801 (audio_output_flags_t)flags);
1802
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001803 if (profile != 0) {
vivek mehtac984b992015-11-25 13:28:55 -08001804
1805 if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301806 (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
vivek mehtac984b992015-11-25 13:28:55 -08001807 ALOGI("got Direct_PCM without requesting ... reject ");
1808 profile = NULL;
1809 goto non_direct_output;
1810 }
1811
Sharad Sangle36781612015-05-28 16:15:16 +05301812 sp<SwAudioOutputDescriptor> outputDesc = NULL;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001813
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001814 // if multiple concurrent offload decode is supported
1815 // do no check for reuse and also don't close previous output if its offload
1816 // previous output will be closed during track destruction
1817 if (!(property_get_bool("audio.offload.multiple.enabled", false) &&
1818 ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) {
1819 for (size_t i = 0; i < mOutputs.size(); i++) {
1820 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1821 if (!desc->isDuplicated() && (profile == desc->mProfile)) {
1822 outputDesc = desc;
1823 // reuse direct output if currently open and configured with same parameters
1824 if ((samplingRate == outputDesc->mSamplingRate) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301825 audio_formats_match(format, outputDesc->mFormat) &&
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001826 (channelMask == outputDesc->mChannelMask)) {
1827 outputDesc->mDirectOpenCount++;
1828 ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
1829 return mOutputs.keyAt(i);
1830 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001831 }
1832 }
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001833 // close direct output if currently open and configured with different parameters
1834 if (outputDesc != NULL) {
1835 closeOutput(outputDesc->mIoHandle);
1836 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001837 }
Sharad Sangle36781612015-05-28 16:15:16 +05301838
1839 // if the selected profile is offloaded and no offload info was specified,
1840 // create a default one
1841 audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER;
Ashish Jain40cab3a2016-03-23 11:14:14 +05301842 if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) {
Sharad Sangle36781612015-05-28 16:15:16 +05301843 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
1844 defaultOffloadInfo.sample_rate = samplingRate;
1845 defaultOffloadInfo.channel_mask = channelMask;
1846 defaultOffloadInfo.format = format;
1847 defaultOffloadInfo.stream_type = stream;
1848 defaultOffloadInfo.bit_rate = 0;
1849 defaultOffloadInfo.duration_us = -1;
1850 defaultOffloadInfo.has_video = true; // conservative
1851 defaultOffloadInfo.is_streaming = true; // likely
1852 offloadInfo = &defaultOffloadInfo;
1853 }
1854
1855 outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001856 outputDesc->mDevice = device;
1857 outputDesc->mLatency = 0;
Sharad Sangle36781612015-05-28 16:15:16 +05301858 outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001859 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1860 config.sample_rate = samplingRate;
1861 config.channel_mask = channelMask;
1862 config.format = format;
1863 if (offloadInfo != NULL) {
1864 config.offload_info = *offloadInfo;
1865 }
Sharad Sangle36781612015-05-28 16:15:16 +05301866 status = mpClientInterface->openOutput(profile->getModuleHandle(),
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001867 &output,
1868 &config,
1869 &outputDesc->mDevice,
1870 String8(""),
1871 &outputDesc->mLatency,
1872 outputDesc->mFlags);
1873
1874 // only accept an output with the requested parameters
1875 if (status != NO_ERROR ||
1876 (samplingRate != 0 && samplingRate != config.sample_rate) ||
Ashish Jain40cab3a2016-03-23 11:14:14 +05301877 (format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) ||
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001878 (channelMask != 0 && channelMask != config.channel_mask)) {
1879 ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
1880 "format %d %d, channelMask %04x %04x", output, samplingRate,
1881 outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
1882 outputDesc->mChannelMask);
1883 if (output != AUDIO_IO_HANDLE_NONE) {
1884 mpClientInterface->closeOutput(output);
1885 }
Sharad Sangle36781612015-05-28 16:15:16 +05301886 // fall back to mixer output if possible when the direct output could not be open
Ashish Jain40cab3a2016-03-23 11:14:14 +05301887 if (audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX) {
Sharad Sangle36781612015-05-28 16:15:16 +05301888 goto non_direct_output;
1889 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001890 return AUDIO_IO_HANDLE_NONE;
1891 }
1892 outputDesc->mSamplingRate = config.sample_rate;
1893 outputDesc->mChannelMask = config.channel_mask;
1894 outputDesc->mFormat = config.format;
1895 outputDesc->mRefCount[stream] = 0;
1896 outputDesc->mStopTime[stream] = 0;
1897 outputDesc->mDirectOpenCount = 1;
1898
1899 audio_io_handle_t srcOutput = getOutputForEffect();
1900 addOutput(output, outputDesc);
1901 audio_io_handle_t dstOutput = getOutputForEffect();
1902 if (dstOutput == output) {
Gao Jiedb057832015-11-12 08:51:22 +08001903#ifdef DOLBY_ENABLE
1904 status_t status = mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
1905 if (status == NO_ERROR) {
1906 for (size_t i = 0; i < mEffects.size(); i++) {
1907 sp<EffectDescriptor> desc = mEffects.valueAt(i);
1908 if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) {
1909 // update the mIo member of EffectDescriptor for the global effect
1910 ALOGV("%s updating mIo", __FUNCTION__);
1911 desc->mIo = dstOutput;
1912 }
1913 }
1914 } else {
1915 ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, srcOutput, dstOutput);
1916 }
1917#else // DOLBY_END
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001918 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
Gao Jiedb057832015-11-12 08:51:22 +08001919#endif // LINE_ADDED_BY_DOLBY
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001920 }
1921 mPreviousOutputs = mOutputs;
1922 ALOGV("getOutput() returns new direct output %d", output);
1923 mpClientInterface->onAudioPortListUpdate();
1924 return output;
1925 }
1926
1927non_direct_output:
Ashish Jain5fe12412016-04-18 18:44:17 +05301928
1929 // A request for HW A/V sync cannot fallback to a mixed output because time
1930 // stamps are embedded in audio data
1931 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1932 return AUDIO_IO_HANDLE_NONE;
1933 }
1934
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001935 // ignoring channel mask due to downmix capability in mixer
1936
1937 // open a non direct output
1938
1939 // for non direct outputs, only PCM is supported
1940 if (audio_is_linear_pcm(format)) {
1941 // get which output is suitable for the specified stream. The actual
1942 // routing change will happen when startOutput() will be called
1943 SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
1944
1945 // at this stage we should ignore the DIRECT flag as no direct output could be found earlier
1946 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT);
Ashish Jain660d3112016-06-20 10:16:51 +05301947
1948 if (forced_deep) {
1949 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
1950 ALOGI("setting force DEEP buffer now ");
1951 } else if(flags == AUDIO_OUTPUT_FLAG_NONE) {
1952 // no deep buffer playback is requested hence fallback to primary
1953 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_PRIMARY);
1954 ALOGI("FLAG None hence request for a primary output");
1955 }
1956
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001957 output = selectOutput(outputs, flags, format);
1958 }
1959 ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d,"
1960 "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
1961
vivek mehta0ea887a2015-08-26 14:01:20 -07001962 ALOGV("getOutputForDevice() returns output %d", output);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001963
1964 return output;
1965}
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301966
1967status_t AudioPolicyManagerCustom::getInputForAttr(const audio_attributes_t *attr,
1968 audio_io_handle_t *input,
1969 audio_session_t session,
1970 uid_t uid,
1971 uint32_t samplingRate,
1972 audio_format_t format,
1973 audio_channel_mask_t channelMask,
1974 audio_input_flags_t flags,
1975 audio_port_handle_t selectedDeviceId,
1976 input_type_t *inputType)
1977{
Ashish Jain40cab3a2016-03-23 11:14:14 +05301978 audio_source_t inputSource;
1979 inputSource = attr->source;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301980#ifdef VOICE_CONCURRENCY
1981
1982 char propValue[PROPERTY_VALUE_MAX];
1983 bool prop_rec_enabled=false, prop_voip_enabled = false;
1984
1985 if(property_get("voice.record.conc.disabled", propValue, NULL)) {
1986 prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1987 }
1988
1989 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1990 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1991 }
1992
1993 if (prop_rec_enabled && mvoice_call_state) {
1994 //check if voice call is active / running in background
1995 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1996 //Need to block input request
1997 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1998 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
1999 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
2000 {
2001 switch(inputSource) {
2002 case AUDIO_SOURCE_VOICE_UPLINK:
2003 case AUDIO_SOURCE_VOICE_DOWNLINK:
2004 case AUDIO_SOURCE_VOICE_CALL:
2005 ALOGD("voice_conc:Creating input during incall mode for inputSource: %d",
2006 inputSource);
2007 break;
2008
2009 case AUDIO_SOURCE_VOICE_COMMUNICATION:
2010 if(prop_voip_enabled) {
2011 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
2012 inputSource);
2013 return NO_INIT;
2014 }
2015 break;
2016 default:
2017 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
2018 inputSource);
2019 return NO_INIT;
2020 }
2021 }
2022 }//check for VoIP flag
2023 else if(prop_voip_enabled && mvoice_call_state) {
2024 //check if voice call is active / running in background
2025 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
2026 //Need to block input request
2027 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
2028 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
2029 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
2030 {
2031 if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) {
2032 ALOGD("BLOCKING VoIP request during incall mode for inputSource: %d ",inputSource);
2033 return NO_INIT;
2034 }
2035 }
2036 }
2037
2038#endif
2039
2040 return AudioPolicyManager::getInputForAttr(attr,
2041 input,
2042 session,
2043 uid,
2044 samplingRate,
2045 format,
2046 channelMask,
2047 flags,
2048 selectedDeviceId,
2049 inputType);
2050}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002051
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302052status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,
2053 audio_session_t session)
2054{
2055 ALOGV("startInput() input %d", input);
2056 ssize_t index = mInputs.indexOfKey(input);
2057 if (index < 0) {
2058 ALOGW("startInput() unknown input %d", input);
2059 return BAD_VALUE;
2060 }
2061 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index);
2062
Ashish Jain40cab3a2016-03-23 11:14:14 +05302063 sp<AudioSession> audioSession = inputDesc->getAudioSession(session);
2064 if (audioSession == 0) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302065 ALOGW("startInput() unknown session %d on input %d", session, input);
2066 return BAD_VALUE;
2067 }
2068
2069 // virtual input devices are compatible with other input devices
2070 if (!is_virtual_input_device(inputDesc->mDevice)) {
2071
2072 // for a non-virtual input device, check if there is another (non-virtual) active input
2073 audio_io_handle_t activeInput = mInputs.getActiveInput();
2074 if (activeInput != 0 && activeInput != input) {
2075
2076 // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed,
2077 // otherwise the active input continues and the new input cannot be started.
2078 sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302079 if ((activeDesc->inputSource() == AUDIO_SOURCE_HOTWORD) &&
2080 !activeDesc->hasPreemptedSession(session)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302081 ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302082 //FIXME: consider all active sessions
2083 AudioSessionCollection activeSessions = activeDesc->getActiveAudioSessions();
2084 audio_session_t activeSession = activeSessions.keyAt(0);
2085 SortedVector<audio_session_t> sessions =
2086 activeDesc->getPreemptedSessions();
2087 sessions.add(activeSession);
2088 inputDesc->setPreemptedSessions(sessions);
2089 stopInput(activeInput, activeSession);
2090 releaseInput(activeInput, activeSession);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302091 } else {
2092 ALOGE("startInput(%d) failed: other input %d already started", input, activeInput);
2093 return INVALID_OPERATION;
2094 }
2095 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05302096 // Do not allow capture if an active voice call is using a software patch and
2097 // the call TX source device is on the same HW module.
2098 // FIXME: would be better to refine to only inputs whose profile connects to the
2099 // call TX device but this information is not in the audio patch
2100 if (mCallTxPatch != 0 &&
2101 inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) {
2102 return INVALID_OPERATION;
2103 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302104 }
2105
2106 // Routing?
2107 mInputRoutes.incRouteActivity(session);
2108#ifdef RECORD_PLAY_CONCURRENCY
2109 mIsInputRequestOnProgress = true;
2110
2111 char getPropValue[PROPERTY_VALUE_MAX];
2112 bool prop_rec_play_enabled = false;
2113
2114 if (property_get("rec.playback.conc.disabled", getPropValue, NULL)) {
2115 prop_rec_play_enabled = atoi(getPropValue) || !strncmp("true", getPropValue, 4);
2116 }
2117
Lalit Kansara33918092016-12-06 22:42:26 +05302118 if ((prop_rec_play_enabled) &&(mInputs.activeInputsCountOnDevices() == 0)){
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302119 // send update to HAL on record playback concurrency
2120 AudioParameter param = AudioParameter();
2121 param.add(String8("rec_play_conc_on"), String8("true"));
2122 ALOGD("startInput() setParameters rec_play_conc is setting to ON ");
2123 mpClientInterface->setParameters(0, param.toString());
2124
2125 // Call invalidate to reset all opened non ULL audio tracks
2126 // Move tracks associated to this strategy from previous output to new output
2127 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
2128 // Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder)
Sharad Sangle4509cef2015-08-19 20:47:12 +05302129 if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302130 ALOGD("Invalidate on releaseInput for stream :: %d ", i);
2131 //FIXME see fixme on name change
2132 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2133 }
2134 }
2135 // close compress tracks
2136 for (size_t i = 0; i < mOutputs.size(); i++) {
2137 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
2138 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
2139 ALOGD("ouput desc / profile is NULL");
2140 continue;
2141 }
2142 if (outputDesc->mProfile->mFlags
2143 & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
2144 // close compress sessions
2145 ALOGD("calling closeOutput on record conc for COMPRESS output");
2146 closeOutput(mOutputs.keyAt(i));
2147 }
2148 }
Ashish Jaine4a22d52016-06-22 11:55:08 +05302149 // If effects where present on any of the above closed outputs,
2150 // audioflinger moved them to the primary output by default
2151 // move them back to the appropriate output.
2152 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302153 }
2154#endif
2155
Ashish Jain40cab3a2016-03-23 11:14:14 +05302156 if (!inputDesc->isActive() || mInputRoutes.hasRouteChanged(session)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302157 // if input maps to a dynamic policy with an activity listener, notify of state change
Ashish Jain630c5e12016-04-18 11:50:21 +05302158 if ((inputDesc->mPolicyMix != NULL)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302159 && ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) {
Ashish Jain5fe12412016-04-18 18:44:17 +05302160 mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress,
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302161 MIX_STATE_MIXING);
Ashish Jain630c5e12016-04-18 11:50:21 +05302162 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302163
Lalit Kansara33918092016-12-06 22:42:26 +05302164 if (mInputs.activeInputsCountOnDevices() == 0) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302165 SoundTrigger::setCaptureState(true);
2166 }
2167 setInputDevice(input, getNewInputDevice(input), true /* force */);
2168
2169 // automatically enable the remote submix output when input is started if not
2170 // used by a policy mix of type MIX_TYPE_RECORDERS
2171 // For remote submix (a virtual device), we open only one input per capture request.
2172 if (audio_is_remote_submix_device(inputDesc->mDevice)) {
2173 String8 address = String8("");
2174 if (inputDesc->mPolicyMix == NULL) {
2175 address = String8("0");
Ashish Jain630c5e12016-04-18 11:50:21 +05302176 } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) {
Ashish Jain5fe12412016-04-18 18:44:17 +05302177 address = inputDesc->mPolicyMix->mDeviceAddress;
Ashish Jain630c5e12016-04-18 11:50:21 +05302178 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302179 if (address != "") {
2180 setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
2181 AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
2182 address, "remote-submix");
2183 }
2184 }
2185 }
2186
Ashish Jain40cab3a2016-03-23 11:14:14 +05302187 ALOGV("AudioPolicyManager::startInput() input source = %d", audioSession->inputSource());
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302188
Ashish Jain40cab3a2016-03-23 11:14:14 +05302189 audioSession->changeActiveCount(1);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302190#ifdef RECORD_PLAY_CONCURRENCY
2191 mIsInputRequestOnProgress = false;
2192#endif
2193 return NO_ERROR;
2194}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002195
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302196status_t AudioPolicyManagerCustom::stopInput(audio_io_handle_t input,
2197 audio_session_t session)
2198{
2199 status_t status;
2200 status = AudioPolicyManager::stopInput(input, session);
2201#ifdef RECORD_PLAY_CONCURRENCY
2202 char propValue[PROPERTY_VALUE_MAX];
2203 bool prop_rec_play_enabled = false;
2204
2205 if (property_get("rec.playback.conc.disabled", propValue, NULL)) {
2206 prop_rec_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
2207 }
2208
Lalit Kansara33918092016-12-06 22:42:26 +05302209 if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302210
2211 //send update to HAL on record playback concurrency
2212 AudioParameter param = AudioParameter();
2213 param.add(String8("rec_play_conc_on"), String8("false"));
2214 ALOGD("stopInput() setParameters rec_play_conc is setting to OFF ");
2215 mpClientInterface->setParameters(0, param.toString());
2216
2217 //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL
2218 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
2219 //Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder stop tone)
2220 if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE) && (i != AUDIO_STREAM_PATCH)) {
2221 ALOGD(" Invalidate on stopInput for stream :: %d ", i);
2222 //FIXME see fixme on name change
2223 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2224 }
2225 }
2226 }
2227#endif
2228 return status;
2229}
2230
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302231void AudioPolicyManagerCustom::closeAllInputs() {
2232 bool patchRemoved = false;
2233
Dhanalakshmi Siddanibfeca7f2015-10-08 15:17:11 +05302234 for(size_t input_index = mInputs.size(); input_index > 0; input_index--) {
2235 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index-1);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302236 ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->getPatchHandle());
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302237 if (patch_index >= 0) {
2238 sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302239 status_t status;
2240 status = mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302241 mAudioPatches.removeItemsAt(patch_index);
2242 patchRemoved = true;
2243 }
Haynes Mathew George2e4655a2017-01-05 15:01:53 -08002244 mpClientInterface->closeInput(mInputs.keyAt(input_index-1));
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302245 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05302246 mInputs.clear();
2247 SoundTrigger::setCaptureState(false);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302248 nextAudioPortGeneration();
2249
2250 if (patchRemoved) {
2251 mpClientInterface->onAudioPatchListUpdate();
2252 }
2253}
2254
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302255AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
Sharad Sangle4509cef2015-08-19 20:47:12 +05302256 : AudioPolicyManager(clientInterface),
2257 mHdmiAudioDisabled(false),
2258 mHdmiAudioEvent(false),
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08002259 mPrevPhoneState(0),
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08002260 mPrevFMVolumeDb(0.0f),
2261 mFMIsActive(false)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302262{
Ashish Jain40cab3a2016-03-23 11:14:14 +05302263
Satya Krishna Pindiproli8f83f102016-06-21 17:56:14 +05302264#ifdef USE_XML_AUDIO_POLICY_CONF
2265 ALOGD("USE_XML_AUDIO_POLICY_CONF is TRUE");
2266#else
2267 ALOGD("USE_XML_AUDIO_POLICY_CONF is FALSE");
2268#endif
2269
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302270#ifdef RECORD_PLAY_CONCURRENCY
2271 mIsInputRequestOnProgress = false;
2272#endif
2273
2274
2275#ifdef VOICE_CONCURRENCY
2276 mFallBackflag = getFallBackPath();
2277#endif
2278}
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07002279}