Skip to content

Commit 9ecbee2

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: audio: capabilities: Remove callbacks
This removes the callbacks from capabilities. The callbacks are used for unicast server role only, while the capabilities are used for the broadcast sink role as well. Thus the callbacks can be removed as there is another bt_audio_unicast_server_cb API that is specific for unicast server role. Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 9cec058 commit 9ecbee2

File tree

6 files changed

+169
-619
lines changed

6 files changed

+169
-619
lines changed

include/zephyr/bluetooth/audio/capabilities.h

Lines changed: 1 addition & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -19,225 +19,12 @@ extern "C" {
1919
/* Get list of capabilities by type */
2020
sys_slist_t *bt_audio_capability_get(enum bt_audio_dir dir);
2121

22-
23-
/** @brief Audio Capability type */
24-
enum bt_audio_capability_framing {
25-
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED = 0x00,
26-
BT_AUDIO_CAPABILITY_UNFRAMED_NOT_SUPPORTED = 0x01,
27-
};
28-
29-
/**
30-
* @brief Helper to declare elements of @ref bt_audio_capability_pref
31-
*
32-
* @param _framing Framing Support
33-
* @param _phy Preferred Target PHY
34-
* @param _rtn Preferred Retransmission number
35-
* @param _latency Preferred Maximum Transport Latency (msec)
36-
* @param _pd_min Minimum Presentation Delay (usec)
37-
* @param _pd_max Maximum Presentation Delay (usec)
38-
* @param _pref_pd_min Preferred Minimum Presentation Delay (usec)
39-
* @param _pref_pd_max Preferred Maximum Presentation Delay (usec)
40-
*/
41-
#define BT_AUDIO_CAPABILITY_PREF(_framing, _phy, _rtn, _latency, _pd_min, \
42-
_pd_max, _pref_pd_min, _pref_pd_max) \
43-
{ \
44-
.framing = _framing, \
45-
.phy = _phy, \
46-
.rtn = _rtn, \
47-
.latency = _latency, \
48-
.pd_min = _pd_min, \
49-
.pd_max = _pd_max, \
50-
.pref_pd_min = _pref_pd_min, \
51-
.pref_pd_max = _pref_pd_max, \
52-
}
53-
54-
/** @brief Audio Capability Preference structure. */
55-
struct bt_audio_capability_pref {
56-
/** @brief Framing support value
57-
*
58-
* Unlike the other fields, this is not a preference but whether
59-
* the capability supports unframed ISOAL PDUs.
60-
*
61-
* Possible values: BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED and
62-
* BT_AUDIO_CAPABILITY_UNFRAMED_NOT_SUPPORTED.
63-
*/
64-
uint8_t framing;
65-
66-
/** Preferred PHY */
67-
uint8_t phy;
68-
69-
/** Preferred Retransmission Number */
70-
uint8_t rtn;
71-
72-
/** Preferred Transport Latency in ms */
73-
uint16_t latency;
74-
75-
/** @brief Minimum Presentation Delay in us
76-
*
77-
* Unlike the other fields, this is not a preference but a minimum
78-
* requirement.
79-
*/
80-
uint32_t pd_min;
81-
82-
/** @brief Maximum Presentation Delay in us
83-
*
84-
* Unlike the other fields, this is not a preference but a maximum
85-
* requirement.
86-
*/
87-
uint32_t pd_max;
88-
89-
/** @brief Preferred minimum Presentation Delay in us*/
90-
uint32_t pref_pd_min;
91-
92-
/** @brief Preferred maximum Presentation Delay in us */
93-
uint32_t pref_pd_max;
94-
};
95-
96-
struct bt_audio_capability; /* Handle circular dependency */
97-
98-
/** @brief Capability operations structure.
99-
*
100-
* These are only used for unicast streams and broadcast sink streams.
101-
*/
102-
struct bt_audio_capability_ops {
103-
/** @brief Capability config callback
104-
*
105-
* Config callback is called whenever a new Audio Stream needs to be
106-
* allocated.
107-
*
108-
* @param conn Connection object
109-
* @param ep Remote Audio Endpoint being configured
110-
* @param dir Direction of the endpoint.
111-
* @param cap Local Audio Capability being configured
112-
* @param codec Codec configuration
113-
*
114-
* @return Allocated Audio Stream object or NULL in case of error.
115-
*/
116-
struct bt_audio_stream *(*config)(struct bt_conn *conn,
117-
struct bt_audio_ep *ep,
118-
enum bt_audio_dir dir,
119-
struct bt_audio_capability *cap,
120-
struct bt_codec *codec);
121-
122-
/** @brief Capability reconfig callback
123-
*
124-
* Reconfig callback is called whenever an Audio Stream needs to be
125-
* reconfigured with different codec configuration.
126-
*
127-
* @param stream Stream object being reconfigured.
128-
* @param cap Local Audio Capability being reconfigured
129-
* @param codec Codec configuration
130-
*
131-
* @return 0 in case of success or negative value in case of error.
132-
*/
133-
int (*reconfig)(struct bt_audio_stream *stream,
134-
struct bt_audio_capability *cap,
135-
struct bt_codec *codec);
136-
137-
/** @brief Capability QoS callback
138-
*
139-
* QoS callback is called whenever an Audio Stream Quality of
140-
* Service needs to be configured.
141-
*
142-
* @param stream Stream object being reconfigured.
143-
* @param QoS Quality of Service configuration
144-
*
145-
* @return 0 in case of success or negative value in case of error.
146-
*/
147-
int (*qos)(struct bt_audio_stream *stream, struct bt_codec_qos *qos);
148-
149-
/** @brief Capability Enable callback
150-
*
151-
* Enable callback is called whenever an Audio Stream is about to be
152-
* enabled.
153-
*
154-
* @param stream Stream object being enabled.
155-
* @param meta_count Number of metadata entries
156-
* @param meta Metadata entries
157-
*
158-
* @return 0 in case of success or negative value in case of error.
159-
*/
160-
int (*enable)(struct bt_audio_stream *stream,
161-
struct bt_codec_data *meta,
162-
size_t meta_count);
163-
164-
/** @brief Capability Start callback
165-
*
166-
* Start callback is called whenever an Audio Stream is about to
167-
* start streaming.
168-
*
169-
* @param stream Stream object.
170-
*
171-
* @return 0 in case of success or negative value in case of error.
172-
*/
173-
int (*start)(struct bt_audio_stream *stream);
174-
175-
/** @brief Capability Metadata callback
176-
*
177-
* Metadata callback is called whenever an Audio Stream needs to
178-
* update its metadata.
179-
*
180-
* @param stream Stream object.
181-
* @param meta_count Number of metadata entries
182-
* @param meta Metadata entries
183-
*
184-
* @return 0 in case of success or negative value in case of error.
185-
*/
186-
int (*metadata)(struct bt_audio_stream *stream,
187-
struct bt_codec_data *meta,
188-
size_t meta_count);
189-
190-
/** @brief Capability Disable callback
191-
*
192-
* Disable callback is called whenever an Audio Stream is about to be
193-
* disabled.
194-
*
195-
* @param stream Stream object being disabled.
196-
*
197-
* @return 0 in case of success or negative value in case of error.
198-
*/
199-
int (*disable)(struct bt_audio_stream *stream);
200-
201-
/** @brief Capability Stop callback
202-
*
203-
* Stop callback is called whenever an Audio Stream is about to
204-
* stop streaming.
205-
*
206-
* @param stream Stream object.
207-
*
208-
* @return 0 in case of success or negative value in case of error.
209-
*/
210-
int (*stop)(struct bt_audio_stream *stream);
211-
212-
/** @brief Capability release callback
213-
*
214-
* Release callback is called whenever a new Audio Stream needs to be
215-
* deallocated.
216-
*
217-
* @param stream Stream object.
218-
*
219-
* @return 0 in case of success or negative value in case of error.
220-
*/
221-
int (*release)(struct bt_audio_stream *stream);
222-
};
223-
224-
/** @brief Audio Capability structure.
225-
*
226-
* Audio Capability represents a Local Codec including its preferrable
227-
* Quality of service.
228-
*
229-
*/
22+
/** @brief Audio Capability structure. */
23023
struct bt_audio_capability {
23124
/** Capability direction */
23225
enum bt_audio_dir dir;
23326
/** Capability codec reference */
23427
struct bt_codec *codec;
235-
#if defined(CONFIG_BT_AUDIO_UNICAST_SERVER)
236-
/** Capability preferences */
237-
struct bt_audio_capability_pref pref;
238-
/** Capability operations reference */
239-
struct bt_audio_capability_ops *ops;
240-
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER */
24128

24229
/* Internally used list node */
24330
sys_snode_t _node;

samples/bluetooth/hap_ha/src/bap_unicast_sr.c

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static struct bt_audio_source {
3535
} source_streams[CONFIG_BT_ASCS_ASE_SRC_COUNT];
3636
static size_t configured_source_stream_count;
3737

38+
static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02,
39+
10, 20000, 40000, 20000, 40000);
40+
3841
static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream)
3942
{
4043
for (size_t i = 0U; i < configured_source_stream_count; i++) {
@@ -98,7 +101,7 @@ static void print_codec(const struct bt_codec *codec)
98101
}
99102
}
100103

