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

Commit 3c8b376f authored by Shunkai Yao's avatar Shunkai Yao Committed by Gerrit Code Review
Browse files

Merge "Send effect device/mode/source update if indicator was set in descriptor" into main

parents 838177b7 29f327a7
Loading
Loading
Loading
Loading
+43 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <media/AidlConversionCppNdk.h>
#include <media/AidlConversionNdk.h>
#include <media/AidlConversionEffect.h>
#include <media/AudioContainers.h>
#include <system/audio_effects/effect_visualizer.h>

#include <utils/Log.h>
@@ -61,6 +62,7 @@ const std::map<uint32_t /* effect_command_e */, EffectConversionHelperAidl::Comm
                {EFFECT_CMD_RESET, &EffectConversionHelperAidl::handleReset},
                {EFFECT_CMD_ENABLE, &EffectConversionHelperAidl::handleEnable},
                {EFFECT_CMD_DISABLE, &EffectConversionHelperAidl::handleDisable},
                {EFFECT_CMD_SET_AUDIO_MODE, &EffectConversionHelperAidl::handleSetAudioMode},
                {EFFECT_CMD_SET_AUDIO_SOURCE, &EffectConversionHelperAidl::handleSetAudioSource},
                {EFFECT_CMD_SET_DEVICE, &EffectConversionHelperAidl::handleSetDevice},
                {EFFECT_CMD_SET_INPUT_DEVICE, &EffectConversionHelperAidl::handleSetDevice},
@@ -279,6 +281,10 @@ status_t EffectConversionHelperAidl::handleSetAudioSource(uint32_t cmdSize, cons
              pReplyData);
        return BAD_VALUE;
    }
    if (!getDescriptor().common.flags.audioSourceIndication) {
        ALOGW("%s parameter no audioSourceIndication, skipping", __func__);
        return OK;
    }

    audio_source_t source = *(audio_source_t*)pCmdData;
    AudioSource aidlSource =
@@ -295,6 +301,10 @@ status_t EffectConversionHelperAidl::handleSetAudioMode(uint32_t cmdSize, const
              pReplyData);
        return BAD_VALUE;
    }
    if (!getDescriptor().common.flags.audioModeIndication) {
        ALOGW("%s parameter no audioModeIndication, skipping", __func__);
        return OK;
    }
    audio_mode_t mode = *(audio_mode_t *)pCmdData;
    AudioMode aidlMode =
            VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_audio_mode_t_AudioMode(mode));
@@ -310,9 +320,26 @@ status_t EffectConversionHelperAidl::handleSetDevice(uint32_t cmdSize, const voi
              pReplyData);
        return BAD_VALUE;
    }
    // TODO: convert from audio_devices_t to std::vector<AudioDeviceDescription>
    // const auto& legacyDevice = *(uint32_t*)(pCmdData);
    if (!getDescriptor().common.flags.deviceIndication) {
        ALOGW("%s parameter no deviceIndication, skipping", __func__);
        return OK;
    }
    // convert from bitmask of audio_devices_t to std::vector<AudioDeviceDescription>
    auto legacyDevices = *(uint32_t*)(pCmdData);
    // extract the input bit and remove it from bitmasks
    const auto inputBit = legacyDevices & AUDIO_DEVICE_BIT_IN;
    legacyDevices &= ~AUDIO_DEVICE_BIT_IN;
    std::vector<AudioDeviceDescription> aidlDevices;
    while (legacyDevices) {
        // get audio_devices_t represented by the last true bit and convert to AIDL
        const auto lowestBitDevice = legacyDevices & -legacyDevices;
        AudioDeviceDescription deviceDesc = VALUE_OR_RETURN_STATUS(
                ::aidl::android::legacy2aidl_audio_devices_t_AudioDeviceDescription(
                        static_cast<audio_devices_t>(lowestBitDevice | inputBit)));
        aidlDevices.emplace_back(deviceDesc);
        legacyDevices -= lowestBitDevice;
    }

    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
            mEffect->setParameter(Parameter::make<Parameter::deviceDescription>(aidlDevices))));
    return *static_cast<int32_t*>(pReplyData) = OK;
