Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
a2dp.h
Go to the documentation of this file.
1
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
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define BT_A2DP_STREAM_BUF_RESERVE (12U + BT_L2CAP_BUF_SIZE(0))
25
27#define BT_A2DP_SBC_IE_LENGTH (4U)
29#define BT_A2DP_MPEG_1_2_IE_LENGTH (4U)
31#define BT_A2DP_MPEG_2_4_IE_LENGTH (6U)
33#define BT_A2DP_MAX_IE_LENGTH (8U)
34
40#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
51#define BT_A2DP_SINK_EP_INIT(_codec, _capability) \
52 BT_A2DP_EP_INIT(BT_AVDTP_SINK, _codec, _capability)
53
58#define BT_A2DP_SOURCE_EP_INIT(_codec, _capability) \
59 BT_A2DP_EP_INIT(BT_AVDTP_SOURCE, _codec, _capability)
60
82#define BT_A2DP_SBC_SINK_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd, _min_bitpool, \
83 _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
111#define BT_A2DP_SBC_SOURCE_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd, \
112 _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
128#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
148#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
177#define BT_A2DP_SBC_EP_CFG(_name, _freq_cfg, _ch_mode_cfg, _blk_len_cfg, _subband_cfg, \
178 _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
194#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
290};
291
305
307struct bt_a2dp;
308
309/* Internal to pass build */
310struct bt_a2dp_stream;
311
319
325
334 /* Internally used stream object pointer */
336};
337
346
350enum {
353};
354
380typedef uint8_t (*bt_a2dp_discover_ep_cb)(struct bt_a2dp *a2dp, struct bt_a2dp_ep_info *info,
381 struct bt_a2dp_ep **ep);
382
395
408 void (*connected)(struct bt_a2dp *a2dp, int err);
416 void (*disconnected)(struct bt_a2dp *a2dp);
432 int (*config_req)(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep,
433 struct bt_a2dp_codec_cfg *codec_cfg, struct bt_a2dp_stream **stream,
434 uint8_t *rsp_err_code);
447 int (*reconfig_req)(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *codec_cfg,
448 uint8_t *rsp_err_code);
457 void (*config_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
470 int (*establish_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
480 void (*establish_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
493 int (*release_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
503 void (*release_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
516 int (*start_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
525 void (*start_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
538 int (*suspend_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
547 void (*suspend_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
560 int (*abort_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
569 void (*abort_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
570};
571
586struct bt_a2dp *bt_a2dp_connect(struct bt_conn *conn);
587
597int bt_a2dp_disconnect(struct bt_a2dp *a2dp);
598
607int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_type);
608
618
626int bt_a2dp_discover(struct bt_a2dp *a2dp, struct bt_a2dp_discover_param *param);
627
643
653 void (*configured)(struct bt_a2dp_stream *stream);
661 void (*established)(struct bt_a2dp_stream *stream);
670 void (*released)(struct bt_a2dp_stream *stream);
678 void (*started)(struct bt_a2dp_stream *stream);
686 void (*suspended)(struct bt_a2dp_stream *stream);
695 void (*aborted)(struct bt_a2dp_stream *stream);
696#if defined(CONFIG_BT_A2DP_SINK)
703 void (*recv)(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
704 uint32_t ts);
705#endif
706#if defined(CONFIG_BT_A2DP_SOURCE)
719 void (*sent)(struct bt_a2dp_stream *stream);
720#endif
721};
722
732
748int bt_a2dp_stream_config(struct bt_a2dp *a2dp, struct bt_a2dp_stream *stream,
749 struct bt_a2dp_ep *local_ep, struct bt_a2dp_ep *remote_ep,
750 struct bt_a2dp_codec_cfg *config);
751
761
772
782
792
802int bt_a2dp_stream_reconfig(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *config);
803
814
822
823#if defined(CONFIG_BT_A2DP_SOURCE)
835int bt_a2dp_stream_send(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
836 uint32_t ts);
837#endif
838
839#ifdef __cplusplus
840}
841#endif
842
843#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ */
int bt_a2dp_stream_release(struct bt_a2dp_stream *stream)
release a2dp streamer.
int bt_a2dp_stream_start(struct bt_a2dp_stream *stream)
start a2dp streamer.
int bt_a2dp_stream_config(struct bt_a2dp *a2dp, struct bt_a2dp_stream *stream, struct bt_a2dp_ep *local_ep, struct bt_a2dp_ep *remote_ep, struct bt_a2dp_codec_cfg *config)
configure endpoint.
bt_a2dp_err_code
A2DP error code.
Definition a2dp.h:209
@ BT_A2DP_INVALID_CP_FORMAT
The format of Content Protection Service Capability/Content Protection Scheme Dependent Data is not c...
Definition a2dp.h:277
@ BT_A2DP_INVALID_CODEC_TYPE
Media Codec Type is not valid.
Definition a2dp.h:211
@ BT_A2DP_INVALID_CHANNELS
Either 1) Channels is not valid or 2) None or multiple values have been selected for Channels.
Definition a2dp.h:261
@ BT_A2DP_NOT_SUPPORTED_DRC
DRC is not supported.
Definition a2dp.h:289
@ BT_A2DP_NOT_SUPPORTED_VERSION
Version is not supported.
Definition a2dp.h:267
@ BT_A2DP_NOT_SUPPORTED_SUBBANDS
Number of Subbands is not supported.
Definition a2dp.h:225
@ BT_A2DP_NOT_SUPPORTED_CHANNELS
Channels is not supported.
Definition a2dp.h:263
@ BT_A2DP_INVALID_OBJECT_TYPE
Either 1) Object type is not valid or 2) None or multiple values have been selected for Object Type.
Definition a2dp.h:255
@ BT_A2DP_NOT_SUPPORTED_CODEC_PARAMETER
The codec parameter is not supported.
Definition a2dp.h:285
@ BT_A2DP_INVALID_VERSION
Version is not valid.
Definition a2dp.h:265
@ BT_A2DP_NOT_SUPPORTED_LAYER
Layer is not supported.
Definition a2dp.h:241
@ BT_A2DP_NOT_SUPPORTED_SAMPLING_FREQUENCY
Sampling Frequency is not supported.
Definition a2dp.h:217
@ BT_A2DP_NOT_SUPPORTED_CRC
CRC is not supported.
Definition a2dp.h:243
@ BT_A2DP_INVALID_CHANNEL_MODE
Channel Mode is not valid or multiple values have been selected.
Definition a2dp.h:219
@ BT_A2DP_INVALID_SAMPLING_FREQUENCY
Sampling Frequency is not valid or multiple values have been selected.
Definition a2dp.h:215
@ BT_A2DP_INVALID_MAXIMUM_BITPOOL_VALUE
Maximum Bitpool Value is not valid.
Definition a2dp.h:235
@ BT_A2DP_NOT_SUPPORTED_OBJECT_TYPE
Object Type is not supported.
Definition a2dp.h:257
@ BT_A2DP_NOT_SUPPORTED_ALLOCATION_METHOD
Allocation Method is not supported.
Definition a2dp.h:229
@ BT_A2DP_INVALID_SUBBANDS
None or multiple values have been selected for Number of Subbands.
Definition a2dp.h:223
@ BT_A2DP_NOT_SUPPORTED_CHANNEL_MODE
Channel Mode is not supported.
Definition a2dp.h:221
@ BT_A2DP_NOT_SUPPORTED_VBR
VBR is not supported.
Definition a2dp.h:247
@ BT_A2DP_NOT_SUPPORTED_MPF
MPF-2 is not supported.
Definition a2dp.h:245
@ BT_A2DP_INVALID_CODEC_PARAMETER
The codec parameter is invalid.
Definition a2dp.h:281
@ BT_A2DP_NOT_SUPPORTED_MAXIMUM_BITPOOL_VALUE
Maximum Bitpool Value is not supported.
Definition a2dp.h:237
@ BT_A2DP_INVALID_CP_TYPE
The requested CP Type is not supported.
Definition a2dp.h:273
@ BT_A2DP_NOT_SUPPORTED_CODEC_TYPE
Media Codec Type is not supported.
Definition a2dp.h:213
@ BT_A2DP_NOT_SUPPORTED_MINIMUM_BITPOOL_VALUE
Minimum Bitpool Value is not supported.
Definition a2dp.h:233
@ BT_A2DP_INVALID_MINIMUM_BITPOOL_VALUE
Minimum Bitpool Value is not valid.
Definition a2dp.h:231
@ BT_A2DP_INVALID_BIT_RATE
None or multiple values have been selected for Bit Rate.
Definition a2dp.h:249
@ BT_A2DP_INVALID_BLOCK_LENGTH
None or multiple values have been selected for Block Length.
Definition a2dp.h:271
@ BT_A2DP_INVALID_ALLOCATION_METHOD
None or multiple values have been selected for Allocation Method.
Definition a2dp.h:227
@ BT_A2DP_INVALID_LAYER
None or multiple values have been selected for Layer.
Definition a2dp.h:239
@ BT_A2DP_NOT_SUPPORTED_BIT_RATE
Bit Rate is not supported.
Definition a2dp.h:251
@ BT_A2DP_INVALID_DRC
Combination of Object Type and DRC is invalid.
Definition a2dp.h:287
@ BT_A2DP_NOT_SUPPORTED_MAXIMUM_SUL
Maximum SUL is not acceptable for the Decoder in the SNK.
Definition a2dp.h:269
int bt_a2dp_register_cb(struct bt_a2dp_cb *cb)
register callback.
int bt_a2dp_stream_reconfig(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *config)
re-configure a2dp streamer
int bt_a2dp_stream_abort(struct bt_a2dp_stream *stream)
abort a2dp streamer.
#define BT_A2DP_MAX_IE_LENGTH
The max IE (Codec Info Element) length.
Definition a2dp.h:33
int bt_a2dp_discover(struct bt_a2dp *a2dp, struct bt_a2dp_discover_param *param)
Discover remote endpoints.
@ BT_A2DP_DISCOVER_EP_STOP
Definition a2dp.h:351
@ BT_A2DP_DISCOVER_EP_CONTINUE
Definition a2dp.h:352
int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_type)
Endpoint Registration.
void bt_a2dp_stream_cb_register(struct bt_a2dp_stream *stream, struct bt_a2dp_stream_ops *ops)
Register Audio callbacks for a stream.
int bt_a2dp_disconnect(struct bt_a2dp *a2dp)
disconnect l2cap a2dp
struct bt_a2dp * bt_a2dp_connect(struct bt_conn *conn)
A2DP Connect.
uint8_t(* bt_a2dp_discover_ep_cb)(struct bt_a2dp *a2dp, struct bt_a2dp_ep_info *info, struct bt_a2dp_ep **ep)
Called when a stream endpoint is discovered.
Definition a2dp.h:380
int bt_a2dp_stream_suspend(struct bt_a2dp_stream *stream)
suspend a2dp streamer.
int bt_a2dp_stream_establish(struct bt_a2dp_stream *stream)
establish a2dp streamer.
uint32_t bt_a2dp_get_mtu(struct bt_a2dp_stream *stream)
get the stream l2cap mtu
bt_a2dp_codec_type
Codec Type.
Definition a2dp.h:293
@ BT_A2DP_MPEG1
Codec MPEG-1.
Definition a2dp.h:297
@ BT_A2DP_ATRAC
Codec ATRAC.
Definition a2dp.h:301
@ BT_A2DP_SBC
Codec SBC.
Definition a2dp.h:295
@ BT_A2DP_VENDOR
Codec Non-A2DP.
Definition a2dp.h:303
@ BT_A2DP_MPEG2
Codec MPEG-2.
Definition a2dp.h:299
Audio/Video Distribution Transport Protocol header.
Bluetooth subsystem core APIs.
Bluetooth L2CAP handling.
ssize_t recv(int sock, void *buf, size_t max_len, int flags)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
The connecting callback.
Definition a2dp.h:397
int(* start_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code)
Stream start request callback.
Definition a2dp.h:516
void(* config_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_config() and bt_a2dp_stream_reconfig()
Definition a2dp.h:457
void(* start_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_start()
Definition a2dp.h:525
void(* suspend_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_suspend()
Definition a2dp.h:547
int(* suspend_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code)
Stream suspend request callback.
Definition a2dp.h:538
void(* disconnected)(struct bt_a2dp *a2dp)
A a2dp connection has been disconnected.
Definition a2dp.h:416
int(* abort_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code)
Stream abort request callback.
Definition a2dp.h:560
int(* release_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code)
Stream release request callback.
Definition a2dp.h:493
int(* config_req)(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep, struct bt_a2dp_codec_cfg *codec_cfg, struct bt_a2dp_stream **stream, uint8_t *rsp_err_code)
Endpoint config request callback.
Definition a2dp.h:432
void(* connected)(struct bt_a2dp *a2dp, int err)
A a2dp connection has been established.
Definition a2dp.h:408
void(* release_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_release()
Definition a2dp.h:503
int(* reconfig_req)(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *codec_cfg, uint8_t *rsp_err_code)
Endpoint config request callback.
Definition a2dp.h:447
int(* establish_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code)
Stream establishment request callback.
Definition a2dp.h:470
void(* abort_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_abort()
Definition a2dp.h:569
void(* establish_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code)
Callback function for bt_a2dp_stream_establish()
Definition a2dp.h:480
The endpoint configuration.
Definition a2dp.h:321
struct bt_a2dp_codec_ie * codec_config
The media codec configuration content.
Definition a2dp.h:323
codec information elements for the endpoint
Definition a2dp.h:313
uint8_t len
Length of codec_cap.
Definition a2dp.h:315
uint8_t codec_ie[(8U)]
codec information element
Definition a2dp.h:317
Definition a2dp.h:383
struct bt_a2dp_ep_info info
The discovered endpoint info that is callbacked by cb.
Definition a2dp.h:387
uint8_t sep_count
The max count of seps (stream endpoint) that can be got in this call route.
Definition a2dp.h:393
bt_a2dp_discover_ep_cb cb
discover callback
Definition a2dp.h:385
struct bt_avdtp_sep_info * seps_info
The max count of remote endpoints that can be got, it save endpoint info internally.
Definition a2dp.h:391
Definition a2dp.h:338
struct bt_avdtp_sep_info sep_info
Stream End Point Information.
Definition a2dp.h:344
struct bt_a2dp_codec_ie codec_cap
Codec capabilities, if SBC, use function of a2dp_codec_sbc.h to parse it.
Definition a2dp.h:342
uint8_t codec_type
Code Type bt_a2dp_codec_type.
Definition a2dp.h:340
Stream End Point.
Definition a2dp.h:327
struct bt_avdtp_sep sep
AVDTP Stream End Point Identifier.
Definition a2dp.h:333
struct bt_a2dp_stream * stream
Definition a2dp.h:335
uint8_t codec_type
Code Type bt_a2dp_codec_type.
Definition a2dp.h:329
struct bt_a2dp_codec_ie * codec_cap
Capabilities.
Definition a2dp.h:331
The stream endpoint related operations.
Definition a2dp.h:645
void(* configured)(struct bt_a2dp_stream *stream)
Stream configured callback.
Definition a2dp.h:653
void(* started)(struct bt_a2dp_stream *stream)
Stream start callback.
Definition a2dp.h:678
void(* established)(struct bt_a2dp_stream *stream)
Stream establishment callback.
Definition a2dp.h:661
void(* aborted)(struct bt_a2dp_stream *stream)
Stream abort callback.
Definition a2dp.h:695
void(* released)(struct bt_a2dp_stream *stream)
Stream release callback.
Definition a2dp.h:670
void(* suspended)(struct bt_a2dp_stream *stream)
Stream suspend callback.
Definition a2dp.h:686
A2DP Stream.
Definition a2dp.h:629
uint8_t remote_ep_id
remote endpoint's Stream End Point ID
Definition a2dp.h:635
struct bt_a2dp_ep * remote_ep
remote endpoint
Definition a2dp.h:633
struct bt_a2dp_ep * local_ep
local endpoint
Definition a2dp.h:631
struct bt_a2dp_stream_ops * ops
Audio stream operations.
Definition a2dp.h:637
struct bt_a2dp * a2dp
the a2dp connection
Definition a2dp.h:639
struct bt_a2dp_codec_ie codec_config
the stream current configuration
Definition a2dp.h:641
AVDTP stream endpoint information.
Definition avdtp.h:88
AVDTP Stream End Point.
Definition avdtp.h:124
Network buffer representation.
Definition net_buf.h:1006