1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AUDIO_ENHANCE_CHAIN_MANAGER_IMPL_H 17 #define AUDIO_ENHANCE_CHAIN_MANAGER_IMPL_H 18 19 #include "audio_enhance_chain_manager.h" 20 21 #include <map> 22 #include <memory> 23 #include <mutex> 24 #include <set> 25 #include <string> 26 #include <vector> 27 28 #include "audio_enhance_chain.h" 29 #include "thread_handler.h" 30 31 namespace OHOS { 32 namespace AudioStandard { 33 struct EnhanceConfigInfo { 34 bool relateWithDevice { false }; 35 std::string defaultProp; 36 std::shared_ptr<AudioEffectLibEntry> enhanceLib { nullptr }; 37 }; 38 39 struct EnhanceChainConfigInfo { 40 std::string chainName; 41 std::string chainLabel; 42 std::vector<std::string> enhanceNames; 43 }; 44 45 class AudioEnhanceChainManagerImpl : public AudioEnhanceChainManager, public NoCopyable { 46 public: 47 void InitAudioEnhanceChainManager(const std::vector<EffectChain> &enhanceChains, 48 const EffectChainManagerParam &managerParam, 49 const std::vector<std::shared_ptr<AudioEffectLibEntry>> &libList) override; 50 51 int32_t CreateAudioEnhanceChainDynamic(uint64_t sceneKeyCode, const AudioEnhanceDeviceAttr &deviceAttr) override; 52 53 int32_t ReleaseAudioEnhanceChainDynamic(uint64_t sceneKeyCode) override; 54 55 int32_t AudioEnhanceChainGetAlgoConfig(uint64_t sceneKeyCode, AudioBufferConfig &micConfig, 56 AudioBufferConfig &ecConfig, AudioBufferConfig &micRefConfig) override; 57 58 int32_t ApplyEnhanceChainById(uint64_t sceneKeyCode, const EnhanceTransBuffer &transBuf) override; 59 60 int32_t GetChainOutputDataById(uint64_t sceneKeyCode, void *buf, size_t bufSize) override; 61 62 int32_t SetInputDevice(uint32_t captureId, DeviceType inputDevice, const std::string &deviceName = "") override; 63 64 int32_t SetOutputDevice(uint32_t renderId, DeviceType outputDevice) override; 65 66 int32_t SetVolumeInfo(AudioVolumeType volumeType, float systemVol) override; 67 68 int32_t SetMicrophoneMuteInfo(bool isMute) override; 69 70 int32_t SetStreamVolumeInfo(uint32_t sessionId, float streamVol) override; 71 72 int32_t SetAudioEnhanceProperty(const AudioEffectPropertyArrayV3 &propertyArray, 73 DeviceType deviceType = DEVICE_TYPE_NONE) override; 74 75 int32_t GetAudioEnhanceProperty(AudioEffectPropertyArrayV3 &propertyArray, 76 DeviceType deviceType = DEVICE_TYPE_NONE) override; 77 78 int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray, 79 DeviceType deviceType = DEVICE_TYPE_NONE) override; 80 81 int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray, 82 DeviceType deviceType = DEVICE_TYPE_NONE) override; 83 84 void ResetInfo() override; 85 86 void UpdateExtraSceneType(const std::string &mainkey, const std::string &subkey, 87 const std::string &extraSceneType) override; 88 89 int32_t SendInitCommand() override; 90 91 private: 92 friend class AudioEnhanceChainManager; 93 AudioEnhanceChainManagerImpl() = default; 94 ~AudioEnhanceChainManagerImpl() override = default; 95 96 int32_t AddAudioEnhanceChainHandles(std::shared_ptr<AudioEnhanceChain> &audioEnhanceChain, 97 const std::vector<std::string> &enhanceNames); 98 int32_t ParseSceneKeyCode(uint64_t sceneKeyCode, std::string &sceneType, std::string &capturerDeviceStr, 99 std::string &rendererDeviceStr); 100 std::shared_ptr<AudioEnhanceChain> CreateEnhanceChainInner(uint64_t sceneKeyCode, 101 const AudioEnhanceDeviceAttr &deviceAttr); 102 std::vector<std::string> GetEnhanceNamesBySceneCode(uint64_t sceneKeyCode, bool defaultFlag); 103 void ReleaseThreadHandlerByScene(AudioEnhanceScene scene); 104 int32_t UpdatePropertyAndSendToAlgo(DeviceType inputDevice); 105 void UpdateEnhancePropertyMapFromDb(DeviceType deviceType); 106 int32_t WriteEnhancePropertyToDb(const std::string &key, const std::string &property); 107 int32_t SetAudioEnhancePropertyToChains(const AudioEffectPropertyV3 &property); 108 void GetDeviceTypeName(DeviceType deviceType, std::string &deviceName); 109 void SetRelateWithDevicePropForEnhance(); 110 std::shared_ptr<ThreadHandler> GetThreadHandlerByScene(AudioEnhanceScene scene); 111 112 std::map<std::string, EnhanceConfigInfo> enhanceConfigInfoMap_; 113 std::map<std::string, EnhanceChainConfigInfo> chainConfigInfoMap_; 114 std::map<std::string, std::string> enhancePropertyMap_; 115 std::map<uint32_t, DeviceType> captureIdToDeviceMap_; 116 std::map<uint32_t, std::pair<std::shared_ptr<ThreadHandler>, uint32_t>> threadHandlerMap_; 117 uint32_t maxNormalInstanceNum_ { 0 }; 118 std::string defaultScene_; 119 std::set<std::string> priorSceneSet_; 120 AudioEnhanceParamAdapter enhancePara_ {}; 121 std::mutex chainManagerMutex_; 122 }; 123 } // namespace AudioStandard 124 } // namespace OHOS 125 126 #endif // AUDIO_ENHANCE_CHAIN_MANAGER_IMPL_H