From b56a01b017daefb5cfa9b4f90b9f1e59bae30d61 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Tue, 16 Jul 2024 21:26:35 +0800 Subject: [PATCH 01/18] effectPropertyImpl Signed-off-by: owencreeper --- .../napi_audio_stream_manager.cpp | 146 +++++++++++++++++ .../audiomanager/napi_audio_stream_manager.h | 6 + .../js/napi/common/napi_audio_error.cpp | 1 + .../js/napi/common/napi_param_utils.cpp | 121 ++++++++++++++ frameworks/js/napi/common/napi_param_utils.h | 8 +- .../audioeffect/include/audio_effect_chain.h | 5 +- .../include/audio_effect_chain_manager.h | 5 +- .../audioeffect/include/audio_enhance_chain.h | 2 + .../include/audio_enhance_chain_manager.h | 7 +- .../audioeffect/src/audio_effect_chain.cpp | 60 +++++-- .../src/audio_effect_chain_manager.cpp | 42 ++++- .../audioeffect/src/audio_enhance_chain.cpp | 23 +++ .../src/audio_enhance_chain_manager.cpp | 44 ++++- .../include/audio_policy_manager.h | 7 + .../native/audiocommon/include/audio_effect.h | 64 +++++++- .../include/audio_stream_manager.h | 60 +++++++ .../client/include/audio_policy_base.h | 13 ++ .../include/audio_policy_manager_stub.h | 12 ++ .../client/include/audio_policy_proxy.h | 13 ++ .../client/src/audio_policy_manager.cpp | 43 +++++ .../client/src/audio_policy_proxy.cpp | 134 ++++++++++++++++ .../include/audio_policy_ipc_interface_code.h | 8 +- .../server/include/audio_policy_server.h | 7 + .../include/service/audio_policy_service.h | 8 + .../service/effect/audio_effect_manager.h | 11 ++ .../server/src/audio_policy_manager_stub.cpp | 85 ++++++++++ .../server/src/audio_policy_server.cpp | 37 +++++ .../src/service/audio_policy_service.cpp | 82 +++++++++- .../service/effect/audio_effect_manager.cpp | 150 ++++++++++++++++++ .../client/include/audio_manager_base.h | 17 +- .../client/include/audio_manager_proxy.h | 9 +- .../include/pulseaudio_ipc_interface_code.h | 4 + .../client/src/audio_manager_proxy.cpp | 117 ++++++++++++-- .../client/src/audio_stream_manager.cpp | 31 ++++ .../server/include/audio_server.h | 10 +- .../server/src/audio_manager_stub.cpp | 92 ++++++++++- .../audio_service/server/src/audio_server.cpp | 47 +++++- 37 files changed, 1479 insertions(+), 52 deletions(-) diff --git a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp index e66f8501e6..cad89c9325 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp +++ b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp @@ -95,6 +95,12 @@ napi_value NapiAudioStreamMgr::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getAudioEffectInfoArray", GetEffectInfoArray), DECLARE_NAPI_FUNCTION("getAudioEffectInfoArraySync", GetEffectInfoArraySync), DECLARE_NAPI_FUNCTION("getHardwareOutputSamplingRate", GetHardwareOutputSamplingRate), + DECLARE_NAPI_FUNCTION("getSupportedAudioEffectProperty", GetSupportedAudioEffectProperty), + DECLARE_NAPI_FUNCTION("getAudioEffectProperty", GetAudioEffectProperty), + DECLARE_NAPI_FUNCTION("setAudioEffectProperty", SetAudioEffectProperty), + DECLARE_NAPI_FUNCTION("getSupportedAudioEnhanceProperty", GetSupportedAudioEnhanceProperty), + DECLARE_NAPI_FUNCTION("getAudioEnhanceProperty", GetAudioEnhanceProperty), + DECLARE_NAPI_FUNCTION("setAudioEnhanceProperty", SetAudioEnhanceProperty), }; status = napi_define_class(env, AUDIO_STREAM_MGR_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Construct, nullptr, @@ -645,5 +651,145 @@ napi_value NapiAudioStreamMgr::Off(napi_env env, napi_callback_info info) UnregisterCallback(env, jsThis, callbackName); return undefinedResult; } + +napi_value NapiAudioStreamMgr::GetSupportedAudioEffectProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = PARAM0; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr); + CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be empty"), "argcCount invalid"); + + AudioEffectPropertyArray propertyArray = {}; + int32_t ret = napiStreamMgr->audioStreamMngr_->GetSupportedAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "get support audio effect property failure!"); + + napi_status status = NapiParamUtils::SetEffectProperty(env, propertyArray, result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "Combining property data fail"), "fill support effect property failed"); + + return result; +} + +napi_value NapiAudioStreamMgr::GetSupportedAudioEnhanceProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = PARAM0; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr); + CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be empty"), "argcCount invalid"); + + AudioEnhancePropertyArray propertyArray = {}; + int32_t ret = napiStreamMgr->audioStreamMngr_->GetSupportedAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "get support audio enhance property failure!"); + + napi_status status = NapiParamUtils::SetEnhanceProperty(env, propertyArray, result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "Combining property data fail"), "fill enhance property failed"); + return result; +} + +napi_value NapiAudioStreamMgr::GetAudioEffectProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = PARAM0; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr); + CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be empty"), "argcCount invalid"); + + AudioEffectPropertyArray propertyArray = {}; + int32_t ret = napiStreamMgr->audioStreamMngr_->GetAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "get audio enhance property failure!"); + + napi_status status = NapiParamUtils::SetEffectProperty(env, propertyArray, result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "combining property data fail"), "fill effect property failed"); + + return result; +} + +napi_value NapiAudioStreamMgr::SetAudioEffectProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = ARGS_ONE; + napi_value args[ARGS_ONE] = {}; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, args); + CHECK_AND_RETURN_RET_LOG(argc == ARGS_ONE && napiStreamMgr != nullptr && + napiStreamMgr->audioStreamMngr_ != nullptr, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "parameter verification failed: mandatory parameters are left unspecified"), "argcCount invalid"); + + napi_valuetype valueType = napi_undefined; + napi_typeof(env, args[PARAM0], &valueType); + CHECK_AND_RETURN_RET_LOG(valueType == napi_object, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be array"), "invaild valueType"); + + AudioEffectPropertyArray propertyArray = {}; + napi_status status = NapiParamUtils::GetEffectPropertyArray(env, propertyArray, args[PARAM0]); + CHECK_AND_RETURN_RET_LOG(status == napi_ok && propertyArray.property.size() > 0, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "parameter verification failed: mandatory parameters are left unspecified"), "status or arguments error"); + + int32_t ret = napiStreamMgr->audioStreamMngr_->SetAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "set audio effect property failure!"); + + return result; +} + +napi_value NapiAudioStreamMgr::GetAudioEnhanceProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = PARAM0; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, nullptr); + CHECK_AND_RETURN_RET_LOG(argc == PARAM0 && napiStreamMgr != nullptr && napiStreamMgr->audioStreamMngr_ != nullptr, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be empty"), "argcCount invalid"); + + AudioEnhancePropertyArray propertyArray = {}; + int32_t ret = napiStreamMgr->audioStreamMngr_->GetAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "get audio enhance property failure!"); + + napi_status status = NapiParamUtils::SetEnhanceProperty(env, propertyArray, result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "combining property data fail"), "fill effect property failed"); + + return result; +} + +napi_value NapiAudioStreamMgr::SetAudioEnhanceProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = ARGS_ONE; + napi_value args[ARGS_ONE] = {}; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, args); + CHECK_AND_RETURN_RET_LOG(argc == ARGS_ONE && napiStreamMgr != nullptr && + napiStreamMgr->audioStreamMngr_ != nullptr, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "parameter verification failed: mandatory parameters are left unspecified"), "argcCount invalid"); + + napi_valuetype valueType = napi_undefined; + napi_typeof(env, args[PARAM0], &valueType); + CHECK_AND_RETURN_RET_LOG(valueType == napi_object, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of options must be array"), "invaild valueType"); + + AudioEnhancePropertyArray propertyArray = {}; + napi_status status = NapiParamUtils::GetEnhancePropertyArray(env, propertyArray, args[PARAM0]); + CHECK_AND_RETURN_RET_LOG(status == napi_ok && propertyArray.property.size() > 0, + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "parameter verification failed: mandatory parameters are left unspecified"), "status or arguments error"); + + int32_t ret = napiStreamMgr->audioStreamMngr_->SetAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, NapiAudioError::ThrowErrorAndReturn(env, ret, + "interface operation failed"), "set audio enhance property failure!"); + + return result; +} + } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h index 3e7c02b076..78643b86a0 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h +++ b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h @@ -70,6 +70,12 @@ private: static napi_value IsStreamActiveSync(napi_env env, napi_callback_info info); static napi_value GetEffectInfoArray(napi_env env, napi_callback_info info); static napi_value GetEffectInfoArraySync(napi_env env, napi_callback_info info); + static napi_value GetSupportedAudioEffectProperty(napi_env env, napi_callback_info info); + static napi_value GetSupportedAudioEnhanceProperty(napi_env env, napi_callback_info info); + static napi_value SetAudioEnhanceProperty(napi_env env, napi_callback_info info); + static napi_value GetAudioEnhanceProperty(napi_env env, napi_callback_info info); + static napi_value GetAudioEffectProperty(napi_env env, napi_callback_info info); + static napi_value SetAudioEffectProperty(napi_env env, napi_callback_info info); static napi_value GetHardwareOutputSamplingRate(napi_env env, napi_callback_info info); static napi_value On(napi_env env, napi_callback_info info); static napi_value Off(napi_env env, napi_callback_info info); diff --git a/frameworks/js/napi/common/napi_audio_error.cpp b/frameworks/js/napi/common/napi_audio_error.cpp index eceec16f7d..4ac0360e49 100644 --- a/frameworks/js/napi/common/napi_audio_error.cpp +++ b/frameworks/js/napi/common/napi_audio_error.cpp @@ -91,6 +91,7 @@ std::string NapiAudioError::GetMessageByCode(int32_t &code) break; case NAPI_ERR_PERMISSION_DENIED: case ERR_PERMISSION_DENIED: + case ERR_SYSTEM_PERMISSION_DENIED: errMessage = NAPI_ERROR_PERMISSION_DENIED_INFO; code = NAPI_ERR_PERMISSION_DENIED; break; diff --git a/frameworks/js/napi/common/napi_param_utils.cpp b/frameworks/js/napi/common/napi_param_utils.cpp index 9991a22018..2ec7166774 100644 --- a/frameworks/js/napi/common/napi_param_utils.cpp +++ b/frameworks/js/napi/common/napi_param_utils.cpp @@ -1049,5 +1049,126 @@ napi_status NapiParamUtils::SetExtraAudioParametersInfo(const napi_env &env, return status; } + +napi_status NapiParamUtils::GetEffectPropertyArray(napi_env env, AudioEffectPropertyArray &effectArray, + napi_value in) +{ + uint32_t arrayLen = 0; + napi_status status = napi_get_array_length(env, in, &arrayLen); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "get subKeys length failed"); + + for (size_t i = 0; i < arrayLen; i++) { + napi_value element = nullptr; + napi_get_element(env, in, i, &element); + + AudioEffectProperty prop; + napi_value propValue = nullptr; + + status = napi_get_named_property(env, element, "effectClass", &propValue); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Get effectClass failed"); + prop.effectClass = GetStringArgument(env, propValue); + + status = napi_get_named_property(env, element, "effectProp", &propValue); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Get effectProp failed"); + prop.effectProp = GetStringArgument(env, propValue); + + effectArray.property.push_back(prop); + } + + int32_t size = effectArray.property.size(); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + napi_invalid_arg, "Audio effect property array size invalid"); + + std::set classSet; + for (int32_t i = 0; i < size; i++) { + if (effectArray.property[i].effectClass != "" && effectArray.property[i].effectProp != "") { + classSet.insert(effectArray.property[i].effectClass); + } + } + CHECK_AND_RETURN_RET_LOG(size == static_cast(classSet.size()), napi_invalid_arg, + "Audio enhance property array exist duplicate data"); + + return napi_ok; +} + +napi_status NapiParamUtils::GetEnhancePropertyArray(napi_env env, AudioEnhancePropertyArray &enhanceArray, + napi_value in) +{ + uint32_t arrayLen = 0; + napi_status status = napi_get_array_length(env, in, &arrayLen); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "get subKeys length failed"); + + for (size_t i = 0; i < arrayLen; i++) { + napi_value element = nullptr; + napi_get_element(env, in, i, &element); + + AudioEnhanceProperty prop; + napi_value propValue = nullptr; + + status = napi_get_named_property(env, element, "enhanceClass", &propValue); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Get enhanceClass failed"); + prop.enhanceClass = GetStringArgument(env, propValue); + + status = napi_get_named_property(env, element, "enhanceProp", &propValue); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Get enhanceProp failed"); + prop.enhanceProp = GetStringArgument(env, propValue); + + enhanceArray.property.push_back(prop); + } + + int32_t size = enhanceArray.property.size(); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + napi_invalid_arg, "Audio enhance property array size invalid"); + + std::set classSet; + for (int32_t i = 0; i < size; i++) { + if (enhanceArray.property[i].enhanceClass != "" && enhanceArray.property[i].enhanceProp != "") { + classSet.insert(enhanceArray.property[i].enhanceClass); + } + } + CHECK_AND_RETURN_RET_LOG(size == static_cast(classSet.size()), napi_invalid_arg, + "Audio enhance property array exist duplicate data"); + + return napi_ok; +} + +napi_status NapiParamUtils::SetEnhanceProperty(const napi_env &env, const AudioEnhancePropertyArray &enhanceArray, + napi_value &result) +{ + int32_t position = 0; + napi_value jsEnhanceInfoObj = nullptr; + napi_status status = napi_create_array_with_length(env, enhanceArray.property.size(), &result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "get create array failed"); + for (const auto &property : enhanceArray.property) { + napi_create_object(env, &jsEnhanceInfoObj); + status = SetValueString(env, "enhanceClass", property.enhanceClass, jsEnhanceInfoObj); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Set enhanceClass failed"); + status = SetValueString(env, "enhanceProp", property.enhanceProp, jsEnhanceInfoObj); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Set enhanceProp failed"); + napi_set_element(env, result, position, jsEnhanceInfoObj); + position++; + } + return napi_ok; +} + +napi_status NapiParamUtils::SetEffectProperty(const napi_env &env, const AudioEffectPropertyArray &effectArray, + napi_value &result) +{ + int32_t position = 0; + napi_value jsEffectInfoObj = nullptr; + napi_status status = napi_create_array_with_length(env, effectArray.property.size(), &result); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "get create array failed"); + for (const auto &property : effectArray.property) { + napi_create_object(env, &jsEffectInfoObj); + status = SetValueString(env, "effectClass", property.effectClass, jsEffectInfoObj); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Set effectClass failed"); + status = SetValueString(env, "effectProp", property.effectProp, jsEffectInfoObj); + CHECK_AND_RETURN_RET_LOG(status == napi_ok, status, "Set effectProp failed"); + napi_set_element(env, result, position, jsEffectInfoObj); + position++; + } + return napi_ok; +} + } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/js/napi/common/napi_param_utils.h b/frameworks/js/napi/common/napi_param_utils.h index 25513d4fd0..7da6730543 100644 --- a/frameworks/js/napi/common/napi_param_utils.h +++ b/frameworks/js/napi/common/napi_param_utils.h @@ -201,7 +201,13 @@ public: static napi_status GetSpatialDeviceState(napi_env env, AudioSpatialDeviceState *spatialDeviceState, napi_value in); static napi_status GetExtraParametersSubKV(napi_env env, std::vector> &subKV, - napi_value in); + napi_value in); + static napi_status SetEffectProperty(const napi_env &env, + const AudioEffectPropertyArray &effectArray, napi_value &result); + static napi_status SetEnhanceProperty(const napi_env &env, + const AudioEnhancePropertyArray &enhanceArray, napi_value &result); + static napi_status GetEffectPropertyArray(napi_env env, AudioEffectPropertyArray &effectArray, napi_value in); + static napi_status GetEnhancePropertyArray(napi_env env, AudioEnhancePropertyArray &enhanceArray, napi_value in); static napi_status GetExtraParametersVector(const napi_env &env, std::vector &subKeys, napi_value in); static napi_status SetExtraAudioParametersInfo(const napi_env &env, const std::vector> &extraParameters, napi_value &result); diff --git a/frameworks/native/audioeffect/include/audio_effect_chain.h b/frameworks/native/audioeffect/include/audio_effect_chain.h index a899ebd339..7bb68f4cb2 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain.h @@ -45,7 +45,8 @@ public: ~AudioEffectChain(); std::string GetEffectMode(); void SetEffectMode(const std::string &mode); - void AddEffectHandle(AudioEffectHandle effectHandle, AudioEffectLibrary *libHandle, AudioEffectScene currSceneType); + void AddEffectHandle(AudioEffectHandle effectHandle, AudioEffectLibrary *libHandle, AudioEffectScene currSceneType, + const std::string &effectName, const std::string &property); void ApplyEffectChain(float *bufIn, float *bufOut, uint32_t frameLen, AudioEffectProcInfo procInfo); bool IsEmptyEffectHandles(); void Dump(); @@ -58,6 +59,7 @@ public: void ResetIoBufferConfig(); void SetFinalVolume(float volume); float GetFinalVolume(); + int32_t SetEffectProperty(const std::string &effect, const std::string &property); private: AudioEffectConfig GetIoBufferConfig(); @@ -69,6 +71,7 @@ private: std::string effectMode_ = ""; uint32_t latency_ = 0; std::vector standByEffectHandles_; + std::vector effectNames_; std::vector libHandles_; AudioEffectConfig ioBufferConfig_ = {}; AudioBuffer audioBufIn_ = {}; diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 066d4d9d45..e3098cd4f9 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -95,7 +95,7 @@ public: ~AudioEffectChainManager(); static AudioEffectChainManager *GetInstance(); void InitAudioEffectChainManager(std::vector &effectChains, - std::unordered_map &map, + const EffectChainManagerParam &effectChainManagerParam, std::vector> &effectLibraryList); bool CheckAndAddSessionID(const std::string &sessionID); int32_t CreateAudioEffectChainDynamic(const std::string &sceneType); @@ -133,6 +133,8 @@ public: void UpdateSpkOffloadEnabled(); // Used for AISS scene temporarily void InitHdiState(); + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray); + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray); private: int32_t SetAudioEffectChainDynamic(const std::string &sceneType, const std::string &effectMode); void UpdateSensorState(); @@ -169,6 +171,7 @@ private: std::map SessionIDToEffectInfoMap_; std::map SceneTypeToEffectChainCountBackupMap_; std::set SceneTypeToSpecialEffectSet_; + std::unordered_map effectPropertyMap_; DeviceType deviceType_ = DEVICE_TYPE_SPEAKER; std::string deviceSink_ = DEFAULT_DEVICE_SINK; std::string deviceClass_ = ""; diff --git a/frameworks/native/audioeffect/include/audio_enhance_chain.h b/frameworks/native/audioeffect/include/audio_enhance_chain.h index 69c48f1cae..9b5279955b 100644 --- a/frameworks/native/audioeffect/include/audio_enhance_chain.h +++ b/frameworks/native/audioeffect/include/audio_enhance_chain.h @@ -69,6 +69,7 @@ public: uint32_t GetAlgoBufferSize(); uint32_t GetAlgoBufferSizeEc(); int32_t ApplyEnhanceChain(std::unique_ptr &enhanceBuffer, uint32_t length); + int32_t SetAudioEnhanceProperty(const std::string &effect, const std::string &property); private: void InitAudioEnhanceChain(); @@ -87,6 +88,7 @@ private: FILE *dumpFileOut_ = nullptr; bool needEcFlag_; std::vector standByEnhanceHandles_; + std::vector effectNames_; std::vector enhanceLibHandles_; }; diff --git a/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h b/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h index f8c16b6200..15a47a2cba 100644 --- a/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h @@ -35,7 +35,7 @@ public: ~AudioEnhanceChainManager(); static AudioEnhanceChainManager* GetInstance(); void InitAudioEnhanceChainManager(std::vector &enhanceChains, - std::unordered_map &enhanceChainNameMap, + const EffectChainManagerParam &managerParam, std::vector> &enhanceLibraryList); int32_t CreateAudioEnhanceChainDynamic(const std::string &scene, const std::string &mode, const std::string &up, const std::string &down); @@ -54,7 +54,9 @@ public: int32_t SetVolumeInfo(const AudioVolumeType &volumeType, const float &systemVol); int32_t SetMicrophoneMuteInfo(const bool &isMute); int32_t SetStreamVolumeInfo(const uint32_t &sessionId, const float &streamVol); - + + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); private: int32_t SetAudioEnhanceChainDynamic(const std::string &sceneType, const std::string &sceneMode, const std::string &upDevice, const std::string &downDevice); @@ -67,6 +69,7 @@ private: std::map> enhanceChainToEnhancesMap_; std::map> enhanceToLibraryEntryMap_; std::map enhanceToLibraryNameMap_; + std::unordered_map effectPropertyMap_; std::unique_ptr enhanceBuffer_ = nullptr; std::mutex chainManagerMutex_; bool isInitialized_; diff --git a/frameworks/native/audioeffect/src/audio_effect_chain.cpp b/frameworks/native/audioeffect/src/audio_effect_chain.cpp index 44194484f6..4a43f9486a 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain.cpp @@ -22,6 +22,7 @@ #include "audio_log.h" #include "audio_utils.h" #include "securec.h" +#include namespace OHOS { namespace AudioStandard { @@ -144,9 +145,9 @@ int32_t AudioEffectChain::SetEffectParamToHandle(AudioEffectHandle handle, Audio { AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectConfig), &ioBufferConfig_}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + std::vector paramBuffer(sizeof(AudioEffectParam) + NUM_SET_EFFECT_PARAM * sizeof(int32_t)); // Set param - AudioEffectParam *effectParam = - new AudioEffectParam[sizeof(AudioEffectParam) + NUM_SET_EFFECT_PARAM * sizeof(int32_t)]; + AudioEffectParam *effectParam = reinterpret_cast(paramBuffer.data()); effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; @@ -171,39 +172,70 @@ int32_t AudioEffectChain::SetEffectParamToHandle(AudioEffectHandle handle, Audio AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); - delete[] effectParam; + return ret; +} + +int32_t AudioEffectChain::SetEffectProperty(const std::string &effect, const std::string &property) +{ + std::lock_guard lock(reloadMutex_); + int32_t ret = 0; + int32_t size = standByEffectHandles_.size(); + for (int32_t index = 0; index < size; index++) { + auto &handle = standByEffectHandles_[index]; + auto const &effectName = effectNames_[index]; + if (effect == effectName) { + int32_t replyData = 0; + const char *propCstr = property.c_str(); + AudioEffectTransInfo cmdInfo = {sizeof(const char *), reinterpret_cast(&propCstr)}; + AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + ret = (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); + CHECK_AND_RETURN_RET_LOG(ret == 0, ret, + "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_SET_PROPERTY fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); + } + } return ret; } void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle, - AudioEffectScene currSceneType) + AudioEffectScene currSceneType, const std::string &effectName, const std::string &effectProperty) { int32_t ret; int32_t replyData = 0; AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectConfig), &ioBufferConfig_}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; ret = (*handle)->command(handle, EFFECT_CMD_INIT, &cmdInfo, &replyInfo); - CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{pubilc}s lib EFFECT_CMD_INIT fail", - sceneType_.c_str(), effectMode_.c_str(), libHandle->name); + CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_INIT fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); ret = (*handle)->command(handle, EFFECT_CMD_ENABLE, &cmdInfo, &replyInfo); - CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{pubilc}s lib EFFECT_CMD_ENABLE fail", - sceneType_.c_str(), effectMode_.c_str(), libHandle->name); + CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_ENABLE fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); CHECK_AND_RETURN_LOG(SetEffectParamToHandle(handle, currSceneType, replyData) == 0, - "[%{public}s] with mode [%{public}s], %{pubilc}s lib EFFECT_CMD_SET_PARAM fail", sceneType_.c_str(), - effectMode_.c_str(), libHandle->name); + "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_SET_PARAM fail", sceneType_.c_str(), + effectMode_.c_str(), effectName.c_str()); + + if (!effectProperty.empty()) { + const char *propCstr = effectProperty.c_str(); + cmdInfo = {sizeof(const char *), &propCstr}; + ret = (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); + CHECK_AND_RETURN_LOG(ret == 0, + "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_SET_PROPERTY fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); + } cmdInfo = {sizeof(AudioEffectConfig), &ioBufferConfig_}; ret = (*handle)->command(handle, EFFECT_CMD_SET_CONFIG, &cmdInfo, &replyInfo); - CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{pubilc}s lib EFFECT_CMD_SET_CONFIG fail", - sceneType_.c_str(), effectMode_.c_str(), libHandle->name); + CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_SET_CONFIG fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); ret = (*handle)->command(handle, EFFECT_CMD_GET_CONFIG, &cmdInfo, &cmdInfo); - CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{pubilc}s lib EFFECT_CMD_GET_CONFIG fail", - sceneType_.c_str(), effectMode_.c_str(), libHandle->name); + CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], %{public}s effect EFFECT_CMD_GET_CONFIG fail", + sceneType_.c_str(), effectMode_.c_str(), effectName.c_str()); Swap(ioBufferConfig_.inputCfg, ioBufferConfig_.outputCfg); // pass outputCfg to next algo as inputCfg standByEffectHandles_.emplace_back(handle); + effectNames_.emplace_back(effectName); libHandles_.emplace_back(libHandle); latency_ += static_cast(replyData); } diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 6fb977b079..c01bf7b9b6 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -88,6 +88,7 @@ AudioEffectChainManager::AudioEffectChainManager() SceneTypeToSessionIDMap_.clear(); SessionIDToEffectInfoMap_.clear(); SceneTypeToEffectChainCountBackupMap_.clear(); + effectPropertyMap_.clear(); deviceType_ = DEVICE_TYPE_SPEAKER; deviceSink_ = DEFAULT_DEVICE_SINK; isInitialized_ = false; @@ -250,9 +251,10 @@ void AudioEffectChainManager::InitHdiState() // Boot initialize void AudioEffectChainManager::InitAudioEffectChainManager(std::vector &effectChains, - std::unordered_map &map, + const EffectChainManagerParam &effectChainManagerParam, std::vector> &effectLibraryList) { + const std::unordered_map &map = effectChainManagerParam.sceneTypeToChainNameMap; std::set effectSet; for (EffectChain efc: effectChains) { for (std::string effect: efc.apply) { @@ -285,6 +287,8 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorfirst] = item->second; } + // Construct effectPropertyMap_ that stores effect's property + effectPropertyMap_ = effectChainManagerParam.effectDefaultProperty; AUDIO_INFO_LOG("EffectToLibraryEntryMap size %{public}zu", EffectToLibraryEntryMap_.size()); AUDIO_DEBUG_LOG("EffectChainToEffectsMap size %{public}zu", EffectChainToEffectsMap_.size()); @@ -385,7 +389,7 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(const std::string &s GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType))); } audioEffectChain->AddEffectHandle(handle, EffectToLibraryEntryMap_[effect]->audioEffectLibHandle, - currSceneType); + currSceneType, effect, ""); } audioEffectChain->ResetIoBufferConfig(); @@ -1344,5 +1348,39 @@ bool AudioEffectChainManager::CheckIfSpkDsp() } return true; } + +int32_t AudioEffectChainManager::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + for (const auto &property : propertyArray.property) { + auto item = effectPropertyMap_.find(property.effectClass); + if (item == effectPropertyMap_.end()) { + effectPropertyMap_[property.effectClass] = property.effectProp; + } else { + if (item->second == property.effectProp) { + AUDIO_INFO_LOG("No need to update effect %{public}s with mode %{public}s", + property.effectClass.c_str(), property.effectProp.c_str()); + continue; + } + item->second = property.effectProp; + } + for (const auto &[sceneType, effectChain] : SceneTypeToEffectChainMap_) { + if (effectChain) { + effectChain->SetEffectProperty(property.effectClass, property.effectProp); + } + } + } + return AUDIO_OK; +} + +int32_t AudioEffectChainManager::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + propertyArray.property.clear(); + for (const auto &[effect, prop] : effectPropertyMap_) { + if (!prop.empty()) { + propertyArray.property.emplace_back(AudioEffectProperty{effect, prop}); + } + } + return AUDIO_OK; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp index 5a90c1ebef..74cd32dc15 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp @@ -19,6 +19,7 @@ #include "audio_enhance_chain.h" #include +#include #include "securec.h" #include "audio_log.h" @@ -222,5 +223,27 @@ int32_t AudioEnhanceChain::ApplyEnhanceChain(std::unique_ptr &enh return SUCCESS; } +int32_t AudioEnhanceChain::SetAudioEnhanceProperty(const std::string &effect, const std::string &property) +{ + std::lock_guard lock(chainMutex_); + int32_t ret = 0; + int32_t size = standByEnhanceHandles_.size(); + for (int32_t index = 0; index < size; index++) { + auto &handle = standByEnhanceHandles_[index]; + auto const &effectName = effectNames_[index]; + if (effect == effectName) { + int32_t replyData = 0; + const char *propCstr = property.c_str(); + AudioEffectTransInfo cmdInfo = {sizeof(const char *), reinterpret_cast(&propCstr)}; + AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + ret = (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); + CHECK_AND_RETURN_RET_LOG(ret == 0, ret, + "[%{public}s] %{public}s effect EFFECT_CMD_SET_PROPERTY fail", + sceneType_.c_str(), effectName.c_str()); + } + } + return ret; +} + } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index fc14b98171..6145797258 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -85,9 +85,9 @@ AudioEnhanceChainManager *AudioEnhanceChainManager::GetInstance() } void AudioEnhanceChainManager::InitAudioEnhanceChainManager(std::vector &enhanceChains, - std::unordered_map &enhanceChainNameMap, - std::vector> &enhanceLibraryList) + const EffectChainManagerParam &managerParam, std::vector> &enhanceLibraryList) { + const std::unordered_map &enhanceChainNameMap = managerParam.sceneTypeToChainNameMap; std::lock_guard lock(chainManagerMutex_); std::set enhanceSet; for (EffectChain enhanceChain : enhanceChains) { @@ -118,6 +118,9 @@ void AudioEnhanceChainManager::InitAudioEnhanceChainManager(std::vectorfirst] = item->second; } + // Construct effectPropertyMap_ that stores effect's property + effectPropertyMap_ = managerParam.effectDefaultProperty; + AUDIO_INFO_LOG("enhanceToLibraryEntryMap_ size %{public}zu \ enhanceToLibraryNameMap_ size %{public}zu \ sceneTypeAndModeToEnhanceChainNameMap_ size %{public}zu", @@ -429,5 +432,42 @@ int32_t AudioEnhanceChainManager::SetStreamVolumeInfo(const uint32_t &sessionId, AUDIO_INFO_LOG("success, sessionId: %{public}d, streamVol: %{public}f", sessionId_, streamVol_); return SUCCESS; } + +int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + return AUDIO_OK; + int32_t ret = 0; + for (const auto &property : propertyArray.property) { + auto item = effectPropertyMap_.find(property.enhanceClass); + if (item == effectPropertyMap_.end()) { + effectPropertyMap_[property.enhanceClass] = property.enhanceProp; + } else { + if (item->second == property.enhanceProp) { + AUDIO_INFO_LOG("No need to update effect %{public}s with mode %{public}s", + property.enhanceClass.c_str(), property.enhanceProp.c_str()); + continue; + } + item->second = property.enhanceProp; + } + for (const auto &[sceneType, enhanceChain] : sceneTypeToEnhanceChainMap_) { + if (enhanceChain) { + ret = enhanceChain->SetAudioEnhanceProperty(property.enhanceClass, property.enhanceProp); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "set property failed"); + } + } + } + return ret; +} + +int32_t AudioEnhanceChainManager::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + propertyArray.property.clear(); + for (const auto &[effect, prop] : effectPropertyMap_) { + if (!prop.empty()) { + propertyArray.property.emplace_back(AudioEnhanceProperty{effect, prop}); + } + } + return AUDIO_OK; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 30992aeb53..bfc6c019c7 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -382,6 +382,13 @@ public: int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType); int32_t ResetRingerModeMute(); + + int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray); + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); private: AudioPolicyManager() {} ~AudioPolicyManager() {} diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 22de0be68d..09d87a50b2 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -39,6 +39,9 @@ constexpr int32_t AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT = 1; constexpr int32_t AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT = 64; // max conf for sceneType + effectMode + deviceType constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32; // max num of effectChain constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; // max num of effect per effectChain +constexpr int32_t AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT = 20; // max num of property + +constexpr int32_t MAX_PARA_LEN = 20; constexpr int32_t HDI_EFFECT_NUM = 2; constexpr int32_t HDI_SET_PATAM = 6; @@ -255,6 +258,52 @@ const std::unordered_map SUPPORTED_DEVICE_TYPE { {DEVICE_TYPE_DEFAULT, "DEVICE_TYPE_DEFAULT"}, }; +struct AudioEnhanceProperty { + std::string enhanceClass; + std::string enhanceProp; + friend bool operator==(const AudioEnhanceProperty &lhs, const AudioEnhanceProperty &rhs) + { + return lhs.enhanceClass == rhs.enhanceClass && lhs.enhanceProp == rhs.enhanceProp; + } + bool Marshalling(Parcel &parcel) const + { + return parcel.WriteString(enhanceClass)&& + parcel.WriteString(enhanceProp); + } + void Unmarshalling(Parcel &parcel) + { + enhanceClass = parcel.ReadString(); + enhanceProp = parcel.ReadString(); + } +}; + +struct AudioEnhancePropertyArray { + std::vector property; +}; + +struct AudioEffectProperty { + std::string effectClass; + std::string effectProp; + friend bool operator==(const AudioEffectProperty &lhs, const AudioEffectProperty &rhs) + { + return lhs.effectClass == rhs.effectClass && lhs.effectProp == rhs.effectProp; + } + bool Marshalling(Parcel &parcel) const + { + return parcel.WriteString(effectClass)&& + parcel.WriteString(effectProp); + } + void Unmarshalling(Parcel &parcel) + { + effectClass = parcel.ReadString(); + effectProp = parcel.ReadString(); + } +}; + +struct AudioEffectPropertyArray { + std::vector property; +}; + enum AudioEffectCommandCode { EFFECT_CMD_INIT = 0, EFFECT_CMD_SET_CONFIG = 1, @@ -263,7 +312,8 @@ enum AudioEffectCommandCode { EFFECT_CMD_SET_PARAM = 4, EFFECT_CMD_GET_PARAM = 5, EFFECT_CMD_GET_CONFIG = 6, - EFFECT_CMD_SET_IMU = 7 + EFFECT_CMD_SET_IMU = 7, + EFFECT_CMD_SET_PROPERTY = 8 }; enum AudioEffectParamSetCode { @@ -285,6 +335,18 @@ struct AudioEffectParam { int32_t data[]; }; +struct AudioEnhanceParam { + uint32_t volumeInfo; + uint32_t isMute; + const char *upDeivce; + const char *downDeivce; +}; + +struct EffectChainManagerParam { + std::unordered_map sceneTypeToChainNameMap; + std::unordered_map effectDefaultProperty; +}; + struct AudioBuffer { size_t frameLength; union { diff --git a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h index b4d995877e..1be6542518 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h @@ -224,6 +224,66 @@ public: */ int32_t GetEffectInfoArray(AudioSceneEffectInfo &audioSceneEffectInfo, StreamUsage streamUsage); + /** + * @brief Get Audio render Effect param. + * + * @param AudioSceneEffectInfo AudioSceneEffectInfo + * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + + /** + * @brief Get Audio Capture Effect param. + * + * @param AudioSceneEffectInfo AudioSceneEffectInfo + * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); + + /** + * @brief Sets the audio effect Param. + * + * * @param effectParam The audio effect Param at which the stream needs to be rendered. + * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray); + + /** + * @brief Gets the audio effect Param. + * + * * @param effectParam The audio effect moParamde at which the stream needs to be rendered. + * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + + /** + * @brief Sets the audio effect Param. + * + * * @param effectParam The audio effect Param at which the stream needs to be rendered. + * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); + + /** + * @brief Gets the audio effect Param. + * + * * @param effectParam The audio effect moParamde at which the stream needs to be rendered. + * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code + * defined in {@link audio_errors.h} otherwise. + * @since 13 + */ + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); + /** * @brief Is stream active. * diff --git a/services/audio_policy/client/include/audio_policy_base.h b/services/audio_policy/client/include/audio_policy_base.h index 1fdb8d048f..4899ffe499 100644 --- a/services/audio_policy/client/include/audio_policy_base.h +++ b/services/audio_policy/client/include/audio_policy_base.h @@ -301,6 +301,19 @@ public: virtual int32_t MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType) = 0; virtual int32_t ResetRingerModeMute() = 0; + + virtual int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0; + + virtual int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) = 0; + + virtual int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) = 0; + + virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0; + + virtual int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) = 0; + + virtual int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) = 0; + public: DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicy"); }; diff --git a/services/audio_policy/client/include/audio_policy_manager_stub.h b/services/audio_policy/client/include/audio_policy_manager_stub.h index 0fde1ba0ea..200b00dbd9 100644 --- a/services/audio_policy/client/include/audio_policy_manager_stub.h +++ b/services/audio_policy/client/include/audio_policy_manager_stub.h @@ -152,6 +152,12 @@ private: void SetRingerStreamMuteInternal(MessageParcel &data, MessageParcel &reply); void SetMicrophoneMutePersistentInternal(MessageParcel &data, MessageParcel &reply); void GetMicrophoneMutePersistentInternal(MessageParcel &data, MessageParcel &reply); + void GetSupportedAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply); + void GetSupportedAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply); + void SetAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply); + void GetAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply); + void SetAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply); + void GetAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply); using HandlerFunc = void(AudioPolicyManagerStub::*)(MessageParcel &data, MessageParcel &reply); static inline HandlerFunc handlers[] = { @@ -278,6 +284,12 @@ private: &AudioPolicyManagerStub::SetRingerStreamMuteInternal, &AudioPolicyManagerStub::SetMicrophoneMutePersistentInternal, &AudioPolicyManagerStub::GetMicrophoneMutePersistentInternal, + &AudioPolicyManagerStub::GetSupportedAudioEnhancePropertyInternal, + &AudioPolicyManagerStub::GetSupportedAudioEffectPropertyInternal, + &AudioPolicyManagerStub::GetAudioEnhancePropertyInternal, + &AudioPolicyManagerStub::GetAudioEffectPropertyInternal, + &AudioPolicyManagerStub::SetAudioEnhancePropertyInternal, + &AudioPolicyManagerStub::SetAudioEffectPropertyInternal, }; static constexpr size_t handlersNums = sizeof(handlers) / sizeof(HandlerFunc); static_assert(handlersNums == (static_cast (AudioPolicyInterfaceCode::AUDIO_POLICY_MANAGER_CODE_MAX) + 1), diff --git a/services/audio_policy/client/include/audio_policy_proxy.h b/services/audio_policy/client/include/audio_policy_proxy.h index c95ee9ecf7..18a4f2a32c 100644 --- a/services/audio_policy/client/include/audio_policy_proxy.h +++ b/services/audio_policy/client/include/audio_policy_proxy.h @@ -288,6 +288,19 @@ public: int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType) override; int32_t ResetRingerModeMute() override; + + int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + + int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; + + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override; + + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) override; + + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; + private: static inline BrokerDelegator mDdelegator; void WriteStreamChangeInfo(MessageParcel &data, const AudioMode &mode, diff --git a/services/audio_policy/client/src/audio_policy_manager.cpp b/services/audio_policy/client/src/audio_policy_manager.cpp index 76f73a1f91..27f9344bc1 100644 --- a/services/audio_policy/client/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/src/audio_policy_manager.cpp @@ -1726,5 +1726,48 @@ AudioPolicyManager& AudioPolicyManager::GetInstance() static AudioPolicyManager policyManager; return policyManager; } + +int32_t AudioPolicyManager::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->GetSupportedAudioEffectProperty(propertyArray); +} + +int32_t AudioPolicyManager::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->GetSupportedAudioEnhanceProperty(propertyArray); +} + +int32_t AudioPolicyManager::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->SetAudioEffectProperty(propertyArray); +} + +int32_t AudioPolicyManager::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->GetAudioEffectProperty(propertyArray); +} + +int32_t AudioPolicyManager::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->SetAudioEnhanceProperty(propertyArray); +} + +int32_t AudioPolicyManager::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); + return gsp->GetAudioEnhanceProperty(propertyArray); +} + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/client/src/audio_policy_proxy.cpp b/services/audio_policy/client/src/audio_policy_proxy.cpp index f33ac067ee..b8be1b242a 100644 --- a/services/audio_policy/client/src/audio_policy_proxy.cpp +++ b/services/audio_policy/client/src/audio_policy_proxy.cpp @@ -2253,5 +2253,139 @@ int32_t AudioPolicyProxy::ResetRingerModeMute() CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate concurrency failed, error: %{public}d", error); return reply.ReadInt32(); } + +int32_t AudioPolicyProxy::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_ENHANCE_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Enhance Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + // write and read must keep same order + AudioEnhanceProperty prop = {}; + prop.Unmarshalling(reply); + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioPolicyProxy::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_EFFECT_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Effect Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEffectProperty prop = {}; + prop.Unmarshalling(reply); + // write and read must keep same order + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioPolicyProxy::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Enhance Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + // write and read must keep same order + AudioEnhanceProperty prop = {}; + prop.Unmarshalling(reply); + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioPolicyProxy::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::GET_AUDIO_EFFECT_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEffectProperty prop = {}; + prop.Unmarshalling(reply); + // write and read must keep same order + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioPolicyProxy::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); + + int32_t size = static_cast(propertyArray.property.size()); + data.WriteInt32(size); + for (int32_t i = 0; i < size; i++) { + // write and read must keep same order + propertyArray.property[i].Marshalling(data); + } + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + +int32_t AudioPolicyProxy::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); + + int32_t size = static_cast(propertyArray.property.size()); + data.WriteInt32(size); + for (int32_t i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(data); + } + int32_t error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::SET_AUDIO_EFFECT_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h index a2b2a044ff..7e95544c5d 100644 --- a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h +++ b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h @@ -143,7 +143,13 @@ enum class AudioPolicyInterfaceCode { SET_RINGER_MODE_MUTE, SET_MICROPHONE_MUTE_PERSISTENT, GET_MICROPHONE_MUTE_PERSISTENT, - AUDIO_POLICY_MANAGER_CODE_MAX = GET_MICROPHONE_MUTE_PERSISTENT, + GET_SUPPORT_AUDIO_ENHANCE_PROPERTY, + GET_SUPPORT_AUDIO_EFFECT_PROPERTY, + GET_AUDIO_ENHANCE_PROPERTY, + GET_AUDIO_EFFECT_PROPERTY, + SET_AUDIO_ENHANCE_PROPERTY, + SET_AUDIO_EFFECT_PROPERTY, + AUDIO_POLICY_MANAGER_CODE_MAX = SET_AUDIO_EFFECT_PROPERTY, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/include/audio_policy_server.h b/services/audio_policy/server/include/audio_policy_server.h index 583168d226..08b98ce917 100644 --- a/services/audio_policy/server/include/audio_policy_server.h +++ b/services/audio_policy/server/include/audio_policy_server.h @@ -242,6 +242,13 @@ public: int32_t GetVolumeGroupInfos(std::string networkId, std::vector> &infos) override; + int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override; + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) override; + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; + int32_t GetNetworkIdByGroupId(int32_t groupId, std::string &networkId) override; std::vector> GetPreferredOutputDeviceDescriptors( diff --git a/services/audio_policy/server/include/service/audio_policy_service.h b/services/audio_policy/server/include/service/audio_policy_service.h index 8dd2f2e878..7eacc82144 100644 --- a/services/audio_policy/server/include/service/audio_policy_service.h +++ b/services/audio_policy/server/include/service/audio_policy_service.h @@ -518,6 +518,14 @@ public: bool IsRingerModeMute(); void OnReceiveBluetoothEvent(const std::string macAddress, const std::string deviceName); + // for effect + int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray); + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray); + // for enhance + int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); private: AudioPolicyService() :audioPolicyManager_(AudioPolicyManagerFactory::GetAudioPolicyManager()), diff --git a/services/audio_policy/server/include/service/effect/audio_effect_manager.h b/services/audio_policy/server/include/service/effect/audio_effect_manager.h index 89ddc115f0..421862c969 100644 --- a/services/audio_policy/server/include/service/effect/audio_effect_manager.h +++ b/services/audio_policy/server/include/service/effect/audio_effect_manager.h @@ -43,6 +43,11 @@ public: void ConstructEffectChainManagerParam(EffectChainManagerParam &effectChainMgrParam); void ConstructEnhanceChainManagerParam(EffectChainManagerParam &enhanceChainMgrParam); int32_t QueryEffectManagerSceneMode(SupportedEffectConfig &supportedEffectConfig); + int32_t GetSupportedAudioEffectProperty(const DeviceType& deviceType, + std::set> &mergedSet); + int32_t GetSupportedAudioEnhanceProperty(const DeviceType& deviceType, + std::set> &mergedSet); + private: OriginalEffectConfig oriEffectConfig_; std::vector availableEffects_; @@ -51,6 +56,10 @@ private: bool isMasterSinkAvailable_ = false; bool isEffectChainManagerAvailable_ = false; std::vector postSceneTypeSet_; + std::unordered_map>> device2EffectPropertySet_; + std::unordered_map>> device2EnhancePropertySet_; + std::unordered_map effectDefaultProperty_; + std::unordered_map enhanceDefaultProperty_; void UpdateAvailableAEConfig(OriginalEffectConfig &aeConfig); void UpdateEffectChains(std::vector &availableLayout); @@ -61,6 +70,8 @@ private: void UpdateDuplicateDevice(ProcessNew &processNew); int32_t UpdateUnavailableEffectChains(std::vector &availableLayout, ProcessNew &processNew); bool VerifySceneMappingItem(const SceneMappingItem &item); + void UpdateSupportedEffectProperty(ProcessNew &processnew, + std::unordered_map>> &device2PropertySet); }; } // namespce AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/src/audio_policy_manager_stub.cpp b/services/audio_policy/server/src/audio_policy_manager_stub.cpp index 8af064c780..58ec120a0d 100644 --- a/services/audio_policy/server/src/audio_policy_manager_stub.cpp +++ b/services/audio_policy/server/src/audio_policy_manager_stub.cpp @@ -150,6 +150,12 @@ const char *g_audioPolicyCodeStrs[] = { "SET_RINGER_MODE_MUTE", "SET_MICROPHONE_MUTE_PERSISTENT", "GET_MICROPHONE_MUTE_PERSISTENT", + "GET_SUPPORT_AUDIO_ENHANCE_PROPERTY", + "GET_SUPPORT_AUDIO_EFFECT_PROPERTY", + "GET_AUDIO_ENHANCE_PROPERTY", + "GET_AUDIO_EFFECT_PROPERTY", + "SET_AUDIO_ENHANCE_PROPERTY", + "SET_AUDIO_EFFECT_PROPERTY", }; constexpr size_t codeNums = sizeof(g_audioPolicyCodeStrs) / sizeof(const char *); static_assert(codeNums == (static_cast (AudioPolicyInterfaceCode::AUDIO_POLICY_MANAGER_CODE_MAX) + 1), @@ -1340,5 +1346,84 @@ void AudioPolicyManagerStub::GetMicrophoneMutePersistentInternal(MessageParcel & bool result = GetPersistentMicMuteState(); reply.WriteBool(result); } + +void AudioPolicyManagerStub::GetSupportedAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + AudioEnhancePropertyArray propertyArray = {}; + int32_t result = GetSupportedAudioEnhanceProperty(propertyArray); + int32_t size = propertyArray.property.size(); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return; +} + +void AudioPolicyManagerStub::GetSupportedAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + AudioEffectPropertyArray propertyArray = {}; + int32_t result = GetSupportedAudioEffectProperty(propertyArray); + int32_t size = propertyArray.property.size(); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return; +} + +void AudioPolicyManagerStub::SetAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + int32_t size = data.ReadInt32(); + AudioEffectPropertyArray propertyArray = {}; + for (int i = 0; i < size; i++) { + AudioEffectProperty prop = {}; + prop.Unmarshalling(data); + propertyArray.property.push_back(prop); + } + int32_t result = SetAudioEffectProperty(propertyArray); + reply.WriteInt32(result); +} + +void AudioPolicyManagerStub::GetAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + AudioEffectPropertyArray propertyArray = {}; + int32_t result = GetAudioEffectProperty(propertyArray); + int32_t size = propertyArray.property.size(); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return; +} + +void AudioPolicyManagerStub::SetAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + int32_t size = data.ReadInt32(); + AudioEnhancePropertyArray propertyArray = {}; + for (int i = 0; i < size; i++) { + AudioEnhanceProperty prop = {}; + prop.Unmarshalling(data); + propertyArray.property.push_back(prop); + } + int32_t result = SetAudioEnhanceProperty(propertyArray); + reply.WriteInt32(result); +} + +void AudioPolicyManagerStub::GetAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply) +{ + AudioEnhancePropertyArray propertyArray = {}; + int32_t result = GetAudioEnhanceProperty(propertyArray); + int32_t size = propertyArray.property.size(); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return; +} + } // namespace audio_policy } // namespace OHOS diff --git a/services/audio_policy/server/src/audio_policy_server.cpp b/services/audio_policy/server/src/audio_policy_server.cpp index f3ef3baa4f..474097b9b4 100644 --- a/services/audio_policy/server/src/audio_policy_server.cpp +++ b/services/audio_policy/server/src/audio_policy_server.cpp @@ -2783,5 +2783,42 @@ void AudioPolicyServer::UnregisterCommonEventReceiver() AUDIO_INFO_LOG("unregister bluetooth device name commonevent"); } } +int32_t AudioPolicyServer::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.GetSupportedAudioEffectProperty(propertyArray); +} +int32_t AudioPolicyServer::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.GetSupportedAudioEnhanceProperty(propertyArray); +} +int32_t AudioPolicyServer::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.GetAudioEnhanceProperty(propertyArray); +} + +int32_t AudioPolicyServer::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.SetAudioEnhanceProperty(propertyArray); +} +int32_t AudioPolicyServer::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.SetAudioEffectProperty(propertyArray); +} +int32_t AudioPolicyServer::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + bool ret = PermissionUtil::VerifySystemPermission(); + CHECK_AND_RETURN_RET_LOG(ret, ERR_SYSTEM_PERMISSION_DENIED, "No system permission"); + return audioPolicyService_.GetAudioEffectProperty(propertyArray); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index de63356f10..5e521ee522 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -4456,14 +4456,14 @@ void AudioPolicyService::LoadEffectLibrary() // Initialize EffectChainManager in audio service through IPC SupportedEffectConfig supportedEffectConfig; audioEffectManager_.GetSupportedEffectConfig(supportedEffectConfig); - std::unique_ptr effectChainMgrParam = std::make_unique(); - std::unique_ptr enhanceChainMgrParam = std::make_unique(); - audioEffectManager_.ConstructEffectChainManagerParam(*effectChainMgrParam); - audioEffectManager_.ConstructEnhanceChainManagerParam(*enhanceChainMgrParam); + EffectChainManagerParam effectChainManagerParam; + EffectChainManagerParam enhanceChainManagerParam; + audioEffectManager_.ConstructEffectChainManagerParam(effectChainManagerParam); + audioEffectManager_.ConstructEnhanceChainManagerParam(enhanceChainManagerParam); identity = IPCSkeleton::ResetCallingIdentity(); bool ret = gsp->CreateEffectChainManager(supportedEffectConfig.effectChains, - effectChainMgrParam->sceneTypeToChainNameMap, enhanceChainMgrParam->sceneTypeToChainNameMap); + effectChainManagerParam, enhanceChainManagerParam); IPCSkeleton::SetCallingIdentity(identity); CHECK_AND_RETURN_LOG(ret, "EffectChainManager create failed"); @@ -8423,5 +8423,77 @@ void AudioPolicyService::LoadHdiEffectModel() gsp->LoadHdiEffectModel(); IPCSkeleton::SetCallingIdentity(identity); } + +int32_t AudioPolicyService::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + std::set> mergedSet = {}; + // Get supported property for all device + audioEffectManager_.GetSupportedAudioEnhanceProperty(DEVICE_TYPE_INVALID, mergedSet); + std::vector> descriptor = GetDevices(OUTPUT_DEVICES_FLAG); + for (auto &item : descriptor) { + audioEffectManager_.GetSupportedAudioEffectProperty(item->getType(), mergedSet); + } + std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), + [](const std::pair& p) { + return AudioEffectProperty{p.first, p.second}; + }); + return AUDIO_OK; +} + +int32_t AudioPolicyService::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + std::set> mergedSet = {}; + // Get supported property for all device + audioEffectManager_.GetSupportedAudioEnhanceProperty(DEVICE_TYPE_INVALID, mergedSet); + std::vector> descriptor = GetDevices(INPUT_DEVICES_FLAG); + for (auto &item : descriptor) { + audioEffectManager_.GetSupportedAudioEnhanceProperty(item->getType(), mergedSet); + } + std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), + [](const std::pair& p) { + return AudioEnhanceProperty{p.first, p.second}; + }); + return AUDIO_OK; +} + +int32_t AudioPolicyService::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + const sptr gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Set Audio Effect Property: gsp null"); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = gsp->SetAudioEffectProperty(propertyArray); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} + +int32_t AudioPolicyService::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + const sptr gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Get Audio Effect Property: gsp null"); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = gsp->GetAudioEffectProperty(propertyArray); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} + +int32_t AudioPolicyService::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + const sptr gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Set Audio Enhance Property: gsp null"); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = gsp->SetAudioEnhanceProperty(propertyArray); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} + +int32_t AudioPolicyService::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + const sptr gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Get Audio Enhance Property: gsp null"); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = gsp->GetAudioEnhanceProperty(propertyArray); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index df60a22fd2..c33dee0f01 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -485,6 +485,45 @@ int32_t AudioEffectManager::UpdateUnavailableEffectChains(std::vector>> &device2PropertySet) +{ + for (auto &stream : processnew.stream) { + for (auto &streamMode : stream.streamEffectMode) { + for (auto &device : streamMode.devicePort) { + auto chainName = device.chain; + auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), + supportedEffectConfig_.effectChains.end(), + [&chainName](const EffectChain& x) { + return x.name == chainName; + }); + if (effectChain == supportedEffectConfig_.effectChains.end()) { + continue; + } + for (auto &effectName : effectChain->apply) { + auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), + [&effectName](const Effect& effect) { + return effect.name == effectName; + }); + if (effectIter == availableEffects_.end()) { + continue; + } + for (auto &property : effectIter->effectProperty) { + auto deviceIter = device2PropertySet.find(device.type); + if (deviceIter == device2PropertySet.end()) { + device2PropertySet[device.type].insert({effectIter->name, property}); + } else { + deviceIter->second.insert({effectIter->name, property}); + } + AUDIO_INFO_LOG("device %{public}s support effect [%{public}s, %{public}s]", + device.type.c_str(), effectIter->name.c_str(), property.c_str()); + } + } + } + } + } +} + void AudioEffectManager::BuildAvailableAEConfig() { int32_t ret = 0 ; @@ -536,6 +575,8 @@ void AudioEffectManager::BuildAvailableAEConfig() if (ret != 0) { existDefault_ = -1; } + UpdateSupportedEffectProperty(supportedEffectConfig_.preProcessNew, device2EnhancePropertySet_); + UpdateSupportedEffectProperty(supportedEffectConfig_.postProcessNew, device2EffectPropertySet_); } void AudioEffectManager::SetMasterSinkAvailable() @@ -570,6 +611,8 @@ void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerPara std::string sceneType; std::string sceneMode; std::string key; + std::unordered_map &effectDefaultProperty = effectChainMgrParam.effectDefaultProperty; + for (auto &scene: supportedEffectConfig_.postProcessNew.stream) { sceneType = scene.scene; if (scene.priority == PRIOR_SCENE) { @@ -583,6 +626,36 @@ void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerPara for (auto &device: mode.devicePort) { key = sceneType + "_&_" + sceneMode + "_&_" + device.type; AddKeyValueIntoMap(map, key, device.chain); + auto chainName = device.chain; + auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), + supportedEffectConfig_.effectChains.end(), + [&chainName](const EffectChain& x) { + return x.name == chainName; + }); + if (effectChain == supportedEffectConfig_.effectChains.end()) { + continue; + } + for (auto &effectName : effectChain->apply) { + auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), + [&effectName](const Effect& effect) { + return effect.name == effectName; + }); + if (effectIter == availableEffects_.end()) { + continue; + } + // if 0 property, no need to set default + for (auto &property : effectIter->effectProperty) { + auto it = effectDefaultProperty.find(effectIter->name); + // first assign, and no need to assign twice + if (it == effectDefaultProperty.end()) { + effectDefaultProperty[effectIter->name] = property; + AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", + effectIter->name.c_str(), property.c_str()); + } + // only first property is default set + break; + } + } } } } @@ -598,6 +671,8 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar std::string sceneType; std::string sceneMode; std::string key; + std::unordered_map &enhanceDefaultProperty = enhanceChainMgrParam.effectDefaultProperty; + for (auto &scene: supportedEffectConfig_.preProcessNew.stream) { sceneType = scene.scene; @@ -613,6 +688,36 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar for (auto &device: mode.devicePort) { key = sceneType + "_&_" + sceneMode; AddKeyValueIntoMap(map, key, device.chain); + auto chainName = device.chain; + auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), + supportedEffectConfig_.effectChains.end(), + [&chainName](const EffectChain& x) { + return x.name == chainName; + }); + if (effectChain == supportedEffectConfig_.effectChains.end()) { + continue; + } + for (auto &effectName : effectChain->apply) { + auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), + [&effectName](const Effect& effect) { + return effect.name == effectName; + }); + if (effectIter == availableEffects_.end()) { + continue; + } + // if 0 property, no need to set default + for (auto &property : effectIter->effectProperty) { + auto it = enhanceDefaultProperty.find(effectIter->name); + // first assign, and no need to assign twice + if (it == enhanceDefaultProperty.end()) { + enhanceDefaultProperty[effectIter->name] = property; + AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", + effectIter->name.c_str(), property.c_str()); + } + // only first property is default set + break; + } + } } } } @@ -620,5 +725,50 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar (int32_t)map.size()); } +int32_t AudioEffectManager::GetSupportedAudioEffectProperty(const DeviceType &deviceType, + std::set> &mergedSet) +{ + auto deviceIter = SUPPORTED_DEVICE_TYPE.find(deviceType); + if (deviceIter == SUPPORTED_DEVICE_TYPE.end()) { + AUDIO_ERR_LOG("device not supported."); + return -1; + } + auto propertySetIter = device2EffectPropertySet_.find(deviceIter->second); + if (propertySetIter != device2EffectPropertySet_.end()) { + mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); + } else { + AUDIO_INFO_LOG("property is empty"); + } + if (deviceType == DEVICE_TYPE_INVALID) { + propertySetIter = device2EffectPropertySet_.find(""); + if (propertySetIter != device2EffectPropertySet_.end()) { + mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); + } + } + return AUDIO_OK; +} + +int32_t AudioEffectManager::GetSupportedAudioEnhanceProperty(const DeviceType &deviceType, + std::set> &mergedSet) +{ + auto deviceIter = SUPPORTED_DEVICE_TYPE.find(deviceType); + if (deviceIter == SUPPORTED_DEVICE_TYPE.end()) { + AUDIO_ERR_LOG("device not supported."); + return -1; + } + auto propertySetIter = device2EnhancePropertySet_.find(deviceIter->second); + if (propertySetIter != device2EnhancePropertySet_.end()) { + mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); + } else { + AUDIO_INFO_LOG("property is empty"); + } + if (deviceType == DEVICE_TYPE_INVALID) { + propertySetIter = device2EnhancePropertySet_.find(""); + if (propertySetIter != device2EnhancePropertySet_.end()) { + mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); + } + } + return AUDIO_OK; +} } // namespce AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/include/audio_manager_base.h b/services/audio_service/client/include/audio_manager_base.h index 04b018cd17..d5aeb4250e 100644 --- a/services/audio_service/client/include/audio_manager_base.h +++ b/services/audio_service/client/include/audio_manager_base.h @@ -310,8 +310,7 @@ public: * @return true/false. */ virtual bool CreateEffectChainManager(std::vector &effectChains, - std::unordered_map &effectMap, - std::unordered_map &enhanceMap) = 0; + const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) = 0; /** * Set output device sink for effect chain manager. @@ -415,6 +414,12 @@ public: // Check if the multi-channel sound effect is working on the DSP virtual bool GetEffectOffloadEnabled() = 0; + // for effect + virtual int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) = 0; + virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0; + // for enhance + virtual int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) = 0; + virtual int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) = 0; /** * Load effect hdi model when audio_host online. @@ -482,6 +487,10 @@ private: int HandleSetAsrVoiceMuteMode(MessageParcel &data, MessageParcel &reply); int HandleIsWhispering(MessageParcel &data, MessageParcel &reply); int HandleGetEffectOffloadEnabled(MessageParcel &data, MessageParcel &reply); + int HandleSetAudioEffectProperty(MessageParcel &data, MessageParcel &reply); + int HandleGetAudioEffectProperty(MessageParcel &data, MessageParcel &reply); + int HandleSetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply); + int HandleGetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply); int HandleSuspendRenderSink(MessageParcel &data, MessageParcel &reply); int HandleRestoreRenderSink(MessageParcel &data, MessageParcel &reply); int HandleLoadHdiEffectModel(MessageParcel &data, MessageParcel &reply); @@ -540,6 +549,10 @@ private: &AudioManagerStub::HandleSetAsrVoiceMuteMode, &AudioManagerStub::HandleIsWhispering, &AudioManagerStub::HandleGetEffectOffloadEnabled, + &AudioManagerStub::HandleGetAudioEnhanceProperty, + &AudioManagerStub::HandleGetAudioEffectProperty, + &AudioManagerStub::HandleSetAudioEnhanceProperty, + &AudioManagerStub::HandleSetAudioEffectProperty, &AudioManagerStub::HandleSuspendRenderSink, &AudioManagerStub::HandleRestoreRenderSink, &AudioManagerStub::HandleLoadHdiEffectModel, diff --git a/services/audio_service/client/include/audio_manager_proxy.h b/services/audio_service/client/include/audio_manager_proxy.h index 3edfe4c594..c3473e6e41 100644 --- a/services/audio_service/client/include/audio_manager_proxy.h +++ b/services/audio_service/client/include/audio_manager_proxy.h @@ -67,8 +67,7 @@ public: std::vector &successEffects) override; void RequestThreadPriority(uint32_t tid, std::string bundleName) override; bool CreateEffectChainManager(std::vector &effectChains, - std::unordered_map &effectMap, - std::unordered_map &enhanceMap) override; + const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) override; void SetOutputDeviceSink(int32_t deviceType, std::string &sinkName) override; bool CreatePlaybackCapturerManager() override; int32_t SetSupportStreamUsage(std::vector usage) override; @@ -93,6 +92,12 @@ public: int32_t IsWhispering() override; bool GetEffectOffloadEnabled() override; void LoadHdiEffectModel() override; + // for effect + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override; + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + // for enhance + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) override; + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; private: static inline BrokerDelegator delegator_; }; diff --git a/services/audio_service/client/include/pulseaudio_ipc_interface_code.h b/services/audio_service/client/include/pulseaudio_ipc_interface_code.h index 2d5f00089f..f15e33f1cf 100644 --- a/services/audio_service/client/include/pulseaudio_ipc_interface_code.h +++ b/services/audio_service/client/include/pulseaudio_ipc_interface_code.h @@ -74,6 +74,10 @@ namespace AudioStandard { SET_ASR_VOICE_MUTE_MODE, IS_WHISPERING, GET_EFFECT_OFFLOAD_ENABLED, + GET_AUDIO_ENHANCE_PROPERTY, + GET_AUDIO_EFFECT_PROPERTY, + SET_AUDIO_ENHANCE_PROPERTY, + SET_AUDIO_EFFECT_PROPERTY, SUSPEND_RENDERSINK, RESTORE_RENDERSINK, LOAD_HDI_EFFECT_MODEL, diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index 6cf8030310..0cc9ca86c1 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -818,8 +818,7 @@ void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName) } bool AudioManagerProxy::CreateEffectChainManager(std::vector &effectChains, - std::unordered_map &effectMap, - std::unordered_map &enhanceMap) + const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) { int32_t error; @@ -849,15 +848,25 @@ bool AudioManagerProxy::CreateEffectChainManager(std::vector &effec } } - dataParcel.WriteInt32(effectMap.size()); - for (auto item = effectMap.begin(); item != effectMap.end(); ++item) { - dataParcel.WriteString(item->first); - dataParcel.WriteString(item->second); + dataParcel.WriteInt32(effectParam.sceneTypeToChainNameMap.size()); + for (auto &[sceneType, effectChain] : effectParam.sceneTypeToChainNameMap) { + dataParcel.WriteString(sceneType); + dataParcel.WriteString(effectChain); } - dataParcel.WriteInt32(enhanceMap.size()); - for (auto item = enhanceMap.begin(); item != enhanceMap.end(); ++item) { - dataParcel.WriteString(item->first); - dataParcel.WriteString(item->second); + dataParcel.WriteInt32(enhanceParam.sceneTypeToChainNameMap.size()); + for (auto &[sceneType, effectChain] : enhanceParam.sceneTypeToChainNameMap) { + dataParcel.WriteString(sceneType); + dataParcel.WriteString(effectChain); + } + dataParcel.WriteInt32(effectParam.effectDefaultProperty.size()); + for (auto &[effect, property] : effectParam.effectDefaultProperty) { + dataParcel.WriteString(effect); + dataParcel.WriteString(property); + } + dataParcel.WriteInt32(enhanceParam.effectDefaultProperty.size()); + for (auto &[effect, property] : enhanceParam.effectDefaultProperty) { + dataParcel.WriteString(effect); + dataParcel.WriteString(property); } error = Remote()->SendRequest( @@ -1130,6 +1139,93 @@ void AudioManagerProxy::UpdateLatencyTimestamp(std::string ×tamp, bool isRe "LatencyMeas UpdateLatencyTimestamp failed, error:%{public}d", error); } +int32_t AudioManagerProxy::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Enhance Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + // write and read must keep same order + AudioEnhanceProperty prop = {}; + prop.Unmarshalling(reply); + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioManagerProxy::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool res = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(res, ERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + int32_t error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error); + + int32_t size = reply.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEffectProperty prop = {}; + prop.Unmarshalling(reply); + // write and read must keep same order + propertyArray.property.push_back(prop); + } + return AUDIO_OK; +} + +int32_t AudioManagerProxy::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, ERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + int32_t size = static_cast(propertyArray.property.size()); + data.WriteInt32(size); + for (int32_t i = 0; i < size; i++) { + // write and read must keep same order + propertyArray.property[i].Marshalling(data); + } + int32_t error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + +int32_t AudioManagerProxy::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, ERR_INVALID_OPERATION, "WriteInterfaceToken failed"); + + int32_t size = static_cast(propertyArray.property.size()); + data.WriteInt32(size); + for (int32_t i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(data); + } + int32_t error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + void AudioManagerProxy::LoadHdiEffectModel() { MessageParcel data; @@ -1143,5 +1239,6 @@ void AudioManagerProxy::LoadHdiEffectModel() static_cast(AudioServerInterfaceCode::LOAD_HDI_EFFECT_MODEL), data, reply, option); CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error); } + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/src/audio_stream_manager.cpp b/services/audio_service/client/src/audio_stream_manager.cpp index c3aee3201a..c0f404a861 100644 --- a/services/audio_service/client/src/audio_stream_manager.cpp +++ b/services/audio_service/client/src/audio_stream_manager.cpp @@ -203,5 +203,36 @@ int32_t AudioStreamManager::GetHardwareOutputSamplingRate(sptr& successEffectList) override; bool CreatePlaybackCapturerManager() override; bool CreateEffectChainManager(std::vector &effectChains, - std::unordered_map &effectMap, - std::unordered_map &enhanceMap) override; + const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) override; void SetOutputDeviceSink(int32_t deviceType, std::string &sinkName) override; int32_t SetMicrophoneMute(bool isMute) override; int32_t SetVoiceVolume(float volume) override; @@ -93,6 +92,13 @@ public: int32_t SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode, bool on) override; int32_t IsWhispering() override; + // for effect + int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override; + int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; + // for enhance + int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) override; + int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; + void NotifyDeviceInfo(std::string networkId, bool connected) override; int32_t CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice) override; diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index b15ab87d34..d195762f66 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -85,6 +85,10 @@ const char *g_audioServerCodeStrs[] = { "SUSPEND_RENDERSINK", "RESTORE_RENDERSINK", "LOAD_HDI_EFFECT_MODEL", + "GET_AUDIO_ENHANCE_PROPERTY", + "GET_AUDIO_EFFECT_PROPERTY", + "SET_AUDIO_ENHANCE_PROPERTY", + "SET_AUDIO_EFFECT_PROPERTY", }; constexpr size_t codeNums = sizeof(g_audioServerCodeStrs) / sizeof(const char *); static_assert(codeNums == (static_cast (AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX) + 1), @@ -475,8 +479,29 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M sceneTypeToEnhanceChainNameMap[key] = value; } - bool createSuccess = CreateEffectChainManager(effectChains, sceneTypeToEffectChainNameMap, - sceneTypeToEnhanceChainNameMap); + unordered_map effectDefaultProperty; + mapSize = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, + AUDIO_ERR, "Create audio effect chain manager failed, please check log"); + for (i = 0; i < mapSize; i++) { + string key = data.ReadString(); + string value = data.ReadString(); + effectDefaultProperty[key] = value; + } + + unordered_map enhanceDefaultProperty; + mapSize = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, + AUDIO_ERR, "Create audio enhance chain manager failed, please check log"); + for (i = 0; i < mapSize; i++) { + string key = data.ReadString(); + string value = data.ReadString(); + enhanceDefaultProperty[key] = value; + } + + bool createSuccess = CreateEffectChainManager(effectChains, + { sceneTypeToEffectChainNameMap, effectDefaultProperty }, + { sceneTypeToEnhanceChainNameMap, enhanceDefaultProperty }); CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR, "Create audio effect chain manager failed, please check log"); return AUDIO_OK; @@ -715,5 +740,68 @@ int AudioManagerStub::HandleLoadHdiEffectModel(MessageParcel &data, MessageParce LoadHdiEffectModel(); return AUDIO_OK; } + +int AudioManagerStub::HandleSetAudioEffectProperty(MessageParcel &data, MessageParcel &reply) +{ + int32_t size = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "Audio enhance property array size invalid"); + AudioEffectPropertyArray propertyArray = {}; + for (int i = 0; i < size; i++) { + AudioEffectProperty prop = {}; + prop.Unmarshalling(data); + propertyArray.property.push_back(prop); + } + int32_t result = SetAudioEffectProperty(propertyArray); + reply.WriteInt32(result); + return AUDIO_OK; +} + +int AudioManagerStub::HandleGetAudioEffectProperty(MessageParcel &data, MessageParcel &reply) +{ + AudioEffectPropertyArray propertyArray = {}; + int32_t result = GetAudioEffectProperty(propertyArray); + int32_t size = propertyArray.property.size(); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "Audio enhance property array size invalid"); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return AUDIO_OK; +} + +int AudioManagerStub::HandleSetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply) +{ + int32_t size = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "Audio enhance property array size invalid"); + AudioEnhancePropertyArray propertyArray = {}; + for (int i = 0; i < size; i++) { + AudioEnhanceProperty prop = {}; + prop.Unmarshalling(data); + propertyArray.property.push_back(prop); + } + int32_t result = SetAudioEnhanceProperty(propertyArray); + reply.WriteInt32(result); + return AUDIO_OK; +} + +int AudioManagerStub::HandleGetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply) +{ + AudioEnhancePropertyArray propertyArray = {}; + int32_t result = GetAudioEnhanceProperty(propertyArray); + int32_t size = propertyArray.property.size(); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "Audio enhance property array size invalid"); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + propertyArray.property[i].Marshalling(reply); + } + reply.WriteInt32(result); + return AUDIO_OK; +} + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/src/audio_server.cpp b/services/audio_service/server/src/audio_server.cpp index 8988f04323..fb8fc82271 100644 --- a/services/audio_service/server/src/audio_server.cpp +++ b/services/audio_service/server/src/audio_server.cpp @@ -911,18 +911,17 @@ bool AudioServer::LoadAudioEffectLibraries(const std::vector libraries, } bool AudioServer::CreateEffectChainManager(std::vector &effectChains, - std::unordered_map &effectMap, - std::unordered_map &enhanceMap) + const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) { int32_t audio_policy_server_id = 1041; if (IPCSkeleton::GetCallingUid() != audio_policy_server_id) { return false; } AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); - audioEffectChainManager->InitAudioEffectChainManager(effectChains, effectMap, + audioEffectChainManager->InitAudioEffectChainManager(effectChains, effectParam, audioEffectServer_->GetEffectEntries()); AudioEnhanceChainManager *audioEnhanceChainManager = AudioEnhanceChainManager::GetInstance(); - audioEnhanceChainManager->InitAudioEnhanceChainManager(effectChains, enhanceMap, + audioEnhanceChainManager->InitAudioEnhanceChainManager(effectChains, enhanceParam, audioEffectServer_->GetEffectEntries()); return true; } @@ -1912,6 +1911,46 @@ void AudioServer::LoadHdiEffectModel() audioEffectChainManager->InitHdiState(); } +int32_t AudioServer::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_, ERR_PERMISSION_DENIED, + "SetA udio Effect Property refused for %{public}d", callingUid); + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERROR, "audioEffectChainManager is nullptr"); + return audioEffectChainManager->SetAudioEffectProperty(propertyArray); +} + +int32_t AudioServer::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_, ERR_PERMISSION_DENIED, + "Get Audio Effect Property refused for %{public}d", callingUid); + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERROR, "audioEffectChainManager is nullptr"); + return audioEffectChainManager->GetAudioEffectProperty(propertyArray); +} + +int32_t AudioServer::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_, ERR_PERMISSION_DENIED, + "Set Audio Enhance Property refused for %{public}d", callingUid); + AudioEnhanceChainManager *audioEnhanceChainManager = AudioEnhanceChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEnhanceChainManager != nullptr, ERROR, "audioEnhanceChainManager is nullptr"); + return audioEnhanceChainManager->SetAudioEnhanceProperty(propertyArray); +} + +int32_t AudioServer::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_, ERR_PERMISSION_DENIED, + "Get Audio Enhance Property refused for %{public}d", callingUid); + AudioEnhanceChainManager *audioEnhanceChainManager = AudioEnhanceChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEnhanceChainManager != nullptr, ERROR, "audioEnhanceChainManager is nullptr"); + return audioEnhanceChainManager->GetAudioEnhanceProperty(propertyArray); +} + int32_t AudioServer::SetVolumeInfoForEnhanceChain(const AudioStreamType &streamType) { AudioEnhanceChainManager *audioEnhanceChainManager = AudioEnhanceChainManager::GetInstance(); -- Gitee From f3bc356363f1c73b881a4704c74223190720734b Mon Sep 17 00:00:00 2001 From: owencreeper Date: Tue, 16 Jul 2024 23:01:53 +0800 Subject: [PATCH 02/18] fix compile err Signed-off-by: owencreeper --- .../inner_api/native/audiocommon/include/audio_effect.h | 5 ----- services/audio_service/server/src/audio_manager_stub.cpp | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 09d87a50b2..2774f8b588 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -342,11 +342,6 @@ struct AudioEnhanceParam { const char *downDeivce; }; -struct EffectChainManagerParam { - std::unordered_map sceneTypeToChainNameMap; - std::unordered_map effectDefaultProperty; -}; - struct AudioBuffer { size_t frameLength; union { diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index d195762f66..6118617c52 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -500,8 +500,9 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M } bool createSuccess = CreateEffectChainManager(effectChains, - { sceneTypeToEffectChainNameMap, effectDefaultProperty }, - { sceneTypeToEnhanceChainNameMap, enhanceDefaultProperty }); + { .sceneTypeToChainNameMap = sceneTypeToEffectChainNameMap, .effectDefaultProperty = effectDefaultProperty }, + { .sceneTypeToChainNameMap = sceneTypeToEnhanceChainNameMap, .effectDefaultProperty = enhanceDefaultProperty } + ); CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR, "Create audio effect chain manager failed, please check log"); return AUDIO_OK; -- Gitee From 9a3574bcaf84b249945b7493e0de39b2e838d1d2 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Fri, 19 Jul 2024 12:38:55 +0800 Subject: [PATCH 03/18] fix Signed-off-by: owencreeper --- .../native/audioeffect/include/audio_enhance_chain.h | 2 +- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 7 ++++++- frameworks/native/audioeffect/src/audio_enhance_chain.cpp | 3 +-- .../native/audioeffect/src/audio_enhance_chain_manager.cpp | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_enhance_chain.h b/frameworks/native/audioeffect/include/audio_enhance_chain.h index 9b5279955b..08a044ae15 100644 --- a/frameworks/native/audioeffect/include/audio_enhance_chain.h +++ b/frameworks/native/audioeffect/include/audio_enhance_chain.h @@ -69,7 +69,7 @@ public: uint32_t GetAlgoBufferSize(); uint32_t GetAlgoBufferSizeEc(); int32_t ApplyEnhanceChain(std::unique_ptr &enhanceBuffer, uint32_t length); - int32_t SetAudioEnhanceProperty(const std::string &effect, const std::string &property); + int32_t SetEnhanceProperty(const std::string &effect, const std::string &property); private: void InitAudioEnhanceChain(); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index c01bf7b9b6..2f15fa21eb 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -388,8 +388,13 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(const std::string &s currSceneType = GetSceneTypeFromSpatializationSceneType(static_cast( GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType))); } + auto propIter = effectPropertyMap_.find(effect); + std::string property = ""; + if (propIter != effectPropertyMap_.end()) { + property = propIter->second; + } audioEffectChain->AddEffectHandle(handle, EffectToLibraryEntryMap_[effect]->audioEffectLibHandle, - currSceneType, effect, ""); + currSceneType, effect, property); } audioEffectChain->ResetIoBufferConfig(); diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp index 74cd32dc15..f547624163 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp @@ -19,7 +19,6 @@ #include "audio_enhance_chain.h" #include -#include #include "securec.h" #include "audio_log.h" @@ -223,7 +222,7 @@ int32_t AudioEnhanceChain::ApplyEnhanceChain(std::unique_ptr &enh return SUCCESS; } -int32_t AudioEnhanceChain::SetAudioEnhanceProperty(const std::string &effect, const std::string &property) +int32_t AudioEnhanceChain::SetEnhanceProperty(const std::string &effect, const std::string &property) { std::lock_guard lock(chainMutex_); int32_t ret = 0; diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index 6145797258..50d18d592c 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -451,7 +451,7 @@ int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhanceProp } for (const auto &[sceneType, enhanceChain] : sceneTypeToEnhanceChainMap_) { if (enhanceChain) { - ret = enhanceChain->SetAudioEnhanceProperty(property.enhanceClass, property.enhanceProp); + ret = enhanceChain->SetEnhanceProperty(property.enhanceClass, property.enhanceProp); CHECK_AND_RETURN_RET_LOG(ret == 0, ERR_OPERATION_FAILED, "set property failed"); } } -- Gitee From cd7be752e9f43f0095216c12384c0d4369245e5d Mon Sep 17 00:00:00 2001 From: owencreeper Date: Fri, 19 Jul 2024 15:14:24 +0800 Subject: [PATCH 04/18] reconstruct ipc Signed-off-by: owencreeper --- .../audioeffect/src/audio_effect_chain.cpp | 1 - .../native/audiocommon/include/audio_effect.h | 1 + .../service/effect/audio_effect_manager.cpp | 100 +++++++----------- .../client/src/audio_manager_proxy.cpp | 45 ++++---- .../server/src/audio_manager_stub.cpp | 84 +++++++-------- 5 files changed, 103 insertions(+), 128 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain.cpp b/frameworks/native/audioeffect/src/audio_effect_chain.cpp index 4a43f9486a..23aa400084 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain.cpp @@ -22,7 +22,6 @@ #include "audio_log.h" #include "audio_utils.h" #include "securec.h" -#include namespace OHOS { namespace AudioStandard { diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 2774f8b588..effa7c4d5f 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -39,6 +39,7 @@ constexpr int32_t AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT = 1; constexpr int32_t AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT = 64; // max conf for sceneType + effectMode + deviceType constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32; // max num of effectChain constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; // max num of effect per effectChain +constexpr int32_t AUDIO_EFFECT_PRIO_SCENE_UPPER_LIMIT = 7; // max num of effect prio scene constexpr int32_t AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT = 20; // max num of property constexpr int32_t MAX_PARA_LEN = 20; diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index c33dee0f01..bad5d55569 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -603,15 +603,49 @@ void AddKeyValueIntoMap(std::unordered_map &map, std::string &ke map[key] = value; } +void AudioEffectManager::ConstructDefaultEffectProperty(const std::string &chainName, + std::unordered_map &effectDefaultProperty) +{ + auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), + supportedEffectConfig_.effectChains.end(), + [&chainName](const EffectChain& x) { + return x.name == chainName; + }); + if (effectChain == supportedEffectConfig_.effectChains.end()) { + continue; + } + for (auto &effectName : effectChain->apply) { + auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), + [&effectName](const Effect& effect) { + return effect.name == effectName; + }); + if (effectIter == availableEffects_.end()) { + continue; + } + // if 0 property, no need to set default + for (auto &property : effectIter->effectProperty) { + auto it = effectDefaultProperty.find(effectIter->name); + // first assign, and no need to assign twice + if (it == effectDefaultProperty.end()) { + effectDefaultProperty[effectIter->name] = property; + AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", + effectIter->name.c_str(), property.c_str()); + } + // only first property is default set + break; + } + } +} + void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerParam &effectChainMgrParam) { std::unordered_map &map = effectChainMgrParam.sceneTypeToChainNameMap; + std::unordered_map &effectDefaultProperty = effectChainMgrParam.effectDefaultProperty; effectChainMgrParam.maxExtraNum = oriEffectConfig_.postProcess.maxExtSceneNum; std::string sceneType; std::string sceneMode; std::string key; - std::unordered_map &effectDefaultProperty = effectChainMgrParam.effectDefaultProperty; for (auto &scene: supportedEffectConfig_.postProcessNew.stream) { sceneType = scene.scene; @@ -626,36 +660,7 @@ void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerPara for (auto &device: mode.devicePort) { key = sceneType + "_&_" + sceneMode + "_&_" + device.type; AddKeyValueIntoMap(map, key, device.chain); - auto chainName = device.chain; - auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), - supportedEffectConfig_.effectChains.end(), - [&chainName](const EffectChain& x) { - return x.name == chainName; - }); - if (effectChain == supportedEffectConfig_.effectChains.end()) { - continue; - } - for (auto &effectName : effectChain->apply) { - auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), - [&effectName](const Effect& effect) { - return effect.name == effectName; - }); - if (effectIter == availableEffects_.end()) { - continue; - } - // if 0 property, no need to set default - for (auto &property : effectIter->effectProperty) { - auto it = effectDefaultProperty.find(effectIter->name); - // first assign, and no need to assign twice - if (it == effectDefaultProperty.end()) { - effectDefaultProperty[effectIter->name] = property; - AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", - effectIter->name.c_str(), property.c_str()); - } - // only first property is default set - break; - } - } + ConstructDefaultEffectProperty(device.chain, effectDefaultProperty); } } } @@ -666,12 +671,12 @@ void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerPara void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerParam &enhanceChainMgrParam) { std::unordered_map &map = enhanceChainMgrParam.sceneTypeToChainNameMap; + std::unordered_map &enhanceDefaultProperty = enhanceChainMgrParam.effectDefaultProperty; enhanceChainMgrParam.maxExtraNum = oriEffectConfig_.preProcess.maxExtSceneNum; std::string sceneType; std::string sceneMode; std::string key; - std::unordered_map &enhanceDefaultProperty = enhanceChainMgrParam.effectDefaultProperty; for (auto &scene: supportedEffectConfig_.preProcessNew.stream) { @@ -688,36 +693,7 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar for (auto &device: mode.devicePort) { key = sceneType + "_&_" + sceneMode; AddKeyValueIntoMap(map, key, device.chain); - auto chainName = device.chain; - auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), - supportedEffectConfig_.effectChains.end(), - [&chainName](const EffectChain& x) { - return x.name == chainName; - }); - if (effectChain == supportedEffectConfig_.effectChains.end()) { - continue; - } - for (auto &effectName : effectChain->apply) { - auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), - [&effectName](const Effect& effect) { - return effect.name == effectName; - }); - if (effectIter == availableEffects_.end()) { - continue; - } - // if 0 property, no need to set default - for (auto &property : effectIter->effectProperty) { - auto it = enhanceDefaultProperty.find(effectIter->name); - // first assign, and no need to assign twice - if (it == enhanceDefaultProperty.end()) { - enhanceDefaultProperty[effectIter->name] = property; - AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", - effectIter->name.c_str(), property.c_str()); - } - // only first property is default set - break; - } - } + ConstructDefaultEffectProperty(device.chain, enhanceDefaultProperty); } } } diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index 0cc9ca86c1..1640ebfe71 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -817,6 +817,29 @@ void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName) CHECK_AND_RETURN_LOG(error == ERR_NONE, "RequestThreadPriority failed, error: %{public}d", error); } +static bool MarshellEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) +{ + bool ret = data.WriteInt32(effectChainMgrParam.maxExtraNum); + ret &&= data.WriteString(effectChainMgrParam.defaultSceneName); + ret &&= data.WriteInt32(effectChainMgrParam.priorSceneList.size()); + for (const auto &prioScene : effectChainMgrParam.priorSceneList) { + ret &&= data.WriteString(prioScene); + } + + ret &&= data.WriteInt32(effectChainMgrParam.sceneTypeToChainNameMap.size()); + for (const auto &[scene, chain] : effectChainMgrParam.sceneTypeToChainNameMap) { + ret &&= data.WriteString(scene); + ret &&= data.WriteString(chain); + } + + ret &&= data.WriteInt32(effectChainMgrParam.effectDefaultProperty.size()); + for (const auto &[effect, prop] : effectChainMgrParam.effectDefaultProperty) { + ret &&= data.WriteString(effect); + ret &&= data.WriteString(prop); + } + return ret; +} + bool AudioManagerProxy::CreateEffectChainManager(std::vector &effectChains, const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) { @@ -848,26 +871,8 @@ bool AudioManagerProxy::CreateEffectChainManager(std::vector &effec } } - dataParcel.WriteInt32(effectParam.sceneTypeToChainNameMap.size()); - for (auto &[sceneType, effectChain] : effectParam.sceneTypeToChainNameMap) { - dataParcel.WriteString(sceneType); - dataParcel.WriteString(effectChain); - } - dataParcel.WriteInt32(enhanceParam.sceneTypeToChainNameMap.size()); - for (auto &[sceneType, effectChain] : enhanceParam.sceneTypeToChainNameMap) { - dataParcel.WriteString(sceneType); - dataParcel.WriteString(effectChain); - } - dataParcel.WriteInt32(effectParam.effectDefaultProperty.size()); - for (auto &[effect, property] : effectParam.effectDefaultProperty) { - dataParcel.WriteString(effect); - dataParcel.WriteString(property); - } - dataParcel.WriteInt32(enhanceParam.effectDefaultProperty.size()); - for (auto &[effect, property] : enhanceParam.effectDefaultProperty) { - dataParcel.WriteString(effect); - dataParcel.WriteString(property); - } + MarshellEffectChainMgrParam(effectParam, dataParcel); + MarshellEffectChainMgrParam(enhanceParam, dataParcel); error = Remote()->SendRequest( static_cast(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER), diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index 6118617c52..8e7be05eac 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -435,6 +435,38 @@ int AudioManagerStub::HandleRequestThreadPriority(MessageParcel &data, MessagePa return AUDIO_OK; } +static bool UnmarshellEffectChainMgrParam(EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) +{ + effectChainMgrParam.maxExtraNum = data.ReadInt32(); + effectChainMgrParam.defaultSceneName = data.ReadString(); + + int32_t containSize = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIO_SCENE_UPPER_LIMIT, + AUDIO_ERR, "Create audio effect prioscene failed, please check log"); + while (containSize--) { + effectChainMgrParam.priorSceneList.emplace_back(data.ReadString()); + } + + containSize = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT, + AUDIO_ERR, "Create audio effect chain name map failed, please check log"); + while (containSize--) { + string key = data.ReadString(); + string value = data.ReadString(); + effectChainMgrParam.sceneTypeToChainNameMap[key] = value; + } + + containSize = data.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, + AUDIO_ERR, "Create audio effect default property failed, please check log"); + while (containSize--) { + string key = data.ReadString(); + string value = data.ReadString(); + effectChainMgrParam.effectDefaultProperty[key] = value; + } + return true; +} + int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, MessageParcel &reply) { int32_t i; @@ -442,11 +474,11 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M vector countEffect = {}; int32_t countChains = data.ReadInt32(); CHECK_AND_RETURN_RET_LOG(countChains >= 0 && countChains <= AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect chain manager failed, please check log"); + AUDIO_ERR, "Create audio effect chains failed, please check log"); for (i = 0; i < countChains; i++) { int32_t count = data.ReadInt32(); CHECK_AND_RETURN_RET_LOG(count >= 0 && count <= AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect chain manager failed, please check log"); + AUDIO_ERR, "Create audio effect chains failed, please check log"); countEffect.emplace_back(count); } @@ -459,50 +491,12 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M effectChains.emplace_back(effectChain); } - unordered_map sceneTypeToEffectChainNameMap; - int32_t mapSize = data.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect chain manager failed, please check log"); - for (i = 0; i < mapSize; i++) { - string key = data.ReadString(); - string value = data.ReadString(); - sceneTypeToEffectChainNameMap[key] = value; - } - - unordered_map sceneTypeToEnhanceChainNameMap; - mapSize = data.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT, - AUDIO_ERR, "Create audio enhance chain manager failed, please check log"); - for (i = 0; i < mapSize; i++) { - string key = data.ReadString(); - string value = data.ReadString(); - sceneTypeToEnhanceChainNameMap[key] = value; - } - - unordered_map effectDefaultProperty; - mapSize = data.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect chain manager failed, please check log"); - for (i = 0; i < mapSize; i++) { - string key = data.ReadString(); - string value = data.ReadString(); - effectDefaultProperty[key] = value; - } - - unordered_map enhanceDefaultProperty; - mapSize = data.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, - AUDIO_ERR, "Create audio enhance chain manager failed, please check log"); - for (i = 0; i < mapSize; i++) { - string key = data.ReadString(); - string value = data.ReadString(); - enhanceDefaultProperty[key] = value; - } + EffectChainManagerParam effectParam; + EffectChainManagerParam enhanceParam; + UnmarshellEffectChainMgrParam(effectParam, data); + UnmarshellEffectChainMgrParam(enhanceParam, data); - bool createSuccess = CreateEffectChainManager(effectChains, - { .sceneTypeToChainNameMap = sceneTypeToEffectChainNameMap, .effectDefaultProperty = effectDefaultProperty }, - { .sceneTypeToChainNameMap = sceneTypeToEnhanceChainNameMap, .effectDefaultProperty = enhanceDefaultProperty } - ); + bool createSuccess = CreateEffectChainManager(effectChains, effectParam, enhanceParam); CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR, "Create audio effect chain manager failed, please check log"); return AUDIO_OK; -- Gitee From 85e62875263d50d34f33381cf30e4d4e0915b1d9 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Fri, 19 Jul 2024 19:39:25 +0800 Subject: [PATCH 05/18] fix ret code Signed-off-by: owencreeper --- .../client/src/audio_manager_proxy.cpp | 27 +++++++++---------- .../server/src/audio_manager_stub.cpp | 11 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index 1640ebfe71..8744647612 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -817,27 +817,26 @@ void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName) CHECK_AND_RETURN_LOG(error == ERR_NONE, "RequestThreadPriority failed, error: %{public}d", error); } -static bool MarshellEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) +static void MarshellEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) { - bool ret = data.WriteInt32(effectChainMgrParam.maxExtraNum); - ret &&= data.WriteString(effectChainMgrParam.defaultSceneName); - ret &&= data.WriteInt32(effectChainMgrParam.priorSceneList.size()); + data.WriteInt32(effectChainMgrParam.maxExtraNum); + data.WriteString(effectChainMgrParam.defaultSceneName); + data.WriteInt32(effectChainMgrParam.priorSceneList.size()); for (const auto &prioScene : effectChainMgrParam.priorSceneList) { - ret &&= data.WriteString(prioScene); + data.WriteString(prioScene); } - - ret &&= data.WriteInt32(effectChainMgrParam.sceneTypeToChainNameMap.size()); + + data.WriteInt32(effectChainMgrParam.sceneTypeToChainNameMap.size()); for (const auto &[scene, chain] : effectChainMgrParam.sceneTypeToChainNameMap) { - ret &&= data.WriteString(scene); - ret &&= data.WriteString(chain); + data.WriteString(scene); + data.WriteString(chain); } - - ret &&= data.WriteInt32(effectChainMgrParam.effectDefaultProperty.size()); + + data.WriteInt32(effectChainMgrParam.effectDefaultProperty.size()); for (const auto &[effect, prop] : effectChainMgrParam.effectDefaultProperty) { - ret &&= data.WriteString(effect); - ret &&= data.WriteString(prop); + data.WriteString(effect); + data.WriteString(prop); } - return ret; } bool AudioManagerProxy::CreateEffectChainManager(std::vector &effectChains, diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index 8e7be05eac..bf3b2deb29 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -442,14 +442,14 @@ static bool UnmarshellEffectChainMgrParam(EffectChainManagerParam &effectChainMg int32_t containSize = data.ReadInt32(); CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIO_SCENE_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect prioscene failed, please check log"); + false, "Create audio effect prioscene failed, please check log"); while (containSize--) { effectChainMgrParam.priorSceneList.emplace_back(data.ReadString()); } containSize = data.ReadInt32(); CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect chain name map failed, please check log"); + false, "Create audio effect chain name map failed, please check log"); while (containSize--) { string key = data.ReadString(); string value = data.ReadString(); @@ -458,7 +458,7 @@ static bool UnmarshellEffectChainMgrParam(EffectChainManagerParam &effectChainMg containSize = data.ReadInt32(); CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT, - AUDIO_ERR, "Create audio effect default property failed, please check log"); + false, "Create audio effect default property failed, please check log"); while (containSize--) { string key = data.ReadString(); string value = data.ReadString(); @@ -493,8 +493,9 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M EffectChainManagerParam effectParam; EffectChainManagerParam enhanceParam; - UnmarshellEffectChainMgrParam(effectParam, data); - UnmarshellEffectChainMgrParam(enhanceParam, data); + if (!UnmarshellEffectChainMgrParam(effectParam, data) || UnmarshellEffectChainMgrParam(enhanceParam, data)) { + return AUDIO_ERR; + } bool createSuccess = CreateEffectChainManager(effectChains, effectParam, enhanceParam); CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR, -- Gitee From 38ac262037b1a804bc2cccecf293bf1886080234 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Fri, 19 Jul 2024 20:06:33 +0800 Subject: [PATCH 06/18] fix compile err Signed-off-by: owencreeper --- .../server/src/service/effect/audio_effect_manager.cpp | 2 +- services/audio_service/server/src/audio_manager_stub.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index bad5d55569..a0d87151a7 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -612,7 +612,7 @@ void AudioEffectManager::ConstructDefaultEffectProperty(const std::string &chain return x.name == chainName; }); if (effectChain == supportedEffectConfig_.effectChains.end()) { - continue; + return; } for (auto &effectName : effectChain->apply) { auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index bf3b2deb29..7bd7299a77 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -493,7 +493,7 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M EffectChainManagerParam effectParam; EffectChainManagerParam enhanceParam; - if (!UnmarshellEffectChainMgrParam(effectParam, data) || UnmarshellEffectChainMgrParam(enhanceParam, data)) { + if (!UnmarshellEffectChainMgrParam(effectParam, data) || !UnmarshellEffectChainMgrParam(enhanceParam, data)) { return AUDIO_ERR; } -- Gitee From 3049e32a58a2ee20ac20eb131d0df0ebadc5023e Mon Sep 17 00:00:00 2001 From: owencreeper Date: Fri, 19 Jul 2024 22:41:01 +0800 Subject: [PATCH 07/18] fix Signed-off-by: owencreeper --- .../src/audio_effect_chain_manager.cpp | 8 +- .../src/audio_enhance_chain_manager.cpp | 7 +- .../audio_effect_chain_manager_unit_test.cpp | 172 +++++++++++------- .../native/audiocommon/include/audio_effect.h | 4 +- .../service/effect/audio_effect_manager.h | 5 +- .../src/service/audio_policy_service.cpp | 2 + .../service/effect/audio_effect_manager.cpp | 117 ++++++------ .../client/src/audio_manager_proxy.cpp | 6 +- .../server/src/audio_manager_stub.cpp | 4 +- 9 files changed, 188 insertions(+), 137 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 2f15fa21eb..f563b57d5c 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -389,12 +389,8 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(const std::string &s GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType))); } auto propIter = effectPropertyMap_.find(effect); - std::string property = ""; - if (propIter != effectPropertyMap_.end()) { - property = propIter->second; - } audioEffectChain->AddEffectHandle(handle, EffectToLibraryEntryMap_[effect]->audioEffectLibHandle, - currSceneType, effect, property); + currSceneType, effect, propIter == effectPropertyMap_.end() ? "" : propIter->second); } audioEffectChain->ResetIoBufferConfig(); @@ -1356,6 +1352,7 @@ bool AudioEffectChainManager::CheckIfSpkDsp() int32_t AudioEffectChainManager::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) { + std::lock_guard lock(dynamicMutex_); for (const auto &property : propertyArray.property) { auto item = effectPropertyMap_.find(property.effectClass); if (item == effectPropertyMap_.end()) { @@ -1379,6 +1376,7 @@ int32_t AudioEffectChainManager::SetAudioEffectProperty(const AudioEffectPropert int32_t AudioEffectChainManager::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) { + std::lock_guard lock(dynamicMutex_); propertyArray.property.clear(); for (const auto &[effect, prop] : effectPropertyMap_) { if (!prop.empty()) { diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index 50d18d592c..27d01a54fa 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -435,7 +435,7 @@ int32_t AudioEnhanceChainManager::SetStreamVolumeInfo(const uint32_t &sessionId, int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) { - return AUDIO_OK; + std::lock_guard lock(chainManagerMutex_); int32_t ret = 0; for (const auto &property : propertyArray.property) { auto item = effectPropertyMap_.find(property.enhanceClass); @@ -456,15 +456,18 @@ int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhanceProp } } } - return ret; + return 0; } int32_t AudioEnhanceChainManager::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) { + std::lock_guard lock(chainManagerMutex_); propertyArray.property.clear(); for (const auto &[effect, prop] : effectPropertyMap_) { if (!prop.empty()) { propertyArray.property.emplace_back(AudioEnhanceProperty{effect, prop}); + AUDIO_INFO_LOG("effect %{public}s is now %{public}s mode", + effect.c_str(), prop.c_str()); } } return AUDIO_OK; diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index 654967d9ce..863667f9d8 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -18,6 +18,7 @@ #include "audio_effect_chain_manager_unit_test.h" +#include #include #include #include @@ -42,12 +43,17 @@ constexpr uint32_t INFOCHANNELS = 2; constexpr uint64_t INFOCHANNELLAYOUT = 0x3; vector DEFAULT_EFFECT_CHAINS = {{"EFFECTCHAIN_SPK_MUSIC", {}, ""}, {"EFFECTCHAIN_BT_MUSIC", {}, ""}}; - -unordered_map DEFAULT_MAP = { - {"SCENE_MOVIE_&_EFFECT_DEFAULT_&_DEVICE_TYPE_SPEAKER", "EFFECTCHAIN_SPK_MUSIC"}, - {"SCENE_MOVIE_&_EFFECT_DEFAULT_&_DEVICE_TYPE_BLUETOOTH_A2DP", "EFFECTCHAIN_BT_MUSIC"}, +EffectChainManagerParam DEFAULT_EFFECT_CHAIN_MANAGER_PARAM{ + 3, + "SCENE_DEFAULT", + {}, + {{"SCENE_MOVIE_&_EFFECT_DEFAULT_&_DEVICE_TYPE_SPEAKER", "EFFECTCHAIN_SPK_MUSIC"}, + {"SCENE_MOVIE_&_EFFECT_DEFAULT_&_DEVICE_TYPE_BLUETOOTH_A2DP", "EFFECTCHAIN_BT_MUSIC"}}, + {{"effect1", "property1"}, {"effect4", "property5"}, {"effect1", "property4"}} }; +AudioEffectPropertyArray DEFAULT_AUDIO_PROPERTY_ARRAY = { { {"effect19", "property19"}, {"effect8", "property10"} } }; + vector> DEFAULT_EFFECT_LIBRARY_LIST = {}; SessionEffectInfo DEFAULT_INFO = { "EFFECT_DEFAULT", @@ -73,8 +79,8 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_001, TestS { string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); EXPECT_EQ(ERROR, result); @@ -91,8 +97,9 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_002, TestS { string sceneType = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); + int32_t result = AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -108,8 +115,9 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_003, TestS { string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); + int32_t result = AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -182,8 +190,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_001, Test { string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ReleaseAudioEffectChainDynamic(sceneType); EXPECT_EQ(ERROR, result); @@ -199,8 +207,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_002, Test { string sceneType = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ReleaseAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); @@ -216,8 +224,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_003, Test { string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ReleaseAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); @@ -252,8 +260,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_002, TestSize.Leve string effectMode = "EFFECT_DEFAULT"; string spatializationEnabled = "0"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); bool result = AudioEffectChainManager::GetInstance()->ExistAudioEffectChain(sceneType, effectMode, spatializationEnabled); @@ -272,8 +280,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_003, TestSize.Leve string effectMode = ""; string spatializationEnabled = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); bool result = AudioEffectChainManager::GetInstance()->ExistAudioEffectChain(sceneType, effectMode, spatializationEnabled); @@ -292,8 +300,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_004, TestSize.Leve string effectMode = "123"; string spatializationEnabled = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); bool result = AudioEffectChainManager::GetInstance()->ExistAudioEffectChain(sceneType, effectMode, spatializationEnabled); @@ -312,8 +320,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_005, TestSize.Leve string effectMode = "EFFECT_DEFAULT"; string spatializationEnabled = "0"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); bool result = AudioEffectChainManager::GetInstance()->ExistAudioEffectChain(sceneType, effectMode, spatializationEnabled); EXPECT_EQ(false, result); @@ -340,8 +348,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_001, TestSize.Leve auto eBufferAttr = make_unique(bufIn, bufOut, numChans, frameLen); string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ApplyAudioEffectChain(sceneType, eBufferAttr); EXPECT_EQ(ERROR, result); @@ -368,8 +376,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_002, TestSize.Leve auto eBufferAttr = make_unique(bufIn, bufOut, numChans, frameLen); string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ApplyAudioEffectChain(sceneType, eBufferAttr); EXPECT_EQ(SUCCESS, result); @@ -396,8 +404,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_003, TestSize.Leve auto eBufferAttr = make_unique(bufIn, bufOut, numChans, frameLen); string sceneType = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->ApplyAudioEffectChain(sceneType, eBufferAttr); EXPECT_EQ(SUCCESS, result); @@ -424,8 +432,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_004, TestSize.Leve auto eBufferAttr = make_unique(bufIn, bufOut, numChans, frameLen); string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->ApplyAudioEffectChain(sceneType, eBufferAttr); EXPECT_EQ(ERROR, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -442,8 +450,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_001, TestSize.Level1 int32_t device = 2; string sinkName = "Speaker"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->SetOutputDeviceSink(device, sinkName); AudioEffectChainManager::GetInstance()->ResetInfo(); } @@ -459,8 +467,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_002, TestSize.Level1 int32_t device = 2; string sinkName = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->SetOutputDeviceSink(device, sinkName); AudioEffectChainManager::GetInstance()->ResetInfo(); } @@ -476,8 +484,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_003, TestSize.Level1 int32_t device = 2; string sinkName = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->SetOutputDeviceSink(device, sinkName); AudioEffectChainManager::GetInstance()->ResetInfo(); } @@ -527,8 +535,8 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_001, TestSize.L { string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->UpdateMultichannelConfig(sceneType); EXPECT_EQ(SUCCESS, result); @@ -544,8 +552,8 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_002, TestSize.L { string sceneType = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->UpdateMultichannelConfig(sceneType); EXPECT_EQ(SUCCESS, result); @@ -561,8 +569,8 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_003, TestSize.L { string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t result = AudioEffectChainManager::GetInstance()->UpdateMultichannelConfig(sceneType); EXPECT_EQ(ERROR, result); @@ -578,8 +586,8 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_004, TestSize.L { string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->UpdateMultichannelConfig(sceneType); EXPECT_EQ(ERROR, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -608,8 +616,8 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_002, TestSiz { string sceneType = "SCENE_MOVIE"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->InitAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -624,8 +632,8 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_003, TestSiz { string sceneType = "123"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->InitAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -640,8 +648,8 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_004, TestSiz { string sceneType = ""; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->InitAudioEffectChainDynamic(sceneType); EXPECT_EQ(ERROR, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -704,8 +712,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_002, TestSize.Level1) string effectMode = "EFFECT_DEFAULT"; bool enabled = true; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->SetHdiParam(sceneType, effectMode, enabled); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -722,8 +730,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_003, TestSize.Level1) string effectMode = "EFFECT_DEFAULT"; bool enabled = false; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->SetHdiParam(sceneType, effectMode, enabled); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -740,8 +748,8 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_004, TestSize.Level1) string effectMode = ""; bool enabled = true; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->SetHdiParam(sceneType, effectMode, enabled); EXPECT_EQ(ERROR, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -759,7 +767,7 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_005, TestSize.Level1) bool enabled = true; AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, - DEFAULT_MAP, DEFAULT_EFFECT_LIBRARY_LIST); + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); int32_t result = AudioEffectChainManager::GetInstance()->SetHdiParam(sceneType, effectMode, enabled); EXPECT_EQ(SUCCESS, result); AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -887,8 +895,8 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_002, TestSize.Le uint64_t channelLayout = 0x3; string sessionID = "123456"; - AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_MAP, - DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); AudioEffectChainManager::GetInstance()->CreateAudioEffectChainDynamic(sceneType); int32_t addRes = AudioEffectChainManager::GetInstance()->SessionInfoMapAdd(sessionID, DEFAULT_INFO); @@ -1127,5 +1135,47 @@ HWTEST(AudioEffectChainManagerUnitTest, ResetEffectBuffer_001, TestSize.Level1) { AudioEffectChainManager::GetInstance()->ResetEffectBuffer(); } + +/** +* @tc.name : Test GetAudioEffectProperty API +* @tc.number : GetAudioEffectProperty_001 +* @tc.desc : Test GetAudioEffectProperty interface. +*/ +HWTEST(AudioEffectChainManagerUnitTest, GetAudioEffectProperty_001, TestSize.Level1) +{ + AudioEffectChainManager::GetInstance()->ResetInfo(); + AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); + AudioEffectPropertyArray properties; + auto ret = AudioEffectChainManager::GetInstance()->GetAudioEffectProperty(properties); + EXPECT_EQ(SUCCESS, ret); + for (auto &[effect, property] : DEFAULT_EFFECT_CHAIN_MANAGER_PARAM.effectDefaultProperty) { + auto it = std::find(properties.property.begin(), properties.property.end(), + AudioEffectProperty{effect, property}); + EXPECT_NE(properties.property.end(), it); + } +} + +/** +* @tc.name : Test SetAudioEffectProperty API +* @tc.number : SetAudioEffectProperty_001 +* @tc.desc : Test SetAudioEffectProperty interface. +*/ +HWTEST(AudioEffectChainManagerUnitTest, SetAudioEffectProperty_001, TestSize.Level1) +{ + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + audioEffectChainManager->ResetInfo(); + audioEffectChainManager->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, + DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); + auto ret = audioEffectChainManager->SetAudioEffectProperty(DEFAULT_AUDIO_PROPERTY_ARRAY); + EXPECT_EQ(SUCCESS, ret); + AudioEffectPropertyArray properties; + ret = audioEffectChainManager->GetAudioEffectProperty(properties); + EXPECT_EQ(SUCCESS, ret); + for (auto &property : DEFAULT_AUDIO_PROPERTY_ARRAY.property) { + auto it = std::find(properties.property.begin(), properties.property.end(), property); + EXPECT_NE(properties.property.end(), it); + } +} } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index effa7c4d5f..9efe80ba13 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -39,11 +39,9 @@ constexpr int32_t AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT = 1; constexpr int32_t AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT = 64; // max conf for sceneType + effectMode + deviceType constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32; // max num of effectChain constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; // max num of effect per effectChain -constexpr int32_t AUDIO_EFFECT_PRIO_SCENE_UPPER_LIMIT = 7; // max num of effect prio scene +constexpr int32_t AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT = 7; // max num of effect prior scene constexpr int32_t AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT = 20; // max num of property -constexpr int32_t MAX_PARA_LEN = 20; - constexpr int32_t HDI_EFFECT_NUM = 2; constexpr int32_t HDI_SET_PATAM = 6; constexpr int32_t HDI_INIT = 0; diff --git a/services/audio_policy/server/include/service/effect/audio_effect_manager.h b/services/audio_policy/server/include/service/effect/audio_effect_manager.h index 421862c969..583e8361d8 100644 --- a/services/audio_policy/server/include/service/effect/audio_effect_manager.h +++ b/services/audio_policy/server/include/service/effect/audio_effect_manager.h @@ -70,8 +70,11 @@ private: void UpdateDuplicateDevice(ProcessNew &processNew); int32_t UpdateUnavailableEffectChains(std::vector &availableLayout, ProcessNew &processNew); bool VerifySceneMappingItem(const SceneMappingItem &item); - void UpdateSupportedEffectProperty(ProcessNew &processnew, + void UpdateSupportedEffectProperty(const Device &device, std::unordered_map>> &device2PropertySet); + void UpdateDuplicateProcessNew(std::vector &availableLayout, ProcessNew &processNew); + void ConstructDefaultEffectProperty(const std::string &chainName, + std::unordered_map &defaultProperty); }; } // namespce AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index 5e521ee522..8ab8752c0c 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -8433,6 +8433,7 @@ int32_t AudioPolicyService::GetSupportedAudioEffectProperty(AudioEffectPropertyA for (auto &item : descriptor) { audioEffectManager_.GetSupportedAudioEffectProperty(item->getType(), mergedSet); } + propertyArray.property.reserve(mergedSet.size()); std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), [](const std::pair& p) { return AudioEffectProperty{p.first, p.second}; @@ -8449,6 +8450,7 @@ int32_t AudioPolicyService::GetSupportedAudioEnhanceProperty(AudioEnhancePropert for (auto &item : descriptor) { audioEffectManager_.GetSupportedAudioEnhanceProperty(item->getType(), mergedSet); } + propertyArray.property.reserve(mergedSet.size()); std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), [](const std::pair& p) { return AudioEnhanceProperty{p.first, p.second}; diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index a0d87151a7..63f8d58806 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -485,45 +485,52 @@ int32_t AudioEffectManager::UpdateUnavailableEffectChains(std::vector>> &device2PropertySet) { - for (auto &stream : processnew.stream) { - for (auto &streamMode : stream.streamEffectMode) { - for (auto &device : streamMode.devicePort) { - auto chainName = device.chain; - auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), - supportedEffectConfig_.effectChains.end(), - [&chainName](const EffectChain& x) { - return x.name == chainName; - }); - if (effectChain == supportedEffectConfig_.effectChains.end()) { - continue; - } - for (auto &effectName : effectChain->apply) { - auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), - [&effectName](const Effect& effect) { - return effect.name == effectName; - }); - if (effectIter == availableEffects_.end()) { - continue; - } - for (auto &property : effectIter->effectProperty) { - auto deviceIter = device2PropertySet.find(device.type); - if (deviceIter == device2PropertySet.end()) { - device2PropertySet[device.type].insert({effectIter->name, property}); - } else { - deviceIter->second.insert({effectIter->name, property}); - } - AUDIO_INFO_LOG("device %{public}s support effect [%{public}s, %{public}s]", - device.type.c_str(), effectIter->name.c_str(), property.c_str()); - } - } + auto chainName = device.chain; + auto effectChain = std::find_if(supportedEffectConfig_.effectChains.begin(), + supportedEffectConfig_.effectChains.end(), + [&chainName](const EffectChain& x) { + return x.name == chainName; + }); + if (effectChain == supportedEffectConfig_.effectChains.end()) { + return; + } + for (auto &effectName : effectChain->apply) { + auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), + [&effectName](const Effect& effect) { + return effect.name == effectName; + }); + if (effectIter == availableEffects_.end()) { + continue; + } + for (auto &property : effectIter->effectProperty) { + auto deviceIter = device2PropertySet.find(device.type); + if (deviceIter == device2PropertySet.end()) { + device2PropertySet[device.type].insert({effectIter->name, property}); + } else { + deviceIter->second.insert({effectIter->name, property}); } + AUDIO_INFO_LOG("device %{public}s support effect [%{public}s, %{public}s]", + device.type.c_str(), effectIter->name.c_str(), property.c_str()); } } } +void AudioEffectManager::UpdateDuplicateProcessNew(std::vector &availableLayout, ProcessNew &processNew) +{ + UpdateEffectChains(availableLayout); + UpdateDuplicateBypassMode(processNew); + UpdateDuplicateMode(processNew); + UpdateDuplicateDevice(processNew); + UpdateDuplicateDefaultScene(processNew); + UpdateDuplicateScene(processNew); + if (UpdateUnavailableEffectChains(availableLayout, supportedEffectConfig_.preProcessNew) != 0) { + existDefault_ = -1; + } +} + void AudioEffectManager::BuildAvailableAEConfig() { int32_t ret = 0 ; @@ -552,31 +559,23 @@ void AudioEffectManager::BuildAvailableAEConfig() // Update duplicate defined modes, devices, and unsupported effect chain. UpdateAvailableAEConfig(oriEffectConfig_); - ProcessNew preProcessNew = supportedEffectConfig_.preProcessNew; - ProcessNew postProcessNew = supportedEffectConfig_.postProcessNew; + UpdateDuplicateProcessNew(availableLayout, supportedEffectConfig_.preProcessNew); + UpdateDuplicateProcessNew(availableLayout, supportedEffectConfig_.postProcessNew); - UpdateEffectChains(availableLayout); - UpdateDuplicateBypassMode(supportedEffectConfig_.preProcessNew); - UpdateDuplicateMode(supportedEffectConfig_.preProcessNew); - UpdateDuplicateDevice(supportedEffectConfig_.preProcessNew); - UpdateDuplicateDefaultScene(supportedEffectConfig_.preProcessNew); - UpdateDuplicateScene(supportedEffectConfig_.preProcessNew); - ret = UpdateUnavailableEffectChains(availableLayout, supportedEffectConfig_.preProcessNew); - if (ret != 0) { - existDefault_ = -1; + for (auto &stream : supportedEffectConfig_.preProcessNew.stream) { + for (auto &streamMode : stream.streamEffectMode) { + for (auto &device : streamMode.devicePort) { + UpdateSupportedEffectProperty(device, device2EnhancePropertySet_); + } + } } - - UpdateDuplicateBypassMode(supportedEffectConfig_.postProcessNew); - UpdateDuplicateMode(supportedEffectConfig_.postProcessNew); - UpdateDuplicateDevice(supportedEffectConfig_.postProcessNew); - UpdateDuplicateDefaultScene(supportedEffectConfig_.postProcessNew); - UpdateDuplicateScene(supportedEffectConfig_.postProcessNew); - ret = UpdateUnavailableEffectChains(availableLayout, supportedEffectConfig_.postProcessNew); - if (ret != 0) { - existDefault_ = -1; + for (auto &stream : supportedEffectConfig_.postProcessNew.stream) { + for (auto &streamMode : stream.streamEffectMode) { + for (auto &device : streamMode.devicePort) { + UpdateSupportedEffectProperty(device, device2EffectPropertySet_); + } + } } - UpdateSupportedEffectProperty(supportedEffectConfig_.preProcessNew, device2EnhancePropertySet_); - UpdateSupportedEffectProperty(supportedEffectConfig_.postProcessNew, device2EffectPropertySet_); } void AudioEffectManager::SetMasterSinkAvailable() @@ -623,16 +622,14 @@ void AudioEffectManager::ConstructDefaultEffectProperty(const std::string &chain continue; } // if 0 property, no need to set default - for (auto &property : effectIter->effectProperty) { - auto it = effectDefaultProperty.find(effectIter->name); + if (effectIter->effectProperty.size() > 0) { // first assign, and no need to assign twice - if (it == effectDefaultProperty.end()) { - effectDefaultProperty[effectIter->name] = property; + if (!effectDefaultProperty.count(effectIter->name)) { + // only first property is default set + effectDefaultProperty[effectIter->name] = effectIter->effectProperty[0]; AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", effectIter->name.c_str(), property.c_str()); } - // only first property is default set - break; } } } diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index 8744647612..61f2d51b8d 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -817,7 +817,7 @@ void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName) CHECK_AND_RETURN_LOG(error == ERR_NONE, "RequestThreadPriority failed, error: %{public}d", error); } -static void MarshellEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) +static void MarshallEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) { data.WriteInt32(effectChainMgrParam.maxExtraNum); data.WriteString(effectChainMgrParam.defaultSceneName); @@ -870,8 +870,8 @@ bool AudioManagerProxy::CreateEffectChainManager(std::vector &effec } } - MarshellEffectChainMgrParam(effectParam, dataParcel); - MarshellEffectChainMgrParam(enhanceParam, dataParcel); + MarshallEffectChainMgrParam(effectParam, dataParcel); + MarshallEffectChainMgrParam(enhanceParam, dataParcel); error = Remote()->SendRequest( static_cast(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER), diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index 7bd7299a77..3a92279d25 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -435,7 +435,7 @@ int AudioManagerStub::HandleRequestThreadPriority(MessageParcel &data, MessagePa return AUDIO_OK; } -static bool UnmarshellEffectChainMgrParam(EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) +static bool UnmarshallEffectChainMgrParam(EffectChainManagerParam &effectChainMgrParam, MessageParcel &data) { effectChainMgrParam.maxExtraNum = data.ReadInt32(); effectChainMgrParam.defaultSceneName = data.ReadString(); @@ -493,7 +493,7 @@ int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, M EffectChainManagerParam effectParam; EffectChainManagerParam enhanceParam; - if (!UnmarshellEffectChainMgrParam(effectParam, data) || !UnmarshellEffectChainMgrParam(enhanceParam, data)) { + if (!UnmarshallEffectChainMgrParam(effectParam, data) || !UnmarshallEffectChainMgrParam(enhanceParam, data)) { return AUDIO_ERR; } -- Gitee From d16f33174b5ca885c116abbfa3be6f4ac7e0e1da Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 00:26:05 +0800 Subject: [PATCH 08/18] fix bug Signed-off-by: owencreeper --- .../src/audio_effect_chain_manager.cpp | 14 ++++-- .../src/audio_enhance_chain_manager.cpp | 14 ++++-- .../service/effect/audio_effect_manager.h | 3 ++ .../service/effect/audio_effect_manager.cpp | 46 ++++++------------- .../server/src/audio_manager_stub.cpp | 2 +- 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 9cdebeffe8..26594763fd 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -49,10 +49,12 @@ static int32_t FindEffectLib(const std::string &effect, std::shared_ptr &libEntry, std::string &libName) { for (const std::shared_ptr &lib : effectLibraryList) { - if (lib->libraryName == effect) { - libName = lib->libraryName; - libEntry = lib; - return SUCCESS; + for (const auto &effectName : lib->effectName) { + if (effectName == effect) { + libName = lib->libraryName; + libEntry = lib; + return SUCCESS; + } } } return ERROR; @@ -280,7 +282,9 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vector effects; for (std::string effectName: efc.apply) { - effects.emplace_back(effectName); + if (EffectToLibraryEntryMap_.count(effectName)) { + effects.emplace_back(effectName); + } } EffectChainToEffectsMap_[key] = effects; } diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index 8ec52a3e70..28713bf828 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -35,10 +35,12 @@ static int32_t FindEnhanceLib(const std::string &enhance, std::shared_ptr &libEntry, std::string &libName) { for (const std::shared_ptr &lib : enhanceLibraryList) { - if (lib->libraryName == enhance) { - libName = lib->libraryName; - libEntry = lib; - return SUCCESS; + for (const auto &effectName : lib->effectName) { + if (effectName == enhance) { + libName = lib->libraryName; + libEntry = lib; + return SUCCESS; + } } } return ERROR; @@ -110,7 +112,9 @@ void AudioEnhanceChainManager::InitAudioEnhanceChainManager(std::vector enhances; for (std::string enhanceName : enhanceChain.apply) { - enhances.emplace_back(enhanceName); + if (enhanceToLibraryEntryMap_.count(enhanceName)) { + enhances.emplace_back(enhanceName); + } } enhanceChainToEnhancesMap_[key] = enhances; } diff --git a/services/audio_policy/server/include/service/effect/audio_effect_manager.h b/services/audio_policy/server/include/service/effect/audio_effect_manager.h index 583e8361d8..f6059080d4 100644 --- a/services/audio_policy/server/include/service/effect/audio_effect_manager.h +++ b/services/audio_policy/server/include/service/effect/audio_effect_manager.h @@ -75,6 +75,9 @@ private: void UpdateDuplicateProcessNew(std::vector &availableLayout, ProcessNew &processNew); void ConstructDefaultEffectProperty(const std::string &chainName, std::unordered_map &defaultProperty); + int32_t GetSupportedPropertyInner(const DeviceType& deviceType, + std::set> &mergedSet, + const std::unordered_map>> &device2PropertySet); }; } // namespce AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index 63f8d58806..e2bce3ff16 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -533,7 +533,6 @@ void AudioEffectManager::UpdateDuplicateProcessNew(std::vector &ava void AudioEffectManager::BuildAvailableAEConfig() { - int32_t ret = 0 ; std::vector availableLayout; existDefault_ = 1; if (oriEffectConfig_.effectChains.size() == 0) { @@ -628,7 +627,7 @@ void AudioEffectManager::ConstructDefaultEffectProperty(const std::string &chain // only first property is default set effectDefaultProperty[effectIter->name] = effectIter->effectProperty[0]; AUDIO_INFO_LOG("effect %{public}s defaultProperty is %{public}s", - effectIter->name.c_str(), property.c_str()); + effectIter->name.c_str(), effectIter->effectProperty[0].c_str()); } } } @@ -698,50 +697,33 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar (int32_t)map.size()); } -int32_t AudioEffectManager::GetSupportedAudioEffectProperty(const DeviceType &deviceType, - std::set> &mergedSet) +int32_t AudioEffectManager::GetSupportedPropertyInner(const DeviceType& deviceType, + std::set> &mergedSet, + const std::unordered_map>> &device2PropertySet) { auto deviceIter = SUPPORTED_DEVICE_TYPE.find(deviceType); if (deviceIter == SUPPORTED_DEVICE_TYPE.end()) { AUDIO_ERR_LOG("device not supported."); return -1; } - auto propertySetIter = device2EffectPropertySet_.find(deviceIter->second); - if (propertySetIter != device2EffectPropertySet_.end()) { + auto deviceStr = deviceType == DEVICE_TYPE_INVALID ? "" : deviceIter->second; + auto propertySetIter = device2PropertySet.find(deviceStr); + if (propertySetIter != device2PropertySet.end()) { mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); - } else { - AUDIO_INFO_LOG("property is empty"); - } - if (deviceType == DEVICE_TYPE_INVALID) { - propertySetIter = device2EffectPropertySet_.find(""); - if (propertySetIter != device2EffectPropertySet_.end()) { - mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); - } } return AUDIO_OK; } +int32_t AudioEffectManager::GetSupportedAudioEffectProperty(const DeviceType &deviceType, + std::set> &mergedSet) +{ + return GetSupportedPropertyInner(deviceType, mergedSet, device2EffectPropertySet_); +} + int32_t AudioEffectManager::GetSupportedAudioEnhanceProperty(const DeviceType &deviceType, std::set> &mergedSet) { - auto deviceIter = SUPPORTED_DEVICE_TYPE.find(deviceType); - if (deviceIter == SUPPORTED_DEVICE_TYPE.end()) { - AUDIO_ERR_LOG("device not supported."); - return -1; - } - auto propertySetIter = device2EnhancePropertySet_.find(deviceIter->second); - if (propertySetIter != device2EnhancePropertySet_.end()) { - mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); - } else { - AUDIO_INFO_LOG("property is empty"); - } - if (deviceType == DEVICE_TYPE_INVALID) { - propertySetIter = device2EnhancePropertySet_.find(""); - if (propertySetIter != device2EnhancePropertySet_.end()) { - mergedSet.insert(propertySetIter->second.begin(), propertySetIter->second.end()); - } - } - return AUDIO_OK; + return GetSupportedPropertyInner(deviceType, mergedSet, device2EnhancePropertySet_); } } // namespce AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index b81bcc8807..7670161e8e 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -441,7 +441,7 @@ static bool UnmarshallEffectChainMgrParam(EffectChainManagerParam &effectChainMg effectChainMgrParam.defaultSceneName = data.ReadString(); int32_t containSize = data.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIO_SCENE_UPPER_LIMIT, + CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT, false, "Create audio effect prioscene failed, please check log"); while (containSize--) { effectChainMgrParam.priorSceneList.emplace_back(data.ReadString()); -- Gitee From cf5a95fb7a27225202be58ad8ae1fab105a6a091 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 00:30:00 +0800 Subject: [PATCH 09/18] fix bug Signed-off-by: owencreeper --- .../src/audio_effect_chain_manager_unit_test.cpp | 2 +- .../server/src/service/effect/audio_effect_manager.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index 863667f9d8..2f6ebac1d8 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -1172,7 +1172,7 @@ HWTEST(AudioEffectChainManagerUnitTest, SetAudioEffectProperty_001, TestSize.Lev AudioEffectPropertyArray properties; ret = audioEffectChainManager->GetAudioEffectProperty(properties); EXPECT_EQ(SUCCESS, ret); - for (auto &property : DEFAULT_AUDIO_PROPERTY_ARRAY.property) { + for (const auto &property : DEFAULT_AUDIO_PROPERTY_ARRAY.property) { auto it = std::find(properties.property.begin(), properties.property.end(), property); EXPECT_NE(properties.property.end(), it); } diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index e2bce3ff16..89f0b4068a 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -209,7 +209,7 @@ void AudioEffectManager::UpdateEffectChains(std::vector &availableL int32_t count = 0; std::vector deviceDelIdx; for (const auto &ec: supportedEffectConfig_.effectChains) { - for (auto &effectName: ec.apply) { + for (const auto &effectName: ec.apply) { auto it = std::find_if(availableEffects_.begin(), availableEffects_.end(), [&effectName](const Effect &effect) { return effect.name == effectName; @@ -497,7 +497,7 @@ void AudioEffectManager::UpdateSupportedEffectProperty(const Device &device, if (effectChain == supportedEffectConfig_.effectChains.end()) { return; } - for (auto &effectName : effectChain->apply) { + for (const auto &effectName : effectChain->apply) { auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), [&effectName](const Effect& effect) { return effect.name == effectName; @@ -505,7 +505,7 @@ void AudioEffectManager::UpdateSupportedEffectProperty(const Device &device, if (effectIter == availableEffects_.end()) { continue; } - for (auto &property : effectIter->effectProperty) { + for (const auto &property : effectIter->effectProperty) { auto deviceIter = device2PropertySet.find(device.type); if (deviceIter == device2PropertySet.end()) { device2PropertySet[device.type].insert({effectIter->name, property}); @@ -612,7 +612,7 @@ void AudioEffectManager::ConstructDefaultEffectProperty(const std::string &chain if (effectChain == supportedEffectConfig_.effectChains.end()) { return; } - for (auto &effectName : effectChain->apply) { + for (const auto &effectName : effectChain->apply) { auto effectIter = std::find_if(availableEffects_.begin(), availableEffects_.end(), [&effectName](const Effect& effect) { return effect.name == effectName; @@ -674,7 +674,6 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar std::string sceneMode; std::string key; - for (auto &scene: supportedEffectConfig_.preProcessNew.stream) { sceneType = scene.scene; if (scene.priority == PRIOR_SCENE) { -- Gitee From 11431601c45dd81de0cd7dbea79d100fa26f7d14 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 01:51:23 +0800 Subject: [PATCH 10/18] xxx Signed-off-by: owencreeper --- .../audioeffect/include/audio_enhance_chain.h | 6 ++- .../include/audio_enhance_chain_manager.h | 2 +- .../audioeffect/src/audio_enhance_chain.cpp | 37 +++++++++++++------ .../src/audio_enhance_chain_manager.cpp | 16 ++++---- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_enhance_chain.h b/frameworks/native/audioeffect/include/audio_enhance_chain.h index 08a044ae15..025f65ac3b 100644 --- a/frameworks/native/audioeffect/include/audio_enhance_chain.h +++ b/frameworks/native/audioeffect/include/audio_enhance_chain.h @@ -63,7 +63,8 @@ class AudioEnhanceChain { public: AudioEnhanceChain(const std::string &scene, const std::string &mode); ~AudioEnhanceChain(); - void AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle); + void AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle, const std::string &enhance, + const std::string &property); bool IsEmptyEnhanceHandles(); void GetAlgoConfig(AudioBufferConfig &algoConfig); uint32_t GetAlgoBufferSize(); @@ -76,6 +77,7 @@ private: void InitDump(); void ReleaseEnhanceChain(); int32_t GetOneFrameInputData(std::unique_ptr &enhanceBuffer); + int32_t SetPropertyToHandle(AudioEffectHandle handle, const std::string &property); bool setConfigFlag_; std::mutex chainMutex_; @@ -88,7 +90,7 @@ private: FILE *dumpFileOut_ = nullptr; bool needEcFlag_; std::vector standByEnhanceHandles_; - std::vector effectNames_; + std::vector enhanceNames_; std::vector enhanceLibHandles_; }; diff --git a/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h b/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h index e5ddbf01f0..47387b1083 100644 --- a/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_enhance_chain_manager.h @@ -68,7 +68,7 @@ private: std::map> enhanceChainToEnhancesMap_; std::map> enhanceToLibraryEntryMap_; std::map enhanceToLibraryNameMap_; - std::unordered_map effectPropertyMap_; + std::unordered_map enhancePropertyMap_; std::unique_ptr enhanceBuffer_ = nullptr; std::mutex chainManagerMutex_; bool isInitialized_; diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp index 6cdb6e240a..1a685f64a6 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp @@ -109,13 +109,19 @@ void AudioEnhanceChain::ReleaseEnhanceChain() enhanceLibHandles_.clear(); } -void AudioEnhanceChain::AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle) +void AudioEnhanceChain::AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle, + const std::string &enhnace, const std::string &property) { std::lock_guard lock(chainMutex_); int32_t ret = 0; AudioEffectTransInfo cmdInfo = {}; AudioEffectTransInfo replyInfo = {}; + if (SetPropertyToHandle(handle, property) != SUCCESS) { + AUDIO_INFO_LOG("[%{public}s] %{public}s effect EFFECT_CMD_SET_PROPERTY fail", + sceneType_.c_str(), enhance.c_str()); + } + uint32_t maxSampleRate = DEFAULT_SAMPLE_RATE; replyInfo.data = &maxSampleRate; replyInfo.size = sizeof(maxSampleRate); @@ -231,27 +237,34 @@ int32_t AudioEnhanceChain::ApplyEnhanceChain(std::unique_ptr &enh return SUCCESS; } -int32_t AudioEnhanceChain::SetEnhanceProperty(const std::string &effect, const std::string &property) +int32_t AudioEnhanceChain::SetEnhanceProperty(const std::string &enhance, const std::string &property) { std::lock_guard lock(chainMutex_); int32_t ret = 0; int32_t size = standByEnhanceHandles_.size(); for (int32_t index = 0; index < size; index++) { auto &handle = standByEnhanceHandles_[index]; - auto const &effectName = effectNames_[index]; - if (effect == effectName) { - int32_t replyData = 0; - const char *propCstr = property.c_str(); - AudioEffectTransInfo cmdInfo = {sizeof(const char *), reinterpret_cast(&propCstr)}; - AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; - ret = (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); - CHECK_AND_RETURN_RET_LOG(ret == 0, ret, - "[%{public}s] %{public}s effect EFFECT_CMD_SET_PROPERTY fail", - sceneType_.c_str(), effectName.c_str()); + auto const &enhanceName = enhanceNames_[index]; + if (enhance == enhanceName) { + if (SetPropertyToHandle(handle, property) != SUCCESS) { + AUDIO_INFO_LOG("[%{public}s] %{public}s effect EFFECT_CMD_SET_PROPERTY fail", + sceneType_.c_str(), enhance.c_str()); + ret = ERROR; + } } } return ret; } +int32_t AudioEnhanceChain::SetPropertyToHandle(AudioEffectHandle handle, const std::string &property) +{ + if (property.empty()) { return SUCCESS; } + int32_t replyData = 0; + const char *propCstr = property.c_str(); + AudioEffectTransInfo cmdInfo = {sizeof(const char *), reinterpret_cast(&propCstr)}; + AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + return (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); +} + } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index 28713bf828..6080ef919d 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -122,8 +122,8 @@ void AudioEnhanceChainManager::InitAudioEnhanceChainManager(std::vectorfirst] = item->second; } - // Construct effectPropertyMap_ that stores effect's property - effectPropertyMap_ = managerParam.effectDefaultProperty; + // Construct enhancePropertyMap_ that stores effect's property + enhancePropertyMap_ = managerParam.effectDefaultProperty; AUDIO_INFO_LOG("enhanceToLibraryEntryMap_ size %{public}zu \ enhanceToLibraryNameMap_ size %{public}zu \ @@ -255,7 +255,9 @@ int32_t AudioEnhanceChainManager::SetAudioEnhanceChainDynamic(const std::string int32_t ret = enhanceToLibraryEntryMap_[enhance]->audioEffectLibHandle->createEffect(descriptor, &handle); CHECK_AND_CONTINUE_LOG(ret == 0, "EnhanceToLibraryEntryMap[%{public}s] createEffect fail", enhance.c_str()); - audioEnhanceChain->AddEnhanceHandle(handle, enhanceToLibraryEntryMap_[enhance]->audioEffectLibHandle); + auto propIter = enhancePropertyMap_.find(enhance); + audioEnhanceChain->AddEnhanceHandle(handle, enhanceToLibraryEntryMap_[enhance]->audioEffectLibHandle, + enhance, propIter == enhancePropertyMap_.end() ? "" : propIter->second); } if (audioEnhanceChain->IsEmptyEnhanceHandles()) { @@ -439,9 +441,9 @@ int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhanceProp std::lock_guard lock(chainManagerMutex_); int32_t ret = 0; for (const auto &property : propertyArray.property) { - auto item = effectPropertyMap_.find(property.enhanceClass); - if (item == effectPropertyMap_.end()) { - effectPropertyMap_[property.enhanceClass] = property.enhanceProp; + auto item = enhancePropertyMap_.find(property.enhanceClass); + if (item == enhancePropertyMap_.end()) { + enhancePropertyMap_[property.enhanceClass] = property.enhanceProp; } else { if (item->second == property.enhanceProp) { AUDIO_INFO_LOG("No need to update effect %{public}s with mode %{public}s", @@ -464,7 +466,7 @@ int32_t AudioEnhanceChainManager::GetAudioEnhanceProperty(AudioEnhancePropertyAr { std::lock_guard lock(chainManagerMutex_); propertyArray.property.clear(); - for (const auto &[effect, prop] : effectPropertyMap_) { + for (const auto &[effect, prop] : enhancePropertyMap_) { if (!prop.empty()) { propertyArray.property.emplace_back(AudioEnhanceProperty{effect, prop}); AUDIO_INFO_LOG("effect %{public}s is now %{public}s mode", -- Gitee From 0c89c54bc10e249e76d1bef864b3887b03683bf5 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 02:27:06 +0800 Subject: [PATCH 11/18] fix enhance param Signed-off-by: owencreeper --- frameworks/native/audioeffect/src/audio_enhance_chain.cpp | 2 +- .../inner_api/native/audiocommon/include/audio_effect.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp index 1a685f64a6..db8a1aee7a 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp @@ -110,7 +110,7 @@ void AudioEnhanceChain::ReleaseEnhanceChain() } void AudioEnhanceChain::AddEnhanceHandle(AudioEffectHandle handle, AudioEffectLibrary *libHandle, - const std::string &enhnace, const std::string &property) + const std::string &enhance, const std::string &property) { std::lock_guard lock(chainMutex_); int32_t ret = 0; diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 9efe80ba13..3810331e0c 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -335,10 +335,10 @@ struct AudioEffectParam { }; struct AudioEnhanceParam { + uint32_t muteInfo; uint32_t volumeInfo; - uint32_t isMute; - const char *upDeivce; - const char *downDeivce; + const char *preDeivce; + const char *postDeivce; }; struct AudioBuffer { -- Gitee From 702084dde42bae39081273cc8d782d7aebbf2733 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 02:35:34 +0800 Subject: [PATCH 12/18] fix insert_or_assgin Signed-off-by: owencreeper --- .../audioeffect/src/audio_effect_chain_manager.cpp | 12 +----------- .../audioeffect/src/audio_enhance_chain_manager.cpp | 12 +----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 26594763fd..121aa64958 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -1365,17 +1365,7 @@ int32_t AudioEffectChainManager::SetAudioEffectProperty(const AudioEffectPropert { std::lock_guard lock(dynamicMutex_); for (const auto &property : propertyArray.property) { - auto item = effectPropertyMap_.find(property.effectClass); - if (item == effectPropertyMap_.end()) { - effectPropertyMap_[property.effectClass] = property.effectProp; - } else { - if (item->second == property.effectProp) { - AUDIO_INFO_LOG("No need to update effect %{public}s with mode %{public}s", - property.effectClass.c_str(), property.effectProp.c_str()); - continue; - } - item->second = property.effectProp; - } + effectPropertyMap_.insert_or_assign(property.effectClass, property.effectProp); for (const auto &[sceneType, effectChain] : SceneTypeToEffectChainMap_) { if (effectChain) { effectChain->SetEffectProperty(property.effectClass, property.effectProp); diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp index 6080ef919d..fef72d3a84 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain_manager.cpp @@ -441,17 +441,7 @@ int32_t AudioEnhanceChainManager::SetAudioEnhanceProperty(const AudioEnhanceProp std::lock_guard lock(chainManagerMutex_); int32_t ret = 0; for (const auto &property : propertyArray.property) { - auto item = enhancePropertyMap_.find(property.enhanceClass); - if (item == enhancePropertyMap_.end()) { - enhancePropertyMap_[property.enhanceClass] = property.enhanceProp; - } else { - if (item->second == property.enhanceProp) { - AUDIO_INFO_LOG("No need to update effect %{public}s with mode %{public}s", - property.enhanceClass.c_str(), property.enhanceProp.c_str()); - continue; - } - item->second = property.enhanceProp; - } + enhancePropertyMap_.insert_or_assign(property.enhanceClass, property.enhanceProp); for (const auto &[sceneType, enhanceChain] : sceneTypeToEnhanceChainMap_) { if (enhanceChain) { ret = enhanceChain->SetEnhanceProperty(property.enhanceClass, property.enhanceProp); -- Gitee From 35333133ad537f0f2db261717425d3eccc391bdf Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 02:55:17 +0800 Subject: [PATCH 13/18] remove blank space Signed-off-by: owencreeper --- frameworks/native/audioeffect/src/audio_enhance_chain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp index b11639dc28..b29f34789f 100644 --- a/frameworks/native/audioeffect/src/audio_enhance_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_enhance_chain.cpp @@ -276,6 +276,5 @@ int32_t AudioEnhanceChain::SetPropertyToHandle(AudioEffectHandle handle, const s AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; return (*handle)->command(handle, EFFECT_CMD_SET_PROPERTY, &cmdInfo, &replyInfo); } - } // namespace AudioStandard } // namespace OHOS \ No newline at end of file -- Gitee From afeca5821da5a7da89814b15754d3201e4fe0aa6 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 03:05:08 +0800 Subject: [PATCH 14/18] remove extra enhanceparam Signed-off-by: owencreeper --- .../inner_api/native/audiocommon/include/audio_effect.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 1aa61419fa..719c226263 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -334,13 +334,6 @@ struct AudioEffectParam { int32_t data[]; }; -struct AudioEnhanceParam { - uint32_t muteInfo; - uint32_t volumeInfo; - const char *preDeivce; - const char *postDeivce; -}; - struct AudioBuffer { size_t frameLength; union { -- Gitee From 8c4960c67aad496230036ea9f9c27a20d1fc9946 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 03:10:41 +0800 Subject: [PATCH 15/18] add insert_or_assign Signed-off-by: owencreeper --- .../server/src/service/effect/audio_effect_manager.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index 89f0b4068a..5db6c2f016 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -506,12 +506,7 @@ void AudioEffectManager::UpdateSupportedEffectProperty(const Device &device, continue; } for (const auto &property : effectIter->effectProperty) { - auto deviceIter = device2PropertySet.find(device.type); - if (deviceIter == device2PropertySet.end()) { - device2PropertySet[device.type].insert({effectIter->name, property}); - } else { - deviceIter->second.insert({effectIter->name, property}); - } + device2PropertySet.insert_or_assign(device.type, {effectIter->name, property}); AUDIO_INFO_LOG("device %{public}s support effect [%{public}s, %{public}s]", device.type.c_str(), effectIter->name.c_str(), property.c_str()); } -- Gitee From 4f4bdd42b150c8f75f7937238af25d9352ed0509 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 03:33:16 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E6=94=B9=E9=94=99=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: owencreeper --- .../server/src/service/effect/audio_effect_manager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index 5db6c2f016..89f0b4068a 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -506,7 +506,12 @@ void AudioEffectManager::UpdateSupportedEffectProperty(const Device &device, continue; } for (const auto &property : effectIter->effectProperty) { - device2PropertySet.insert_or_assign(device.type, {effectIter->name, property}); + auto deviceIter = device2PropertySet.find(device.type); + if (deviceIter == device2PropertySet.end()) { + device2PropertySet[device.type].insert({effectIter->name, property}); + } else { + deviceIter->second.insert({effectIter->name, property}); + } AUDIO_INFO_LOG("device %{public}s support effect [%{public}s, %{public}s]", device.type.c_str(), effectIter->name.c_str(), property.c_str()); } -- Gitee From ff1ae7dd46222ed40c2e802182263c21626a1ab4 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 04:59:06 +0800 Subject: [PATCH 17/18] fix ut style Signed-off-by: owencreeper --- .../audio_effect_chain_manager_unit_test.cpp | 675 +++++++++--------- 1 file changed, 337 insertions(+), 338 deletions(-) diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index 2f6ebac1d8..6fe85c13c2 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -69,12 +69,12 @@ void AudioEffectChainManagerUnitTest::TearDownTestCase(void) {} void AudioEffectChainManagerUnitTest::SetUp(void) {} void AudioEffectChainManagerUnitTest::TearDown(void) {} -/** -* @tc.name : Test CreateAudioEffectChainDynamic API -* @tc.number : CreateAudioEffectChainDynamic_001 -* @tc.desc : Test CreateAudioEffectChainDynamic interface(using empty use case). -* Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. -*/ +/* + * tc.name : Test CreateAudioEffectChainDynamic API + * tc.number : CreateAudioEffectChainDynamic_001 + * tc.desc : Test CreateAudioEffectChainDynamic interface(using empty use case). + * Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_001, TestSize.Level1) { string sceneType = ""; @@ -87,12 +87,12 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_001, TestS AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CreateAudioEffectChainDynamic API -* @tc.number : CreateAudioEffectChainDynamic_002 -* @tc.desc : Test CreateAudioEffectChainDynamic interface(using abnormal use case). -* Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. -*/ +/* + * tc.name : Test CreateAudioEffectChainDynamic API + * tc.number : CreateAudioEffectChainDynamic_002 + * tc.desc : Test CreateAudioEffectChainDynamic interface(using abnormal use case). + * Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_002, TestSize.Level1) { string sceneType = "123"; @@ -105,12 +105,12 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_002, TestS AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CreateAudioEffectChainDynamic API -* @tc.number : CreateAudioEffectChainDynamic_003 -* @tc.desc : Test CreateAudioEffectChainDynamic interface(using correct use case). -* Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. -*/ +/* + * tc.name : Test CreateAudioEffectChainDynamic API + * tc.number : CreateAudioEffectChainDynamic_003 + * tc.desc : Test CreateAudioEffectChainDynamic interface(using correct use case). + * Test GetDeviceTypeName interface and SetAudioEffectChainDynamic interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_003, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -123,11 +123,11 @@ HWTEST(AudioEffectChainManagerUnitTest, CreateAudioEffectChainDynamic_003, TestS AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CheckAndAddSessionID API -* @tc.number : CheckAndAddSessionID_001 -* @tc.desc : Test CheckAndAddSessionID interface. -*/ +/* + * tc.name : Test CheckAndAddSessionID API + * tc.number : CheckAndAddSessionID_001 + * tc.desc : Test CheckAndAddSessionID interface. + */ HWTEST(AudioEffectChainManagerUnitTest, CheckAndAddSessionID_001, TestSize.Level1) { string sessionID = "123456"; @@ -137,11 +137,11 @@ HWTEST(AudioEffectChainManagerUnitTest, CheckAndAddSessionID_001, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CheckAndRemoveSessionID API -* @tc.number : CheckAndRemoveSessionID_001 -* @tc.desc : Test CheckAndRemoveSessionID interface(using incorrect use case). -*/ +/* + * tc.name : Test CheckAndRemoveSessionID API + * tc.number : CheckAndRemoveSessionID_001 + * tc.desc : Test CheckAndRemoveSessionID interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_001, TestSize.Level1) { string sessionID = "123456"; @@ -152,11 +152,11 @@ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_001, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CheckAndRemoveSessionID API -* @tc.number : CheckAndRemoveSessionID_002 -* @tc.desc : Test CheckAndRemoveSessionID interface(using correct use case). -*/ +/* + * tc.name : Test CheckAndRemoveSessionID API + * tc.number : CheckAndRemoveSessionID_002 + * tc.desc : Test CheckAndRemoveSessionID interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_002, TestSize.Level1) { string sessionID = "123456"; @@ -167,11 +167,11 @@ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_002, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test CheckAndRemoveSessionID API -* @tc.number : CheckAndRemoveSessionID_003 -* @tc.desc : Test CheckAndRemoveSessionID interface(without using CheckAndAddSessionID interface). -*/ +/* + * tc.name : Test CheckAndRemoveSessionID API + * tc.number : CheckAndRemoveSessionID_003 + * tc.desc : Test CheckAndRemoveSessionID interface(without using CheckAndAddSessionID interface). + */ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_003, TestSize.Level1) { string sessionID = "123456"; @@ -181,11 +181,11 @@ HWTEST(AudioEffectChainManagerUnitTest, CheckAndRemoveSessionID_003, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReleaseAudioEffectChainDynamic API -* @tc.number : ReleaseAudioEffectChainDynamic_001 -* @tc.desc : Test ReleaseAudioEffectChainDynamic interface(using empty use case). -*/ +/* + * tc.name : Test ReleaseAudioEffectChainDynamic API + * tc.number : ReleaseAudioEffectChainDynamic_001 + * tc.desc : Test ReleaseAudioEffectChainDynamic interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_001, TestSize.Level1) { string sceneType = ""; @@ -198,11 +198,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_001, Test AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReleaseAudioEffectChainDynamic API -* @tc.number : ReleaseAudioEffectChainDynamic_002 -* @tc.desc : Test ReleaseAudioEffectChainDynamic interface(using incorrect use case). -*/ +/* + * tc.name : Test ReleaseAudioEffectChainDynamic API + * tc.number : ReleaseAudioEffectChainDynamic_002 + * tc.desc : Test ReleaseAudioEffectChainDynamic interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_002, TestSize.Level1) { string sceneType = "123"; @@ -215,11 +215,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_002, Test AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReleaseAudioEffectChainDynamic API -* @tc.number : ReleaseAudioEffectChainDynamic_003 -* @tc.desc : Test ReleaseAudioEffectChainDynamic interface(using correct use case). -*/ +/* + * tc.name : Test ReleaseAudioEffectChainDynamic API + * tc.number : ReleaseAudioEffectChainDynamic_003 + * tc.desc : Test ReleaseAudioEffectChainDynamic interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_003, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -232,11 +232,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReleaseAudioEffectChainDynamic_003, Test AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ExistAudioEffectChain API -* @tc.number : ExistAudioEffectChain_001 -* @tc.desc : Test ExistAudioEffectChain interface(without using InitAudioEffectChainManager). -*/ +/* + * tc.name : Test ExistAudioEffectChain API + * tc.number : ExistAudioEffectChain_001 + * tc.desc : Test ExistAudioEffectChain interface(without using InitAudioEffectChainManager). + */ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -249,11 +249,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_001, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ExistAudioEffectChain API -* @tc.number : ExistAudioEffectChain_002 -* @tc.desc : Test ExistAudioEffectChain interface(using correct use case). -*/ +/* + * tc.name : Test ExistAudioEffectChain API + * tc.number : ExistAudioEffectChain_002 + * tc.desc : Test ExistAudioEffectChain interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -269,11 +269,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_002, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ExistAudioEffectChain API -* @tc.number : ExistAudioEffectChain_003 -* @tc.desc : Test ExistAudioEffectChain interface(using empty use case). -*/ +/* + * tc.name : Test ExistAudioEffectChain API + * tc.number : ExistAudioEffectChain_003 + * tc.desc : Test ExistAudioEffectChain interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_003, TestSize.Level1) { string sceneType = ""; @@ -289,11 +289,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_003, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ExistAudioEffectChain API -* @tc.number : ExistAudioEffectChain_004 -* @tc.desc : Test ExistAudioEffectChain interface(using incorrect use case). -*/ +/* + * tc.name : Test ExistAudioEffectChain API + * tc.number : ExistAudioEffectChain_004 + * tc.desc : Test ExistAudioEffectChain interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_004, TestSize.Level1) { string sceneType = "123"; @@ -309,11 +309,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_004, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ExistAudioEffectChain API -* @tc.number : ExistAudioEffectChain_005 -* @tc.desc : Test ExistAudioEffectChain interface(without using CreateAudioEffectChainDynamic). -*/ +/* + * tc.name : Test ExistAudioEffectChain API + * tc.number : ExistAudioEffectChain_005 + * tc.desc : Test ExistAudioEffectChain interface(without using CreateAudioEffectChainDynamic). + */ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_005, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -328,11 +328,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ExistAudioEffectChain_005, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ApplyAudioEffectChain API -* @tc.number : ApplyAudioEffectChain_001 -* @tc.desc : Test ApplyAudioEffectChain interface(using empty use case). -*/ +/* + * tc.name : Test ApplyAudioEffectChain API + * tc.number : ApplyAudioEffectChain_001 + * tc.desc : Test ApplyAudioEffectChain interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_001, TestSize.Level1) { float* bufIn; @@ -356,11 +356,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_001, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ApplyAudioEffectChain API -* @tc.number : ApplyAudioEffectChain_002 -* @tc.desc : Test ApplyAudioEffectChain interface(using correct use case). -*/ +/* + * tc.name : Test ApplyAudioEffectChain API + * tc.number : ApplyAudioEffectChain_002 + * tc.desc : Test ApplyAudioEffectChain interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_002, TestSize.Level1) { float* bufIn; @@ -384,11 +384,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_002, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ApplyAudioEffectChain API -* @tc.number : ApplyAudioEffectChain_003 -* @tc.desc : Test ApplyAudioEffectChain interface(using abnormal use case). -*/ +/* + * tc.name : Test ApplyAudioEffectChain API + * tc.number : ApplyAudioEffectChain_003 + * tc.desc : Test ApplyAudioEffectChain interface(using abnormal use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_003, TestSize.Level1) { float* bufIn; @@ -412,11 +412,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_003, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ApplyAudioEffectChain API -* @tc.number : ApplyAudioEffectChain_004 -* @tc.desc : Test ApplyAudioEffectChain interface(without using CreateAudioEffectChainDynamic interface). -*/ +/* + * tc.name : Test ApplyAudioEffectChain API + * tc.number : ApplyAudioEffectChain_004 + * tc.desc : Test ApplyAudioEffectChain interface(without using CreateAudioEffectChainDynamic interface). + */ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_004, TestSize.Level1) { float* bufIn; @@ -439,12 +439,12 @@ HWTEST(AudioEffectChainManagerUnitTest, ApplyAudioEffectChain_004, TestSize.Leve AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetOutputDeviceSink API -* @tc.number : SetOutputDeviceSink_001 -* @tc.desc : Test SetOutputDeviceSink interface(using correct use case), -* test SetSpkOffloadState interface simultaneously. -*/ +/* + * tc.name : Test SetOutputDeviceSink API + * tc.number : SetOutputDeviceSink_001 + * tc.desc : Test SetOutputDeviceSink interface(using correct use case), + * test SetSpkOffloadState interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_001, TestSize.Level1) { int32_t device = 2; @@ -456,12 +456,12 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_001, TestSize.Level1 AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetOutputDeviceSink API -* @tc.number : SetOutputDeviceSink_002 -* @tc.desc : Test SetOutputDeviceSink interface(using empty use case), -* test SetSpkOffloadState interface simultaneously. -*/ +/* + * tc.name : Test SetOutputDeviceSink API + * tc.number : SetOutputDeviceSink_002 + * tc.desc : Test SetOutputDeviceSink interface(using empty use case), + * test SetSpkOffloadState interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_002, TestSize.Level1) { int32_t device = 2; @@ -473,12 +473,12 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_002, TestSize.Level1 AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetOutputDeviceSink API -* @tc.number : SetOutputDeviceSink_003 -* @tc.desc : Test SetOutputDeviceSink interface(using abnormal use case), -* test SetSpkOffloadState interface simultaneously. -*/ +/* + * tc.name : Test SetOutputDeviceSink API + * tc.number : SetOutputDeviceSink_003 + * tc.desc : Test SetOutputDeviceSink interface(using abnormal use case), + * test SetSpkOffloadState interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_003, TestSize.Level1) { int32_t device = 2; @@ -490,11 +490,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetOutputDeviceSink_003, TestSize.Level1 AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test GetDeviceSinkName API -* @tc.number : GetDeviceSinkName_001 -* @tc.desc : Test GetDeviceSinkName interface. -*/ +/* + * tc.name : Test GetDeviceSinkName API + * tc.number : GetDeviceSinkName_001 + * tc.desc : Test GetDeviceSinkName interface. + */ HWTEST(AudioEffectChainManagerUnitTest, GetDeviceSinkName_001, TestSize.Level1) { string result = AudioEffectChainManager::GetInstance()->GetDeviceSinkName(); @@ -503,11 +503,11 @@ HWTEST(AudioEffectChainManagerUnitTest, GetDeviceSinkName_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test GetOffloadEnabled API -* @tc.number : GetOffloadEnabled_001 -* @tc.desc : Test GetOffloadEnabled interface. -*/ +/* + * tc.name : Test GetOffloadEnabled API + * tc.number : GetOffloadEnabled_001 + * tc.desc : Test GetOffloadEnabled interface. + */ HWTEST(AudioEffectChainManagerUnitTest, GetOffloadEnabled_001, TestSize.Level1) { bool result = AudioEffectChainManager::GetInstance()->GetOffloadEnabled(); @@ -516,21 +516,21 @@ HWTEST(AudioEffectChainManagerUnitTest, GetOffloadEnabled_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test Dump API -* @tc.number : Dump_001 -* @tc.desc : Test Dump interface. -*/ +/* + * tc.name : Test Dump API + * tc.number : Dump_001 + * tc.desc : Test Dump interface. + */ HWTEST(AudioEffectChainManagerUnitTest, Dump_001, TestSize.Level1) { AudioEffectChainManager::GetInstance()->Dump(); } -/** -* @tc.name : Test UpdateMultichannelConfig API -* @tc.number : UpdateMultichannelConfig_001 -* @tc.desc : Test UpdateMultichannelConfig interface(using correct use case). -*/ +/* + * tc.name : Test UpdateMultichannelConfig API + * tc.number : UpdateMultichannelConfig_001 + * tc.desc : Test UpdateMultichannelConfig interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -543,11 +543,11 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_001, TestSize.L AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test UpdateMultichannelConfig API -* @tc.number : UpdateMultichannelConfig_002 -* @tc.desc : Test UpdateMultichannelConfig interface(using abnormal use case). -*/ +/* + * tc.name : Test UpdateMultichannelConfig API + * tc.number : UpdateMultichannelConfig_002 + * tc.desc : Test UpdateMultichannelConfig interface(using abnormal use case). + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_002, TestSize.Level1) { string sceneType = "123"; @@ -560,11 +560,11 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_002, TestSize.L AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test UpdateMultichannelConfig API -* @tc.number : UpdateMultichannelConfig_003 -* @tc.desc : Test UpdateMultichannelConfig interface(using empty use case). -*/ +/* + * tc.name : Test UpdateMultichannelConfig API + * tc.number : UpdateMultichannelConfig_003 + * tc.desc : Test UpdateMultichannelConfig interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_003, TestSize.Level1) { string sceneType = ""; @@ -577,11 +577,11 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_003, TestSize.L AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test UpdateMultichannelConfig API -* @tc.number : UpdateMultichannelConfig_004 -* @tc.desc : Test UpdateMultichannelConfig interface(without using CreateAudioEffectChainDynamic interface). -*/ +/* + * tc.name : Test UpdateMultichannelConfig API + * tc.number : UpdateMultichannelConfig_004 + * tc.desc : Test UpdateMultichannelConfig interface(without using CreateAudioEffectChainDynamic interface). + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_004, TestSize.Level1) { string sceneType = ""; @@ -593,11 +593,11 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateMultichannelConfig_004, TestSize.L AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test InitAudioEffectChainDynamic API -* @tc.number : InitAudioEffectChainDynamic_001 -* @tc.desc : Test InitAudioEffectChainDynamic interface(without using InitAudioEffectChainManager interface). -*/ +/* + * tc.name : Test InitAudioEffectChainDynamic API + * tc.number : InitAudioEffectChainDynamic_001 + * tc.desc : Test InitAudioEffectChainDynamic interface(without using InitAudioEffectChainManager interface). + */ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -607,11 +607,11 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_001, TestSiz AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test InitAudioEffectChainDynamic API -* @tc.number : InitAudioEffectChainDynamic_002 -* @tc.desc : Test InitAudioEffectChainDynamic interface(using correct use case). -*/ +/* + * tc.name : Test InitAudioEffectChainDynamic API + * tc.number : InitAudioEffectChainDynamic_002 + * tc.desc : Test InitAudioEffectChainDynamic interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -623,11 +623,11 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_002, TestSiz AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test InitAudioEffectChainDynamic API -* @tc.number : InitAudioEffectChainDynamic_003 -* @tc.desc : Test InitAudioEffectChainDynamic interface(using incorrect use case). -*/ +/* + * tc.name : Test InitAudioEffectChainDynamic API + * tc.number : InitAudioEffectChainDynamic_003 + * tc.desc : Test InitAudioEffectChainDynamic interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_003, TestSize.Level1) { string sceneType = "123"; @@ -639,11 +639,11 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_003, TestSiz AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test InitAudioEffectChainDynamic API -* @tc.number : InitAudioEffectChainDynamic_004 -* @tc.desc : Test InitAudioEffectChainDynamic interface(using empty use case). -*/ +/* + * tc.name : Test InitAudioEffectChainDynamic API + * tc.number : InitAudioEffectChainDynamic_004 + * tc.desc : Test InitAudioEffectChainDynamic interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_004, TestSize.Level1) { string sceneType = ""; @@ -655,12 +655,12 @@ HWTEST(AudioEffectChainManagerUnitTest, InitAudioEffectChainDynamic_004, TestSiz AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test UpdateSpatializationState API -* @tc.number : UpdateSpatializationState_001 -* @tc.desc : Test UpdateSpatializationState interface.Test UpdateSensorState, -* DeleteAllChains and RecoverAllChains interface simultaneously. -*/ +/* + * tc.name : Test UpdateSpatializationState API + * tc.number : UpdateSpatializationState_001 + * tc.desc : Test UpdateSpatializationState interface.Test UpdateSensorState, + * DeleteAllChains and RecoverAllChains interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_001, TestSize.Level1) { AudioSpatializationState spatializationState = {false, false}; @@ -670,12 +670,12 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_001, TestSize. AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test UpdateSpatializationState API -* @tc.number : UpdateSpatializationState_002 -* @tc.desc : Test UpdateSpatializationState interface.Test UpdateSensorState, -* DeleteAllChains and RecoverAllChains interface simultaneously. -*/ +/* + * tc.name : Test UpdateSpatializationState API + * tc.number : UpdateSpatializationState_002 + * tc.desc : Test UpdateSpatializationState interface.Test UpdateSensorState, + * DeleteAllChains and RecoverAllChains interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_002, TestSize.Level1) { AudioSpatializationState spatializationState = {true, true}; @@ -685,11 +685,11 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_002, TestSize. AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetHdiParam API -* @tc.number : SetHdiParam_001 -* @tc.desc : Test SetHdiParam interface(without using InitAudioEffectChainManager interface). -*/ +/* + * tc.name : Test SetHdiParam API + * tc.number : SetHdiParam_001 + * tc.desc : Test SetHdiParam interface(without using InitAudioEffectChainManager interface). + */ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -701,11 +701,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetHdiParam API -* @tc.number : SetHdiParam_002 -* @tc.desc : Test SetHdiParam interface(enabled = true). -*/ +/* + * tc.name : Test SetHdiParam API + * tc.number : SetHdiParam_002 + * tc.desc : Test SetHdiParam interface(enabled = true). + */ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -719,11 +719,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_002, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetHdiParam API -* @tc.number : SetHdiParam_003 -* @tc.desc : Test SetHdiParam interface(enabled = false). -*/ +/* + * tc.name : Test SetHdiParam API + * tc.number : SetHdiParam_003 + * tc.desc : Test SetHdiParam interface(enabled = false). + */ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_003, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -737,11 +737,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_003, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetHdiParam API -* @tc.number : SetHdiParam_004 -* @tc.desc : Test SetHdiParam interface(using empty use case). -*/ +/* + * tc.name : Test SetHdiParam API + * tc.number : SetHdiParam_004 + * tc.desc : Test SetHdiParam interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_004, TestSize.Level1) { string sceneType = ""; @@ -755,11 +755,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_004, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SetHdiParam API -* @tc.number : SetHdiParam_005 -* @tc.desc : Test SetHdiParam interface(using incorrect use case). -*/ +/* + * tc.name : Test SetHdiParam API + * tc.number : SetHdiParam_005 + * tc.desc : Test SetHdiParam interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_005, TestSize.Level1) { string sceneType = "123"; @@ -773,11 +773,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetHdiParam_005, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapAdd API -* @tc.number : SessionInfoMapAdd_001 -* @tc.desc : Test SessionInfoMapAdd interface. -*/ +/* + * tc.name : Test SessionInfoMapAdd API + * tc.number : SessionInfoMapAdd_001 + * tc.desc : Test SessionInfoMapAdd interface. + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapAdd_001, TestSize.Level1) { string sessionID = "123456"; @@ -787,11 +787,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapAdd_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapAdd API -* @tc.number : SessionInfoMapAdd_002 -* @tc.desc : Test SessionInfoMapAdd interface(using empty use case). -*/ +/* + * tc.name : Test SessionInfoMapAdd API + * tc.number : SessionInfoMapAdd_002 + * tc.desc : Test SessionInfoMapAdd interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapAdd_002, TestSize.Level1) { string sessionID = ""; @@ -801,11 +801,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapAdd_002, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapDelete API -* @tc.number : SessionInfoMapDelete_001 -* @tc.desc : Test SessionInfoMapDelete interface(without using SessionInfoMapAdd interface). -*/ +/* + * tc.name : Test SessionInfoMapDelete API + * tc.number : SessionInfoMapDelete_001 + * tc.desc : Test SessionInfoMapDelete interface(without using SessionInfoMapAdd interface). + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -816,11 +816,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_001, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapDelete API -* @tc.number : SessionInfoMapDelete_002 -* @tc.desc : Test SessionInfoMapDelete interface(using correct use case). -*/ +/* + * tc.name : Test SessionInfoMapDelete API + * tc.number : SessionInfoMapDelete_002 + * tc.desc : Test SessionInfoMapDelete interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -834,11 +834,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_002, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapDelete API -* @tc.number : SessionInfoMapDelete_003 -* @tc.desc : Test SessionInfoMapDelete interface(using incorrect use case). -*/ +/* + * tc.name : Test SessionInfoMapDelete API + * tc.number : SessionInfoMapDelete_003 + * tc.desc : Test SessionInfoMapDelete interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_003, TestSize.Level1) { string sceneType = "123"; @@ -850,11 +850,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_003, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test SessionInfoMapDelete API -* @tc.number : SessionInfoMapDelete_004 -* @tc.desc : Test SessionInfoMapDelete interface(using empty use case). -*/ +/* + * tc.name : Test SessionInfoMapDelete API + * tc.number : SessionInfoMapDelete_004 + * tc.desc : Test SessionInfoMapDelete interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_004, TestSize.Level1) { string sceneType = ""; @@ -866,11 +866,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SessionInfoMapDelete_004, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReturnEffectChannelInfo API -* @tc.number : ReturnEffectChannelInfo_001 -* @tc.desc : Test ReturnEffectChannelInfo interface(without using SessionInfoMapAdd interface). -*/ +/* + * tc.name : Test ReturnEffectChannelInfo API + * tc.number : ReturnEffectChannelInfo_001 + * tc.desc : Test ReturnEffectChannelInfo interface(without using SessionInfoMapAdd interface). + */ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -883,11 +883,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_001, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReturnEffectChannelInfo API -* @tc.number : ReturnEffectChannelInfo_002 -* @tc.desc : Test ReturnEffectChannelInfo interface(using correct use case). -*/ +/* + * tc.name : Test ReturnEffectChannelInfo API + * tc.number : ReturnEffectChannelInfo_002 + * tc.desc : Test ReturnEffectChannelInfo interface(using correct use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -908,11 +908,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_002, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReturnEffectChannelInfo API -* @tc.number : ReturnEffectChannelInfo_003 -* @tc.desc : Test ReturnEffectChannelInfo interface(using incorrect use case). -*/ +/* + * tc.name : Test ReturnEffectChannelInfo API + * tc.number : ReturnEffectChannelInfo_003 + * tc.desc : Test ReturnEffectChannelInfo interface(using incorrect use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_003, TestSize.Level1) { string sceneType = "123"; @@ -927,11 +927,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_003, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReturnEffectChannelInfo API -* @tc.number : ReturnEffectChannelInfo_004 -* @tc.desc : Test ReturnEffectChannelInfo interface(using empty use case). -*/ +/* + * tc.name : Test ReturnEffectChannelInfo API + * tc.number : ReturnEffectChannelInfo_004 + * tc.desc : Test ReturnEffectChannelInfo interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_004, TestSize.Level1) { string sceneType = ""; @@ -946,11 +946,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnEffectChannelInfo_004, TestSize.Le AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ReturnMultiChannelInfo API -* @tc.number : ReturnMultiChannelInfo_001 -* @tc.desc : Test ReturnMultiChannelInfo interface. -*/ +/* + * tc.name : Test ReturnMultiChannelInfo API + * tc.number : ReturnMultiChannelInfo_001 + * tc.desc : Test ReturnMultiChannelInfo interface. + */ HWTEST(AudioEffectChainManagerUnitTest, ReturnMultiChannelInfo_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -964,11 +964,11 @@ HWTEST(AudioEffectChainManagerUnitTest, ReturnMultiChannelInfo_001, TestSize.Lev AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test RegisterEffectChainCountBackupMap API -* @tc.number : RegisterEffectChainCountBackupMap_001 -* @tc.desc : Test RegisterEffectChainCountBackupMap interface. -*/ +/* + * tc.name : Test RegisterEffectChainCountBackupMap API + * tc.number : RegisterEffectChainCountBackupMap_001 + * tc.desc : Test RegisterEffectChainCountBackupMap interface. + */ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_001, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -978,11 +978,11 @@ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_001, T AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test RegisterEffectChainCountBackupMap API -* @tc.number : RegisterEffectChainCountBackupMap_002 -* @tc.desc : Test RegisterEffectChainCountBackupMap interface. -*/ +/* + * tc.name : Test RegisterEffectChainCountBackupMap API + * tc.number : RegisterEffectChainCountBackupMap_002 + * tc.desc : Test RegisterEffectChainCountBackupMap interface. + */ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_002, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -992,11 +992,11 @@ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_002, T AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test RegisterEffectChainCountBackupMap API -* @tc.number : RegisterEffectChainCountBackupMap_003 -* @tc.desc : Test RegisterEffectChainCountBackupMap interface(using empty use case). -*/ +/* + * tc.name : Test RegisterEffectChainCountBackupMap API + * tc.number : RegisterEffectChainCountBackupMap_003 + * tc.desc : Test RegisterEffectChainCountBackupMap interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_003, TestSize.Level1) { string sceneType = "SCENE_MOVIE"; @@ -1006,12 +1006,12 @@ HWTEST(AudioEffectChainManagerUnitTest, RegisterEffectChainCountBackupMap_003, T AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test EffectRotationUpdate API -* @tc.number : EffectRotationUpdate_001 -* @tc.desc : Test EffectRotationUpdate interface. -* Test EffectDspRotationUpdate and EffectApRotationUpdate simultaneously. -*/ +/* + * tc.name : Test EffectRotationUpdate API + * tc.number : EffectRotationUpdate_001 + * tc.desc : Test EffectRotationUpdate interface. + * Test EffectDspRotationUpdate and EffectApRotationUpdate simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, EffectRotationUpdate_001, TestSize.Level1) { uint32_t rotationState = 0; @@ -1021,12 +1021,12 @@ HWTEST(AudioEffectChainManagerUnitTest, EffectRotationUpdate_001, TestSize.Level AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test EffectRotationUpdate API -* @tc.number : EffectRotationUpdate_002 -* @tc.desc : Test EffectRotationUpdate interface. -* Test EffectDspRotationUpdate and EffectApRotationUpdate simultaneously. -*/ +/* + * tc.name : Test EffectRotationUpdate API + * tc.number : EffectRotationUpdate_002 + * tc.desc : Test EffectRotationUpdate interface. + * Test EffectDspRotationUpdate and EffectApRotationUpdate simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, EffectRotationUpdate_002, TestSize.Level1) { uint32_t rotationState = 1; @@ -1035,11 +1035,11 @@ HWTEST(AudioEffectChainManagerUnitTest, EffectRotationUpdate_002, TestSize.Level EXPECT_EQ(SUCCESS, result); } -/** -* @tc.name : Test EffectVolumeUpdate API -* @tc.number : EffectVolumeUpdate_001 -* @tc.desc : Test EffectVolumeUpdate interface.Test EffectDspVolumeUpdate and EffectApVolumeUpdate simultaneously. -*/ +/* + * tc.name : Test EffectVolumeUpdate API + * tc.number : EffectVolumeUpdate_001 + * tc.desc : Test EffectVolumeUpdate interface.Test EffectDspVolumeUpdate and EffectApVolumeUpdate simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, StreamVolumeUpdate_001, TestSize.Level1) { string sessionIDString = "123456"; @@ -1051,12 +1051,12 @@ HWTEST(AudioEffectChainManagerUnitTest, StreamVolumeUpdate_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test EffectVolumeUpdate API -* @tc.number : EffectVolumeUpdate_002 -* @tc.desc : Test EffectVolumeUpdate interface(using abnormal use case). -* Test EffectDspVolumeUpdate and EffectApVolumeUpdate simultaneously. -*/ +/* + * tc.name : Test EffectVolumeUpdate API + * tc.number : EffectVolumeUpdate_002 + * tc.desc : Test EffectVolumeUpdate interface(using abnormal use case). + * Test EffectDspVolumeUpdate and EffectApVolumeUpdate simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, SystemVolumeUpdate_001, TestSize.Level1) { float systemVolume = 0.888; @@ -1068,11 +1068,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SystemVolumeUpdate_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test GetLatency API -* @tc.number : GetLatency_001 -* @tc.desc : Test GetLatency interface. -*/ +/* + * tc.name : Test GetLatency API + * tc.number : GetLatency_001 + * tc.desc : Test GetLatency interface. + */ HWTEST(AudioEffectChainManagerUnitTest, GetLatency_001, TestSize.Level1) { string sessionID = "123456" ; @@ -1083,11 +1083,11 @@ HWTEST(AudioEffectChainManagerUnitTest, GetLatency_001, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test GetLatency API -* @tc.number : GetLatency_002 -* @tc.desc : Test GetLatency interface(using empty use case). -*/ +/* + * tc.name : Test GetLatency API + * tc.number : GetLatency_002 + * tc.desc : Test GetLatency interface(using empty use case). + */ HWTEST(AudioEffectChainManagerUnitTest, GetLatency_002, TestSize.Level1) { string sessionID = "" ; @@ -1098,13 +1098,12 @@ HWTEST(AudioEffectChainManagerUnitTest, GetLatency_002, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } - -/** -* @tc.name : Test SetSpatializationSceneType API -* @tc.number : SetSpatializationSceneType_001 -* @tc.desc : Test SetSpatializationSceneType interface. -* Test GetSceneTypeFromSpatializationSceneType and UpdateEffectChainParams interface simultaneously. -*/ +/* + * tc.name : Test SetSpatializationSceneType API + * tc.number : SetSpatializationSceneType_001 + * tc.desc : Test SetSpatializationSceneType interface. + * Test GetSceneTypeFromSpatializationSceneType and UpdateEffectChainParams interface simultaneously. + */ HWTEST(AudioEffectChainManagerUnitTest, SetSpatializationSceneType_001, TestSize.Level1) { AudioSpatializationSceneType spatializationSceneType = SPATIALIZATION_SCENE_TYPE_DEFAULT; @@ -1114,11 +1113,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetSpatializationSceneType_001, TestSize AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test GetCurSpatializationEnabled API -* @tc.number : GetCurSpatializationEnabled_001 -* @tc.desc : Test GetCurSpatializationEnabled interface. -*/ +/* + * tc.name : Test GetCurSpatializationEnabled API + * tc.number : GetCurSpatializationEnabled_001 + * tc.desc : Test GetCurSpatializationEnabled interface. + */ HWTEST(AudioEffectChainManagerUnitTest, GetCurSpatializationEnabled_001, TestSize.Level1) { bool result = AudioEffectChainManager::GetInstance()->GetCurSpatializationEnabled(); @@ -1126,21 +1125,21 @@ HWTEST(AudioEffectChainManagerUnitTest, GetCurSpatializationEnabled_001, TestSiz AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test ResetEffectBuffer API -* @tc.number : ResetEffectBuffer_001 -* @tc.desc : Test ResetEffectBuffer interface. -*/ +/* + * tc.name : Test ResetEffectBuffer API + * tc.number : ResetEffectBuffer_001 + * tc.desc : Test ResetEffectBuffer interface. + */ HWTEST(AudioEffectChainManagerUnitTest, ResetEffectBuffer_001, TestSize.Level1) { AudioEffectChainManager::GetInstance()->ResetEffectBuffer(); } -/** -* @tc.name : Test GetAudioEffectProperty API -* @tc.number : GetAudioEffectProperty_001 -* @tc.desc : Test GetAudioEffectProperty interface. -*/ +/* + * tc.name : Test GetAudioEffectProperty API + * tc.number : GetAudioEffectProperty_001 + * tc.desc : Test GetAudioEffectProperty interface. + */ HWTEST(AudioEffectChainManagerUnitTest, GetAudioEffectProperty_001, TestSize.Level1) { AudioEffectChainManager::GetInstance()->ResetInfo(); @@ -1156,11 +1155,11 @@ HWTEST(AudioEffectChainManagerUnitTest, GetAudioEffectProperty_001, TestSize.Lev } } -/** -* @tc.name : Test SetAudioEffectProperty API -* @tc.number : SetAudioEffectProperty_001 -* @tc.desc : Test SetAudioEffectProperty interface. -*/ +/* + * tc.name : Test SetAudioEffectProperty API + * tc.number : SetAudioEffectProperty_001 + * tc.desc : Test SetAudioEffectProperty interface. + */ HWTEST(AudioEffectChainManagerUnitTest, SetAudioEffectProperty_001, TestSize.Level1) { AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); -- Gitee From 87dff2c0fb40d867cc3e6e286ae152612d4238c7 Mon Sep 17 00:00:00 2001 From: owencreeper Date: Sat, 20 Jul 2024 05:23:22 +0800 Subject: [PATCH 18/18] fix func name Signed-off-by: owencreeper --- .../include/service/effect/audio_effect_manager.h | 6 +++--- .../server/src/service/audio_policy_service.cpp | 8 ++++---- .../server/src/service/effect/audio_effect_manager.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/services/audio_policy/server/include/service/effect/audio_effect_manager.h b/services/audio_policy/server/include/service/effect/audio_effect_manager.h index f6059080d4..c0a94e5197 100644 --- a/services/audio_policy/server/include/service/effect/audio_effect_manager.h +++ b/services/audio_policy/server/include/service/effect/audio_effect_manager.h @@ -43,9 +43,9 @@ public: void ConstructEffectChainManagerParam(EffectChainManagerParam &effectChainMgrParam); void ConstructEnhanceChainManagerParam(EffectChainManagerParam &enhanceChainMgrParam); int32_t QueryEffectManagerSceneMode(SupportedEffectConfig &supportedEffectConfig); - int32_t GetSupportedAudioEffectProperty(const DeviceType& deviceType, + int32_t AddSupportedAudioEffectPropertyByDevice(const DeviceType& deviceType, std::set> &mergedSet); - int32_t GetSupportedAudioEnhanceProperty(const DeviceType& deviceType, + int32_t AddSupportedAudioEnhancePropertyByDevice(const DeviceType& deviceType, std::set> &mergedSet); private: @@ -75,7 +75,7 @@ private: void UpdateDuplicateProcessNew(std::vector &availableLayout, ProcessNew &processNew); void ConstructDefaultEffectProperty(const std::string &chainName, std::unordered_map &defaultProperty); - int32_t GetSupportedPropertyInner(const DeviceType& deviceType, + int32_t AddSupportedPropertyByDeviceInner(const DeviceType& deviceType, std::set> &mergedSet, const std::unordered_map>> &device2PropertySet); }; diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index 8ab8752c0c..fca41895ed 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -8428,10 +8428,10 @@ int32_t AudioPolicyService::GetSupportedAudioEffectProperty(AudioEffectPropertyA { std::set> mergedSet = {}; // Get supported property for all device - audioEffectManager_.GetSupportedAudioEnhanceProperty(DEVICE_TYPE_INVALID, mergedSet); + audioEffectManager_.AddSupportedAudioEffectPropertyByDevice(DEVICE_TYPE_INVALID, mergedSet); std::vector> descriptor = GetDevices(OUTPUT_DEVICES_FLAG); for (auto &item : descriptor) { - audioEffectManager_.GetSupportedAudioEffectProperty(item->getType(), mergedSet); + audioEffectManager_.AddSupportedAudioEffectPropertyByDevice(item->getType(), mergedSet); } propertyArray.property.reserve(mergedSet.size()); std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), @@ -8445,10 +8445,10 @@ int32_t AudioPolicyService::GetSupportedAudioEnhanceProperty(AudioEnhancePropert { std::set> mergedSet = {}; // Get supported property for all device - audioEffectManager_.GetSupportedAudioEnhanceProperty(DEVICE_TYPE_INVALID, mergedSet); + audioEffectManager_.AddSupportedAudioEnhancePropertyByDevice(DEVICE_TYPE_INVALID, mergedSet); std::vector> descriptor = GetDevices(INPUT_DEVICES_FLAG); for (auto &item : descriptor) { - audioEffectManager_.GetSupportedAudioEnhanceProperty(item->getType(), mergedSet); + audioEffectManager_.AddSupportedAudioEnhancePropertyByDevice(item->getType(), mergedSet); } propertyArray.property.reserve(mergedSet.size()); std::transform(mergedSet.begin(), mergedSet.end(), std::back_inserter(propertyArray.property), diff --git a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp index 89f0b4068a..607ab5d0ab 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_manager.cpp @@ -696,7 +696,7 @@ void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerPar (int32_t)map.size()); } -int32_t AudioEffectManager::GetSupportedPropertyInner(const DeviceType& deviceType, +int32_t AudioEffectManager::AddSupportedPropertyByDeviceInner(const DeviceType& deviceType, std::set> &mergedSet, const std::unordered_map>> &device2PropertySet) { @@ -713,16 +713,16 @@ int32_t AudioEffectManager::GetSupportedPropertyInner(const DeviceType& deviceTy return AUDIO_OK; } -int32_t AudioEffectManager::GetSupportedAudioEffectProperty(const DeviceType &deviceType, +int32_t AudioEffectManager::AddSupportedAudioEffectPropertyByDevice(const DeviceType &deviceType, std::set> &mergedSet) { - return GetSupportedPropertyInner(deviceType, mergedSet, device2EffectPropertySet_); + return AddSupportedPropertyByDeviceInner(deviceType, mergedSet, device2EffectPropertySet_); } -int32_t AudioEffectManager::GetSupportedAudioEnhanceProperty(const DeviceType &deviceType, +int32_t AudioEffectManager::AddSupportedAudioEnhancePropertyByDevice(const DeviceType &deviceType, std::set> &mergedSet) { - return GetSupportedPropertyInner(deviceType, mergedSet, device2EnhancePropertySet_); + return AddSupportedPropertyByDeviceInner(deviceType, mergedSet, device2EnhancePropertySet_); } } // namespce AudioStandard } // namespace OHOS -- Gitee