Skip to content

Commit 38095f8

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: BAP: Shell: Delete uni group when all streams released
Previously we assumed only a single stream, and deleted the unicast group on the first stream released. Now we wait for all the streams to be released before deleting the group. This still assumes that all streams are initiated by us as the client, and will not work if using the BAP unicast client and server role concurrently. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 2ca438f commit 38095f8

File tree

1 file changed

+27
-11
lines changed
  • subsys/bluetooth/shell

1 file changed

+27
-11
lines changed

subsys/bluetooth/shell/bap.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,19 +1784,35 @@ static void stream_released_cb(struct bt_bap_stream *stream)
17841784
shell_print(ctx_shell, "Stream %p released\n", stream);
17851785

17861786
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
1787-
/* The current shell application only supports a single stream in
1788-
* the unicast group, so when that gets disconnected, we delete the
1789-
* unicast group so that it can be recreated when settings the QoS
1790-
*/
17911787
if (default_unicast_group != NULL) {
1792-
int err = bt_bap_unicast_group_delete(default_unicast_group);
1788+
bool group_can_be_deleted = true;
17931789

1794-
if (err != 0) {
1795-
shell_error(ctx_shell,
1796-
"Failed to delete unicast group: %d",
1797-
err);
1798-
} else {
1799-
default_unicast_group = NULL;
1790+
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
1791+
if (unicast_streams[i].stream.ep != NULL) {
1792+
struct bt_bap_ep_info ep_info;
1793+
1794+
bt_bap_ep_get_info(unicast_streams[i].stream.ep, &ep_info);
1795+
1796+
if (ep_info.state != BT_BAP_EP_STATE_CODEC_CONFIGURED &&
1797+
ep_info.state != BT_BAP_EP_STATE_IDLE) {
1798+
group_can_be_deleted = false;
1799+
break;
1800+
}
1801+
}
1802+
}
1803+
1804+
if (group_can_be_deleted) {
1805+
int err;
1806+
1807+
shell_print(ctx_shell, "All streams released, deleting group\n");
1808+
1809+
err = bt_bap_unicast_group_delete(default_unicast_group);
1810+
1811+
if (err != 0) {
1812+
shell_error(ctx_shell, "Failed to delete unicast group: %d", err);
1813+
} else {
1814+
default_unicast_group = NULL;
1815+
}
18001816
}
18011817
}
18021818
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */

0 commit comments

Comments
 (0)