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

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

Merge "Update EffectUUID initialization"

parents d0c02789 f8be1acd
Loading
Loading
Loading
Loading
+42 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#define LOG_TAG "AHAL_EffectConfig"
#include <android-base/logging.h>
#include <system/audio_effects/effect_uuid.h>

#include "effectFactory-impl/EffectConfig.h"

@@ -163,15 +164,53 @@ bool EffectConfig::parseLibraryUuid(const tinyxml2::XMLElement& xml,
        libraryUuid.name = name;
    }

    const char* uuid = xml.Attribute("uuid");
    RETURN_VALUE_IF(!uuid, false, "noUuidAttribute");
    RETURN_VALUE_IF(!stringToUuid(uuid, &libraryUuid.uuid), false, "invalidUuidAttribute");
    const char* uuidStr = xml.Attribute("uuid");
    RETURN_VALUE_IF(!uuidStr, false, "noUuidAttribute");
    libraryUuid.uuid = stringToUuid(uuidStr);
    RETURN_VALUE_IF((libraryUuid.uuid == getEffectUuidZero()), false, "invalidUuidAttribute");

    LOG(DEBUG) << __func__ << (isProxy ? " proxy " : libraryUuid.name) << " : "
               << libraryUuid.uuid.toString();
    return true;
}

bool EffectConfig::findUuid(const std::string& xmlEffectName, AudioUuid* uuid) {
// Difference from EFFECT_TYPE_LIST_DEF, there could be multiple name mapping to same Effect Type
#define EFFECT_XML_TYPE_LIST_DEF(V)                        \
    V("acoustic_echo_canceler", AcousticEchoCanceler)      \
    V("automatic_gain_control_v1", AutomaticGainControlV1) \
    V("automatic_gain_control_v2", AutomaticGainControlV2) \
    V("bassboost", BassBoost)                              \
    V("downmix", Downmix)                                  \
    V("dynamics_processing", DynamicsProcessing)           \
    V("equalizer", Equalizer)                              \
    V("haptic_generator", HapticGenerator)                 \
    V("loudness_enhancer", LoudnessEnhancer)               \
    V("env_reverb", EnvReverb)                             \
    V("reverb_env_aux", EnvReverb)                         \
    V("reverb_env_ins", EnvReverb)                         \
    V("preset_reverb", PresetReverb)                       \
    V("reverb_pre_aux", PresetReverb)                      \
    V("reverb_pre_ins", PresetReverb)                      \
    V("noise_suppression", NoiseSuppression)               \
    V("spatializer", Spatializer)                          \
    V("virtualizer", Virtualizer)                          \
    V("visualizer", Visualizer)                            \
    V("volume", Volume)

#define GENERATE_MAP_ENTRY_V(s, symbol) {s, &getEffectTypeUuid##symbol},

    typedef const AudioUuid& (*UuidGetter)(void);
    static const std::map<std::string, UuidGetter> uuidMap{
            // std::make_pair("s", &getEffectTypeUuidExtension)};
            {EFFECT_XML_TYPE_LIST_DEF(GENERATE_MAP_ENTRY_V)}};
    if (auto it = uuidMap.find(xmlEffectName); it != uuidMap.end()) {
        *uuid = (*it->second)();
        return true;
    }
    return false;
}

