policy-hal: squash multiple changes/fixes to custom policy
This commit is a squash of below changes. Only relevant
changes have been ported and the other required changes
are in base policy manager.
audiopolicy: support extended feature in audiopolicymanager.
Change-Id: I1925339b591cd29f11a71c287a2e53c0627e9e62
audiopolicy: additional change for extended feature
Change-Id: I9bad6a294ddd7aee72f6f6a314666b892b730c8e
audiopolicy: Do not route audio to HDMI if HDMI not connected
Change-Id: I1c76ba3c3a1438463461ea7c41799633bd977283
audiopolicy: Fix for device selection during concurrent audio playback
Change-Id: Ibf3c1bfd05b68d70c6cb9e8b9b95e989f27c2e75
Change-Id: I00470a057cdeefff7bba3bffd333fb556f3d97e6
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index f105e15..a1becd8 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -122,6 +122,15 @@
// handle output device connection
case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: {
if (index >= 0) {
+#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
+ if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
+ if (!strncmp(device_address, "hdmi_spkr", 9)) {
+ mHdmiAudioDisabled = false;
+ } else {
+ mHdmiAudioEvent = true;
+ }
+ }
+#endif
ALOGW("setDeviceConnectionState() device already connected: %x", device);
return INVALID_OPERATION;
}
@@ -129,6 +138,20 @@
// register new device as available
index = mAvailableOutputDevices.add(devDesc);
+#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
+ if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
+ if (!strncmp(device_address, "hdmi_spkr", 9)) {
+ mHdmiAudioDisabled = false;
+ } else {
+ mHdmiAudioEvent = true;
+ }
+ if (mHdmiAudioDisabled || !mHdmiAudioEvent) {
+ mAvailableOutputDevices.remove(devDesc);
+ ALOGW("HDMI sink not connected, do not route audio to HDMI out");
+ return INVALID_OPERATION;
+ }
+ }
+#endif
if (index >= 0) {
sp<HwModule> module = mHwModules.getModuleForDevice(device);
if (module == 0) {
@@ -164,6 +187,15 @@
// handle output device disconnection
case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
if (index < 0) {
+#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
+ if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
+ if (!strncmp(device_address, "hdmi_spkr", 9)) {
+ mHdmiAudioDisabled = true;
+ } else {
+ mHdmiAudioEvent = false;
+ }
+ }
+#endif
ALOGW("setDeviceConnectionState() device not connected: %x", device);
return INVALID_OPERATION;
}
@@ -177,7 +209,15 @@
// remove device from available output devices
mAvailableOutputDevices.remove(devDesc);
-
+#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED
+ if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
+ if (!strncmp(device_address, "hdmi_spkr", 9)) {
+ mHdmiAudioDisabled = true;
+ } else {
+ mHdmiAudioEvent = false;
+ }
+ }
+#endif
checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress);
// Propagate device availability to Engine
@@ -524,9 +564,8 @@
(isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION)
&& (!isStrategyActive(mPrimaryOutput,STRATEGY_MEDIA)))) {
device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
- } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL)||
- (isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION_RESPECTFUL)
- && (!isStrategyActive(mPrimaryOutput, STRATEGY_MEDIA)))) {
+ } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION_RESPECTFUL) ||
+ isStrategyActive(mPrimaryOutput,STRATEGY_SONIFICATION_RESPECTFUL)) {
device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache);
} else if (isStrategyActive(outputDesc, STRATEGY_ACCESSIBILITY)) {
device = getDeviceForStrategy(STRATEGY_ACCESSIBILITY, fromCache);
@@ -547,6 +586,7 @@
{
ALOGV("setPhoneState() state %d", state);
// store previous phone state for management of sonification strategy below
+ audio_devices_t newDevice = AUDIO_DEVICE_NONE;
int oldState = mEngine->getPhoneState();
if (mEngine->setPhoneState(state) != NO_ERROR) {
@@ -564,8 +604,7 @@
if (stream == AUDIO_STREAM_PATCH) {
continue;
}
-
- handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput);
+ handleIncallSonification((audio_stream_type_t)stream, false, true, curOutput);
}
}
@@ -837,7 +876,14 @@
setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
}
}
-
+ //update device for all non-primary outputs
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ audio_io_handle_t output = mOutputs.keyAt(i);
+ if (output != mPrimaryOutput->mIoHandle) {
+ newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/);
+ setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE));
+ }
+ }
// if entering in call state, handle special case of active streams
// pertaining to sonification strategy see handleIncallSonification()
if (isStateInCall(state)) {
@@ -848,7 +894,7 @@
if (stream == AUDIO_STREAM_PATCH) {
continue;
}
- handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
+ handleIncallSonification((audio_stream_type_t)stream, true, true, curOutput);
}
}
}
@@ -869,10 +915,10 @@
handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT);
// handle special case for sonification while in call
- if (isInCall()) {
+ if (isInCall() && (outputDesc->mRefCount[stream] == 1)) {
if (outputDesc->isDuplicated()) {
- handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
- handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
+ handleIncallSonification(stream, false, false, outputDesc->mOutput1->mIoHandle);
+ handleIncallSonification(stream, false, false, outputDesc->mOutput2->mIoHandle);
}
handleIncallSonification(stream, false, false, outputDesc->mIoHandle);
}
@@ -901,8 +947,9 @@
desc->isActive() &&
outputDesc->sharesHwModuleWith(desc) &&
(newDevice != desc->device())) {
- setOutputDevice(desc,
- getNewOutputDevice(desc, false /*fromCache*/),
+ audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/);
+ setOutputDevice(desc,
+ dev,
true,
outputDesc->latency()*2);
}
@@ -1361,6 +1408,7 @@
}
#endif
+#ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
/*
* WFD audio routes back to target speaker when starting a ringtone playback.
* This is because primary output is reused for ringtone, so output device is
@@ -1380,6 +1428,8 @@
else //route every thing else to ULL path
flags = AUDIO_OUTPUT_FLAG_FAST;
}
+#endif
+
// open a direct output if required by specified parameters
// force direct flag if offload flag is set: offloading implies a direct output stream
// and all common behaviors are driven by checking only the direct flag
@@ -1720,7 +1770,7 @@
// Move tracks associated to this strategy from previous output to new output
for (int i = AUDIO_STREAM_SYSTEM; i < (int)AUDIO_STREAM_CNT; i++) {
// Do not call invalidate for ENFORCED_AUDIBLE (otherwise pops are seen for camcorder)
- if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH)) {
+ if ((i != AUDIO_STREAM_ENFORCED_AUDIBLE && (i != AUDIO_STREAM_PATCH))) {
ALOGD("Invalidate on releaseInput for stream :: %d ", i);
//FIXME see fixme on name change
mpClientInterface->invalidateStream((audio_stream_type_t)i);
@@ -1818,7 +1868,10 @@
}
AudioPolicyManagerCustom::AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
- : AudioPolicyManager(clientInterface)
+ : AudioPolicyManager(clientInterface),
+ mHdmiAudioDisabled(false),
+ mHdmiAudioEvent(false),
+ mPrevPhoneState(0)
{
#ifdef RECORD_PLAY_CONCURRENCY
mIsInputRequestOnProgress = false;
@@ -1829,31 +1882,4 @@
mFallBackflag = getFallBackPath();
#endif
}
-audio_devices_t AudioPolicyManagerCustom::getDeviceForStrategy(routing_strategy strategy, bool fromCache)
-{
- audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types();
- audio_devices_t device = AUDIO_DEVICE_NONE;
- switch (strategy) {
- case STRATEGY_SONIFICATION:
- case STRATEGY_ENFORCED_AUDIBLE:
- case STRATEGY_ACCESSIBILITY:
- case STRATEGY_REROUTING:
- case STRATEGY_MEDIA:
- if (strategy != STRATEGY_SONIFICATION){
- // no sonification on WFD sink
- device |= availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY;
- if (device != AUDIO_DEVICE_NONE) {
- ALOGV("Found proxy for strategy %d", strategy);
- return device;
- }
- }
- break;
- default:
- ALOGV("getDeviceForStrategy() unknown strategy: %d", strategy);
- break;
- }
- device = AudioPolicyManager::getDeviceForStrategy(strategy, fromCache);
- return device;
-}
-
}