Line data Source code
1 1 : /** @file
2 : * @brief Advanced Audio Distribution Profile header.
3 : */
4 :
5 : /*
6 : * Copyright (c) 2015-2016 Intel Corporation
7 : * Copyright 2024 NXP
8 : *
9 : * SPDX-License-Identifier: Apache-2.0
10 : */
11 : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
12 : #define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
13 :
14 : #include <stdint.h>
15 :
16 : #include <zephyr/bluetooth/bluetooth.h>
17 : #include <zephyr/bluetooth/l2cap.h>
18 : #include <zephyr/bluetooth/classic/avdtp.h>
19 :
20 : #ifdef __cplusplus
21 : extern "C" {
22 : #endif
23 :
24 0 : #define BT_A2DP_STREAM_BUF_RESERVE (12U + BT_L2CAP_BUF_SIZE(0))
25 :
26 : /** SBC IE length */
27 1 : #define BT_A2DP_SBC_IE_LENGTH (4U)
28 : /** MPEG1,2 IE length */
29 1 : #define BT_A2DP_MPEG_1_2_IE_LENGTH (4U)
30 : /** MPEG2,4 IE length */
31 1 : #define BT_A2DP_MPEG_2_4_IE_LENGTH (6U)
32 : /** The max IE (Codec Info Element) length */
33 1 : #define BT_A2DP_MAX_IE_LENGTH (8U)
34 :
35 : /** @brief define the audio endpoint
36 : * @param _role BT_AVDTP_SOURCE or BT_AVDTP_SINK.
37 : * @param _codec value of enum bt_a2dp_codec_id.
38 : * @param _capability the codec capability.
39 : */
40 1 : #define BT_A2DP_EP_INIT(_role, _codec, _capability) \
41 : { \
42 : .codec_type = _codec, \
43 : .sep = {.sep_info = {.media_type = BT_AVDTP_AUDIO, .tsep = _role}}, \
44 : .codec_cap = _capability, .stream = NULL, \
45 : }
46 :
47 : /** @brief define the audio sink endpoint
48 : * @param _codec value of enum bt_a2dp_codec_id.
49 : * @param _capability the codec capability.
50 : */
51 1 : #define BT_A2DP_SINK_EP_INIT(_codec, _capability) \
52 : BT_A2DP_EP_INIT(BT_AVDTP_SINK, _codec, _capability)
53 :
54 : /** @brief define the audio source endpoint
55 : * @param _codec value of enum bt_a2dp_codec_id.
56 : * @param _capability the codec capability.
57 : */
58 1 : #define BT_A2DP_SOURCE_EP_INIT(_codec, _capability) \
59 : BT_A2DP_EP_INIT(BT_AVDTP_SOURCE, _codec, _capability)
60 :
61 : /** @brief define the SBC sink endpoint that can be used as
62 : * bt_a2dp_register_endpoint's parameter.
63 : *
64 : * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SINK_EP_DEFAULT
65 : * is more convenient for user to register SBC endpoint.
66 : *
67 : * @param _name unique structure name postfix.
68 : * @param _freq sbc codec frequency.
69 : * for example: A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000
70 : * @param _ch_mode sbc codec channel mode.
71 : * for example: A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO
72 : * @param _blk_len sbc codec block length.
73 : * for example: A2DP_SBC_BLK_LEN_16
74 : * @param _subband sbc codec subband.
75 : * for example: A2DP_SBC_SUBBAND_8
76 : * @param _alloc_mthd sbc codec allocate method.
77 : * for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
78 : * @param _min_bitpool sbc codec min bit pool. for example: 18
79 : * @param _max_bitpool sbc codec max bit pool. for example: 35
80 : * @
81 : */
82 : #define BT_A2DP_SBC_SINK_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd, _min_bitpool, \
83 1 : _max_bitpool) \
84 : static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = { \
85 : .len = BT_A2DP_SBC_IE_LENGTH, \
86 : .codec_ie = {_freq | _ch_mode, _blk_len | _subband | _alloc_mthd, _min_bitpool, \
87 : _max_bitpool}}; \
88 : static struct bt_a2dp_ep _name = \
89 : BT_A2DP_SINK_EP_INIT(BT_A2DP_SBC, (&bt_a2dp_ep_cap_ie##_name))
90 :
91 : /** @brief define the SBC source endpoint that can be used as bt_a2dp_register_endpoint's
92 : * parameter.
93 : *
94 : * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SOURCE_EP_DEFAULT
95 : * is more convenient for user to register SBC endpoint.
96 : *
97 : * @param _name the endpoint variable name.
98 : * @param _freq sbc codec frequency.
99 : * for example: A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000
100 : * @param _ch_mode sbc codec channel mode.
101 : * for example: A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO
102 : * @param _blk_len sbc codec block length.
103 : * for example: A2DP_SBC_BLK_LEN_16
104 : * @param _subband sbc codec subband.
105 : * for example: A2DP_SBC_SUBBAND_8
106 : * @param _alloc_mthd sbc codec allocate method.
107 : * for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
108 : * @param _min_bitpool sbc codec min bit pool. for example: 18
109 : * @param _max_bitpool sbc codec max bit pool. for example: 35
110 : */
111 : #define BT_A2DP_SBC_SOURCE_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd, \
112 1 : _min_bitpool, _max_bitpool) \
113 : static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = { \
114 : .len = BT_A2DP_SBC_IE_LENGTH, \
115 : .codec_ie = {_freq | _ch_mode, _blk_len | _subband | _alloc_mthd, _min_bitpool, \
116 : _max_bitpool}}; \
117 : static struct bt_a2dp_ep _name = \
118 : BT_A2DP_SOURCE_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
119 :
120 : /** @brief define the default SBC sink endpoint that can be used as
121 : * bt_a2dp_register_endpoint's parameter.
122 : *
123 : * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SINK_EP_DEFAULT
124 : * is more convenient for user to register SBC endpoint.
125 : *
126 : * @param _name the endpoint variable name.
127 : */
128 1 : #define BT_A2DP_SBC_SINK_EP_DEFAULT(_name) \
129 : static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = { \
130 : .len = BT_A2DP_SBC_IE_LENGTH, \
131 : .codec_ie = {A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000 | \
132 : A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO | \
133 : A2DP_SBC_CH_MODE_JOINT, \
134 : A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 | \
135 : A2DP_SBC_ALLOC_MTHD_LOUDNESS, \
136 : 18U, 35U}}; \
137 : static struct bt_a2dp_ep _name = \
138 : BT_A2DP_SINK_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
139 :
140 : /** @brief define the default SBC source endpoint that can be used as bt_a2dp_register_endpoint's
141 : * parameter.
142 : *
143 : * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SOURCE_EP_DEFAULT
144 : * is more convenient for user to register SBC endpoint.
145 : *
146 : * @param _name the endpoint variable name.
147 : */
148 1 : #define BT_A2DP_SBC_SOURCE_EP_DEFAULT(_name) \
149 : static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = { \
150 : .len = BT_A2DP_SBC_IE_LENGTH, \
151 : .codec_ie = {A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000 | \
152 : A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO | \
153 : A2DP_SBC_CH_MODE_JOINT, \
154 : A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 | \
155 : A2DP_SBC_ALLOC_MTHD_LOUDNESS, \
156 : 18U, 35U}, \
157 : }; \
158 : static struct bt_a2dp_ep _name = \
159 : BT_A2DP_SOURCE_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
160 :
161 : /** @brief define the SBC default configuration.
162 : *
163 : * @param _name unique structure name postfix.
164 : * @param _freq_cfg sbc codec frequency.
165 : * for example: A2DP_SBC_SAMP_FREQ_44100
166 : * @param _ch_mode_cfg sbc codec channel mode.
167 : * for example: A2DP_SBC_CH_MODE_JOINT
168 : * @param _blk_len_cfg sbc codec block length.
169 : * for example: A2DP_SBC_BLK_LEN_16
170 : * @param _subband_cfg sbc codec subband.
171 : * for example: A2DP_SBC_SUBBAND_8
172 : * @param _alloc_mthd_cfg sbc codec allocate method.
173 : * for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
174 : * @param _min_bitpool_cfg sbc codec min bit pool. for example: 18
175 : * @param _max_bitpool_cfg sbc codec max bit pool. for example: 35
176 : */
177 : #define BT_A2DP_SBC_EP_CFG(_name, _freq_cfg, _ch_mode_cfg, _blk_len_cfg, _subband_cfg, \
178 1 : _alloc_mthd_cfg, _min_bitpool_cfg, _max_bitpool_cfg) \
179 : static struct bt_a2dp_codec_ie bt_a2dp_codec_ie##_name = { \
180 : .len = BT_A2DP_SBC_IE_LENGTH, \
181 : .codec_ie = {_freq_cfg | _ch_mode_cfg, \
182 : _blk_len_cfg | _subband_cfg | _alloc_mthd_cfg, _min_bitpool_cfg, \
183 : _max_bitpool_cfg}, \
184 : }; \
185 : struct bt_a2dp_codec_cfg _name = { \
186 : .codec_config = &bt_a2dp_codec_ie##_name, \
187 : }
188 :
189 : /** @brief define the SBC default configuration.
190 : *
191 : * @param _name unique structure name postfix.
192 : * @param _freq_cfg the frequency to configure the remote same codec type endpoint.
193 : */
194 1 : #define BT_A2DP_SBC_EP_CFG_DEFAULT(_name, _freq_cfg) \
195 : static struct bt_a2dp_codec_ie bt_a2dp_codec_ie##_name = { \
196 : .len = BT_A2DP_SBC_IE_LENGTH, \
197 : .codec_ie = {_freq_cfg | A2DP_SBC_CH_MODE_JOINT, \
198 : A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 | \
199 : A2DP_SBC_ALLOC_MTHD_LOUDNESS, \
200 : 18U, 35U}, \
201 : }; \
202 : struct bt_a2dp_codec_cfg _name = { \
203 : .codec_config = &bt_a2dp_codec_ie##_name, \
204 : }
205 :
206 : /**
207 : * @brief A2DP error code
208 : */
209 1 : enum bt_a2dp_err_code {
210 : /** Media Codec Type is not valid */
211 : BT_A2DP_INVALID_CODEC_TYPE = 0xC1,
212 : /** Media Codec Type is not supported */
213 : BT_A2DP_NOT_SUPPORTED_CODEC_TYPE = 0xC2,
214 : /** Sampling Frequency is not valid or multiple values have been selected */
215 : BT_A2DP_INVALID_SAMPLING_FREQUENCY = 0xC3,
216 : /** Sampling Frequency is not supported */
217 : BT_A2DP_NOT_SUPPORTED_SAMPLING_FREQUENCY = 0xC4,
218 : /** Channel Mode is not valid or multiple values have been selected */
219 : BT_A2DP_INVALID_CHANNEL_MODE = 0xC5,
220 : /** Channel Mode is not supported */
221 : BT_A2DP_NOT_SUPPORTED_CHANNEL_MODE = 0xC6,
222 : /** None or multiple values have been selected for Number of Subbands */
223 : BT_A2DP_INVALID_SUBBANDS = 0xC7,
224 : /** Number of Subbands is not supported */
225 : BT_A2DP_NOT_SUPPORTED_SUBBANDS = 0xC8,
226 : /** None or multiple values have been selected for Allocation Method */
227 : BT_A2DP_INVALID_ALLOCATION_METHOD = 0xC9,
228 : /** Allocation Method is not supported */
229 : BT_A2DP_NOT_SUPPORTED_ALLOCATION_METHOD = 0xCA,
230 : /** Minimum Bitpool Value is not valid */
231 : BT_A2DP_INVALID_MINIMUM_BITPOOL_VALUE = 0xCB,
232 : /** Minimum Bitpool Value is not supported */
233 : BT_A2DP_NOT_SUPPORTED_MINIMUM_BITPOOL_VALUE = 0xCC,
234 : /** Maximum Bitpool Value is not valid */
235 : BT_A2DP_INVALID_MAXIMUM_BITPOOL_VALUE = 0xCD,
236 : /** Maximum Bitpool Value is not supported */
237 : BT_A2DP_NOT_SUPPORTED_MAXIMUM_BITPOOL_VALUE = 0xCE,
238 : /** None or multiple values have been selected for Layer */
239 : BT_A2DP_INVALID_LAYER = 0xCF,
240 : /** Layer is not supported */
241 : BT_A2DP_NOT_SUPPORTED_LAYER = 0xD0,
242 : /** CRC is not supported */
243 : BT_A2DP_NOT_SUPPORTED_CRC = 0xD1,
244 : /** MPF-2 is not supported */
245 : BT_A2DP_NOT_SUPPORTED_MPF = 0xD2,
246 : /** VBR is not supported */
247 : BT_A2DP_NOT_SUPPORTED_VBR = 0xD3,
248 : /** None or multiple values have been selected for Bit Rate */
249 : BT_A2DP_INVALID_BIT_RATE = 0xD4,
250 : /** Bit Rate is not supported */
251 : BT_A2DP_NOT_SUPPORTED_BIT_RATE = 0xD5,
252 : /** Either 1) Object type is not valid or
253 : * 2) None or multiple values have been selected for Object Type
254 : */
255 : BT_A2DP_INVALID_OBJECT_TYPE = 0xD6,
256 : /** Object Type is not supported */
257 : BT_A2DP_NOT_SUPPORTED_OBJECT_TYPE = 0xD7,
258 : /** Either 1) Channels is not valid or
259 : * 2) None or multiple values have been selected for Channels
260 : */
261 : BT_A2DP_INVALID_CHANNELS = 0xD8,
262 : /** Channels is not supported */
263 : BT_A2DP_NOT_SUPPORTED_CHANNELS = 0xD9,
264 : /** Version is not valid */
265 : BT_A2DP_INVALID_VERSION = 0xDA,
266 : /** Version is not supported */
267 : BT_A2DP_NOT_SUPPORTED_VERSION = 0xDB,
268 : /** Maximum SUL is not acceptable for the Decoder in the SNK */
269 : BT_A2DP_NOT_SUPPORTED_MAXIMUM_SUL = 0xDC,
270 : /** None or multiple values have been selected for Block Length */
271 : BT_A2DP_INVALID_BLOCK_LENGTH = 0xDD,
272 : /** The requested CP Type is not supported */
273 : BT_A2DP_INVALID_CP_TYPE = 0xE0,
274 : /** The format of Content Protection Service Capability/Content
275 : * Protection Scheme Dependent Data is not correct
276 : */
277 : BT_A2DP_INVALID_CP_FORMAT = 0xE1,
278 : /** The codec parameter is invalid.
279 : * Used if a more specific error code does not exist for the codec in use
280 : */
281 : BT_A2DP_INVALID_CODEC_PARAMETER = 0xE2,
282 : /** The codec parameter is not supported.
283 : * Used if a more specific error code does not exist for the codec in use
284 : */
285 : BT_A2DP_NOT_SUPPORTED_CODEC_PARAMETER = 0xE3,
286 : /** Combination of Object Type and DRC is invalid */
287 : BT_A2DP_INVALID_DRC = 0xE4,
288 : /** DRC is not supported */
289 : BT_A2DP_NOT_SUPPORTED_DRC = 0xE5,
290 : };
291 :
292 : /** @brief Codec Type */
293 1 : enum bt_a2dp_codec_type {
294 : /** Codec SBC */
295 : BT_A2DP_SBC = 0x00,
296 : /** Codec MPEG-1 */
297 : BT_A2DP_MPEG1 = 0x01,
298 : /** Codec MPEG-2 */
299 : BT_A2DP_MPEG2 = 0x02,
300 : /** Codec MPEG-D */
301 : BT_A2DP_MPEGD = 0x03,
302 : /** Codec ATRAC */
303 : BT_A2DP_ATRAC = 0x04,
304 : /** Codec Non-A2DP */
305 : BT_A2DP_VENDOR = 0xff
306 : };
307 :
308 : /** @brief A2DP structure */
309 : struct bt_a2dp;
310 :
311 : /* Internal to pass build */
312 : struct bt_a2dp_stream;
313 :
314 : /** @brief codec information elements for the endpoint */
315 1 : struct bt_a2dp_codec_ie {
316 : /** Length of codec_cap */
317 1 : uint8_t len;
318 : /** codec information element */
319 1 : uint8_t codec_ie[BT_A2DP_MAX_IE_LENGTH];
320 : };
321 :
322 : /** @brief The endpoint configuration */
323 1 : struct bt_a2dp_codec_cfg {
324 : /** The media codec configuration content */
325 1 : struct bt_a2dp_codec_ie *codec_config;
326 : };
327 :
328 : /** @brief Stream End Point */
329 1 : struct bt_a2dp_ep {
330 : /** Code Type @ref bt_a2dp_codec_type */
331 1 : uint8_t codec_type;
332 : /** Capabilities */
333 1 : struct bt_a2dp_codec_ie *codec_cap;
334 : /** AVDTP Stream End Point Identifier */
335 1 : struct bt_avdtp_sep sep;
336 : /* Internally used stream object pointer */
337 0 : struct bt_a2dp_stream *stream;
338 : };
339 :
340 0 : struct bt_a2dp_ep_info {
341 : /** Code Type @ref bt_a2dp_codec_type */
342 1 : uint8_t codec_type;
343 : /** Codec capabilities, if SBC, use function of a2dp_codec_sbc.h to parse it */
344 1 : struct bt_a2dp_codec_ie codec_cap;
345 : /** Stream End Point Information */
346 1 : struct bt_avdtp_sep_info *sep_info;
347 : };
348 :
349 : /** @brief Helper enum to be used as return value of bt_a2dp_discover_ep_cb.
350 : * The value informs the caller to perform further pending actions or stop them.
351 : */
352 0 : enum {
353 : BT_A2DP_DISCOVER_EP_STOP = 0,
354 : BT_A2DP_DISCOVER_EP_CONTINUE,
355 : };
356 :
357 : /** @typedef bt_a2dp_discover_ep_cb
358 : *
359 : * @brief Called when a stream endpoint is discovered.
360 : *
361 : * A function of this type is given by the user to the bt_a2dp_discover_param
362 : * object. It'll be called on each valid stream endpoint discovery completion.
363 : * When no more endpoint then NULL is passed to the user. Otherwise user can get
364 : * valid endpoint information from parameter info, user can set parameter ep to
365 : * get the endpoint after the callback is return.
366 : * The returned function value allows the user to control retrieving follow-up
367 : * endpoints if any. If the user doesn't want to read more endpoints since
368 : * current found endpoints fulfill its requirements then should return
369 : * BT_A2DP_DISCOVER_EP_STOP. Otherwise returned value means
370 : * more subcall iterations are allowable.
371 : *
372 : * @param a2dp a2dp connection object identifying a2dp connection to queried remote.
373 : * @param info Object pointing to the information of the callbacked endpoint.
374 : * @param ep If the user want to use this found endpoint, user can set value to it
375 : * to get the endpoint that can be used further in other A2DP APIs. It is NULL if info
376 : * is NULL (no more endpoint is found).
377 : *
378 : * @return BT_A2DP_DISCOVER_EP_STOP in case of no more need to continue discovery
379 : * for next endpoint. By returning BT_A2DP_DISCOVER_EP_STOP user allows this
380 : * discovery continuation.
381 : */
382 1 : typedef uint8_t (*bt_a2dp_discover_ep_cb)(struct bt_a2dp *a2dp, struct bt_a2dp_ep_info *info,
383 : struct bt_a2dp_ep **ep);
384 :
385 0 : struct bt_a2dp_discover_param {
386 : /** discover callback */
387 1 : bt_a2dp_discover_ep_cb cb;
388 : /** The discovered endpoint info that is callbacked by cb */
389 1 : struct bt_a2dp_ep_info info;
390 : /** The max count of remote endpoints that can be got,
391 : * it save endpoint info internally.
392 : */
393 1 : struct bt_avdtp_sep_info *seps_info;
394 : /** The AVDTP version of the peer's A2DP sdp service.
395 : * Stack uses it to determine using get_all_cap or get_cap cmd. When both
396 : * versions are v1.3 or bigger version, get_all_cap is used, otherwise
397 : * get_cap is used.
398 : * It is the same value of the avdtp sepcificaiton's version value.
399 : * For example: 0x0103 means version 1.3
400 : * If the value is 0 (unknown), stack process it as less than v1.3
401 : */
402 1 : uint16_t avdtp_version;
403 : /** The max count of seps (stream endpoint) that can be got in this call route */
404 1 : uint8_t sep_count;
405 : };
406 :
407 : /** @brief The connecting callback */
408 1 : struct bt_a2dp_cb {
409 : /** @brief A a2dp connection has been established.
410 : *
411 : * This callback notifies the application of a a2dp connection.
412 : * It means the AVDTP L2CAP connection.
413 : * In case the err parameter is non-zero it means that the
414 : * connection establishment failed.
415 : *
416 : * @param a2dp a2dp connection object.
417 : * @param err error code.
418 : */
419 1 : void (*connected)(struct bt_a2dp *a2dp, int err);
420 : /** @brief A a2dp connection has been disconnected.
421 : *
422 : * This callback notifies the application that a a2dp connection
423 : * has been disconnected.
424 : *
425 : * @param a2dp a2dp connection object.
426 : */
427 1 : void (*disconnected)(struct bt_a2dp *a2dp);
428 : /**
429 : * @brief Endpoint config request callback
430 : *
431 : * The callback is called whenever an endpoint is requested to be
432 : * configured.
433 : *
434 : * @param a2dp a2dp connection object.
435 : * @param[in] ep Local Audio Endpoint being configured.
436 : * @param[in] codec_cfg Codec configuration.
437 : * @param[out] stream Pointer to stream that will be configured for the endpoint.
438 : * @param[out] rsp_err_code give the error code if response error.
439 : * bt_a2dp_err_code or bt_avdtp_err_code
440 : *
441 : * @return 0 in case of success or negative value in case of error.
442 : */
443 1 : int (*config_req)(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep,
444 : struct bt_a2dp_codec_cfg *codec_cfg, struct bt_a2dp_stream **stream,
445 : uint8_t *rsp_err_code);
446 : /**
447 : * @brief Endpoint config request callback
448 : *
449 : * The callback is called whenever an endpoint is requested to be
450 : * reconfigured.
451 : *
452 : * @param[in] stream Pointer to stream object.
453 : * @param[out] rsp_err_code give the error code if response error.
454 : * bt_a2dp_err_code or bt_avdtp_err_code
455 : *
456 : * @return 0 in case of success or negative value in case of error.
457 : */
458 1 : int (*reconfig_req)(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *codec_cfg,
459 : uint8_t *rsp_err_code);
460 : /** @brief Callback function for bt_a2dp_stream_config() and bt_a2dp_stream_reconfig()
461 : *
462 : * Called when the codec configure operation is completed.
463 : *
464 : * @param[in] stream Pointer to stream object.
465 : * @param[in] rsp_err_code the remote responded error code
466 : * bt_a2dp_err_code or bt_avdtp_err_code
467 : */
468 1 : void (*config_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
469 : /**
470 : * @brief Stream establishment request callback
471 : *
472 : * The callback is called whenever an stream is requested to be
473 : * established (open cmd and create the stream l2cap channel).
474 : *
475 : * @param[in] stream Pointer to stream object.
476 : * @param[out] rsp_err_code give the error code if response error.
477 : * bt_a2dp_err_code or bt_avdtp_err_code
478 : *
479 : * @return 0 in case of success or negative value in case of error.
480 : */
481 1 : int (*establish_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
482 : /** @brief Callback function for bt_a2dp_stream_establish()
483 : *
484 : * Called when the establishment operation is completed.
485 : * (open cmd and create the stream l2cap channel).
486 : *
487 : * @param[in] stream Pointer to stream object.
488 : * @param[in] rsp_err_code the remote responded error code
489 : * bt_a2dp_err_code or bt_avdtp_err_code
490 : */
491 1 : void (*establish_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
492 : /**
493 : * @brief Stream release request callback
494 : *
495 : * The callback is called whenever an stream is requested to be
496 : * released (release cmd and release the l2cap channel)
497 : *
498 : * @param[in] stream Pointer to stream object.
499 : * @param[out] rsp_err_code give the error code if response error.
500 : * bt_a2dp_err_code or bt_avdtp_err_code
501 : *
502 : * @return 0 in case of success or negative value in case of error.
503 : */
504 1 : int (*release_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
505 : /** @brief Callback function for bt_a2dp_stream_release()
506 : *
507 : * Called when the release operation is completed.
508 : * (release cmd and release the l2cap channel)
509 : *
510 : * @param[in] stream Pointer to stream object.
511 : * @param[in] rsp_err_code the remote responded error code
512 : * bt_a2dp_err_code or bt_avdtp_err_code
513 : */
514 1 : void (*release_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
515 : /**
516 : * @brief Stream start request callback
517 : *
518 : * The callback is called whenever an stream is requested to be
519 : * started.
520 : *
521 : * @param[in] stream Pointer to stream object.
522 : * @param[out] rsp_err_code give the error code if response error.
523 : * bt_a2dp_err_code or bt_avdtp_err_code
524 : *
525 : * @return 0 in case of success or negative value in case of error.
526 : */
527 1 : int (*start_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
528 : /** @brief Callback function for bt_a2dp_stream_start()
529 : *
530 : * Called when the start operation is completed.
531 : *
532 : * @param[in] stream Pointer to stream object.
533 : * @param[in] rsp_err_code the remote responded error code
534 : * bt_a2dp_err_code or bt_avdtp_err_code
535 : */
536 1 : void (*start_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
537 : /**
538 : * @brief Stream suspend request callback
539 : *
540 : * The callback is called whenever an stream is requested to be
541 : * suspended.
542 : *
543 : * @param[in] stream Pointer to stream object.
544 : * @param[out] rsp_err_code give the error code if response error.
545 : * bt_a2dp_err_code or bt_avdtp_err_code
546 : *
547 : * @return 0 in case of success or negative value in case of error.
548 : */
549 1 : int (*suspend_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
550 : /** @brief Callback function for bt_a2dp_stream_suspend()
551 : *
552 : * Called when the suspend operation is completed.
553 : *
554 : * @param[in] stream Pointer to stream object.
555 : * @param[in] rsp_err_code the remote responded error code
556 : * bt_a2dp_err_code or bt_avdtp_err_code
557 : */
558 1 : void (*suspend_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
559 : /**
560 : * @brief Stream abort request callback
561 : *
562 : * The callback is called whenever an stream is requested to be
563 : * aborted.
564 : *
565 : * @param[in] stream Pointer to stream object.
566 : * @param[out] rsp_err_code give the error code if response error.
567 : * bt_a2dp_err_code or bt_avdtp_err_code
568 : *
569 : * @return 0 in case of success or negative value in case of error.
570 : */
571 1 : int (*abort_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
572 : /** @brief Callback function for bt_a2dp_stream_abort()
573 : *
574 : * Called when the abort operation is completed.
575 : *
576 : * @param[in] stream Pointer to stream object.
577 : * @param[in] rsp_err_code the remote responded error code
578 : * bt_a2dp_err_code or bt_avdtp_err_code
579 : */
580 1 : void (*abort_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
581 : };
582 :
583 : /** @brief A2DP Connect.
584 : *
585 : * This function is to be called after the conn parameter is obtained by
586 : * performing a GAP procedure. The API is to be used to establish A2DP
587 : * connection between devices.
588 : * This function only establish AVDTP L2CAP Signaling connection.
589 : * After connection success, the callback that is registered by
590 : * bt_a2dp_register_connect_callback is called.
591 : *
592 : * @param conn Pointer to bt_conn structure.
593 : *
594 : * @return pointer to struct bt_a2dp in case of success or NULL in case
595 : * of error.
596 : */
597 1 : struct bt_a2dp *bt_a2dp_connect(struct bt_conn *conn);
598 :
599 : /** @brief disconnect l2cap a2dp
600 : *
601 : * This function close AVDTP L2CAP Signaling connection.
602 : * It closes the AVDTP L2CAP Media connection too if it is established.
603 : *
604 : * @param a2dp The a2dp instance.
605 : *
606 : * @return 0 in case of success and error code in case of error.
607 : */
608 1 : int bt_a2dp_disconnect(struct bt_a2dp *a2dp);
609 :
610 : /** @brief Endpoint Registration.
611 : *
612 : * @param ep Pointer to bt_a2dp_ep structure.
613 : * @param media_type Media type that the Endpoint is, #bt_avdtp_media_type.
614 : * @param sep_type Stream endpoint type, #bt_avdtp_sep_type.
615 : *
616 : * @return 0 in case of success and error code in case of error.
617 : */
618 1 : int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_type);
619 :
620 : /** @brief register callback.
621 : *
622 : * The cb is called when bt_a2dp_connect is called or it is operated by remote device.
623 : *
624 : * @param cb The callback function.
625 : *
626 : * @return 0 in case of success and error code in case of error.
627 : */
628 1 : int bt_a2dp_register_cb(struct bt_a2dp_cb *cb);
629 :
630 : /** @brief Obtain the ACL connection corresponding to A2DP.
631 : *
632 : * @param a2dp The A2DP instance.
633 : *
634 : * @return Connection object associated with the A2DP context. The caller gets a new
635 : * reference to the connection object which must be released with bt_conn_unref()
636 : * once done using the object.
637 : */
638 1 : struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp);
639 :
640 : /** @brief Discover remote endpoints.
641 : *
642 : * @param a2dp The a2dp instance.
643 : * @param param the discover used param.
644 : *
645 : * @return 0 in case of success and error code in case of error.
646 : */
647 1 : int bt_a2dp_discover(struct bt_a2dp *a2dp, struct bt_a2dp_discover_param *param);
648 :
649 : /** @brief A2DP Stream */
650 1 : struct bt_a2dp_stream {
651 : /** local endpoint */
652 1 : struct bt_a2dp_ep *local_ep;
653 : /** remote endpoint */
654 1 : struct bt_a2dp_ep *remote_ep;
655 : /** remote endpoint's Stream End Point ID */
656 1 : uint8_t remote_ep_id;
657 : /** Audio stream operations */
658 1 : struct bt_a2dp_stream_ops *ops;
659 : /** the a2dp connection */
660 1 : struct bt_a2dp *a2dp;
661 : /** the stream current configuration */
662 1 : struct bt_a2dp_codec_ie codec_config;
663 : };
664 :
665 : /** @brief The stream endpoint related operations */
666 1 : struct bt_a2dp_stream_ops {
667 : /**
668 : * @brief Stream configured callback
669 : *
670 : * The callback is called whenever an Audio Stream has been configured or reconfigured.
671 : *
672 : * @param stream Stream object that has been configured.
673 : */
674 1 : void (*configured)(struct bt_a2dp_stream *stream);
675 : /**
676 : * @brief Stream establishment callback
677 : *
678 : * The callback is called whenever an Audio Stream has been established.
679 : *
680 : * @param stream Stream object that has been established.
681 : */
682 1 : void (*established)(struct bt_a2dp_stream *stream);
683 : /**
684 : * @brief Stream release callback
685 : *
686 : * The callback is called whenever an Audio Stream has been released.
687 : * After released, the stream becomes invalid.
688 : *
689 : * @param stream Stream object that has been released.
690 : */
691 1 : void (*released)(struct bt_a2dp_stream *stream);
692 : /**
693 : * @brief Stream start callback
694 : *
695 : * The callback is called whenever an Audio Stream has been started.
696 : *
697 : * @param stream Stream object that has been started.
698 : */
699 1 : void (*started)(struct bt_a2dp_stream *stream);
700 : /**
701 : * @brief Stream suspend callback
702 : *
703 : * The callback is called whenever an Audio Stream has been suspended.
704 : *
705 : * @param stream Stream object that has been suspended.
706 : */
707 1 : void (*suspended)(struct bt_a2dp_stream *stream);
708 : /**
709 : * @brief Stream abort callback
710 : *
711 : * The callback is called whenever an Audio Stream has been aborted.
712 : * After aborted, the stream becomes invalid.
713 : *
714 : * @param stream Stream object that has been aborted.
715 : */
716 1 : void (*aborted)(struct bt_a2dp_stream *stream);
717 : #if defined(CONFIG_BT_A2DP_SINK)
718 : /** @brief the media streaming data, only for sink
719 : *
720 : * @param buf the data buf
721 : * @param seq_num the sequence number
722 : * @param ts the time stamp
723 : */
724 : void (*recv)(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
725 : uint32_t ts);
726 : #endif
727 : #if defined(CONFIG_BT_A2DP_SOURCE)
728 : /**
729 : * @brief Stream audio HCI sent callback
730 : *
731 : * This callback will be called once the controller marks the SDU
732 : * as completed. When the controller does so is implementation
733 : * dependent. It could be after the SDU is enqueued for transmission,
734 : * or after it is sent on air or flushed.
735 : *
736 : * This callback is only used if the ISO data path is HCI.
737 : *
738 : * @param stream Stream object.
739 : */
740 : void (*sent)(struct bt_a2dp_stream *stream);
741 : #endif
742 : };
743 :
744 : /**
745 : * @brief Register Audio callbacks for a stream.
746 : *
747 : * Register Audio callbacks for a stream.
748 : *
749 : * @param stream Stream object.
750 : * @param ops Stream operations structure.
751 : */
752 1 : void bt_a2dp_stream_cb_register(struct bt_a2dp_stream *stream, struct bt_a2dp_stream_ops *ops);
753 :
754 : /** @brief configure endpoint.
755 : *
756 : * bt_a2dp_discover can be used to find remote's endpoints.
757 : * This function to configure the selected endpoint that is found by
758 : * bt_a2dp_discover.
759 : * This function sends AVDTP_SET_CONFIGURATION.
760 : *
761 : * @param a2dp The a2dp instance.
762 : * @param stream Stream object.
763 : * @param local_ep The configured endpoint that is registered.
764 : * @param remote_ep The remote endpoint.
765 : * @param config The config to configure the endpoint.
766 : *
767 : * @return 0 in case of success and error code in case of error.
768 : */
769 1 : int bt_a2dp_stream_config(struct bt_a2dp *a2dp, struct bt_a2dp_stream *stream,
770 : struct bt_a2dp_ep *local_ep, struct bt_a2dp_ep *remote_ep,
771 : struct bt_a2dp_codec_cfg *config);
772 :
773 : /** @brief establish a2dp streamer.
774 : *
775 : * This function sends the AVDTP_OPEN command and create the l2cap channel.
776 : *
777 : * @param stream The stream object.
778 : *
779 : * @return 0 in case of success and error code in case of error.
780 : */
781 1 : int bt_a2dp_stream_establish(struct bt_a2dp_stream *stream);
782 :
783 : /** @brief release a2dp streamer.
784 : *
785 : * This function sends the AVDTP_CLOSE command and release the l2cap channel.
786 : * After release, the stream becomes invalid.
787 : *
788 : * @param stream The stream object.
789 : *
790 : * @return 0 in case of success and error code in case of error.
791 : */
792 1 : int bt_a2dp_stream_release(struct bt_a2dp_stream *stream);
793 :
794 : /** @brief start a2dp streamer.
795 : *
796 : * This function sends the AVDTP_START command.
797 : *
798 : * @param stream The stream object.
799 : *
800 : * @return 0 in case of success and error code in case of error.
801 : */
802 1 : int bt_a2dp_stream_start(struct bt_a2dp_stream *stream);
803 :
804 : /** @brief suspend a2dp streamer.
805 : *
806 : * This function sends the AVDTP_SUSPEND command.
807 : *
808 : * @param stream The stream object.
809 : *
810 : * @return 0 in case of success and error code in case of error.
811 : */
812 1 : int bt_a2dp_stream_suspend(struct bt_a2dp_stream *stream);
813 :
814 : /** @brief re-configure a2dp streamer
815 : *
816 : * This function sends the AVDTP_RECONFIGURE command.
817 : *
818 : * @param stream The stream object.
819 : * @param config The config to configure the stream.
820 : *
821 : * @return 0 in case of success and error code in case of error.
822 : */
823 1 : int bt_a2dp_stream_reconfig(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *config);
824 :
825 : /** @brief abort a2dp streamer.
826 : *
827 : * This function sends the AVDTP_ABORT command.
828 : * After abort, the stream becomes invalid.
829 : *
830 : * @param stream The stream object.
831 : *
832 : * @return 0 in case of success and error code in case of error.
833 : */
834 1 : int bt_a2dp_stream_abort(struct bt_a2dp_stream *stream);
835 :
836 : /** @brief get the stream l2cap mtu
837 : *
838 : * @param stream The stream object.
839 : *
840 : * @return mtu value
841 : */
842 1 : uint32_t bt_a2dp_get_mtu(struct bt_a2dp_stream *stream);
843 :
844 : /** @brief send a2dp media data
845 : *
846 : * Only A2DP source side can call this function.
847 : *
848 : * @param stream The stream object.
849 : * @param buf The data.
850 : * @param seq_num The sequence number.
851 : * @param ts The time stamp.
852 : *
853 : * @return 0 in case of success and error code in case of error.
854 : */
855 1 : int bt_a2dp_stream_send(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
856 : uint32_t ts);
857 :
858 : #ifdef __cplusplus
859 : }
860 : #endif
861 :
862 : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ */
|