const char* EffectConfig::dump(const tinyxml2::XMLElement& element,
                               tinyxml2::XMLPrinter&& printer) const {
    element.Accept(&printer);
+6 −7
Original line number Diff line number Diff line
@@ -14,20 +14,19 @@
 * limitations under the License.
 */

#include <dlfcn.h>
#include <iterator>
#include <memory>
#include <tuple>
#include "include/effect-impl/EffectTypes.h"
#define LOG_TAG "AHAL_EffectFactory"
#include <dlfcn.h>
#include <unordered_set>
#define LOG_TAG "AHAL_EffectFactory"

#include <android-base/logging.h>
#include <android/binder_ibinder_platform.h>
#include <system/audio_effects/effect_uuid.h>
#include <system/thread_defs.h>

#include "effect-impl/EffectTypes.h"
#include "effect-impl/EffectUUID.h"
#include "effectFactory-impl/EffectFactory.h"

using aidl::android::media::audio::common::AudioUuid;
@@ -214,8 +213,8 @@ void Factory::createIdentityWithConfig(const EffectConfig::LibraryUuid& configLi
void Factory::loadEffectLibs() {
    const auto& configEffectsMap = mConfig.getEffectsMap();
    for (const auto& configEffects : configEffectsMap) {
        if (auto typeUuid = kUuidNameTypeMap.find(configEffects.first /* effect name */);
            typeUuid != kUuidNameTypeMap.end()) {
        if (AudioUuid uuid;
            EffectConfig::findUuid(configEffects.first /* xml effect name */, &uuid)) {
            const auto& configLibs = configEffects.second;
            std::optional<AudioUuid> proxyUuid;
            if (configLibs.proxyLibrary.has_value()) {
@@ -223,7 +222,7 @@ void Factory::loadEffectLibs() {
                proxyUuid = proxyLib.uuid;
            }
            for (const auto& configLib : configLibs.libraries) {
                createIdentityWithConfig(configLib, typeUuid->second, proxyUuid);
                createIdentityWithConfig(configLib, uuid, proxyUuid);
            }
        } else {
            LOG(ERROR) << __func__ << ": can not find type UUID for effect " << configEffects.first
+15 −13
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ namespace aidl::android::hardware::audio::effect {
ndk::ScopedAStatus EffectImpl::open(const Parameter::Common& common,
                                    const std::optional<Parameter::Specific>& specific,
                                    OpenEffectReturn* ret) {
    LOG(DEBUG) << __func__;
    LOG(DEBUG) << getEffectName() << __func__;
    // effect only support 32bits float
    RETURN_IF(common.input.base.format.pcm != common.output.base.format.pcm ||
                      common.input.base.format.pcm != PcmType::FLOAT_32_BIT,
@@ -71,12 +71,12 @@ ndk::ScopedAStatus EffectImpl::close() {
    RETURN_IF(releaseContext() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION,
              "FailedToCreateWorker");

    LOG(DEBUG) << __func__;
    LOG(DEBUG) << getEffectName() << __func__;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus EffectImpl::setParameter(const Parameter& param) {
    LOG(DEBUG) << __func__ << " with: " << param.toString();
    LOG(DEBUG) << getEffectName() << __func__ << " with: " << param.toString();

    const auto tag = param.getTag();
    switch (tag) {
@@ -91,7 +91,8 @@ ndk::ScopedAStatus EffectImpl::setParameter(const Parameter& param) {
            return setParameterSpecific(param.get<Parameter::specific>());
        }
        default: {
            LOG(ERROR) << __func__ << " unsupportedParameterTag " << toString(tag);
            LOG(ERROR) << getEffectName() << __func__ << " unsupportedParameterTag "
                       << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "ParameterNotSupported");
        }
@@ -99,7 +100,7 @@ ndk::ScopedAStatus EffectImpl::setParameter(const Parameter& param) {
}

ndk::ScopedAStatus EffectImpl::getParameter(const Parameter::Id& id, Parameter* param) {
    LOG(DEBUG) << __func__ << id.toString();
    LOG(DEBUG) << getEffectName() << __func__ << id.toString();
    auto tag = id.getTag();
    switch (tag) {
        case Parameter::Id::commonTag: {
@@ -116,7 +117,7 @@ ndk::ScopedAStatus EffectImpl::getParameter(const Parameter::Id& id, Parameter*
            break;
        }
    }
    LOG(DEBUG) << __func__ << param->toString();
    LOG(DEBUG) << getEffectName() << __func__ << param->toString();
    return ndk::ScopedAStatus::ok();
}

@@ -149,7 +150,8 @@ ndk::ScopedAStatus EffectImpl::setParameterCommon(const Parameter& param) {
                      EX_ILLEGAL_ARGUMENT, "setVolumeStereoFailed");
            break;
        default: {
            LOG(ERROR) << __func__ << " unsupportedParameterTag " << toString(tag);
            LOG(ERROR) << getEffectName() << __func__ << " unsupportedParameterTag "
                       << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "commonParamNotSupported");
        }
@@ -183,7 +185,7 @@ ndk::ScopedAStatus EffectImpl::getParameterCommon(const Parameter::Tag& tag, Par
            break;
        }
        default: {
            LOG(DEBUG) << __func__ << " unsupported tag " << toString(tag);
            LOG(DEBUG) << getEffectName() << __func__ << " unsupported tag " << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "tagNotSupported");
        }
@@ -198,8 +200,8 @@ ndk::ScopedAStatus EffectImpl::getState(State* state) {

ndk::ScopedAStatus EffectImpl::command(CommandId command) {
    RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "CommandStateError");
    LOG(DEBUG) << __func__ << ": receive command: " << toString(command) << " at state "
               << toString(mState);
    LOG(DEBUG) << getEffectName() << __func__ << ": receive command: " << toString(command)
               << " at state " << toString(mState);

    switch (command) {
        case CommandId::START:
@@ -217,11 +219,11 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) {
            mState = State::IDLE;
            break;
        default:
            LOG(ERROR) << __func__ << " instance still processing";
            LOG(ERROR) << getEffectName() << __func__ << " instance still processing";
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "CommandIdNotSupported");
    }
    LOG(DEBUG) << __func__ << " transfer to state: " << toString(mState);
    LOG(DEBUG) << getEffectName() << __func__ << " transfer to state: " << toString(mState);
    return ndk::ScopedAStatus::ok();
}

@@ -252,7 +254,7 @@ IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int samples
    for (int i = 0; i < samples; i++) {
        *out++ = *in++;
    }
    LOG(DEBUG) << __func__ << " done processing " << samples << " samples";
    LOG(DEBUG) << getEffectName() << __func__ << " done processing " << samples << " samples";
    return {STATUS_OK, samples, samples};
}

+14 −10
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ EffectThread::~EffectThread() {
RetCode EffectThread::createThread(std::shared_ptr<EffectContext> context, const std::string& name,
                                   int priority, int sleepUs /* kSleepTimeUs */) {
    if (mThread.joinable()) {
        LOG(WARNING) << __func__ << " thread already created, no-op";
        LOG(WARNING) << "-" << mName << "-" << __func__ << " thread already created, no-op";
        return RetCode::SUCCESS;
    }
    mName = name;
@@ -47,7 +47,7 @@ RetCode EffectThread::createThread(std::shared_ptr<EffectContext> context, const
        mThreadContext = std::move(context);
    }
    mThread = std::thread(&EffectThread::threadLoop, this);
    LOG(DEBUG) << __func__ << " " << name << " priority " << mPriority << " done";
    LOG(DEBUG) << "-" << mName << "-" << __func__ << " priority " << mPriority << " done";
    return RetCode::SUCCESS;
}

@@ -66,7 +66,7 @@ RetCode EffectThread::destroyThread() {
        std::lock_guard lg(mThreadMutex);
        mThreadContext.reset();
    }
    LOG(DEBUG) << __func__ << " done";
    LOG(DEBUG) << "-" << mName << "-" << __func__ << " done";
    return RetCode::SUCCESS;
}

@@ -80,21 +80,23 @@ RetCode EffectThread::stopThread() {

RetCode EffectThread::handleStartStop(bool stop) {
    if (!mThread.joinable()) {
        LOG(ERROR) << __func__ << " thread already destroyed";
        LOG(ERROR) << "-" << mName << "-" << __func__ << ": "
                   << " thread already destroyed";
        return RetCode::ERROR_THREAD;
    }

    {
        std::lock_guard lg(mThreadMutex);
        if (stop == mStop) {
            LOG(WARNING) << __func__ << " already " << (stop ? "stop" : "start");
            LOG(WARNING) << "-" << mName << "-" << __func__ << ": "
                         << " already " << (stop ? "stop" : "start");
            return RetCode::SUCCESS;
        }
        mStop = stop;
    }

    mCv.notify_one();
    LOG(DEBUG) << (stop ? "stop done" : "start done");
    LOG(DEBUG) << ": " << mName << (stop ? " stop done" : " start done");
    return RetCode::SUCCESS;
}

@@ -124,16 +126,18 @@ void EffectThread::process_l() {
    auto readSamples = inputMQ->availableToRead(), writeSamples = outputMQ->availableToWrite();
    if (readSamples && writeSamples) {
        auto processSamples = std::min(readSamples, writeSamples);
        LOG(DEBUG) << __func__ << " available to read " << readSamples << " available to write "
                   << writeSamples << " process " << processSamples;
        LOG(DEBUG) << "-" << mName << "-" << __func__ << ": "
                   << " available to read " << readSamples << " available to write " << writeSamples
                   << " process " << processSamples;

        inputMQ->read(buffer, processSamples);

        IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
        outputMQ->write(buffer, status.fmqProduced);
        statusMQ->writeBlocking(&status, 1);
        LOG(DEBUG) << __func__ << " done processing, effect consumed " << status.fmqConsumed
                   << " produced " << status.fmqProduced;
        LOG(DEBUG) << "-" << mName << "-" << __func__ << ": "
                   << " done processing, effect consumed " << status.fmqConsumed << " produced "
                   << status.fmqProduced;
    } else {
        usleep(mSleepTimeUs);
    }
+7 −5
Original line number Diff line number Diff line
@@ -22,19 +22,21 @@
#define LOG_TAG "AHAL_AcousticEchoCancelerSw"
#include <android-base/logging.h>
#include <fmq/AidlMessageQueue.h>
#include <system/audio_effects/effect_uuid.h>

#include "AcousticEchoCancelerSw.h"

using aidl::android::hardware::audio::effect::AcousticEchoCancelerSw;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::getEffectImplUuidAcousticEchoCancelerSw;
using aidl::android::hardware::audio::effect::getEffectTypeUuidAcousticEchoCanceler;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::kAcousticEchoCancelerSwImplUUID;
using aidl::android::hardware::audio::effect::Range;
using aidl::android::media::audio::common::AudioUuid;

extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
                                           std::shared_ptr<IEffect>* instanceSpp) {
    if (!in_impl_uuid || *in_impl_uuid != kAcousticEchoCancelerSwImplUUID) {
    if (!in_impl_uuid || *in_impl_uuid != getEffectImplUuidAcousticEchoCancelerSw()) {
        LOG(ERROR) << __func__ << "uuid not supported";
        return EX_ILLEGAL_ARGUMENT;
    }
@@ -49,7 +51,7 @@ extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
}

extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descriptor* _aidl_return) {
    if (!in_impl_uuid || *in_impl_uuid != kAcousticEchoCancelerSwImplUUID) {
    if (!in_impl_uuid || *in_impl_uuid != getEffectImplUuidAcousticEchoCancelerSw()) {
        LOG(ERROR) << __func__ << "uuid not supported";
        return EX_ILLEGAL_ARGUMENT;
    }
@@ -69,8 +71,8 @@ const std::vector<Range::AcousticEchoCancelerRange> AcousticEchoCancelerSw::kRan
const Capability AcousticEchoCancelerSw::kCapability = {.range = AcousticEchoCancelerSw::kRanges};

const Descriptor AcousticEchoCancelerSw::kDescriptor = {
        .common = {.id = {.type = kAcousticEchoCancelerTypeUUID,
                          .uuid = kAcousticEchoCancelerSwImplUUID,
        .common = {.id = {.type = getEffectTypeUuidAcousticEchoCanceler(),
                          .uuid = getEffectImplUuidAcousticEchoCancelerSw(),
                          .proxy = std::nullopt},
                   .flags = {.type = Flags::Type::INSERT,
                             .insert = Flags::Insert::FIRST,
Loading