Bluetooth: Audio: Refactor bt_audio_codec_cap to flat arrays

Refactor the bt_audio_codec_cap to use flat arrays to store
metadata and codec specific capabilities.

The purpose of this is to make it easier to copy the data
between layers, but also to support non-LTV data for non-LC3
codec capabilities.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-05-18 17:37:19 +02:00 committed by Fabio Baltieri
commit aa990ae6dc
21 changed files with 356 additions and 351 deletions

View file

@ -51,8 +51,10 @@ static struct bt_bap_stream *streams_p[ARRAY_SIZE(streams)];
static struct bt_conn *broadcast_assistant_conn;
static struct bt_le_ext_adv *ext_adv;
static struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
static struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
BT_AUDIO_CODEC_LC3_FREQ_16KHZ | BT_AUDIO_CODEC_LC3_FREQ_24KHZ,
BT_AUDIO_CODEC_LC3_DURATION_10, BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 60u, 1u,
(BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
/* Create a mask for the maximum BIS we can sync to using the number of streams
* we have. We add an additional 1 since the bis indexes start from 1 and not

View file

@ -21,7 +21,7 @@ NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ASCS_ASE_SRC_COUNT,
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU),
CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL);
static struct bt_audio_codec_cap lc3_codec_cap = BT_AUDIO_CODEC_LC3(
static struct bt_audio_codec_cap lc3_codec_cap = BT_AUDIO_CODEC_CAP_LC3(
BT_AUDIO_CODEC_LC3_FREQ_16KHZ | BT_AUDIO_CODEC_LC3_FREQ_24KHZ,
BT_AUDIO_CODEC_LC3_DURATION_10, BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 60u, 1u,
(BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));

View file

@ -55,10 +55,9 @@ static struct bt_le_per_adv_sync *bcast_pa_sync;
static struct bt_bap_stream streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
struct bt_bap_stream *streams_p[ARRAY_SIZE(streams)];
static struct bt_audio_codec_cap codec = BT_AUDIO_CODEC_LC3(
BT_AUDIO_CODEC_LC3_FREQ_48KHZ,
BT_AUDIO_CODEC_LC3_DURATION_10, BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 60u, 1u,
(BT_AUDIO_CONTEXT_TYPE_MEDIA));
static struct bt_audio_codec_cap codec = BT_AUDIO_CODEC_CAP_LC3(
BT_AUDIO_CODEC_LC3_FREQ_48KHZ, BT_AUDIO_CODEC_LC3_DURATION_10,
BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 60u, 1u, (BT_AUDIO_CONTEXT_TYPE_MEDIA));
/* Create a mask for the maximum BIS we can sync to using the number of streams
* we have. We add an additional 1 since the bis indexes start from 1 and not

View file

@ -180,32 +180,43 @@ static void print_hex(const uint8_t *ptr, size_t len)
}
}
static void print_codec_capabilities(const struct bt_audio_codec_cap *codec_cap)
static void print_ltv_elem(const char *str, uint8_t type, uint8_t value_len, const uint8_t *value,
size_t cnt)
{
printk("codec_cap 0x%02x cid 0x%04x vid 0x%04x count %u\n", codec_cap->id, codec_cap->cid,
codec_cap->vid, codec_cap->data_count);
printk("%s #%zu: type 0x%02x value_len %u\n", str, cnt, type, value_len);
print_hex(value, value_len);
printk("\n");
}
for (size_t i = 0; i < codec_cap->data_count; i++) {
printk("data #%zu: type 0x%02x len %u\n", i, codec_cap->data[i].data.type,
codec_cap->data[i].data.data_len);
print_hex(codec_cap->data[i].data.data,
codec_cap->data[i].data.data_len - sizeof(codec_cap->data[i].data.type));
printk("\n");
}
static void print_ltv_array(const char *str, const uint8_t *ltv_data, size_t ltv_data_len)
{
size_t cnt = 0U;
for (size_t i = 0; i < codec_cap->meta_count; i++) {
printk("meta #%zu: type 0x%02x len %u\n", i, codec_cap->meta[i].data.type,
codec_cap->meta[i].data.data_len);
print_hex(codec_cap->meta[i].data.data,
codec_cap->meta[i].data.data_len - sizeof(codec_cap->meta[i].data.type));
printk("\n");
for (size_t i = 0U; i < ltv_data_len; i++) {
const uint8_t len = ltv_data[i++];
const uint8_t type = ltv_data[i++];
const uint8_t *value = &ltv_data[i];
const uint8_t value_len = len - sizeof(type);
print_ltv_elem(str, type, value_len, value, cnt++);
i += value_len;
}
}
static void print_remote_codec(const struct bt_audio_codec_cap *codec_cap, enum bt_audio_dir dir)
{
printk("codec_cap %p dir 0x%02x\n", codec_cap, dir);
print_codec_capabilities(codec_cap);
printk("codec id 0x%02x cid 0x%04x vid 0x%04x count %u\n", codec_cap->id, codec_cap->cid,
codec_cap->vid, codec_cap->data_len);
if (codec_cap->id == BT_AUDIO_CODEC_LC3_ID) {
print_ltv_array("data", codec_cap->data, codec_cap->data_len);
} else { /* If not LC3, we cannot assume it's LTV */
printk("data: ");
print_hex(codec_cap->data, codec_cap->data_len);
printk("\n");
}
print_ltv_array("meta", codec_cap->meta, codec_cap->meta_len);
}
static void add_remote_sink(struct bt_bap_ep *ep)

