[AudioPolicyManager] Fix mute/unmute while use DevicePortGain

In case of using Device Port Gain to control the volume, the logic
of setVolumeIndexForAttributes for device type check has been bypassed.

However, in case of unmuting, the volume will be applied to all streams
with requested device then will be set for AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME
which is a convention used in case of no volume for device has been set
previously.
As this logic is bypassed, in case of HwGain, the final gain applied will
be the one for AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME, which may be completely
different from the gain of current device.

This CL fixes this by factorizing the device check logic for both SW/HW gains.

Test: build & play music & Vol - until mute then volume +. No gap expected.
Change-Id: I24c57df84496e404c05c92f08f907131ef79cf3a
Signed-off-by: François Gaffie <francois.gaffie@renault.com>
gugelfrei
François Gaffie 4 years ago
parent c9a69d3796
commit ed91f58c8a

@ -2512,15 +2512,29 @@ status_t AudioPolicyManager::setVolumeIndexForAttributes(const audio_attributes_
if (curDevices.erase(AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
curDevices.insert(AUDIO_DEVICE_OUT_SPEAKER);
}
if (!(desc->isActive(vs) || isInCall())) {
continue;
}
if (device != AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME &&
curDevices.find(device) == curDevices.end()) {
continue;
}
bool applyVolume = false;
if (device != AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME) {
curSrcDevices.insert(device);
applyVolume = (curSrcDevices.find(
Volume::getDeviceForVolume(curDevices)) != curSrcDevices.end());
} else {
applyVolume = !curves.hasVolumeIndexForDevice(curSrcDevice);
}
if (!applyVolume) {
continue; // next output
}
// Inter / intra volume group priority management: Loop on strategies arranged by priority
// If a higher priority strategy is active, and the output is routed to a device with a
// HW Gain management, do not change the volume
bool applyVolume = false;
if (desc->useHwGain()) {
if (!(desc->isActive(toVolumeSource(group)) || isInCall())) {
continue;
}
applyVolume = false;
for (const auto &productStrategy : mEngine->getOrderedProductStrategies()) {
auto activeClients = desc->clientsList(true /*activeOnly*/, productStrategy,
false /*preferredDevice*/);
@ -2554,39 +2568,16 @@ status_t AudioPolicyManager::setVolumeIndexForAttributes(const audio_attributes_
if (!applyVolume) {
continue; // next output
}
status_t volStatus = checkAndSetVolume(curves, vs, index, desc, curDevices,
(vs == toVolumeSource(AUDIO_STREAM_SYSTEM)?
TOUCH_SOUND_FIXED_DELAY_MS : 0));
if (volStatus != NO_ERROR) {
status = volStatus;
}
continue;
}
if (!(desc->isActive(vs) || isInCall())) {
continue;
}
if (device != AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME &&
curDevices.find(device) == curDevices.end()) {
continue;
}
if (device != AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME) {
curSrcDevices.insert(device);
applyVolume = (curSrcDevices.find(
Volume::getDeviceForVolume(curDevices)) != curSrcDevices.end());
} else {
applyVolume = !curves.hasVolumeIndexForDevice(curSrcDevice);
}
if (applyVolume) {
//FIXME: workaround for truncated touch sounds
// delayed volume change for system stream to be removed when the problem is
// handled by system UI
status_t volStatus = checkAndSetVolume(
curves, vs, index, desc, curDevices,
((vs == toVolumeSource(AUDIO_STREAM_SYSTEM))?
TOUCH_SOUND_FIXED_DELAY_MS : 0));
if (volStatus != NO_ERROR) {
status = volStatus;
}
//FIXME: workaround for truncated touch sounds
// delayed volume change for system stream to be removed when the problem is
// handled by system UI
status_t volStatus = checkAndSetVolume(
curves, vs, index, desc, curDevices,
((vs == toVolumeSource(AUDIO_STREAM_SYSTEM))?
TOUCH_SOUND_FIXED_DELAY_MS : 0));
if (volStatus != NO_ERROR) {
status = volStatus;
}
}
mpClientInterface->onAudioVolumeGroupChanged(group, 0 /*flags*/);

Loading…
Cancel
Save