Bluetooth: Audio: Update codec_cfg_get_chan_allocation

Update the function name from codec_cfg_get_chan_allocation_val
to just codec_cfg_get_chan_allocation, and add
codec_cfg_set_chan_allocation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-09-27 14:23:11 +02:00 committed by Carles Cufí
parent a35decaf90
commit f5dd62bbec
7 changed files with 64 additions and 11 deletions

View file

@ -637,9 +637,22 @@ int bt_audio_codec_cfg_get_frame_duration_us(const struct bt_audio_codec_cfg *co
* @retval -ENODATA if not found
* @retval -EBADMSG if found value has invalid size or value
*/
int bt_audio_codec_cfg_get_chan_allocation_val(const struct bt_audio_codec_cfg *codec_cfg,
int bt_audio_codec_cfg_get_chan_allocation(const struct bt_audio_codec_cfg *codec_cfg,
enum bt_audio_location *chan_allocation);
/**
* @brief Set the channel allocation of a codec configuration.
*
* @param codec_cfg The codec configuration to set data for.
* @param chan_allocation The channel allocation to set.
*
* @retval The data_len of @p codec_cfg on success
* @retval -EINVAL if arguments are invalid
* @retval -ENOMEM if the new value could not set or added due to memory
*/
int bt_audio_codec_cfg_set_chan_allocation(struct bt_audio_codec_cfg *codec_cfg,
enum bt_audio_location chan_allocation);
/** @brief Extract frame size in octets from BT codec config
*
* The overall SDU size will be octets_per_frame * blocks_per_sdu.

View file

@ -89,7 +89,7 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
printk(" Frame Duration: %d us\n",
bt_audio_codec_cfg_get_frame_duration_us(codec_cfg));
if (bt_audio_codec_cfg_get_chan_allocation_val(codec_cfg, &chan_allocation) == 0) {
if (bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation) == 0) {
printk(" Channel allocation: 0x%x\n", chan_allocation);
}

View file

@ -78,7 +78,7 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
printk(" Frame Duration: %d us\n",
bt_audio_codec_cfg_get_frame_duration_us(codec_cfg));
if (bt_audio_codec_cfg_get_chan_allocation_val(codec_cfg, &chan_allocation) == 0) {
if (bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation) == 0) {
printk(" Channel allocation: 0x%x\n", chan_allocation);
}

View file

@ -149,7 +149,7 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
printk(" Frame Duration: %d us\n",
bt_audio_codec_cfg_get_frame_duration_us(codec_cfg));
if (bt_audio_codec_cfg_get_chan_allocation_val(codec_cfg, &chan_allocation) == 0) {
if (bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation) == 0) {
printk(" Channel allocation: 0x%x\n", chan_allocation);
}

View file

@ -322,7 +322,7 @@ int bt_audio_codec_cfg_get_frame_duration_us(const struct bt_audio_codec_cfg *co
}
}
int bt_audio_codec_cfg_get_chan_allocation_val(const struct bt_audio_codec_cfg *codec_cfg,
int bt_audio_codec_cfg_get_chan_allocation(const struct bt_audio_codec_cfg *codec_cfg,
enum bt_audio_location *chan_allocation)
{
const uint8_t *data;
@ -354,6 +354,23 @@ int bt_audio_codec_cfg_get_chan_allocation_val(const struct bt_audio_codec_cfg *
return 0;
}
int bt_audio_codec_cfg_set_chan_allocation(struct bt_audio_codec_cfg *codec_cfg,
enum bt_audio_location chan_allocation)
{
uint32_t chan_allocation_u32;
if ((chan_allocation & BT_AUDIO_LOCATION_ANY) != chan_allocation) {
LOG_DBG("Invalid chan_allocation value: 0x%08X", chan_allocation);
return -EINVAL;
}
chan_allocation_u32 = sys_cpu_to_le32((uint32_t)chan_allocation);
return bt_audio_codec_cfg_set_val(codec_cfg, BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC,
(const uint8_t *)&chan_allocation_u32,
sizeof(chan_allocation_u32));
}
int bt_audio_codec_cfg_get_octets_per_frame(const struct bt_audio_codec_cfg *codec_cfg)
{
const uint8_t *data;

View file

@ -84,7 +84,7 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_duration_us)
zassert_equal(ret, 10000u, "unexpected return value %d", ret);
}
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_val)
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation)
{
const struct bt_bap_lc3_preset preset =
BT_BAP_LC3_UNICAST_PRESET_8_1_1(BT_AUDIO_LOCATION_FRONT_LEFT,
@ -92,12 +92,35 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_val)
enum bt_audio_location chan_allocation = BT_AUDIO_LOCATION_FRONT_RIGHT;
int err;
err = bt_audio_codec_cfg_get_chan_allocation_val(&preset.codec_cfg, &chan_allocation);
err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation);
zassert_false(err, "unexpected error %d", err);
zassert_equal(chan_allocation, BT_AUDIO_LOCATION_FRONT_LEFT, "unexpected return value %d",
chan_allocation);
}
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_chan_allocation)
{
struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
enum bt_audio_location chan_allocation;
int err;
err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation);
zassert_equal(err, 0, "Unexpected return value %d", err);
zassert_equal(chan_allocation, 0x00000001, "Unexpected chan_allocation value %d",
chan_allocation);
chan_allocation = BT_AUDIO_LOCATION_FRONT_RIGHT | BT_AUDIO_LOCATION_SIDE_RIGHT |
BT_AUDIO_LOCATION_TOP_SIDE_RIGHT | BT_AUDIO_LOCATION_RIGHT_SURROUND;
err = bt_audio_codec_cfg_set_chan_allocation(&preset.codec_cfg, chan_allocation);
zassert_true(err > 0, "Unexpected return value %d", err);
err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation);
zassert_equal(err, 0, "Unexpected return value %d", err);
zassert_equal(chan_allocation, 0x8080802, "Unexpected chan_allocation value %d",
chan_allocation);
}
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_octets_per_frame)
{
const struct bt_bap_lc3_preset preset =

View file

@ -150,7 +150,7 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
LOG_DBG(" Frame Duration: %d us",
bt_audio_codec_cfg_get_frame_duration_us(codec_cfg));
if (bt_audio_codec_cfg_get_chan_allocation_val(codec_cfg, &chan_allocation) == 0) {
if (bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation) == 0) {
LOG_DBG(" Channel allocation: 0x%x", chan_allocation);
}
@ -269,7 +269,7 @@ static int validate_codec_parameters(const struct bt_audio_codec_cfg *codec_cfg)
frame_duration_us = bt_audio_codec_cfg_get_frame_duration_us(codec_cfg);
chan_allocation_err =
bt_audio_codec_cfg_get_chan_allocation_val(codec_cfg, &chan_allocation);
bt_audio_codec_cfg_get_chan_allocation(codec_cfg, &chan_allocation);
octets_per_frame = bt_audio_codec_cfg_get_octets_per_frame(codec_cfg);
frames_per_sdu = bt_audio_codec_cfg_get_frame_blocks_per_sdu(codec_cfg, true);