• 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_SERVICE_ADAPTER_H
17 #define ST_AUDIO_SERVICE_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 #include <unistd.h>
22 #include <vector>
23 
24 #include "audio_effect.h"
25 #include "audio_errors.h"
26 #include "audio_module_info.h"
27 
28 #define NOT_SUPPORT_RET { return ERR_NOT_SUPPORTED; }
29 namespace OHOS {
30 namespace AudioStandard {
31 class AudioServiceAdapterCallback {
32 public:
33     virtual void OnAudioStreamRemoved(const uint64_t sessionID) = 0;
34 
35     virtual void OnSetVolumeDbCb() = 0;
36 
~AudioServiceAdapterCallback()37     virtual ~AudioServiceAdapterCallback() {}
38 };
39 
40 class AudioServiceAdapter {
41 public:
42     /**
43      * @brief create audioserviceadapter instance
44      *
45      * @param cb callback reference for AudioServiceAdapterCallback class
46      * @return Returns instance of class that extends AudioServiceAdapter
47     */
48     static std::shared_ptr<AudioServiceAdapter> CreateAudioAdapter(std::unique_ptr<AudioServiceAdapterCallback> cb,
49         bool isAudioEngine = false);
50 
51     /**
52      * @brief Connect to underlining audio server
53      *
54      * @return Returns true if connection is success, else return false
55      * @since 1.0
56      * @version 1.0
57      */
58     virtual bool Connect() = 0;
59 
60     /**
61      * @brief Opens the audio port while loading the audio modules source and sink.
62      *
63      * @param audioPortName name of the audio modules to be loaded
64      * @param moduleArgs audio module info like rate, channel etc
65      * @return Returns module index if module loaded successfully; returns an error code
66      * defined in {@link audio_errors.h} otherwise.
67      */
68     virtual uint32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) = 0;
69     virtual int32_t OpenAudioPort(std::string audioPortName, const AudioModuleInfo& audioModuleInfo) = 0;
70 
71     /**
72      * @brief Reload the audio port while loading the audio modules sink.
73      *
74      * @param audioPortName name of the audio modules to be loaded
75      * @param audioModuleInfo audio module info like rate, channel etc
76      * @return Returns module index if module loaded successfully; returns an error code
77      * defined in {@link audio_errors .h} otherwise.
78      */
79     virtual int32_t ReloadAudioPort(const std::string &audioPortName, const AudioModuleInfo& audioModuleInfo) = 0;
80 
81     /**
82      * @brief closes/unloads the audio modules loaded.
83      *
84      * @param audioHandleIndex the index of the loaded audio module
85      * @return Returns {@link SUCCESS} if module/port is closed successfully; returns an error code
86      * defined in {@link audio_errors.h} otherwise.
87      */
88     virtual int32_t CloseAudioPort(int32_t audioHandleIndex) = 0;
89 
90     /**
91      * @brief sets default audio sink.
92      *
93      * @param name name of default audio sink to be set
94      * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code
95      * defined in {@link audio_errors.h} otherwise.
96      */
97     virtual int32_t SetDefaultSink(std::string name) = 0;
98 
99     /**
100      * @brief sets default audio source.
101      *
102      * @param name name of default audio source to be set
103      * @return Returns {@link SUCCESS} if default audio source is set successfully; returns an error code
104      * defined in {@link audio_errors.h} otherwise.
105      */
106     virtual int32_t SetDefaultSource(std::string name) = 0;
107 
108     /**
109      * @brief sets all sink-input connect to one default dink
110      *
111      * @param name name of default audio sink to be set
112      * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code
113      * defined in {@link audio_errors.h} otherwise.
114      */
115     virtual int32_t SetLocalDefaultSink(std::string name) = 0;
116 
117     /**
118      * @brief get sinks by adapter name
119      *
120      * @param adapterName name of default audio sink to be set
121      * @return Returns sink ids.
122      */
123     virtual std::vector<uint32_t> GetTargetSinks(std::string adapterName) = 0;
124 
125     /**
126      * @brief get all sinks
127      *
128      * @return Returns sink infos.
129      */
130     virtual std::vector<SinkInfo> GetAllSinks() = 0;
131 
132     /**
133      * @brief set mute for give output streamType
134      *
135      * @param streamType the output streamType for which mute will be set, streamType defined in{@link audio_info.h}
136      * @param mute boolean value, true: Set mute; false: Set unmute
137      * @return Returns {@link SUCCESS} if mute/unmute is set successfully; returns an error code
138      * defined in {@link audio_errors.h} otherwise.
139      */
140     virtual int32_t SetSourceOutputMute(int32_t uid, bool setMute) = 0;
141 
142     /**
143      * @brief suspends the current active device
144      *
145      * @param audioPortName Name of the default audio sink to be suspended
146      * @return Returns {@link SUCCESS} if suspend is success; returns an error code
147      * defined in {@link audio_errors.h} otherwise.
148      */
149     virtual int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) = 0;
150 
151     /**
152      * @brief mute the device or unmute
153      *
154      * @param sinkName Name of the audio sink
155      * @return Returns {@link true} if mute is success; returns false otherwise.
156      */
157     virtual bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) = 0;
158 
159     /**
160      * @brief returns the list of all sink inputs
161      *
162      * @return Returns : List of all sink inputs
163      */
164     virtual std::vector<SinkInput> GetAllSinkInputs() = 0;
165 
166     /**
167      * @brief returns the list of all source outputs
168      *
169      * @return Returns : List of all source outputs
170      */
171     virtual std::vector<SourceOutput> GetAllSourceOutputs() = 0;
172 
173     /**
174      * @brief Disconnects the connected audio server
175      *
176      * @return void
177      */
178     virtual void Disconnect() = 0;
179 
180     /**
181      * @brief Move one stream to target source.
182      *
183      * @return int32_t the result.
184      */
185     virtual int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId,
186         uint32_t sourceIndex, std::string sourceName) = 0;
187 
188     /**
189      * @brief Move one stream to target sink.
190      *
191      * @return int32_t the result.
192      */
193     virtual int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) = 0;
194 
195     /**
196      * @brief Get current effect property.
197      *
198      * @return int32_t the result.
199      */
200     virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) = 0;
201 
202     /**
203      * @brief Get current effect property.
204      *
205      * @return int32_t the result.
206      */
207     virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0;
208 
209     /**
210      * @brief Get current enhance property.
211      *
212      * @return int32_t the result.
213      */
214     virtual int32_t GetAudioEnhanceProperty(AudioEffectPropertyArrayV3 &propertyArray,
215         DeviceType deviceType = DEVICE_TYPE_NONE) = 0;
216 
217     /**
218      * @brief Get current enhance property.
219      *
220      * @return int32_t the result.
221      */
222     virtual int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray,
223         DeviceType deviceType = DEVICE_TYPE_NONE) = 0;
224 
225     /**
226      * @brief Set collaborative service enabled
227      *
228      * @return int32_t the result, only supports proaudio for now.
229      */
230     virtual int32_t UpdateCollaborativeState(bool isCollaborationEnabled) NOT_SUPPORT_RET
231 
232     /**
233      * @brief Set SetAbsVolumeStateToEffect service enabled
234      *
235      * @return int32_t the result, only supports proaudio for now.
236      */
237     virtual int32_t SetAbsVolumeStateToEffect(const bool absVolumeState) NOT_SUPPORT_RET
238     virtual ~AudioServiceAdapter();
239 };
240 } // namespace AudioStandard
241 } // namespace OHOS
242 #endif  // ST_AUDIO_SERVICE_ADAPTER_H
243