Skip to content

Commit

Permalink
tests: Bluetooth: BAP: Add broadcast tests with VS codec
Browse files Browse the repository at this point in the history
A broadcast tests with various BASEs that use a vendor
specific (VS) codec. This tests that we support
non-LC3 codecs on both broadcast sources and sinks
in various configurations.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and kartben committed Jan 7, 2025
1 parent cd98a34 commit 892e5e1
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 21 deletions.
30 changes: 21 additions & 9 deletions tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ static bool valid_base_subgroup(const struct bt_bap_base_subgroup *subgroup)
return false;
}

if (codec_cfg.id == BT_HCI_CODING_FORMAT_VS) {
return memcmp(&codec_cfg, &vs_codec_cfg, sizeof(codec_cfg)) == 0;
}

ret = bt_audio_codec_cfg_get_freq(&codec_cfg);
if (ret >= 0) {
const int freq = bt_audio_codec_cfg_freq_to_freq_hz(ret);
Expand Down Expand Up @@ -366,10 +370,6 @@ static struct bt_le_per_adv_sync_cb bap_pa_sync_cb = {
.term = bap_pa_sync_terminated_cb,
};

static struct bt_pacs_cap cap = {
.codec_cap = &codec_cap,
};

static int pa_sync_req_cb(struct bt_conn *conn,
const struct bt_bap_scan_delegator_recv_state *recv_state,
bool past_avail, uint16_t pa_interval)
Expand Down Expand Up @@ -454,6 +454,11 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
uint8_t chan_cnt;
int ret;

if (codec_cfg->id != BT_HCI_CODING_FORMAT_LC3) {
/* We can only validate LC3 codecs */
return;
}

ret = bt_audio_codec_cfg_get_freq(codec_cfg);
if (ret >= 0) {
const int freq = bt_audio_codec_cfg_freq_to_freq_hz(ret);
Expand Down Expand Up @@ -606,6 +611,12 @@ static struct bt_bap_stream_ops stream_ops = {

static int init(void)
{
static struct bt_pacs_cap cap = {
.codec_cap = &codec_cap,
};
static struct bt_pacs_cap vs_cap = {
.codec_cap = &vs_codec_cap,
};
int err;

err = bt_enable(NULL);
Expand All @@ -622,6 +633,12 @@ static int init(void)
return err;
}

err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &vs_cap);
if (err) {
FAIL("VS capability register failed (err %d)\n", err);
return err;
}

err = bt_bap_scan_delegator_register(&scan_delegator_cbs);
if (err) {
FAIL("Scan delegator register failed (err %d)\n", err);
Expand Down Expand Up @@ -1167,11 +1184,6 @@ static void broadcast_sink_with_assistant(void)
WAIT_FOR_FLAG(flag_audio_received);
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */

/* Ensure that we also see the metadata update */
printk("Waiting for metadata update\n");
WAIT_FOR_FLAG(flag_base_metadata_updated)
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */

printk("Waiting for BIG sync terminate request\n");
WAIT_FOR_UNSET_FLAG(flag_bis_sync_requested);
test_broadcast_stop();
Expand Down
50 changes: 38 additions & 12 deletions tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
CREATE_FLAG(flag_source_started);

static struct audio_test_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT];
/* We always default to the mandatory-to-support preset_16_2_1 */
static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
static struct bt_bap_lc3_preset preset_16_1_1 = BT_BAP_LC3_BROADCAST_PRESET_16_1_1(
BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
static struct bt_audio_codec_cfg *codec_cfg = &preset_16_2_1.codec_cfg;

static uint8_t bis_codec_data[] = {
BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC,
Expand All @@ -58,8 +60,8 @@ static K_SEM_DEFINE(sem_stream_stopped, 0U, ARRAY_SIZE(broadcast_source_streams)

static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
{
const struct bt_audio_codec_cfg *codec_cfg = stream->codec_cfg;
const struct bt_audio_codec_cfg *exp_codec_cfg = &preset_16_1_1.codec_cfg;
const struct bt_audio_codec_cfg *stream_codec_cfg = stream->codec_cfg;
const struct bt_audio_codec_cfg *exp_codec_cfg = codec_cfg;
enum bt_audio_location chan_allocation;
uint8_t frames_blocks_per_sdu;
size_t min_sdu_size_required;
Expand All @@ -68,7 +70,12 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
int ret;
int exp_ret;

ret = bt_audio_codec_cfg_get_freq(codec_cfg);
if (stream_codec_cfg->id != BT_HCI_CODING_FORMAT_LC3) {
/* We can only validate LC3 codecs */
return;
}

ret = bt_audio_codec_cfg_get_freq(stream_codec_cfg);
exp_ret = bt_audio_codec_cfg_get_freq(exp_codec_cfg);
if (ret >= 0) {
const int freq = bt_audio_codec_cfg_freq_to_freq_hz(ret);
Expand All @@ -85,7 +92,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
return;
}

ret = bt_audio_codec_cfg_get_frame_dur(codec_cfg);
ret = bt_audio_codec_cfg_get_frame_dur(stream_codec_cfg);
exp_ret = bt_audio_codec_cfg_get_frame_dur(exp_codec_cfg);
if (ret >= 0) {
const int frm_dur_us = bt_audio_codec_cfg_frame_dur_to_frame_dur_us(ret);
Expand All @@ -105,7 +112,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
/* The broadcast source sets the channel allocation in the BIS to
* BT_AUDIO_LOCATION_FRONT_CENTER
*/
ret = bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation, true);
ret = bt_audio_codec_cfg_get_chan_allocation(stream_codec_cfg, &chan_allocation, true);
if (ret == 0) {
if (chan_allocation != BT_AUDIO_LOCATION_FRONT_CENTER) {
FAIL("Unexpected channel allocation: 0x%08X", chan_allocation);
Expand All @@ -126,7 +133,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
return;
}

ret = bt_audio_codec_cfg_get_octets_per_frame(codec_cfg);
ret = bt_audio_codec_cfg_get_octets_per_frame(stream_codec_cfg);
if (ret > 0) {
octets_per_frame = (uint16_t)ret;
} else {
Expand All @@ -142,7 +149,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
return;
}

ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(codec_cfg, true);
ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(stream_codec_cfg, true);
if (ret > 0) {
frames_blocks_per_sdu = (uint8_t)ret;
} else {
Expand Down Expand Up @@ -283,7 +290,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
subgroup_params[i].codec_cfg = codec_cfg;
}

create_param.params_count = subgroup_cnt_arg;
Expand Down Expand Up @@ -399,14 +406,17 @@ static int setup_extended_adv(struct bt_bap_broadcast_source *source, struct bt_
return 0;
}

static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *source)
static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *source,
struct bt_le_ext_adv *adv)
{
struct bt_bap_broadcast_source_stream_param
stream_params[ARRAY_SIZE(broadcast_source_streams)];
struct bt_bap_broadcast_source_subgroup_param
subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
struct bt_bap_broadcast_source_param reconfig_param;
NET_BUF_SIMPLE_DEFINE(base_buf, 128);
struct bt_data per_ad;
int err;

for (size_t i = 0; i < stream_cnt; i++) {
Expand All @@ -416,15 +426,16 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
stream_params[i].data = bis_codec_data;
}

codec_cfg = &preset_16_1_1.codec_cfg;
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
subgroup_params[i].codec_cfg = codec_cfg; /* update the cfg 16_1_1 */
}

reconfig_param.params_count = subgroup_cnt_arg;
reconfig_param.params = subgroup_params;
reconfig_param.qos = &preset_16_1_1.qos;
reconfig_param.qos = &preset_16_1_1.qos; /* update the QoS from 16_2_1 to 16_1_1 */
reconfig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
reconfig_param.encryption = false;

Expand All @@ -440,6 +451,17 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc

test_stream->tx_sdu_size = preset_16_1_1.qos.sdu;
}

/* Update the BASE */
test_broadcast_source_get_base(source, &base_buf);

per_ad.type = BT_DATA_SVC_DATA16;
per_ad.data_len = base_buf.len;
per_ad.data = base_buf.data;
err = bt_le_per_adv_set_data(adv, &per_ad, 1);
if (err != 0) {
FAIL("Failed to set periodic advertising data: %d\n", err);
}
}

static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
Expand Down Expand Up @@ -653,7 +675,7 @@ static void test_main_update(void)
return;
}

test_broadcast_source_reconfig(source);
test_broadcast_source_reconfig(source, adv);

test_broadcast_source_start(source, adv);

Expand Down Expand Up @@ -749,6 +771,10 @@ static void test_args(int argc, char *argv[])
FAIL("Invalid number of streams per subgroup: %lu\n",
streams_per_subgroup_cnt_arg);
}
} else if (strcmp(arg, "vs_codec") == 0) {
codec_cfg = &vs_codec_cfg;
} else if (strcmp(arg, "lc3_codec") == 0) {
codec_cfg = &preset_16_2_1.codec_cfg;
} else {
FAIL("Invalid arg: %s\n", arg);
}
Expand Down
38 changes: 38 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,49 @@
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/printk.h>

