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

Commit 3035c98d authored by Shunkai Yao's avatar Shunkai Yao Committed by Android (Google) Code Review
Browse files

Merge "Audio effect aidl log reduce and level adjust" into 24D1-dev

parents 2ff1f0a2 dd43b56f
Loading
Loading
Loading
Loading
+7 −9
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@ namespace aidl::android::hardware::audio::effect {
EffectConfig::EffectConfig(const std::string& file) {
EffectConfig::EffectConfig(const std::string& file) {
    tinyxml2::XMLDocument doc;
    tinyxml2::XMLDocument doc;
    doc.LoadFile(file.c_str());
    doc.LoadFile(file.c_str());
    LOG(DEBUG) << __func__ << " loading " << file;
    // parse the xml file into maps
    // parse the xml file into maps
    if (doc.Error()) {
    if (doc.Error()) {
        LOG(ERROR) << __func__ << " tinyxml2 failed to load " << file
        LOG(ERROR) << __func__ << " tinyxml2 failed to load " << file
@@ -143,7 +142,7 @@ bool EffectConfig::parseEffect(const tinyxml2::XMLElement& xml) {
    std::string name = xml.Attribute("name");
    std::string name = xml.Attribute("name");
    RETURN_VALUE_IF(name == "", false, "effectsNoName");
    RETURN_VALUE_IF(name == "", false, "effectsNoName");


    LOG(DEBUG) << __func__ << dump(xml);
    LOG(VERBOSE) << __func__ << dump(xml);
    struct Library library;
    struct Library library;
    if (std::strcmp(xml.Name(), "effectProxy") == 0) {
    if (std::strcmp(xml.Name(), "effectProxy") == 0) {
        // proxy lib and uuid
        // proxy lib and uuid
@@ -187,7 +186,7 @@ bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml, struct Library&
    }
    }
    RETURN_VALUE_IF((library.uuid == getEffectUuidZero()), false, "invalidUuidAttribute");
    RETURN_VALUE_IF((library.uuid == getEffectUuidZero()), false, "invalidUuidAttribute");


    LOG(DEBUG) << __func__ << (isProxy ? " proxy " : library.name) << " : uuid "
    LOG(VERBOSE) << __func__ << (isProxy ? " proxy " : library.name) << " : uuid "
                 << ::android::audio::utils::toString(library.uuid)
                 << ::android::audio::utils::toString(library.uuid)
                 << (library.type.has_value()
                 << (library.type.has_value()
                             ? ::android::audio::utils::toString(library.type.value())
                             ? ::android::audio::utils::toString(library.type.value())
@@ -245,7 +244,7 @@ std::optional<Processing::Type> EffectConfig::stringToProcessingType(Processing:
}
}


bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml) {
bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml) {
    LOG(DEBUG) << __func__ << dump(xml);
    LOG(VERBOSE) << __func__ << dump(xml);
    const char* typeStr = xml.Attribute("type");
    const char* typeStr = xml.Attribute("type");
    auto aidlType = stringToProcessingType(typeTag, typeStr);
    auto aidlType = stringToProcessingType(typeTag, typeStr);
    RETURN_VALUE_IF(!aidlType.has_value(), false, "illegalStreamType");
    RETURN_VALUE_IF(!aidlType.has_value(), false, "illegalStreamType");
@@ -259,7 +258,6 @@ bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2
        }
        }
        RETURN_VALUE_IF(!name, false, "noEffectAttribute");
        RETURN_VALUE_IF(!name, false, "noEffectAttribute");
        mProcessingMap[aidlType.value()].emplace_back(mEffectsMap[name]);
        mProcessingMap[aidlType.value()].emplace_back(mEffectsMap[name]);
        LOG(WARNING) << __func__ << " " << typeStr << " : " << name;
    }
    }
    return true;
    return true;
}
}
+1 −3
Original line number Original line Diff line number Diff line
@@ -157,7 +157,6 @@ Parameter::VolumeStereo EffectContext::getVolumeStereo() {
}
}


