blob: f4c0722296bf0323240ef4285ede31db1fd5f327 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sangleca67a022015-05-28 16:15:16 +05302 * Copyright (c) 2013-2015, 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.
18 */
19
Sharad Sangleca67a022015-05-28 16:15:16 +053020#define LOG_TAG "AudioPolicyManagerCustom"
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070021//#define LOG_NDEBUG 0
22
23//#define VERY_VERBOSE_LOGGING
24#ifdef VERY_VERBOSE_LOGGING
25#define ALOGVV ALOGV
26#else
27#define ALOGVV(a...) do { } while(0)
28#endif
29
Sharad Sangleca67a022015-05-28 16:15:16 +053030#define MIN(a, b) ((a) < (b) ? (a) : (b))
31
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070032// A device mask for all audio output devices that are considered "remote" when evaluating
33// active output devices in isStreamActiveRemotely()
34#define APM_AUDIO_OUT_DEVICE_REMOTE_ALL AUDIO_DEVICE_OUT_REMOTE_SUBMIX
Sharad Sangleca67a022015-05-28 16:15:16 +053035// A device mask for all audio input and output devices where matching inputs/outputs on device
36// type alone is not enough: the address must match too
37#define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \
38 AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
39// Following delay should be used if the calculated routing delay from all active
40// input streams is higher than this value
41#define MAX_VOICE_CALL_START_DELAY_MS 100
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070042
Sharad Sangleca67a022015-05-28 16:15:16 +053043#include <inttypes.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070044#include <math.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070045
Sharad Sangleca67a022015-05-28 16:15:16 +053046#include <cutils/properties.h>
47#include <utils/Log.h>
48#include <hardware/audio.h>
49#include <hardware/audio_effect.h>
50#include <media/AudioParameter.h>
51#include <soundtrigger/SoundTrigger.h>
52#include "AudioPolicyManager.h"
53#include <policy.h>
54
55namespace android {
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070056
57// ----------------------------------------------------------------------------
58// AudioPolicyInterface implementation
59// ----------------------------------------------------------------------------
Sharad Sangleca67a022015-05-28 16:15:16 +053060extern "C" AudioPolicyInterface* createAudioPolicyManager(
61 AudioPolicyClientInterface *clientInterface)
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070062{
Sharad Sangleca67a022015-05-28 16:15:16 +053063 return new AudioPolicyManagerCustom(clientInterface);
64}
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070065
Sharad Sangleca67a022015-05-28 16:15:16 +053066extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
67{
68 delete interface;
69}
70
71status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t device,
72 audio_policy_dev_state_t state,
73 const char *device_address,
74 const char *device_name)
75{
76 ALOGV("setDeviceConnectionStateInt() device: 0x%X, state %d, address %s name %s",
77 device, state, device_address, device_name);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070078
79 // connect/disconnect only 1 device at a time
80 if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE;
81
Sharad Sangleca67a022015-05-28 16:15:16 +053082 sp<DeviceDescriptor> devDesc =
83 mHwModules.getDeviceDescriptor(device, device_address, device_name);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070084
85 // handle output devices
86 if (audio_is_output_device(device)) {
Sharad Sangleca67a022015-05-28 16:15:16 +053087 SortedVector <audio_io_handle_t> outputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070088
Sharad Sangleca67a022015-05-28 16:15:16 +053089 ssize_t index = mAvailableOutputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070090
91 // save a copy of the opened output descriptors before any output is opened or closed
92 // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies()
93 mPreviousOutputs = mOutputs;
94 switch (state)
95 {
96 // handle output device connection
Sharad Sangleca67a022015-05-28 16:15:16 +053097 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
98 if (index >= 0) {
Ramjee Singhae5f8902015-08-19 20:47:12 +053099#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
100 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
101 if (!strncmp(device_address, "hdmi_spkr", 9)) {
102 mHdmiAudioDisabled = false;
103 } else {
104 mHdmiAudioEvent = true;
105 }
106 }
107#endif
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700108 ALOGW("setDeviceConnectionState() device already connected: %x", device);
109 return INVALID_OPERATION;
110 }
111 ALOGV("setDeviceConnectionState() connecting device %x", device);
112
Sharad Sangleca67a022015-05-28 16:15:16 +0530113 // register new device as available
114 index = mAvailableOutputDevices.add(devDesc);
Ramjee Singhae5f8902015-08-19 20:47:12 +0530115#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
116 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
117 if (!strncmp(device_address, "hdmi_spkr", 9)) {
118 mHdmiAudioDisabled = false;
119 } else {
120 mHdmiAudioEvent = true;
121 }
122 if (mHdmiAudioDisabled || !mHdmiAudioEvent) {
123 mAvailableOutputDevices.remove(devDesc);
124 ALOGW("HDMI sink not connected, do not route audio to HDMI out");
125 return INVALID_OPERATION;
126 }
127 }
128#endif
Sharad Sangleca67a022015-05-28 16:15:16 +0530129 if (index >= 0) {
130 sp<HwModule> module = mHwModules.getModuleForDevice(device);
131 if (module == 0) {
132 ALOGD("setDeviceConnectionState() could not find HW module for device %08x",
133 device);
134 mAvailableOutputDevices.remove(devDesc);
135 return INVALID_OPERATION;
136 }
137 mAvailableOutputDevices[index]->attach(module);
138 } else {
139 return NO_MEMORY;
140 }
141
142 if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) {
143 mAvailableOutputDevices.remove(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700144 return INVALID_OPERATION;
145 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530146 // Propagate device availability to Engine
147 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700148
Sharad Sangleca67a022015-05-28 16:15:16 +0530149 // outputs should never be empty here
150 ALOG_ASSERT(outputs.size() != 0, "setDeviceConnectionState():"
151 "checkOutputsForDevice() returned no outputs but status OK");
152 ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %zu outputs",
153 outputs.size());
154
155 // Send connect to HALs
156 AudioParameter param = AudioParameter(devDesc->mAddress);
157 param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device);
158 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
159
160 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700161 // handle output device disconnection
Sharad Sangleca67a022015-05-28 16:15:16 +0530162 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
163 if (index < 0) {
Ramjee Singhae5f8902015-08-19 20:47:12 +0530164#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
165 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
166 if (!strncmp(device_address, "hdmi_spkr", 9)) {
167 mHdmiAudioDisabled = true;
168 } else {
169 mHdmiAudioEvent = false;
170 }
171 }
172#endif
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700173 ALOGW("setDeviceConnectionState() device not connected: %x", device);
174 return INVALID_OPERATION;
175 }
176
Sharad Sangleca67a022015-05-28 16:15:16 +0530177 ALOGV("setDeviceConnectionState() disconnecting output device %x", device);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700178
Sharad Sangleca67a022015-05-28 16:15:16 +0530179 // Send Disconnect to HALs
180 AudioParameter param = AudioParameter(devDesc->mAddress);
181 param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
182 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
183
184 // remove device from available output devices
185 mAvailableOutputDevices.remove(devDesc);
Ramjee Singhae5f8902015-08-19 20:47:12 +0530186#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
187 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
188 if (!strncmp(device_address, "hdmi_spkr", 9)) {
189 mHdmiAudioDisabled = true;
190 } else {
191 mHdmiAudioEvent = false;
192 }
193 }
194#endif
Sharad Sangleca67a022015-05-28 16:15:16 +0530195 checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress);
196
197 // Propagate device availability to Engine
198 mEngine->setDeviceConnectionState(devDesc, state);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700199 } break;
200
201 default:
202 ALOGE("setDeviceConnectionState() invalid state: %x", state);
203 return BAD_VALUE;
204 }
205
Sharad Sangleca67a022015-05-28 16:15:16 +0530206 // checkA2dpSuspend must run before checkOutputForAllStrategies so that A2DP
207 // output is suspended before any tracks are moved to it
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700208 checkA2dpSuspend();
209 checkOutputForAllStrategies();
210 // outputs must be closed after checkOutputForAllStrategies() is executed
211 if (!outputs.isEmpty()) {
212 for (size_t i = 0; i < outputs.size(); i++) {
Sharad Sangleca67a022015-05-28 16:15:16 +0530213 sp<SwAudioOutputDescriptor> desc = mOutputs.valueFor(outputs[i]);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700214 // close unused outputs after device disconnection or direct outputs that have been
215 // opened by checkOutputsForDevice() to query dynamic parameters
Sharad Sangleca67a022015-05-28 16:15:16 +0530216 if ((state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) ||
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700217 (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) &&
218 (desc->mDirectOpenCount == 0))) {
219 closeOutput(outputs[i]);
220 }
221 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530222 // check again after closing A2DP output to reset mA2dpSuspended if needed
223 checkA2dpSuspend();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700224 }
225
226 updateDevicesAndOutputs();
Sharad Sangleca67a022015-05-28 16:15:16 +0530227 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
228 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
229 updateCallRouting(newDevice);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700230 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700231 for (size_t i = 0; i < mOutputs.size(); i++) {
Sharad Sangleca67a022015-05-28 16:15:16 +0530232 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
233 if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (desc != mPrimaryOutput)) {
234 audio_devices_t newDevice = getNewOutputDevice(desc, true /*fromCache*/);
235 // do not force device change on duplicated output because if device is 0, it will
236 // also force a device 0 for the two outputs it is duplicated to which may override
237 // a valid device selection on those outputs.
238 bool force = !desc->isDuplicated()
239 && (!device_distinguishes_on_address(device)
240 // always force when disconnecting (a non-duplicated device)
241 || (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
242 setOutputDevice(desc, newDevice, force, 0);
Satya Krishna Pindiproli5cf8c1a2014-05-08 12:22:16 +0530243 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700244 }
245
Sharad Sangleca67a022015-05-28 16:15:16 +0530246 mpClientInterface->onAudioPortListUpdate();
247 return NO_ERROR;
248 } // end if is output device
249
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700250 // handle input devices
251 if (audio_is_input_device(device)) {
Sharad Sangleca67a022015-05-28 16:15:16 +0530252 SortedVector <audio_io_handle_t> inputs;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700253
Sharad Sangleca67a022015-05-28 16:15:16 +0530254 ssize_t index = mAvailableInputDevices.indexOf(devDesc);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700255 switch (state)
256 {
257 // handle input device connection
Sharad Sangleca67a022015-05-28 16:15:16 +0530258 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
259 if (index >= 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700260 ALOGW("setDeviceConnectionState() device already connected: %d", device);
261 return INVALID_OPERATION;
262 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530263 sp<HwModule> module = mHwModules.getModuleForDevice(device);
264 if (module == NULL) {
265 ALOGW("setDeviceConnectionState(): could not find HW module for device %08x",
266 device);
267 return INVALID_OPERATION;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700268 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530269 if (checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress) != NO_ERROR) {
270 return INVALID_OPERATION;
271 }
272
273 index = mAvailableInputDevices.add(devDesc);
274 if (index >= 0) {
275 mAvailableInputDevices[index]->attach(module);
276 } else {
277 return NO_MEMORY;
278 }
279
280 // Set connect to HALs
281 AudioParameter param = AudioParameter(devDesc->mAddress);
282 param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device);
283 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
284
285 // Propagate device availability to Engine
286 mEngine->setDeviceConnectionState(devDesc, state);
287 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700288
289 // handle input device disconnection
Sharad Sangleca67a022015-05-28 16:15:16 +0530290 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
291 if (index < 0) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700292 ALOGW("setDeviceConnectionState() device not connected: %d", device);
293 return INVALID_OPERATION;
294 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530295
296 ALOGV("setDeviceConnectionState() disconnecting input device %x", device);
297
298 // Set Disconnect to HALs
299 AudioParameter param = AudioParameter(devDesc->mAddress);
300 param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
301 mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
302
303 checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress);
304 mAvailableInputDevices.remove(devDesc);
305
306 // Propagate device availability to Engine
307 mEngine->setDeviceConnectionState(devDesc, state);
308 } break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700309
310 default:
311 ALOGE("setDeviceConnectionState() invalid state: %x", state);
312 return BAD_VALUE;
313 }
314
Sharad Sangleca67a022015-05-28 16:15:16 +0530315 closeAllInputs();
316
317 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
318 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
319 updateCallRouting(newDevice);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700320 }
321
Sharad Sangleca67a022015-05-28 16:15:16 +0530322 mpClientInterface->onAudioPortListUpdate();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700323 return NO_ERROR;
Sharad Sangleca67a022015-05-28 16:15:16 +0530324 } // end if is input device
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700325
326 ALOGW("setDeviceConnectionState() invalid device: %x", device);
327 return BAD_VALUE;
328}
ApurupaPattapu0c566872014-01-10 14:46:02 -0800329// This function checks for the parameters which can be offloaded.
330// This can be enhanced depending on the capability of the DSP and policy
331// of the system.
Sharad Sangleca67a022015-05-28 16:15:16 +0530332bool AudioPolicyManagerCustom::isOffloadSupported(const audio_offload_info_t& offloadInfo)
ApurupaPattapu0c566872014-01-10 14:46:02 -0800333{
Sharad Sangleca67a022015-05-28 16:15:16 +0530334 ALOGV("isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d,"
335 " BitRate=%u, duration=%" PRId64 " us, has_video=%d",
ApurupaPattapu0c566872014-01-10 14:46:02 -0800336 offloadInfo.sample_rate, offloadInfo.channel_mask,
337 offloadInfo.format,
338 offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us,
339 offloadInfo.has_video);
340
ApurupaPattapu0c566872014-01-10 14:46:02 -0800341 // Check if stream type is music, then only allow offload as of now.
342 if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC)
343 {
344 ALOGV("isOffloadSupported: stream_type != MUSIC, returning false");
345 return false;
346 }
ApurupaPattapu0c566872014-01-10 14:46:02 -0800347
Preetam Singh Ranawatfdba8132015-07-21 19:30:09 +0530348 char propValue[PROPERTY_VALUE_MAX];
349 bool pcmOffload = false;
350#ifdef PCM_OFFLOAD_ENABLED
351 if ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM_OFFLOAD) {
352 bool prop_enabled = false;
353 if ((AUDIO_FORMAT_PCM_16_BIT_OFFLOAD == offloadInfo.format) &&
354 property_get("audio.offload.pcm.16bit.enable", propValue, NULL)) {
355 prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
356 }
357
358#ifdef PCM_OFFLOAD_ENABLED_24
359 if ((AUDIO_FORMAT_PCM_24_BIT_OFFLOAD == offloadInfo.format) &&
360 property_get("audio.offload.pcm.24bit.enable", propValue, NULL)) {
361 prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
362 }
363#endif
364
365 if (prop_enabled) {
366 ALOGI("PCM offload property is enabled");
367 pcmOffload = true;
368 }
369
370 if (!pcmOffload) {
371 ALOGD("system property not enabled for PCM offload format[%x]",offloadInfo.format);
372 return false;
373 }
374 }
375#endif
376 if (!pcmOffload) {
377 // Check if offload has been disabled
378 if (property_get("audio.offload.disable", propValue, "0")) {
379 if (atoi(propValue) != 0) {
380 ALOGV("offload disabled by audio.offload.disable=%s", propValue );
381 return false;
382 }
383 }
384 //check if it's multi-channel AAC (includes sub formats) and FLAC format
385 if ((popcount(offloadInfo.channel_mask) > 2) &&
386 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) ||
387 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS))) {
388 ALOGD("offload disabled for multi-channel AAC,FLAC and VORBIS format");
389 return false;
390 }
391#ifdef AUDIO_EXTN_FORMATS_ENABLED
392 //check if it's multi-channel FLAC/ALAC/WMA format with sample rate > 48k
393 if ((popcount(offloadInfo.channel_mask) > 2) &&
394 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) ||
395 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) && offloadInfo.sample_rate > 48000) ||
396 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) && offloadInfo.sample_rate > 48000) ||
397 (((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) && offloadInfo.sample_rate > 48000))) {
398 ALOGD("offload disabled for multi-channel FLAC/ALAC/WMA clips with sample rate > 48kHz");
399 return false;
400 }
401#endif
402 //TODO: enable audio offloading with video when ready
403 const bool allowOffloadWithVideo =
404 property_get_bool("audio.offload.video", false /* default_value */);
405 if (offloadInfo.has_video && !allowOffloadWithVideo) {
406 ALOGV("isOffloadSupported: has_video == true, returning false");
407 return false;
408 }
Manish Dewangan66e27c92015-10-13 14:04:36 +0530409
410 const bool allowOffloadStreamingWithVideo = property_get_bool("av.streaming.offload.enable",
411 false /*default value*/);
412 if(offloadInfo.has_video && offloadInfo.is_streaming && !allowOffloadStreamingWithVideo) {
413 ALOGW("offload disabled by av.streaming.offload.enable = %s ", propValue );
414 return false;
415 }
416
ApurupaPattapu0c566872014-01-10 14:46:02 -0800417 }
418
419 //If duration is less than minimum value defined in property, return false
420 if (property_get("audio.offload.min.duration.secs", propValue, NULL)) {
421 if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) {
422 ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue);
423 return false;
424 }
425 } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) {
426 ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS);
Sharad Sangleca67a022015-05-28 16:15:16 +0530427 //duration checks only valid for MP3/AAC/ formats,
ApurupaPattapu0c566872014-01-10 14:46:02 -0800428 //do not check duration for other audio formats, e.g. dolby AAC/AC3 and amrwb+ formats
Sharad Sangleca67a022015-05-28 16:15:16 +0530429 if ((offloadInfo.format == AUDIO_FORMAT_MP3) ||
430 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) ||
431 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_FLAC) ||
432 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_VORBIS) ||
433 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA) ||
434 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_WMA_PRO) ||
435 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_ALAC) ||
436 ((offloadInfo.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_APE))
ApurupaPattapu0c566872014-01-10 14:46:02 -0800437 return false;
Sharad Sangleca67a022015-05-28 16:15:16 +0530438
ApurupaPattapu0c566872014-01-10 14:46:02 -0800439 }
440
441 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
442 // creating an offloaded track and tearing it down immediately after start when audioflinger
443 // detects there is an active non offloadable effect.
444 // FIXME: We should check the audio session here but we do not have it in this context.
445 // This may prevent offloading in rare situations where effects are left active by apps
446 // in the background.
Sharad Sangleca67a022015-05-28 16:15:16 +0530447 if (mEffects.isNonOffloadableEffectEnabled()) {
ApurupaPattapu0c566872014-01-10 14:46:02 -0800448 return false;
449 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530450 // Check for soundcard status
451 String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
452 String8("SND_CARD_STATUS"));
453 AudioParameter result = AudioParameter(valueStr);
454 int isonline = 0;
455 if ((result.getInt(String8("SND_CARD_STATUS"), isonline) == NO_ERROR)
456 && !isonline) {
457 ALOGD("copl: soundcard is offline rejecting offload request");
458 return false;
459 }
ApurupaPattapu0c566872014-01-10 14:46:02 -0800460 // See if there is a profile to support this.
461 // AUDIO_DEVICE_NONE
Sharad Sangleca67a022015-05-28 16:15:16 +0530462 sp<IOProfile> profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */,
ApurupaPattapu0c566872014-01-10 14:46:02 -0800463 offloadInfo.sample_rate,
464 offloadInfo.format,
465 offloadInfo.channel_mask,
466 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
Sharad Sangleca67a022015-05-28 16:15:16 +0530467 ALOGV("isOffloadSupported() profile %sfound", profile != 0 ? "" : "NOT ");
468 return (profile != 0);
ApurupaPattapu0c566872014-01-10 14:46:02 -0800469}
Sharad Sangleca67a022015-05-28 16:15:16 +0530470audio_devices_t AudioPolicyManagerCustom::getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
471 bool fromCache)
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700472{
Sharad Sangleca67a022015-05-28 16:15:16 +0530473 audio_devices_t device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700474
Sharad Sangleca67a022015-05-28 16:15:16 +0530475 ssize_t index = mAudioPatches.indexOfKey(outputDesc->mPatchHandle);
476 if (index >= 0) {
477 sp<AudioPatch> patchDesc = mAudioPatches.valueAt(index);
478 if (patchDesc->mUid != mUidCached) {
479 ALOGV("getNewOutputDevice() device %08x forced by patch %d",
480 outputDesc->device(), outputDesc->mPatchHandle);
481 return outputDesc->device();
482 }
483 }
484
485 // check the following by order of priority to request a routing change if necessary:
486 // 1: the strategy enforced audible is active and enforced on the output:
487 // use device for strategy enforced audible
488 // 2: we are in call or the strategy phone is active on the output:
489 // use device for strategy phone
490 // 3: the strategy for enforced audible is active but not enforced on the output:
491 // use the device for strategy enforced audible
492 // 4: the strategy sonification is active on the output:
493 // use device for strategy sonification
494 // 5: the strategy "respectful" sonification is active on the output:
495 // use device for strategy "respectful" sonification
496 // 6: the strategy accessibility is active on the output:
497 // use device for strategy accessibility
498 // 7: the strategy media is active on the output:
499 // use device for strategy media
500 // 8: the strategy DTMF is active on the output:
501 // use device for strategy DTMF
502 // 9: the strategy for beacon, a.k.a. "transmitted through speaker" is active on the output:
503 // use device for strategy t-t-s
504 if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE) &&
505 mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
506 device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
507 } else if (isInCall() ||
508 isStrategyActive(outputDesc, STRATEGY_PHONE)||
509 isStrategyActive(mPrimaryOutput, STRATEGY_PHONE)) {
510 device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
511 } else if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE)) {
512 device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
513 } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION)||
514 (isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION)
515 && (!isStrategyActive(mPrimaryOutput,STRATEGY_MEDIA)))) {
516 device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
517 } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL)||
518 (isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION_RESPECTFUL)
519 && (!isStrategyActive(mPrimaryOutput, STRATEGY_MEDIA)))) {
520 device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache);
521 } else if (isStrategyActive(outputDesc, STRATEGY_ACCESSIBILITY)) {
522 device = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, fromCache);
523 } else if (isStrategyActive(outputDesc, STRATEGY_MEDIA)) {
524 device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache);
525 } else if (isStrategyActive(outputDesc, STRATEGY_DTMF)) {
526 device = getDeviceForStrategy(STRATEGY_DTMF, fromCache);
527 } else if (isStrategyActive(outputDesc, STRATEGY_TRANSMITTED_THROUGH_SPEAKER)) {
528 device = getDeviceForStrategy(STRATEGY_TRANSMITTED_THROUGH_SPEAKER, fromCache);
529 } else if (isStrategyActive(outputDesc, STRATEGY_REROUTING)) {
530 device = getDeviceForStrategy(STRATEGY_REROUTING, fromCache);
531 }
532
533 ALOGV("getNewOutputDevice() selected device %x", device);
534 return device;
535}
536void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state)
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700537{
Sharad Sangleca67a022015-05-28 16:15:16 +0530538 ALOGV("setPhoneState() state %d", state);
539 // store previous phone state for management of sonification strategy below
Ramjee Singhae5f8902015-08-19 20:47:12 +0530540 audio_devices_t newDevice = AUDIO_DEVICE_NONE;
Sharad Sangleca67a022015-05-28 16:15:16 +0530541 int oldState = mEngine->getPhoneState();
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700542
Sharad Sangleca67a022015-05-28 16:15:16 +0530543 if (mEngine->setPhoneState(state) != NO_ERROR) {
544 ALOGW("setPhoneState() invalid or same state %d", state);
545 return;
546 }
547 /// Opens: can these line be executed after the switch of volume curves???
548 // if leaving call state, handle special case of active streams
549 // pertaining to sonification strategy see handleIncallSonification()
Ramjee Singhf9345b32015-10-13 18:13:04 +0530550 if (isStateInCall(oldState)) {
Sharad Sangleca67a022015-05-28 16:15:16 +0530551 ALOGV("setPhoneState() in call state management: new state is %d", state);
552 for (size_t j = 0; j < mOutputs.size(); j++) {
553 audio_io_handle_t curOutput = mOutputs.keyAt(j);
554 for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
555 if (stream == AUDIO_STREAM_PATCH) {
556 continue;
557 }
558
559 handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput);
560 }
561 }
562
563 // force reevaluating accessibility routing when call starts
564 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
565 }
566
567 /**
568 * Switching to or from incall state or switching between telephony and VoIP lead to force
569 * routing command.
570 */
571 bool force = ((is_state_in_call(oldState) != is_state_in_call(state))
572 || (is_state_in_call(state) && (state != oldState)));
573
574 // check for device and output changes triggered by new phone state
575 checkA2dpSuspend();
576 checkOutputForAllStrategies();
577 updateDevicesAndOutputs();
578
579 sp<SwAudioOutputDescriptor> hwOutputDesc = mPrimaryOutput;
580
581 int delayMs = 0;
582 if (isStateInCall(state)) {
583 nsecs_t sysTime = systemTime();
584 for (size_t i = 0; i < mOutputs.size(); i++) {
585 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
586 // mute media and sonification strategies and delay device switch by the largest
587 // latency of any output where either strategy is active.
588 // This avoid sending the ring tone or music tail into the earpiece or headset.
589 if ((isStrategyActive(desc, STRATEGY_MEDIA,
590 SONIFICATION_HEADSET_MUSIC_DELAY,
591 sysTime) ||
592 isStrategyActive(desc, STRATEGY_SONIFICATION,
593 SONIFICATION_HEADSET_MUSIC_DELAY,
594 sysTime)) &&
595 (delayMs < (int)desc->latency()*2)) {
596 delayMs = desc->latency()*2;
597 }
598 setStrategyMute(STRATEGY_MEDIA, true, desc);
599 setStrategyMute(STRATEGY_MEDIA, false, desc, MUTE_TIME_MS,
600 getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));
601 setStrategyMute(STRATEGY_SONIFICATION, true, desc);
602 setStrategyMute(STRATEGY_SONIFICATION, false, desc, MUTE_TIME_MS,
603 getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/));
604 }
605 ALOGV("Setting the delay from %dms to %dms", delayMs,
606 MIN(delayMs, MAX_VOICE_CALL_START_DELAY_MS));
607 delayMs = MIN(delayMs, MAX_VOICE_CALL_START_DELAY_MS);
608 }
609
610 if (hasPrimaryOutput()) {
611 // Note that despite the fact that getNewOutputDevice() is called on the primary output,
612 // the device returned is not necessarily reachable via this output
613 audio_devices_t rxDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
614 // force routing command to audio hardware when ending call
615 // even if no device change is needed
616 if (isStateInCall(oldState) && rxDevice == AUDIO_DEVICE_NONE) {
617 rxDevice = mPrimaryOutput->device();
618 }
619
620 if (state == AUDIO_MODE_IN_CALL) {
621 updateCallRouting(rxDevice, delayMs);
622 } else if (oldState == AUDIO_MODE_IN_CALL) {
623 if (mCallRxPatch != 0) {
624 mpClientInterface->releaseAudioPatch(mCallRxPatch->mAfPatchHandle, 0);
625 mCallRxPatch.clear();
626 }
627 if (mCallTxPatch != 0) {
628 mpClientInterface->releaseAudioPatch(mCallTxPatch->mAfPatchHandle, 0);
629 mCallTxPatch.clear();
630 }
631 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
632 } else {
633 setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
634 }
635 }
Ramjee Singhae5f8902015-08-19 20:47:12 +0530636 //update device for all non-primary outputs
637 for (size_t i = 0; i < mOutputs.size(); i++) {
638 audio_io_handle_t output = mOutputs.keyAt(i);
639 if (output != mPrimaryOutput->mIoHandle) {
640 newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/);
641 setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE));
642 }
643 }
Sharad Sangleca67a022015-05-28 16:15:16 +0530644 // if entering in call state, handle special case of active streams
645 // pertaining to sonification strategy see handleIncallSonification()
646 if (isStateInCall(state)) {
647 ALOGV("setPhoneState() in call state management: new state is %d", state);
648 for (size_t j = 0; j < mOutputs.size(); j++) {
649 audio_io_handle_t curOutput = mOutputs.keyAt(j);
650 for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
651 if (stream == AUDIO_STREAM_PATCH) {
652 continue;
653 }
654 handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
655 }
656 }
657 }
658
659 // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE
660 if (state == AUDIO_MODE_RINGTONE &&
661 isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) {
662 mLimitRingtoneVolume = true;
663 } else {
664 mLimitRingtoneVolume = false;
665 }
666}
Dhananjay Kumar42441032015-09-16 19:44:33 +0530667
668void AudioPolicyManagerCustom::setForceUse(audio_policy_force_use_t usage,
669 audio_policy_forced_cfg_t config)
670{
671 ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mEngine->getPhoneState());
672
673 if (mEngine->setForceUse(usage, config) != NO_ERROR) {
674 ALOGW("setForceUse() could not set force cfg %d for usage %d", config, usage);
675 return;
676 }
677 bool forceVolumeReeval = (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) ||
678 (usage == AUDIO_POLICY_FORCE_FOR_DOCK) ||
679 (usage == AUDIO_POLICY_FORCE_FOR_SYSTEM);
680
681 // check for device and output changes triggered by new force usage
682 checkA2dpSuspend();
683 checkOutputForAllStrategies();
684 updateDevicesAndOutputs();
685 if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) {
686 audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/);
687 updateCallRouting(newDevice);
688 }
689 // Use reverse loop to make sure any low latency usecases (generally tones)
690 // are not routed before non LL usecases (generally music).
691 // We can safely assume that LL output would always have lower index,
692 // and use this work-around to avoid routing of output with music stream
693 // from the context of short lived LL output.
694 // Note: in case output's share backend(HAL sharing is implicit) all outputs
695 // gets routing update while processing first output itself.
696 for (size_t i = mOutputs.size(); i > 0; i--) {
697 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i-1);
698 audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/);
699 if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || outputDesc != mPrimaryOutput) {
700 setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE));
701 }
702 if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
703 applyStreamVolumes(outputDesc, newDevice, 0, true);
704 }
705 }
706
707 audio_io_handle_t activeInput = mInputs.getActiveInput();
708 if (activeInput != 0) {
709 setInputDevice(activeInput, getNewInputDevice(activeInput));
710 }
711
712}
713
Ramjee Singh5b022de2015-09-15 18:25:20 +0530714status_t AudioPolicyManagerCustom::stopSource(sp<AudioOutputDescriptor> outputDesc1,
Sharad Sangleca67a022015-05-28 16:15:16 +0530715 audio_stream_type_t stream,
716 bool forceDeviceUpdate)
717{
718 // always handle stream stop, check which stream type is stopping
Steve Kondikc1ff6852015-11-01 03:58:16 -0800719 const sp<SwAudioOutputDescriptor> outputDesc = (SwAudioOutputDescriptor *) outputDesc1.get();
Sharad Sangleca67a022015-05-28 16:15:16 +0530720 handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT);
721
722 // handle special case for sonification while in call
Ramjee Singhae5f8902015-08-19 20:47:12 +0530723 if (isInCall() && (outputDesc->mRefCount[stream] == 1)) {
Sharad Sangleca67a022015-05-28 16:15:16 +0530724 if (outputDesc->isDuplicated()) {
Ramjee Singhae5f8902015-08-19 20:47:12 +0530725 handleIncallSonification(stream, false, false, outputDesc->mOutput1->mIoHandle);
726 handleIncallSonification(stream, false, false, outputDesc->mOutput2->mIoHandle);
Sharad Sangleca67a022015-05-28 16:15:16 +0530727 }
728 handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
729 }
730
731 if (outputDesc->mRefCount[stream] > 0) {
732 // decrement usage count of this stream on the output
733 outputDesc->changeRefCount(stream, -1);
734
735 // store time at which the stream was stopped - see isStreamActive()
736 if (outputDesc->mRefCount[stream] == 0 || forceDeviceUpdate) {
737 outputDesc->mStopTime[stream] = systemTime();
738 audio_devices_t newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/);
739 // delay the device switch by twice the latency because stopOutput() is executed when
740 // the track stop() command is received and at that time the audio track buffer can
741 // still contain data that needs to be drained. The latency only covers the audio HAL
742 // and kernel buffers. Also the latency does not always include additional delay in the
743 // audio path (audio DSP, CODEC ...)
744 setOutputDevice(outputDesc, newDevice, false, outputDesc->latency()*2);
745
746 // force restoring the device selection on other active outputs if it differs from the
747 // one being selected for this output
748 for (size_t i = 0; i < mOutputs.size(); i++) {
749 audio_io_handle_t curOutput = mOutputs.keyAt(i);
750 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
751 if (desc != outputDesc &&
752 desc->isActive() &&
753 outputDesc->sharesHwModuleWith(desc) &&
754 (newDevice != desc->device())) {
Ramjee Singhae5f8902015-08-19 20:47:12 +0530755 audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false
756 /*fromCache*/);
757 setOutputDevice(desc,
758 dev,
Sharad Sangleca67a022015-05-28 16:15:16 +0530759 true,
760 outputDesc->latency()*2);
761 }
762 }
763 // update the outputs if stopping one with a stream that can affect notification routing
764 handleNotificationRoutingForStream(stream);
765 }
766 return NO_ERROR;
767 } else {
768 ALOGW("stopOutput() refcount is already 0");
769 return INVALID_OPERATION;
770 }
771}
Ramjee Singh5b022de2015-09-15 18:25:20 +0530772status_t AudioPolicyManagerCustom::startSource(sp<AudioOutputDescriptor> outputDesc1,
Sharad Sangleca67a022015-05-28 16:15:16 +0530773 audio_stream_type_t stream,
774 audio_devices_t device,
775 uint32_t *delayMs)
776{
777 // cannot start playback of STREAM_TTS if any other output is being used
778 uint32_t beaconMuteLatency = 0;
Steve Kondikc1ff6852015-11-01 03:58:16 -0800779 const sp<SwAudioOutputDescriptor> outputDesc = (SwAudioOutputDescriptor *) outputDesc1.get();
Sharad Sangleca67a022015-05-28 16:15:16 +0530780
781 *delayMs = 0;
782 if (stream == AUDIO_STREAM_TTS) {
783 ALOGV("\t found BEACON stream");
784 if (mOutputs.isAnyOutputActive(AUDIO_STREAM_TTS /*streamToIgnore*/)) {
785 return INVALID_OPERATION;
786 } else {
787 beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
788 }
789 } else {
790 // some playback other than beacon starts
791 beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT);
792 }
793
794 // increment usage count for this stream on the requested output:
795 // NOTE that the usage count is the same for duplicated output and hardware output which is
796 // necessary for a correct control of hardware output routing by startOutput() and stopOutput()
797 outputDesc->changeRefCount(stream, 1);
798
799 if (outputDesc->mRefCount[stream] == 1 || device != AUDIO_DEVICE_NONE) {
800 // starting an output being rerouted?
801 if (device == AUDIO_DEVICE_NONE) {
802 device = getNewOutputDevice(outputDesc, false /*fromCache*/);
803 }
804 routing_strategy strategy = getStrategy(stream);
805 bool shouldWait = (strategy == STRATEGY_SONIFICATION) ||
806 (strategy == STRATEGY_SONIFICATION_RESPECTFUL) ||
807 (beaconMuteLatency > 0);
808 uint32_t waitMs = beaconMuteLatency;
809 bool force = false;
810 for (size_t i = 0; i < mOutputs.size(); i++) {
811 sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
812 if (desc != outputDesc) {
813 // force a device change if any other output is managed by the same hw
814 // module and has a current device selection that differs from selected device.
815 // In this case, the audio HAL must receive the new device selection so that it can
816 // change the device currently selected by the other active output.
817 if (outputDesc->sharesHwModuleWith(desc) &&
818 desc->device() != device) {
819 force = true;
820 }
821 // wait for audio on other active outputs to be presented when starting
822 // a notification so that audio focus effect can propagate, or that a mute/unmute
823 // event occurred for beacon
824 uint32_t latency = desc->latency();
825 if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) {
826 waitMs = latency;
827 }
828 }
829 }
830 uint32_t muteWaitMs = setOutputDevice(outputDesc, device, force);
831
832 // handle special case for sonification while in call
833 if (isInCall()) {
834 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
835 }
836
837 // apply volume rules for current stream and device if necessary
838 checkAndSetVolume(stream,
839 mStreams.valueFor(stream).getVolumeIndex(device),
840 outputDesc,
841 device);
842
843 // update the outputs if starting an output with a stream that can affect notification
844 // routing
845 handleNotificationRoutingForStream(stream);
846
847 // force reevaluating accessibility routing when ringtone or alarm starts
848 if (strategy == STRATEGY_SONIFICATION) {
849 mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY);
850 }
851 }
852 else {
853 // handle special case for sonification while in call
854 if (isInCall()) {
855 handleIncallSonification(stream, true, false, outputDesc->mIoHandle);
856 }
857 }
858 return NO_ERROR;
859}
860void AudioPolicyManagerCustom::handleIncallSonification(audio_stream_type_t stream,
861 bool starting, bool stateChange,
862 audio_io_handle_t output)
863{
864 if(!hasPrimaryOutput()) {
865 return;
866 }
867 // no action needed for AUDIO_STREAM_PATCH stream type, it's for internal flinger tracks
868 if (stream == AUDIO_STREAM_PATCH) {
869 return;
870 }
871 // if the stream pertains to sonification strategy and we are in call we must
872 // mute the stream if it is low visibility. If it is high visibility, we must play a tone
873 // in the device used for phone strategy and play the tone if the selected device does not
874 // interfere with the device used for phone strategy
875 // if stateChange is true, we are called from setPhoneState() and we must mute or unmute as
876 // many times as there are active tracks on the output
877 const routing_strategy stream_strategy = getStrategy(stream);
878 if ((stream_strategy == STRATEGY_SONIFICATION) ||
879 ((stream_strategy == STRATEGY_SONIFICATION_RESPECTFUL))) {
880 sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
881 ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
882 stream, starting, outputDesc->mDevice, stateChange);
883 if (outputDesc->mRefCount[stream]) {
884 int muteCount = 1;
885 if (stateChange) {
886 muteCount = outputDesc->mRefCount[stream];
887 }
888 if (audio_is_low_visibility(stream)) {
889 ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
890 for (int i = 0; i < muteCount; i++) {
891 setStreamMute(stream, starting, outputDesc);
892 }
893 } else {
894 ALOGV("handleIncallSonification() high visibility");
895 if (outputDesc->device() &
896 getDeviceForStrategy(STRATEGY_PHONE, true /*fromCache*/)) {
897 ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
898 for (int i = 0; i < muteCount; i++) {
899 setStreamMute(stream, starting, outputDesc);
900 }
901 }
902 if (starting) {
903 mpClientInterface->startTone(AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION,
904 AUDIO_STREAM_VOICE_CALL);
905 } else {
906 mpClientInterface->stopTone();
907 }
908 }
909 }
910 }
911}
912void AudioPolicyManagerCustom::handleNotificationRoutingForStream(audio_stream_type_t stream) {
913 switch(stream) {
914 case AUDIO_STREAM_MUSIC:
915 checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL);
916 updateDevicesAndOutputs();
917 break;
918 default:
919 break;
920 }
921}
922status_t AudioPolicyManagerCustom::checkAndSetVolume(audio_stream_type_t stream,
923 int index,
Steve Kondikc1ff6852015-11-01 03:58:16 -0800924 const sp<AudioOutputDescriptor>& outputDesc1,
Sharad Sangleca67a022015-05-28 16:15:16 +0530925 audio_devices_t device,
926 int delayMs, bool force)
927{
Steve Kondikc1ff6852015-11-01 03:58:16 -0800928 const sp<SwAudioOutputDescriptor> outputDesc = (SwAudioOutputDescriptor *) outputDesc1.get();
929
Sharad Sangleca67a022015-05-28 16:15:16 +0530930 // do not change actual stream volume if the stream is muted
931 if (outputDesc->mMuteCount[stream] != 0) {
932 ALOGVV("checkAndSetVolume() stream %d muted count %d",
933 stream, outputDesc->mMuteCount[stream]);
934 return NO_ERROR;
935 }
936 audio_policy_forced_cfg_t forceUseForComm =
937 mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_COMMUNICATION);
938 // do not change in call volume if bluetooth is connected and vice versa
939 if ((stream == AUDIO_STREAM_VOICE_CALL && forceUseForComm == AUDIO_POLICY_FORCE_BT_SCO) ||
940 (stream == AUDIO_STREAM_BLUETOOTH_SCO && forceUseForComm != AUDIO_POLICY_FORCE_BT_SCO)) {
941 ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
942 stream, forceUseForComm);
943 return INVALID_OPERATION;
944 }
945
946 if (device == AUDIO_DEVICE_NONE) {
947 device = outputDesc->device();
948 }
949
950 float volumeDb = computeVolume(stream, index, device);
951 if (outputDesc->isFixedVolume(device)) {
952 volumeDb = 0.0f;
953 }
954
955 outputDesc->setVolume(volumeDb, stream, device, delayMs, force);
956
957 if (stream == AUDIO_STREAM_VOICE_CALL ||
958 stream == AUDIO_STREAM_BLUETOOTH_SCO) {
959 float voiceVolume;
960 // Force voice volume to max for bluetooth SCO as volume is managed by the headset
961 if (stream == AUDIO_STREAM_VOICE_CALL) {
962 voiceVolume = (float)index/(float)mStreams.valueFor(stream).getVolumeIndexMax();
963 } else {
964 voiceVolume = 1.0;
965 }
966
967 if (voiceVolume != mLastVoiceVolume && ((outputDesc == mPrimaryOutput) ||
968 isDirectOutput(outputDesc->mIoHandle) || device & AUDIO_DEVICE_OUT_ALL_USB)) {
969 mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
970 mLastVoiceVolume = voiceVolume;
971 }
972 }
973
974 return NO_ERROR;
975}
976bool AudioPolicyManagerCustom::isDirectOutput(audio_io_handle_t output) {
977 for (size_t i = 0; i < mOutputs.size(); i++) {
978 audio_io_handle_t curOutput = mOutputs.keyAt(i);
979 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
980 if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
981 return true;
982 }
983 }
984 return false;
985}
986audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice(
987 audio_devices_t device,
988 audio_session_t session __unused,
989 audio_stream_type_t stream,
990 uint32_t samplingRate,
991 audio_format_t format,
992 audio_channel_mask_t channelMask,
993 audio_output_flags_t flags,
994 const audio_offload_info_t *offloadInfo)
995{
996 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
997 uint32_t latency = 0;
998 status_t status;
999
1000#ifdef AUDIO_POLICY_TEST
1001 if (mCurOutput != 0) {
1002 ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d",
1003 mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
1004
1005 if (mTestOutputs[mCurOutput] == 0) {
1006 ALOGV("getOutput() opening test output");
1007 sp<AudioOutputDescriptor> outputDesc = new SwAudioOutputDescriptor(NULL,
1008 mpClientInterface);
1009 outputDesc->mDevice = mTestDevice;
1010 outputDesc->mLatency = mTestLatencyMs;
1011 outputDesc->mFlags =
1012 (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0);
1013 outputDesc->mRefCount[stream] = 0;
1014 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1015 config.sample_rate = mTestSamplingRate;
1016 config.channel_mask = mTestChannels;
1017 config.format = mTestFormat;
1018 if (offloadInfo != NULL) {
1019 config.offload_info = *offloadInfo;
1020 }
1021 status = mpClientInterface->openOutput(0,
1022 &mTestOutputs[mCurOutput],
1023 &config,
1024 &outputDesc->mDevice,
1025 String8(""),
1026 &outputDesc->mLatency,
1027 outputDesc->mFlags);
1028 if (status == NO_ERROR) {
1029 outputDesc->mSamplingRate = config.sample_rate;
1030 outputDesc->mFormat = config.format;
1031 outputDesc->mChannelMask = config.channel_mask;
1032 AudioParameter outputCmd = AudioParameter();
1033 outputCmd.addInt(String8("set_id"),mCurOutput);
1034 mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString());
1035 addOutput(mTestOutputs[mCurOutput], outputDesc);
1036 }
1037 }
1038 return mTestOutputs[mCurOutput];
1039 }
1040#endif //AUDIO_POLICY_TEST
1041 if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) &&
1042 (stream != AUDIO_STREAM_MUSIC)) {
1043 // compress should not be used for non-music streams
1044 ALOGE("Offloading only allowed with music stream");
1045 return 0;
Karthik Reddy Kattaeb605c92015-07-14 16:05:18 +05301046 }
1047
1048 if ((stream == AUDIO_STREAM_VOICE_CALL) &&
1049 (channelMask == 1) &&
1050 (samplingRate == 8000 || samplingRate == 16000)) {
1051 // Allow Voip direct output only if:
1052 // audio mode is MODE_IN_COMMUNCATION; AND
1053 // voip output is not opened already; AND
1054 // requested sample rate matches with that of voip input stream (if opened already)
1055 int value = 0;
1056 uint32_t mode = 0, voipOutCount = 1, voipSampleRate = 1;
1057 String8 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1058 String8("audio_mode"));
1059 AudioParameter result = AudioParameter(valueStr);
1060 if (result.getInt(String8("audio_mode"), value) == NO_ERROR) {
1061 mode = value;
1062 }
1063
1064 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1065 String8("voip_out_stream_count"));
1066 result = AudioParameter(valueStr);
1067 if (result.getInt(String8("voip_out_stream_count"), value) == NO_ERROR) {
1068 voipOutCount = value;
1069 }
1070
1071 valueStr = mpClientInterface->getParameters((audio_io_handle_t)0,
1072 String8("voip_sample_rate"));
1073 result = AudioParameter(valueStr);
1074 if (result.getInt(String8("voip_sample_rate"), value) == NO_ERROR) {
1075 voipSampleRate = value;
1076 }
1077
1078 if ((mode == AUDIO_MODE_IN_COMMUNICATION) && (voipOutCount == 0) &&
1079 ((voipSampleRate == 0) || (voipSampleRate == samplingRate))) {
1080 if (audio_is_linear_pcm(format)) {
1081 char propValue[PROPERTY_VALUE_MAX] = {0};
1082 property_get("use.voice.path.for.pcm.voip", propValue, "0");
1083 bool voipPcmSysPropEnabled = !strncmp("true", propValue, sizeof("true"));
1084 if (voipPcmSysPropEnabled && (format == AUDIO_FORMAT_PCM_16_BIT)) {
1085 flags = (audio_output_flags_t)((flags &~AUDIO_OUTPUT_FLAG_FAST) |
1086 AUDIO_OUTPUT_FLAG_VOIP_RX | AUDIO_OUTPUT_FLAG_DIRECT);
1087 ALOGD("Set VoIP and Direct output flags for PCM format");
1088 }
1089 }
1090 }
Sharad Sangleca67a022015-05-28 16:15:16 +05301091 }
Karthik Reddy Kattaeb605c92015-07-14 16:05:18 +05301092
Ramjee Singhae5f8902015-08-19 20:47:12 +05301093#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
Sharad Sangleca67a022015-05-28 16:15:16 +05301094 /*
1095 * WFD audio routes back to target speaker when starting a ringtone playback.
1096 * This is because primary output is reused for ringtone, so output device is
1097 * updated based on SONIFICATION strategy for both ringtone and music playback.
1098 * The same issue is not seen on remoted_submix HAL based WFD audio because
1099 * primary output is not reused and a new output is created for ringtone playback.
1100 * Issue is fixed by updating output flag to AUDIO_OUTPUT_FLAG_FAST when there is
1101 * a non-music stream playback on WFD, so primary output is not reused for ringtone.
1102 */
1103 audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types();
1104 if ((availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY)
1105 && (stream != AUDIO_STREAM_MUSIC)) {
1106 ALOGD("WFD audio: use OUTPUT_FLAG_FAST for non music stream. flags:%x", flags );
1107 //For voip paths
1108 if(flags & AUDIO_OUTPUT_FLAG_DIRECT)
1109 flags = AUDIO_OUTPUT_FLAG_DIRECT;
1110 else //route every thing else to ULL path
1111 flags = AUDIO_OUTPUT_FLAG_FAST;
1112 }
Ramjee Singhae5f8902015-08-19 20:47:12 +05301113#endif
Sharad Sangleca67a022015-05-28 16:15:16 +05301114 // open a direct output if required by specified parameters
1115 //force direct flag if offload flag is set: offloading implies a direct output stream
1116 // and all common behaviors are driven by checking only the direct flag
1117 // this should normally be set appropriately in the policy configuration file
1118 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
1119 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1120 }
1121 if ((flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC) != 0) {
1122 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
1123 }
1124 // only allow deep buffering for music stream type
1125 if (stream != AUDIO_STREAM_MUSIC) {
1126 flags = (audio_output_flags_t)(flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
Sharad Sangle412d96c2015-08-03 17:55:48 +05301127 } else if (/* stream == AUDIO_STREAM_MUSIC && */
1128 flags == AUDIO_OUTPUT_FLAG_NONE &&
1129 property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
1130 flags = (audio_output_flags_t)AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
Sharad Sangleca67a022015-05-28 16:15:16 +05301131 }
Sharad Sangle412d96c2015-08-03 17:55:48 +05301132
Sharad Sangleca67a022015-05-28 16:15:16 +05301133 if (stream == AUDIO_STREAM_TTS) {
1134 flags = AUDIO_OUTPUT_FLAG_TTS;
1135 }
1136
1137 sp<IOProfile> profile;
1138
1139 // skip direct output selection if the request can obviously be attached to a mixed output
1140 // and not explicitly requested
1141 if (((flags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) &&
1142 audio_is_linear_pcm(format) && samplingRate <= MAX_MIXER_SAMPLING_RATE &&
1143 audio_channel_count_from_out_mask(channelMask) <= 2) {
1144 goto non_direct_output;
1145 }
1146
1147 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
1148 // creating an offloaded track and tearing it down immediately after start when audioflinger
1149 // detects there is an active non offloadable effect.
1150 // FIXME: We should check the audio session here but we do not have it in this context.
1151 // This may prevent offloading in rare situations where effects are left active by apps
1152 // in the background.
1153
1154 if (((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0) ||
1155 !mEffects.isNonOffloadableEffectEnabled()) {
1156 profile = getProfileForDirectOutput(device,
1157 samplingRate,
1158 format,
1159 channelMask,
1160 (audio_output_flags_t)flags);
1161 }
1162
1163 if (profile != 0) {
1164 sp<SwAudioOutputDescriptor> outputDesc = NULL;
1165
1166 for (size_t i = 0; i < mOutputs.size(); i++) {
1167 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
1168 if (!desc->isDuplicated() && (profile == desc->mProfile)) {
1169 outputDesc = desc;
1170 // reuse direct output if currently open and configured with same parameters
1171 if ((samplingRate == outputDesc->mSamplingRate) &&
1172 (format == outputDesc->mFormat) &&
1173 (channelMask == outputDesc->mChannelMask)) {
1174 outputDesc->mDirectOpenCount++;
1175 ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
1176 return mOutputs.keyAt(i);
1177 }
1178 }
1179 }
1180 // close direct output if currently open and configured with different parameters
1181 if (outputDesc != NULL) {
1182 closeOutput(outputDesc->mIoHandle);
1183 }
1184
1185 // if the selected profile is offloaded and no offload info was specified,
1186 // create a default one
1187 audio_offload_info_t defaultOffloadInfo = AUDIO_INFO_INITIALIZER;
1188 if ((profile->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && !offloadInfo) {
1189 flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
1190 defaultOffloadInfo.sample_rate = samplingRate;
1191 defaultOffloadInfo.channel_mask = channelMask;
1192 defaultOffloadInfo.format = format;
1193 defaultOffloadInfo.stream_type = stream;
1194 defaultOffloadInfo.bit_rate = 0;
1195 defaultOffloadInfo.duration_us = -1;
1196 defaultOffloadInfo.has_video = true; // conservative
1197 defaultOffloadInfo.is_streaming = true; // likely
1198 offloadInfo = &defaultOffloadInfo;
1199 }
1200
1201 outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
1202 outputDesc->mDevice = device;
1203 outputDesc->mLatency = 0;
1204 outputDesc->mFlags = (audio_output_flags_t)(outputDesc->mFlags | flags);
1205 audio_config_t config = AUDIO_CONFIG_INITIALIZER;
1206 config.sample_rate = samplingRate;
1207 config.channel_mask = channelMask;
1208 config.format = format;
1209 if (offloadInfo != NULL) {
1210 config.offload_info = *offloadInfo;
1211 }
1212 status = mpClientInterface->openOutput(profile->getModuleHandle(),
1213 &output,
1214 &config,
1215 &outputDesc->mDevice,
1216 String8(""),
1217 &outputDesc->mLatency,
1218 outputDesc->mFlags);
1219
1220 // only accept an output with the requested parameters
1221 if (status != NO_ERROR ||
1222 (samplingRate != 0 && samplingRate != config.sample_rate) ||
1223 (format != AUDIO_FORMAT_DEFAULT && format != config.format) ||
1224 (channelMask != 0 && channelMask != config.channel_mask)) {
1225 ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
1226 "format %d %d, channelMask %04x %04x", output, samplingRate,
1227 outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
1228 outputDesc->mChannelMask);
1229 if (output != AUDIO_IO_HANDLE_NONE) {
1230 mpClientInterface->closeOutput(output);
1231 }
1232 // fall back to mixer output if possible when the direct output could not be open
1233 if (audio_is_linear_pcm(format) && samplingRate <= MAX_MIXER_SAMPLING_RATE) {
1234 goto non_direct_output;
1235 }
1236 return AUDIO_IO_HANDLE_NONE;
1237 }
1238 outputDesc->mSamplingRate = config.sample_rate;
1239 outputDesc->mChannelMask = config.channel_mask;
1240 outputDesc->mFormat = config.format;
1241 outputDesc->mRefCount[stream] = 0;
1242 outputDesc->mStopTime[stream] = 0;
1243 outputDesc->mDirectOpenCount = 1;
1244
1245 audio_io_handle_t srcOutput = getOutputForEffect();
1246 addOutput(output, outputDesc);
1247 audio_io_handle_t dstOutput = getOutputForEffect();
1248 if (dstOutput == output) {
1249 mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
1250 }
1251 mPreviousOutputs = mOutputs;
1252 ALOGV("getOutput() returns new direct output %d", output);
1253 mpClientInterface->onAudioPortListUpdate();
1254 return output;
1255 }
1256
1257non_direct_output:
1258 // ignoring channel mask due to downmix capability in mixer
1259
1260 // open a non direct output
1261
1262 // for non direct outputs, only PCM is supported
1263 if (audio_is_linear_pcm(format)) {
1264 // get which output is suitable for the specified stream. The actual
1265 // routing change will happen when startOutput() will be called
1266 SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
1267
1268 // at this stage we should ignore the DIRECT flag as no direct output could be found earlier
1269 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT);
1270 output = selectOutput(outputs, flags, format);
1271 }
1272 ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d,"
1273 "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
1274
1275 ALOGV(" getOutputForDevice() returns output %d", output);
1276
1277 return output;
1278}
Ramjee Singh58a28312015-08-14 14:40:44 +05301279
Mingming Yin38877802015-10-05 15:24:04 -07001280AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
1281 : AudioPolicyManager(clientInterface),
1282 mHdmiAudioDisabled(false),
1283 mHdmiAudioEvent(false),
1284 mPrevPhoneState(0)
1285{
1286 char ssr_enabled[PROPERTY_VALUE_MAX] = {0};
1287 bool prop_ssr_enabled = false;
1288
1289 if (property_get("ro.qc.sdk.audio.ssr", ssr_enabled, NULL)) {
1290 prop_ssr_enabled = atoi(ssr_enabled) || !strncmp("true", ssr_enabled, 4);
1291 }
1292
1293 for (size_t i = 0; i < mHwModules.size(); i++) {
1294 ALOGV("Hw module %d", i);
1295 for (size_t j = 0; j < mHwModules[i]->mInputProfiles.size(); j++) {
1296 const sp<IOProfile> inProfile = mHwModules[i]->mInputProfiles[j];
Steve Kondik13582572015-12-05 17:19:19 -08001297 ALOGV("Input profile %d", j);
Mingming Yin38877802015-10-05 15:24:04 -07001298 for (size_t k = 0; k < inProfile->mChannelMasks.size(); k++) {
1299 audio_channel_mask_t channelMask =
1300 inProfile->mChannelMasks.itemAt(k);
1301 ALOGV("Channel Mask %x size %d", channelMask,
1302 inProfile->mChannelMasks.size());
1303 if (AUDIO_CHANNEL_IN_5POINT1 == channelMask) {
1304 if (!prop_ssr_enabled) {
1305 ALOGI("removing AUDIO_CHANNEL_IN_5POINT1 from"
1306 " input profile as SSR(surround sound record)"
1307 " is not supported on this chipset variant");
1308 inProfile->mChannelMasks.removeItemsAt(k, 1);
1309 ALOGV("Channel Mask size now %d",
1310 inProfile->mChannelMasks.size());
1311 }
1312 }
1313 }
1314 }
1315 }
1316
1317#ifdef RECORD_PLAY_CONCURRENCY
1318 mIsInputRequestOnProgress = false;
1319#endif
1320
1321
1322#ifdef VOICE_CONCURRENCY
1323 mFallBackflag = getFallBackPath();
1324#endif
1325}
1326
Sharad Sangleca67a022015-05-28 16:15:16 +05301327}