#include "bap_common.h"

#define VS_CODEC_CID 0x05F1 /* Linux foundation*/
#define VS_CODEC_VID 0x1234 /* any value*/

/* Vendor specific codec configuration with some random values */
struct bt_audio_codec_cfg vs_codec_cfg = {
.path_id = BT_ISO_DATA_PATH_HCI,
.ctlr_transcode = false,
.id = BT_HCI_CODING_FORMAT_VS,
.cid = VS_CODEC_CID,
.vid = VS_CODEC_VID,
#if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0
.data_len = 5,
.data = {1, 2, 3, 4, 5}, /* any value */
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
#if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0
.meta_len = 5,
.meta = {10, 20, 30, 40, 50}, /* any value */
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */
};

/* Vendor specific codec configuration with some random values */
struct bt_audio_codec_cap vs_codec_cap = {
.path_id = BT_ISO_DATA_PATH_HCI,
.ctlr_transcode = false,
.id = BT_HCI_CODING_FORMAT_VS,
.cid = VS_CODEC_CID,
.vid = VS_CODEC_VID,
#if CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0
.data_len = 5,
.data = {1, 2, 3, 4, 5}, /* any value */
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
#if CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE > 0
.meta_len = 5,
.meta = {10, 20, 30, 40, 50}, /* any value */
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */
};

