• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef ST_AUDIO_EC_MANAGER_H
17 #define ST_AUDIO_EC_MANAGER_H
18 
19 #include <bitset>
20 #include <list>
21 #include <string>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <mutex>
25 #include "singleton.h"
26 #include "audio_group_handle.h"
27 #include "audio_ec_info.h"
28 #include "audio_manager_base.h"
29 #include "audio_module_info.h"
30 #include "audio_router_center.h"
31 #include "audio_policy_manager_factory.h"
32 
33 #include "audio_config_manager.h"
34 #include "audio_active_device.h"
35 #include "audio_iohandle_map.h"
36 
37 namespace OHOS {
38 namespace AudioStandard {
39 
40 class AudioEcManager {
41 public:
GetInstance()42     static AudioEcManager& GetInstance()
43     {
44         static AudioEcManager instance;
45         return instance;
46     }
47 
48     void Init(int32_t ecEnableState, int32_t micRefEnableState);
49     void PrepareAndOpenNormalSource(SessionInfo &sessionInfo, StreamPropInfo &targetInfo, SourceType targetSource);
50     void CloseNormalSource();
51     AudioEcInfo GetAudioEcInfo();
52     void ResetAudioEcInfo();
53 
54     void PresetArmIdleInput(const string &address);
55     void ActivateArmDevice(const string &address, const DeviceRole role);
56     void CloseUsbArmDevice(const AudioDeviceDescriptor &device);
57     void GetTargetSourceTypeAndMatchingFlag(SourceType source, SourceType &targetSource, bool &useMatchingPropInfo);
58 
59     int32_t FetchTargetInfoForSessionAdd(const SessionInfo sessionInfo, StreamPropInfo &targetInfo,
60         SourceType &targetSourceType);
61 
62     void ReloadSourceForSession(SessionInfo sessionInfo);
63 
64     void SetDpSinkModuleInfo(const AudioModuleInfo &moduleInfo);
65     void SetPrimaryMicModuleInfo(const AudioModuleInfo &moduleInfo);
66     SourceType GetSourceOpened();
67     bool GetEcFeatureEnable();
68     bool GetMicRefFeatureEnable();
69     void UpdateStreamEcAndMicRefInfo(AudioModuleInfo &moduleInfo, SourceType sourceType);
70 private:
AudioEcManager()71     AudioEcManager() : audioPolicyManager_(AudioPolicyManagerFactory::GetAudioPolicyManager()),
72         audioRouterCenter_(AudioRouterCenter::GetAudioRouterCenter()),
73         audioIOHandleMap_(AudioIOHandleMap::GetInstance()),
74         audioActiveDevice_(AudioActiveDevice::GetInstance()),
75         audioConfigManager_(AudioConfigManager::GetInstance()) {}
~AudioEcManager()76     ~AudioEcManager() {}
77 
78     void UpdateEnhanceEffectState(SourceType source);
79     void UpdateStreamCommonInfo(AudioModuleInfo &moduleInfo, StreamPropInfo &targetInfo, SourceType sourceType);
80     void UpdateStreamEcInfo(AudioModuleInfo &moduleInfo, SourceType sourceType);
81     void UpdateStreamMicRefInfo(AudioModuleInfo &moduleInfo, SourceType sourceType);
82     void UpdateAudioEcInfo(const AudioDeviceDescriptor &inputDevice, const AudioDeviceDescriptor &outputDevice);
83     void UpdateModuleInfoForEc(AudioModuleInfo &moduleInfo);
84     void UpdateModuleInfoForMicRef(AudioModuleInfo &moduleInfo, SourceType sourceType);
85     std::string ShouldOpenMicRef(SourceType source);
86 
87     EcType GetEcType(const DeviceType inputDevice, const DeviceType outputDevice);
88     std::string GetEcSamplingRate(const std::string &halName, StreamPropInfo &streamPropInfo);
89     std::string GetEcFormat(const std::string &halName, StreamPropInfo &streamPropInfo);
90     std::string GetEcChannels(const std::string &halName, StreamPropInfo &streamPropInfo);
91 
92     int32_t GetPipeInfoByDeviceTypeForEc(const std::string &role, const DeviceType deviceType, PipeInfo &pipeInfo);
93 
94     void UpdateArmModuleInfo(const string &address, const DeviceRole role, AudioModuleInfo &moduleInfo);
95     std::string GetHalNameForDevice(const std::string &role, const DeviceType deviceType);
96     std::string GetPipeNameByDeviceForEc(const std::string &role, const DeviceType deviceType);
97 private:
98     bool isEcFeatureEnable_ = false;
99     bool isMicRefFeatureEnable_ = false;
100 
101     AudioModuleInfo usbSinkModuleInfo_ = {};
102     AudioModuleInfo usbSourceModuleInfo_ = {};
103     AudioModuleInfo primaryMicModuleInfo_ = {};
104     AudioModuleInfo dpSinkModuleInfo_ = {};
105     SourceType normalSourceOpened_ = SOURCE_TYPE_INVALID;
106 
107     std::mutex audioEcInfoMutex_;
108     AudioEcInfo audioEcInfo_;
109     std::string activeArmInputAddr_;
110     std::string activeArmOutputAddr_;
111 
112     bool isMicRefVoipUpOn_ = false;
113     bool isMicRefRecordOn_ = false;
114 
115     IAudioPolicyInterface& audioPolicyManager_;
116     AudioRouterCenter& audioRouterCenter_;
117     AudioIOHandleMap& audioIOHandleMap_;
118     AudioActiveDevice& audioActiveDevice_;
119     AudioConfigManager& audioConfigManager_;
120 };
121 
122 }
123 }
124 
125 #endif