RetCode EffectContext::setCommon(const Parameter::Common& common) {
RetCode EffectContext::setCommon(const Parameter::Common& common) {
    LOG(VERBOSE) << __func__ << common.toString();
    auto& input = common.input;
    auto& input = common.input;
    auto& output = common.output;
    auto& output = common.output;


@@ -186,7 +185,6 @@ RetCode EffectContext::setCommon(const Parameter::Common& common) {
}
}


Parameter::Common EffectContext::getCommon() {
Parameter::Common EffectContext::getCommon() {
    LOG(VERBOSE) << __func__ << mCommon.toString();
    return mCommon;
    return mCommon;
}
}


@@ -241,7 +239,7 @@ RetCode EffectContext::notifyDataMqUpdate() {
        LOG(ERROR) << __func__ << ": wake failure with ret " << ret;
        LOG(ERROR) << __func__ << ": wake failure with ret " << ret;
        return RetCode::ERROR_EVENT_FLAG_ERROR;
        return RetCode::ERROR_EVENT_FLAG_ERROR;
    }
    }
    LOG(DEBUG) << __func__ << " : signal client for reopen";
    LOG(VERBOSE) << __func__ << " : signal client for reopen";
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}
}  // namespace aidl::android::hardware::audio::effect
}  // namespace aidl::android::hardware::audio::effect
+15 −16
Original line number Original line Diff line number Diff line
@@ -43,11 +43,11 @@ Factory::Factory(const std::string& file) : mConfig(EffectConfig(file)) {


Factory::~Factory() {
Factory::~Factory() {
    if (auto count = mEffectMap.size()) {
    if (auto count = mEffectMap.size()) {
        LOG(ERROR) << __func__ << " remaining " << count
        LOG(WARNING) << __func__ << " remaining " << count
                     << " effect instances not destroyed indicating resource leak!";
                     << " effect instances not destroyed indicating resource leak!";
        for (const auto& it : mEffectMap) {
        for (const auto& it : mEffectMap) {
            if (auto spEffect = it.first.lock()) {
            if (auto spEffect = it.first.lock()) {
                LOG(ERROR) << __func__ << " erase remaining instance UUID "
                LOG(WARNING) << __func__ << " erase remaining instance UUID "
                             << ::android::audio::utils::toString(it.second.first);
                             << ::android::audio::utils::toString(it.second.first);
                destroyEffectImpl_l(spEffect);
                destroyEffectImpl_l(spEffect);
            }
            }
@@ -139,7 +139,7 @@ ndk::ScopedAStatus Factory::createEffect(const AudioUuid& in_impl_uuid,
        std::shared_ptr<IEffect> effectSp;
        std::shared_ptr<IEffect> effectSp;
        RETURN_IF_BINDER_EXCEPTION(libInterface->createEffectFunc(&in_impl_uuid, &effectSp));
        RETURN_IF_BINDER_EXCEPTION(libInterface->createEffectFunc(&in_impl_uuid, &effectSp));
        if (!effectSp) {
        if (!effectSp) {
            LOG(ERROR) << __func__ << ": library created null instance without return error!";
            LOG(WARNING) << __func__ << ": library created null instance without return error!";
            return ndk::ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED);
            return ndk::ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED);
        }
        }
        *_aidl_return = effectSp;
        *_aidl_return = effectSp;
@@ -147,7 +147,6 @@ ndk::ScopedAStatus Factory::createEffect(const AudioUuid& in_impl_uuid,
        AIBinder_setMinSchedulerPolicy(effectBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
        AIBinder_setMinSchedulerPolicy(effectBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
        mEffectMap[std::weak_ptr<IEffect>(effectSp)] =
        mEffectMap[std::weak_ptr<IEffect>(effectSp)] =
                std::make_pair(in_impl_uuid, std::move(effectBinder));
                std::make_pair(in_impl_uuid, std::move(effectBinder));
        LOG(DEBUG) << __func__ << ": instance " << effectSp.get() << " created successfully";
        return ndk::ScopedAStatus::ok();
        return ndk::ScopedAStatus::ok();
    } else {
    } else {
        LOG(ERROR) << __func__ << ": library doesn't exist";
        LOG(ERROR) << __func__ << ": library doesn't exist";
@@ -192,7 +191,6 @@ void Factory::cleanupEffectMap_l() {
}
}


ndk::ScopedAStatus Factory::destroyEffect(const std::shared_ptr<IEffect>& in_handle) {
ndk::ScopedAStatus Factory::destroyEffect(const std::shared_ptr<IEffect>& in_handle) {
    LOG(DEBUG) << __func__ << ": instance " << in_handle.get();
    std::lock_guard lg(mMutex);
    std::lock_guard lg(mMutex);
    ndk::ScopedAStatus status = destroyEffectImpl_l(in_handle);
    ndk::ScopedAStatus status = destroyEffectImpl_l(in_handle);
    // always do the cleanup
    // always do the cleanup
@@ -215,7 +213,7 @@ bool Factory::openEffectLibrary(const AudioUuid& impl,
        return false;
        return false;
    }
    }


    LOG(INFO) << __func__ << " dlopen lib:" << path
    LOG(DEBUG) << __func__ << " dlopen lib: " << path
               << "\nimpl:" << ::android::audio::utils::toString(impl) << "\nhandle:" << libHandle;
               << "\nimpl:" << ::android::audio::utils::toString(impl) << "\nhandle:" << libHandle;
    auto interface = new effect_dl_interface_s{nullptr, nullptr, nullptr};
    auto interface = new effect_dl_interface_s{nullptr, nullptr, nullptr};
    mEffectLibMap.insert(
    mEffectLibMap.insert(
@@ -235,10 +233,11 @@ void Factory::createIdentityWithConfig(
        id.type = typeUuid;
        id.type = typeUuid;
        id.uuid = configLib.uuid;
        id.uuid = configLib.uuid;
        id.proxy = proxyUuid;
        id.proxy = proxyUuid;
        LOG(DEBUG) << __func__ << " loading lib " << path->second << ": typeUuid "
        LOG(WARNING) << __func__ << " loading lib " << path->second << ": typeUuid "
                     << ::android::audio::utils::toString(id.type) << "\nimplUuid "
                     << ::android::audio::utils::toString(id.type) << "\nimplUuid "
                     << ::android::audio::utils::toString(id.uuid) << " proxyUuid "
                     << ::android::audio::utils::toString(id.uuid) << " proxyUuid "
                   << (proxyUuid.has_value() ? ::android::audio::utils::toString(proxyUuid.value())
                     << (proxyUuid.has_value()
                                 ? ::android::audio::utils::toString(proxyUuid.value())
                                 : "null");
                                 : "null");
        if (openEffectLibrary(id.uuid, path->second)) {
        if (openEffectLibrary(id.uuid, path->second)) {
            mIdentitySet.insert(std::move(id));
            mIdentitySet.insert(std::move(id));
@@ -263,8 +262,8 @@ void Factory::loadEffectLibs() {
                createIdentityWithConfig(configLib, type, proxyUuid);
                createIdentityWithConfig(configLib, type, proxyUuid);
            }
            }
        } else {
        } else {
            LOG(ERROR) << __func__ << ": can not find type UUID for effect " << configEffects.first
            LOG(WARNING) << __func__ << ": can not find type UUID for effect "
                       << " skipping!";
                         << configEffects.first << " skipping!";
        }
        }
    }
    }
}
}
+6 −11
Original line number Original line Diff line number Diff line
@@ -35,7 +35,6 @@ extern "C" binder_exception_t destroyEffect(const std::shared_ptr<IEffect>& inst
                   << " in state: " << toString(state) << ", status: " << status.getDescription();
                   << " in state: " << toString(state) << ", status: " << status.getDescription();
        return EX_ILLEGAL_STATE;
        return EX_ILLEGAL_STATE;
    }
    }
    LOG(DEBUG) << __func__ << " instance " << instanceSp.get() << " destroyed";
    return EX_NONE;
    return EX_NONE;
}
}


@@ -91,7 +90,7 @@ ndk::ScopedAStatus EffectImpl::close() {
    }
    }


    RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
    RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
              "notifyEventFlagFailed");
              "notifyEventFlagNotEmptyFailed");
    // stop the worker thread, ignore the return code
    // stop the worker thread, ignore the return code
    RETURN_IF(destroyThread() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION,
    RETURN_IF(destroyThread() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION,
              "FailedToDestroyWorker");
              "FailedToDestroyWorker");
@@ -231,8 +230,6 @@ ndk::ScopedAStatus EffectImpl::getState(State* state) NO_THREAD_SAFETY_ANALYSIS
ndk::ScopedAStatus EffectImpl::command(CommandId command) {
ndk::ScopedAStatus EffectImpl::command(CommandId command) {
    std::lock_guard lg(mImplMutex);
    std::lock_guard lg(mImplMutex);
    RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "instanceNotOpen");
    RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "instanceNotOpen");
    LOG(DEBUG) << getEffectName() << __func__ << ": receive command: " << toString(command)
               << " at state " << toString(mState);


    switch (command) {
    switch (command) {
        case CommandId::START:
        case CommandId::START:
@@ -240,7 +237,7 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) {
            RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed");
            RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed");
            mState = State::PROCESSING;
            mState = State::PROCESSING;
            RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
            RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
                      "notifyEventFlagFailed");
                      "notifyEventFlagNotEmptyFailed");
            startThread();
            startThread();
            break;
            break;
        case CommandId::STOP:
        case CommandId::STOP:
@@ -248,7 +245,7 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) {
            RETURN_OK_IF(mState == State::IDLE);
            RETURN_OK_IF(mState == State::IDLE);
            mState = State::IDLE;
            mState = State::IDLE;
            RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
            RETURN_IF(notifyEventFlag(kEventFlagNotEmpty) != RetCode::SUCCESS, EX_ILLEGAL_STATE,
                      "notifyEventFlagFailed");
                      "notifyEventFlagNotEmptyFailed");
            stopThread();
            stopThread();
            RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed");
            RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed");
            break;
            break;