View file

@ -24,11 +24,11 @@
#define AVAILABLE_SOURCE_CONTEXT CONFIG_BT_PACS_SRC_CONTEXT
static struct bt_audio_codec_cap lc3_codec_cap =
BT_AUDIO_CODEC_LC3(BT_AUDIO_CODEC_LC3_FREQ_16KHZ | BT_AUDIO_CODEC_LC3_FREQ_32KHZ |
BT_AUDIO_CODEC_LC3_FREQ_48KHZ,
BT_AUDIO_CODEC_LC3_DURATION_7_5 | BT_AUDIO_CODEC_LC3_DURATION_10,
BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(2), 30, 155u, 1u,
(CONFIG_BT_PACS_SNK_CONTEXT | CONFIG_BT_PACS_SRC_CONTEXT));
BT_AUDIO_CODEC_CAP_LC3(BT_AUDIO_CODEC_LC3_FREQ_16KHZ | BT_AUDIO_CODEC_LC3_FREQ_32KHZ |
BT_AUDIO_CODEC_LC3_FREQ_48KHZ,
BT_AUDIO_CODEC_LC3_DURATION_7_5 | BT_AUDIO_CODEC_LC3_DURATION_10,
BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(2), 30, 155u, 1u,
(CONFIG_BT_PACS_SNK_CONTEXT | CONFIG_BT_PACS_SRC_CONTEXT));
static struct bt_conn *default_conn;
static struct bt_bap_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT];

View file

@ -353,26 +353,43 @@ static void print_hex(const uint8_t *ptr, size_t len)
}
}
static void print_ltv_elem(const char *str, uint8_t type, uint8_t value_len, const uint8_t *value,
size_t cnt)
{
printk("%s #%zu: type 0x%02x value_len %u\n", str, cnt, type, value_len);
print_hex(value, value_len);
printk("\n");
}
static void print_ltv_array(const char *str, const uint8_t *ltv_data, size_t ltv_data_len)
{
size_t cnt = 0U;
for (size_t i = 0U; i < ltv_data_len; i++) {
const uint8_t len = ltv_data[i++];
const uint8_t type = ltv_data[i++];
const uint8_t *value = &ltv_data[i];
const uint8_t value_len = len - sizeof(type);
print_ltv_elem(str, type, value_len, value, cnt++);
i += value_len;
}
}
static void print_codec_cap(const struct bt_audio_codec_cap *codec_cap)
{
printk("codec 0x%02x cid 0x%04x vid 0x%04x count %u\n", codec_cap->id, codec_cap->cid,
codec_cap->vid, codec_cap->data_count);
printk("codec id 0x%02x cid 0x%04x vid 0x%04x count %u\n", codec_cap->id, codec_cap->cid,
codec_cap->vid, codec_cap->data_len);
for (size_t i = 0; i < codec_cap->data_count; i++) {
printk("data #%zu: type 0x%02x len %u\n", i, codec_cap->data[i].data.type,
codec_cap->data[i].data.data_len);
print_hex(codec_cap->data[i].data.data,
codec_cap->data[i].data.data_len - sizeof(codec_cap->data[i].data.type));
if (codec_cap->id == BT_AUDIO_CODEC_LC3_ID) {
print_ltv_array("data", codec_cap->data, codec_cap->data_len);
} else { /* If not LC3, we cannot assume it's LTV */
printk("data: ");
print_hex(codec_cap->data, codec_cap->data_len);
printk("\n");
}
for (size_t i = 0; i < codec_cap->meta_count; i++) {
printk("meta #%zu: type 0x%02x len %u\n", i, codec_cap->meta[i].data.type,
codec_cap->meta[i].data.data_len);
print_hex(codec_cap->meta[i].data.data,
codec_cap->meta[i].data.data_len - sizeof(codec_cap->meta[i].data.type));
printk("\n");
}
print_ltv_array("meta", codec_cap->meta, codec_cap->meta_len);
}
static bool check_audio_support_and_connect(struct bt_data *data,

View file

@ -33,10 +33,10 @@ NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ASCS_ASE_SRC_COUNT,
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU),
CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL);
static struct bt_audio_codec_cap lc3_codec_cap =
BT_AUDIO_CODEC_LC3(BT_AUDIO_CODEC_LC3_FREQ_ANY, BT_AUDIO_CODEC_LC3_DURATION_10,
BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 120u, 1u,
(BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
static struct bt_audio_codec_cap lc3_codec_cap = BT_AUDIO_CODEC_CAP_LC3(
BT_AUDIO_CODEC_LC3_FREQ_ANY, BT_AUDIO_CODEC_LC3_DURATION_10,
BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 120u, 1u,
(BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
static struct bt_conn *default_conn;
static struct k_work_delayable audio_send_work;