Skip to content

Commit

Permalink
tests: Bluetooth: Audio: Add testing of source stream
Browse files Browse the repository at this point in the history
Expand the CAP tests to also discover and setup a source
stream, so that the CAP procedures are run on multiple
streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley committed Jul 4, 2023
1 parent d534ba3 commit 1e99990
Showing 1 changed file with 52 additions and 25 deletions.
77 changes: 52 additions & 25 deletions tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ extern enum bst_result_t bst_result;
static struct bt_bap_lc3_preset unicast_preset_16_2_1 = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_cap_stream unicast_client_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
static struct bt_cap_stream unicast_client_sink_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
static struct bt_cap_stream
unicast_client_source_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT];
static struct bt_bap_ep
*unicast_sink_eps[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
static struct bt_bap_ep
Expand Down Expand Up @@ -351,8 +353,12 @@ static void init(void)
return;
}

for (size_t i = 0; i < ARRAY_SIZE(unicast_client_streams); i++) {
bt_cap_stream_ops_register(&unicast_client_streams[i], &unicast_stream_ops);
for (size_t i = 0; i < ARRAY_SIZE(unicast_client_sink_streams); i++) {
bt_cap_stream_ops_register(&unicast_client_sink_streams[i], &unicast_stream_ops);
}

for (size_t i = 0; i < ARRAY_SIZE(unicast_client_source_streams); i++) {
bt_cap_stream_ops_register(&unicast_client_source_streams[i], &unicast_stream_ops);
}
}

Expand Down Expand Up @@ -506,15 +512,18 @@ static void discover_cas(struct bt_conn *conn)

