1 /*
2  * Copyright 2024 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <zephyr/sys/atomic.h>
11 #include <zephyr/sys/byteorder.h>
12 #include <zephyr/sys/util.h>
13 #include <zephyr/sys/printk.h>
14 
15 #include <zephyr/bluetooth/classic/a2dp_codec_sbc.h>
16 #include <zephyr/bluetooth/classic/a2dp.h>
17 
18 
bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params * sbc_codec)19 uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
20 {
21 	__ASSERT_NO_MSG(sbc_codec != NULL);
22 
23 	if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_MONO) {
24 		return 1U;
25 	} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_DUAL) {
26 		return 2U;
27 	} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_STREO) {
28 		return 2U;
29 	} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_JOINT) {
30 		return 2U;
31 	} else {
32 		return 0U;
33 	}
34 }
35 
bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params * sbc_codec)36 uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec)
37 {
38 	__ASSERT_NO_MSG(sbc_codec != NULL);
39 
40 	if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_16000) {
41 		return 16000U;
42 	} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_32000) {
43 		return 32000U;
44 	} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_44100) {
45 		return 44100U;
46 	} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_48000) {
47 		return 48000U;
48 	} else {
49 		return 0U;
50 	}
51 }
52