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

Commit 06267d9d authored by Shunkai Yao's avatar Shunkai Yao Committed by Gerrit Code Review
Browse files

Merge changes from topic "effect_reopen" into main

* changes:
   Effect AIDL: implement IEffect.reopen
  Add an AIDL interface for reopen when dataMQ not valid
parents cf3e9b3e 1afb46c9
Loading
Loading
Loading
Loading
+21 −22
Original line number Diff line number Diff line
@@ -180,18 +180,6 @@ status_t EffectConversionHelperAidl::handleSetConfig(uint32_t cmdSize, const voi

    State state;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getState(&state)));
    // in case of buffer/ioHandle re-configure for an opened effect, close it and re-open
    if (state != State::INIT && mCommon != common) {
        ALOGI("%s at state %s, common parameter change from %s to %s, closing effect", __func__,
              android::internal::ToString(state).c_str(), mCommon.toString().c_str(),
              common.toString().c_str());
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->close()));
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getState(&state)));
        mStatusQ.reset();
        mInputQ.reset();
        mOutputQ.reset();
    }

    if (state == State::INIT) {
        ALOGI("%s at state %s, opening effect with input %s output %s", __func__,
              android::internal::ToString(state).c_str(), common.input.toString().c_str(),
@@ -199,16 +187,7 @@ status_t EffectConversionHelperAidl::handleSetConfig(uint32_t cmdSize, const voi
        IEffect::OpenEffectReturn openReturn;
        RETURN_STATUS_IF_ERROR(
                statusTFromBinderStatus(mEffect->open(common, std::nullopt, &openReturn)));

        if (mIsProxyEffect) {
            mStatusQ = std::static_pointer_cast<EffectProxy>(mEffect)->getStatusMQ();
            mInputQ = std::static_pointer_cast<EffectProxy>(mEffect)->getInputMQ();
            mOutputQ = std::static_pointer_cast<EffectProxy>(mEffect)->getOutputMQ();
        } else {
            mStatusQ = std::make_shared<StatusMQ>(openReturn.statusMQ);
            mInputQ = std::make_shared<DataMQ>(openReturn.inputDataMQ);
            mOutputQ = std::make_shared<DataMQ>(openReturn.outputDataMQ);
        }
        updateMqs(openReturn);

        if (status_t status = updateEventFlags(); status != OK) {
            ALOGV("%s closing at status %d", __func__, status);
@@ -225,6 +204,18 @@ status_t EffectConversionHelperAidl::handleSetConfig(uint32_t cmdSize, const voi
    return *static_cast<int32_t*>(pReplyData) = OK;
}

void EffectConversionHelperAidl::updateMqs(const IEffect::OpenEffectReturn& ret) {
    if (mIsProxyEffect) {
        mStatusQ = std::static_pointer_cast<EffectProxy>(mEffect)->getStatusMQ();
        mInputQ = std::static_pointer_cast<EffectProxy>(mEffect)->getInputMQ();
        mOutputQ = std::static_pointer_cast<EffectProxy>(mEffect)->getOutputMQ();
    } else {
        mStatusQ = std::make_shared<StatusMQ>(ret.statusMQ);
        mInputQ = std::make_shared<DataMQ>(ret.inputDataMQ);
        mOutputQ = std::make_shared<DataMQ>(ret.outputDataMQ);
    }
}

status_t EffectConversionHelperAidl::handleGetConfig(uint32_t cmdSize __unused,
                                                     const void* pCmdData __unused,
                                                     uint32_t* replySize, void* pReplyData) {
@@ -517,5 +508,13 @@ Descriptor EffectConversionHelperAidl::getDescriptor() const {
    return desc;
}

status_t EffectConversionHelperAidl::reopen() {
    IEffect::OpenEffectReturn openReturn;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->reopen(&openReturn)));

    updateMqs(openReturn);
    return OK;
}

}  // namespace effect
}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ class EffectConversionHelperAidl {
    bool isBypassingOrTunnel() const;

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

  protected:
    const int32_t mSessionId;
@@ -108,6 +109,8 @@ class EffectConversionHelperAidl {
    std::shared_ptr<android::hardware::EventFlag> mEfGroup = nullptr;
    status_t updateEventFlags();

    void updateMqs(const ::aidl::android::hardware::audio::effect::IEffect::OpenEffectReturn& ret);

    status_t handleInit(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize,
                        void* pReplyData);
    status_t handleSetConfig(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize,
+21 −9
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ using ::aidl::android::aidl_utils::statusTFromBinderStatus;
using ::aidl::android::hardware::audio::effect::Descriptor;
using ::aidl::android::hardware::audio::effect::IEffect;
using ::aidl::android::hardware::audio::effect::IFactory;
using ::aidl::android::hardware::audio::effect::kEventFlagDataMqUpdate;
using ::aidl::android::hardware::audio::effect::State;

namespace android {
@@ -165,26 +166,37 @@ status_t EffectHalAidl::setOutBuffer(const sp<EffectBufferHalInterface>& buffer)

// write to input FMQ here, wait for statusMQ STATUS_OK, and read from output FMQ
status_t EffectHalAidl::process() {
    const std::string effectName = mConversion->getDescriptor().common.name;
    State state = State::INIT;
    if (mConversion->isBypassing() || !mEffect->getState(&state).isOk() ||
        state != State::PROCESSING) {
        ALOGI("%s skipping %s process because it's %s", __func__,
              mConversion->getDescriptor().common.name.c_str(),
        ALOGI("%s skipping %s process because it's %s", __func__, effectName.c_str(),
              mConversion->isBypassing()
                      ? "bypassing"
                      : aidl::android::hardware::audio::effect::toString(state).c_str());
        return -ENODATA;
    }

    // check if the DataMq needs any update, timeout at 1ns to avoid being blocked
    auto efGroup = mConversion->getEventFlagGroup();
    if (!efGroup) {
        ALOGE("%s invalid efGroup", __func__);
        return INVALID_OPERATION;
    }

    if (uint32_t efState = 0;
        ::android::OK == efGroup->wait(kEventFlagDataMqUpdate, &efState, 1 /* ns */,
                                       true /* retry */)) {
        ALOGI("%s %s receive dataMQUpdate eventFlag from HAL", __func__, effectName.c_str());
        mConversion->reopen();
    }
    auto statusQ = mConversion->getStatusMQ();
    auto inputQ = mConversion->getInputMQ();
    auto outputQ = mConversion->getOutputMQ();
    auto efGroup = mConversion->getEventFlagGroup();
    if (!statusQ || !statusQ->isValid() || !inputQ || !inputQ->isValid() || !outputQ ||
        !outputQ->isValid() || !efGroup) {
        ALOGE("%s invalid FMQ [Status %d I %d O %d] efGroup %p", __func__,
              statusQ ? statusQ->isValid() : 0, inputQ ? inputQ->isValid() : 0,
              outputQ ? outputQ->isValid() : 0, efGroup.get());
        !outputQ->isValid()) {
        ALOGE("%s invalid FMQ [Status %d I %d O %d]", __func__, statusQ ? statusQ->isValid() : 0,
              inputQ ? inputQ->isValid() : 0, outputQ ? outputQ->isValid() : 0);
        return INVALID_OPERATION;
    }

@@ -225,8 +237,8 @@ status_t EffectHalAidl::process() {
        return INVALID_OPERATION;
    }

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

+27 −2
Original line number Diff line number Diff line
@@ -106,8 +106,8 @@ ndk::ScopedAStatus EffectProxy::setOffloadParam(const effect_offload_param_t* of
ndk::ScopedAStatus EffectProxy::open(const Parameter::Common& common,
                                     const std::optional<Parameter::Specific>& specific,
                                     IEffect::OpenEffectReturn* ret __unused) {
    ndk::ScopedAStatus status = ndk::ScopedAStatus::fromExceptionCodeWithMessage(
            EX_ILLEGAL_ARGUMENT, "nullEffectHandle");
    ndk::ScopedAStatus status =
            ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_STATE, "nullEffectHandle");
    for (auto& sub : mSubEffects) {
        IEffect::OpenEffectReturn openReturn;
        if (!sub.handle || !(status = sub.handle->open(common, specific, &openReturn)).isOk()) {
@@ -130,6 +130,31 @@ ndk::ScopedAStatus EffectProxy::open(const Parameter::Common& common,
    return status;
}

ndk::ScopedAStatus EffectProxy::reopen(OpenEffectReturn* ret __unused) {
    ndk::ScopedAStatus status =
            ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_STATE, "nullEffectHandle");
    for (auto& sub : mSubEffects) {
        IEffect::OpenEffectReturn openReturn;
        if (!sub.handle || !(status = sub.handle->reopen(&openReturn)).isOk()) {
            ALOGE("%s: failed to open %p UUID %s", __func__, sub.handle.get(),
                  ::android::audio::utils::toString(sub.descriptor.common.id.uuid).c_str());
            break;
        }
        sub.effectMq.statusQ = std::make_shared<StatusMQ>(openReturn.statusMQ);
        sub.effectMq.inputQ = std::make_shared<DataMQ>(openReturn.inputDataMQ);
        sub.effectMq.outputQ = std::make_shared<DataMQ>(openReturn.outputDataMQ);
    }

    // close all opened effects if failure
    if (!status.isOk()) {
        ALOGE("%s: closing all sub-effects with error %s", __func__,
              status.getDescription().c_str());
        close();
    }

    return status;
}

ndk::ScopedAStatus EffectProxy::close() {
    return runWithAllSubEffects([&](std::shared_ptr<IEffect>& effect) {
        return effect->close();
+2 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ class EffectProxy final : public ::aidl::android::hardware::audio::effect::BnEff
                    specific,
            ::aidl::android::hardware::audio::effect::IEffect::OpenEffectReturn* ret) override;
    ndk::ScopedAStatus close() override;
    ndk::ScopedAStatus reopen(
            ::aidl::android::hardware::audio::effect::IEffect::OpenEffectReturn* ret) override;
    ndk::ScopedAStatus getDescriptor(
            ::aidl::android::hardware::audio::effect::Descriptor* desc) override;
    ndk::ScopedAStatus command(::aidl::android::hardware::audio::effect::CommandId id) override;
Loading