• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef HPAE_MANAGER_IMPL_H
16 #define HPAE_MANAGER_IMPL_H
17 
18 #include <functional>
19 #include <any>
20 #include "audio_module_info.h"
21 #include "hpae_manager.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 namespace HPAE {
26 class HpaeManagerImpl : public IHpaeManager {
27 public:
28     HpaeManagerImpl();
29     ~HpaeManagerImpl() = default;
30     // sync interface
31     int32_t Init() override;
32     int32_t DeInit() override;
33     int32_t RegisterSerivceCallback(const std::weak_ptr<AudioServiceHpaeCallback> &callback) override;
34     int32_t RegisterHpaeDumpCallback(const std::weak_ptr<AudioServiceHpaeDumpCallback> &callback) override;
35     void DumpSinkInfo(std::string deviceName) override;
36     void DumpSourceInfo(std::string deviceName) override;
37     void DumpAllAvailableDevice(HpaeDeviceInfo &devicesInfo) override;
38     void DumpSinkInputsInfo() override;
39     void DumpSourceOutputsInfo() override;
40     uint32_t OpenAudioPort(const AudioModuleInfo &audioModuleInfo) override;
41     int32_t CloseAudioPort(int32_t audioHandleIndex) override;
42     uint32_t ReloadAudioPort(const AudioModuleInfo &audioModuleInfo) override;
43     int32_t GetSinkInfoByIdx(const int32_t &sinkIdx,
44         std::function<void(const HpaeSinkInfo &sinkInfo, int32_t result)> callback) override;
45     int32_t GetSourceInfoByIdx(const int32_t &sourceIdx,
46         std::function<void(const HpaeSourceInfo &sourceInfo, int32_t result)> callback) override;
47 
48     int32_t GetAllSinkInputs() override;
49     int32_t GetAllSourceOutputs() override;
50     int32_t MoveSourceOutputByIndexOrName(
51         uint32_t sourceOutputId, uint32_t sourceIndex, std::string sourceName) override;
52     int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) override;
53     void HandleMsg() override;
54     bool IsInit() override;
55     bool IsRunning() override;
56     bool IsMsgProcessing() override;
57     // async interface
58     int32_t SetDefaultSink(std::string name) override;
59     int32_t SetDefaultSource(std::string name) override;
60     int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) override;
61     bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) override;
62     int32_t SetSourceOutputMute(int32_t uid, bool setMute) override;
63     int32_t GetAllSinks() override;
64 
65     // play and record stream interface
66     int32_t CreateStream(const HpaeStreamInfo &streamInfo) override;
67     int32_t DestroyStream(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
68     int32_t Start(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
69     int32_t StartWithSyncId(HpaeStreamClassType streamClassType, uint32_t sessionId, int32_t syncId) override;
70     int32_t Pause(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
71     int32_t Flush(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
72     int32_t Drain(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
73     int32_t Stop(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
74     int32_t Release(HpaeStreamClassType streamClassType, uint32_t sessionId) override;
75     int32_t RegisterStatusCallback(HpaeStreamClassType streamClassType, uint32_t sessionId,
76         const std::weak_ptr<IStreamStatusCallback> &callback) override;
77     // record stream interface
78     int32_t RegisterReadCallback(uint32_t sessionId, const std::weak_ptr<ICapturerStreamCallback> &callback) override;
79     int32_t GetSourceOutputInfo(uint32_t sessionId, HpaeStreamInfo &streamInfo) override;
80     // play stream interface
81     int32_t SetClientVolume(uint32_t sessionId, float volume) override;
82     int32_t SetLoudnessGain(uint32_t sessionId, float loudnessGain) override;
83     int32_t SetRate(uint32_t sessionId, int32_t rate) override;
84     int32_t SetAudioEffectMode(uint32_t sessionId, int32_t effectMode) override;
85     int32_t GetAudioEffectMode(uint32_t sessionId, int32_t &effectMode) override;
86     int32_t SetPrivacyType(uint32_t sessionId, int32_t privacyType) override;
87     int32_t GetPrivacyType(uint32_t sessionId, int32_t &privacyType) override;
88     int32_t RegisterWriteCallback(uint32_t sessionId, const std::weak_ptr<IStreamCallback> &callback) override;
89     int32_t SetOffloadPolicy(uint32_t sessionId, int32_t state) override;
90     size_t GetWritableSize(uint32_t sessionId) override;
91     int32_t UpdateSpatializationState(
92         uint32_t sessionId, bool spatializationEnabled, bool headTrackingEnabled) override;
93     int32_t UpdateMaxLength(uint32_t sessionId, uint32_t maxLength) override;
94     int32_t SetOffloadRenderCallbackType(uint32_t sessionId, int32_t type) override;
95     void SetSpeed(uint32_t sessionId, float speed) override;
96 
97     // interfaces for render effect
98     void InitAudioEffectChainManager(const std::vector<EffectChain> &effectChains,
99         const EffectChainManagerParam &effectChainManagerParam,
100         const std::vector<std::shared_ptr<AudioEffectLibEntry>> &effectLibraryList) override;
101     void SetOutputDeviceSink(int32_t device, const std::string &sinkName) override;
102     int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) override;
103     int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) override;
104     int32_t SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType) override;
105     int32_t EffectRotationUpdate(const uint32_t rotationState) override;
106     int32_t SetEffectSystemVolume(const int32_t systemVolumeType, const float systemVolume) override;
107     int32_t SetAbsVolumeStateToEffect(const bool absVolumeState) override;
108     int32_t SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray) override;
109     int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) override;
110     int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override;
111     int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override;
112     void InitHdiState() override;
113     void UpdateEffectBtOffloadSupported(const bool &isSupported) override;
114     void UpdateParamExtra(const std::string &mainkey, const std::string &subkey, const std::string &value) override;
115     // interfaces for capture effect
116     void InitAudioEnhanceChainManager(const std::vector<EffectChain> &enhanceChains,
117         const EffectChainManagerParam &managerParam,
118         const std::vector<std::shared_ptr<AudioEffectLibEntry>> &enhanceLibraryList) override;
119     int32_t SetOutputDevice(const uint32_t &renderId, const DeviceType &outputDevice) override;
120     int32_t SetVolumeInfo(const AudioVolumeType &volumeType, const float &systemVol) override;
121     int32_t SetMicrophoneMuteInfo(const bool &isMute) override;
122     int32_t SetStreamVolumeInfo(const uint32_t &sessionId, const float &streamVol) override;
123     int32_t SetAudioEnhanceProperty(
124         const AudioEffectPropertyArrayV3 &propertyArray, DeviceType deviceType = DEVICE_TYPE_NONE) override;
125     int32_t GetAudioEnhanceProperty(
126         AudioEffectPropertyArrayV3 &propertyArray, DeviceType deviceType = DEVICE_TYPE_NONE) override;
127     int32_t SetAudioEnhanceProperty(
128         const AudioEnhancePropertyArray &propertyArray, DeviceType deviceType = DEVICE_TYPE_NONE) override;
129     int32_t GetAudioEnhanceProperty(
130         AudioEnhancePropertyArray &propertyArray, DeviceType deviceType = DEVICE_TYPE_NONE) override;
131     void UpdateExtraSceneType(
132         const std::string &mainkey, const std::string &subkey, const std::string &extraSceneType) override;
133     void NotifySettingsDataReady() override;
134     void NotifyAccountsChanged() override;
135     bool IsAcousticEchoCancelerSupported(SourceType sourceType) override;
136     bool SetEffectLiveParameter(const std::vector<std::pair<std::string, std::string>> &params) override;
137     bool GetEffectLiveParameter(const std::vector<std::string> &subKeys,
138         std::vector<std::pair<std::string, std::string>> &result) override;
139     int32_t UpdateCollaborativeState(bool isCollaborationEnabled) override;
140     void AddStreamVolumeToEffect(const std::string stringSessionID, const float streamVolume) override;
141     void DeleteStreamVolumeToEffect(const std::string stringSessionID) override;
142 private:
143     std::shared_ptr<HpaeManager> manager_;
144 };
145 }  // namespace HPAE
146 }  // namespace AudioStandard
147 }  // namespace OHOS
148 #endif  // HPAE_MANAGER_IMPL_H