1 /* 2 * Copyright (c) 2021-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 #ifndef ST_AUDIO_CONFIG_MANAGER_H 16 #define ST_AUDIO_CONFIG_MANAGER_H 17 18 #include <bitset> 19 #include <list> 20 #include <string> 21 #include <unordered_map> 22 #include <unordered_set> 23 #include <mutex> 24 #include "iport_observer.h" 25 #include "singleton.h" 26 #include "audio_group_handle.h" 27 #include "audio_manager_base.h" 28 #include "audio_module_info.h" 29 #include "audio_volume_config.h" 30 #include "audio_errors.h" 31 #include "audio_policy_parser_factory.h" 32 #include "audio_device_manager.h" 33 34 namespace OHOS { 35 namespace AudioStandard { 36 37 class AudioConfigManager : public IPortObserver { 38 public: GetInstance()39 static AudioConfigManager& GetInstance() 40 { 41 static AudioConfigManager instance; 42 return instance; 43 } 44 bool Init(); 45 // Audio Policy Parser callbacks 46 void OnAudioPolicyXmlParsingCompleted(const std::unordered_map<AdaptersType, AudioAdapterInfo> adapterInfoMap); 47 48 // Parser callbacks 49 void OnXmlParsingCompleted(const std::unordered_map<ClassType, std::list<AudioModuleInfo>> &xmldata); 50 51 void OnUpdateRouteSupport(bool isSupported); 52 53 void OnUpdateAnahsSupport(std::string anahsShowType); 54 55 void OnUpdateDefaultAdapter(bool isEnable); 56 57 void OnAudioLatencyParsed(uint64_t latency); 58 59 void OnSinkLatencyParsed(uint32_t latency); 60 61 void OnVolumeGroupParsed(std::unordered_map<std::string, std::string>& volumeGroupData); 62 63 void OnInterruptGroupParsed(std::unordered_map<std::string, std::string>& interruptGroupData); 64 65 void OnGlobalConfigsParsed(GlobalConfigs &globalConfigs); 66 67 void OnVoipConfigParsed(bool enableFastVoip); 68 69 // other 70 71 bool GetModuleListByType(ClassType type, std::list<AudioModuleInfo>& moduleList); 72 73 void GetDeviceClassInfo(std::unordered_map<ClassType, std::list<AudioModuleInfo>> &deviceClassInfo); 74 75 std::string GetGroupName(const std::string& deviceName, const GroupType type); 76 77 int32_t GetMaxRendererInstances(); 78 void SetNormalVoipFlag(const bool &normalVoipFlag); 79 80 bool GetNormalVoipFlag(); 81 82 int32_t GetVoipRendererFlag(const std::string &sinkPortName, const std::string &networkId, 83 const AudioSamplingRate &samplingRate); 84 85 bool GetVoipConfig(); 86 87 int32_t GetAudioLatencyFromXml() const; 88 89 uint32_t GetSinkLatencyFromXml() const; 90 91 void GetAudioAdapterInfos(std::unordered_map<AdaptersType, AudioAdapterInfo> &adapterInfoMap); 92 93 void GetVolumeGroupData(std::unordered_map<std::string, std::string>& volumeGroupData); 94 95 void GetInterruptGroupData(std::unordered_map<std::string, std::string>& interruptGroupData); 96 97 bool GetUpdateRouteSupport(); 98 99 bool GetDefaultAdapterEnable(); 100 101 bool GetAdapterInfoFlag(); 102 103 bool GetAdapterInfoByType(AdaptersType type, AudioAdapterInfo &info); 104 105 bool GetHasEarpiece(); 106 107 void GetGlobalConfigs(GlobalConfigs &globalConfigs); 108 private: AudioConfigManager()109 AudioConfigManager() : audioDeviceManager_(AudioDeviceManager::GetAudioDeviceManager()) 110 { 111 } ~AudioConfigManager()112 ~AudioConfigManager() 113 { 114 } 115 private: 116 std::unordered_map<ClassType, std::list<AudioModuleInfo>> deviceClassInfo_ = {}; 117 std::unordered_map<AdaptersType, AudioAdapterInfo> adapterInfoMap_ {}; 118 119 bool hasEarpiece_ = false; 120 bool isUpdateRouteSupported_ = true; 121 bool isDefaultAdapterEnable_ = false; 122 std::unordered_map<std::string, std::string> volumeGroupData_; 123 std::unordered_map<std::string, std::string> interruptGroupData_; 124 GlobalConfigs globalConfigs_; 125 bool enableFastVoip_ = false; 126 uint64_t audioLatencyInMsec_ = 50; 127 uint32_t sinkLatencyInMsec_ {0}; 128 bool normalVoipFlag_ = false; 129 130 std::atomic<bool> isAdapterInfoMap_ = false; 131 AudioDeviceManager &audioDeviceManager_; 132 }; 133 134 } 135 } 136 137 #endif