Skip to content

Commit ab013ff

Browse files
committed
Bluetooth: CAP: Shell: Change to use default_unicast_group
Use default_unicast_group everywhere in the CAP shell, and mark all creation of it as default_unicast_group.is_cap = true. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 079df1c commit ab013ff

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

subsys/bluetooth/audio/shell/cap_initiator.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#define UNICAST_SINK_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0)
4343
#define UNICAST_SRC_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0)
4444

45-
struct bt_cap_unicast_group *cap_unicast_group;
46-
4745
#define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams)
4846

4947
static void cap_discover_cb(struct bt_conn *conn, int err,
@@ -90,13 +88,14 @@ static void unicast_stop_complete_cb(int err, struct bt_conn *conn)
9088
} else {
9189
bt_shell_print("Unicast stop completed");
9290

93-
if (cap_unicast_group != NULL) {
94-
err = bt_cap_unicast_group_delete(cap_unicast_group);
91+
if (default_unicast_group.is_cap && default_unicast_group.cap_group != NULL) {
92+
err = bt_cap_unicast_group_delete(default_unicast_group.cap_group);
9593
if (err != 0) {
9694
bt_shell_error("Failed to delete unicast group %p: %d",
97-
cap_unicast_group, err);
95+
default_unicast_group.cap_group, err);
9896
} else {
99-
cap_unicast_group = NULL;
97+
default_unicast_group.cap_group = NULL;
98+
default_unicast_group.is_cap = false;
10099
}
101100
}
102101
}
@@ -320,13 +319,15 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc,
320319
group_param.params_count = pair_cnt;
321320
group_param.params = pair_params;
322321

323-
if (cap_unicast_group == NULL) {
324-
err = bt_cap_unicast_group_create(&group_param, &cap_unicast_group);
322+
if (default_unicast_group.cap_group == NULL) {
323+
err = bt_cap_unicast_group_create(&group_param, &default_unicast_group.cap_group);
325324
if (err != 0) {
326325
shell_print(sh, "Failed to create group: %d", err);
327326

328327
return -ENOEXEC;
329328
}
329+
330+
default_unicast_group.is_cap = true;
330331
}
331332

332333
shell_print(sh, "Starting %zu streams", start_param.count);
@@ -754,6 +755,7 @@ static int cap_ac_create_unicast_group(const struct cap_unicast_ac_param *param,
754755
size_t snk_stream_cnt = 0U;
755756
size_t src_stream_cnt = 0U;
756757
size_t pair_cnt = 0U;
758+
int err;
757759

758760
for (size_t i = 0U; i < snk_cnt; i++) {
759761
snk_qos[i] = &snk_uni_streams[i]->qos;
@@ -803,7 +805,12 @@ static int cap_ac_create_unicast_group(const struct cap_unicast_ac_param *param,
803805
group_param.params = pair_params;
804806
group_param.params_count = pair_cnt;
805807

806-
return bt_cap_unicast_group_create(&group_param, &default_unicast_group.cap_group);
808+
err = bt_cap_unicast_group_create(&group_param, &default_unicast_group.cap_group);
809+
if (err == 0) {
810+
default_unicast_group.is_cap = true;
811+
}
812+
813+
return err;
807814
}
808815

809816
int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *param)
@@ -817,7 +824,7 @@ int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *pa
817824
size_t src_cnt = 0;
818825
int err;
819826

820-
if (cap_unicast_group != NULL) {
827+
if (default_unicast_group.cap_group != NULL) {
821828
shell_error(sh, "Unicast Group already exist, please delete first");
822829
return -ENOEXEC;
823830
}
@@ -909,11 +916,12 @@ int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *pa
909916
if (err != 0) {
910917
shell_error(sh, "Failed to start unicast audio: %d", err);
911918

912-
err = bt_cap_unicast_group_delete(cap_unicast_group);
919+
err = bt_cap_unicast_group_delete(default_unicast_group.cap_group);
913920
if (err != 0) {
914921
shell_error(sh, "Failed to delete group: %d", err);
915922
} else {
916-
cap_unicast_group = NULL;
923+
default_unicast_group.cap_group = NULL;
924+
default_unicast_group.is_cap = false;
917925
}
918926

919927
return -ENOEXEC;

0 commit comments

Comments
 (0)