blob: cb26ed645eb3e2d8babfb0219b8bfb9f006d378a [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Mingming Yin4a72d652014-01-03 18:54:18 -08002 * Copyright (c) 2013-2014, 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
20#define LOG_TAG "AudioPolicyManager"
21//#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
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070030// A device mask for all audio output devices that are considered "remote" when evaluating
31// active output devices in isStreamActiveRemotely()
32#define APM_AUDIO_OUT_DEVICE_REMOTE_ALL AUDIO_DEVICE_OUT_REMOTE_SUBMIX
33
34#include <utils/Log.h>
35#include "AudioPolicyManager.h"
36#include <hardware/audio_effect.h>
37#include <hardware/audio.h>
38#include <math.h>
39#include <hardware_legacy/audio_policy_conf.h>
40#include <cutils/properties.h>
41
42namespace android_audio_legacy {
43
44// ----------------------------------------------------------------------------
45// AudioPolicyInterface implementation
46// ----------------------------------------------------------------------------
47
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070048status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device,
49 AudioSystem::device_connection_state state,
50 const char *device_address)
51{
52 SortedVector <audio_io_handle_t> outputs;
53
54 ALOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
55
56 // connect/disconnect only 1 device at a time
57 if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE;
58
59 if (strlen(device_address) >= MAX_DEVICE_ADDRESS_LEN) {
60 ALOGE("setDeviceConnectionState() invalid address: %s", device_address);
61 return BAD_VALUE;
62 }
63
64 // handle output devices
65 if (audio_is_output_device(device)) {
66
67 if (!mHasA2dp && audio_is_a2dp_device(device)) {
68 ALOGE("setDeviceConnectionState() invalid A2DP device: %x", device);
69 return BAD_VALUE;
70 }
71 if (!mHasUsb && audio_is_usb_device(device)) {
72 ALOGE("setDeviceConnectionState() invalid USB audio device: %x", device);
73 return BAD_VALUE;
74 }
75 if (!mHasRemoteSubmix && audio_is_remote_submix_device((audio_devices_t)device)) {
76 ALOGE("setDeviceConnectionState() invalid remote submix audio device: %x", device);
77 return BAD_VALUE;
78 }
79
80 // save a copy of the opened output descriptors before any output is opened or closed
81 // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies()
82 mPreviousOutputs = mOutputs;
83 switch (state)
84 {
85 // handle output device connection
86 case AudioSystem::DEVICE_STATE_AVAILABLE:
87 if (mAvailableOutputDevices & device) {
88 ALOGW("setDeviceConnectionState() device already connected: %x", device);
89 return INVALID_OPERATION;
90 }
91 ALOGV("setDeviceConnectionState() connecting device %x", device);
92
93 if (checkOutputsForDevice(device, state, outputs) != NO_ERROR) {
94 return INVALID_OPERATION;
95 }
96 ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %d outputs",
97 outputs.size());
98 // register new device as available
99 mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device);
100
101 if (!outputs.isEmpty()) {
102 String8 paramStr;
103 if (mHasA2dp && audio_is_a2dp_device(device)) {
104 // handle A2DP device connection
105 AudioParameter param;
106 param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address));
107 paramStr = param.toString();
108 mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
109 mA2dpSuspended = false;
110 } else if (audio_is_bluetooth_sco_device(device)) {
111 // handle SCO device connection
112 mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
113 } else if (mHasUsb && audio_is_usb_device(device)) {
114 // handle USB device connection
115 mUsbCardAndDevice = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
116 paramStr = mUsbCardAndDevice;
117 }
118 // not currently handling multiple simultaneous submixes: ignoring remote submix
119 // case and address
120 if (!paramStr.isEmpty()) {
121 for (size_t i = 0; i < outputs.size(); i++) {
122 mpClientInterface->setParameters(outputs[i], paramStr);
123 }
124 }
125 }
126 break;
127 // handle output device disconnection
128 case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
129 if (!(mAvailableOutputDevices & device)) {
130 ALOGW("setDeviceConnectionState() device not connected: %x", device);
131 return INVALID_OPERATION;
132 }
133
134 ALOGV("setDeviceConnectionState() disconnecting device %x", device);
135 // remove device from available output devices
136 mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
137
138 checkOutputsForDevice(device, state, outputs);
139 if (mHasA2dp && audio_is_a2dp_device(device)) {
140 // handle A2DP device disconnection
141 mA2dpDeviceAddress = "";
142 mA2dpSuspended = false;
143 } else if (audio_is_bluetooth_sco_device(device)) {
144 // handle SCO device disconnection
145 mScoDeviceAddress = "";
146 } else if (mHasUsb && audio_is_usb_device(device)) {
147 // handle USB device disconnection
148 mUsbCardAndDevice = "";
149 }
150 // not currently handling multiple simultaneous submixes: ignoring remote submix
151 // case and address
152 } break;
153
154 default:
155 ALOGE("setDeviceConnectionState() invalid state: %x", state);
156 return BAD_VALUE;
157 }
158
159 checkA2dpSuspend();
160 checkOutputForAllStrategies();
161 // outputs must be closed after checkOutputForAllStrategies() is executed
162 if (!outputs.isEmpty()) {
163 for (size_t i = 0; i < outputs.size(); i++) {
164 AudioOutputDescriptor *desc = mOutputs.valueFor(outputs[i]);
165 // close unused outputs after device disconnection or direct outputs that have been
166 // opened by checkOutputsForDevice() to query dynamic parameters
167 if ((state == AudioSystem::DEVICE_STATE_UNAVAILABLE) ||
168 (((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) &&
169 (desc->mDirectOpenCount == 0))) {
170 closeOutput(outputs[i]);
171 }
172 }
173 }
174
175 updateDevicesAndOutputs();
176 audio_devices_t newDevice = getNewDevice(mPrimaryOutput, false /*fromCache*/);
177#ifdef AUDIO_EXTN_FM_ENABLED
178 if(device == AUDIO_DEVICE_OUT_FM) {
179 if (state == AudioSystem::DEVICE_STATE_AVAILABLE) {
180 mOutputs.valueFor(mPrimaryOutput)->changeRefCount(AudioSystem::MUSIC, 1);
181 newDevice = (audio_devices_t)(getNewDevice(mPrimaryOutput, false) | AUDIO_DEVICE_OUT_FM);
182 } else {
183 mOutputs.valueFor(mPrimaryOutput)->changeRefCount(AudioSystem::MUSIC, -1);
184 }
185
186 AudioParameter param = AudioParameter();
187 param.addInt(String8("handle_fm"), (int)newDevice);
188 ALOGV("setDeviceConnectionState() setParameters handle_fm");
189 mpClientInterface->setParameters(mPrimaryOutput, param.toString());
190 }
191#endif
192 for (size_t i = 0; i < mOutputs.size(); i++) {
193 // do not force device change on duplicated output because if device is 0, it will
194 // also force a device 0 for the two outputs it is duplicated to which may override
195 // a valid device selection on those outputs.
196 setOutputDevice(mOutputs.keyAt(i),
197 getNewDevice(mOutputs.keyAt(i), true /*fromCache*/),
198 !mOutputs.valueAt(i)->isDuplicated(),
199 0);
200 }
201
202 if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET) {
203 device = AUDIO_DEVICE_IN_WIRED_HEADSET;
204 } else if (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO ||
205 device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET ||
206 device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) {
207 device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
208 } else if(device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET){
209 device = AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET;
210 } else {
211 return NO_ERROR;
212 }
213 }
214 // handle input devices
215 if (audio_is_input_device(device)) {
216
217 switch (state)
218 {
219 // handle input device connection
220 case AudioSystem::DEVICE_STATE_AVAILABLE: {
221 if (mAvailableInputDevices & device) {
222 ALOGW("setDeviceConnectionState() device already connected: %d", device);
223 return INVALID_OPERATION;
224 }
225 mAvailableInputDevices = mAvailableInputDevices | (device & ~AUDIO_DEVICE_BIT_IN);
226 }
227 break;
228
229 // handle input device disconnection
230 case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
231 if (!(mAvailableInputDevices & device)) {
232 ALOGW("setDeviceConnectionState() device not connected: %d", device);
233 return INVALID_OPERATION;
234 }
235 mAvailableInputDevices = (audio_devices_t) (mAvailableInputDevices & ~device);
236 } break;
237
238 default:
239 ALOGE("setDeviceConnectionState() invalid state: %x", state);
240 return BAD_VALUE;
241 }
242
243 audio_io_handle_t activeInput = getActiveInput();
244 if (activeInput != 0) {
245 AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
246 audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
247 if ((newDevice != AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) {
248 ALOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
249 inputDesc->mDevice, newDevice, activeInput);
250 inputDesc->mDevice = newDevice;
251 AudioParameter param = AudioParameter();
252 param.addInt(String8(AudioParameter::keyRouting), (int)newDevice);
253 mpClientInterface->setParameters(activeInput, param.toString());
254 }
255 }
256
257 return NO_ERROR;
258 }
259
260 ALOGW("setDeviceConnectionState() invalid device: %x", device);
261 return BAD_VALUE;
262}
263
264void AudioPolicyManager::setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config)
265{
266 ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
267
268 bool forceVolumeReeval = false;
269 switch(usage) {
270 case AudioSystem::FOR_COMMUNICATION:
271 if (config != AudioSystem::FORCE_SPEAKER && config != AudioSystem::FORCE_BT_SCO &&
272 config != AudioSystem::FORCE_NONE) {
273 ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
274 return;
275 }
276 forceVolumeReeval = true;
277 mForceUse[usage] = config;
278 break;
279 case AudioSystem::FOR_MEDIA:
280 if (config != AudioSystem::FORCE_HEADPHONES && config != AudioSystem::FORCE_BT_A2DP &&
281#ifdef AUDIO_EXTN_FM_ENABLED
282 config != AudioSystem::FORCE_SPEAKER &&
283#endif
284 config != AudioSystem::FORCE_WIRED_ACCESSORY &&
285 config != AudioSystem::FORCE_ANALOG_DOCK &&
286 config != AudioSystem::FORCE_DIGITAL_DOCK && config != AudioSystem::FORCE_NONE &&
287 config != AudioSystem::FORCE_NO_BT_A2DP) {
288 ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
289 return;
290 }
291 mForceUse[usage] = config;
292 break;
293 case AudioSystem::FOR_RECORD:
294 if (config != AudioSystem::FORCE_BT_SCO && config != AudioSystem::FORCE_WIRED_ACCESSORY &&
295 config != AudioSystem::FORCE_NONE) {
296 ALOGW("setForceUse() invalid config %d for FOR_RECORD", config);
297 return;
298 }
299 mForceUse[usage] = config;
300 break;
301 case AudioSystem::FOR_DOCK:
302 if (config != AudioSystem::FORCE_NONE && config != AudioSystem::FORCE_BT_CAR_DOCK &&
303 config != AudioSystem::FORCE_BT_DESK_DOCK &&
304 config != AudioSystem::FORCE_WIRED_ACCESSORY &&
305 config != AudioSystem::FORCE_ANALOG_DOCK &&
306 config != AudioSystem::FORCE_DIGITAL_DOCK) {
307 ALOGW("setForceUse() invalid config %d for FOR_DOCK", config);
308 }
309 forceVolumeReeval = true;
310 mForceUse[usage] = config;
311 break;
312 case AudioSystem::FOR_SYSTEM:
313 if (config != AudioSystem::FORCE_NONE &&
314 config != AudioSystem::FORCE_SYSTEM_ENFORCED) {
315 ALOGW("setForceUse() invalid config %d for FOR_SYSTEM", config);
316 }
317 forceVolumeReeval = true;
318 mForceUse[usage] = config;
319 break;
320 default:
321 ALOGW("setForceUse() invalid usage %d", usage);
322 break;
323 }
324
325 // check for device and output changes triggered by new force usage
326 checkA2dpSuspend();
327 checkOutputForAllStrategies();
328 updateDevicesAndOutputs();
329 for (int i = mOutputs.size() -1; i >= 0; i--) {
330 audio_io_handle_t output = mOutputs.keyAt(i);
331 audio_devices_t newDevice = getNewDevice(output, true /*fromCache*/);
332 setOutputDevice(output, newDevice, (newDevice != AUDIO_DEVICE_NONE));
333 if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) {
334 applyStreamVolumes(output, newDevice, 0, true);
335 }
336 }
337
338 audio_io_handle_t activeInput = getActiveInput();
339 if (activeInput != 0) {
340 AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
341 audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
342 if ((newDevice != AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) {
343 ALOGV("setForceUse() changing device from %x to %x for input %d",
344 inputDesc->mDevice, newDevice, activeInput);
345 inputDesc->mDevice = newDevice;
346 AudioParameter param = AudioParameter();
347 param.addInt(String8(AudioParameter::keyRouting), (int)newDevice);
348 mpClientInterface->setParameters(activeInput, param.toString());
349 }
350 }
351
352}
353
354audio_io_handle_t AudioPolicyManager::getInput(int inputSource,
355 uint32_t samplingRate,
356 uint32_t format,
357 uint32_t channelMask,
358 AudioSystem::audio_in_acoustics acoustics)
359{
360 audio_io_handle_t input = 0;
361 audio_devices_t device = getDeviceForInputSource(inputSource);
362
363 ALOGV("getInput() inputSource %d, samplingRate %d, format %d, channelMask %x, acoustics %x",
364 inputSource, samplingRate, format, channelMask, acoustics);
365
366 if (device == AUDIO_DEVICE_NONE) {
367 ALOGW("getInput() could not find device for inputSource %d", inputSource);
368 return 0;
369 }
370
371
372 IOProfile *profile = getInputProfile(device,
373 samplingRate,
374 format,
375 channelMask);
376 if (profile == NULL) {
377 ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d,"
378 "channelMask %04x",
379 device, samplingRate, format, channelMask);
380 return 0;
381 }
382
383 if (profile->mModule->mHandle == 0) {
384 ALOGE("getInput(): HW module %s not opened", profile->mModule->mName);
385 return 0;
386 }
387
388 AudioInputDescriptor *inputDesc = new AudioInputDescriptor(profile);
389
390 inputDesc->mInputSource = inputSource;
391 inputDesc->mDevice = device;
392 inputDesc->mSamplingRate = samplingRate;
393 inputDesc->mFormat = (audio_format_t)format;
394 inputDesc->mChannelMask = (audio_channel_mask_t)channelMask;
395 inputDesc->mRefCount = 0;
396 input = mpClientInterface->openInput(profile->mModule->mHandle,
397 &inputDesc->mDevice,
398 &inputDesc->mSamplingRate,
399 &inputDesc->mFormat,
400 &inputDesc->mChannelMask);
401
402 // only accept input with the exact requested set of parameters
403 if (input == 0 ||
404 (samplingRate != inputDesc->mSamplingRate) ||
405 (format != inputDesc->mFormat) ||
406 (channelMask != inputDesc->mChannelMask)) {
407 ALOGV("getInput() failed opening input: samplingRate %d, format %d, channelMask %d",
408 samplingRate, format, channelMask);
409 if (input != 0) {
410 mpClientInterface->closeInput(input);
411 }
412 delete inputDesc;
413 return 0;
414 }
415 mInputs.add(input, inputDesc);
416 return input;
417}
418
419AudioPolicyManager::routing_strategy AudioPolicyManager::getStrategy(AudioSystem::stream_type stream)
420{
421#ifdef QCOM_INCALL_MUSIC_ENABLED
422 if (stream == AudioSystem::INCALL_MUSIC)
423 return STRATEGY_MEDIA;
424#endif
425
426 return getStrategy(stream);
427}
428
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700429audio_devices_t AudioPolicyManager::getDeviceForStrategy(routing_strategy strategy,
430 bool fromCache)
431{
432 uint32_t device = AUDIO_DEVICE_NONE;
433
434 if (fromCache) {
435 ALOGVV("getDeviceForStrategy() from cache strategy %d, device %x",
436 strategy, mDeviceForStrategy[strategy]);
437 return mDeviceForStrategy[strategy];
438 }
439
440 switch (strategy) {
441
442 case STRATEGY_SONIFICATION_RESPECTFUL:
443 if (isInCall()) {
444 device = getDeviceForStrategy(STRATEGY_SONIFICATION, false /*fromCache*/);
445 } else if (isStreamActiveRemotely(AudioSystem::MUSIC,
446 SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)) {
447 // while media is playing on a remote device, use the the sonification behavior.
448 // Note that we test this usecase before testing if media is playing because
449 // the isStreamActive() method only informs about the activity of a stream, not
450 // if it's for local playback. Note also that we use the same delay between both tests
451 device = getDeviceForStrategy(STRATEGY_SONIFICATION, false /*fromCache*/);
452 } else if (isStreamActive(AudioSystem::MUSIC, SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)) {
453 // while media is playing (or has recently played), use the same device
454 device = getDeviceForStrategy(STRATEGY_MEDIA, false /*fromCache*/);
455 } else {
456 // when media is not playing anymore, fall back on the sonification behavior
457 device = getDeviceForStrategy(STRATEGY_SONIFICATION, false /*fromCache*/);
458 }
459
460 break;
461
462 case STRATEGY_DTMF:
463 if (!isInCall()) {
464 // when off call, DTMF strategy follows the same rules as MEDIA strategy
465 device = getDeviceForStrategy(STRATEGY_MEDIA, false /*fromCache*/);
466 break;
467 }
468 // when in call, DTMF and PHONE strategies follow the same rules
469 // FALL THROUGH
470
471 case STRATEGY_PHONE:
472 // for phone strategy, we first consider the forced use and then the available devices by order
473 // of priority
474 switch (mForceUse[AudioSystem::FOR_COMMUNICATION]) {
475 case AudioSystem::FORCE_BT_SCO:
476 if (!isInCall() || strategy != STRATEGY_DTMF) {
477 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
478 if (device) break;
479 }
480 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
481 if (device) break;
482 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_SCO;
483 if (device) break;
484 // if SCO device is requested but no SCO device is available, fall back to default case
485 // FALL THROUGH
486
487 default: // FORCE_NONE
488 // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
489 if (mHasA2dp && !isInCall() &&
490 (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) &&
491 (getA2dpOutput() != 0) && !mA2dpSuspended) {
492 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
493 if (device) break;
494 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
495 if (device) break;
496 }
497 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
498 if (device) break;
499 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADSET;
500 if (device) break;
501 if (mPhoneState != AudioSystem::MODE_IN_CALL) {
502 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_ACCESSORY;
503 if (device) break;
504 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_DEVICE;
505 if (device) break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700506 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
507 if (device) break;
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700508 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
509 if (device) break;
510 }
511
512 // Allow voice call on USB ANLG DOCK headset
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700513 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
514 if (device) break;
515
516 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_EARPIECE;
517 if (device) break;
518 device = mDefaultOutputDevice;
519 if (device == AUDIO_DEVICE_NONE) {
520 ALOGE("getDeviceForStrategy() no device found for STRATEGY_PHONE");
521 }
522 break;
523
524 case AudioSystem::FORCE_SPEAKER:
525 // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to
526 // A2DP speaker when forcing to speaker output
527 if (mHasA2dp && !isInCall() &&
528 (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) &&
529 (getA2dpOutput() != 0) && !mA2dpSuspended) {
530 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
531 if (device) break;
532 }
533 if (mPhoneState != AudioSystem::MODE_IN_CALL) {
534 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_ACCESSORY;
535 if (device) break;
536 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_DEVICE;
537 if (device) break;
538 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
539 if (device) break;
540 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
541 if (device) break;
Helen Zengbbce4952013-12-16 20:26:46 -0800542 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
543 if (device) break;
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700544 }
545 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER;
546 if (device) break;
547 device = mDefaultOutputDevice;
548 if (device == AUDIO_DEVICE_NONE) {
549 ALOGE("getDeviceForStrategy() no device found for STRATEGY_PHONE, FORCE_SPEAKER");
550 }
551 break;
552 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700553 // FIXME: Why do need to replace with speaker? If voice call is active
554 // We should use device from STRATEGY_PHONE
555#ifdef AUDIO_EXTN_FM_ENABLED
556 if (mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM) {
557 if (mForceUse[AudioSystem::FOR_MEDIA] == AudioSystem::FORCE_SPEAKER) {
558 device = AUDIO_DEVICE_OUT_SPEAKER;
559 }
560 }
561#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700562 break;
563
564 case STRATEGY_SONIFICATION:
565
566 // If incall, just select the STRATEGY_PHONE device: The rest of the behavior is handled by
567 // handleIncallSonification().
568 if (isInCall()) {
569 device = getDeviceForStrategy(STRATEGY_PHONE, false /*fromCache*/);
570 break;
571 }
572 // FALL THROUGH
573
574 case STRATEGY_ENFORCED_AUDIBLE:
575 // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION
576 // except:
577 // - when in call where it doesn't default to STRATEGY_PHONE behavior
578 // - in countries where not enforced in which case it follows STRATEGY_MEDIA
579
580 if ((strategy == STRATEGY_SONIFICATION) ||
581 (mForceUse[AudioSystem::FOR_SYSTEM] == AudioSystem::FORCE_SYSTEM_ENFORCED)) {
582 device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER;
583 if (device == AUDIO_DEVICE_NONE) {
584 ALOGE("getDeviceForStrategy() speaker device not found for STRATEGY_SONIFICATION");
585 }
586 }
587 // The second device used for sonification is the same as the device used by media strategy
588 // FALL THROUGH
589
590 case STRATEGY_MEDIA: {
591 uint32_t device2 = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700592
Mingming Yin4a72d652014-01-03 18:54:18 -0800593 if (isInCall() && (device == AUDIO_DEVICE_NONE)) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700594 // when in call, get the device for Phone strategy
595 device = getDeviceForStrategy(STRATEGY_PHONE, false /*fromCache*/);
596 break;
597 }
598#ifdef AUDIO_EXTN_FM_ENABLED
599 if (mForceUse[AudioSystem::FOR_MEDIA] == AudioSystem::FORCE_SPEAKER) {
600 device = AUDIO_DEVICE_OUT_SPEAKER;
601 break;
602 }
603#endif
604
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700605 if (strategy != STRATEGY_SONIFICATION) {
606 // no sonification on remote submix (e.g. WFD)
607 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_REMOTE_SUBMIX;
608 }
609 if ((device2 == AUDIO_DEVICE_NONE) &&
610 mHasA2dp && (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) &&
611 (getA2dpOutput() != 0) && !mA2dpSuspended) {
612 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
613 if (device2 == AUDIO_DEVICE_NONE) {
614 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
615 }
616 if (device2 == AUDIO_DEVICE_NONE) {
617 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
618 }
619 }
620 if (device2 == AUDIO_DEVICE_NONE) {
621 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
622 }
623 if (device2 == AUDIO_DEVICE_NONE) {
624 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADSET;
625 }
626 if (device2 == AUDIO_DEVICE_NONE) {
627 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_ACCESSORY;
628 }
629 if (device2 == AUDIO_DEVICE_NONE) {
630 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_DEVICE;
631 }
632 if (device2 == AUDIO_DEVICE_NONE) {
633 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
634 }
Apoorv Raghuvanshi8506a982014-01-17 13:10:09 -0800635 if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
636 && (device2 == AUDIO_DEVICE_NONE)) {
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700637 // no sonification on aux digital (e.g. HDMI)
638 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
639 }
640 if ((device2 == AUDIO_DEVICE_NONE) &&
Krishnankutty Kolathappilly4b7fdaa2013-12-16 00:40:11 -0800641 (mForceUse[AudioSystem::FOR_DOCK] == AudioSystem::FORCE_ANALOG_DOCK)
642 && (strategy != STRATEGY_SONIFICATION)) {
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700643 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
644 }
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700645#ifdef AUDIO_EXTN_FM_ENABLED
Apoorv Raghuvanshi8506a982014-01-17 13:10:09 -0800646 if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
647 && (device2 == AUDIO_DEVICE_NONE)) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700648 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM_TX;
649 }
650#endif
651#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
Apoorv Raghuvanshi8506a982014-01-17 13:10:09 -0800652 if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
653 && (device2 == AUDIO_DEVICE_NONE)) {
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700654 // no sonification on WFD sink
655 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_PROXY;
656 }
657#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700658 if (device2 == AUDIO_DEVICE_NONE) {
659 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER;
660 }
661
662 // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or
663 // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise
664 device |= device2;
665 if (device) break;
666 device = mDefaultOutputDevice;
667 if (device == AUDIO_DEVICE_NONE) {
668 ALOGE("getDeviceForStrategy() no device found for STRATEGY_MEDIA");
669 }
670 } break;
671
672 default:
673 ALOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
674 break;
675 }
676
677 ALOGVV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
678 return device;
679}
680
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700681audio_devices_t AudioPolicyManager::getDeviceForInputSource(int inputSource)
682{
683 uint32_t device = AUDIO_DEVICE_NONE;
684
685 switch (inputSource) {
686 case AUDIO_SOURCE_VOICE_UPLINK:
687 if (mAvailableInputDevices & AUDIO_DEVICE_IN_VOICE_CALL) {
688 device = AUDIO_DEVICE_IN_VOICE_CALL;
689 break;
690 }
691 // FALL THROUGH
692
693 case AUDIO_SOURCE_DEFAULT:
694 case AUDIO_SOURCE_MIC:
695 case AUDIO_SOURCE_VOICE_RECOGNITION:
696 case AUDIO_SOURCE_HOTWORD:
697 case AUDIO_SOURCE_VOICE_COMMUNICATION:
698 if (mForceUse[AudioSystem::FOR_RECORD] == AudioSystem::FORCE_BT_SCO &&
699 mAvailableInputDevices & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
700 device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
701 } else if (mAvailableInputDevices & AUDIO_DEVICE_IN_WIRED_HEADSET) {
702 device = AUDIO_DEVICE_IN_WIRED_HEADSET;
703 } else if (mAvailableInputDevices & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET) {
704 device = AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET;
705 } else if (mAvailableInputDevices & AUDIO_DEVICE_IN_BUILTIN_MIC) {
706 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
707 }
708 break;
709 case AUDIO_SOURCE_CAMCORDER:
710 if (mAvailableInputDevices & AUDIO_DEVICE_IN_BACK_MIC) {
711 device = AUDIO_DEVICE_IN_BACK_MIC;
712 } else if (mAvailableInputDevices & AUDIO_DEVICE_IN_BUILTIN_MIC) {
713 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
714 }
715 break;
716 case AUDIO_SOURCE_VOICE_DOWNLINK:
717 case AUDIO_SOURCE_VOICE_CALL:
718 if (mAvailableInputDevices & AUDIO_DEVICE_IN_VOICE_CALL) {
719 device = AUDIO_DEVICE_IN_VOICE_CALL;
720 }
721 break;
722 case AUDIO_SOURCE_REMOTE_SUBMIX:
723 if (mAvailableInputDevices & AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
724 device = AUDIO_DEVICE_IN_REMOTE_SUBMIX;
725 }
726 break;
727#ifdef AUDIO_EXTN_FM_ENABLED
728 case AUDIO_SOURCE_FM_RX:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700729 device = AUDIO_DEVICE_IN_FM_RX;
730 break;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700731 case AUDIO_SOURCE_FM_RX_A2DP:
732 device = AUDIO_DEVICE_IN_FM_RX_A2DP;
733 break;
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700734#endif
735 default:
736 ALOGW("getDeviceForInputSource() invalid input source %d", inputSource);
737 break;
738 }
739 ALOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
740 return device;
741}
742
743AudioPolicyManager::device_category AudioPolicyManager::getDeviceCategory(audio_devices_t device)
744{
745 switch(getDeviceForVolume(device)) {
746 case AUDIO_DEVICE_OUT_EARPIECE:
747 return DEVICE_CATEGORY_EARPIECE;
748 case AUDIO_DEVICE_OUT_WIRED_HEADSET:
749 case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
750 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
751 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
752 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
753 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
754#ifdef AUDIO_EXTN_FM_ENABLED
755 case AUDIO_DEVICE_OUT_FM:
756#endif
757 return DEVICE_CATEGORY_HEADSET;
758 case AUDIO_DEVICE_OUT_SPEAKER:
759 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
760 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
761 case AUDIO_DEVICE_OUT_AUX_DIGITAL:
762 case AUDIO_DEVICE_OUT_USB_ACCESSORY:
763 case AUDIO_DEVICE_OUT_USB_DEVICE:
764 case AUDIO_DEVICE_OUT_REMOTE_SUBMIX:
765#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
766 case AUDIO_DEVICE_OUT_PROXY:
767#endif
768 default:
769 return DEVICE_CATEGORY_SPEAKER;
770 }
771}
772
773status_t AudioPolicyManager::checkAndSetVolume(int stream,
774 int index,
775 audio_io_handle_t output,
776 audio_devices_t device,
777 int delayMs,
778 bool force)
779{
780 ALOGV("checkAndSetVolume: index %d output %d device %x", index, output, device);
781 // do not change actual stream volume if the stream is muted
782 if (mOutputs.valueFor(output)->mMuteCount[stream] != 0) {
783 ALOGVV("checkAndSetVolume() stream %d muted count %d",
784 stream, mOutputs.valueFor(output)->mMuteCount[stream]);
785 return NO_ERROR;
786 }
787
788 // do not change in call volume if bluetooth is connected and vice versa
789 if ((stream == AudioSystem::VOICE_CALL && mForceUse[AudioSystem::FOR_COMMUNICATION] == AudioSystem::FORCE_BT_SCO) ||
790 (stream == AudioSystem::BLUETOOTH_SCO && mForceUse[AudioSystem::FOR_COMMUNICATION] != AudioSystem::FORCE_BT_SCO)) {
791 ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
792 stream, mForceUse[AudioSystem::FOR_COMMUNICATION]);
793 return INVALID_OPERATION;
794 }
795
796 float volume = computeVolume(stream, index, output, device);
797 // We actually change the volume if:
798 // - the float value returned by computeVolume() changed
799 // - the force flag is set
800 if (volume != mOutputs.valueFor(output)->mCurVolume[stream] ||
801 force) {
802 mOutputs.valueFor(output)->mCurVolume[stream] = volume;
803 ALOGV("checkAndSetVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs);
804 // Force VOICE_CALL to track BLUETOOTH_SCO stream volume when bluetooth audio is
805 // enabled
806 if (stream == AudioSystem::BLUETOOTH_SCO) {
807 mpClientInterface->setStreamVolume(AudioSystem::VOICE_CALL, volume, output, delayMs);
808#ifdef AUDIO_EXTN_FM_ENABLED
809 } else if (stream == AudioSystem::MUSIC &&
810 output == mPrimaryOutput) {
811 float fmVolume = -1.0;
812 fmVolume = computeVolume(stream, index, output, device);
813 if (fmVolume >= 0) {
814 AudioParameter param = AudioParameter();
815 param.addFloat(String8("fm_volume"), fmVolume);
816 ALOGV("checkAndSetVolume setParameters fm_volume, volume=:%f delay=:%d",fmVolume,delayMs*2);
817 //Double delayMs to avoid sound burst while device switch.
818 mpClientInterface->setParameters(mPrimaryOutput, param.toString(), delayMs*2);
819 }
820#endif
821 }
822 mpClientInterface->setStreamVolume((AudioSystem::stream_type)stream, volume, output, delayMs);
823 }
824
825 if (stream == AudioSystem::VOICE_CALL ||
826 stream == AudioSystem::BLUETOOTH_SCO) {
827 float voiceVolume;
828
829 voiceVolume = (float)index/(float)mStreams[stream].mIndexMax;
830
831 // Force voice volume to max when Vgs is set for bluetooth SCO as volume is managed by the headset
832 if (stream == AudioSystem::BLUETOOTH_SCO) {
833 String8 key ("bt_headset_vgs");
834 mpClientInterface->getParameters(output,key);
835 AudioParameter result(mpClientInterface->getParameters(0,key));
836 int value;
837 if (result.getInt(String8("isVGS"),value) == NO_ERROR) {
838 ALOGV("Use BT-SCO Voice Volume");
839 voiceVolume = 1.0;
840 }
841 }
842
843 if (voiceVolume != mLastVoiceVolume && output == mPrimaryOutput) {
844 mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
845 mLastVoiceVolume = voiceVolume;
846 }
847 }
848
849 return NO_ERROR;
850}
851
852
853float AudioPolicyManager::computeVolume(int stream,
854 int index,
855 audio_io_handle_t output,
856 audio_devices_t device)
857{
858 float volume = 1.0;
859 AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
860
861 if (device == AUDIO_DEVICE_NONE) {
862 device = outputDesc->device();
863 }
864
865 // if volume is not 0 (not muted), force media volume to max on digital output
866 if (stream == AudioSystem::MUSIC &&
867 index != mStreams[stream].mIndexMin &&
868 (device == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
869 device == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET ||
870 device == AUDIO_DEVICE_OUT_USB_ACCESSORY ||
871#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
872 device == AUDIO_DEVICE_OUT_PROXY ||
873#endif
874 device == AUDIO_DEVICE_OUT_USB_DEVICE )) {
875 return 1.0;
876 }
877#ifdef AUDIO_EXTN_INCALL_MUSIC_ENABLED
878 if (stream == AudioSystem::INCALL_MUSIC) {
879 return 1.0;
880 }
881#endif
882 return AudioPolicyManagerBase::computeVolume(stream, index, output, device);
883}
ApurupaPattapu0c566872014-01-10 14:46:02 -0800884
885// This function checks for the parameters which can be offloaded.
886// This can be enhanced depending on the capability of the DSP and policy
887// of the system.
888bool AudioPolicyManager::isOffloadSupported(const audio_offload_info_t& offloadInfo)
889{
890 ALOGV(" isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d,"
891 " BitRate=%u, duration=%lld us, has_video=%d",
892 offloadInfo.sample_rate, offloadInfo.channel_mask,
893 offloadInfo.format,
894 offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us,
895 offloadInfo.has_video);
896
897#ifdef VOICE_CONCURRENCY
898 if(isInCall())
899 {
900 ALOGD("\n blocking compress offload on call mode\n");
901 return false;
902 }
903#endif
904 // Check if stream type is music, then only allow offload as of now.
905 if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC)
906 {
907 ALOGV("isOffloadSupported: stream_type != MUSIC, returning false");
908 return false;
909 }
910
911 char propValue[PROPERTY_VALUE_MAX];
912 bool pcmOffload = false;
913 if (audio_is_offload_pcm(offloadInfo.format)) {
914 if(property_get("audio.offload.pcm.enable", propValue, NULL)) {
915 bool prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
916 if (prop_enabled) {
917 ALOGW("PCM offload property is enabled");
918 pcmOffload = true;
919 }
920 }
921 if (!pcmOffload) {
922 ALOGV("PCM offload disabled by property audio.offload.pcm.enable");
923 return false;
924 }
925 }
926
927 if (!pcmOffload) {
928 // Check if offload has been disabled
929 if (property_get("audio.offload.disable", propValue, "0")) {
930 if (atoi(propValue) != 0) {
931 ALOGV("offload disabled by audio.offload.disable=%s", propValue );
932 return false;
933 }
934 }
935
936 //check if it's multi-channel AAC format
937 if (AudioSystem::popCount(offloadInfo.channel_mask) > 2
938 && offloadInfo.format == AUDIO_FORMAT_AAC) {
939 ALOGV("offload disabled for multi-channel AAC format");
940 return false;
941 }
942
943 if (offloadInfo.has_video)
944 {
945 if(property_get("av.offload.enable", propValue, NULL)) {
946 bool prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
947 if (!prop_enabled) {
948 ALOGW("offload disabled by av.offload.enable = %s ", propValue );
949 return false;
950 }
951 } else {
952 return false;
953 }
954
955 if(offloadInfo.is_streaming) {
956 if (property_get("av.streaming.offload.enable", propValue, NULL)) {
957 bool prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
958 if (!prop_enabled) {
959 ALOGW("offload disabled by av.streaming.offload.enable = %s ", propValue );
960 return false;
961 }
962 } else {
963 //Do not offload AV streamnig if the property is not defined
964 return false;
965 }
966 }
967 ALOGV("isOffloadSupported: has_video == true, property\
968 set to enable offload");
969 }
970 }
971
972 //If duration is less than minimum value defined in property, return false
973 if (property_get("audio.offload.min.duration.secs", propValue, NULL)) {
974 if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) {
975 ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue);
976 return false;
977 }
978 } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) {
979 ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS);
980 //duration checks only valid for MP3/AAC formats,
981 //do not check duration for other audio formats, e.g. dolby AAC/AC3 and amrwb+ formats
982 if (offloadInfo.format == AUDIO_FORMAT_MP3 || offloadInfo.format == AUDIO_FORMAT_AAC || pcmOffload)
983 return false;
984 }
985
986 // Do not allow offloading if one non offloadable effect is enabled. This prevents from
987 // creating an offloaded track and tearing it down immediately after start when audioflinger
988 // detects there is an active non offloadable effect.
989 // FIXME: We should check the audio session here but we do not have it in this context.
990 // This may prevent offloading in rare situations where effects are left active by apps
991 // in the background.
992 if (isNonOffloadableEffectEnabled()) {
993 return false;
994 }
995
996 // See if there is a profile to support this.
997 // AUDIO_DEVICE_NONE
998 IOProfile *profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */,
999 offloadInfo.sample_rate,
1000 offloadInfo.format,
1001 offloadInfo.channel_mask,
1002 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
1003 ALOGV("isOffloadSupported() profile %sfound", profile != NULL ? "" : "NOT ");
1004 return (profile != NULL);
1005}
1006
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001007extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface)
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001008{
1009 return new AudioPolicyManager(clientInterface);
1010}
1011
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -07001012extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001013{
1014 delete interface;
1015}
1016
1017}; // namespace android