• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_info.h"
25 #include "audio_effect.h"
26 
27 namespace OHOS {
28 namespace AudioStandard {
29 class AudioServiceAdapterCallback {
30 public:
31     /**
32      * @brief computes the volume to be set in audioserver
33      *
34      * @param streamType streamType for which volume will be computed
35      * @return Returns volume level in float
36      */
37     virtual float OnGetVolumeDbCb(AudioStreamType streamType) = 0;
38 
39     virtual void OnSessionRemoved(const uint32_t sessionID) = 0;
40 
41     virtual void OnPlaybackCapturerStop() = 0;
42 
43     virtual void OnWakeupCapturerStop() = 0;
44 
~AudioServiceAdapterCallback()45     virtual ~AudioServiceAdapterCallback() {}
46 };
47 
48 class AudioServiceAdapter {
49 public:
50     /**
51      * @brief create audioserviceadapter instance
52      *
53      * @param cb callback reference for AudioServiceAdapterCallback class
54      * @return Returns instance of class that extends AudioServiceAdapter
55     */
56     static std::unique_ptr<AudioServiceAdapter> CreateAudioAdapter(std::unique_ptr<AudioServiceAdapterCallback> cb);
57 
58     /**
59      * @brief Connect to underlining audio server
60      *
61      * @return Returns true if connection is success, else return false
62      * @since 1.0
63      * @version 1.0
64      */
65     virtual bool Connect() = 0;
66 
67     /**
68      * @brief Opens the audio port while loading the audio modules source and sink.
69      *
70      * @param audioPortName name of the audio modules to be loaded
71      * @param moduleArgs audio module info like rate, channel etc
72      * @return Returns module index if module loaded successfully; returns an error code
73      * defined in {@link audio_errors.h} otherwise.
74      */
75     virtual uint32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) = 0;
76 
77     /**
78      * @brief closes/unloads the audio modules loaded.
79      *
80      * @param audioHandleIndex the index of the loaded audio module
81      * @return Returns {@link SUCCESS} if module/port is closed successfully; returns an error code
82      * defined in {@link audio_errors.h} otherwise.
83      */
84     virtual int32_t CloseAudioPort(int32_t audioHandleIndex) = 0;
85 
86     /**
87      * @brief sets default audio sink.
88      *
89      * @param name name of default audio sink to be set
90      * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code
91      * defined in {@link audio_errors.h} otherwise.
92      */
93     virtual int32_t SetDefaultSink(std::string name) = 0;
94 
95     /**
96      * @brief sets default audio source.
97      *
98      * @param name name of default audio source to be set
99      * @return Returns {@link SUCCESS} if default audio source is set successfully; returns an error code
100      * defined in {@link audio_errors.h} otherwise.
101      */
102     virtual int32_t SetDefaultSource(std::string name) = 0;
103 
104     /**
105      * @brief sets all sink-input connect to one default dink
106      *
107      * @param name name of default audio sink to be set
108      * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code
109      * defined in {@link audio_errors.h} otherwise.
110      */
111     virtual int32_t SetLocalDefaultSink(std::string name) = 0;
112 
113     /**
114      * @brief get sinks by adapter name
115      *
116      * @param adapterName name of default audio sink to be set
117      * @return Returns sink ids.
118      */
119     virtual std::vector<uint32_t> GetTargetSinks(std::string adapterName) = 0;
120 
121     /**
122      * @brief get all sinks
123      *
124      * @return Returns sink infos.
125      */
126     virtual std::vector<SinkInfo> GetAllSinks() = 0;
127 
128     /**
129      * @brief sets audio volume db
130      *
131      * @param streamType the streamType for which volume will be set, streamType defined in{@link audio_info.h}
132      * @param volume the volume level to be set
133      * @return Returns {@link SUCCESS} if volume is set successfully; returns an error code
134      * defined in {@link audio_errors.h} otherwise.
135      */
136     virtual int32_t SetVolumeDb(AudioStreamType streamType, float volume) = 0;
137 
138     /**
139      * @brief set mute for give output streamType
140      *
141      * @param streamType the output streamType for which mute will be set, streamType defined in{@link audio_info.h}
142      * @param mute boolean value, true: Set mute; false: Set unmute
143      * @return Returns {@link SUCCESS} if mute/unmute is set successfully; returns an error code
144      * defined in {@link audio_errors.h} otherwise.
145      */
146     virtual int32_t SetSourceOutputMute(int32_t uid, bool setMute) = 0;
147 
148     /**
149      * @brief suspends the current active device
150      *
151      * @param audioPortName Name of the default audio sink to be suspended
152      * @return Returns {@link SUCCESS} if suspend is success; returns an error code
153      * defined in {@link audio_errors.h} otherwise.
154      */
155     virtual int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) = 0;
156 
157     /**
158      * @brief mute the device or unmute
159      *
160      * @param sinkName Name of the audio sink
161      * @return Returns {@link true} if mute is success; returns false otherwise.
162      */
163     virtual bool SetSinkMute(const std::string &sinkName, bool isMute) = 0;
164 
165     /**
166      * @brief returns if given streamType is active(currently the streamType audio is played)
167      *
168      * @param streamType the streamType for which status will be fetched streamType defined in{@link audio_info.h}
169      * @return Returns true: If streamType is active; else returns false
170      */
171     virtual bool IsStreamActive(AudioStreamType streamType);
172 
173     /**
174      * @brief returns the list of all sink inputs
175      *
176      * @return Returns : List of all sink inputs
177      */
178     virtual std::vector<SinkInput> GetAllSinkInputs() = 0;
179 
180     /**
181      * @brief returns the list of all source outputs
182      *
183      * @return Returns : List of all source outputs
184      */
185     virtual std::vector<SourceOutput> GetAllSourceOutputs() = 0;
186 
187     /**
188      * @brief Disconnects the connected audio server
189      *
190      * @return void
191      */
192     virtual void Disconnect() = 0;
193 
194     /**
195      * @brief Move one stream to target source.
196      *
197      * @return int32_t the result.
198      */
199     virtual int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId,
200         uint32_t sourceIndex, std::string sourceName) = 0;
201 
202     /**
203      * @brief Move one stream to target sink.
204      *
205      * @return int32_t the result.
206      */
207     virtual int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) = 0;
208 
209     virtual int32_t UpdateSwapDeviceStatus() = 0;
210 
211     virtual ~AudioServiceAdapter();
212 };
213 } // namespace AudioStandard
214 } // namespace OHOS
215 #endif  // ST_AUDIO_SERVICE_ADAPTER_H
216