static void unicast_group_create(struct bt_bap_unicast_group **out_unicast_group)
{
struct bt_bap_unicast_group_stream_param group_stream_params;
struct bt_bap_unicast_group_stream_param group_source_stream_params;
struct bt_bap_unicast_group_stream_param group_sink_stream_params;
struct bt_bap_unicast_group_stream_pair_param pair_params;
struct bt_bap_unicast_group_param group_param;
int err;

group_stream_params.qos = &unicast_preset_16_2_1.qos;
group_stream_params.stream = &unicast_client_streams[0].bap_stream;
pair_params.tx_param = &group_stream_params;
pair_params.rx_param = NULL;
group_sink_stream_params.qos = &unicast_preset_16_2_1.qos;
group_sink_stream_params.stream = &unicast_client_sink_streams[0].bap_stream;
group_source_stream_params.qos = &unicast_preset_16_2_1.qos;
group_source_stream_params.stream = &unicast_client_source_streams[0].bap_stream;
pair_params.tx_param = &group_sink_stream_params;
pair_params.rx_param = &group_source_stream_params;

group_param.packing = BT_ISO_PACKING_SEQUENTIAL;
group_param.params_count = 1;
Expand Down Expand Up @@ -542,7 +551,7 @@ static void unicast_audio_start_inval(struct bt_bap_unicast_group *unicast_group
valid_start_param.stream_params = &valid_stream_param;

valid_stream_param.member.member = default_conn;
valid_stream_param.stream = &unicast_client_streams[0];
valid_stream_param.stream = &unicast_client_sink_streams[0];
valid_stream_param.ep = unicast_sink_eps[bt_conn_index(default_conn)][0];
valid_stream_param.codec_cfg = &unicast_preset_16_2_1.codec_cfg;
valid_stream_param.qos = &unicast_preset_16_2_1.qos;
Expand Down Expand Up @@ -650,19 +659,25 @@ static void unicast_audio_start_inval(struct bt_bap_unicast_group *unicast_group

static void unicast_audio_start(struct bt_bap_unicast_group *unicast_group, bool wait)
{
struct bt_cap_unicast_audio_start_stream_param stream_param[1];
struct bt_cap_unicast_audio_start_stream_param stream_param[2];
struct bt_cap_unicast_audio_start_param param;
int err;

param.type = BT_CAP_SET_TYPE_AD_HOC;
param.count = 1u;
param.count = ARRAY_SIZE(stream_param);
param.stream_params = stream_param;
stream_param[0].member.member = default_conn;
stream_param[0].stream = &unicast_client_streams[0];
stream_param[0].stream = &unicast_client_sink_streams[0];
stream_param[0].ep = unicast_sink_eps[bt_conn_index(default_conn)][0];
stream_param[0].codec_cfg = &unicast_preset_16_2_1.codec_cfg;
stream_param[0].qos = &unicast_preset_16_2_1.qos;

stream_param[1].member.member = default_conn;
stream_param[1].stream = &unicast_client_source_streams[0];
stream_param[1].ep = unicast_source_eps[bt_conn_index(default_conn)][0];
stream_param[1].codec_cfg = &unicast_preset_16_2_1.codec_cfg;
stream_param[1].qos = &unicast_preset_16_2_1.qos;

UNSET_FLAG(flag_started);

err = bt_cap_initiator_unicast_audio_start(&param, unicast_group);
Expand All @@ -683,7 +698,7 @@ static void unicast_audio_update_inval(void)
struct bt_cap_unicast_audio_update_param param;
int err;

param.stream = &unicast_client_streams[0];
param.stream = &unicast_client_sink_streams[0];
param.meta = unicast_preset_16_2_1.codec_cfg.meta;
param.meta_len = unicast_preset_16_2_1.codec_cfg.meta_len;

Expand Down Expand Up @@ -713,16 +728,20 @@ static void unicast_audio_update_inval(void)

static void unicast_audio_update(void)
{
struct bt_cap_unicast_audio_update_param param;
struct bt_cap_unicast_audio_update_param param[2];
int err;

param.stream = &unicast_client_streams[0];
param.meta = unicast_preset_16_2_1.codec_cfg.meta;
param.meta_len = unicast_preset_16_2_1.codec_cfg.meta_len;
param[0].stream = &unicast_client_sink_streams[0];
param[0].meta = unicast_preset_16_2_1.codec_cfg.meta;
param[0].meta_len = unicast_preset_16_2_1.codec_cfg.meta_len;

param[1].stream = &unicast_client_source_streams[0];
param[1].meta = unicast_preset_16_2_1.codec_cfg.meta;
param[1].meta_len = unicast_preset_16_2_1.codec_cfg.meta_len;

UNSET_FLAG(flag_updated);

err = bt_cap_initiator_unicast_audio_update(&param, 1);
err = bt_cap_initiator_unicast_audio_update(param, ARRAY_SIZE(param));
if (err != 0) {
FAIL("Failed to update unicast audio: %d\n", err);
return;
Expand Down Expand Up @@ -820,6 +839,7 @@ static void test_main_cap_initiator_unicast(void)
discover_cas(default_conn);

discover_sink(default_conn);
discover_source(default_conn);

for (size_t i = 0U; i < iterations; i++) {
unicast_group_create(&unicast_group);
Expand Down Expand Up @@ -1029,20 +1049,27 @@ static int cap_initiator_ac_create_unicast_group(const struct cap_initiator_ac_p

static int set_chan_alloc(enum bt_audio_location loc, struct bt_audio_codec_cfg *codec_cfg)
{
for (size_t i = 0U; i < codec_cfg->data_count; i++) {
struct bt_audio_codec_data *data = &codec_cfg->data[i];
for (size_t i = 0U; i < codec_cfg->data_len;) {
const uint8_t len = codec_cfg->data[i++];
const uint8_t type = codec_cfg->data[i++];
const uint8_t value_len = len - sizeof(type);
uint8_t *value = &codec_cfg->data[i];

/* Overwrite the location value */
if (data->data.type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
const uint32_t loc_32 = loc;

sys_put_le32(loc_32, data->value);
sys_put_le32(loc_32, value);

break;
return 0;
}

/* Since we are incrementing i by the value_len, we don't need to increment it
* further in the `for` statement
*/
i += value_len;
}

return 0;
return -ENOENT;
}

static int cap_initiator_ac_cap_unicast_start(const struct cap_initiator_ac_param *param,
Expand Down

0 comments on commit 1e99990

Please sign in to comment.