summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-04-22 13:57:53 -0700
committerEric Laurent <elaurent@google.com>2012-04-23 10:25:13 -0700
commit9029a4fe8abafd383e6fbb1409d1e2f749b51391 (patch)
treef08617bee6c9674c1fb5e7b663a4b64e29077ab6
parentb2971bf2ae4e9da3155559aa134e3aa6c2b216a4 (diff)
downloadhardware_libhardware_legacy-9029a4fe8abafd383e6fbb1409d1e2f749b51391.zip
hardware_libhardware_legacy-9029a4fe8abafd383e6fbb1409d1e2f749b51391.tar.gz
hardware_libhardware_legacy-9029a4fe8abafd383e6fbb1409d1e2f749b51391.tar.bz2
audio policy: volume burst when switching device
The addition of the per device volume feature has introduced a problem where a volume burst can be heard in the headphones just after insertion if the speaker volume is much higher than the headphones volume. Added a temporary mute of the output when switching device to force volume ramp to 0 and back up to new volume. Issue 5984108. Change-Id: I5c9ffbbcadd12d25c78cc2614d351346b8186c55
-rw-r--r--audio/AudioPolicyManagerBase.cpp23
-rw-r--r--include/hardware_legacy/AudioPolicyManagerBase.h3
2 files changed, 20 insertions, 6 deletions
diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp
index 7efa4ba..0c00208 100644
--- a/audio/AudioPolicyManagerBase.cpp
+++ b/audio/AudioPolicyManagerBase.cpp
@@ -2066,8 +2066,12 @@ void AudioPolicyManagerBase::updateDeviceForStrategy()
}
uint32_t AudioPolicyManagerBase::checkDeviceMuteStrategies(AudioOutputDescriptor *outputDesc,
+ audio_devices_t prevDevice,
uint32_t delayMs)
{
+ // mute/unmute strategies using an incompatible device combination
+ // if muting, wait for the audio in pcm buffer to be drained before proceeding
+ // if unmuting, unmute only after the specified delay
if (outputDesc->isDuplicated()) {
return 0;
}
@@ -2076,6 +2080,9 @@ uint32_t AudioPolicyManagerBase::checkDeviceMuteStrategies(AudioOutputDescriptor
audio_devices_t device = outputDesc->device();
bool shouldMute = (outputDesc->refCount() != 0) &&
(AudioSystem::popCount(device) >= 2);
+ // temporary mute output if device selection changes to avoid volume bursts due to
+ // different per device volumes
+ bool tempMute = (outputDesc->refCount() != 0) && (device != prevDevice);
for (size_t i = 0; i < NUM_STRATEGIES; i++) {
audio_devices_t curDevice = getDeviceForStrategy((routing_strategy)i, false /*fromCache*/);
@@ -2089,7 +2096,7 @@ uint32_t AudioPolicyManagerBase::checkDeviceMuteStrategies(AudioOutputDescriptor
doMute = true;
outputDesc->mStrategyMutedByDevice[i] = false;
}
- if (doMute) {
+ if (doMute || tempMute) {
for (size_t j = 0; j < mOutputs.size(); j++) {
AudioOutputDescriptor *desc = mOutputs.valueAt(j);
if ((desc->supportedDevices() & outputDesc->supportedDevices()) == 0) {
@@ -2099,9 +2106,15 @@ uint32_t AudioPolicyManagerBase::checkDeviceMuteStrategies(AudioOutputDescriptor
ALOGV("checkDeviceMuteStrategies() %s strategy %d (curDevice %04x) on output %d",
mute ? "muting" : "unmuting", i, curDevice, curOutput);
setStrategyMute((routing_strategy)i, mute, curOutput, mute ? 0 : delayMs);
- if (mute && (desc->strategyRefCount((routing_strategy)i) != 0)) {
- if (muteWaitMs < desc->latency()) {
- muteWaitMs = desc->latency();
+ if (desc->strategyRefCount((routing_strategy)i) != 0) {
+ if (tempMute) {
+ setStrategyMute((routing_strategy)i, true, curOutput, 0);
+ setStrategyMute((routing_strategy)i, false, curOutput, desc->latency() * 2);
+ }
+ if (tempMute || mute) {
+ if (muteWaitMs < desc->latency()) {
+ muteWaitMs = desc->latency();
+ }
}
}
}
@@ -2147,7 +2160,7 @@ uint32_t AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output,
if (device != 0) {
outputDesc->mDevice = device;
}
- muteWaitMs = checkDeviceMuteStrategies(outputDesc, delayMs);
+ muteWaitMs = checkDeviceMuteStrategies(outputDesc, prevDevice, delayMs);
// Do not change the routing if:
// - the requested device is 0
diff --git a/include/hardware_legacy/AudioPolicyManagerBase.h b/include/hardware_legacy/AudioPolicyManagerBase.h
index d56247b..916c952 100644
--- a/include/hardware_legacy/AudioPolicyManagerBase.h
+++ b/include/hardware_legacy/AudioPolicyManagerBase.h
@@ -447,7 +447,8 @@ protected:
// if unmuting, unmute only after the specified delay
// Returns the number of ms waited
uint32_t checkDeviceMuteStrategies(AudioOutputDescriptor *outputDesc,
- uint32_t delayMs);
+ audio_devices_t prevDevice,
+ uint32_t delayMs);
audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
AudioSystem::output_flags flags);