From 1ae5c5644ae0c445719ea1c6be7d9d21cbfc7ce0 Mon Sep 17 00:00:00 2001 From: lizihao Date: Wed, 10 Sep 2025 15:47:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizihao --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 1 + .../audio_service/client/src/audio_spatialization_manager.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index d20da21de6..ed7da4a90e 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -360,6 +360,7 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(std::string &sceneTy AudioEffectDescriptor descriptor; descriptor.libraryName = effectToLibraryNameMap_[effect]; descriptor.effectName = effect; + CHECK_AND_CONTINUE_LOG(effectToLibraryEntryMap_[effect] != nullptr, "null AudioEffectLibEntry"); int32_t ret = effectToLibraryEntryMap_[effect]->audioEffectLibHandle->createEffect(descriptor, &handle); CHECK_AND_CONTINUE_LOG(ret == 0, "EffectToLibraryEntryMap[%{public}s] createEffect fail", effect.c_str()); diff --git a/services/audio_service/client/src/audio_spatialization_manager.cpp b/services/audio_service/client/src/audio_spatialization_manager.cpp index c844ad242e..1a383886c2 100644 --- a/services/audio_service/client/src/audio_spatialization_manager.cpp +++ b/services/audio_service/client/src/audio_spatialization_manager.cpp @@ -56,6 +56,7 @@ bool AudioSpatializationManager::IsSpatializationEnabled() bool AudioSpatializationManager::IsSpatializationEnabled( const std::shared_ptr &selectedAudioDevice) { + CHECK_AND_RETURN_RET_LOG(selectedAudioDevice != nullptr, false, "selectedAudioDevice is nullptr"); return AudioPolicyManager::GetInstance().IsSpatializationEnabled(selectedAudioDevice->macAddress_); } @@ -83,6 +84,7 @@ bool AudioSpatializationManager::IsHeadTrackingEnabled() bool AudioSpatializationManager::IsHeadTrackingEnabled( const std::shared_ptr &selectedAudioDevice) { + CHECK_AND_RETURN_RET_LOG(selectedAudioDevice != nullptr, false, "selectedAudioDevice is nullptr"); return AudioPolicyManager::GetInstance().IsHeadTrackingEnabled(selectedAudioDevice->macAddress_); } @@ -141,6 +143,7 @@ bool AudioSpatializationManager::IsSpatializationSupported() bool AudioSpatializationManager::IsSpatializationSupportedForDevice( const std::shared_ptr &selectedAudioDevice) { + CHECK_AND_RETURN_RET_LOG(selectedAudioDevice != nullptr, false, "selectedAudioDevice is nullptr"); return AudioPolicyManager::GetInstance().IsSpatializationSupportedForDevice(selectedAudioDevice->macAddress_); } @@ -152,6 +155,7 @@ bool AudioSpatializationManager::IsHeadTrackingSupported() bool AudioSpatializationManager::IsHeadTrackingSupportedForDevice( const std::shared_ptr &selectedAudioDevice) { + CHECK_AND_RETURN_RET_LOG(selectedAudioDevice != nullptr, false, "selectedAudioDevice is nullptr"); return AudioPolicyManager::GetInstance().IsHeadTrackingSupportedForDevice(selectedAudioDevice->macAddress_); } -- Gitee From d3aeae3de9a67ee4bc49cf65d1b9cde88562ac39 Mon Sep 17 00:00:00 2001 From: lizihao Date: Wed, 10 Sep 2025 16:00:28 +0800 Subject: [PATCH 2/3] codecheck Signed-off-by: lizihao --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index ed7da4a90e..7611878570 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -360,7 +360,8 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(std::string &sceneTy AudioEffectDescriptor descriptor; descriptor.libraryName = effectToLibraryNameMap_[effect]; descriptor.effectName = effect; - CHECK_AND_CONTINUE_LOG(effectToLibraryEntryMap_[effect] != nullptr, "null AudioEffectLibEntry"); + CHECK_AND_CONTINUE_LOG(effectToLibraryEntryMap_.count(effect) && effectToLibraryEntryMap_[effect] != nullptr, + "null AudioEffectLibEntry"); int32_t ret = effectToLibraryEntryMap_[effect]->audioEffectLibHandle->createEffect(descriptor, &handle); CHECK_AND_CONTINUE_LOG(ret == 0, "EffectToLibraryEntryMap[%{public}s] createEffect fail", effect.c_str()); -- Gitee From 503245de67948d58b3c82a0e1b56cf87216ed7a9 Mon Sep 17 00:00:00 2001 From: lizihao Date: Wed, 10 Sep 2025 16:49:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8B=86=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizihao --- .../include/audio_effect_chain_manager.h | 1 + .../src/audio_effect_chain_manager.cpp | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 8405aedc45..79b0673113 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -213,6 +213,7 @@ private: int32_t NotifyAndCreateAudioEffectChain(const std::string &sceneType); void WaitAndReleaseEffectChain(const std::string &sceneType, const std::string &sceneTypeAndDeviceKey, const std::string &defaultSceneTypeAndDeviceKey, int32_t ret); + std::string GetEffectChainByMode(std::string effectChainKey); std::map> effectToLibraryEntryMap_; std::map effectToLibraryNameMap_; std::map> effectChainToEffectsMap_; diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 7611878570..886af3e98a 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -330,23 +330,8 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(std::string &sceneTy "SceneType [%{public}s] does not exist, failed to set", sceneType.c_str()); std::shared_ptr audioEffectChain = sceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; - const std::unordered_map &audioSupportedSceneModes = GetAudioSupportedSceneModes(); - std::string effectChain; std::string effectChainKey = sceneType + "_&_" + effectMode + "_&_" + GetDeviceTypeName(); - std::string effectNone = audioSupportedSceneModes.find(EFFECT_NONE)->second; - if (!sceneTypeAndModeToEffectChainNameMap_.count(effectChainKey)) { - AUDIO_ERR_LOG("EffectChain key [%{public}s] does not exist, auto set to %{public}s", - effectChainKey.c_str(), effectNone.c_str()); - effectChain = effectNone; - } else { - effectChain = sceneTypeAndModeToEffectChainNameMap_[effectChainKey]; - } - - if (effectChain != effectNone && !effectChainToEffectsMap_.count(effectChain)) { - AUDIO_ERR_LOG("EffectChain name [%{public}s] does not exist, auto set to %{public}s", - effectChain.c_str(), effectNone.c_str()); - effectChain = effectNone; - } + std::string effectChain = GetEffectChainByMode(effectChainKey); ConfigureAudioEffectChain(audioEffectChain, effectMode); bool exists = std::find(AUDIO_PERSISTENCE_SCENE.begin(), AUDIO_PERSISTENCE_SCENE.end(), sceneType) != @@ -383,6 +368,27 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(std::string &sceneTy return SUCCESS; } +std::string AudioEffectChainManager::GetEffectChainByMode(std::string effectChainKey) +{ + std::string effectChain; + const std::unordered_map &audioSupportedSceneModes = GetAudioSupportedSceneModes(); + std::string effectNone = audioSupportedSceneModes.find(EFFECT_NONE)->second; + if (!sceneTypeAndModeToEffectChainNameMap_.count(effectChainKey)) { + AUDIO_ERR_LOG("EffectChain key [%{public}s] does not exist, auto set to %{public}s", + effectChainKey.c_str(), effectNone.c_str()); + effectChain = effectNone; + } else { + effectChain = sceneTypeAndModeToEffectChainNameMap_[effectChainKey]; + } + + if (effectChain != effectNone && !effectChainToEffectsMap_.count(effectChain)) { + AUDIO_ERR_LOG("EffectChain name [%{public}s] does not exist, auto set to %{public}s", + effectChain.c_str(), effectNone.c_str()); + effectChain = effectNone; + } + return effectChain; +} + void AudioEffectChainManager::ConfigureAudioEffectChain(std::shared_ptr audioEffectChain, const std::string &effectMode) { -- Gitee