Browse Source
implement a2dp.c and avdtp.c add a2dp related Kconfig: BT_AVDTP_RTP_VERSION, BT_A2DP_SOURCE and BT_A2DP_SINK a2dp_codec_sbc.c/h are used to provide some APIs to get A2DP SBC codec information. (like: channel num). Signed-off-by: Mark Wang <yichang.wang@nxp.com>pull/73011/head
10 changed files with 3071 additions and 295 deletions
@ -1,115 +0,0 @@ |
|||||||
/** @file
|
|
||||||
* @brief Advance Audio Distribution Profile - SBC Codec header. |
|
||||||
*/ |
|
||||||
/*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 |
|
||||||
* Copyright (c) 2015-2016 Intel Corporation |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ |
|
||||||
#define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ |
|
||||||
|
|
||||||
#include <stdint.h> |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Sampling Frequency |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define A2DP_SBC_SAMP_FREQ_16000 BIT(7) /**< 16 kHz */ |
|
||||||
#define A2DP_SBC_SAMP_FREQ_32000 BIT(6) /**< 32 kHz */ |
|
||||||
#define A2DP_SBC_SAMP_FREQ_44100 BIT(5) /**< 44.1 kHz */ |
|
||||||
#define A2DP_SBC_SAMP_FREQ_48000 BIT(4) /**< 48 kHz */ |
|
||||||
/** @} */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Channel Mode |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define A2DP_SBC_CH_MODE_MONO BIT(3) /**< Mono */ |
|
||||||
#define A2DP_SBC_CH_MODE_DUAL BIT(2) /**< Dual Channel */ |
|
||||||
#define A2DP_SBC_CH_MODE_STREO BIT(1) /**< Stereo */ |
|
||||||
#define A2DP_SBC_CH_MODE_JOINT BIT(0) /**< Joint Stereo */ |
|
||||||
/** @} */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Block Length |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define A2DP_SBC_BLK_LEN_4 BIT(7) /**< 4 blocks */ |
|
||||||
#define A2DP_SBC_BLK_LEN_8 BIT(6) /**< 8 blocks */ |
|
||||||
#define A2DP_SBC_BLK_LEN_12 BIT(5) /**< 12 blocks */ |
|
||||||
#define A2DP_SBC_BLK_LEN_16 BIT(4) /**< 16 blocks */ |
|
||||||
/** @} */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Subbands |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define A2DP_SBC_SUBBAND_4 BIT(3) /**< 4 subbands */ |
|
||||||
#define A2DP_SBC_SUBBAND_8 BIT(2) /**< 8 subbands */ |
|
||||||
/** @} */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Bit pool Allocation Method |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define A2DP_SBC_ALLOC_MTHD_SNR BIT(1) /**< Allocate based on loudness of the subband signal */ |
|
||||||
#define A2DP_SBC_ALLOC_MTHD_LOUDNESS BIT(0) /**< Allocate based on the signal-to-noise ratio */ |
|
||||||
/** @} */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the sampling rate from a codec preset |
|
||||||
* @param preset Codec preset |
|
||||||
*/ |
|
||||||
#define BT_A2DP_SBC_SAMP_FREQ(preset) ((preset->config[0] >> 4) & 0x0f) |
|
||||||
/**
|
|
||||||
* Gets the channel mode from a codec preset |
|
||||||
* @param preset Codec preset |
|
||||||
*/ |
|
||||||
#define BT_A2DP_SBC_CHAN_MODE(preset) ((preset->config[0]) & 0x0f) |
|
||||||
/**
|
|
||||||
* Gets the block length from a codec preset |
|
||||||
* @param preset Codec preset |
|
||||||
*/ |
|
||||||
#define BT_A2DP_SBC_BLK_LEN(preset) ((preset->config[1] >> 4) & 0x0f) |
|
||||||
/**
|
|
||||||
* Gets the number subbands from a codec preset |
|
||||||
* @param preset Codec preset |
|
||||||
*/ |
|
||||||
#define BT_A2DP_SBC_SUB_BAND(preset) ((preset->config[1] >> 2) & 0x03) |
|
||||||
/**
|
|
||||||
* Gets the bitpool allocation method from a codec preset |
|
||||||
* @param preset Codec preset |
|
||||||
*/ |
|
||||||
#define BT_A2DP_SBC_ALLOC_MTHD(preset) ((preset->config[1]) & 0x03) |
|
||||||
|
|
||||||
/** @brief SBC Codec */ |
|
||||||
struct bt_a2dp_codec_sbc_params { |
|
||||||
/** First two octets of configuration */ |
|
||||||
uint8_t config[2]; |
|
||||||
/** Minimum Bitpool Value */ |
|
||||||
uint8_t min_bitpool; |
|
||||||
/** Maximum Bitpool Value */ |
|
||||||
uint8_t max_bitpool; |
|
||||||
} __packed; |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ */ |
|
@ -0,0 +1,124 @@ |
|||||||
|
/** @file
|
||||||
|
* @brief Advance Audio Distribution Profile - SBC Codec header. |
||||||
|
*/ |
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
* Copyright (c) 2015-2016 Intel Corporation |
||||||
|
* Copyright (c) 2021 NXP |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ |
||||||
|
#define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Sampling Frequency */ |
||||||
|
#define A2DP_SBC_SAMP_FREQ_16000 BIT(7) |
||||||
|
#define A2DP_SBC_SAMP_FREQ_32000 BIT(6) |
||||||
|
#define A2DP_SBC_SAMP_FREQ_44100 BIT(5) |
||||||
|
#define A2DP_SBC_SAMP_FREQ_48000 BIT(4) |
||||||
|
|
||||||
|
/* Channel Mode */ |
||||||
|
#define A2DP_SBC_CH_MODE_MONO BIT(3) |
||||||
|
#define A2DP_SBC_CH_MODE_DUAL BIT(2) |
||||||
|
#define A2DP_SBC_CH_MODE_STREO BIT(1) |
||||||
|
#define A2DP_SBC_CH_MODE_JOINT BIT(0) |
||||||
|
|
||||||
|
/* Block Length */ |
||||||
|
#define A2DP_SBC_BLK_LEN_4 BIT(7) |
||||||
|
#define A2DP_SBC_BLK_LEN_8 BIT(6) |
||||||
|
#define A2DP_SBC_BLK_LEN_12 BIT(5) |
||||||
|
#define A2DP_SBC_BLK_LEN_16 BIT(4) |
||||||
|
|
||||||
|
/* Subbands */ |
||||||
|
#define A2DP_SBC_SUBBAND_4 BIT(3) |
||||||
|
#define A2DP_SBC_SUBBAND_8 BIT(2) |
||||||
|
|
||||||
|
/* Allocation Method */ |
||||||
|
#define A2DP_SBC_ALLOC_MTHD_SNR BIT(1) |
||||||
|
#define A2DP_SBC_ALLOC_MTHD_LOUDNESS BIT(0) |
||||||
|
|
||||||
|
#define BT_A2DP_SBC_SAMP_FREQ(cap) ((cap->config[0] >> 4) & 0x0f) |
||||||
|
#define BT_A2DP_SBC_CHAN_MODE(cap) ((cap->config[0]) & 0x0f) |
||||||
|
#define BT_A2DP_SBC_BLK_LEN(cap) ((cap->config[1] >> 4) & 0x0f) |
||||||
|
#define BT_A2DP_SBC_SUB_BAND(cap) ((cap->config[1] >> 2) & 0x03) |
||||||
|
#define BT_A2DP_SBC_ALLOC_MTHD(cap) ((cap->config[1]) & 0x03) |
||||||
|
|
||||||
|
/** @brief SBC Codec */ |
||||||
|
struct bt_a2dp_codec_sbc_params { |
||||||
|
/** First two octets of configuration */ |
||||||
|
uint8_t config[2]; |
||||||
|
/** Minimum Bitpool Value */ |
||||||
|
uint8_t min_bitpool; |
||||||
|
/** Maximum Bitpool Value */ |
||||||
|
uint8_t max_bitpool; |
||||||
|
} __packed; |
||||||
|
|
||||||
|
/** If the F bit is set to 0, this field indicates the number of frames contained
|
||||||
|
* in this packet. If the F bit is set to 1, this field indicates the number |
||||||
|
* of remaining fragments, including the current fragment. |
||||||
|
* Therefore, the last counter value shall be one. |
||||||
|
*/ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_NUM_FRAMES_GET(hdr) FIELD_GET(GENMASK(3, 0), (hdr)) |
||||||
|
/** Set to 1 for the last packet of a fragmented SBC frame, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_L_GET(hdr) FIELD_GET(BIT(5), (hdr)) |
||||||
|
/** Set to 1 for the starting packet of a fragmented SBC frame, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_S_GET(hdr) FIELD_GET(BIT(6), (hdr)) |
||||||
|
/** Set to 1 if the SBC frame is fragmented, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_F_GET(hdr) FIELD_GET(BIT(7), (hdr)) |
||||||
|
|
||||||
|
/** If the F bit is set to 0, this field indicates the number of frames contained
|
||||||
|
* in this packet. If the F bit is set to 1, this field indicates the number |
||||||
|
* of remaining fragments, including the current fragment. |
||||||
|
* Therefore, the last counter value shall be one. |
||||||
|
*/ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_NUM_FRAMES_SET(hdr, val)\ |
||||||
|
hdr = ((hdr) & ~GENMASK(3, 0)) | FIELD_PREP(GENMASK(3, 0), (val)) |
||||||
|
/** Set to 1 for the last packet of a fragmented SBC frame, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_L_SET(hdr, val)\ |
||||||
|
hdr = ((hdr) & ~BIT(5)) | FIELD_PREP(BIT(5), (val)) |
||||||
|
/** Set to 1 for the starting packet of a fragmented SBC frame, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_S_SET(hdr, val)\ |
||||||
|
hdr = ((hdr) & ~BIT(6)) | FIELD_PREP(BIT(6), (val)) |
||||||
|
/** Set to 1 if the SBC frame is fragmented, otherwise set to 0. */ |
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_F_SET(hdr, val)\ |
||||||
|
hdr = ((hdr) & ~BIT(7)) | FIELD_PREP(BIT(7), (val)) |
||||||
|
|
||||||
|
#define BT_A2DP_SBC_MEDIA_HDR_ENCODE(num_frames, l, s, f)\ |
||||||
|
FIELD_PREP(GENMASK(3, 0), num_frames) | FIELD_PREP(BIT(5), l) |\ |
||||||
|
FIELD_PREP(BIT(6), s) | FIELD_PREP(BIT(7), f) |
||||||
|
|
||||||
|
/** @brief get channel num of a2dp sbc config.
|
||||||
|
* |
||||||
|
* @param sbc_codec The a2dp sbc parameter. |
||||||
|
* |
||||||
|
* @return the channel num. |
||||||
|
*/ |
||||||
|
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec); |
||||||
|
|
||||||
|
/** @brief get sample rate of a2dp sbc config.
|
||||||
|
* |
||||||
|
* @param sbc_codec The a2dp sbc parameter. |
||||||
|
* |
||||||
|
* @return the sample rate. |
||||||
|
*/ |
||||||
|
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec); |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ */ |
@ -0,0 +1,51 @@ |
|||||||
|
/*
|
||||||
|
* Copyright 2024 NXP |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <zephyr/kernel.h> |
||||||
|
#include <string.h> |
||||||
|
#include <errno.h> |
||||||
|
#include <zephyr/sys/atomic.h> |
||||||
|
#include <zephyr/sys/byteorder.h> |
||||||
|
#include <zephyr/sys/util.h> |
||||||
|
#include <zephyr/sys/printk.h> |
||||||
|
|
||||||
|
#include <zephyr/bluetooth/classic/a2dp_codec_sbc.h> |
||||||
|
#include <zephyr/bluetooth/classic/a2dp.h> |
||||||
|
|
||||||
|
|
||||||
|
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec) |
||||||
|
{ |
||||||
|
__ASSERT_NO_MSG(sbc_codec != NULL); |
||||||
|
|
||||||
|
if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_MONO) { |
||||||
|
return 1U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_DUAL) { |
||||||
|
return 2U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_STREO) { |
||||||
|
return 2U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_JOINT) { |
||||||
|
return 2U; |
||||||
|
} else { |
||||||
|
return 0U; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec) |
||||||
|
{ |
||||||
|
__ASSERT_NO_MSG(sbc_codec != NULL); |
||||||
|
|
||||||
|
if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_16000) { |
||||||
|
return 16000U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_32000) { |
||||||
|
return 32000U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_44100) { |
||||||
|
return 44100U; |
||||||
|
} else if (sbc_codec->config[0] & A2DP_SBC_SAMP_FREQ_48000) { |
||||||
|
return 48000U; |
||||||
|
} else { |
||||||
|
return 0U; |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue