• 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 
16 #ifndef ST_AUDIO_POLICY_INTERFACE_H
17 #define ST_AUDIO_POLICY_INTERFACE_H
18 
19 #include <list>
20 #include <mutex>
21 
22 #include "audio_device_descriptor.h"
23 #include "audio_device_info.h"
24 #include "audio_info.h"
25 #include "audio_interrupt_info.h"
26 #include "audio_stream_change_info.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 /**
31  * Describes the device change type and device information.
32  *
33  * @since 7
34  */
35 struct DeviceChangeAction : public Parcelable {
36     DeviceChangeType type;
37     DeviceFlag flag;
38     std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptors;
39     static constexpr int32_t DEVICE_CHANGE_VALID_SIZE = 128;
40 
SetClientInfoDeviceChangeAction41     void SetClientInfo(std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo) const
42     {
43         for (auto &des : deviceDescriptors) {
44             if (des != nullptr) {
45                 des->SetClientInfo(clientInfo);
46             }
47         }
48     }
49 
MarshallingDeviceChangeAction50     bool Marshalling(Parcel &parcel) const override
51     {
52         parcel.WriteInt32(static_cast<int32_t>(type));
53         parcel.WriteInt32(static_cast<int32_t>(flag));
54         int32_t size = static_cast<int32_t>(deviceDescriptors.size());
55         parcel.WriteInt32(size);
56         for (auto &des : deviceDescriptors) {
57             if (des == nullptr) {
58                 return false;
59             }
60             des->Marshalling(parcel);
61         }
62         return true;
63     }
64 
UnmarshallingDeviceChangeAction65     static DeviceChangeAction *Unmarshalling(Parcel &parcel)
66     {
67         auto info = new(std::nothrow) DeviceChangeAction();
68         if (info == nullptr) {
69             return nullptr;
70         }
71 
72         info->type = static_cast<DeviceChangeType>(parcel.ReadUint32());
73         info->flag = static_cast<DeviceFlag>(parcel.ReadUint32());
74         int32_t size = parcel.ReadInt32();
75         if (size < 0 || size >= DEVICE_CHANGE_VALID_SIZE) {
76             delete info;
77             return nullptr;
78         }
79 
80         for (int32_t i = 0; i < size; i++) {
81             auto device = AudioDeviceDescriptor::Unmarshalling(parcel);
82             if (device != nullptr) {
83                 info->deviceDescriptors.emplace_back(std::shared_ptr<AudioDeviceDescriptor>(device));
84             }
85         }
86         return info;
87     }
88 };
89 
90 class AudioFocusInfoChangeCallback {
91 public:
92     virtual ~AudioFocusInfoChangeCallback() = default;
93     /**
94      * Called when focus info change.
95      *
96      * @param focusInfoList Indicates the focusInfoList information needed by client.
97      * For details, refer audioFocusInfoList_ struct in audio_policy_server.h
98      * @since 9
99      */
100     virtual void OnAudioFocusInfoChange(const std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList) = 0;
101 
OnAudioFocusRequested(const AudioInterrupt &)102     virtual void OnAudioFocusRequested(const AudioInterrupt &) {}
103 
OnAudioFocusAbandoned(const AudioInterrupt &)104     virtual void OnAudioFocusAbandoned(const AudioInterrupt &) {}
105 };
106 
107 class AudioDeviceRefiner {
108 public:
109     virtual ~AudioDeviceRefiner() = default;
110 
111     virtual int32_t OnAudioOutputDeviceRefined(std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs,
112         RouterType routerType, StreamUsage streamUsage, int32_t clientUid, AudioPipeType audioPipeType) = 0;
113     virtual int32_t OnAudioInputDeviceRefined(std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs,
114         RouterType routerType, SourceType sourceType, int32_t clientUid, AudioPipeType audioPipeType) = 0;
115     virtual int32_t GetSplitInfoRefined(std::string &splitInfo) = 0;
116     virtual int32_t OnDistributedOutputChange(bool isRemote) = 0;
117 };
118 
119 class AudioClientInfoMgrCallback {
120 public:
121     virtual ~AudioClientInfoMgrCallback() = default;
122     virtual bool OnCheckClientInfo(const std::string &bundleName, int32_t &uid, int32_t pid) = 0;
123 };
124 
125 class AudioVKBInfoMgrCallback {
126 public:
127     virtual ~AudioVKBInfoMgrCallback() = default;
128     virtual bool OnCheckVKBInfo(const std::string &bundleName) = 0;
129 };
130 
131 class AudioPreferredOutputDeviceChangeCallback {
132 public:
133     virtual ~AudioPreferredOutputDeviceChangeCallback() = default;
134     /**
135      * Called when the prefer output device changes
136      *
137      * @param vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptor.
138      */
139     virtual void OnPreferredOutputDeviceUpdated(const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc) = 0;
140 };
141 
142 class AudioPreferredInputDeviceChangeCallback {
143     public:
144     virtual ~AudioPreferredInputDeviceChangeCallback() = default;
145     /**
146      * Called when the prefer input device changes
147      *
148      * @param vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptor.
149      */
150     virtual void OnPreferredInputDeviceUpdated(const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc) = 0;
151 };
152 
153 class AudioManagerDeviceChangeCallback {
154 public:
155     virtual ~AudioManagerDeviceChangeCallback() = default;
156     /**
157      * Called when an interrupt is received.
158      *
159      * @param deviceChangeAction Indicates the DeviceChangeAction information needed by client.
160      * For details, refer DeviceChangeAction struct
161      * @since 8
162      */
163     virtual void OnDeviceChange(const DeviceChangeAction &deviceChangeAction) = 0;
164 };
165 
166 class AudioQueryClientTypeCallback {
167 public:
168     virtual ~AudioQueryClientTypeCallback() = default;
169     virtual bool OnQueryClientType(const std::string &bundleName, uint32_t uid) = 0;
170 };
171 
172 class AudioQueryDeviceVolumeBehaviorCallback {
173 public:
174     virtual ~AudioQueryDeviceVolumeBehaviorCallback() = default;
175     virtual VolumeBehavior OnQueryDeviceVolumeBehavior() = 0;
176 };
177 
178 class VolumeKeyEventCallback {
179 public:
180     virtual ~VolumeKeyEventCallback() = default;
181     /**
182      * @brief VolumeKeyEventCallback will be executed when hard volume key is pressed up/down
183      *
184      * @param volumeEvent the volume event info.
185      * @since 8
186      */
187     virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0;
188     /**
189      * @brief VolumeKeyEventCallback will be executed when volume degree is updated
190      *
191      * @param volumeEvent the volume event info.
192      */
OnVolumeDegreeEvent(VolumeEvent volumeEvent)193     virtual void OnVolumeDegreeEvent(VolumeEvent volumeEvent) {}
194 };
195 
196 class StreamVolumeChangeCallback {
197 public:
198     virtual ~StreamVolumeChangeCallback() = default;
199     /**
200      * @brief StreamVolumeChangeCallback will be executed when stream volume changed
201      *
202      * @param volumeEvent the volume event info.
203      * @since 20
204      */
205     virtual void OnStreamVolumeChange(StreamVolumeEvent streamVolumeEvent) = 0;
206 };
207 
208 class SystemVolumeChangeCallback {
209 public:
210     virtual ~SystemVolumeChangeCallback() = default;
211     /**
212      * @brief SystemVolumeChangeCallback will be executed when system volume changed
213      *
214      * @param volumeEvent the volume event info.
215      * @since 20
216      */
217     virtual void OnSystemVolumeChange(VolumeEvent volumeEvent) = 0;
218 };
219 
220 class AudioCapturerStateChangeCallback {
221 public:
222     virtual ~AudioCapturerStateChangeCallback() = default;
223     /**
224      * Called when the capturer state changes
225      *
226      * @param capturerChangeInfo Contains the renderer state information.
227      */
228     virtual void OnCapturerStateChange(
229         const std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) = 0;
230     std::mutex cbMutex_;
231 };
232 
233 class AudioRendererStateChangeCallback {
234 public:
235     virtual ~AudioRendererStateChangeCallback() = default;
236     /**
237      * Called when the renderer state changes
238      *
239      * @param rendererChangeInfo Contains the renderer state information.
240      */
241     virtual void OnRendererStateChange(
242         const std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) = 0;
243 };
244 
245 class AudioQueryAllowedPlaybackCallback {
246     public:
247         virtual ~AudioQueryAllowedPlaybackCallback() = default;
248         virtual bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) = 0;
249 };
250 
251 class AudioBackgroundMuteCallback {
252     public:
253         virtual ~AudioBackgroundMuteCallback() = default;
254         virtual void OnBackgroundMute(const int32_t uid) = 0;
255 };
256 class AudioManagerAudioSceneChangedCallback {
257 public:
258     virtual ~AudioManagerAudioSceneChangedCallback() = default;
259     /**
260      * Called when AudioScene changed.
261      *
262      * @param AudioScene audio scene
263      * @since 16
264      */
265     virtual void OnAudioSceneChange(const AudioScene audioScene) = 0;
266 };
267 
268 /**
269  * @brief NearLink audio stream operation callback interface.
270  */
271 class SleAudioOperationCallback {
272 public:
273     /**
274      * @brief Retrieve the list of active NearLink physical audio devices.
275      * @param devices Output vector for storing device descriptors.
276      */
277     virtual void GetSleAudioDeviceList(std::vector<AudioDeviceDescriptor> &devices) = 0;
278 
279     /**
280      * @brief Retrieve the list of virtual NearLink audio devices.
281      * @param devices Output vector for storing virtual device descriptors.
282      */
283     virtual void GetSleVirtualAudioDeviceList(std::vector<AudioDeviceDescriptor> &devices) = 0;
284 
285     /**
286      * @brief Check if in-band ringtone is enabled for a NearLink device.
287      * @param[in] device MAC address of the peer NearLink device.
288      * @return true if in-band ringtone is active, false otherwise.
289      */
290     virtual bool IsInBandRingOpen(const std::string &device) const = 0;
291 
292     /**
293      * @brief Query supported audio stream types for a device.
294      * @param device Address of the peer NearLink device.
295      * @return Bitmask of supported stream types
296      */
297     virtual uint32_t GetSupportStreamType(const std::string &device) const = 0;
298 
299     /**
300      * @brief Set a device as the active sink for a specific stream type.
301      * @param device Address of the peer NearLink device.
302      * @param streamType Target stream type to activate.
303      * @return Returns the status code for this function called.
304      */
305     virtual int32_t SetActiveSinkDevice(const std::string &device, uint32_t streamType) = 0;
306 
307     /**
308      * @brief Start audio streaming to a device.
309      * @param device Address of the peer NearLink device.
310      * @param streamType Stream type to start.
311      * @return Returns the status code for this function called.
312      */
313     virtual int32_t StartPlaying(const std::string &device, uint32_t streamType) = 0;
314 
315     /**
316      * @brief Stop audio streaming to a device.
317      * @param device Address of the peer NearLink device.
318      * @param streamType Stream type to stop.
319      * @return Returns the status code for this function called.
320      */
321     virtual int32_t StopPlaying(const std::string &device, uint32_t streamType) = 0;
322 
323     /**
324      * @brief Establish connection with allowed profiles for a device.
325      * @param remoteAddr Address of the peer NearLink device.
326      * @return Returns the status code for this function called.
327      */
328     virtual int32_t ConnectAllowedProfiles(const std::string &remoteAddr) const = 0;
329 
330     /**
331      * @brief Set absolute volume level for a device.
332      * @param remoteAddr Address of the peer NearLink device.
333      * @param volume Target volume level.
334      * @param streamType Stream type to configure.
335      * @return int32_t
336      */
337     virtual int32_t SetDeviceAbsVolume(const std::string &remoteAddr, uint32_t volume, uint32_t streamType) = 0;
338 
339     /**
340      * @brief Send user selection to the device server.
341      * @param device Address of the peer NearLink device.
342      * @param streamType Stream type associated with the selection.
343      * @return int32_t
344      */
345     virtual int32_t SendUserSelection(const std::string &device, uint32_t streamType) = 0;
346 
347     /**
348      * @brief Get the delay from a device.
349      * @param device Address of the peer NearLink device.
350      * @param delayValue Render delay.
351      * @return int32_t
352      */
353     virtual int32_t GetRenderPosition(const std::string &device, uint32_t &delayValue) = 0;
354 };
355 } // namespace AudioStandard
356 } // namespace OHOS
357 #endif // ST_AUDIO_POLICY_INTERFACE_H
358 
359