audio: Fix the getters of the hardware mixer controls
Since there is a local cache of hardware mixer controls
(mHwGains and mHwVolumes), the getters do not need to
query the mixer every time. Instead, we only read from
the mixer when the cache is empty.
Bug: 375030900
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I8de367cee503124acd485465dffadaadcbac88af
Signed-off-by: Jindong Yue <jindong.yue@nxp.com>
diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp
index de66293..3d7f30c 100644
--- a/audio/aidl/default/Stream.cpp
+++ b/audio/aidl/default/Stream.cpp
@@ -937,9 +937,12 @@
}
StreamInHwGainHelper::StreamInHwGainHelper(const StreamContext* context)
- : mChannelCount(getChannelCount(context->getChannelLayout())), mHwGains(mChannelCount, 0.0f) {}
+ : mChannelCount(getChannelCount(context->getChannelLayout())) {}
ndk::ScopedAStatus StreamInHwGainHelper::getHwGainImpl(std::vector<float>* _aidl_return) {
+ if (mHwGains.empty()) {
+ mHwGains.resize(mChannelCount, 0.0f);
+ }
*_aidl_return = mHwGains;
LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
return ndk::ScopedAStatus::ok();
@@ -1068,10 +1071,12 @@
}
StreamOutHwVolumeHelper::StreamOutHwVolumeHelper(const StreamContext* context)
- : mChannelCount(getChannelCount(context->getChannelLayout())),
- mHwVolumes(mChannelCount, 0.0f) {}
+ : mChannelCount(getChannelCount(context->getChannelLayout())) {}
ndk::ScopedAStatus StreamOutHwVolumeHelper::getHwVolumeImpl(std::vector<float>* _aidl_return) {
+ if (mHwVolumes.empty()) {
+ mHwVolumes.resize(mChannelCount, 0.0f);
+ }
*_aidl_return = mHwVolumes;
LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
return ndk::ScopedAStatus::ok();