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

Commit be04a8d5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[AIDL CTS] pass EnvReverb implementation cts" am: 1f772bf9

parents f2017ff6 1f772bf9
Loading
Loading
Loading
Loading
+122 −71
Original line number Diff line number Diff line
@@ -43,157 +43,208 @@ using ::android::status_t;
using utils::EffectParamReader;
using utils::EffectParamWriter;

#define MAKE_AIDL_PARAMETER(aidlParam, param, value, tag)                            \
/**
 * Macro to get a parameter from effect_param_t wrapper and set it to AIDL effect.
 *
 * Return if there is any error, otherwise continue execution.
 *
 * @param param EffectParamReader, a reader wrapper of effect_param_t.
 * @param aidlType Type of the AIDL parameter field, used to construct AIDL Parameter union.
 * @param valueType Type of the value get from effect_param_t.
 * @param tag The AIDL parameter union field tag.
 */
#define SET_AIDL_PARAMETER(param, aidlType, valueType, tag)                                \
    {                                                                                      \
        if (OK != param.readFromValue(&value)) {                                     \
            ALOGE("%s invalid parameter %s %d", __func__, #tag, value);              \
            return BAD_VALUE;                                                        \
        Parameter aidlParam;                                                               \
        valueType value;                                                                   \
        if (status_t status = param.readFromValue(&value); status != OK) {                 \
            ALOGE("%s  %s read from parameter failed, ret %d", __func__, #tag, status);    \
            return status;                                                                 \
        }                                                                                  \
        aidlParam = MAKE_SPECIFIC_PARAMETER(                                               \
                EnvironmentalReverb, environmentalReverb, tag,                             \
                VALUE_OR_RETURN_STATUS(aidl::android::convertIntegral<int>(value))); \
                VALUE_OR_RETURN_STATUS(aidl::android::convertIntegral<aidlType>(value)));  \
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->setParameter(aidlParam))); \
    }

#define GET_AIDL_PARAMETER(tag, value, param)                                                      \
/**
 * Macro to get a parameter from AIDL effect and write the value to effect_param_t with wrapper.
 *
 * Return if there is any error, otherwise continue execution.
 *
 * @param param EffectParamWriter, a writer wrapper of effect_param_t.
 * @param aidlType Type of the AIDL parameter field, used to construct AIDL Parameter union.
 * @param valueType  Type of the value get from effect_param_t.
 * @param tag The AIDL parameter union field tag.
 */
#define GET_AIDL_PARAMETER(param, aidltype, valueType, tag)                                        \
    {                                                                                              \
        aidltype value;                                                                            \
        Parameter aidlParam;                                                                       \
        Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(EnvironmentalReverb, environmentalReverbTag, \
                                                      EnvironmentalReverb::tag);                   \
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));    \
        value = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(                               \
                aidlParam, EnvironmentalReverb, environmentalReverb, EnvironmentalReverb::tag,     \
                std::decay_t<decltype(value)>));                                                   \
        return param.writeToValue(&value);                                                         \
        value = VALUE_OR_RETURN_STATUS(                                                            \
                GET_PARAMETER_SPECIFIC_FIELD(aidlParam, EnvironmentalReverb, environmentalReverb,  \
                                             EnvironmentalReverb::tag, std::decay_t<aidltype>));   \
        if (status_t status = param.writeToValue((valueType*)&value); status != OK) {              \
            param.setStatus(status);                                                               \
            ALOGE("%s %s write to parameter failed %d, ret %d", __func__, #tag, value, status);    \
            return status;                                                                         \
        }                                                                                          \
    }

