diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index f8f802856338cdc133b087ceaf42650c08e7e235..22de0be68d5a9e9be90150ca1924211728123742 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -35,6 +35,7 @@ constexpr int32_t AUDIO_EFFECT_COUNT_UPPER_LIMIT = 20; constexpr int32_t AUDIO_EFFECT_COUNT_STREAM_USAGE_UPPER_LIMIT = 200; constexpr int32_t AUDIO_EFFECT_COUNT_FIRST_NODE_UPPER_LIMIT = 1; constexpr int32_t AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT = 1; +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 @@ -74,6 +75,7 @@ struct Library { struct Effect { std::string name; std::string libraryName; + std::vector effectProperty; }; struct EffectChain { @@ -87,13 +89,13 @@ struct Device { std::string chain; }; -struct Preprocess { +struct PreStreamScene { std::string stream; std::vector mode; std::vector> device; }; -struct EffectSceneStream { +struct PostStreamScene { std::string stream; std::vector mode; std::vector> device; @@ -104,8 +106,18 @@ struct SceneMappingItem { std::string sceneType; }; +struct PreProcessConfig { + int32_t maxExtSceneNum; + std::vector defaultScenes; + std::vector priorScenes; + std::vector normalScenes; +}; + struct PostProcessConfig { - std::vector effectSceneStreams; + int32_t maxExtSceneNum; + std::vector defaultScenes; + std::vector priorScenes; + std::vector normalScenes; std::vector sceneMap; }; @@ -114,16 +126,31 @@ struct OriginalEffectConfig { std::vector libraries; std::vector effects; std::vector effectChains; - std::vector preProcess; + PreProcessConfig preProcess; PostProcessConfig postProcess; }; +struct EffectChainManagerParam { + uint32_t maxExtraNum = 0; + std::string defaultSceneName; + std::vector priorSceneList; + std::unordered_map sceneTypeToChainNameMap; + std::unordered_map effectDefaultProperty; +}; + struct StreamEffectMode { std::string mode; std::vector devicePort; }; +enum ScenePriority { + DEFAULT_SCENE = 0, + PRIOR_SCENE = 1, + NORMAL_SCENE = 2 +}; + struct Stream { + ScenePriority priority; std::string scene; std::vector streamEffectMode; }; @@ -150,7 +177,7 @@ enum AudioEffectScene { SCENE_GAME = 3, SCENE_SPEECH = 4, SCENE_RING = 5, - SCENE_VOIP = 6 + SCENE_VOIP_DOWN = 6, }; /** @@ -158,7 +185,9 @@ enum AudioEffectScene { */ enum AudioEnhanceScene { SCENE_VOIP_UP = 0, - SCENE_RECORD = 1 + SCENE_RECORD = 1, + SCENE_PRE_ENHANCE = 2, + SCENE_ASR = 4, }; /** @@ -187,12 +216,15 @@ const std::unordered_map AUDIO_SUPPORTED_SCENE_TY {SCENE_MOVIE, "SCENE_MOVIE"}, {SCENE_GAME, "SCENE_GAME"}, {SCENE_SPEECH, "SCENE_SPEECH"}, - {SCENE_RING, "SCENE_RING"} + {SCENE_RING, "SCENE_RING"}, + {SCENE_VOIP_DOWN, "SCENE_VOIP_DOWN"}, }; const std::unordered_map AUDIO_ENHANCE_SUPPORTED_SCENE_TYPES { {SCENE_VOIP_UP, "SCENE_VOIP_UP"}, - {SCENE_RECORD, "SCENE_RECORD"} + {SCENE_RECORD, "SCENE_RECORD"}, + {SCENE_ASR, "SCENE_ASR"}, + {SCENE_PRE_ENHANCE, "SCENE_PRE_ENHANCE"}, }; const std::unordered_map AUDIO_SUPPORTED_SCENE_MODES { diff --git a/services/audio_policy/server/config/audio_effect_config.xml b/services/audio_policy/server/config/audio_effect_config.xml index ee97444952eb884cc1c9b749c2d9ca8a67a0e42a..df21b53c16ef0bb9f82219d1972fe8d38e25fa32 100644 --- a/services/audio_policy/server/config/audio_effect_config.xml +++ b/services/audio_policy/server/config/audio_effect_config.xml @@ -17,15 +17,18 @@ - - + + - - + + + + + @@ -36,45 +39,54 @@ - + - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + @@ -105,7 +117,7 @@ - + diff --git a/services/audio_policy/server/include/service/effect/audio_effect_config_parser.h b/services/audio_policy/server/include/service/effect/audio_effect_config_parser.h index 34c65c1ea0ee067fd3edee7f7dddb8eb867faa79..08d04ce210bb04ac99b7fe9f2dcf580a25550a69 100644 --- a/services/audio_policy/server/include/service/effect/audio_effect_config_parser.h +++ b/services/audio_policy/server/include/service/effect/audio_effect_config_parser.h @@ -26,6 +26,22 @@ namespace OHOS { namespace AudioStandard { +typedef enum { + INDEX_PRE_DEFAULT_SCENE = 0, + INDEX_PRE_PRIOR_SCENE = 1, + INDEX_PRE_NORMAL_SCENE = 2, + INDEX_PRE_EXCEPTION = 3, + NODE_SIZE_PRE = 4, +} XmlPreNodeIndex; + +typedef enum { + INDEX_POST_DEFAULT_SCENE = 0, + INDEX_POST_PRIOR_SCENE = 1, + INDEX_POST_NORMAL_SCENE = 2, + INDEX_POST_MAPPING = 3, + INDEX_POST_EXCEPTION = 4, + NODE_SIZE_POST = 5, +} XmlPostNodeIndex; class AudioEffectConfigParser { public: 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 aa6fd828d728d1309e5440fd63f27601575c8d1f..89ddc115f0ee155d802efb78404579110646bc2f 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 @@ -40,8 +40,8 @@ public: void SetMasterSinkAvailable(); void SetEffectChainManagerAvailable(); bool CanLoadEffectSinks(); - void ConstructSceneTypeToEffectChainNameMap(std::unordered_map &map); - void ConstructSceneTypeToEnhanceChainNameMap(std::unordered_map &map); + void ConstructEffectChainManagerParam(EffectChainManagerParam &effectChainMgrParam); + void ConstructEnhanceChainManagerParam(EffectChainManagerParam &enhanceChainMgrParam); int32_t QueryEffectManagerSceneMode(SupportedEffectConfig &supportedEffectConfig); private: OriginalEffectConfig oriEffectConfig_; @@ -54,10 +54,12 @@ private: void UpdateAvailableAEConfig(OriginalEffectConfig &aeConfig); void UpdateEffectChains(std::vector &availableLayout); - void UpdateDuplicateBypassMode(ProcessNew &preProcessNew); - void UpdateDuplicateMode(ProcessNew &preProcessNew); - void UpdateDuplicateDevice(ProcessNew &preProcessNew); - int32_t UpdateUnavailableEffectChains(std::vector &availableLayout, ProcessNew &preProcessNew); + void UpdateDuplicateBypassMode(ProcessNew &processNew); + void UpdateDuplicateMode(ProcessNew &processNew); + void UpdateDuplicateDefaultScene(ProcessNew &processNew); + void UpdateDuplicateScene(ProcessNew &processNew); + void UpdateDuplicateDevice(ProcessNew &processNew); + int32_t UpdateUnavailableEffectChains(std::vector &availableLayout, ProcessNew &processNew); bool VerifySceneMappingItem(const SceneMappingItem &item); }; } // namespce AudioStandard 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 1e619f358d23abaee751c90ad40d685b2752675f..71e1a9b6f0e22e6a41f3f4eea172c39feec22e8f 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -4396,14 +4396,14 @@ void AudioPolicyService::LoadEffectLibrary() // Initialize EffectChainManager in audio service through IPC SupportedEffectConfig supportedEffectConfig; audioEffectManager_.GetSupportedEffectConfig(supportedEffectConfig); - std::unordered_map sceneTypeToEffectChainNameMap; - audioEffectManager_.ConstructSceneTypeToEffectChainNameMap(sceneTypeToEffectChainNameMap); - std::unordered_map sceneTypeToEnhanceChainNameMap; - audioEffectManager_.ConstructSceneTypeToEnhanceChainNameMap(sceneTypeToEnhanceChainNameMap); + std::unique_ptr effectChainMgrParam = std::make_unique(); + std::unique_ptr enhanceChainMgrParam = std::make_unique(); + audioEffectManager_.ConstructEffectChainManagerParam(*effectChainMgrParam); + audioEffectManager_.ConstructEnhanceChainManagerParam(*enhanceChainMgrParam); identity = IPCSkeleton::ResetCallingIdentity(); bool ret = gsp->CreateEffectChainManager(supportedEffectConfig.effectChains, - sceneTypeToEffectChainNameMap, sceneTypeToEnhanceChainNameMap); + effectChainMgrParam->sceneTypeToChainNameMap, enhanceChainMgrParam->sceneTypeToChainNameMap); IPCSkeleton::SetCallingIdentity(identity); CHECK_AND_RETURN_LOG(ret, "EffectChainManager create failed"); diff --git a/services/audio_policy/server/src/service/effect/audio_effect_config_parser.cpp b/services/audio_policy/server/src/service/effect/audio_effect_config_parser.cpp index 1763ad40b3ea167a1b14fb2fd7ab6f1bd09cd13c..7d7e436a8e893cd9935bf9df867f51154a3cd849 100644 --- a/services/audio_policy/server/src/service/effect/audio_effect_config_parser.cpp +++ b/services/audio_policy/server/src/service/effect/audio_effect_config_parser.cpp @@ -43,10 +43,6 @@ static constexpr int32_t NODE_SIZE = 6; static constexpr int32_t MODULE_SIZE = 5; static constexpr uint32_t XML_PARSE_NOERROR = 1 << 5; static constexpr uint32_t XML_PARSE_NOWARNING = 1 << 6; -static constexpr int32_t INDEX_POST_STREAMS = 0; -static constexpr int32_t INDEX_POST_MAPPING = 1; -static constexpr int32_t INDEX_POST_EXCEPTION = 2; -static constexpr int32_t NODE_SIZE_POST = 3; AudioEffectConfigParser::AudioEffectConfigParser() { @@ -175,10 +171,45 @@ static void LoadEffectConfigLibraries(OriginalEffectConfig &result, const xmlNod } } +static void LoadEffectProperty(OriginalEffectConfig &result, const xmlNode *thirdNode, const int32_t effectIdx) +{ + CHECK_AND_RETURN_LOG(thirdNode->xmlChildrenNode, "effect '%{public}s' does not support effectProperty settings.", + result.effects[effectIdx].name.c_str()); + int32_t countProperty = 0; + xmlNode *currNode = thirdNode->xmlChildrenNode; + while (currNode != nullptr) { + CHECK_AND_RETURN_LOG(countProperty < AUDIO_EFFECT_COUNT_UPPER_LIMIT, + "the number of effectProperty nodes exceeds limit: %{public}d", AUDIO_EFFECT_COUNT_UPPER_LIMIT); + if (currNode->type != XML_ELEMENT_NODE) { + currNode = currNode->next; + continue; + } + if (!xmlStrcmp(currNode->name, reinterpret_cast("effectProperty"))) { + if (!xmlHasProp(currNode, reinterpret_cast("mode"))) { + AUDIO_WARNING_LOG("missing information: EFFECTPROPERTY has no MODE attribute"); + } else { + std::string pMode = reinterpret_cast + (xmlGetProp(currNode, reinterpret_cast("mode"))); + result.effects[effectIdx].effectProperty.push_back(pMode); + } + } else { + AUDIO_WARNING_LOG("wrong name: %{public}s, should be effectProperty", currNode->name); + } + countProperty++; + currNode = currNode->next; + } + if (countProperty == 0) { + AUDIO_WARNING_LOG("effect '%{public}s' does not support effectProperty settings.", + result.effects[effectIdx].name.c_str()); + } +} + static void LoadEffect(OriginalEffectConfig &result, xmlNode *secondNode) { xmlNode *currNode = secondNode; int32_t countEffect = 0; + std::vector effectProperty = {}; + int32_t effectIdx = 0; while (currNode != nullptr) { CHECK_AND_RETURN_LOG(countEffect < AUDIO_EFFECT_COUNT_UPPER_LIMIT, "the number of effect nodes exceeds limit: %{public}d", AUDIO_EFFECT_COUNT_UPPER_LIMIT); @@ -196,8 +227,10 @@ static void LoadEffect(OriginalEffectConfig &result, xmlNode *secondNode) (xmlGetProp(currNode, reinterpret_cast("name"))); std::string pEffectLib = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("library"))); - Effect tmp = {pEffectName, pEffectLib}; + Effect tmp = {pEffectName, pEffectLib, effectProperty}; result.effects.push_back(tmp); + LoadEffectProperty(result, currNode, effectIdx); + effectIdx++; } } else { AUDIO_WARNING_LOG("wrong name: %{public}s, should be effect", currNode->name); @@ -316,12 +349,11 @@ static void LoadEffectConfigEffectChains(OriginalEffectConfig &result, const xml } } -static void LoadPreDevice(OriginalEffectConfig &result, const xmlNode *fourthNode, - const int32_t modeNum, const int32_t streamNum) +static void LoadPreDevice(std::vector &devices, const xmlNode *fifthNode) { - CHECK_AND_RETURN_LOG(fourthNode->xmlChildrenNode, "missing information: streamEffectMode has no child devicePort"); + CHECK_AND_RETURN_LOG(fifthNode->xmlChildrenNode, "missing information: streamEffectMode has no child devicePort"); int32_t countDevice = 0; - xmlNode *currNode = fourthNode->xmlChildrenNode; + xmlNode *currNode = fifthNode->xmlChildrenNode; while (currNode != nullptr) { CHECK_AND_RETURN_LOG(countDevice < AUDIO_EFFECT_COUNT_UPPER_LIMIT, "the number of devicePort nodes exceeds limit: %{public}d", AUDIO_EFFECT_COUNT_UPPER_LIMIT); @@ -340,7 +372,7 @@ static void LoadPreDevice(OriginalEffectConfig &result, const xmlNode *fourthNod std::string pChain = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("effectChain"))); Device tmpdev = {pDevType, pChain}; - result.preProcess[streamNum].device[modeNum].push_back(tmpdev); + devices.push_back(tmpdev); } } else { AUDIO_WARNING_LOG("wrong name: %{public}s, should be devicePort", currNode->name); @@ -353,13 +385,13 @@ static void LoadPreDevice(OriginalEffectConfig &result, const xmlNode *fourthNod } } -static void LoadPreMode(OriginalEffectConfig &result, const xmlNode *thirdNode, const int32_t streamNum) +static void LoadPreMode(PreStreamScene &scene, const xmlNode *fourthNode) { - CHECK_AND_RETURN_LOG(thirdNode->xmlChildrenNode, + CHECK_AND_RETURN_LOG(fourthNode->xmlChildrenNode, "missing information: stream has no child streamEffectMode"); int32_t countMode = 0; int32_t modeNum = 0; - xmlNode *currNode = thirdNode->xmlChildrenNode; + xmlNode *currNode = fourthNode->xmlChildrenNode; while (currNode != nullptr) { CHECK_AND_RETURN_LOG(countMode < AUDIO_EFFECT_COUNT_UPPER_LIMIT, "the number of streamEffectMode nodes exceeds limit: %{public}d", AUDIO_EFFECT_COUNT_UPPER_LIMIT); @@ -373,9 +405,9 @@ static void LoadPreMode(OriginalEffectConfig &result, const xmlNode *thirdNode, } else { std::string pStreamAEMode = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("mode"))); - result.preProcess[streamNum].mode.push_back(pStreamAEMode); - result.preProcess[streamNum].device.push_back({}); - LoadPreDevice(result, currNode, modeNum, streamNum); + scene.mode.push_back(pStreamAEMode); + scene.device.push_back({}); + LoadPreDevice(scene.device[modeNum], currNode); modeNum++; } } else { @@ -389,13 +421,13 @@ static void LoadPreMode(OriginalEffectConfig &result, const xmlNode *thirdNode, } } -static void LoadPreProcess(OriginalEffectConfig &result, xmlNode *secondNode) +static void LoadPreStreamScenes(std::vector &scenes, xmlNode *thirdNode) { std::string stream; std::vector mode; std::vector> device; - Preprocess tmp = {stream, mode, device}; - xmlNode *currNode = secondNode; + PreStreamScene tmp = {stream, mode, device}; + xmlNode *currNode = thirdNode; int32_t countPreprocess = 0; int32_t streamNum = 0; while (currNode != nullptr) { @@ -412,8 +444,8 @@ static void LoadPreProcess(OriginalEffectConfig &result, xmlNode *secondNode) std::string pStreamType = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("scene"))); tmp.stream = pStreamType; - result.preProcess.push_back(tmp); - LoadPreMode(result, currNode, streamNum); + scenes.push_back(tmp); + LoadPreMode(scenes[streamNum], currNode); streamNum++; } } else { @@ -427,8 +459,73 @@ static void LoadPreProcess(OriginalEffectConfig &result, xmlNode *secondNode) } } -static void LoadEffectConfigPreProcess(OriginalEffectConfig &result, const xmlNode *currNode, - int32_t (&countFirstNode)[NODE_SIZE]) +static void LoadPreStreamScenesCheck(std::vector &scenes, const xmlNode *currNode, + int32_t &nodeCounter) +{ + if (nodeCounter >= AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT) { + if (nodeCounter == AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT) { + nodeCounter++; + AUDIO_WARNING_LOG("the number of preprocessStreams nodes exceeds limit: %{public}d", + AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT); + } + } else if (currNode->xmlChildrenNode) { + LoadPreStreamScenes(scenes, currNode->xmlChildrenNode); + nodeCounter++; + } else { + AUDIO_WARNING_LOG("missing information: preprocessStreams has no child stream"); + nodeCounter++; + } +} + +static void LoadPreprocessExceptionCheck(OriginalEffectConfig &result, const xmlNode *currNode, + int32_t (&countPreSecondNode)[NODE_SIZE_PRE]) +{ + if (countPreSecondNode[INDEX_PRE_EXCEPTION] >= AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT) { + if (countPreSecondNode[INDEX_PRE_EXCEPTION] == AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT) { + countPreSecondNode[INDEX_PRE_EXCEPTION]++; + AUDIO_ERR_LOG("the number of postprocess nodes with wrong name exceeds limit: %{public}d", + AUDIO_EFFECT_COUNT_PRE_SECOND_NODE_UPPER_LIMIT); + } + } else { + AUDIO_WARNING_LOG("wrong name: %{public}s", currNode->name); + countPreSecondNode[INDEX_PRE_EXCEPTION]++; + } +} + +static void LoadPreProcessCfg(OriginalEffectConfig &result, xmlNode *secondNode) +{ + int32_t countPreSecondNode[NODE_SIZE_PRE] = {0}; + xmlNode *currNode = secondNode; + while (currNode != nullptr) { + if (currNode->type != XML_ELEMENT_NODE) { + currNode = currNode->next; + continue; + } + + if (!xmlStrcmp(currNode->name, reinterpret_cast("defaultScene"))) { + LoadPreStreamScenesCheck(result.preProcess.defaultScenes, currNode, + countPreSecondNode[INDEX_PRE_DEFAULT_SCENE]); + } else if (!xmlStrcmp(currNode->name, reinterpret_cast("priorScene"))) { + LoadPreStreamScenesCheck(result.preProcess.priorScenes, currNode, + countPreSecondNode[INDEX_PRE_PRIOR_SCENE]); + } else if (!xmlStrcmp(currNode->name, reinterpret_cast("normalScene"))) { + int32_t maxExtraNum = 0; + if (xmlHasProp(currNode, reinterpret_cast("maxExtSceneNumber"))) { + maxExtraNum = atoi(reinterpret_cast(xmlGetProp(currNode, + reinterpret_cast("maxExtSceneNumber")))); + } + result.preProcess.maxExtSceneNum = maxExtraNum; + LoadPreStreamScenesCheck(result.preProcess.normalScenes, currNode, + countPreSecondNode[INDEX_PRE_NORMAL_SCENE]); + } else { + LoadPreprocessExceptionCheck(result, currNode, countPreSecondNode); + } + currNode = currNode->next; + } +} + +static void LoadEffectConfigPreProcessCfg(OriginalEffectConfig &result, + const xmlNode *currNode, int32_t (&countFirstNode)[NODE_SIZE]) { if (countFirstNode[INDEX_PREPROCESS] >= AUDIO_EFFECT_COUNT_FIRST_NODE_UPPER_LIMIT) { if (countFirstNode[INDEX_PREPROCESS] == AUDIO_EFFECT_COUNT_FIRST_NODE_UPPER_LIMIT) { @@ -437,7 +534,7 @@ static void LoadEffectConfigPreProcess(OriginalEffectConfig &result, const xmlNo AUDIO_EFFECT_COUNT_FIRST_NODE_UPPER_LIMIT); } } else if (currNode->xmlChildrenNode) { - LoadPreProcess(result, currNode->xmlChildrenNode); + LoadPreProcessCfg(result, currNode->xmlChildrenNode); countFirstNode[INDEX_PREPROCESS]++; } else { AUDIO_WARNING_LOG("missing information: preProcess has no child stream"); @@ -479,8 +576,7 @@ static void LoadStreamUsageMapping(OriginalEffectConfig &result, xmlNode *thirdN } } -static void LoadPostDevice(OriginalEffectConfig &result, const xmlNode *fifthNode, - const int32_t modeNum, const int32_t streamNum) +static void LoadPostDevice(std::vector &devices, const xmlNode *fifthNode) { CHECK_AND_RETURN_LOG(fifthNode->xmlChildrenNode, "missing information: streamEffectMode has no child devicePort"); int32_t countDevice = 0; @@ -503,7 +599,7 @@ static void LoadPostDevice(OriginalEffectConfig &result, const xmlNode *fifthNod std::string pChain = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("effectChain"))); Device tmpdev = {pDevType, pChain}; - result.postProcess.effectSceneStreams[streamNum].device[modeNum].push_back(tmpdev); + devices.push_back(tmpdev); } } else { AUDIO_WARNING_LOG("wrong name: %{public}s, should be devicePort", currNode->name); @@ -516,7 +612,7 @@ static void LoadPostDevice(OriginalEffectConfig &result, const xmlNode *fifthNod } } -static void LoadPostMode(OriginalEffectConfig &result, const xmlNode *fourthNode, const int32_t streamNum) +static void LoadPostMode(PostStreamScene &scene, const xmlNode *fourthNode) { CHECK_AND_RETURN_LOG(fourthNode->xmlChildrenNode, "missing information: stream has no child streamEffectMode"); @@ -536,9 +632,9 @@ static void LoadPostMode(OriginalEffectConfig &result, const xmlNode *fourthNode } else { std::string pStreamAEMode = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("mode"))); - result.postProcess.effectSceneStreams[streamNum].mode.push_back(pStreamAEMode); - result.postProcess.effectSceneStreams[streamNum].device.push_back({}); - LoadPostDevice(result, currNode, modeNum, streamNum); + scene.mode.push_back(pStreamAEMode); + scene.device.push_back({}); + LoadPostDevice(scene.device[modeNum], currNode); modeNum++; } } else { @@ -552,12 +648,12 @@ static void LoadPostMode(OriginalEffectConfig &result, const xmlNode *fourthNode } } -static void LoadEffectSceneStreams(OriginalEffectConfig &result, xmlNode *thirdNode) +static void LoadPostStreamScenes(std::vector &scenes, xmlNode *thirdNode) { std::string stream; std::vector mode; std::vector> device; - EffectSceneStream tmp = {stream, mode, device}; + PostStreamScene tmp = {stream, mode, device}; xmlNode *currNode = thirdNode; int32_t countPostProcess = 0; int32_t streamNum = 0; @@ -575,8 +671,8 @@ static void LoadEffectSceneStreams(OriginalEffectConfig &result, xmlNode *thirdN std::string pStreamType = reinterpret_cast (xmlGetProp(currNode, reinterpret_cast("scene"))); tmp.stream = pStreamType; - result.postProcess.effectSceneStreams.push_back(tmp); - LoadPostMode(result, currNode, streamNum); + scenes.push_back(tmp); + LoadPostMode(scenes[streamNum], currNode); streamNum++; } } else { @@ -590,21 +686,21 @@ static void LoadEffectSceneStreams(OriginalEffectConfig &result, xmlNode *thirdN } } -static void LoadEffectSceneStreamsCheck(OriginalEffectConfig &result, const xmlNode *currNode, - int32_t (&countPostSecondNode)[NODE_SIZE_POST]) +static void LoadPostStreamScenesCheck(std::vector &scenes, const xmlNode *currNode, + int32_t &nodeCounter) { - if (countPostSecondNode[INDEX_POST_STREAMS] >= AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT) { - if (countPostSecondNode[INDEX_POST_STREAMS] == AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT) { - countPostSecondNode[INDEX_POST_STREAMS]++; + if (nodeCounter >= AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT) { + if (nodeCounter == AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT) { + nodeCounter++; AUDIO_WARNING_LOG("the number of postprocessStreams nodes exceeds limit: %{public}d", AUDIO_EFFECT_COUNT_POST_SECOND_NODE_UPPER_LIMIT); } } else if (currNode->xmlChildrenNode) { - LoadEffectSceneStreams(result, currNode->xmlChildrenNode); - countPostSecondNode[INDEX_POST_STREAMS]++; + LoadPostStreamScenes(scenes, currNode->xmlChildrenNode); + nodeCounter++; } else { AUDIO_WARNING_LOG("missing information: postprocessStreams has no child stream"); - countPostSecondNode[INDEX_POST_STREAMS]++; + nodeCounter++; } } @@ -651,8 +747,25 @@ static void LoadPostProcessCfg(OriginalEffectConfig &result, xmlNode *secondNode continue; } - if (!xmlStrcmp(currNode->name, reinterpret_cast("effectSceneStreams"))) { - LoadEffectSceneStreamsCheck(result, currNode, countPostSecondNode); + if (!xmlStrcmp(currNode->name, reinterpret_cast("defaultScene"))) { + LoadPostStreamScenesCheck(result.postProcess.defaultScenes, currNode, + countPostSecondNode[INDEX_POST_DEFAULT_SCENE]); + } else if (!xmlStrcmp(currNode->name, reinterpret_cast("priorScene"))) { + LoadPostStreamScenesCheck(result.postProcess.priorScenes, currNode, + countPostSecondNode[INDEX_POST_PRIOR_SCENE]); + } else if (!xmlStrcmp(currNode->name, reinterpret_cast("normalScene"))) { + int32_t maxExtraNum = 0; + if (xmlHasProp(currNode, reinterpret_cast("maxExtSceneNumber"))) { + maxExtraNum = atoi(reinterpret_cast(xmlGetProp(currNode, + reinterpret_cast("maxExtSceneNumber")))); + } + result.postProcess.maxExtSceneNum = maxExtraNum; + LoadPostStreamScenesCheck(result.postProcess.normalScenes, currNode, + countPostSecondNode[INDEX_POST_NORMAL_SCENE]); + } else if (!xmlStrcmp(currNode->name, reinterpret_cast("effectSceneStreams"))) { + // TO BE COMPATIBLE WITH OLDER VERSION XML + LoadPostStreamScenesCheck(result.postProcess.normalScenes, currNode, + countPostSecondNode[INDEX_POST_NORMAL_SCENE]); } else if (!xmlStrcmp(currNode->name, reinterpret_cast("sceneMap"))) { LoadStreamUsageMappingCheck(result, currNode, countPostSecondNode); } else { @@ -727,7 +840,7 @@ int32_t AudioEffectConfigParser::LoadEffectConfig(OriginalEffectConfig &result) } else if (!xmlStrcmp(currNode->name, reinterpret_cast("effectChains"))) { LoadEffectConfigEffectChains(result, currNode, countFirstNode); } else if (!xmlStrcmp(currNode->name, reinterpret_cast("preProcess"))) { - LoadEffectConfigPreProcess(result, currNode, countFirstNode); + LoadEffectConfigPreProcessCfg(result, currNode, countFirstNode); } else if (!xmlStrcmp(currNode->name, reinterpret_cast("postProcess"))) { LoadEffectConfigPostProcessCfg(result, currNode, countFirstNode); } else { 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 167a8a7669cbd4916fdd917bb0c1042c70fbde0b..df60a22fd296cd1f16c0f4e9287a396841c413ea 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 @@ -63,39 +63,8 @@ void AudioEffectManager::GetSupportedEffectConfig(SupportedEffectConfig &support supportedEffectConfig = supportedEffectConfig_; } -static int32_t UpdateUnsupportedScene(std::string &scene) -{ - int32_t isSupported = 0; - if ((scene != "SCENE_MUSIC") && - (scene != "SCENE_MOVIE") && - (scene != "SCENE_GAME") && - (scene != "SCENE_SPEECH") && - (scene != "SCENE_RING") && - (scene != "SCENE_VOIP_UP") && - (scene != "SCENE_RECORD") && - (scene != "SCENE_MEETING") && - (scene != "SCENE_VOIP") && - (scene != "SCENE_OTHERS")) { - AUDIO_INFO_LOG("[supportedEffectConfig LOG9]:stream-> The scene of %{public}s is unsupported, \ - and this scene is deleted!", scene.c_str()); - isSupported = -1; - } - return isSupported; -} - -static int32_t UpdateUnsupportedEnhanceScene(std::string &scene) -{ - int32_t isSupported = 0; - if ((scene != "SCENE_VOIP_UP") && - (scene != "SCENE_RECORD")) { - AUDIO_INFO_LOG("[supportedEnhanceConfig LOG9]:stream-> The scene of %{public}s is unsupported, \ - and this scene is deleted!", scene.c_str()); - isSupported = -1; - } - return isSupported; -} - -static void UpdateUnsupportedDevicePre(Preprocess &pp, Stream &stream, const std::string &mode, int32_t i, int32_t j) +static void UpdateUnsupportedDevicePre(PreStreamScene &pp, Stream &stream, const std::string &mode, + int32_t i, int32_t j) { StreamEffectMode streamEffectMode; streamEffectMode.mode = mode; @@ -112,7 +81,7 @@ static void UpdateUnsupportedDevicePre(Preprocess &pp, Stream &stream, const std stream.streamEffectMode.push_back(streamEffectMode); } -static void UpdateUnsupportedModePre(Preprocess &pp, Stream &stream, std::string &mode, int32_t i) +static void UpdateUnsupportedModePre(PreStreamScene &pp, Stream &stream, std::string &mode, int32_t i) { int32_t isSupported = 0; if ((mode != "ENHANCE_NONE") && @@ -127,7 +96,7 @@ static void UpdateUnsupportedModePre(Preprocess &pp, Stream &stream, std::string } } -static void UpdateUnsupportedDevicePost(EffectSceneStream &ess, Stream &stream, const std::string &mode, int32_t i) +static void UpdateUnsupportedDevicePost(PostStreamScene &ess, Stream &stream, const std::string &mode, int32_t i) { StreamEffectMode streamEffectMode; streamEffectMode.mode = mode; @@ -144,7 +113,7 @@ static void UpdateUnsupportedDevicePost(EffectSceneStream &ess, Stream &stream, stream.streamEffectMode.push_back(streamEffectMode); } -static void UpdateUnsupportedModePost(EffectSceneStream &ess, Stream &stream, std::string &mode, int32_t i) +static void UpdateUnsupportedModePost(PostStreamScene &ess, Stream &stream, std::string &mode, int32_t i) { int32_t isSupported = 0; if ((mode != "EFFECT_NONE") && @@ -158,15 +127,22 @@ static void UpdateUnsupportedModePost(EffectSceneStream &ess, Stream &stream, st } } -static int32_t UpdateAvailableStreamPre(ProcessNew &preProcessNew, Preprocess &pp) +static int32_t UpdateAvailableStreamPre(ProcessNew &preProcessNew, PreStreamScene &pp, ScenePriority priority) { bool isDuplicate = false; - int32_t isSupported = UpdateUnsupportedEnhanceScene(pp.stream); - auto it = std::find_if(preProcessNew.stream.begin(), preProcessNew.stream.end(), [&pp](const Stream& x) { - return x.scene == pp.stream; + bool isSupported = false; + for (auto &[scene, stream] : AUDIO_ENHANCE_SUPPORTED_SCENE_TYPES) { + if (pp.stream == stream) { + isSupported = true; + break; + } + } + auto it = std::find_if(preProcessNew.stream.begin(), preProcessNew.stream.end(), [&](const Stream &x) { + return ((x.scene == pp.stream) && (x.priority == priority)); }); - if ((it == preProcessNew.stream.end()) && (isSupported == 0)) { + if ((it == preProcessNew.stream.end()) && isSupported) { Stream stream; + stream.priority = priority; stream.scene = pp.stream; int32_t i = 0; for (auto &mode: pp.mode) { @@ -179,15 +155,22 @@ static int32_t UpdateAvailableStreamPre(ProcessNew &preProcessNew, Preprocess &p return isDuplicate; } -static int32_t UpdateAvailableStreamPost(ProcessNew &postProcessNew, EffectSceneStream &ess) +static int32_t UpdateAvailableStreamPost(ProcessNew &postProcessNew, PostStreamScene &ess, ScenePriority priority) { bool isDuplicate = false; - int32_t isSupported = UpdateUnsupportedScene(ess.stream); - auto it = std::find_if(postProcessNew.stream.begin(), postProcessNew.stream.end(), [&ess](const Stream& x) { - return x.scene == ess.stream; + bool isSupported = false; + for (auto &[scene, stream] : AUDIO_SUPPORTED_SCENE_TYPES) { + if (ess.stream == stream) { + isSupported = true; + break; + } + } + auto it = std::find_if(postProcessNew.stream.begin(), postProcessNew.stream.end(), [&](const Stream &x) { + return ((x.scene == ess.stream) && (x.priority == priority)); }); - if ((it == postProcessNew.stream.end()) && (isSupported == 0)) { + if ((it == postProcessNew.stream.end()) && isSupported) { Stream stream; + stream.priority = priority; stream.scene = ess.stream; int32_t i = 0; for (auto &mode: ess.mode) { @@ -204,7 +187,7 @@ static int32_t UpdateAvailableSceneMapPost(SceneMappingItem &item, std::vector &availableL for (const auto &ec: supportedEffectConfig_.effectChains) { for (auto &effectName: ec.apply) { auto it = std::find_if(availableEffects_.begin(), availableEffects_.end(), - [&effectName](const Effect& effect) { + [&effectName](const Effect &effect) { return effect.name == effectName; }); if (it == availableEffects_.end()) { @@ -251,26 +234,32 @@ void AudioEffectManager::UpdateEffectChains(std::vector &availableL void AudioEffectManager::UpdateAvailableAEConfig(OriginalEffectConfig &aeConfig) { - bool isDuplicate = false; - bool ret; + int32_t ret = 0; supportedEffectConfig_.effectChains = aeConfig.effectChains; ProcessNew preProcessNew; - for (Preprocess &pp: aeConfig.preProcess) { - ret = UpdateAvailableStreamPre(preProcessNew, pp); - if (ret == 1) { - isDuplicate = true; - } + for (PreStreamScene &pp: aeConfig.preProcess.defaultScenes) { + ret += UpdateAvailableStreamPre(preProcessNew, pp, DEFAULT_SCENE); } + for (PreStreamScene &pp: aeConfig.preProcess.priorScenes) { + ret += UpdateAvailableStreamPre(preProcessNew, pp, PRIOR_SCENE); + } + for (PreStreamScene &pp: aeConfig.preProcess.normalScenes) { + ret += UpdateAvailableStreamPre(preProcessNew, pp, NORMAL_SCENE); + } + ProcessNew postProcessNew; - for (EffectSceneStream &ess: aeConfig.postProcess.effectSceneStreams) { - ret = UpdateAvailableStreamPost(postProcessNew, ess); - if (ret == 1) { - isDuplicate = true; - } + for (PostStreamScene &ess: aeConfig.postProcess.defaultScenes) { + ret += UpdateAvailableStreamPost(postProcessNew, ess, DEFAULT_SCENE); } - if (isDuplicate == true) { - AUDIO_INFO_LOG("[supportedEffectConfig LOG2]:stream-> The duplicate stream is deleted, \ - and the first configuration is retained!"); + for (PostStreamScene &ess: aeConfig.postProcess.priorScenes) { + ret += UpdateAvailableStreamPost(postProcessNew, ess, PRIOR_SCENE); + } + for (PostStreamScene &ess: aeConfig.postProcess.normalScenes) { + ret += UpdateAvailableStreamPost(postProcessNew, ess, NORMAL_SCENE); + } + + if (ret > 0) { + AUDIO_INFO_LOG("[supportedEffectConfig LOG2]:stream-> duplicate streams has been deleted"); } supportedEffectConfig_.preProcessNew = preProcessNew; supportedEffectConfig_.postProcessNew = postProcessNew; @@ -294,11 +283,11 @@ void AudioEffectManager::UpdateAvailableAEConfig(OriginalEffectConfig &aeConfig) supportedEffectConfig_.postProcessSceneMap = postSceneMap; } -void AudioEffectManager::UpdateDuplicateBypassMode(ProcessNew &preProcessNew) +void AudioEffectManager::UpdateDuplicateBypassMode(ProcessNew &processNew) { int32_t flag = 0; std::vector deviceDelIdx; - for (auto &stream: preProcessNew.stream) { + for (auto &stream: processNew.stream) { int32_t count = 0; deviceDelIdx.clear(); for (const auto &streamEffectMode: stream.streamEffectMode) { @@ -317,12 +306,12 @@ void AudioEffectManager::UpdateDuplicateBypassMode(ProcessNew &preProcessNew) } } -void AudioEffectManager::UpdateDuplicateMode(ProcessNew &preProcessNew) +void AudioEffectManager::UpdateDuplicateMode(ProcessNew &processNew) { std::unordered_set seen; std::vector toRemove; uint32_t i; - for (auto &stream: preProcessNew.stream) { + for (auto &stream: processNew.stream) { seen.clear(); toRemove.clear(); for (i = 0; i < stream.streamEffectMode.size(); i++) { @@ -362,15 +351,62 @@ static void UpdateDuplicateDeviceRecord(StreamEffectMode &streamEffectMode, Stre } } -void AudioEffectManager::UpdateDuplicateDevice(ProcessNew &preProcessNew) +void AudioEffectManager::UpdateDuplicateDevice(ProcessNew &processNew) { - for (auto &stream: preProcessNew.stream) { + for (auto &stream: processNew.stream) { for (auto &streamEffectMode: stream.streamEffectMode) { UpdateDuplicateDeviceRecord(streamEffectMode, stream); } } } +void AudioEffectManager::UpdateDuplicateScene(ProcessNew &processNew) +{ + // erase duplicate scene + std::unordered_set scenes; + for (auto it = processNew.stream.begin(); it != processNew.stream.end();) { + auto &stream = *it; + auto its = scenes.find(stream.scene); + if (its == scenes.end()) { + scenes.insert(stream.scene); + } else { + if (stream.priority == NORMAL_SCENE) { + it = processNew.stream.erase(it); + continue; + } + } + ++it; + } +} + +void AudioEffectManager::UpdateDuplicateDefaultScene(ProcessNew &processNew) +{ + // erase duplicate default scene + bool flag = false; + for (auto it = processNew.stream.begin(); it != processNew.stream.end();) { + auto &stream = *it; + if (stream.priority == DEFAULT_SCENE) { + if (flag) { + it = processNew.stream.erase(it); + continue; + } + flag = true; + } + ++it; + } + + // add default scene if no default + if (!flag) { + for (auto it = processNew.stream.begin(); it != processNew.stream.end(); ++it) { + auto &stream = *it; + if (stream.priority == NORMAL_SCENE) { + stream.priority = DEFAULT_SCENE; + break; + } + } + } +} + static int32_t UpdateUnavailableModes(std::vector &modeDelIdx, Stream &stream) { int32_t ret = 0; @@ -436,7 +472,7 @@ int32_t AudioEffectManager::UpdateUnavailableEffectChains(std::vector modeDelIdx; for (auto &stream: processNew.stream) { modeDelIdx.clear(); @@ -457,20 +493,35 @@ void AudioEffectManager::BuildAvailableAEConfig() if (oriEffectConfig_.effectChains.size() == 0) { AUDIO_INFO_LOG("[supportedEffectConfig LOG12]: effectChains is none!"); } - if (oriEffectConfig_.preProcess.size() == 0) { - AUDIO_INFO_LOG("[supportedEffectConfig LOG11]: preProcess is none!"); + if (oriEffectConfig_.preProcess.defaultScenes.size() != 1) { + AUDIO_INFO_LOG("[supportedEffectConfig LOG13]: pre-defaultScene is not one!"); } - if (oriEffectConfig_.postProcess.effectSceneStreams.size() == 0) { - AUDIO_INFO_LOG("[supportedEffectConfig LOG13]: postProcess is none!"); + + if (oriEffectConfig_.preProcess.normalScenes.size() == 0) { + AUDIO_INFO_LOG("[supportedEffectConfig LOG14]: pre-normalScene is none!"); + } + + if (oriEffectConfig_.postProcess.defaultScenes.size() != 1) { + AUDIO_INFO_LOG("[supportedEffectConfig LOG15]: post-defaultScene is not one!"); + } + if (oriEffectConfig_.postProcess.normalScenes.size() == 0) { + AUDIO_INFO_LOG("[supportedEffectConfig LOG16]: post-normalScene is none!"); } + // update maxExtraSceneNum + // Update duplicate defined modes, devices, and unsupported effect chain. UpdateAvailableAEConfig(oriEffectConfig_); - UpdateEffectChains(availableLayout); + ProcessNew preProcessNew = supportedEffectConfig_.preProcessNew; + ProcessNew postProcessNew = 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; @@ -479,6 +530,8 @@ void AudioEffectManager::BuildAvailableAEConfig() 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; @@ -509,13 +562,22 @@ void AddKeyValueIntoMap(std::unordered_map &map, std::string &ke map[key] = value; } -void AudioEffectManager::ConstructSceneTypeToEffectChainNameMap(std::unordered_map &map) +void AudioEffectManager::ConstructEffectChainManagerParam(EffectChainManagerParam &effectChainMgrParam) { + std::unordered_map &map = effectChainMgrParam.sceneTypeToChainNameMap; + effectChainMgrParam.maxExtraNum = oriEffectConfig_.postProcess.maxExtSceneNum; + std::string sceneType; std::string sceneMode; std::string key; for (auto &scene: supportedEffectConfig_.postProcessNew.stream) { sceneType = scene.scene; + if (scene.priority == PRIOR_SCENE) { + effectChainMgrParam.priorSceneList.push_back(sceneType); + } + if (scene.priority == DEFAULT_SCENE) { + effectChainMgrParam.defaultSceneName = sceneType; + } for (auto &mode: scene.streamEffectMode) { sceneMode = mode.mode; for (auto &device: mode.devicePort) { @@ -528,13 +590,24 @@ void AudioEffectManager::ConstructSceneTypeToEffectChainNameMap(std::unordered_m (int32_t)map.size()); } -void AudioEffectManager::ConstructSceneTypeToEnhanceChainNameMap(std::unordered_map &map) +void AudioEffectManager::ConstructEnhanceChainManagerParam(EffectChainManagerParam &enhanceChainMgrParam) { + std::unordered_map &map = enhanceChainMgrParam.sceneTypeToChainNameMap; + enhanceChainMgrParam.maxExtraNum = oriEffectConfig_.preProcess.maxExtSceneNum; + std::string sceneType; std::string sceneMode; std::string key; + for (auto &scene: supportedEffectConfig_.preProcessNew.stream) { sceneType = scene.scene; + if (scene.priority == PRIOR_SCENE) { + enhanceChainMgrParam.priorSceneList.push_back(sceneType); + } + if (scene.priority == DEFAULT_SCENE) { + enhanceChainMgrParam.defaultSceneName = sceneType; + } + for (auto &mode: scene.streamEffectMode) { sceneMode = mode.mode; for (auto &device: mode.devicePort) {