[AIDL CTS] pass EnvReverb implementation cts
Bug: 270158223
Test: atest android.media.audio.cts.EnvReverbTest
Change-Id: Id0d26503531f905738b5df30125031978ab8b9e3
diff --git a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionEnvReverb.cpp b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionEnvReverb.cpp
index 960273b..0544e3f 100644
--- a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionEnvReverb.cpp
+++ b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionEnvReverb.cpp
@@ -43,157 +43,208 @@
using utils::EffectParamReader;
using utils::EffectParamWriter;
-#define MAKE_AIDL_PARAMETER(aidlParam, param, value, tag) \
- { \
- if (OK != param.readFromValue(&value)) { \
- ALOGE("%s invalid parameter %s %d", __func__, #tag, value); \
- return BAD_VALUE; \
- } \
- aidlParam = MAKE_SPECIFIC_PARAMETER( \
- EnvironmentalReverb, environmentalReverb, tag, \
- VALUE_OR_RETURN_STATUS(aidl::android::convertIntegral<int>(value))); \
+/**
+ * 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) \
+ { \
+ 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<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);
- break;
- }
- case REVERB_PARAM_REVERB_LEVEL: {
- MAKE_AIDL_PARAMETER(aidlParam, param, value16, levelMb);
- break;
- }
- case REVERB_PARAM_REVERB_DELAY: {
- MAKE_AIDL_PARAMETER(aidlParam, param, value32, delayMs);
- break;
- }
- case REVERB_PARAM_DIFFUSION: {
- MAKE_AIDL_PARAMETER(aidlParam, param, value16, diffusionPm);
- break;
- }
- case REVERB_PARAM_DENSITY: {
- MAKE_AIDL_PARAMETER(aidlParam, param, value16, 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);
+ SET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
break;
}
case REVERB_PARAM_REFLECTIONS_LEVEL: {
- // TODO
+ SET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
break;
}
case REVERB_PARAM_REFLECTIONS_DELAY: {
- // TODO
+ SET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
+ break;
+ }
+ case REVERB_PARAM_REVERB_LEVEL: {
+ SET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
+ break;
+ }
+ case REVERB_PARAM_REVERB_DELAY: {
+ SET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
+ break;
+ }
+ case REVERB_PARAM_DIFFUSION: {
+ SET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
+ break;
+ }
+ case REVERB_PARAM_DENSITY: {
+ SET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
+ break;
+ }
+ case REVERB_PARAM_BYPASS: {
+ 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);
- }
- case REVERB_PARAM_REVERB_LEVEL: {
- GET_AIDL_PARAMETER(levelMb, value16, param);
- }
- case REVERB_PARAM_REVERB_DELAY: {
- GET_AIDL_PARAMETER(delayMs, value32, param);
- }
- case REVERB_PARAM_DIFFUSION: {
- GET_AIDL_PARAMETER(diffusionPm, value16, param);
- }
- case REVERB_PARAM_DENSITY: {
- GET_AIDL_PARAMETER(densityPm, value16, param);
- }
- case REVERB_PARAM_BYPASS: {
- bool isByPass;
- GET_AIDL_PARAMETER(bypass, isByPass, param);
+ GET_AIDL_PARAMETER(param, int32_t, int16_t, decayHfRatioPm);
+ break;
}
case REVERB_PARAM_REFLECTIONS_LEVEL: {
- // TODO
+ GET_AIDL_PARAMETER(param, int32_t, int16_t, reflectionsLevelMb);
break;
}
case REVERB_PARAM_REFLECTIONS_DELAY: {
- // TODO
+ GET_AIDL_PARAMETER(param, int32_t, uint32_t, reflectionsDelayMs);
+ break;
+ }
+ case REVERB_PARAM_REVERB_LEVEL: {
+ GET_AIDL_PARAMETER(param, int32_t, int16_t, levelMb);
+ break;
+ }
+ case REVERB_PARAM_REVERB_DELAY: {
+ GET_AIDL_PARAMETER(param, int32_t, uint32_t, delayMs);
+ break;
+ }
+ case REVERB_PARAM_DIFFUSION: {
+ GET_AIDL_PARAMETER(param, int32_t, int16_t, diffusionPm);
+ break;
+ }
+ case REVERB_PARAM_DENSITY: {
+ GET_AIDL_PARAMETER(param, int32_t, int16_t, densityPm);
+ break;
+ }
+ 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
diff --git a/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
index 018f3bc..e9bdf94 100644
--- a/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
@@ -184,6 +184,20 @@
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 @@
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;
diff --git a/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h b/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
index af49a25..9bb0b1a 100644
--- a/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
+++ b/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
@@ -83,6 +83,18 @@
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 @@
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;