101-
static void print_qos(struct bt_codec_qos *qos)
104+
static void print_qos(const struct bt_codec_qos *qos)
102105
{
103106
printk("QoS: interval %u framing 0x%02x phy 0x%02x sdu %u "
104107
"rtn %u latency %u pd %u\n",
@@ -170,45 +173,57 @@ static void audio_timer_timeout(struct k_work *work)
170173
}
171174
}
172175

173-
static struct bt_audio_stream *lc3_config(struct bt_conn *conn, struct bt_audio_ep *ep,
174-
enum bt_audio_dir dir, struct bt_audio_capability *cap,
175-
struct bt_codec *codec)
176+
static struct bt_audio_stream *stream_alloc(void)
176177
{
177-
printk("ASE Codec Config: conn %p ep %p dir %u, cap %p\n",
178-
conn, ep, dir, cap);
179-
180-
print_codec(codec);
181-
182178
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
183179
struct bt_audio_stream *stream = &streams[i];
184180

185181
if (!stream->conn) {
186-
printk("ASE Codec Config stream %p\n", stream);
187-
if (dir == BT_AUDIO_DIR_SOURCE) {
188-
source_streams[configured_source_stream_count++].stream = stream;
189-
}
190-
191182
return stream;
192183
}
193184
}
194185

