• 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 /**
17  * @file interface_profile_a2dp_src.h
18  *
19  * @brief A2dp codec configuration information of a2dp source
20  *
21  * @since 6
22  */
23 
24 #ifndef INTERFACE_PROFILE_A2DP_SRC_H
25 #define INTERFACE_PROFILE_A2DP_SRC_H
26 
27 #include "interface_profile.h"
28 
29 namespace OHOS {
30 namespace bluetooth {
31 struct A2dpSrcCodecInfo {
32     // Codec priority
33     uint32_t codecPriority;
34 
35     // Codec type
36     uint8_t codecType;
37 
38     // Codec sample
39     uint32_t sampleRate;
40 
41     // Codec bits per sample
42     uint32_t bitsPerSample;
43 
44     // Codec channel mode
45     uint8_t channelMode;
46 
47     // Codec specific value1
48     uint64_t codecSpecific1;
49 
50     // Codec specific value2
51     uint64_t codecSpecific2;
52 
53     // Codec specific value3
54     uint64_t codecSpecific3;
55 
56     // Codec specific value4
57     uint64_t codecSpecific4;
58 };
59 
60 /**
61  * @brief The codec configuration and capability information of a2dp source
62  *
63  * @since 6.0
64  */
65 struct A2dpSrcCodecStatus {
66     // current codec information
67     A2dpSrcCodecInfo codecInfo {};
68 
69     // local codec information
70     std::vector<A2dpSrcCodecInfo> codecInfoLocalCap {};
71 
72     // Local device and peer confirmed codec information
73     std::vector<A2dpSrcCodecInfo> codecInfoConfirmedCap {};
74 };
75 
76 /**
77  * @brief Callback function api of A2DP service, including connection, disconnection.
78  *
79  * @since 6.0
80  */
81 class IA2dpObserver {
82 public:
83     /**
84      * @brief A destructor used to delete the A2DP Service Observer instance.
85      *
86      * @since 6.0
87      */
88     virtual ~IA2dpObserver() = default;
89 
90     /**
91      * @brief The callback function after device's playing state changed.
92      *
93      * @param device  the remote bluetooth device.
94      * @param playingState  the playing state after changing.
95      * @param error  the error information.
96      * @since 6.0
97      */
OnPlayingStatusChaned(const RawAddress & device,int playingState,int error)98     virtual void OnPlayingStatusChaned(const RawAddress &device, int playingState, int error) {};
99 
100     /**
101      * @brief The callback function after device's codec information changed.
102      *
103      * @param device  the remote bluetooth device.
104      * @param info  the device's codec information.
105      * @param error  the error information.
106      * @since 6.0
107      */
OnConfigurationChanged(const RawAddress & device,const A2dpSrcCodecInfo & info,int error)108     virtual void OnConfigurationChanged(const RawAddress &device, const A2dpSrcCodecInfo &info, int error) {};
109 
110     /**
111      * @brief ConnectionState Changed observer.
112      * @param device bluetooth device address.
113      * @param state Connection state.
114      * @since 6.0
115      */
OnConnectionStateChanged(const RawAddress & remoteAddr,int state)116     virtual void OnConnectionStateChanged(const RawAddress &remoteAddr, int state) {};
117 
118     /**
119      * @brief Media stack Changed observer.
120      * @param device bluetooth device address.
121      * @param state Action on the device.
122      * @since 11.0
123      */
OnMediaStackChanged(const RawAddress & remoteAddr,int action)124     virtual void OnMediaStackChanged(const RawAddress &remoteAddr, int action) {};
125 };
126 
127 /**
128  * @brief This class provides functions called by Framework API.
129  *
130  * @since 6.0
131  */
132 class IProfileA2dp : public IProfile {
133 public:
134     /**
135      * @brief Get a2dp source service instance.
136      *
137      * @return Returns an instance of a2dp source service.
138      * @since 6.0
139      */
140     static IProfileA2dp *GetSrcProfile();
141 
142     /**
143      * @brief Get a2dp sink service instance.
144      *
145      * @return Returns an instance of a2dp sink service.
146      * @since 6.0
147      */
148     static IProfileA2dp *GetSnkProfile();
149 
150     /**
151      * @brief Get devices by connection states.
152      *
153      * @param states The connection states of the bluetooth device.
154      * @return Returns devices that match the connection states.
155      * @since 6.0
156      */
157     virtual std::vector<RawAddress> GetDevicesByStates(std::vector<int> &states) const = 0;
158 
159     /**
160      * @brief Get device connection state by address.
161      *
162      * @param device The address of the peer bluetooth device.
163      * @return Returns <b>A2DP_DISCONNECTED</b> if device connect state is disconnected;
164      *         Returns <b>A2DP_DISCONNECTING</b> if device connect state is disconnecting;
165      *         Returns <b>A2DP_CONNECTED</b> if device connect state is connected;
166      *         Returns <b>A2DP_CONNECTING</b> if device connect state is connecting;
167      *         Returns <b>A2DP_INVALID_STATUS</b> if target device is not in device list;
168      * @since 6.0
169      */
170     virtual int GetDeviceState(const RawAddress &device) const = 0;
171 
172     /**
173      * @brief Get device playing state by address when target device is on connected.
174      *
175      * @param device The address of the peer bluetooth device.
176      * @return Returns <b>1</b> if device is on playing;
177      *         Returns <b>0</b> if device is not on playing;
178      * @since 6.0
179      */
180     virtual int GetPlayingState(const RawAddress &device, int &state) const = 0;
181 
182     /**
183      * @brief Set target device as active device.
184      *
185      * @param device The address of the peer bluetooth device.
186      * @return Returns <b>RET_NO_ERROR</b> Target device has already been active, or perform normal setting processing.
187      *         Returns <b>RET_BAD_STATUS</b> Target device is not on connected, or set fails.
188      * @since 6.0
189      */
190     virtual int SetActiveSinkDevice(const RawAddress &device) = 0;
191 
192     /**
193      * @brief Get active device.
194      * @return Returns active device.
195      * @since 6.0
196      */
197     virtual const RawAddress &GetActiveSinkDevice() const = 0;
198 
199     /**
200      * @brief Set connection strategy for peer bluetooth device.
201      *        If peer device is connected and the policy is set not allowed,then perform disconnect operation.
202      *        If peer device is disconnected and the policy is set allowed,then perform connect operation.
203      *
204      * @param device The address of the peer bluetooth device.
205      * @param strategy The device connect strategy.
206      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
207      *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
208      * @since 6.0
209      */
210     virtual int SetConnectStrategy(const RawAddress &device, int strategy) = 0;
211 
212     /**
213      * @brief Get connection strategy of peer bluetooth device.
214      *
215      * @param device The address of the peer bluetooth device.
216      * @return Returns <b>CONNECTION_ALLOWED</b> if the peer device is allowed to connect.
217      *         Returns <b>CONNECTION_FORBIDDEN</b> if the peer device is not allowed to connect.
218      *         Returns <b>CONNECTION_UNKNOWN</b> if the connection policy is unknown.
219      * @since 6.0
220      */
221     virtual int GetConnectStrategy(const RawAddress &device) const = 0;
222 
223     /**
224      * @brief Send delay reporting.
225      *
226      * @param device The address of the peer bluetooth device.
227      * @param delayValue The delay value.
228      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
229      *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
230      */
231     virtual int SendDelay(const RawAddress &device, uint16_t delayValue) = 0;
232 
233     /**
234      * @brief Get codec status information of connected device.
235      *
236      * @param device The address of the bluetooth device.
237      * @return Returns codec status information of connected device.
238      * @since 6.0
239      */
240     virtual A2dpSrcCodecStatus GetCodecStatus(const RawAddress &device) const = 0;
241 
242     /**
243      * @brief Set the codec encoding preferences of the specified device.
244      *
245      * @param device The address of the bluetooth device.
246      * @param info The codec encoding information.
247      * @return Return
248      * @since 6.0
249      */
250     virtual int SetCodecPreference(const RawAddress &device, const A2dpSrcCodecInfo &info) = 0;
251 
252     /**
253      * @brief Set whether enables the optional codec.
254      *
255      * @param device The address of the bluetooth device.
256      * @param isEnable Set true if enables the optional codec and set optional codec's priority high.
257      *                 Set false if disables the optional codec and set optional codec's priority low.
258      * @since 6.0
259      */
260     virtual void SwitchOptionalCodecs(const RawAddress &device, bool isEnable) = 0;
261 
262     /**
263      * @brief Get whether the peer bluetooth device supports optional codec.
264      *
265      * @param device The address of the bluetooth device.
266      * @return Returns <b>A2DP_OPTIONAL_SUPPORT</b> The device supports optional codec.
267      *         Returns <b>A2DP_OPTIONAL_NOT_SUPPORT</b> The device doesn't support optional codec.
268      *         Returns <b>A2DP_OPTIONAL_SUPPORT_UNKNOWN</b> Don't know if the device support optional codec.
269      * @since 6.0
270      */
271     virtual int GetOptionalCodecsSupportState(const RawAddress &device) const = 0;
272 
273     /**
274      * @brief Audio start streaming.
275      *
276      * @param device The address of the bluetooth device.
277      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
278      *         Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list.
279      * @since 6.0
280      */
281     virtual int StartPlaying(const RawAddress &device) = 0;
282 
283     /**
284      * @brief Audio suspend streaming.
285      *
286      * @param device The address of the bluetooth device.
287      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
288      *         Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list.
289      * @since 6.0
290      */
291     virtual int SuspendPlaying(const RawAddress &device) = 0;
292 
293     /**
294      * @brief Audio stop streaming.
295      *
296      * @param device The address of the bluetooth device.
297      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
298      *         Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list.
299      * @since 6.0
300      */
301     virtual int StopPlaying(const RawAddress &device) = 0;
302 
303     /**
304      * @brief Register observer function of framework.
305      *
306      * @param observer The observer function pointer of framework.
307      * @since 6.0
308      */
309     virtual void RegisterObserver(IA2dpObserver *observer) = 0;
310 
311     /**
312      * @brief Deregister observer function of framework.
313      *
314      * @since 6.0
315      */
316     virtual void DeregisterObserver(IA2dpObserver *observer) = 0;
317 
318     /**
319      * @brief Send frame data.
320      * @param[in] data: The address of the data
321      * @param[in] size: The size of the data
322      * @since 6.0
323      */
324     virtual int WriteFrame(const uint8_t *data, uint32_t size) = 0;
325 
326     /**
327      * @brief Get the current rendered position.
328      * @param[out] delayValue: The delayed time
329      * @param[out] sendDataSize: The size of the data sent
330      * @param[out] timeStamp: The time of the current position
331      * @since 6.0
332      */
333     virtual void GetRenderPosition(uint16_t &delayValue, uint16_t &sendDataSize, uint32_t &timeStamp) = 0;
334 };
335 /**
336  * @brief This class provides functions called by Framework API for a2dp source.
337  *
338  * @since 6.0
339  */
340 class IProfileA2dpSrc : public IProfileA2dp {};
341 }  // namespace bluetooth
342 }  // namespace OHOS
343 
344 #endif  // INTERFACE_PROFILE_A2DP_SRC_H