@@ -257,7 +254,7 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) {
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "CommandIdNotSupported");
                                                                    "CommandIdNotSupported");
    }
    }
    LOG(DEBUG) << getEffectName() << __func__ << " transfer to state: " << toString(mState);
    LOG(VERBOSE) << getEffectName() << __func__ << " transfer to state: " << toString(mState);
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::ok();
}
}


@@ -294,6 +291,7 @@ RetCode EffectImpl::notifyEventFlag(uint32_t flag) {
        LOG(ERROR) << getEffectName() << __func__ << ": wake failure with ret " << ret;
        LOG(ERROR) << getEffectName() << __func__ << ": wake failure with ret " << ret;
        return RetCode::ERROR_EVENT_FLAG_ERROR;
        return RetCode::ERROR_EVENT_FLAG_ERROR;
    }
    }
    LOG(VERBOSE) << getEffectName() << __func__ << ": " << std::hex << mEventFlag;
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}


@@ -306,7 +304,7 @@ IEffect::Status EffectImpl::status(binder_status_t status, size_t consumed, size
}
}


void EffectImpl::process() {
void EffectImpl::process() {
    ATRACE_CALL();
    ATRACE_NAME(getEffectName().c_str());
    /**
    /**
     * wait for the EventFlag without lock, it's ok because the mEfGroup pointer will not change
     * wait for the EventFlag without lock, it's ok because the mEfGroup pointer will not change
     * in the life cycle of workerThread (threadLoop).
     * in the life cycle of workerThread (threadLoop).
@@ -344,8 +342,6 @@ void EffectImpl::process() {
            IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
            IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
            outputMQ->write(buffer, status.fmqProduced);
            outputMQ->write(buffer, status.fmqProduced);
            statusMQ->writeBlocking(&status, 1);
            statusMQ->writeBlocking(&status, 1);
            LOG(VERBOSE) << getEffectName() << __func__ << ": done processing, effect consumed "
                         << status.fmqConsumed << " produced " << status.fmqProduced;
        }
        }
    }
    }
}
}
@@ -355,7 +351,6 @@ IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int samples
    for (int i = 0; i < samples; i++) {
    for (int i = 0; i < samples; i++) {
        *out++ = *in++;
        *out++ = *in++;
    }
    }
    LOG(VERBOSE) << getEffectName() << __func__ << " done processing " << samples << " samples";
    return {STATUS_OK, samples, samples};
    return {STATUS_OK, samples, samples};
}
}


+5 −10
Original line number Original line Diff line number Diff line
@@ -27,13 +27,8 @@


namespace aidl::android::hardware::audio::effect {
namespace aidl::android::hardware::audio::effect {


EffectThread::EffectThread() {
    LOG(DEBUG) << __func__;
}

EffectThread::~EffectThread() {
EffectThread::~EffectThread() {
    destroyThread();
    destroyThread();
    LOG(DEBUG) << __func__ << " done";
}
}


RetCode EffectThread::createThread(const std::string& name, int priority) {
RetCode EffectThread::createThread(const std::string& name, int priority) {
@@ -51,7 +46,7 @@ RetCode EffectThread::createThread(const std::string& name, int priority) {
    }
    }


    mThread = std::thread(&EffectThread::threadLoop, this);
    mThread = std::thread(&EffectThread::threadLoop, this);
    LOG(DEBUG) << mName << __func__ << " priority " << mPriority << " done";
    LOG(VERBOSE) << mName << __func__ << " priority " << mPriority << " done";
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}


@@ -66,7 +61,7 @@ RetCode EffectThread::destroyThread() {
        mThread.join();
        mThread.join();
    }
    }


    LOG(DEBUG) << mName << __func__;
    LOG(VERBOSE) << mName << __func__;
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}


@@ -77,7 +72,7 @@ RetCode EffectThread::startThread() {
        mCv.notify_one();
        mCv.notify_one();
    }
    }


    LOG(DEBUG) << mName << __func__;
    LOG(VERBOSE) << mName << __func__;
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}


@@ -88,7 +83,7 @@ RetCode EffectThread::stopThread() {
        mCv.notify_one();
        mCv.notify_one();
    }
    }


    LOG(DEBUG) << mName << __func__;
    LOG(VERBOSE) << mName << __func__;
    return RetCode::SUCCESS;
    return RetCode::SUCCESS;
}
}


@@ -101,7 +96,7 @@ void EffectThread::threadLoop() {
            ::android::base::ScopedLockAssertion lock_assertion(mThreadMutex);
            ::android::base::ScopedLockAssertion lock_assertion(mThreadMutex);
            mCv.wait(l, [&]() REQUIRES(mThreadMutex) { return mExit || !mStop; });
            mCv.wait(l, [&]() REQUIRES(mThreadMutex) { return mExit || !mStop; });
            if (mExit) {
            if (mExit) {
                LOG(INFO) << __func__ << " EXIT!";
                LOG(VERBOSE) << mName << " threadLoop EXIT!";
                return;
                return;
            }
            }
        }
        }
Loading