fix(ble_audio): Miscellaneous fixes for ISO & LE Audio (stage 1)

This commit is contained in:
Liu Linyan
2026-05-12 16:38:57 +08:00
parent 036fcf8e37
commit d3da42e608
14 changed files with 328 additions and 71 deletions
@@ -40,19 +40,26 @@ typedef struct bt_bap_lc3_preset esp_ble_audio_bap_lc3_preset_t;
* @param _rtn Number of retransmissions.
* @param _latency Maximum transport latency (in milliseconds).
* @param _pd Presentation delay (in microseconds).
*
* Backing buffers are sized to `CONFIG_BT_AUDIO_CODEC_CFG_MAX_*_SIZE` so
* the preset is safe to mutate via `esp_ble_audio_codec_cfg_*_set_*`.
*/
#define ESP_BLE_AUDIO_BAP_LC3_PRESET_DEFINE(_name, _freq, _duration, _loc, _len, \
_frames_per_sdu, _stream_context, \
_interval, _sdu, _rtn, _latency, _pd) \
static uint8_t codec_cfg_data_##_name[] = \
static uint8_t codec_cfg_data_##_name[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE] = \
ESP_BLE_AUDIO_CODEC_CFG_LC3_DATA(_freq, _duration, _loc, _len, _frames_per_sdu); \
static uint8_t codec_cfg_meta_##_name[] = \
static uint8_t codec_cfg_meta_##_name[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE] = \
ESP_BLE_AUDIO_CODEC_CFG_LC3_META(_stream_context); \
static esp_ble_audio_bap_lc3_preset_t _name = \
ESP_BLE_AUDIO_BAP_LC3_PRESET(ESP_BLE_AUDIO_CODEC_CFG_LC3(codec_cfg_data_##_name, \
codec_cfg_meta_##_name), \
ESP_BLE_AUDIO_BAP_QOS_CFG_UNFRAMED(_interval, _sdu, _rtn, \
_latency, _pd));
ESP_BLE_AUDIO_BAP_LC3_PRESET( \
ESP_BLE_AUDIO_CODEC_CFG_LC3_LEN( \
codec_cfg_data_##_name, \
sizeof((uint8_t[])ESP_BLE_AUDIO_CODEC_CFG_LC3_DATA(_freq, _duration, _loc, \
_len, _frames_per_sdu)), \
codec_cfg_meta_##_name, \
sizeof((uint8_t[])ESP_BLE_AUDIO_CODEC_CFG_LC3_META(_stream_context))), \
ESP_BLE_AUDIO_BAP_QOS_CFG_UNFRAMED(_interval, _sdu, _rtn, _latency, _pd));
/**
* @brief Helper to declare LC3 Unicast 8_1_1 codec configuration.
@@ -77,6 +77,35 @@ typedef enum bt_audio_codec_cfg_target_phy esp_ble_audio_codec_cfg_
.meta = (_meta), \
})
/**
* @brief Variant of ESP_BLE_AUDIO_CODEC_CFG with explicit LVT content lengths.
*
* @param _id Codec ID.
* @param _cid Company ID.
* @param _vid Vendor ID.
* @param _data Codec Specific Data buffer in LVT format.
* @param _data_len Current LVT content length in `_data`.
* @param _meta Codec Specific Metadata buffer in LVT format.
* @param _meta_len Current LVT content length in `_meta`.
*/
#define ESP_BLE_AUDIO_CODEC_CFG_LEN(_id, _cid, _vid, _data, _data_len, _meta, _meta_len) \
((esp_ble_audio_codec_cfg_t){ \
/* Use HCI data path as default, can be overwritten by application */ \
.path_id = ESP_BLE_ISO_DATA_PATH_HCI, \
.ctlr_transcode = false, \
COND_CODE_1(IS_ENABLED(CONFIG_BT_BAP_UNICAST), \
(.target_latency = ESP_BLE_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED, \
.target_phy = ESP_BLE_AUDIO_CODEC_CFG_TARGET_PHY_2M,), \
()) \
.id = (_id), \
.cid = (_cid), \
.vid = (_vid), \
.data_len = (_data_len), \
.data = (_data), \
.meta_len = (_meta_len), \
.meta = (_meta), \
})
/**
* @brief Helper to declare esp_ble_audio_codec_cap_t.
*
@@ -100,6 +129,23 @@ typedef enum bt_audio_codec_cfg_target_phy esp_ble_audio_codec_cfg_
.meta = (_meta), \
})
/**
* @brief Variant of ESP_BLE_AUDIO_CODEC_CAP with explicit LVT content lengths.
*/
#define ESP_BLE_AUDIO_CODEC_CAP_LEN(_id, _cid, _vid, _data, _data_len, _meta, _meta_len) \
((esp_ble_audio_codec_cap_t){ \
/* Use HCI data path as default, can be overwritten by application */ \
.path_id = ESP_BLE_ISO_DATA_PATH_HCI, \
.ctlr_transcode = false, \
.id = (_id), \
.cid = (_cid), \
.vid = (_vid), \
.data_len = (_data_len), \
.data = (_data), \
.meta_len = (_meta_len), \
.meta = (_meta), \
})
/*!< Supported sampling frequencies */
#define ESP_BLE_AUDIO_CODEC_CAP_TYPE_FREQ BT_AUDIO_CODEC_CAP_TYPE_FREQ
/*!< Supported frame durations */
@@ -31,19 +31,26 @@ extern "C" {
* @param _rtn Maximum number of retransmissions.
* @param _latency Maximum latency in milliseconds.
* @param _pd Presentation delay in microseconds.
*
* Backing buffers are sized to `CONFIG_BT_AUDIO_CODEC_CFG_MAX_*_SIZE` so
* the preset is safe to mutate via `esp_ble_audio_codec_cfg_*_set_*`.
*/
#define ESP_BLE_AUDIO_GMAP_LC3_PRESET_DEFINE(_name, _freq, _duration, _loc, _len, \
_frames_per_sdu, _stream_context, \
_interval, _sdu, _rtn, _latency, _pd) \
static uint8_t codec_cfg_data_##_name[] = \
static uint8_t codec_cfg_data_##_name[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE] = \
ESP_BLE_AUDIO_CODEC_CFG_LC3_DATA(_freq, _duration, _loc, _len, _frames_per_sdu); \
static uint8_t codec_cfg_meta_##_name[] = \
static uint8_t codec_cfg_meta_##_name[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE] = \
ESP_BLE_AUDIO_CODEC_CFG_LC3_META(_stream_context); \
static esp_ble_audio_bap_lc3_preset_t _name = \
ESP_BLE_AUDIO_BAP_LC3_PRESET(ESP_BLE_AUDIO_CODEC_CFG_LC3(codec_cfg_data_##_name, \
codec_cfg_meta_##_name), \
ESP_BLE_AUDIO_BAP_QOS_CFG_UNFRAMED(_interval, _sdu, _rtn, \
_latency, _pd));
ESP_BLE_AUDIO_BAP_LC3_PRESET( \
ESP_BLE_AUDIO_CODEC_CFG_LC3_LEN( \
codec_cfg_data_##_name, \
sizeof((uint8_t[])ESP_BLE_AUDIO_CODEC_CFG_LC3_DATA(_freq, _duration, _loc, \
_len, _frames_per_sdu)), \
codec_cfg_meta_##_name, \
sizeof((uint8_t[])ESP_BLE_AUDIO_CODEC_CFG_LC3_META(_stream_context))), \
ESP_BLE_AUDIO_BAP_QOS_CFG_UNFRAMED(_interval, _sdu, _rtn, _latency, _pd));
/**
* @brief Gaming Reliable (GR) preset at 32kHz, 7.5ms frame duration.
@@ -52,6 +52,13 @@ extern "C" {
#define ESP_BLE_AUDIO_CODEC_CAP_LC3(_data, _meta) \
ESP_BLE_AUDIO_CODEC_CAP(ESP_BLE_ISO_CODING_FORMAT_LC3, 0x0000, 0x0000, _data, _meta)
/**
* @brief Variant of ESP_BLE_AUDIO_CODEC_CAP_LC3 with explicit LVT content lengths.
*/
#define ESP_BLE_AUDIO_CODEC_CAP_LC3_LEN(_data, _data_len, _meta, _meta_len) \
ESP_BLE_AUDIO_CODEC_CAP_LEN(ESP_BLE_ISO_CODING_FORMAT_LC3, 0x0000, 0x0000, \
_data, _data_len, _meta, _meta_len)
/**
* @brief Helper to declare LC3 codec data configuration.
*
@@ -82,6 +89,13 @@ extern "C" {
#define ESP_BLE_AUDIO_CODEC_CFG_LC3(_data, _meta) \
ESP_BLE_AUDIO_CODEC_CFG(ESP_BLE_ISO_CODING_FORMAT_LC3, 0x0000, 0x0000, _data, _meta)
/**
* @brief Variant of ESP_BLE_AUDIO_CODEC_CFG_LC3 with explicit LVT content lengths.
*/
#define ESP_BLE_AUDIO_CODEC_CFG_LC3_LEN(_data, _data_len, _meta, _meta_len) \
ESP_BLE_AUDIO_CODEC_CFG_LEN(ESP_BLE_ISO_CODING_FORMAT_LC3, 0x0000, 0x0000, \
_data, _data_len, _meta, _meta_len)
#ifdef __cplusplus
}
#endif
+25 -1
View File
@@ -178,7 +178,7 @@ static const uint16_t ext_structs[] = {
sizeof(struct bt_bond_info),
};
#define LEA_VERSION (0x20260430)
#define LEA_VERSION (0x20260512)
struct lib_ext_cfgs {
/* BLE */
@@ -971,6 +971,12 @@ struct lib_ext_funcs {
void (*_log_wrn)(const char *format, ...);
void (*_log_err)(const char *format, ...);
/* Fatal assert: log + abort with tag/info/file/line/func context.
* Mirrors lib-side lib_ext_funcs._assert in init.h. ABI must match.
*/
void (*_assert)(const char *tag, size_t info,
const char *file, int line, const char *func);
/* Memory */
void *(*_malloc)(size_t size);
void *(*_calloc)(size_t n, size_t size);
@@ -1180,12 +1186,30 @@ static void log_error(const char *format, ...)
#endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */
}
/* Fatal assert handler registered into lib_ext_funcs._assert.
* Always logged (no LOG_LEVEL gate) — this is the last message before
* abort, and the user needs the context to diagnose.
*/
static void assert_fatal(const char *tag, size_t info,
const char *file, int line, const char *func)
{
esp_log_write(ESP_LOG_ERROR, LEA_TAG,
BT_ISO_LOG_COLOR_E
"E (%lu) %s: LibAssert[%s][info=%u][%s:%d][%s]"
BT_ISO_LOG_RESET_COLOR "\n",
esp_log_timestamp(), LEA_TAG,
tag, (unsigned)info, file, line, func);
abort();
}
static const struct lib_ext_funcs ext_funcs = {
._log_dbg = (void *)log_debug,
._log_inf = (void *)log_info,
._log_wrn = (void *)log_warn,
._log_err = (void *)log_error,
._assert = (void *)assert_fatal,
._malloc = (void *)malloc,
._calloc = (void *)calloc,
._free = (void *)free,