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