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

Commit f8be1acd authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Update EffectUUID initialization

Avoid dynamic initialization global UUID variables

Bug: 271500140
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: I7574c1fe1ba0aaff1d9d29a9eed10de1aef33806
parent 1120ee56
Loading
Loading
Loading
Loading
+42 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


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


#include "effectFactory-impl/EffectConfig.h"
#include "effectFactory-impl/EffectConfig.h"


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


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


    LOG(DEBUG) << __func__ << (isProxy ? " proxy " : libraryUuid.name) << " : "
    LOG(DEBUG) << __func__ << (isProxy ? " proxy " : libraryUuid.name) << " : "
               << libraryUuid.uuid.toString();
               << libraryUuid.uuid.toString();
    return true;
    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,
const char* EffectConfig::dump(const tinyxml2::XMLElement& element,
                               tinyxml2::XMLPrinter&& printer) const {
                               tinyxml2::XMLPrinter&& printer) const {
    element.Accept(&printer);
    element.Accept(&printer);
+6 −7
Original line number Original line Diff line number Diff line
@@ -14,20 +14,19 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


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


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


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


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


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


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


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


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


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


    switch (command) {
    switch (command) {
        case CommandId::START:
        case CommandId::START:
@@ -217,11 +219,11 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) {
            mState = State::IDLE;
            mState = State::IDLE;
            break;
            break;
        default:
        default:
            LOG(ERROR) << __func__ << " instance still processing";
            LOG(ERROR) << getEffectName() << __func__ << " instance still processing";
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "CommandIdNotSupported");
                                                                    "CommandIdNotSupported");
    }
    }
    LOG(DEBUG) << __func__ << " transfer to state: " << toString(mState);
    LOG(DEBUG) << getEffectName() << __func__ << " transfer to state: " << toString(mState);
    return ndk::ScopedAStatus::ok();
    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++) {
    for (int i = 0; i < samples; i++) {
        *out++ = *in++;
        *out++ = *in++;
    }
    }
    LOG(DEBUG) << __func__ << " done processing " << samples << " samples";
    LOG(DEBUG) << getEffectName() << __func__ << " done processing " << samples << " samples";
    return {STATUS_OK, samples, samples};
    return {STATUS_OK, samples, samples};
}
}


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


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


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


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


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


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


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


        inputMQ->read(buffer, processSamples);
        inputMQ->read(buffer, processSamples);


        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(DEBUG) << __func__ << " done processing, effect consumed " << status.fmqConsumed
        LOG(DEBUG) << "-" << mName << "-" << __func__ << ": "
                   << " produced " << status.fmqProduced;
                   << " done processing, effect consumed " << status.fmqConsumed << " produced "
                   << status.fmqProduced;
    } else {
    } else {
        usleep(mSleepTimeUs);
        usleep(mSleepTimeUs);
    }
    }
+7 −5
Original line number Original line Diff line number Diff line
@@ -22,19 +22,21 @@
#define LOG_TAG "AHAL_AcousticEchoCancelerSw"
#define LOG_TAG "AHAL_AcousticEchoCancelerSw"
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <fmq/AidlMessageQueue.h>
#include <fmq/AidlMessageQueue.h>
#include <system/audio_effects/effect_uuid.h>


#include "AcousticEchoCancelerSw.h"
#include "AcousticEchoCancelerSw.h"


using aidl::android::hardware::audio::effect::AcousticEchoCancelerSw;
using aidl::android::hardware::audio::effect::AcousticEchoCancelerSw;
using aidl::android::hardware::audio::effect::Descriptor;
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::IEffect;
using aidl::android::hardware::audio::effect::kAcousticEchoCancelerSwImplUUID;
using aidl::android::hardware::audio::effect::Range;
using aidl::android::hardware::audio::effect::Range;
using aidl::android::media::audio::common::AudioUuid;
using aidl::android::media::audio::common::AudioUuid;


extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
                                           std::shared_ptr<IEffect>* instanceSpp) {
                                           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";
        LOG(ERROR) << __func__ << "uuid not supported";
        return EX_ILLEGAL_ARGUMENT;
        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) {
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";
        LOG(ERROR) << __func__ << "uuid not supported";
        return EX_ILLEGAL_ARGUMENT;
        return EX_ILLEGAL_ARGUMENT;
    }
    }
@@ -69,8 +71,8 @@ const std::vector<Range::AcousticEchoCancelerRange> AcousticEchoCancelerSw::kRan
const Capability AcousticEchoCancelerSw::kCapability = {.range = AcousticEchoCancelerSw::kRanges};
const Capability AcousticEchoCancelerSw::kCapability = {.range = AcousticEchoCancelerSw::kRanges};


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