Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c7e78b8 authored by Jindong Yue's avatar Jindong Yue Committed by Mikhail Naganov
Browse files

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: default avatarJindong Yue <jindong.yue@nxp.com>
parent 30338f9a
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -937,9 +937,12 @@ ndk::ScopedAStatus StreamIn::setHwGain(const std::vector<float>& in_channelGains
}

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 @@ ndk::ScopedAStatus StreamOut::selectPresentation(int32_t in_presentationId, int3
}

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();
+11 −8
Original line number Diff line number Diff line
@@ -218,11 +218,12 @@ ndk::ScopedAStatus StreamInPrimary::getHwGain(std::vector<float>* _aidl_return)
    if (isStubStream()) {
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    }
    if (mHwGains.empty()) {
        float gain;
        RETURN_STATUS_IF_ERROR(primary::PrimaryMixer::getInstance().getMicGain(&gain));
    _aidl_return->resize(0);
        _aidl_return->resize(mChannelCount, gain);
        RETURN_STATUS_IF_ERROR(setHwGainImpl(*_aidl_return));
    }
    return getHwGainImpl(_aidl_return);
}

@@ -254,9 +255,11 @@ ndk::ScopedAStatus StreamOutPrimary::getHwVolume(std::vector<float>* _aidl_retur
    if (isStubStream()) {
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    }
    if (mHwVolumes.empty()) {
        RETURN_STATUS_IF_ERROR(primary::PrimaryMixer::getInstance().getVolumes(_aidl_return));
        _aidl_return->resize(mChannelCount);
        RETURN_STATUS_IF_ERROR(setHwVolumeImpl(*_aidl_return));
    }
    return getHwVolumeImpl(_aidl_return);
}