Bluetooth: Audio: Refactor codec_cfg_get_freq
Refactor the codec_cfg_get_freq function to return the assigned numbers value, instead of a converted value, but with support for converting the value. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
551b9afe11
commit
85bb2624bc
10 changed files with 449 additions and 125 deletions
|
@ -75,13 +75,18 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
|
|||
codec_cfg->vid, codec_cfg->data_len);
|
||||
|
||||
if (codec_cfg->id == BT_HCI_CODING_FORMAT_LC3) {
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
enum bt_audio_location chan_allocation;
|
||||
int ret;
|
||||
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
bt_audio_data_parse(codec_cfg->data, codec_cfg->data_len, print_cb, "data");
|
||||
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_get_freq(codec_cfg));
|
||||
ret = bt_audio_codec_cfg_get_freq(codec_cfg);
|
||||
if (ret > 0) {
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_freq_to_freq_hz(ret));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -64,13 +64,18 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
|
|||
codec_cfg->vid, codec_cfg->data_len);
|
||||
|
||||
if (codec_cfg->id == BT_HCI_CODING_FORMAT_LC3) {
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
enum bt_audio_location chan_allocation;
|
||||
int ret;
|
||||
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
bt_audio_data_parse(codec_cfg->data, codec_cfg->data_len, print_cb, "data");
|
||||
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_get_freq(codec_cfg));
|
||||
ret = bt_audio_codec_cfg_get_freq(codec_cfg);
|
||||
if (ret > 0) {
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_freq_to_freq_hz(ret));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -221,12 +221,19 @@ static void lc3_audio_timer_timeout(struct k_work *work)
|
|||
}
|
||||
}
|
||||
|
||||
static void init_lc3(void)
|
||||
static int init_lc3(void)
|
||||
{
|
||||
const struct bt_audio_codec_cfg *codec_cfg = &codec_configuration.codec_cfg;
|
||||
unsigned int num_samples;
|
||||
int ret;
|
||||
|
||||
ret = bt_audio_codec_cfg_get_freq(codec_cfg);
|
||||
if (ret > 0) {
|
||||
freq_hz = bt_audio_codec_cfg_freq_to_freq_hz(ret);
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
|
||||
freq_hz = bt_audio_codec_cfg_get_freq(codec_cfg);
|
||||
frame_duration_us = bt_audio_codec_cfg_get_frame_duration_us(codec_cfg);
|
||||
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);
|
||||
|
@ -271,7 +278,7 @@ static void init_lc3(void)
|
|||
|
||||
#else
|
||||
|
||||
#define init_lc3(...)
|
||||
#define init_lc3(...) 0
|
||||
|
||||
/**
|
||||
* @brief Send audio data on timeout
|
||||
|
@ -979,7 +986,11 @@ static int set_stream_qos(void)
|
|||
static int enable_streams(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_LIBLC3)) {
|
||||
init_lc3();
|
||||
int err = init_lc3();
|
||||
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0U; i < configured_stream_count; i++) {
|
||||
|
|
|
@ -135,13 +135,18 @@ static void print_codec_cfg(const struct bt_audio_codec_cfg *codec_cfg)
|
|||
codec_cfg->vid, codec_cfg->data_len);
|
||||
|
||||
if (codec_cfg->id == BT_HCI_CODING_FORMAT_LC3) {
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
enum bt_audio_location chan_allocation;
|
||||
int ret;
|
||||
|
||||
/* LC3 uses the generic LTV format - other codecs might do as well */
|
||||
|
||||
bt_audio_data_parse(codec_cfg->data, codec_cfg->data_len, print_cb, "data");
|
||||
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_get_freq(codec_cfg));
|
||||
ret = bt_audio_codec_cfg_get_freq(codec_cfg);
|
||||
if (ret > 0) {
|
||||
printk(" Frequency: %d Hz\n", bt_audio_codec_cfg_freq_to_freq_hz(ret));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -349,15 +354,19 @@ static int lc3_enable(struct bt_bap_stream *stream, const uint8_t meta[], size_t
|
|||
|
||||
#if defined(CONFIG_LIBLC3)
|
||||
{
|
||||
const int freq = bt_audio_codec_cfg_get_freq(stream->codec_cfg);
|
||||
const int frame_duration_us =
|
||||
bt_audio_codec_cfg_get_frame_duration_us(stream->codec_cfg);
|
||||
int freq;
|
||||
int ret;
|
||||
|
||||
if (freq < 0) {
|
||||
ret = bt_audio_codec_cfg_get_freq(stream->codec_cfg);
|
||||
if (ret > 0) {
|
||||
freq = bt_audio_codec_cfg_freq_to_freq_hz(ret);
|
||||
} else {
|
||||
printk("Error: Codec frequency not set, cannot start codec.");
|
||||
*rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID,
|
||||
BT_BAP_ASCS_REASON_CODEC_DATA);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (frame_duration_us < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue