Apply volume setting for the volume controller effect in EffectChain
The last EFFECT_CMD_SET_VOLUME parameter received in lvm EffectBundle
takes effect. Always send volume to HAL for the volume controller
effect make sure the effect bundle volume won't be override by non
volume controller effect
Bug: 337114946
Test: atest CtsMediaAudioTestCases
Test: atest AudioEffectTest
Test: repo steps in b/337114946
Change-Id: If3ee3fc85d7268a6f5d4d75abfbb9c61cdc78bd8
Merged-In: If3ee3fc85d7268a6f5d4d75abfbb9c61cdc78bd8
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 0d3d3f8..d9a9a9c 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -1357,15 +1357,16 @@
}
}
-status_t EffectModule::setVolume(uint32_t* left, uint32_t* right, bool controller, bool force) {
+status_t EffectModule::setVolume_l(uint32_t* left, uint32_t* right, bool controller, bool force) {
AutoLockReentrant _l(mutex(), mSetVolumeReentrantTid);
if (mStatus != NO_ERROR) {
return mStatus;
}
status_t status = NO_ERROR;
// Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume
- // if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set)
- if ((isProcessEnabled() || force) &&
+ // if controller flag is set (Note that controller == TRUE => the volume controller effect in
+ // the effect chain)
+ if (((isOffloadedOrDirect_l() ? isEnabled() : isProcessEnabled()) || force) &&
((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL ||
(mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND ||
(mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_MONITOR)) {
@@ -1376,7 +1377,8 @@
status_t EffectModule::setVolumeInternal(
uint32_t *left, uint32_t *right, bool controller) {
- if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1]) {
+ if (mVolume.has_value() && *left == mVolume.value()[0] && *right == mVolume.value()[1] &&
+ !controller) {
LOG_ALWAYS_FATAL_IF(
!mReturnedVolume.has_value(),
"The cached returned volume must not be null when the cached volume has value");
@@ -1385,14 +1387,14 @@
return NO_ERROR;
}
uint32_t volume[2] = {*left, *right};
- uint32_t *pVolume = controller ? volume : nullptr;
+ uint32_t* pVolume = isVolumeControl() ? volume : nullptr;
uint32_t size = sizeof(volume);
status_t status = mEffectInterface->command(EFFECT_CMD_SET_VOLUME,
size,
volume,
&size,
pVolume);
- if (controller && status == NO_ERROR && size == sizeof(volume)) {
+ if (pVolume && status == NO_ERROR && size == sizeof(volume)) {
mVolume = {*left, *right}; // Cache the value that has been set
*left = volume[0];
*right = volume[1];
@@ -2420,7 +2422,7 @@
// volume will be set from setVolume_l.
uint32_t left = 0;
uint32_t right = 0;
- effect->setVolume(&left, &right, true /*controller*/, true /*force*/);
+ effect->setVolume_l(&left, &right, true /*controller*/, true /*force*/);
}
}
@@ -2618,6 +2620,7 @@
// first update volume controller
const auto volumeControlIndex = findVolumeControl_l(0, size);
+ // index of the effect chain volume controller
const int ctrlIdx = volumeControlIndex.value_or(-1);
const sp<IAfEffectModule> volumeControlEffect =
volumeControlIndex.has_value() ? mEffects[ctrlIdx] : nullptr;
@@ -2634,12 +2637,15 @@
mVolumeControlEffect = volumeControlEffect;
for (int i = 0; i < ctrlIdx; ++i) {
- // For all volume control effects before the effect that controls volume, set the volume
+ // For all effects before the effect that controls volume, they are not controlling the
+ // effect chain volume, if these effects has the volume control capability, set the volume
// to maximum to avoid double attenuation.
if (mEffects[i]->isVolumeControl()) {
uint32_t leftMax = 1 << 24;
uint32_t rightMax = 1 << 24;
- mEffects[i]->setVolume(&leftMax, &rightMax, true /*controller*/, true /*force*/);
+ mEffects[i]->setVolume_l(&leftMax, &rightMax,
+ false /* not an effect chain volume controller */,
+ true /* force */);
}
}
@@ -2648,7 +2654,8 @@
// second get volume update from volume controller
if (ctrlIdx >= 0) {
- mEffects[ctrlIdx]->setVolume(&newLeft, &newRight, true);
+ mEffects[ctrlIdx]->setVolume_l(&newLeft, &newRight,
+ true /* effect chain volume controller */);
mNewLeftVolume = newLeft;
mNewRightVolume = newRight;
}
@@ -2669,9 +2676,11 @@
}
// Pass requested volume directly if this is volume monitor module
if (mEffects[i]->isVolumeMonitor()) {
- mEffects[i]->setVolume(left, right, false);
+ mEffects[i]->setVolume_l(left, right,
+ false /* not an effect chain volume controller */);
} else {
- mEffects[i]->setVolume(&lVol, &rVol, false);
+ mEffects[i]->setVolume_l(&lVol, &rVol,
+ false /* not an effect chain volume controller */);
}
}
*left = newLeft;