policy: Avoid unnecessary set_parameter calls
APM calls a set_parameter on primary output with key fm_volume
whenever a checkAndSetVolume is called. This is done irrespective
of whether the volume values are same of different.
A side effect of doing so is that the FastMixer associated with
the MixerThread will be put into HOT_IDLE unnecessarily which in turn
can cause glitches/breaks in audio.
CRs-Fixed: 948361
Change-Id: I7fd8b7340e6c78ee6d00b41ccf679582338c011a
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 8577620..ac814cd 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1271,9 +1271,14 @@
#ifdef FM_POWER_OPT
} else if (stream == AUDIO_STREAM_MUSIC && hasPrimaryOutput() &&
outputDesc == mPrimaryOutput) {
- AudioParameter param = AudioParameter();
- param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb));
- mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs);
+ /* Avoid unnecessary set_parameter calls as it puts the primary
+ outputs FastMixer in HOT_IDLE leading to breaks in audio */
+ if (volumeDb != mPrevFMVolumeDb) {
+ mPrevFMVolumeDb = volumeDb;
+ AudioParameter param = AudioParameter();
+ param.addFloat(String8("fm_volume"), Volume::DbToAmpl(volumeDb));
+ mpClientInterface->setParameters(mPrimaryOutput->mIoHandle, param.toString(), delayMs);
+ }
#endif /* FM_POWER_OPT end */
}
@@ -2037,7 +2042,8 @@
: AudioPolicyManager(clientInterface),
mHdmiAudioDisabled(false),
mHdmiAudioEvent(false),
- mPrevPhoneState(0)
+ mPrevPhoneState(0),
+ mPrevFMVolumeDb(0.0f)
{
char ssr_enabled[PROPERTY_VALUE_MAX] = {0};
bool prop_ssr_enabled = false;
diff --git a/policy_hal/AudioPolicyManager.h b/policy_hal/AudioPolicyManager.h
index 55d59ac..59124b8 100644
--- a/policy_hal/AudioPolicyManager.h
+++ b/policy_hal/AudioPolicyManager.h
@@ -154,6 +154,7 @@
// Used for record + playback concurrency
bool mIsInputRequestOnProgress;
#endif
+ float mPrevFMVolumeDb;
};
};