status_t AidlConversionEnvReverb::setParameter(EffectParamReader& param) {
    uint32_t type = 0;
    if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
        OK != param.readFromParameter(&type)) {
        ALOGE("%s invalid param %s", __func__, param.toString().c_str());
    if (status_t status = param.readFromParameter(&type); status != OK) {
        ALOGE("%s failed to read type from %s, ret %d", __func__, param.toString().c_str(), status);
        return BAD_VALUE;
    }
    Parameter aidlParam;
    uint16_t value16;
    uint32_t value32;

    switch (type) {
        case REVERB_PARAM_ROOM_LEVEL: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, roomLevelMb);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, roomLevelMb);
            break;
        }
        case REVERB_PARAM_ROOM_HF_LEVEL: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, roomHfLevelMb);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, roomHfLevelMb);
            break;
        }
        case REVERB_PARAM_DECAY_TIME: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value32, decayTimeMs);
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, decayTimeMs);
            break;
        }
        case REVERB_PARAM_DECAY_HF_RATIO: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, decayHfRatioPm);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_LEVEL: {
            SET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_DELAY: {
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
            break;
        }
        case REVERB_PARAM_REVERB_LEVEL: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, levelMb);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
            break;
        }
        case REVERB_PARAM_REVERB_DELAY: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value32, delayMs);
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
            break;
        }
        case REVERB_PARAM_DIFFUSION: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, diffusionPm);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
            break;
        }
        case REVERB_PARAM_DENSITY: {
            MAKE_AIDL_PARAMETER(aidlParam, param, value16, densityPm);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
            break;
        }
        case REVERB_PARAM_BYPASS: {
            if (OK != param.readFromValue(&value32)) {
                ALOGE("%s invalid bypass parameter %d", __func__, value32);
                return BAD_VALUE;
            }
            bool isByPass = VALUE_OR_RETURN_STATUS(aidl::android::convertIntegral<bool>(value32));
            aidlParam = MAKE_SPECIFIC_PARAMETER(EnvironmentalReverb, environmentalReverb, bypass,
                                                isByPass);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_LEVEL: {
            // TODO
            break;
        }
        case REVERB_PARAM_REFLECTIONS_DELAY: {
            // TODO
            SET_AIDL_PARAMETER(param, bool, int32_t, bypass);
            break;
        }
        case REVERB_PARAM_PROPERTIES: {
            // TODO
            if (sizeof(t_reverb_settings) > param.getValueSize()) {
                ALOGE("%s vsize %zu less than t_reverb_settings size %zu", __func__,
                      param.getValueSize(), sizeof(t_reverb_settings));
                return BAD_VALUE;
            }
            // this sequency needs to be aligned with t_reverb_settings
            SET_AIDL_PARAMETER(param, int32_t, int16_t, roomLevelMb);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, roomHfLevelMb);
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, decayTimeMs);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
            SET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
            SET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
            break;
        }
        default: {
            // TODO: handle with vendor extension
        }
    }
    return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
    return OK;
}

