blob: c258a399324bcbc3cb91db53f875c78aabe0638a [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05302 * Copyright (c) 2013-2017 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
Garmond Leungfcb00d92017-01-31 11:12:47 -080071#ifndef AUDIO_OUTPUT_FLAG_VOIP_RX
72#define AUDIO_OUTPUT_FLAG_VOIP_RX 0x800
73#endif
74
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070075namespace android {
Sharad Sanglec66b9ca2016-12-21 18:40:54 +053076/*audio policy: workaround for truncated touch sounds*/
77//FIXME: workaround for truncated touch sounds
78// to be removed when the problem is handled by system UI
79#define TOUCH_SOUND_FIXED_DELAY_MS 100
Sharad Sanglec5766ff2015-06-04 20:24:10 +053080#ifdef VOICE_CONCURRENCY
81audio_output_flags_t AudioPolicyManagerCustom::getFallBackPath()
82{
83 audio_output_flags_t flag = AUDIO_OUTPUT_FLAG_FAST;
84 char propValue[PROPERTY_VALUE_MAX];
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070085
Sharad Sanglec5766ff2015-06-04 20:24:10 +053086 if (property_get("voice.conc.fallbackpath", propValue, NULL)) {
87 if (!strncmp(propValue, "deep-buffer", 11)) {
88 flag = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
89 }
90 else if (!strncmp(propValue, "fast", 4)) {
91 flag = AUDIO_OUTPUT_FLAG_FAST;
92 }
93 else {
94 ALOGD("voice_conc:not a recognised path(%s) in prop voice.conc.fallbackpath",
95 propValue);
96 }
97 }
98 else {
99 ALOGD("voice_conc:prop voice.conc.fallbackpath not set");
100 }
101
102 ALOGD("voice_conc:picked up flag(0x%x) from prop voice.conc.fallbackpath",
103 flag);
104
105 return flag;
106}
107#endif /*VOICE_CONCURRENCY*/
Ashish Jaine4a22d52016-06-22 11:55:08 +0530108
109void AudioPolicyManagerCustom::moveGlobalEffect()
110{
111 audio_io_handle_t dstOutput = getOutputForEffect();
112 if (hasPrimaryOutput() && dstOutput != mPrimaryOutput->mIoHandle) {
113#ifdef DOLBY_ENABLE
114 status_t status =
115 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX,
116 mPrimaryOutput->mIoHandle,
117 dstOutput);
118 if (status == NO_ERROR) {
119 for (size_t i = 0; i < mEffects.size(); i++) {
120 sp<EffectDescriptor> desc = mEffects.valueAt(i);
121 if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) {
122 // update the mIo member of EffectDescriptor
123 // for the global effect
124 ALOGV("%s updating mIo", __FUNCTION__);
125 desc->mIo = dstOutput;
126 }
127 }
128 } else {
129 ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__,
130 mPrimaryOutput->mIoHandle, dstOutput);
131 }
132#else // DOLBY_END
133 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX,
134 mPrimaryOutput->mIoHandle, dstOutput);
135#endif
136 }
137}
138
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700139// ----------------------------------------------------------------------------
140// AudioPolicyInterface implementation
141// ----------------------------------------------------------------------------
Sharad Sangle36781612015-05-28 16:15:16 +0530142extern "C" AudioPolicyInterface* createAudioPolicyManager(
143 AudioPolicyClientInterface *clientInterface)
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700144{
Sharad Sangle36781612015-05-28 16:15:16 +0530145 return new AudioPolicyManagerCustom(clientInterface);
146}
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700147
Sharad Sangle36781612015-05-28 16:15:16 +0530148extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
149{
150 delete interface;
151}
152
153status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t device,
154 audio_policy_dev_state_t state,
155 const char *device_address,
156 const char *device_name)
157{
Ashish Jain40cab3a2016-03-23 11:14:14 +0530158 ALOGD("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s",
Sharad Sangle36781612015-05-28 16:15:16 +0530159 device, state, device_address, device_name);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700160
161 // connect/disconnect only 1 device at a time
162 if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE;
163
Sharad Sangle36781612015-05-28 16:15:16 +0530164 sp<DeviceDescriptor> devDesc =
165 mHwModules.getDeviceDescriptor(device, device_address, device_name);
166
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700167 // handle output devices
168 if (audio_is_output_device(device)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700169 SortedVector <audio_io_handle_t> outputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700170
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700171 ssize_t index = mAvailableOutputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700172
173 // save a copy of the opened output descriptors before any output is opened or closed
174 // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies()
175 mPreviousOutputs = mOutputs;
176 switch (state)
177 {
178 // handle output device connection
Sharad Sangle36781612015-05-28 16:15:16 +0530179 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700180 if (index >= 0) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530181#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
182 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
183 if (!strncmp(device_address, "hdmi_spkr", 9)) {
184 mHdmiAudioDisabled = false;
185 } else {
186 mHdmiAudioEvent = true;
187 }
188 }
189#endif
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700190 ALOGW("setDeviceConnectionState() device already connected: %x", device);
191 return INVALID_OPERATION;
192 }
193 ALOGV("setDeviceConnectionState() connecting device %x", device);
194
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700195 // register new device as available
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700196 index = mAvailableOutputDevices.add(devDesc);
Sharad Sangle4509cef2015-08-19 20:47:12 +0530197#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
198 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
199 if (!strncmp(device_address, "hdmi_spkr", 9)) {
200 mHdmiAudioDisabled = false;
201 } else {
202 mHdmiAudioEvent = true;
203 }
204 if (mHdmiAudioDisabled || !mHdmiAudioEvent) {
205 mAvailableOutputDevices.remove(devDesc);
206 ALOGW("HDMI sink not connected, do not route audio to HDMI out");
207 return INVALID_OPERATION;
208 }
209 }
210#endif
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700211 if (index >= 0) {
Sharad Sangle36781612015-05-28 16:15:16 +0530212 sp<HwModule> module = mHwModules.getModuleForDevice(device);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700213 if (module == 0) {
214 ALOGD("setDeviceConnectionState() could not find HW module for device %08x",
215 device);
216 mAvailableOutputDevices.remove(devDesc);
217 return INVALID_OPERATION;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700218 }
Sharad Sangle36781612015-05-28 16:15:16 +0530219 mAvailableOutputDevices[index]->attach(module);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700220 } else {
221 return NO_MEMORY;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700222 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700223
Garmond Leungfcb00d92017-01-31 11:12:47 -0800224 // Before checking outputs, broadcast connect event to allow HAL to retrieve dynamic
225 // parameters on newly connected devices (instead of opening the outputs...)
226 broadcastDeviceConnectionState(device, state, devDesc->mAddress);
227
Sharad Sangle36781612015-05-28 16:15:16 +0530228 if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700229 mAvailableOutputDevices.remove(devDesc);
Garmond Leungfcb00d92017-01-31 11:12:47 -0800230
231 broadcastDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
232 devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700233 return INVALID_OPERATION;
234 }
Sharad Sangle36781612015-05-28 16:15:16 +0530235 // Propagate device availability to Engine
236 mEngine->setDeviceConnectionState(devDesc, state);
237
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700238 // outputs should never be empty here
239 ALOG_ASSERT(outputs.size() != 0, "setDeviceConnectionState():"
240 "checkOutputsForDevice() returned no outputs but status OK");
241 ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %zu outputs",
242 outputs.size());
Sharad Sangle36781612015-05-28 16:15:16 +0530243
Sharad Sangle36781612015-05-28 16:15:16 +0530244 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700245 // handle output device disconnection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700246 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
247 if (index < 0) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530248#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
249 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
250 if (!strncmp(device_address, "hdmi_spkr", 9)) {
251 mHdmiAudioDisabled = true;
252 } else {
253 mHdmiAudioEvent = false;
254 }
255 }
256#endif
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700257 ALOGW("setDeviceConnectionState() device not connected: %x", device);
258 return INVALID_OPERATION;
259 }
260
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700261 ALOGV("setDeviceConnectionState() disconnecting output device %x", device);
262
Sharad Sangle36781612015-05-28 16:15:16 +0530263 // Send Disconnect to HALs
Garmond Leungfcb00d92017-01-31 11:12:47 -0800264 broadcastDeviceConnectionState(device, state, devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700265
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700266 // remove device from available output devices
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700267 mAvailableOutputDevices.remove(devDesc);
Sharad Sangle4509cef2015-08-19 20:47:12 +0530268#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
269 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
270 if (!strncmp(device_address, "hdmi_spkr", 9)) {
271 mHdmiAudioDisabled = true;
272 } else {
273 mHdmiAudioEvent = false;
274 }
275 }
276#endif
Sharad Sangle36781612015-05-28 16:15:16 +0530277 checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress);
278
279 // Propagate device availability to Engine
280 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700281 } break;
282
283 default:
284 ALOGE("setDeviceConnectionState() invalid state: %x", state);
285 return BAD_VALUE;
286 }
287
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700288 // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP
289 // output is suspended before any tracks are moved to it
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700290 checkA2dpSuspend();
291 checkOutputForAllStrategies();
292 // outputs must be closed after checkOutputForAllStrategies() is executed
293 if (!outputs.isEmpty()) {
294 for (size_t i = 0; i < outputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530295 sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700296 // close unused outputs after device disconnection or direct outputs that have been
297 // opened by checkOutputsForDevice() to query dynamic parameters
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700298 if ((state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) ||
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700299 (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) &&
300 (desc->mDirectOpenCount == 0))) {
301 closeOutput(outputs[i]);
302 }
303 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700304 // check again after closing A2DP output to reset mA2dpSuspended if needed
305 checkA2dpSuspend();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700306 }
307
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530308#ifdef FM_POWER_OPT
309 // handle FM device connection state to trigger FM AFE loopback
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800310 if (device == AUDIO_DEVICE_OUT_FM && hasPrimaryOutput()) {
Mingming Yin2dd77c22016-01-06 18:02:42 -0800311 audio_devices_t newDevice = AUDIO_DEVICE_NONE;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530312 if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
313 mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, 1);
Mingming Yin2dd77c22016-01-06 18:02:42 -0800314 newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false)|AUDIO_DEVICE_OUT_FM);
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800315 mFMIsActive = true;
Zhou Songbd0264e2016-06-21 11:01:06 +0800316 mPrimaryOutput->mDevice = newDevice & ~AUDIO_DEVICE_OUT_FM;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530317 } else {
Mingming Yin2dd77c22016-01-06 18:02:42 -0800318 newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false));
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800319 mFMIsActive = false;
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +0530320 mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, -1);
321 }
322 AudioParameter param = AudioParameter();
323 param.addInt(String8("handle_fm"), (int)newDevice);
324 mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString());
325 }
326#endif /* FM_POWER_OPT end */
327
Zhou Songbd0264e2016-06-21 11:01:06 +0800328 updateDevicesAndOutputs();
329#ifdef DOLBY_ENABLE
330 // Before closing the opened outputs, update endpoint property with device capabilities
331 audio_devices_t audioOutputDevice = getDeviceForStrategy(getStrategy(AUDIO_STREAM_MUSIC), true);
332 mDolbyAudioPolicy.setEndpointSystemProperty(audioOutputDevice, mHwModules);
333#endif // DOLBY_END
334 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
335 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
336 updateCallRouting(newDevice);
337 }
338
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700339 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530340 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
341 if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (desc != mPrimaryOutput)) {
342 audio_devices_t newDevice = getNewOutputDevice(desc, true /*fromCache*/);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700343 // do not force device change on duplicated output because if device is 0, it will
344 // also force a device 0 for the two outputs it is duplicated to which may override
345 // a valid device selection on those outputs.
Sharad Sangle36781612015-05-28 16:15:16 +0530346 bool force = !desc->isDuplicated()
347 && (!device_distinguishes_on_address(device)
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700348 // always force when disconnecting (a non-duplicated device)
349 || (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
Sharad Sangle36781612015-05-28 16:15:16 +0530350 setOutputDevice(desc, newDevice, force, 0);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700351 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700352 }
353
Ashish Jain40cab3a2016-03-23 11:14:14 +0530354 if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
355 cleanUpForDevice(devDesc);
356 }
357
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700358 mpClientInterface->onAudioPortListUpdate();
359 return NO_ERROR;
360 } // end if is output device
361
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700362 // handle input devices
363 if (audio_is_input_device(device)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700364 SortedVector <audio_io_handle_t> inputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700365
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700366 ssize_t index = mAvailableInputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700367 switch (state)
368 {
369 // handle input device connection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700370 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
371 if (index >= 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700372 ALOGW("setDeviceConnectionState() device already connected: %d", device);
373 return INVALID_OPERATION;
374 }
Sharad Sangle36781612015-05-28 16:15:16 +0530375 sp<HwModule> module = mHwModules.getModuleForDevice(device);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700376 if (module == NULL) {
377 ALOGW("setDeviceConnectionState(): could not find HW module for device %08x",
378 device);
379 return INVALID_OPERATION;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700380 }
Garmond Leungfcb00d92017-01-31 11:12:47 -0800381
382 // Before checking intputs, broadcast connect event to allow HAL to retrieve dynamic
383 // parameters on newly connected devices (instead of opening the inputs...)
384 broadcastDeviceConnectionState(device, state, devDesc->mAddress);
385
Sharad Sangle36781612015-05-28 16:15:16 +0530386 if (checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress) != NO_ERROR) {
Garmond Leungfcb00d92017-01-31 11:12:47 -0800387 broadcastDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
388 devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700389 return INVALID_OPERATION;
390 }
391
392 index = mAvailableInputDevices.add(devDesc);
393 if (index >= 0) {
Sharad Sangle36781612015-05-28 16:15:16 +0530394 mAvailableInputDevices[index]->attach(module);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700395 } else {
396 return NO_MEMORY;
397 }
Sharad Sangle36781612015-05-28 16:15:16 +0530398
Sharad Sangle36781612015-05-28 16:15:16 +0530399 // Propagate device availability to Engine
400 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700401 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700402
403 // handle input device disconnection
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700404 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
405 if (index < 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700406 ALOGW("setDeviceConnectionState() device not connected: %d", device);
407 return INVALID_OPERATION;
408 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700409
410 ALOGV("setDeviceConnectionState() disconnecting input device %x", device);
411
412 // Set Disconnect to HALs
Garmond Leungfcb00d92017-01-31 11:12:47 -0800413 broadcastDeviceConnectionState(device, state, devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700414
Sharad Sangle36781612015-05-28 16:15:16 +0530415 checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700416 mAvailableInputDevices.remove(devDesc);
417
Sharad Sangle36781612015-05-28 16:15:16 +0530418 // Propagate device availability to Engine
419 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700420 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700421
422 default:
423 ALOGE("setDeviceConnectionState() invalid state: %x", state);
424 return BAD_VALUE;
425 }
426
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700427 closeAllInputs();
Sharad Sanglec66b9ca2016-12-21 18:40:54 +0530428 /*audio policy: fix call volume over USB*/
429 // As the input device list can impact the output device selection, update
430 // getDeviceForStrategy() cache
431 updateDevicesAndOutputs();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700432
Sharad Sangle36781612015-05-28 16:15:16 +0530433 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700434 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
435 updateCallRouting(newDevice);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700436 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700437
Ashish Jain40cab3a2016-03-23 11:14:14 +0530438 if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
439 cleanUpForDevice(devDesc);
440 }
441
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700442 mpClientInterface->onAudioPortListUpdate();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700443 return NO_ERROR;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700444 } // end if is input device
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700445
446 ALOGW("setDeviceConnectionState() invalid device: %x", device);
447 return BAD_VALUE;
448}
Weiyin Jiangd211ef52016-02-16 15:55:11 +0800449
Preetam Singh Ranawat3db94ec2016-10-13 18:35:12 +0530450bool AudioPolicyManagerCustom::isInvalidationOfMusicStreamNeeded(routing_strategy strategy)
451{
452 if (strategy == STRATEGY_MEDIA) {
453 for (size_t i = 0; i < mOutputs.size(); i++) {
454 sp<SwAudioOutputDescriptor> newOutputDesc = mOutputs.valueAt(i);
455 if (newOutputDesc->mFormat == AUDIO_FORMAT_DSD)
456 return false;
457 }
458 }
459 return true;
460}
461
462void AudioPolicyManagerCustom::checkOutputForStrategy(routing_strategy strategy)
463{
464 audio_devices_t oldDevice = getDeviceForStrategy(strategy, true /*fromCache*/);
465 audio_devices_t newDevice = getDeviceForStrategy(strategy, false /*fromCache*/);
466 SortedVector<audio_io_handle_t> srcOutputs = getOutputsForDevice(oldDevice, mOutputs);
467 SortedVector<audio_io_handle_t> dstOutputs = getOutputsForDevice(newDevice, mOutputs);
468
469 // also take into account external policy-related changes: add all outputs which are
470 // associated with policies in the "before" and "after" output vectors
471 ALOGV("checkOutputForStrategy(): policy related outputs");
472 for (size_t i = 0 ; i < mPreviousOutputs.size() ; i++) {
473 const sp<SwAudioOutputDescriptor> desc = mPreviousOutputs.valueAt(i);
474 if (desc != 0 && desc->mPolicyMix != NULL) {
475 srcOutputs.add(desc->mIoHandle);
476 ALOGV(" previous outputs: adding %d", desc->mIoHandle);
477 }
478 }
479 for (size_t i = 0 ; i < mOutputs.size() ; i++) {
480 const sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
481 if (desc != 0 && desc->mPolicyMix != NULL) {
482 dstOutputs.add(desc->mIoHandle);
483 ALOGV(" new outputs: adding %d", desc->mIoHandle);
484 }
485 }
486
487 if (!vectorsEqual(srcOutputs,dstOutputs) && isInvalidationOfMusicStreamNeeded(strategy)) {
488 AudioPolicyManager::checkOutputForStrategy(strategy);
489 }
490}
491
Sharad Sangle36781612015-05-28 16:15:16 +0530492// This function checks for the parameters which can be offloaded.
493// This can be enhanced depending on the capability of the DSP and policy
494// of the system.
495bool AudioPolicyManagerCustom::isOffloadSupported(const audio_offload_info_t& offloadInfo)
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700496{
Sharad Sangle36781612015-05-28 16:15:16 +0530497 ALOGV("isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d,"
498 " BitRate=%u, duration=%" PRId64 " us, has_video=%d",
499 offloadInfo.sample_rate, offloadInfo.channel_mask,
500 offloadInfo.format,
501 offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us,
502 offloadInfo.has_video);
Ashish Jain40cab3a2016-03-23 11:14:14 +0530503
504 if (mMasterMono) {
505 return false; // no offloading if mono is set.
506 }
507
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530508#ifdef VOICE_CONCURRENCY
509 char concpropValue[PROPERTY_VALUE_MAX];
510 if (property_get("voice.playback.conc.disabled", concpropValue, NULL)) {
511 bool propenabled = atoi(concpropValue) || !strncmp("true", concpropValue, 4);
512 if (propenabled) {
513 if (isInCall())
514 {
515 ALOGD("\n copl: blocking compress offload on call mode\n");
516 return false;
517 }
518 }
519 }
520#endif
Preetam Singh Ranawat96afc162016-08-25 14:35:02 +0530521 if (property_get_bool("voice.dsd.playback.conc.disabled", true) &&
522 isInCall() && (offloadInfo.format == AUDIO_FORMAT_DSD)) {
523 ALOGD("blocking DSD compress offload on call mode");
524 return false;
525 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530526#ifdef RECORD_PLAY_CONCURRENCY
527 char recConcPropValue[PROPERTY_VALUE_MAX];
528 bool prop_rec_play_enabled = false;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700529
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530530 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
531 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
532 }
533
534 if ((prop_rec_play_enabled) &&
Lalit Kansara33918092016-12-06 22:42:26 +0530535 ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530536 ALOGD("copl: blocking compress offload for record concurrency");
537 return false;
538 }
539#endif
Sharad Sangle36781612015-05-28 16:15:16 +0530540 // Check if stream type is music, then only allow offload as of now.
541 if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC)
542 {
543 ALOGV("isOffloadSupported: stream_type != MUSIC, returning false");
544 return false;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700545 }
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530546
Alexy Joseph0ac09032015-10-16 15:57:53 -0700547 // Check if offload has been disabled
548 bool offloadDisabled = property_get_bool("audio.offload.disable", false);
549 if (offloadDisabled) {
550 ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled);
551 return false;
552 }
553
Ashish Jainac510a72016-04-28 12:22:58 +0530554 //check if it's multi-channel AAC (includes sub formats) and FLAC format
555 if ((popcount(offloadInfo.channel_mask) > 2) &&
556 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) ||
557 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS))) {
558 ALOGD("offload disabled for multi-channel AAC,FLAC and VORBIS format");
559 return false;
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530560 }
Satya Krishna Pindiproli5d82d012015-08-12 18:21:25 +0530561
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530562#ifdef AUDIO_EXTN_FORMATS_ENABLED
Ashish Jainac510a72016-04-28 12:22:58 +0530563 //check if it's multi-channel FLAC/ALAC/WMA format with sample rate > 48k
564 if ((popcount(offloadInfo.channel_mask) > 2) &&
565 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) ||
566 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) && (offloadInfo.sample_rate > 48000)) ||
567 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) && (offloadInfo.sample_rate > 48000)) ||
568 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.sample_rate > 48000)) ||
569 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS))) {
570 ALOGD("offload disabled for multi-channel FLAC/ALAC/WMA/AAC_ADTS clips with sample rate > 48kHz");
571 return false;
572 }
yidonghae28e3a2016-08-19 11:31:15 +0800573
574 if ((((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) && (offloadInfo.bit_rate > MAX_BITRATE_WMA)) ||
575 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.bit_rate > MAX_BITRATE_WMA_PRO)) ||
576 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && (offloadInfo.bit_rate > MAX_BITRATE_WMA_LOSSLESS))){
577 //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.
578 ALOGD("offload disabled for WMA/WMA_PRO/WMA_LOSSLESS clips with bit rate over maximum supported value");
579 return false;
580 }
Preetam Singh Ranawat8152ab42015-07-21 19:30:09 +0530581#endif
Ashish Jainac510a72016-04-28 12:22:58 +0530582 //TODO: enable audio offloading with video when ready
583 const bool allowOffloadWithVideo =
584 property_get_bool("audio.offload.video", false /* default_value */);
585 if (offloadInfo.has_video && !allowOffloadWithVideo) {
586 ALOGV("isOffloadSupported: has_video == true, returning false");
587 return false;
588 }
Manish Dewanganf3cd0f82015-10-13 14:04:36 +0530589
Ashish Jainac510a72016-04-28 12:22:58 +0530590 const bool allowOffloadStreamingWithVideo = property_get_bool("av.streaming.offload.enable",
591 false /*default value*/);
592 if (offloadInfo.has_video && offloadInfo.is_streaming && !allowOffloadStreamingWithVideo) {
593 ALOGW("offload disabled by av.streaming.offload.enable %d",allowOffloadStreamingWithVideo);
594 return false;
Sharad Sangle36781612015-05-28 16:15:16 +0530595 }
596
597 //If duration is less than minimum value defined in property, return false
Ashish Jainac510a72016-04-28 12:22:58 +0530598 char propValue[PROPERTY_VALUE_MAX];
Sharad Sangle36781612015-05-28 16:15:16 +0530599 if (property_get("audio.offload.min.duration.secs", propValue, NULL)) {
600 if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) {
601 ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue);
602 return false;
603 }
604 } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) {
605 ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS);
606 //duration checks only valid for MP3/AAC/ formats,
607 //do not check duration for other audio formats, e.g. dolby AAC/AC3 and amrwb+ formats
608 if ((offloadInfo.format == AUDIO_FORMAT_MP3) ||
609 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) ||
610 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) ||
Ashish Jainac510a72016-04-28 12:22:58 +0530611 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS))
612 return false;
613
614#ifdef AUDIO_EXTN_FORMATS_ENABLED
615 if (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) ||
Sharad Sangle36781612015-05-28 16:15:16 +0530616 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) ||
617 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) ||
Satya Krishna Pindiproli5d82d012015-08-12 18:21:25 +0530618 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_APE) ||
Preetam Singh Ranawat191eb772016-09-09 17:10:19 +0530619 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_DSD) ||
Ashish Jainac510a72016-04-28 12:22:58 +0530620 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS))
Sharad Sangle36781612015-05-28 16:15:16 +0530621 return false;
Ashish Jainac510a72016-04-28 12:22:58 +0530622#endif
Sharad Sangle36781612015-05-28 16:15:16 +0530623 }
624
625 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
626 // creating an offloaded track and tearing it down immediately after start when audioflinger
627 // detects there is an active non offloadable effect.
628 // FIXME: We should check the audio session here but we do not have it in this context.
629 // This may prevent offloading in rare situations where effects are left active by apps
630 // in the background.
631 if (mEffects.isNonOffloadableEffectEnabled()) {
632 return false;
633 }
Dhananjay Kumarcf558ba2016-07-29 19:33:13 +0530634
Sharad Sangle36781612015-05-28 16:15:16 +0530635 // See if there is a profile to support this.
636 // AUDIO_DEVICE_NONE
637 sp<IOProfile> profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */,
638 offloadInfo.sample_rate,
639 offloadInfo.format,
640 offloadInfo.channel_mask,
641 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
642 ALOGV("isOffloadSupported() profile %sfound", profile != 0 ? "" : "NOT ");
643 return (profile != 0);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700644}
Weiyin Jiangd211ef52016-02-16 15:55:11 +0800645
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700646void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state)
647{
Ashish Jain40cab3a2016-03-23 11:14:14 +0530648 ALOGD("setPhoneState() state %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +0530649 // store previous phone state for management of sonification strategy below
Sharad Sangle4509cef2015-08-19 20:47:12 +0530650 audio_devices_t newDevice = AUDIO_DEVICE_NONE;
Sharad Sangle36781612015-05-28 16:15:16 +0530651 int oldState = mEngine->getPhoneState();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700652
Sharad Sangle36781612015-05-28 16:15:16 +0530653 if (mEngine->setPhoneState(state) != NO_ERROR) {
654 ALOGW("setPhoneState() invalid or same state %d", state);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700655 return;
656 }
Sharad Sangle36781612015-05-28 16:15:16 +0530657 /// Opens: can these line be executed after the switch of volume curves???
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700658 // if leaving call state, handle special case of active streams
659 // pertaining to sonification strategy see handleIncallSonification()
Zhou Song58081b62016-02-24 13:10:55 +0800660 if (isStateInCall(oldState)) {
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700661 ALOGV("setPhoneState() in call state management: new state is %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +0530662 for (size_t j = 0; j < mOutputs.size(); j++) {
663 audio_io_handle_t curOutput = mOutputs.keyAt(j);
Garmond Leungfcb00d92017-01-31 11:12:47 -0800664 for (int stream = 0; stream < AUDIO_STREAM_FOR_POLICY_CNT; stream++) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530665 handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput);
Sharad Sangle36781612015-05-28 16:15:16 +0530666 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700667 }
Sharad Sangle36781612015-05-28 16:15:16 +0530668
Zhou Song58081b62016-02-24 13:10:55 +0800669 // force reevaluating accessibility routing when call stops
Sharad Sangle36781612015-05-28 16:15:16 +0530670 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700671 }
672
Sharad Sangle36781612015-05-28 16:15:16 +0530673 /**
674 * Switching to or from incall state or switching between telephony and VoIP lead to force
675 * routing command.
676 */
677 bool force = ((is_state_in_call(oldState) != is_state_in_call(state))
678 || (is_state_in_call(state) && (state != oldState)));
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700679
680 // check for device and output changes triggered by new phone state
681 checkA2dpSuspend();
682 checkOutputForAllStrategies();
683 updateDevicesAndOutputs();
684
Sharad Sangle36781612015-05-28 16:15:16 +0530685 sp<SwAudioOutputDescriptor> hwOutputDesc = mPrimaryOutput;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530686#ifdef VOICE_CONCURRENCY
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530687 char propValue[PROPERTY_VALUE_MAX];
688 bool prop_playback_enabled = false, prop_rec_enabled=false, prop_voip_enabled = false;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700689
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530690 if(property_get("voice.playback.conc.disabled", propValue, NULL)) {
691 prop_playback_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
692 }
693
694 if(property_get("voice.record.conc.disabled", propValue, NULL)) {
695 prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
696 }
697
698 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
699 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
700 }
701
Dhananjay Kumar9125b2a2015-12-01 16:24:09 +0530702 if ((AUDIO_MODE_IN_CALL != oldState) && (AUDIO_MODE_IN_CALL == state)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530703 ALOGD("voice_conc:Entering to call mode oldState :: %d state::%d ",
704 oldState, state);
Dhananjay Kumar9125b2a2015-12-01 16:24:09 +0530705 mvoice_call_state = state;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530706 if (prop_rec_enabled) {
707 //Close all active inputs
Garmond Leungfcb00d92017-01-31 11:12:47 -0800708 Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
709 if (activeInputs.size() != 0) {
710 for (size_t i = 0; i < activeInputs.size(); i++) {
711 sp<AudioInputDescriptor> activeInput = activeInputs[i];
712 switch(activeInput->inputSource()) {
713 case AUDIO_SOURCE_VOICE_UPLINK:
714 case AUDIO_SOURCE_VOICE_DOWNLINK:
715 case AUDIO_SOURCE_VOICE_CALL:
716 ALOGD("voice_conc:FOUND active input during call active: %d",activeInput->inputSource());
717 break;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530718
Garmond Leungfcb00d92017-01-31 11:12:47 -0800719 case AUDIO_SOURCE_VOICE_COMMUNICATION:
720 if(prop_voip_enabled) {
721 ALOGD("voice_conc:CLOSING VoIP input source on call setup :%d ",activeInput->inputSource());
722 stopInput(activeInput->mIoHandle, activeDesc->mSessions.itemAt(0));
723 releaseInput(activeInput->mIoHandle, activeDesc->mSessions.itemAt(0));
724 }
725 break;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530726
Garmond Leungfcb00d92017-01-31 11:12:47 -0800727 default:
728 ALOGD("voice_conc:CLOSING input on call setup for inputSource: %d",activeInput->inputSource());
729 stopInput(activeInput->mIoHandle, activeDesc->mSessions.itemAt(0));
730 releaseInput(activeInput->mIoHandle, activeDesc->mSessions.itemAt(0));
731 break;
732 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530733 }
734 }
735 } else if (prop_voip_enabled) {
Garmond Leungfcb00d92017-01-31 11:12:47 -0800736 Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
737 if (activeInputs.size() != 0) {
738 for (size_t i = 0; i < activeInputs.size(); i++) {
739 sp<AudioInputDescriptor> activeInput = activeInputs[i];
740 if (AUDIO_SOURCE_VOICE_COMMUNICATION == activeInput->inputSource()) {
741 ALOGD("voice_conc:CLOSING VoIP on call setup : %d",activeInput->inputSource());
742 stopInput(activeInput->mIoHandle, activeInput->mSessions.itemAt(0));
743 releaseInput(activeInput->mIoHandle, activeInput->mSessions.itemAt(0));
744 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530745 }
746 }
747 }
748 if (prop_playback_enabled) {
749 // Move tracks associated to this strategy from previous output to new output
Garmond Leungfcb00d92017-01-31 11:12:47 -0800750 for (int i = AUDIO_STREAM_SYSTEM; i < AUDIO_STREAM_FOR_POLICY_CNT; i++) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530751 ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i);
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530752 if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
753 if ((AUDIO_STREAM_MUSIC == i) ||
754 (AUDIO_STREAM_VOICE_CALL == i) ) {
755 ALOGD("voice_conc:Invalidate stream type %d", i);
756 mpClientInterface->invalidateStream((audio_stream_type_t)i);
757 }
758 } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
759 ALOGD("voice_conc:Invalidate stream type %d", i);
760 mpClientInterface->invalidateStream((audio_stream_type_t)i);
761 }
762 }
763 }
764
765 for (size_t i = 0; i < mOutputs.size(); i++) {
766 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
767 if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
768 ALOGD("voice_conc:ouput desc / profile is NULL");
769 continue;
770 }
771
Sidipotu Ashok738f19e2016-12-07 15:16:01 +0530772 bool isFastFallBackNeeded =
773 ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & outputDesc->mProfile->mFlags);
774
775 if ((AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) && isFastFallBackNeeded) {
776 if (((!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY))
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530777 && prop_playback_enabled) {
778 ALOGD("voice_conc:calling suspendOutput on call mode for primary output");
779 mpClientInterface->suspendOutput(mOutputs.keyAt(i));
780 } //Close compress all sessions
781 else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
782 && prop_playback_enabled) {
783 ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output");
784 closeOutput(mOutputs.keyAt(i));
785 }
786 else if ((outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX)
787 && prop_voip_enabled) {
788 ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output");
789 closeOutput(mOutputs.keyAt(i));
790 }
791 } else if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
kunleiz0b55ec72016-11-10 16:23:58 +0800792 if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_VOIP_RX) {
793 if (prop_voip_enabled) {
794 ALOGD("voice_conc:calling closeOutput on call mode for DIRECT output");
795 closeOutput(mOutputs.keyAt(i));
796 }
797 }
798 else if (prop_playback_enabled
799 && (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530800 ALOGD("voice_conc:calling closeOutput on call mode for COMPRESS output");
801 closeOutput(mOutputs.keyAt(i));
802 }
803 }
804 }
Ashish Jaine4a22d52016-06-22 11:55:08 +0530805 // If effects where present on any of the above closed outputs,
806 // audioflinger moved them to the primary output by default
807 // move them back to the appropriate output.
808 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530809 }
810
811 if ((AUDIO_MODE_IN_CALL == oldState || AUDIO_MODE_IN_COMMUNICATION == oldState) &&
812 (AUDIO_MODE_NORMAL == state) && prop_playback_enabled && mvoice_call_state) {
813 ALOGD("voice_conc:EXITING from call mode oldState :: %d state::%d \n",oldState, state);
814 mvoice_call_state = 0;
815 if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
816 //restore PCM (deep-buffer) output after call termination
817 for (size_t i = 0; i < mOutputs.size(); i++) {
818 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
819 if ( (outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
820 ALOGD("voice_conc:ouput desc / profile is NULL");
821 continue;
822 }
823 if (!outputDesc->isDuplicated() && outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_PRIMARY) {
824 ALOGD("voice_conc:calling restoreOutput after call mode for primary output");
825 mpClientInterface->restoreOutput(mOutputs.keyAt(i));
826 }
827 }
828 }
829 //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL
Garmond Leungfcb00d92017-01-31 11:12:47 -0800830 for (int i = AUDIO_STREAM_SYSTEM; i < AUDIO_STREAM_FOR_POLICY_CNT; i++) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530831 ALOGV("voice_conc:Invalidate on call mode for stream :: %d ", i);
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530832 if (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag) {
833 if ((AUDIO_STREAM_MUSIC == i) ||
834 (AUDIO_STREAM_VOICE_CALL == i) ) {
835 mpClientInterface->invalidateStream((audio_stream_type_t)i);
836 }
837 } else if (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag) {
838 mpClientInterface->invalidateStream((audio_stream_type_t)i);
839 }
840 }
841 }
842
843#endif
Preetam Singh Ranawat96afc162016-08-25 14:35:02 +0530844
845 sp<SwAudioOutputDescriptor> outputDesc = NULL;
846 for (size_t i = 0; i < mOutputs.size(); i++) {
847 outputDesc = mOutputs.valueAt(i);
848 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
849 ALOGD("voice_conc:ouput desc / profile is NULL");
850 continue;
851 }
852
853 if (property_get_bool("voice.dsd.playback.conc.disabled", true) &&
854 (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
855 (outputDesc->mFormat == AUDIO_FORMAT_DSD)) {
856 ALOGD("voice_conc:calling closeOutput on call mode for DSD COMPRESS output");
857 closeOutput(mOutputs.keyAt(i));
858 // call invalidate for music, so that DSD compress will fallback to deep-buffer.
859 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
860 }
861
862 }
863
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530864#ifdef RECORD_PLAY_CONCURRENCY
865 char recConcPropValue[PROPERTY_VALUE_MAX];
866 bool prop_rec_play_enabled = false;
867
868 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
869 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
870 }
871 if (prop_rec_play_enabled) {
872 if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) {
873 ALOGD("phone state changed to MODE_IN_COMM invlaidating music and voice streams");
874 // call invalidate for voice streams, so that it can use deepbuffer with VoIP out device from HAL
875 mpClientInterface->invalidateStream(AUDIO_STREAM_VOICE_CALL);
876 // call invalidate for music, so that compress will fallback to deep-buffer with VoIP out device
877 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
878
879 // close compress output to make sure session will be closed before timeout(60sec)
880 for (size_t i = 0; i < mOutputs.size(); i++) {
881
882 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
883 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
884 ALOGD("ouput desc / profile is NULL");
885 continue;
886 }
887
888 if (outputDesc->mProfile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
889 ALOGD("calling closeOutput on call mode for COMPRESS output");
890 closeOutput(mOutputs.keyAt(i));
891 }
892 }
Ashish Jaine4a22d52016-06-22 11:55:08 +0530893 // If effects where present on any of the above closed outputs,
894 // audioflinger moved them to the primary output by default
895 // move them back to the appropriate output.
896 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530897 } else if ((oldState == AUDIO_MODE_IN_COMMUNICATION) &&
898 (mEngine->getPhoneState() == AUDIO_MODE_NORMAL)) {
899 // call invalidate for music so that music can fallback to compress
900 mpClientInterface->invalidateStream(AUDIO_STREAM_MUSIC);
901 }
902 }
903#endif
904 mPrevPhoneState = oldState;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700905 int delayMs = 0;
906 if (isStateInCall(state)) {
907 nsecs_t sysTime = systemTime();
908 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangle36781612015-05-28 16:15:16 +0530909 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700910 // mute media and sonification strategies and delay device switch by the largest
911 // latency of any output where either strategy is active.
912 // This avoid sending the ring tone or music tail into the earpiece or headset.
Sharad Sangle36781612015-05-28 16:15:16 +0530913 if ((isStrategyActive(desc, STRATEGY_MEDIA,
914 SONIFICATION_HEADSET_MUSIC_DELAY,
915 sysTime) ||
916 isStrategyActive(desc, STRATEGY_SONIFICATION,
917 SONIFICATION_HEADSET_MUSIC_DELAY,
918 sysTime)) &&
919 (delayMs < (int)desc->latency()*2)) {
920 delayMs = desc->latency()*2;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700921 }
Sharad Sangle36781612015-05-28 16:15:16 +0530922 setStrategyMute(STRATEGY_MEDIA, true, desc);
923 setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700924 getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));
Sharad Sangle36781612015-05-28 16:15:16 +0530925 setStrategyMute(STRATEGY_SONIFICATION, true, desc);
926 setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700927 getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/));
928 }
929 }
930
Sharad Sangle36781612015-05-28 16:15:16 +0530931 if (hasPrimaryOutput()) {
932 // Note that despite the fact that getNewOutputDevice() is called on the primary output,
933 // the device returned is not necessarily reachable via this output
934 audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
935 // force routing command to audio hardware when ending call
936 // even if no device change is needed
937 if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) {
938 rxDevice = mPrimaryOutput->device();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700939 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700940
Sharad Sangle36781612015-05-28 16:15:16 +0530941 if (state == AUDIO_MODE_IN_CALL) {
942 updateCallRouting(rxDevice, delayMs);
943 } else if (oldState == AUDIO_MODE_IN_CALL) {
944 if (mCallRxPatch != 0) {
945 mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0);
946 mCallRxPatch.clear();
947 }
948 if (mCallTxPatch != 0) {
949 mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0);
950 mCallTxPatch.clear();
951 }
952 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
953 } else {
954 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700955 }
956 }
Sharad Sangle4509cef2015-08-19 20:47:12 +0530957 //update device for all non-primary outputs
958 for (size_t i = 0; i < mOutputs.size(); i++) {
959 audio_io_handle_t output = mOutputs.keyAt(i);
960 if (output != mPrimaryOutput->mIoHandle) {
961 newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/);
962 setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE));
963 }
964 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700965 // if entering in call state, handle special case of active streams
966 // pertaining to sonification strategy see handleIncallSonification()
967 if (isStateInCall(state)) {
968 ALOGV("setPhoneState() in call state management: new state is %d", state);
Sharad Sangle36781612015-05-28 16:15:16 +0530969 for (size_t j = 0; j < mOutputs.size(); j++) {
970 audio_io_handle_t curOutput = mOutputs.keyAt(j);
Garmond Leungfcb00d92017-01-31 11:12:47 -0800971 for (int stream = 0; stream < AUDIO_STREAM_FOR_POLICY_CNT; stream++) {
Sharad Sangle4509cef2015-08-19 20:47:12 +0530972 handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
Sharad Sangle36781612015-05-28 16:15:16 +0530973 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700974 }
Zhou Song58081b62016-02-24 13:10:55 +0800975
976 // force reevaluating accessibility routing when call starts
977 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700978 }
979
980 // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE
981 if (state == AUDIO_MODE_RINGTONE &&
982 isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) {
983 mLimitRingtoneVolume = true;
984 } else {
985 mLimitRingtoneVolume = false;
986 }
987}
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +0530988
989void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
990 audio_policy_forced_cfg_t config)
991{
Ashish Jain40cab3a2016-03-23 11:14:14 +0530992 ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState());
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +0530993
994 if (mEngine->setForceUse(usage, config) != NO_ERROR) {
995 ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage);
996 return;
997 }
998 bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) ||
999 (usage == AUDIO_POLICY_FORCE_FOR_DOCK) ||
1000 (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM);
1001
1002 // check for device and output changes triggered by new force usage
1003 checkA2dpSuspend();
1004 checkOutputForAllStrategies();
1005 updateDevicesAndOutputs();
Ashish Jain40cab3a2016-03-23 11:14:14 +05301006
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301007 /*audio policy: workaround for truncated touch sounds*/
1008 //FIXME: workaround for truncated touch sounds
1009 // to be removed when the problem is handled by system UI
1010 uint32_t delayMs = 0;
1011 uint32_t waitMs = 0;
1012 if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) {
1013 delayMs = TOUCH_SOUND_FIXED_DELAY_MS;
1014 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301015 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
1016 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/);
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301017 waitMs = updateCallRouting(newDevice, delayMs);
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301018 }
1019 // Use reverse loop to make sure any low latency usecases (generally tones)
1020 // are not routed before non LL usecases (generally music).
1021 // We can safely assume that LL output would always have lower index,
1022 // and use this work-around to avoid routing of output with music stream
1023 // from the context of short lived LL output.
1024 // Note: in case output's share backend(HAL sharing is implicit) all outputs
1025 // gets routing update while processing first output itself.
1026 for (size_t i = mOutputs.size(); i > 0; i--) {
1027 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1);
1028 audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/);
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301029 if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) {
1030 waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE),
1031 delayMs);
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301032 }
1033 if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301034 applyStreamVolumes(outputDesc, newDevice, waitMs, true);
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301035 }
1036 }
1037
Garmond Leungfcb00d92017-01-31 11:12:47 -08001038 Vector<sp <AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
1039 for (size_t i = 0; i < activeInputs.size(); i++) {
1040 sp<AudioInputDescriptor> activeDesc = activeInputs[i];
1041 audio_devices_t newDevice = getNewInputDevice(activeDesc);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301042 // Force new input selection if the new device can not be reached via current input
Garmond Leungfcb00d92017-01-31 11:12:47 -08001043 if (activeDesc->mProfile->getSupportedDevices().types() &
1044 (newDevice & ~AUDIO_DEVICE_BIT_IN)) {
1045 setInputDevice(activeDesc->mIoHandle, newDevice);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301046 } else {
Garmond Leungfcb00d92017-01-31 11:12:47 -08001047 closeInput(activeDesc->mIoHandle);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301048 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301049 }
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +05301050}
1051
Garmond Leungfcb00d92017-01-31 11:12:47 -08001052status_t AudioPolicyManagerCustom::stopSource(const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301053 audio_stream_type_t stream,
1054 bool forceDeviceUpdate)
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001055{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301056 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1057 ALOGW("stopSource() invalid stream %d", stream);
1058 return INVALID_OPERATION;
1059 }
Sharad Sangle36781612015-05-28 16:15:16 +05301060 // always handle stream stop, check which stream type is stopping
1061 handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001062
Sharad Sangle36781612015-05-28 16:15:16 +05301063 // handle special case for sonification while in call
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001064 if (isInCall()) {
Sharad Sangle36781612015-05-28 16:15:16 +05301065 if (outputDesc->isDuplicated()) {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301066 handleIncallSonification(stream, false, false, outputDesc->subOutput1()->mIoHandle);
1067 handleIncallSonification(stream, false, false, outputDesc->subOutput2()->mIoHandle);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001068 }
Sharad Sangle36781612015-05-28 16:15:16 +05301069 handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
1070 }
1071
1072 if (outputDesc->mRefCount[stream] > 0) {
1073 // decrement usage count of this stream on the output
1074 outputDesc->changeRefCount(stream, -1);
1075
1076 // store time at which the stream was stopped - see isStreamActive()
1077 if (outputDesc->mRefCount[stream] == 0 || forceDeviceUpdate) {
1078 outputDesc->mStopTime[stream] = systemTime();
Zhou Song5dcddc92015-09-21 14:36:57 +08001079 audio_devices_t prevDevice = outputDesc->device();
Sharad Sangle36781612015-05-28 16:15:16 +05301080 audio_devices_t newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/);
1081 // delay the device switch by twice the latency because stopOutput() is executed when
1082 // the track stop() command is received and at that time the audio track buffer can
1083 // still contain data that needs to be drained. The latency only covers the audio HAL
1084 // and kernel buffers. Also the latency does not always include additional delay in the
1085 // audio path (audio DSP, CODEC ...)
1086 setOutputDevice(outputDesc, newDevice, false, outputDesc->latency()*2);
1087
1088 // force restoring the device selection on other active outputs if it differs from the
1089 // one being selected for this output
1090 for (size_t i = 0; i < mOutputs.size(); i++) {
1091 audio_io_handle_t curOutput = mOutputs.keyAt(i);
1092 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
1093 if (desc != outputDesc &&
1094 desc->isActive() &&
1095 outputDesc->sharesHwModuleWith(desc) &&
1096 (newDevice != desc->device())) {
Sharad Sangle4509cef2015-08-19 20:47:12 +05301097 audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/);
Naresh Tanniru11393702016-09-14 11:25:37 +05301098 bool force = desc->device() != dev;
Zhou Song5dcddc92015-09-21 14:36:57 +08001099 uint32_t delayMs;
1100 if (dev == prevDevice) {
1101 delayMs = 0;
1102 } else {
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301103 delayMs = outputDesc->latency()*2;
Zhou Song5dcddc92015-09-21 14:36:57 +08001104 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301105 setOutputDevice(desc,
1106 dev,
Naresh Tanniru11393702016-09-14 11:25:37 +05301107 force,
Zhou Song5dcddc92015-09-21 14:36:57 +08001108 delayMs);
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301109 /*audio policy: fix media volume after ringtone*/
1110 // re-apply device specific volume if not done by setOutputDevice()
1111 if (!force) {
1112 applyStreamVolumes(desc, dev, delayMs);
1113 }
Sharad Sangle36781612015-05-28 16:15:16 +05301114 }
1115 }
1116 // update the outputs if stopping one with a stream that can affect notification routing
1117 handleNotificationRoutingForStream(stream);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001118 }
Sharad Sangle36781612015-05-28 16:15:16 +05301119 return NO_ERROR;
1120 } else {
1121 ALOGW("stopOutput() refcount is already 0");
1122 return INVALID_OPERATION;
1123 }
1124}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001125
Garmond Leungfcb00d92017-01-31 11:12:47 -08001126status_t AudioPolicyManagerCustom::startSource(const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301127 audio_stream_type_t stream,
1128 audio_devices_t device,
Lalit Kansaraf803ac52016-05-09 19:12:01 +05301129 const char *address,
Sharad Sangle36781612015-05-28 16:15:16 +05301130 uint32_t *delayMs)
1131{
1132 // cannot start playback of STREAM_TTS if any other output is being used
1133 uint32_t beaconMuteLatency = 0;
1134
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301135 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1136 ALOGW("startSource() invalid stream %d", stream);
1137 return INVALID_OPERATION;
1138 }
1139
Sharad Sangle36781612015-05-28 16:15:16 +05301140 *delayMs = 0;
1141 if (stream == AUDIO_STREAM_TTS) {
1142 ALOGV("\t found BEACON stream");
Ashish Jain40cab3a2016-03-23 11:14:14 +05301143 if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301144 return INVALID_OPERATION;
1145 } else {
1146 beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001147 }
Sharad Sangle36781612015-05-28 16:15:16 +05301148 } else {
1149 // some playback other than beacon starts
1150 beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT);
1151 }
1152
Zhou Song63f0b852016-12-20 14:35:06 +08001153 // force device change if the output is inactive and no audio patch is already present.
Ashish Jain40cab3a2016-03-23 11:14:14 +05301154 // check active before incrementing usage count
Zhou Song63f0b852016-12-20 14:35:06 +08001155 bool force = !outputDesc->isActive() &&
1156 (outputDesc->getPatchHandle() == AUDIO_PATCH_HANDLE_NONE);
Ashish Jain40cab3a2016-03-23 11:14:14 +05301157
Sharad Sangle36781612015-05-28 16:15:16 +05301158 // increment usage count for this stream on the requested output:
1159 // NOTE that the usage count is the same for duplicated output and hardware output which is
1160 // necessary for a correct control of hardware output routing by startOutput() and stopOutput()
1161 outputDesc->changeRefCount(stream, 1);
1162
1163 if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) {
1164 // starting an output being rerouted?
1165 if (device == AUDIO_DEVICE_NONE) {
1166 device = getNewOutputDevice(outputDesc, false /*fromCache*/);
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001167 }
Sharad Sangle36781612015-05-28 16:15:16 +05301168 routing_strategy strategy = getStrategy(stream);
1169 bool shouldWait = (strategy == STRATEGY_SONIFICATION) ||
1170 (strategy == STRATEGY_SONIFICATION_RESPECTFUL) ||
1171 (beaconMuteLatency > 0);
1172 uint32_t waitMs = beaconMuteLatency;
Sharad Sangle36781612015-05-28 16:15:16 +05301173 for (size_t i = 0; i < mOutputs.size(); i++) {
1174 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
1175 if (desc != outputDesc) {
Zhou Song63f0b852016-12-20 14:35:06 +08001176 // force a device change if any other output is:
1177 // - managed by the same hw module
1178 // - has a current device selection that differs from selected device.
1179 // - supports currently selected device
1180 // - has an active audio patch
Sharad Sangle36781612015-05-28 16:15:16 +05301181 // In this case, the audio HAL must receive the new device selection so that it can
1182 // change the device currently selected by the other active output.
1183 if (outputDesc->sharesHwModuleWith(desc) &&
Zhou Song63f0b852016-12-20 14:35:06 +08001184 desc->device() != device &&
1185 desc->supportedDevices() & device &&
1186 desc->getPatchHandle() != AUDIO_PATCH_HANDLE_NONE) {
Sharad Sangle36781612015-05-28 16:15:16 +05301187 force = true;
1188 }
1189 // wait for audio on other active outputs to be presented when starting
1190 // a notification so that audio focus effect can propagate, or that a mute/unmute
1191 // event occurred for beacon
1192 uint32_t latency = desc->latency();
1193 if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) {
1194 waitMs = latency;
1195 }
1196 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001197 }
Garmond Leungfcb00d92017-01-31 11:12:47 -08001198 uint32_t muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address);
Sharad Sangle36781612015-05-28 16:15:16 +05301199
1200 // handle special case for sonification while in call
1201 if (isInCall()) {
1202 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001203 }
Sharad Sangle36781612015-05-28 16:15:16 +05301204
1205 // apply volume rules for current stream and device if necessary
1206 checkAndSetVolume(stream,
Ashish Jain40cab3a2016-03-23 11:14:14 +05301207 mVolumeCurves->getVolumeIndex(stream, device),
Sharad Sangle36781612015-05-28 16:15:16 +05301208 outputDesc,
1209 device);
1210
1211 // update the outputs if starting an output with a stream that can affect notification
1212 // routing
1213 handleNotificationRoutingForStream(stream);
1214
1215 // force reevaluating accessibility routing when ringtone or alarm starts
1216 if (strategy == STRATEGY_SONIFICATION) {
1217 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
1218 }
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05301219 if (waitMs > muteWaitMs) {
1220 *delayMs = waitMs - muteWaitMs;
1221 }
1222
Garmond Leungfcb00d92017-01-31 11:12:47 -08001223 } else {
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001224 // handle special case for sonification while in call
1225 if (isInCall()) {
1226 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
Sharad Sangle36781612015-05-28 16:15:16 +05301227 }
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001228 }
Sharad Sangle36781612015-05-28 16:15:16 +05301229 return NO_ERROR;
1230}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001231
Sharad Sangle36781612015-05-28 16:15:16 +05301232void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream,
1233 bool starting, bool stateChange,
1234 audio_io_handle_t output)
1235{
1236 if(!hasPrimaryOutput()) {
1237 return;
1238 }
1239 // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks
1240 if (stream == AUDIO_STREAM_PATCH) {
1241 return;
1242 }
1243 // if the stream pertains to sonification strategy and we are in call we must
1244 // mute the stream if it is low visibility. If it is high visibility, we must play a tone
1245 // in the device used for phone strategy and play the tone if the selected device does not
1246 // interfere with the device used for phone strategy
1247 // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as
1248 // many times as there are active tracks on the output
1249 const routing_strategy stream_strategy = getStrategy(stream);
1250 if ((stream_strategy == STRATEGY_SONIFICATION) ||
1251 ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) {
1252 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
1253 ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
1254 stream, starting, outputDesc->mDevice, stateChange);
1255 if (outputDesc->mRefCount[stream]) {
1256 int muteCount = 1;
1257 if (stateChange) {
1258 muteCount = outputDesc->mRefCount[stream];
1259 }
1260 if (audio_is_low_visibility(stream)) {
1261 ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
1262 for (int i = 0; i < muteCount; i++) {
1263 setStreamMute(stream, starting, outputDesc);
1264 }
1265 } else {
1266 ALOGV("handleIncallSonification() high visibility");
1267 if (outputDesc->device() &
1268 getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) {
1269 ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
1270 for (int i = 0; i < muteCount; i++) {
1271 setStreamMute(stream, starting, outputDesc);
1272 }
1273 }
1274 if (starting) {
1275 mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION,
1276 AUDIO_STREAM_VOICE_CALL);
1277 } else {
1278 mpClientInterface->stopTone();
1279 }
1280 }
1281 }
1282 }
1283}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001284
Sharad Sangle36781612015-05-28 16:15:16 +05301285void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) {
1286 switch(stream) {
1287 case AUDIO_STREAM_MUSIC:
1288 checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL);
1289 updateDevicesAndOutputs();
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001290 break;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001291 default:
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001292 break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001293 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001294}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001295
Sharad Sangle36781612015-05-28 16:15:16 +05301296status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream,
1297 int index,
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301298 const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +05301299 audio_devices_t device,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001300 int delayMs,
1301 bool force)
Sharad Sangle36781612015-05-28 16:15:16 +05301302{
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +05301303 if (stream < 0 || stream >= AUDIO_STREAM_CNT) {
1304 ALOGW("checkAndSetVolume() invalid stream %d", stream);
1305 return INVALID_OPERATION;
1306 }
Sharad Sangle36781612015-05-28 16:15:16 +05301307 // do not change actual stream volume if the stream is muted
1308 if (outputDesc->mMuteCount[stream] != 0) {
1309 ALOGVV("checkAndSetVolume() stream %d muted count %d",
1310 stream, outputDesc->mMuteCount[stream]);
1311 return NO_ERROR;
1312 }
1313 audio_policy_forced_cfg_t forceUseForComm =
1314 mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION);
1315 // do not change in call volume if bluetooth is connected and vice versa
1316 if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) ||
1317 (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) {
1318 ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
1319 stream, forceUseForComm);
1320 return INVALID_OPERATION;
1321 }
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001322
Sharad Sangle36781612015-05-28 16:15:16 +05301323 if (device == AUDIO_DEVICE_NONE) {
1324 device = outputDesc->device();
1325 }
1326
1327 float volumeDb = computeVolume(stream, index, device);
1328 if (outputDesc->isFixedVolume(device)) {
1329 volumeDb = 0.0f;
1330 }
1331
1332 outputDesc->setVolume(volumeDb, stream, device, delayMs, force);
1333
1334 if (stream == AUDIO_STREAM_VOICE_CALL ||
1335 stream == AUDIO_STREAM_BLUETOOTH_SCO) {
1336 float voiceVolume;
1337 // Force voice volume to max for bluetooth SCO as volume is managed by the headset
1338 if (stream == AUDIO_STREAM_VOICE_CALL) {
Ashish Jain40cab3a2016-03-23 11:14:14 +05301339 voiceVolume = (float)index/(float)mVolumeCurves->getVolumeIndexMax(stream);
Sharad Sangle36781612015-05-28 16:15:16 +05301340 } else {
1341 voiceVolume = 1.0;
1342 }
1343
Garmond Leungfcb00d92017-01-31 11:12:47 -08001344 if (voiceVolume != mLastVoiceVolume) {
Sharad Sangle36781612015-05-28 16:15:16 +05301345 mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
1346 mLastVoiceVolume = voiceVolume;
1347 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301348#ifdef FM_POWER_OPT
1349 } else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() &&
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08001350 outputDesc == mPrimaryOutput && mFMIsActive) {
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001351 /* Avoid unnecessary set_parameter calls as it puts the primary
1352 outputs FastMixer in HOT_IDLE leading to breaks in audio */
1353 if (volumeDb != mPrevFMVolumeDb) {
1354 mPrevFMVolumeDb = volumeDb;
1355 AudioParameter param = AudioParameter();
1356 param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb));
Mingming Yin1433cc62016-01-04 14:58:00 -08001357 //Double delayMs to avoid sound burst while device switch.
1358 mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs*2);
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08001359 }
Dhananjay Kumar8ccb8312015-10-21 12:36:19 +05301360#endif /* FM_POWER_OPT end */
Sharad Sangle36781612015-05-28 16:15:16 +05301361 }
1362
1363 return NO_ERROR;
1364}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001365
Sharad Sangle36781612015-05-28 16:15:16 +05301366bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) {
1367 for (size_t i = 0; i < mOutputs.size(); i++) {
1368 audio_io_handle_t curOutput = mOutputs.keyAt(i);
1369 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1370 if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
1371 return true;
1372 }
1373 }
1374 return false;
1375}
vivek mehta0ea887a2015-08-26 14:01:20 -07001376
Dhananjay Kumarac341582017-02-23 23:42:25 +05301377bool static tryForDirectPCM(audio_output_flags_t flags)
Ashish Jainac510a72016-04-28 12:22:58 +05301378{
Ashish Jain771d02f2016-10-27 22:35:46 +05301379 bool trackDirectPCM = false; // Output request for track created by other apps
Ashish Jainac510a72016-04-28 12:22:58 +05301380
Dhananjay Kumarac341582017-02-23 23:42:25 +05301381 if (flags == AUDIO_OUTPUT_FLAG_NONE) {
Ashish Jain771d02f2016-10-27 22:35:46 +05301382 trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
1383 }
Dhananjay Kumarac341582017-02-23 23:42:25 +05301384 return trackDirectPCM;
Ashish Jainac510a72016-04-28 12:22:58 +05301385}
1386
vivek mehta0ea887a2015-08-26 14:01:20 -07001387status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001388 audio_io_handle_t *output,
1389 audio_session_t session,
1390 audio_stream_type_t *stream,
1391 uid_t uid,
1392 const audio_config_t *config,
1393 audio_output_flags_t flags,
1394 audio_port_handle_t selectedDeviceId,
1395 audio_port_handle_t *portId)
vivek mehta0ea887a2015-08-26 14:01:20 -07001396{
1397 audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
Garmond Leungfcb00d92017-01-31 11:12:47 -08001398 audio_config_t tConfig;
vivek mehta0ea887a2015-08-26 14:01:20 -07001399
Garmond Leungfcb00d92017-01-31 11:12:47 -08001400 uint32_t bitWidth = (audio_bytes_per_sample(config->format) * 8);
Alexy Joseph0ac09032015-10-16 15:57:53 -07001401
Garmond Leungfcb00d92017-01-31 11:12:47 -08001402 memcpy(&tConfig, config, sizeof(audio_config_t));
Dhananjay Kumarac341582017-02-23 23:42:25 +05301403 if ((flags == AUDIO_OUTPUT_FLAG_DIRECT || tryForDirectPCM(flags)) &&
Garmond Leungfcb00d92017-01-31 11:12:47 -08001404 (!memcmp(&config->offload_info, &tOffloadInfo, sizeof(audio_offload_info_t)))) {
1405 tConfig.offload_info.sample_rate = config->sample_rate;
1406 tConfig.offload_info.channel_mask = config->channel_mask;
1407 tConfig.offload_info.format = config->format;
1408 tConfig.offload_info.stream_type = *stream;
1409 tConfig.offload_info.bit_width = bitWidth;
vivek mehta0ea887a2015-08-26 14:01:20 -07001410 if (attr != NULL) {
1411 ALOGV("found attribute .. setting usage %d ", attr->usage);
Garmond Leungfcb00d92017-01-31 11:12:47 -08001412 tConfig.offload_info.usage = attr->usage;
vivek mehta0ea887a2015-08-26 14:01:20 -07001413 } else {
Alexy Joseph0ac09032015-10-16 15:57:53 -07001414 ALOGI("%s:: attribute is NULL .. no usage set", __func__);
vivek mehta0ea887a2015-08-26 14:01:20 -07001415 }
vivek mehta0ea887a2015-08-26 14:01:20 -07001416 }
1417
1418 return AudioPolicyManager::getOutputForAttr(attr, output, session, stream,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001419 (uid_t)uid, &tConfig,
vivek mehta0ea887a2015-08-26 14:01:20 -07001420 flags, (audio_port_handle_t)selectedDeviceId,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001421 portId);
vivek mehta0ea887a2015-08-26 14:01:20 -07001422}
1423
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001424audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice(
1425 audio_devices_t device,
Sharad Sangle36781612015-05-28 16:15:16 +05301426 audio_session_t session __unused,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001427 uid_t clientUid,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001428 audio_stream_type_t stream,
1429 uint32_t samplingRate,
1430 audio_format_t format,
1431 audio_channel_mask_t channelMask,
1432 audio_output_flags_t flags,
1433 const audio_offload_info_t *offloadInfo)
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001434{
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001435 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001436 status_t status;
Mingming Yin0ae14ea2014-07-09 17:55:56 -07001437
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001438#ifdef AUDIO_POLICY_TEST
1439 if (mCurOutput != 0) {
1440 ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d",
1441 mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
1442
1443 if (mTestOutputs[mCurOutput] == 0) {
1444 ALOGV("getOutput() opening test output");
Sharad Sangle36781612015-05-28 16:15:16 +05301445 sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL,
1446 mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001447 outputDesc->mDevice = mTestDevice;
1448 outputDesc->mLatency = mTestLatencyMs;
1449 outputDesc->mFlags =
1450 (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0);
1451 outputDesc->mRefCount[stream] = 0;
1452 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1453 config.sample_rate = mTestSamplingRate;
1454 config.channel_mask = mTestChannels;
1455 config.format = mTestFormat;
1456 if (offloadInfo != NULL) {
1457 config.offload_info = *offloadInfo;
1458 }
1459 status = mpClientInterface->openOutput(0,
1460 &mTestOutputs[mCurOutput],
1461 &config,
1462 &outputDesc->mDevice,
1463 String8(""),
1464 &outputDesc->mLatency,
1465 outputDesc->mFlags);
1466 if (status == NO_ERROR) {
1467 outputDesc->mSamplingRate = config.sample_rate;
1468 outputDesc->mFormat = config.format;
1469 outputDesc->mChannelMask = config.channel_mask;
1470 AudioParameter outputCmd = AudioParameter();
1471 outputCmd.addInt(String8("set_id"),mCurOutput);
1472 mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString());
1473 addOutput(mTestOutputs[mCurOutput], outputDesc);
1474 }
1475 }
1476 return mTestOutputs[mCurOutput];
1477 }
1478#endif //AUDIO_POLICY_TEST
Sharad Sangle36781612015-05-28 16:15:16 +05301479 if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) &&
1480 (stream != AUDIO_STREAM_MUSIC)) {
1481 // compress should not be used for non-music streams
1482 ALOGE("Offloading only allowed with music stream");
1483 return 0;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301484 }
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301485
1486 if ((stream == AUDIO_STREAM_VOICE_CALL) &&
1487 (channelMask == 1) &&
Shiv Maliyappanahallid77d3b32016-02-02 13:45:50 -08001488 (samplingRate == 8000 || samplingRate == 16000 ||
1489 samplingRate == 32000 || samplingRate == 48000)) {
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301490 // Allow Voip direct output only if:
1491 // audio mode is MODE_IN_COMMUNCATION; AND
1492 // voip output is not opened already; AND
1493 // requested sample rate matches with that of voip input stream (if opened already)
1494 int value = 0;
1495 uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1;
Alexy Joseph9323d8b2017-02-17 10:30:07 -08001496 bool is_vr_mode_on = false;
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301497 String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1498 String8("audio_mode"));
1499 AudioParameter result = AudioParameter(valueStr);
1500 if (result.getInt(String8("audio_mode"), value) == NO_ERROR) {
1501 mode = value;
1502 }
1503
1504 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1505 String8("voip_out_stream_count"));
1506 result = AudioParameter(valueStr);
1507 if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) {
1508 voipOutCount = value;
1509 }
1510
1511 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1512 String8("voip_sample_rate"));
1513 result = AudioParameter(valueStr);
1514 if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) {
1515 voipSampleRate = value;
1516 }
1517
1518 if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) &&
1519 ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) {
1520 if (audio_is_linear_pcm(format)) {
1521 char propValue[PROPERTY_VALUE_MAX] = {0};
1522 property_get("use.voice.path.for.pcm.voip", propValue, "0");
1523 bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true"));
1524 if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) {
Karthik Reddy Katta3fb9be72015-11-25 11:18:27 +05301525 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_VOIP_RX |
1526 AUDIO_OUTPUT_FLAG_DIRECT);
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301527 ALOGD("Set VoIP and Direct output flags for PCM format");
1528 }
1529 }
1530 }
Alexy Joseph9323d8b2017-02-17 10:30:07 -08001531 //IF VOIP is going to be started at the same time as when
1532 //vr is enabled, get VOIP to fallback to low latency
1533 String8 vr_value;
1534 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1535 String8("vr_audio_mode_on"));
1536 result = AudioParameter(valueStr);
1537 if (result.get(String8("vr_audio_mode_on"), vr_value) == NO_ERROR) {
1538 is_vr_mode_on = vr_value.contains("true");
1539 ALOGI("VR mode is %d, switch to primary output if request is for fast|raw",
1540 is_vr_mode_on);
1541 }
1542
1543 if (is_vr_mode_on) {
1544 //check the flags being requested for, and clear FAST|RAW
1545 flags = (audio_output_flags_t)(flags &
1546 (~(AUDIO_OUTPUT_FLAG_FAST|AUDIO_OUTPUT_FLAG_RAW)));
1547
1548 }
1549
Karthik Reddy Katta7249d662015-07-14 16:05:18 +05301550 }
1551
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301552#ifdef VOICE_CONCURRENCY
1553 char propValue[PROPERTY_VALUE_MAX];
1554 bool prop_play_enabled=false, prop_voip_enabled = false;
1555
1556 if(property_get("voice.playback.conc.disabled", propValue, NULL)) {
1557 prop_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001558 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301559
1560 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1561 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1562 }
1563
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301564 bool isDeepBufferFallBackNeeded =
1565 ((AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags);
1566 bool isFastFallBackNeeded =
1567 ((AUDIO_OUTPUT_FLAG_DEEP_BUFFER | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT_PCM) & flags);
1568
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301569 if (prop_play_enabled && mvoice_call_state) {
1570 //check if voice call is active / running in background
1571 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1572 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1573 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1574 {
1575 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1576 if(prop_voip_enabled) {
1577 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1578 flags );
1579 return 0;
1580 }
1581 }
1582 else {
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301583 if (isFastFallBackNeeded &&
1584 (AUDIO_OUTPUT_FLAG_FAST == mFallBackflag)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301585 ALOGD("voice_conc:IN call mode adding ULL flags .. flags: %x ", flags );
1586 flags = AUDIO_OUTPUT_FLAG_FAST;
Sidipotu Ashok738f19e2016-12-07 15:16:01 +05301587 } else if (isDeepBufferFallBackNeeded &&
1588 (AUDIO_OUTPUT_FLAG_DEEP_BUFFER == mFallBackflag)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301589 if (AUDIO_STREAM_MUSIC == stream) {
1590 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1591 ALOGD("voice_conc:IN call mode adding deep-buffer flags %x ", flags );
1592 }
1593 else {
1594 flags = AUDIO_OUTPUT_FLAG_FAST;
1595 ALOGD("voice_conc:IN call mode adding fast flags %x ", flags );
1596 }
1597 }
1598 }
1599 }
1600 } else if (prop_voip_enabled && mvoice_call_state) {
1601 //check if voice call is active / running in background
1602 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1603 //return only ULL ouput
1604 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1605 ((AUDIO_MODE_IN_CALL == mPrevPhoneState)
1606 && (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1607 {
1608 if(AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1609 ALOGD("voice_conc:getoutput:IN call mode return no o/p for VoIP %x",
1610 flags );
1611 return 0;
1612 }
1613 }
1614 }
1615#endif
1616#ifdef RECORD_PLAY_CONCURRENCY
1617 char recConcPropValue[PROPERTY_VALUE_MAX];
1618 bool prop_rec_play_enabled = false;
1619
1620 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
1621 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
1622 }
1623 if ((prop_rec_play_enabled) &&
Lalit Kansara33918092016-12-06 22:42:26 +05301624 ((true == mIsInputRequestOnProgress) || (mInputs.activeInputsCountOnDevices() > 0))) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301625 if (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState()) {
1626 if (AUDIO_OUTPUT_FLAG_VOIP_RX & flags) {
1627 // allow VoIP using voice path
1628 // Do nothing
1629 } else if((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1630 ALOGD("voice_conc:MODE_IN_COMM is setforcing deep buffer output for non ULL... flags: %x", flags);
1631 // use deep buffer path for all non ULL outputs
1632 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1633 }
1634 } else if ((flags & AUDIO_OUTPUT_FLAG_FAST) == 0) {
1635 ALOGD("voice_conc:Record mode is on forcing deep buffer output for non ULL... flags: %x ", flags);
1636 // use deep buffer path for all non ULL outputs
1637 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1638 }
1639 }
1640 if (prop_rec_play_enabled &&
1641 (stream == AUDIO_STREAM_ENFORCED_AUDIBLE)) {
1642 ALOGD("Record conc is on forcing ULL output for ENFORCED_AUDIBLE");
1643 flags = AUDIO_OUTPUT_FLAG_FAST;
1644 }
1645#endif
1646
Sharad Sangle4509cef2015-08-19 20:47:12 +05301647#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
Sharad Sangle36781612015-05-28 16:15:16 +05301648 /*
1649 * WFD audio routes back to target speaker when starting a ringtone playback.
1650 * This is because primary output is reused for ringtone, so output device is
1651 * updated based on SONIFICATION strategy for both ringtone and music playback.
1652 * The same issue is not seen on remoted_submix HAL based WFD audio because
1653 * primary output is not reused and a new output is created for ringtone playback.
1654 * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is
1655 * a non-music stream playback on WFD, so primary output is not reused for ringtone.
1656 */
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001657 audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types();
1658 if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY)
1659 && (stream != AUDIO_STREAM_MUSIC)) {
Sharad Sangle36781612015-05-28 16:15:16 +05301660 ALOGD("WFD audio: use OUTPUT_FLAG_FAST for non music stream. flags:%x", flags );
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001661 //For voip paths
1662 if(flags & AUDIO_OUTPUT_FLAG_DIRECT)
1663 flags = AUDIO_OUTPUT_FLAG_DIRECT;
1664 else //route every thing else to ULL path
1665 flags = AUDIO_OUTPUT_FLAG_FAST;
1666 }
Sharad Sangle4509cef2015-08-19 20:47:12 +05301667#endif
1668
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001669 // open a direct output if required by specified parameters
vivek mehta0ea887a2015-08-26 14:01:20 -07001670 // force direct flag if offload flag is set: offloading implies a direct output stream
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001671 // and all common behaviors are driven by checking only the direct flag
1672 // this should normally be set appropriately in the policy configuration file
1673 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
1674 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1675 }
1676 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1677 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1678 }
vivek mehta0ea887a2015-08-26 14:01:20 -07001679
Dhananjay Kumarac341582017-02-23 23:42:25 +05301680 // Do internal direct magic here
1681 bool offload_disabled = property_get_bool("audio.offload.disable", false);
1682 if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
1683 (stream == AUDIO_STREAM_MUSIC) &&
1684 (offloadInfo != NULL) && !offload_disabled &&
1685 ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
1686 audio_output_flags_t old_flags = flags;
1687 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT);
1688 ALOGD("AudioCustomHAL --> Force Direct Flag .. old flags(0x%x)", old_flags);
1689 } else if (flags == AUDIO_OUTPUT_FLAG_DIRECT && offload_disabled) {
1690 ALOGD("AudioCustomHAL --> offloading is disabled: Force Remove Direct Flag");
1691 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_NONE);
1692 }
1693
vivek mehta4b0d8192015-10-16 00:25:59 -07001694 bool forced_deep = false;
Sharad Sangle36781612015-05-28 16:15:16 +05301695 // only allow deep buffering for music stream type
1696 if (stream != AUDIO_STREAM_MUSIC) {
1697 flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
Sharad Sangle497aef82015-08-03 17:55:48 +05301698 } else if (/* stream == AUDIO_STREAM_MUSIC && */
1699 flags == AUDIO_OUTPUT_FLAG_NONE &&
1700 property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
vivek mehtac984b992015-11-25 13:28:55 -08001701 forced_deep = true;
Sharad Sangle36781612015-05-28 16:15:16 +05301702 }
Sharad Sangle497aef82015-08-03 17:55:48 +05301703
Sharad Sangle36781612015-05-28 16:15:16 +05301704 if (stream == AUDIO_STREAM_TTS) {
1705 flags = AUDIO_OUTPUT_FLAG_TTS;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001706 }
1707
1708 sp<IOProfile> profile;
1709
1710 // skip direct output selection if the request can obviously be attached to a mixed output
1711 // and not explicitly requested
Dhananjay Kumarac341582017-02-23 23:42:25 +05301712 if (((flags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301713 audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX &&
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001714 audio_channel_count_from_out_mask(channelMask) <= 2) {
1715 goto non_direct_output;
1716 }
1717
Garmond Leungfcb00d92017-01-31 11:12:47 -08001718 // Do not allow offloading if one non offloadable effect is enabled or MasterMono is enabled.
1719 // This prevents creating an offloaded track and tearing it down immediately after start
1720 // when audioflinger detects there is an active non offloadable effect.
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001721 // FIXME: We should check the audio session here but we do not have it in this context.
1722 // This may prevent offloading in rare situations where effects are left active by apps
1723 // in the background.
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001724 //
1725 // Supplementary annotation:
1726 // For sake of track offload introduced, we need a rollback for both compress offload
1727 // and track offload use cases.
Dhananjay Kumarac341582017-02-23 23:42:25 +05301728 if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT)) &&
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001729 (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) {
1730 ALOGD("non offloadable effect is enabled, try with non direct output");
1731 goto non_direct_output;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001732 }
1733
Weiyin Jiang6bba3202016-03-03 14:49:36 +08001734 profile = getProfileForDirectOutput(device,
1735 samplingRate,
1736 format,
1737 channelMask,
1738 (audio_output_flags_t)flags);
1739
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001740 if (profile != 0) {
vivek mehtac984b992015-11-25 13:28:55 -08001741
Dhananjay Kumarac341582017-02-23 23:42:25 +05301742 if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
1743 (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT)) {
1744 ALOGI("got Direct without requesting ... reject ");
vivek mehtac984b992015-11-25 13:28:55 -08001745 profile = NULL;
1746 goto non_direct_output;
1747 }
1748
Sharad Sangle36781612015-05-28 16:15:16 +05301749 sp<SwAudioOutputDescriptor> outputDesc = NULL;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001750
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001751 // if multiple concurrent offload decode is supported
1752 // do no check for reuse and also don't close previous output if its offload
1753 // previous output will be closed during track destruction
1754 if (!(property_get_bool("audio.offload.multiple.enabled", false) &&
Dhananjay Kumarac341582017-02-23 23:42:25 +05301755 ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0))) {
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001756 for (size_t i = 0; i < mOutputs.size(); i++) {
1757 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1758 if (!desc->isDuplicated() && (profile == desc->mProfile)) {
1759 outputDesc = desc;
Garmond Leungfcb00d92017-01-31 11:12:47 -08001760 // reuse direct output if currently open by the same client
1761 // and configured with same parameters
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001762 if ((samplingRate == outputDesc->mSamplingRate) &&
Ashish Jain40cab3a2016-03-23 11:14:14 +05301763 audio_formats_match(format, outputDesc->mFormat) &&
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001764 (channelMask == outputDesc->mChannelMask)) {
Garmond Leungfcb00d92017-01-31 11:12:47 -08001765 if (clientUid == outputDesc->mDirectClientUid) {
1766 outputDesc->mDirectOpenCount++;
1767 ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
1768 return mOutputs.keyAt(i);
1769 } else {
1770 ALOGV("getOutput() do not reuse direct output because current client (%ld) "
1771 "is not the same as requesting client (%ld)",
1772 (long)outputDesc->mDirectClientUid, (long)clientUid);
1773 goto non_direct_output;
1774 }
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001775 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001776 }
1777 }
Mingming Yin4a4a8c82015-10-21 11:05:08 -07001778 // close direct output if currently open and configured with different parameters
1779 if (outputDesc != NULL) {
1780 closeOutput(outputDesc->mIoHandle);
1781 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001782 }
Sharad Sangle36781612015-05-28 16:15:16 +05301783
1784 // if the selected profile is offloaded and no offload info was specified,
1785 // create a default one
1786 audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER;
Ashish Jain40cab3a2016-03-23 11:14:14 +05301787 if ((profile->getFlags() & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) {
Sharad Sangle36781612015-05-28 16:15:16 +05301788 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
1789 defaultOffloadInfo.sample_rate = samplingRate;
1790 defaultOffloadInfo.channel_mask = channelMask;
1791 defaultOffloadInfo.format = format;
1792 defaultOffloadInfo.stream_type = stream;
1793 defaultOffloadInfo.bit_rate = 0;
1794 defaultOffloadInfo.duration_us = -1;
1795 defaultOffloadInfo.has_video = true; // conservative
1796 defaultOffloadInfo.is_streaming = true; // likely
1797 offloadInfo = &defaultOffloadInfo;
1798 }
1799
1800 outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001801 outputDesc->mDevice = device;
1802 outputDesc->mLatency = 0;
Sharad Sangle36781612015-05-28 16:15:16 +05301803 outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001804 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1805 config.sample_rate = samplingRate;
1806 config.channel_mask = channelMask;
1807 config.format = format;
1808 if (offloadInfo != NULL) {
1809 config.offload_info = *offloadInfo;
1810 }
Sharad Sangle36781612015-05-28 16:15:16 +05301811 status = mpClientInterface->openOutput(profile->getModuleHandle(),
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001812 &output,
1813 &config,
1814 &outputDesc->mDevice,
1815 String8(""),
1816 &outputDesc->mLatency,
1817 outputDesc->mFlags);
1818
1819 // only accept an output with the requested parameters
1820 if (status != NO_ERROR ||
1821 (samplingRate != 0 && samplingRate != config.sample_rate) ||
Ashish Jain40cab3a2016-03-23 11:14:14 +05301822 (format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) ||
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001823 (channelMask != 0 && channelMask != config.channel_mask)) {
1824 ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
1825 "format %d %d, channelMask %04x %04x", output, samplingRate,
1826 outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
1827 outputDesc->mChannelMask);
1828 if (output != AUDIO_IO_HANDLE_NONE) {
1829 mpClientInterface->closeOutput(output);
1830 }
Sharad Sangle36781612015-05-28 16:15:16 +05301831 // fall back to mixer output if possible when the direct output could not be open
Ashish Jain40cab3a2016-03-23 11:14:14 +05301832 if (audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX) {
Sharad Sangle36781612015-05-28 16:15:16 +05301833 goto non_direct_output;
1834 }
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001835 return AUDIO_IO_HANDLE_NONE;
1836 }
1837 outputDesc->mSamplingRate = config.sample_rate;
1838 outputDesc->mChannelMask = config.channel_mask;
1839 outputDesc->mFormat = config.format;
1840 outputDesc->mRefCount[stream] = 0;
1841 outputDesc->mStopTime[stream] = 0;
1842 outputDesc->mDirectOpenCount = 1;
Garmond Leungfcb00d92017-01-31 11:12:47 -08001843 outputDesc->mDirectClientUid = clientUid;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001844
1845 audio_io_handle_t srcOutput = getOutputForEffect();
1846 addOutput(output, outputDesc);
1847 audio_io_handle_t dstOutput = getOutputForEffect();
1848 if (dstOutput == output) {
Gao Jiedb057832015-11-12 08:51:22 +08001849#ifdef DOLBY_ENABLE
1850 status_t status = mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
1851 if (status == NO_ERROR) {
1852 for (size_t i = 0; i < mEffects.size(); i++) {
1853 sp<EffectDescriptor> desc = mEffects.valueAt(i);
1854 if (desc->mSession == AUDIO_SESSION_OUTPUT_MIX) {
1855 // update the mIo member of EffectDescriptor for the global effect
1856 ALOGV("%s updating mIo", __FUNCTION__);
1857 desc->mIo = dstOutput;
1858 }
1859 }
1860 } else {
1861 ALOGW("%s moveEffects from %d to %d failed", __FUNCTION__, srcOutput, dstOutput);
1862 }
1863#else // DOLBY_END
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001864 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
Gao Jiedb057832015-11-12 08:51:22 +08001865#endif // LINE_ADDED_BY_DOLBY
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001866 }
1867 mPreviousOutputs = mOutputs;
1868 ALOGV("getOutput() returns new direct output %d", output);
1869 mpClientInterface->onAudioPortListUpdate();
1870 return output;
1871 }
1872
1873non_direct_output:
Ashish Jain5fe12412016-04-18 18:44:17 +05301874
1875 // A request for HW A/V sync cannot fallback to a mixed output because time
1876 // stamps are embedded in audio data
1877 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1878 return AUDIO_IO_HANDLE_NONE;
1879 }
1880
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001881 // ignoring channel mask due to downmix capability in mixer
1882
1883 // open a non direct output
1884
1885 // for non direct outputs, only PCM is supported
1886 if (audio_is_linear_pcm(format)) {
1887 // get which output is suitable for the specified stream. The actual
1888 // routing change will happen when startOutput() will be called
1889 SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
1890
1891 // at this stage we should ignore the DIRECT flag as no direct output could be found earlier
1892 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT);
Ashish Jain660d3112016-06-20 10:16:51 +05301893
1894 if (forced_deep) {
1895 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
1896 ALOGI("setting force DEEP buffer now ");
1897 } else if(flags == AUDIO_OUTPUT_FLAG_NONE) {
1898 // no deep buffer playback is requested hence fallback to primary
1899 flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_PRIMARY);
1900 ALOGI("FLAG None hence request for a primary output");
1901 }
1902
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001903 output = selectOutput(outputs, flags, format);
1904 }
1905 ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d,"
1906 "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
1907
vivek mehta0ea887a2015-08-26 14:01:20 -07001908 ALOGV("getOutputForDevice() returns output %d", output);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07001909
1910 return output;
1911}
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301912
1913status_t AudioPolicyManagerCustom::getInputForAttr(const audio_attributes_t *attr,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001914 audio_io_handle_t *input,
1915 audio_session_t session,
1916 uid_t uid,
1917 const audio_config_base_t *config,
1918 audio_input_flags_t flags,
1919 audio_port_handle_t selectedDeviceId,
1920 input_type_t *inputType,
1921 audio_port_handle_t *portId)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301922{
Ashish Jain40cab3a2016-03-23 11:14:14 +05301923 audio_source_t inputSource;
1924 inputSource = attr->source;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301925#ifdef VOICE_CONCURRENCY
1926
1927 char propValue[PROPERTY_VALUE_MAX];
1928 bool prop_rec_enabled=false, prop_voip_enabled = false;
1929
1930 if(property_get("voice.record.conc.disabled", propValue, NULL)) {
1931 prop_rec_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1932 }
1933
1934 if(property_get("voice.voip.conc.disabled", propValue, NULL)) {
1935 prop_voip_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
1936 }
1937
1938 if (prop_rec_enabled && mvoice_call_state) {
1939 //check if voice call is active / running in background
1940 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1941 //Need to block input request
1942 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1943 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
1944 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1945 {
1946 switch(inputSource) {
1947 case AUDIO_SOURCE_VOICE_UPLINK:
1948 case AUDIO_SOURCE_VOICE_DOWNLINK:
1949 case AUDIO_SOURCE_VOICE_CALL:
1950 ALOGD("voice_conc:Creating input during incall mode for inputSource: %d",
1951 inputSource);
1952 break;
1953
1954 case AUDIO_SOURCE_VOICE_COMMUNICATION:
1955 if(prop_voip_enabled) {
1956 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
1957 inputSource);
1958 return NO_INIT;
1959 }
1960 break;
1961 default:
1962 ALOGD("voice_conc:BLOCK VoIP requst incall mode for inputSource: %d",
1963 inputSource);
1964 return NO_INIT;
1965 }
1966 }
1967 }//check for VoIP flag
1968 else if(prop_voip_enabled && mvoice_call_state) {
1969 //check if voice call is active / running in background
1970 //some of VoIP apps(like SIP2SIP call) supports resume of VoIP call when call in progress
1971 //Need to block input request
1972 if((AUDIO_MODE_IN_CALL == mEngine->getPhoneState()) ||
1973 ((AUDIO_MODE_IN_CALL == mPrevPhoneState) &&
1974 (AUDIO_MODE_IN_COMMUNICATION == mEngine->getPhoneState())))
1975 {
1976 if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1977 ALOGD("BLOCKING VoIP request during incall mode for inputSource: %d ",inputSource);
1978 return NO_INIT;
1979 }
1980 }
1981 }
1982
1983#endif
1984
1985 return AudioPolicyManager::getInputForAttr(attr,
1986 input,
1987 session,
1988 uid,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001989 config,
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301990 flags,
1991 selectedDeviceId,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001992 inputType,
1993 portId);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301994}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08001995
Garmond Leungfcb00d92017-01-31 11:12:47 -08001996
Sharad Sanglec5766ff2015-06-04 20:24:10 +05301997status_t AudioPolicyManagerCustom::startInput(audio_io_handle_t input,
Garmond Leungfcb00d92017-01-31 11:12:47 -08001998 audio_session_t session,
1999 concurrency_type__mask_t *concurrency)
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302000{
2001 ALOGV("startInput() input %d", input);
Garmond Leungfcb00d92017-01-31 11:12:47 -08002002 *concurrency = API_INPUT_CONCURRENCY_NONE;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302003 ssize_t index = mInputs.indexOfKey(input);
2004 if (index < 0) {
2005 ALOGW("startInput() unknown input %d", input);
2006 return BAD_VALUE;
2007 }
2008 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(index);
2009
Ashish Jain40cab3a2016-03-23 11:14:14 +05302010 sp<AudioSession> audioSession = inputDesc->getAudioSession(session);
2011 if (audioSession == 0) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302012 ALOGW("startInput() unknown session %d on input %d", session, input);
2013 return BAD_VALUE;
2014 }
2015
Garmond Leungfcb00d92017-01-31 11:12:47 -08002016 if (!isConcurentCaptureAllowed(inputDesc, audioSession)) {
2017 ALOGW("startInput(%d) failed: other input already started", input);
2018 return INVALID_OPERATION;
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302019 }
2020
Garmond Leungfcb00d92017-01-31 11:12:47 -08002021 if (isInCall()) {
2022 *concurrency |= API_INPUT_CONCURRENCY_CALL;
2023 }
2024
2025 if (mInputs.activeInputsCountOnDevices() != 0) {
2026 *concurrency |= API_INPUT_CONCURRENCY_CAPTURE;
2027 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302028#ifdef RECORD_PLAY_CONCURRENCY
2029 mIsInputRequestOnProgress = true;
2030
2031 char getPropValue[PROPERTY_VALUE_MAX];
2032 bool prop_rec_play_enabled = false;
2033
2034 if (property_get("rec.playback.conc.disabled", getPropValue, NULL)) {
2035 prop_rec_play_enabled = atoi(getPropValue) || !strncmp("true", getPropValue, 4);
2036 }
2037
Garmond Leungfcb00d92017-01-31 11:12:47 -08002038 if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)){
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302039 // send update to HAL on record playback concurrency
2040 AudioParameter param = AudioParameter();
2041 param.add(String8("rec_play_conc_on"), String8("true"));
2042 ALOGD("startInput() setParameters rec_play_conc is setting to ON ");
2043 mpClientInterface->setParameters(0, param.toString());
2044
2045 // Call invalidate to reset all opened non ULL audio tracks
2046 // Move tracks associated to this strategy from previous output to new output
Garmond Leungfcb00d92017-01-31 11:12:47 -08002047 for (int i = AUDIO_STREAM_SYSTEM; i < AUDIO_STREAM_FOR_POLICY_CNT; i++) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302048 // Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder)
Garmond Leungfcb00d92017-01-31 11:12:47 -08002049 if (i != AUDIO_STREAM_ENFORCED_AUDIBLE) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302050 ALOGD("Invalidate on releaseInput for stream :: %d ", i);
2051 //FIXME see fixme on name change
2052 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2053 }
2054 }
2055 // close compress tracks
2056 for (size_t i = 0; i < mOutputs.size(); i++) {
2057 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i);
2058 if ((outputDesc == NULL) || (outputDesc->mProfile == NULL)) {
2059 ALOGD("ouput desc / profile is NULL");
2060 continue;
2061 }
2062 if (outputDesc->mProfile->mFlags
2063 & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
2064 // close compress sessions
2065 ALOGD("calling closeOutput on record conc for COMPRESS output");
2066 closeOutput(mOutputs.keyAt(i));
2067 }
2068 }
Ashish Jaine4a22d52016-06-22 11:55:08 +05302069 // If effects where present on any of the above closed outputs,
2070 // audioflinger moved them to the primary output by default
2071 // move them back to the appropriate output.
2072 moveGlobalEffect();
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302073 }
2074#endif
2075
Garmond Leungfcb00d92017-01-31 11:12:47 -08002076 // increment activity count before calling getNewInputDevice() below as only active sessions
2077 // are considered for device selection
2078 audioSession->changeActiveCount(1);
2079
2080 // Routing?
2081 mInputRoutes.incRouteActivity(session);
2082
2083 if (audioSession->activeCount() == 1 || mInputRoutes.hasRouteChanged(session)) {
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05302084 // indicate active capture to sound trigger service if starting capture from a mic on
2085 // primary HW module
Garmond Leungfcb00d92017-01-31 11:12:47 -08002086 audio_devices_t device = getNewInputDevice(inputDesc);
Sharad Sanglec66b9ca2016-12-21 18:40:54 +05302087 setInputDevice(input, device, true /* force */);
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302088
Garmond Leungfcb00d92017-01-31 11:12:47 -08002089 if (inputDesc->getAudioSessionCount(true/*activeOnly*/) == 1) {
2090 // if input maps to a dynamic policy with an activity listener, notify of state change
2091 if ((inputDesc->mPolicyMix != NULL)
2092 && ((inputDesc->mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0)) {
2093 mpClientInterface->onDynamicPolicyMixStateUpdate(inputDesc->mPolicyMix->mDeviceAddress,
2094 MIX_STATE_MIXING);
Ashish Jain630c5e12016-04-18 11:50:21 +05302095 }
Garmond Leungfcb00d92017-01-31 11:12:47 -08002096
2097 audio_devices_t primaryInputDevices = availablePrimaryInputDevices();
2098 if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
2099 mInputs.activeInputsCountOnDevices(primaryInputDevices) == 1) {
2100 SoundTrigger::setCaptureState(true);
2101 }
2102
2103 // automatically enable the remote submix output when input is started if not
2104 // used by a policy mix of type MIX_TYPE_RECORDERS
2105 // For remote submix (a virtual device), we open only one input per capture request.
2106 if (audio_is_remote_submix_device(inputDesc->mDevice)) {
2107 String8 address = String8("");
2108 if (inputDesc->mPolicyMix == NULL) {
2109 address = String8("0");
2110 } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) {
2111 address = inputDesc->mPolicyMix->mDeviceAddress;
2112 }
2113 if (address != "") {
2114 setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
2115 AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
2116 address, "remote-submix");
2117 }
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302118 }
2119 }
2120 }
2121
Ashish Jain40cab3a2016-03-23 11:14:14 +05302122 ALOGV("AudioPolicyManager::startInput() input source = %d", audioSession->inputSource());
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302123#ifdef RECORD_PLAY_CONCURRENCY
2124 mIsInputRequestOnProgress = false;
2125#endif
2126 return NO_ERROR;
2127}
Weiyin Jiangd211ef52016-02-16 15:55:11 +08002128
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302129status_t AudioPolicyManagerCustom::stopInput(audio_io_handle_t input,
2130 audio_session_t session)
2131{
2132 status_t status;
2133 status = AudioPolicyManager::stopInput(input, session);
2134#ifdef RECORD_PLAY_CONCURRENCY
2135 char propValue[PROPERTY_VALUE_MAX];
2136 bool prop_rec_play_enabled = false;
2137
2138 if (property_get("rec.playback.conc.disabled", propValue, NULL)) {
2139 prop_rec_play_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
2140 }
2141
Lalit Kansara33918092016-12-06 22:42:26 +05302142 if ((prop_rec_play_enabled) && (mInputs.activeInputsCountOnDevices() == 0)) {
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302143
2144 //send update to HAL on record playback concurrency
2145 AudioParameter param = AudioParameter();
2146 param.add(String8("rec_play_conc_on"), String8("false"));
2147 ALOGD("stopInput() setParameters rec_play_conc is setting to OFF ");
2148 mpClientInterface->setParameters(0, param.toString());
2149
2150 //call invalidate tracks so that any open streams can fall back to deep buffer/compress path from ULL
2151 for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
2152 //Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder stop tone)
2153 if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE) && (i != AUDIO_STREAM_PATCH)) {
2154 ALOGD(" Invalidate on stopInput for stream :: %d ", i);
2155 //FIXME see fixme on name change
2156 mpClientInterface->invalidateStream((audio_stream_type_t)i);
2157 }
2158 }
2159 }
2160#endif
2161 return status;
2162}
2163
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302164void AudioPolicyManagerCustom::closeAllInputs() {
2165 bool patchRemoved = false;
2166
Dhanalakshmi Siddanibfeca7f2015-10-08 15:17:11 +05302167 for(size_t input_index = mInputs.size(); input_index > 0; input_index--) {
2168 sp<AudioInputDescriptor> inputDesc = mInputs.valueAt(input_index-1);
Ashish Jain40cab3a2016-03-23 11:14:14 +05302169 ssize_t patch_index = mAudioPatches.indexOfKey(inputDesc->getPatchHandle());
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302170 if (patch_index >= 0) {
2171 sp<AudioPatch> patchDesc = mAudioPatches.valueAt(patch_index);
Garmond Leungfcb00d92017-01-31 11:12:47 -08002172 (void) /*status_t status*/ mpClientInterface->releaseAudioPatch(patchDesc->mAfPatchHandle, 0);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302173 mAudioPatches.removeItemsAt(patch_index);
2174 patchRemoved = true;
2175 }
Haynes Mathew George2e4655a2017-01-05 15:01:53 -08002176 mpClientInterface->closeInput(mInputs.keyAt(input_index-1));
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302177 }
Ashish Jain40cab3a2016-03-23 11:14:14 +05302178 mInputs.clear();
2179 SoundTrigger::setCaptureState(false);
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +05302180 nextAudioPortGeneration();
2181
2182 if (patchRemoved) {
2183 mpClientInterface->onAudioPatchListUpdate();
2184 }
2185}
2186
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302187AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
Sharad Sangle4509cef2015-08-19 20:47:12 +05302188 : AudioPolicyManager(clientInterface),
2189 mHdmiAudioDisabled(false),
2190 mHdmiAudioEvent(false),
Garmond Leungfcb00d92017-01-31 11:12:47 -08002191#ifndef FM_POWER_OPT
2192 mPrevPhoneState(0)
2193#else
Haynes Mathew George0b2c3772015-12-14 14:22:07 -08002194 mPrevPhoneState(0),
Haynes Mathew George603ae9b2015-12-21 17:23:59 -08002195 mPrevFMVolumeDb(0.0f),
2196 mFMIsActive(false)
Garmond Leungfcb00d92017-01-31 11:12:47 -08002197#endif
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302198{
Ashish Jain40cab3a2016-03-23 11:14:14 +05302199
Satya Krishna Pindiproli8f83f102016-06-21 17:56:14 +05302200#ifdef USE_XML_AUDIO_POLICY_CONF
2201 ALOGD("USE_XML_AUDIO_POLICY_CONF is TRUE");
2202#else
2203 ALOGD("USE_XML_AUDIO_POLICY_CONF is FALSE");
2204#endif
2205
Sharad Sanglec5766ff2015-06-04 20:24:10 +05302206#ifdef RECORD_PLAY_CONCURRENCY
2207 mIsInputRequestOnProgress = false;
2208#endif
2209
2210
2211#ifdef VOICE_CONCURRENCY
2212 mFallBackflag = getFallBackPath();
2213#endif
2214}
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07002215}