195-
printk("No streams available\n");
196-
197186
return NULL;
198187
}
199188

200-
static int lc3_reconfig(struct bt_audio_stream *stream, struct bt_audio_capability *cap,
201-
struct bt_codec *codec)
189+
static int lc3_config(struct bt_conn *conn, const struct bt_audio_ep *ep, enum bt_audio_dir dir,
190+
const struct bt_codec *codec, struct bt_audio_stream **stream,
191+
struct bt_codec_qos_pref *const pref)
192+
{
193+
printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir);
194+
195+
print_codec(codec);
196+
197+
*stream = stream_alloc();
198+
if (*stream == NULL) {
199+
printk("No streams available\n");
200+
201+
return -ENOMEM;
202+
}
203+
204+
printk("ASE Codec Config stream %p\n", *stream);
205+
206+
if (dir == BT_AUDIO_DIR_SOURCE) {
207+
source_streams[configured_source_stream_count++].stream = *stream;
208+
}
209+
210+
*pref = qos_pref;
211+
212+
return 0;
213+
}
214+
215+
static int lc3_reconfig(struct bt_audio_stream *stream, enum bt_audio_dir dir,
216+
const struct bt_codec *codec, struct bt_codec_qos_pref *const pref)
202217
{
203-
printk("ASE Codec Reconfig: stream %p cap %p\n", stream, cap);
218+
printk("ASE Codec Reconfig: stream %p\n", stream);
204219

205220
print_codec(codec);
206221

207222
/* We only support one QoS at the moment, reject changes */
208223
return -ENOEXEC;
209224
}
210225

211-
static int lc3_qos(struct bt_audio_stream *stream, struct bt_codec_qos *qos)
226+
static int lc3_qos(struct bt_audio_stream *stream, const struct bt_codec_qos *qos)
212227
{
213228
printk("QoS: stream %p qos %p\n", stream, qos);
214229

@@ -217,7 +232,7 @@ static int lc3_qos(struct bt_audio_stream *stream, struct bt_codec_qos *qos)
217232
return 0;
218233
}
219234

220-
static int lc3_enable(struct bt_audio_stream *stream, struct bt_codec_data *meta,
235+
static int lc3_enable(struct bt_audio_stream *stream, const struct bt_codec_data *meta,
221236
size_t meta_count)
222237
{
223238
printk("Enable: stream %p meta_count %u\n", stream, meta_count);
@@ -291,7 +306,7 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
291306
}
292307
}
293308

294-
static int lc3_metadata(struct bt_audio_stream *stream, struct bt_codec_data *meta,
309+
static int lc3_metadata(struct bt_audio_stream *stream, const struct bt_codec_data *meta,
295310
size_t meta_count)
296311
{
297312
printk("Metadata: stream %p meta_count %u\n", stream, meta_count);
@@ -328,7 +343,7 @@ static int lc3_release(struct bt_audio_stream *stream)
328343
return 0;
329344
}
330345

331-
static struct bt_audio_capability_ops lc3_ops = {
346+
static const struct bt_audio_unicast_server_cb unicast_server_cb = {
332347
.config = lc3_config,
333348
.reconfig = lc3_reconfig,
334349
.qos = lc3_qos,
@@ -399,28 +414,20 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
399414
static struct bt_audio_capability caps[] = {
400415
{
401416
.dir = BT_AUDIO_DIR_SINK,
402-
.pref = BT_AUDIO_CAPABILITY_PREF(
403-
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED,
404-
BT_GAP_LE_PHY_2M, 0x02, 10, 20000, 40000,
405-
20000, 40000),
406417
.codec = &lc3_codec,
407-
.ops = &lc3_ops,
408418
},
409419
#if defined(CONFIG_BT_ASCS_ASE_SRC)
410420
{
411421
.dir = BT_AUDIO_DIR_SOURCE,
412-
.pref = BT_AUDIO_CAPABILITY_PREF(
413-
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED,
414-
BT_GAP_LE_PHY_2M, 0x02, 10, 20000, 40000,
415-
20000, 40000),
416422
.codec = &lc3_codec,
417-
.ops = &lc3_ops,
418423
}
419424
#endif /* CONFIG_BT_ASCS_ASE_SRC */
420425
};
421426

422427
int bap_unicast_sr_init(void)
423428
{
429+
bt_audio_unicast_server_register_cb(&unicast_server_cb);
430+
424431
for (size_t i = 0; i < ARRAY_SIZE(caps); i++) {
425432
bt_audio_capability_register(&caps[i]);
426433
}

0 commit comments

Comments
 (0)