status_t AidlConversionEnvReverb::getParameter(EffectParamWriter& param) {
    uint32_t type = 0;
    if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) ||
        OK != param.readFromParameter(&type)) {
        ALOGE("%s invalid param %s", __func__, param.toString().c_str());
        param.setStatus(BAD_VALUE);
        return BAD_VALUE;
    if (status_t status = param.readFromParameter(&type); status != OK) {
        ALOGE("%s failed to read type from %s", __func__, param.toString().c_str());
        param.setStatus(status);
        return status;
    }
    uint16_t value16;
    uint32_t value32;

    switch (type) {
        case REVERB_PARAM_ROOM_LEVEL: {
            GET_AIDL_PARAMETER(roomLevelMb, value16, param);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, roomLevelMb);
            break;
        }
        case REVERB_PARAM_ROOM_HF_LEVEL: {
            GET_AIDL_PARAMETER(roomHfLevelMb, value16, param);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, roomHfLevelMb);
            break;
        }
        case REVERB_PARAM_DECAY_TIME: {
            GET_AIDL_PARAMETER(decayTimeMs, value32, param);
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, decayTimeMs);
            break;
        }
        case REVERB_PARAM_DECAY_HF_RATIO: {
            GET_AIDL_PARAMETER(decayHfRatioPm, value16, param);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_LEVEL: {
            GET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_DELAY: {
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
            break;
        }
        case REVERB_PARAM_REVERB_LEVEL: {
            GET_AIDL_PARAMETER(levelMb, value16, param);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
            break;
        }
        case REVERB_PARAM_REVERB_DELAY: {
            GET_AIDL_PARAMETER(delayMs, value32, param);
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
            break;
        }
        case REVERB_PARAM_DIFFUSION: {
            GET_AIDL_PARAMETER(diffusionPm, value16, param);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
            break;
        }
        case REVERB_PARAM_DENSITY: {
            GET_AIDL_PARAMETER(densityPm, value16, param);
        }
        case REVERB_PARAM_BYPASS: {
            bool isByPass;
            GET_AIDL_PARAMETER(bypass, isByPass, param);
        }
        case REVERB_PARAM_REFLECTIONS_LEVEL: {
            // TODO
            GET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
            break;
        }
        case REVERB_PARAM_REFLECTIONS_DELAY: {
            // TODO
        case REVERB_PARAM_BYPASS: {
            GET_AIDL_PARAMETER(param, bool, int32_t, bypass);
            break;
        }
        case REVERB_PARAM_PROPERTIES: {
            // TODO
            // this sequency needs to be aligned with t_reverb_settings
            GET_AIDL_PARAMETER(param, int32_t, int16_t, roomLevelMb);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, roomHfLevelMb);
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, decayTimeMs);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
            GET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
            GET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
            break;
        }
        default: {
            // TODO: handle with vendor extension
            return BAD_VALUE;
        }
    }
    return BAD_VALUE;
    return OK;
}

} // namespace effect
+22 −0
Original line number Diff line number Diff line
@@ -184,6 +184,20 @@ ndk::ScopedAStatus EffectReverb::setParameterEnvironmentalReverb(
                    EX_ILLEGAL_ARGUMENT, "setDecayHfRatioFailed");
            return ndk::ScopedAStatus::ok();
        }
        case EnvironmentalReverb::reflectionsLevelMb: {
            RETURN_IF(mContext->setReflectionsLevel(
                              erParam.get<EnvironmentalReverb::reflectionsLevelMb>()) !=
                              RetCode::SUCCESS,
                      EX_ILLEGAL_ARGUMENT, "setReflectionsLevelFailed");
            return ndk::ScopedAStatus::ok();
        }
        case EnvironmentalReverb::reflectionsDelayMs: {
            RETURN_IF(mContext->setReflectionsDelay(
                              erParam.get<EnvironmentalReverb::reflectionsDelayMs>()) !=
                              RetCode::SUCCESS,
                      EX_ILLEGAL_ARGUMENT, "setReflectionsDelayFailed");
            return ndk::ScopedAStatus::ok();
        }
        case EnvironmentalReverb::levelMb: {
            RETURN_IF(mContext->setEnvironmentalReverbLevel(
                              erParam.get<EnvironmentalReverb::levelMb>()) != RetCode::SUCCESS,
@@ -292,6 +306,14 @@ ndk::ScopedAStatus EffectReverb::getParameterEnvironmentalReverb(const Environme
                    mContext->getEnvironmentalReverbDecayHfRatio());
            break;
        }
        case EnvironmentalReverb::reflectionsLevelMb: {
            erParam.set<EnvironmentalReverb::reflectionsLevelMb>(mContext->getReflectionsLevel());
            break;
        }
        case EnvironmentalReverb::reflectionsDelayMs: {
            erParam.set<EnvironmentalReverb::reflectionsDelayMs>(mContext->getReflectionsDelay());
            break;
        }
        case EnvironmentalReverb::levelMb: {
            erParam.set<EnvironmentalReverb::levelMb>(mContext->getEnvironmentalReverbLevel());
            break;
+23 −9
Original line number Diff line number Diff line
@@ -83,6 +83,18 @@ class ReverbContext final : public EffectContext {
    RetCode setVolumeStereo(const Parameter::VolumeStereo& volumeStereo) override;
    Parameter::VolumeStereo getVolumeStereo() override { return mVolumeStereo; }

    RetCode setReflectionsDelay(int delay) {
        mReflectionsDelayMs = delay;
        return RetCode::SUCCESS;
    }
    bool getReflectionsDelay() const { return mReflectionsDelayMs; }

    RetCode setReflectionsLevel(int level) {
        mReflectionsLevelMb = level;
        return RetCode::SUCCESS;
    }
    bool getReflectionsLevel() const { return mReflectionsLevelMb; }

    IEffect::Status lvmProcess(float* in, float* out, int samples);

  private:
@@ -146,15 +158,17 @@ class ReverbContext final : public EffectContext {
    bool mEnabled = false;
    LVREV_Handle_t mInstance GUARDED_BY(mMutex);

    int mRoomLevel;
    int mRoomHfLevel;
    int mDecayTime;
    int mDecayHfRatio;
    int mLevel;
    int mDelay;
    int mDiffusion;
    int mDensity;
    bool mBypass;
    int mRoomLevel = 0;
    int mRoomHfLevel = 0;
    int mDecayTime = 0;
    int mDecayHfRatio = 0;
    int mLevel = 0;
    int mDelay = 0;
    int mDiffusion = 0;
    int mDensity = 0;
    bool mBypass = 0;
    int mReflectionsLevelMb = 0;
    int mReflectionsDelayMs = 0;

    PresetReverb::Presets mPreset;
    PresetReverb::Presets mNextPreset;