@@ -435,5 +462,19 @@ bool EffectConversionHelperAidl::isBypassing() const {
            (mIsProxyEffect && std::static_pointer_cast<EffectProxy>(mEffect)->isBypassing()));
}

Descriptor EffectConversionHelperAidl::getDescriptor() const {
    if (!mIsProxyEffect) {
        return mDesc;
    }

    Descriptor desc;
    if (const auto status = mEffect->getDescriptor(&desc); !status.isOk()) {
        ALOGE("%s failed to get proxy descriptor (%d:%s), using default", __func__,
              status.getStatus(), status.getMessage());
        return mDesc;
    }
    return desc;
}

}  // namespace effect
}  // namespace android
+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ class EffectConversionHelperAidl {
    std::shared_ptr<android::hardware::EventFlag> getEventFlagGroup() { return mEfGroup; }
    bool isBypassing() const;

    ::aidl::android::hardware::audio::effect::Descriptor getDescriptor() const;

  protected:
    const int32_t mSessionId;
    const int32_t mIoId;
@@ -134,7 +136,6 @@ class EffectConversionHelperAidl {
    virtual status_t visualizerMeasure(uint32_t* replySize __unused, void* pReplyData __unused) {
        return BAD_VALUE;
    }

};

}  // namespace effect
+4 −4
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ EffectHalAidl::EffectHalAidl(const std::shared_ptr<IFactory>& factory,
      mEffect(effect),
      mSessionId(sessionId),
      mIoId(ioId),
      mDesc(desc),
      mIsProxyEffect(isProxyEffect) {
    createAidlConversion(effect, sessionId, ioId, desc);
}
@@ -169,7 +168,8 @@ status_t EffectHalAidl::process() {
    State state = State::INIT;
    if (mConversion->isBypassing() || !mEffect->getState(&state).isOk() ||
        state != State::PROCESSING) {
        ALOGI("%s skipping %s process because it's %s", __func__, mDesc.common.name.c_str(),
        ALOGI("%s skipping %s process because it's %s", __func__,
              mConversion->getDescriptor().common.name.c_str(),
              mConversion->isBypassing()
                      ? "bypassing"
                      : aidl::android::hardware::audio::effect::toString(state).c_str());
@@ -225,8 +225,8 @@ status_t EffectHalAidl::process() {
        return INVALID_OPERATION;
    }

    ALOGD("%s %s consumed %zu produced %zu", __func__, mDesc.common.name.c_str(), floatsToWrite,
          floatsToRead);
    ALOGD("%s %s consumed %zu produced %zu", __func__,
          mConversion->getDescriptor().common.name.c_str(), floatsToWrite, floatsToRead);
    return OK;
}

+0 −1
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ class EffectHalAidl : public EffectHalInterface {
    const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
    const int32_t mSessionId;
    const int32_t mIoId;
    const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
    const bool mIsProxyEffect;

    std::unique_ptr<EffectConversionHelperAidl> mConversion;
+0 −6
Original line number Diff line number Diff line
@@ -169,12 +169,6 @@ Descriptor::Common EffectProxy::buildDescriptorCommon(
            common.flags.hwAcceleratorMode = Flags::HardwareAccelerator::TUNNEL;
        }

        // initial flag values before we know which sub-effect to active (with setOffloadParam)
        // same as HIDL EffectProxy flags
        common.flags.type = Flags::Type::INSERT;
        common.flags.insert = Flags::Insert::LAST;
        common.flags.volume = Flags::Volume::NONE;

        // set indication if any sub-effect indication was set
        common.flags.offloadIndication |= desc.common.flags.offloadIndication;
        common.flags.deviceIndication |= desc.common.flags.deviceIndication;
Loading