Skip to content

Commit 384e23e

Browse files
committed
Bluetooth: CAP: Shell: Share args between modules
Instead of defining the same arguments in all 3 CAP files, we declare them in audio.h and initiate them in either the initiator or commander, depending on their use. The reason for this change, is that the CAP Handover API require several of the parameter to be globally/statically allocated, and cannot just rely on stack allocated parameters. By doing this, we can use the same argument among the CAP shell modules, while keeping the memory usage down. This has the additional postive effect that we do not allocate some of these arrays, which can be quite larger, on the stack. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 512650f commit 384e23e

File tree

4 files changed

+289
-166
lines changed

4 files changed

+289
-166
lines changed

subsys/bluetooth/audio/shell/audio.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,28 @@ extern struct named_lc3_preset default_sink_preset;
266266
extern struct named_lc3_preset default_source_preset;
267267

268268
int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *param);
269+
270+
#if defined(CONFIG_BT_CAP_INITIATOR)
271+
extern struct bt_cap_unicast_audio_start_stream_param
272+
cap_initiator_audio_start_stream_params[UNICAST_CLIENT_STREAM_COUNT];
273+
extern struct bt_cap_unicast_group_stream_param
274+
cap_initiator_unicast_group_stream_params[UNICAST_CLIENT_STREAM_COUNT];
275+
extern struct bt_cap_unicast_group_stream_pair_param
276+
cap_initiator_unicast_group_pair_params[UNICAST_CLIENT_STREAM_COUNT];
277+
extern struct bt_cap_unicast_audio_start_param cap_initiator_unicast_audio_start_param;
278+
extern struct bt_cap_unicast_group_param cap_initiator_unicast_group_param;
279+
#endif /* CONFIG_BT_CAP_INITIATOR */
269280
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */
270281
#endif /* CONFIG_BT_BAP_UNICAST */
271282

272283
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
273284
extern struct broadcast_assistant_recv_state broadcast_assistant_recv_states[CONFIG_BT_MAX_CONN];
285+
286+
#if defined(CONFIG_BT_CAP_COMMANDER)
287+
extern struct bt_cap_commander_broadcast_reception_stop_param cap_commander_reception_stop_param;
288+
extern struct bt_cap_commander_broadcast_reception_stop_member_param
289+
cap_commander_reception_stop_member_params[CONFIG_BT_MAX_CONN];
290+
#endif /* CONFIG_BT_CAP_COMMANDER */
274291
#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */
275292
#if defined(CONFIG_BT_BAP_SCAN_DELEGATOR)
276293
extern struct scan_delegator_sync_state
@@ -841,6 +858,22 @@ int cap_ac_broadcast(const struct shell *sh, size_t argc, char **argv,
841858
extern struct shell_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT];
842859
extern struct broadcast_source default_source;
843860
extern struct named_lc3_preset default_broadcast_source_preset;
861+
862+
#if defined(CONFIG_BT_CAP_INITIATOR)
863+
#define MAX_CAP_BROADCAST_STREAMS \
864+
MAX(BAP_UNICAST_AC_MAX_SRC, \
865+
COND_CODE_1(CONFIG_BT_CAP_HANDOVER, \
866+
(CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT), (0)))
867+
BUILD_ASSERT(MAX_CAP_BROADCAST_STREAMS > CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT,
868+
"CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT needs to be equal or greater to "
869+
"MAX_CAP_BROADCAST_STREAMS");
870+
871+
extern struct bt_cap_initiator_broadcast_stream_param
872+
cap_initiator_broadcast_stream_params[MAX_CAP_BROADCAST_STREAMS];
873+
874+
extern struct bt_cap_initiator_broadcast_subgroup_param cap_initiator_broadcast_subgroup_param;
875+
extern struct bt_cap_initiator_broadcast_create_param cap_initiator_broadcast_create_param;
876+
#endif /* CONFIG_BT_CAP_INITIATOR */
844877
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */
845878

846879
static inline bool print_base_subgroup_bis_cb(const struct bt_bap_base_subgroup_bis *bis,

subsys/bluetooth/audio/shell/cap_commander.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ static int cmd_cap_commander_change_microphone_gain(const struct shell *sh, size
521521
#endif /* CONFIG_BT_MICP_MIC_CTLR */
522522

523523
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
524+
struct bt_cap_commander_broadcast_reception_stop_param cap_commander_reception_stop_param;
525+
struct bt_cap_commander_broadcast_reception_stop_member_param
526+
cap_commander_reception_stop_member_params[CONFIG_BT_MAX_CONN];
527+
524528
static int cmd_cap_commander_broadcast_reception_start(const struct shell *sh, size_t argc,
525529
char *argv[])
526530
{
@@ -693,14 +697,7 @@ static int cmd_cap_commander_broadcast_reception_start(const struct shell *sh, s
693697
static int cmd_cap_commander_broadcast_reception_stop(const struct shell *sh, size_t argc,
694698
char *argv[])
695699
{
696-
struct bt_cap_commander_broadcast_reception_stop_member_param
697-
member_params[CONFIG_BT_MAX_CONN] = {0};
698700
const size_t cap_args = argc - 1; /* First argument is the command itself */
699-
struct bt_cap_commander_broadcast_reception_stop_param param = {
700-
.type = BT_CAP_SET_TYPE_AD_HOC,
701-
.param = member_params,
702-
};
703-
704701
struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0};
705702
size_t conn_cnt = 0U;
706703
int err = 0;
@@ -710,6 +707,19 @@ static int cmd_cap_commander_broadcast_reception_stop(const struct shell *sh, si
710707
return -ENOEXEC;
711708
}
712709

710+
#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE)
711+
if (default_source.handover_in_progress) {
712+
shell_error(sh, "Handover already in progress");
713+
714+
return -ENOEXEC;
715+
}
716+
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */
717+
718+
(void)memset(&cap_commander_reception_stop_param, 0,
719+
sizeof((cap_commander_reception_stop_param)));
720+
(void)memset(&cap_commander_reception_stop_member_params, 0,
721+
sizeof((cap_commander_reception_stop_member_params)));
722+
713723
/* TODO: Add support for coordinated sets */
714724

715725
/* Populate the array of connected connections */
@@ -748,15 +758,19 @@ static int cmd_cap_commander_broadcast_reception_stop(const struct shell *sh, si
748758
}
749759

750760
/* TODO: Allow for multiple subgroups */
751-
member_params[i].num_subgroups = 1;
752-
member_params[i].src_id = src_id;
753-
member_params[i].member.member = connected_conns[i];
754-
param.count++;
761+
cap_commander_reception_stop_member_params[i].num_subgroups = 1;
762+
cap_commander_reception_stop_member_params[i].src_id = src_id;
763+
cap_commander_reception_stop_member_params[i].member.member = connected_conns[i];
764+
cap_commander_reception_stop_param.count++;
755765
}
756766

757-
shell_print(sh, "Stopping broadcast reception on %zu connection(s)", param.count);
767+
cap_commander_reception_stop_param.type = BT_CAP_SET_TYPE_AD_HOC;
768+
cap_commander_reception_stop_param.param = cap_commander_reception_stop_member_params;
769+
770+
shell_print(sh, "Stopping broadcast reception on %zu connection(s)",
771+
cap_commander_reception_stop_param.count);
758772

759-
err = bt_cap_commander_broadcast_reception_stop(&param);
773+
err = bt_cap_commander_broadcast_reception_stop(&cap_commander_reception_stop_param);
760774
if (err != 0) {
761775
shell_print(sh, "Failed to initiate broadcast reception stop: %d", err);
762776

0 commit comments

Comments
 (0)