Skip to content

Commit

Permalink
Bluetooth: audio: capabilities: Remove redundant direction parameter
Browse files Browse the repository at this point in the history
The direction is used to identify the list to append the registered
capabilities. There is no need to keep it in the bt_audio_capabilities,
it can be provided as a function parameter instead.

Signed-off-by: Mariusz Skamra <[email protected]>
  • Loading branch information
MariuszSkamra authored and fabiobaltieri committed Oct 6, 2022
1 parent 8673fab commit 28ce0a9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 57 deletions.
8 changes: 4 additions & 4 deletions include/zephyr/bluetooth/audio/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ sys_slist_t *bt_audio_capability_get(enum bt_audio_dir dir);

/** @brief Audio Capability structure. */
struct bt_audio_capability {
/** Capability direction */
enum bt_audio_dir dir;
/** Capability codec reference */
struct bt_codec *codec;

Expand All @@ -34,21 +32,23 @@ struct bt_audio_capability {
*
* Register Audio Local Capability.
*
* @param dir Direction of the endpoint to register capability for.
* @param cap Capability structure.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_audio_capability_register(struct bt_audio_capability *cap);
int bt_audio_capability_register(enum bt_audio_dir dir, struct bt_audio_capability *cap);

/** @brief Unregister Audio Capability.
*
* Unregister Audio Local Capability.
*
* @param dir Direction of the endpoint to unregister capability for.
* @param cap Capability structure.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_audio_capability_unregister(struct bt_audio_capability *cap);
int bt_audio_capability_unregister(enum bt_audio_dir dir, struct bt_audio_capability *cap);

/** @brief Set the location for an endpoint type
*
Expand Down
3 changes: 1 addition & 2 deletions samples/bluetooth/broadcast_audio_sink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ static struct bt_audio_broadcast_sink_cb broadcast_sink_cbs = {
};

static struct bt_audio_capability capabilities = {
.dir = BT_AUDIO_DIR_SINK,
.codec = &codec,
};

Expand All @@ -165,7 +164,7 @@ static int init(void)

printk("Bluetooth initialized\n");

err = bt_audio_capability_register(&capabilities);
err = bt_audio_capability_register(BT_AUDIO_DIR_SINK, &capabilities);
if (err) {
printk("Capability register failed (err %d)\n", err);
return err;
Expand Down
23 changes: 10 additions & 13 deletions samples/bluetooth/hap_ha/src/bap_unicast_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,22 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
.disconnected = disconnected,
};

static struct bt_audio_capability caps[] = {
{
.dir = BT_AUDIO_DIR_SINK,
.codec = &lc3_codec,
},
#if defined(CONFIG_BT_ASCS_ASE_SRC)
{
.dir = BT_AUDIO_DIR_SOURCE,
.codec = &lc3_codec,
}
#endif /* CONFIG_BT_ASCS_ASE_SRC */
static struct bt_audio_capability caps_sink = {
.codec = &lc3_codec,
};

static struct bt_audio_capability caps_source = {
.codec = &lc3_codec,
};

int bap_unicast_sr_init(void)
{
bt_audio_unicast_server_register_cb(&unicast_server_cb);

for (size_t i = 0; i < ARRAY_SIZE(caps); i++) {
bt_audio_capability_register(&caps[i]);
bt_audio_capability_register(BT_AUDIO_DIR_SINK, &caps_sink);

if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SRC)) {
bt_audio_capability_register(BT_AUDIO_DIR_SOURCE, &caps_source);
}

for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
Expand Down
20 changes: 8 additions & 12 deletions samples/bluetooth/unicast_audio_server/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,12 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
.disconnected = disconnected,
};

static struct bt_audio_capability caps[] = {
{
.dir = BT_AUDIO_DIR_SINK,
.codec = &lc3_codec,
},
{
.dir = BT_AUDIO_DIR_SOURCE,
.codec = &lc3_codec,
}
static struct bt_audio_capability caps_sink = {
.codec = &lc3_codec,
};

static struct bt_audio_capability caps_source = {
.codec = &lc3_codec,
};

static int set_location(void)
Expand Down Expand Up @@ -643,9 +640,8 @@ void main(void)

bt_audio_unicast_server_register_cb(&unicast_server_cb);

for (size_t i = 0; i < ARRAY_SIZE(caps); i++) {
bt_audio_capability_register(&caps[i]);
}
bt_audio_capability_register(BT_AUDIO_DIR_SINK, &caps_sink);
bt_audio_capability_register(BT_AUDIO_DIR_SOURCE, &caps_source);

for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
bt_audio_stream_cb_register(&streams[i], &stream_ops);
Expand Down
16 changes: 8 additions & 8 deletions subsys/bluetooth/audio/capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ sys_slist_t *bt_audio_capability_get(enum bt_audio_dir dir)
}

/* Register Audio Capability */
int bt_audio_capability_register(struct bt_audio_capability *cap)
int bt_audio_capability_register(enum bt_audio_dir dir, struct bt_audio_capability *cap)
{
static bool pacs_cb_registered;
sys_slist_t *lst;
Expand All @@ -143,13 +143,13 @@ int bt_audio_capability_register(struct bt_audio_capability *cap)
return -EINVAL;
}

lst = bt_audio_capability_get(cap->dir);
lst = bt_audio_capability_get(dir);
if (!lst) {
return -EINVAL;
}

BT_DBG("cap %p dir 0x%02x codec 0x%02x codec cid 0x%04x "
"codec vid 0x%04x", cap, cap->dir, cap->codec->id,
"codec vid 0x%04x", cap, dir, cap->codec->id,
cap->codec->cid, cap->codec->vid);

if (!pacs_cb_registered) {
Expand All @@ -168,34 +168,34 @@ int bt_audio_capability_register(struct bt_audio_capability *cap)
sys_slist_append(lst, &cap->_node);

#if defined(CONFIG_BT_PACS)
bt_pacs_capabilities_changed(cap->dir);
bt_pacs_capabilities_changed(dir);
#endif /* CONFIG_BT_PACS */

return 0;
}

/* Unregister Audio Capability */
int bt_audio_capability_unregister(struct bt_audio_capability *cap)
int bt_audio_capability_unregister(enum bt_audio_dir dir, struct bt_audio_capability *cap)
{
sys_slist_t *lst;

if (!cap) {
return -EINVAL;
}

lst = bt_audio_capability_get(cap->dir);
lst = bt_audio_capability_get(dir);
if (!lst) {
return -EINVAL;
}

BT_DBG("cap %p dir 0x%02x", cap, cap->dir);
BT_DBG("cap %p dir 0x%02x", cap, dir);

if (!sys_slist_find_and_remove(lst, &cap->_node)) {
return -ENOENT;
}

#if defined(CONFIG_BT_PACS)
bt_pacs_capabilities_changed(cap->dir);
bt_pacs_capabilities_changed(dir);
#endif /* CONFIG_BT_PACS */

return 0;
Expand Down
25 changes: 11 additions & 14 deletions subsys/bluetooth/shell/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,12 @@ static const struct bt_audio_unicast_server_cb unicast_server_cb = {
.release = lc3_release,
};

static struct bt_audio_capability caps[] = {
#if defined(CONFIG_BT_AUDIO_UNICAST_SERVER)
{
.dir = BT_AUDIO_DIR_SOURCE,
.codec = &lc3_codec,
},
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER */
{
.dir = BT_AUDIO_DIR_SINK,
.codec = &lc3_codec,
},
static struct bt_audio_capability caps_sink = {
.codec = &lc3_codec,
};

static struct bt_audio_capability caps_source = {
.codec = &lc3_codec,
};

#if defined(CONFIG_BT_AUDIO_UNICAST_CLIENT)
Expand Down Expand Up @@ -1474,9 +1469,11 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[])

if (IS_ENABLED(CONFIG_BT_AUDIO_UNICAST_SERVER) ||
IS_ENABLED(CONFIG_BT_AUDIO_BROADCAST_SINK)) {
for (i = 0; i < ARRAY_SIZE(caps); i++) {
bt_audio_capability_register(&caps[i]);
}
bt_audio_capability_register(BT_AUDIO_DIR_SINK, &caps_sink);
}

if (IS_ENABLED(CONFIG_BT_AUDIO_UNICAST_SERVER)) {
bt_audio_capability_register(BT_AUDIO_DIR_SOURCE, &caps_source);
}

if (IS_ENABLED(CONFIG_BT_AUDIO_CAPABILITY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ static struct bt_audio_broadcast_sink_cb broadcast_sink_cbs = {
};

static struct bt_audio_capability capabilities = {
.dir = BT_AUDIO_DIR_SINK,
.codec = &preset_16_2_1.codec,
};

Expand Down Expand Up @@ -172,7 +171,7 @@ static int init(void)

printk("Bluetooth initialized\n");

err = bt_audio_capability_register(&capabilities);
err = bt_audio_capability_register(BT_AUDIO_DIR_SINK, &capabilities);
if (err) {
FAIL("Capability register failed (err %d)\n", err);
return err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
static void init(void)
{
static struct bt_audio_capability caps = {
.dir = BT_AUDIO_DIR_SINK,
.codec = &lc3_codec,
};
int err;
Expand All @@ -248,7 +247,7 @@ static void init(void)

bt_audio_unicast_server_register_cb(&unicast_server_cb);

err = bt_audio_capability_register(&caps);
err = bt_audio_capability_register(BT_AUDIO_DIR_SINK, &caps);
if (err != 0) {
FAIL("Failed to register capabilities: %d", err);
return;
Expand Down

0 comments on commit 28ce0a9

Please sign in to comment.