void print_hex(const uint8_t *ptr, size_t len)
{
while (len-- != 0) {
Expand Down
3 changes: 3 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct named_lc3_preset {
struct bt_bap_lc3_preset preset;
};

extern struct bt_audio_codec_cfg vs_codec_cfg;
extern struct bt_audio_codec_cap vs_codec_cap;

void print_hex(const uint8_t *ptr, size_t len);
void print_codec_cap(const struct bt_audio_codec_cap *codec_cap);
void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0

VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=120

source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

cd ${BSIM_OUT_PATH}/bin

SIMULATION_ID="bap_broadcast_audio_vs_multiple_group_multiple_bis"

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source \
-RealEncryption=1 -rs=23 -D=2 -argstest subgroup_cnt 2 streams_per_subgroup_cnt 2 vs_codec

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=broadcast_sink \
-RealEncryption=1 -rs=27 -D=2

# Simulation time should be larger than the WAIT_TIME in common.h
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
-D=2 -sim_length=60e6 $@

wait_for_background_jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0

VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=120

source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

cd ${BSIM_OUT_PATH}/bin

SIMULATION_ID="bap_broadcast_audio_vs_multiple_group_single_bis"

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source \
-RealEncryption=1 -rs=23 -D=2 -argstest subgroup_cnt 2 streams_per_subgroup_cnt 1 vs_codec

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=broadcast_sink \
-RealEncryption=1 -rs=27 -D=2

# Simulation time should be larger than the WAIT_TIME in common.h
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
-D=2 -sim_length=60e6 $@

wait_for_background_jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0

VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=120

source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

cd ${BSIM_OUT_PATH}/bin

SIMULATION_ID="bap_broadcast_audio_vs_single_group_multiple_bis"

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source \
-RealEncryption=1 -rs=23 -D=2 -argstest subgroup_cnt 1 streams_per_subgroup_cnt 2 vs_codec

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=broadcast_sink \
-RealEncryption=1 -rs=27 -D=2

# Simulation time should be larger than the WAIT_TIME in common.h
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
-D=2 -sim_length=60e6 $@

wait_for_background_jobs
Loading

0 comments on commit 892e5e1

Please sign in to comment.