diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index e09d7a18cf2..9ba245c7c9b 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -709,193 +709,168 @@ uint8_t bt_audio_codec_cfg_get_val(const struct bt_audio_codec_cfg *codec_cfg, u int bt_audio_codec_cfg_set_val(struct bt_audio_codec_cfg *codec_cfg, uint8_t type, const uint8_t *data, size_t data_len); -/** @} */ /* End of bt_audio_codec_cfg */ - -/** - * @brief Audio codec Config APIs - * @defgroup bt_audio_codec_meta Metadata parsing APIs - * - * Functions to parse LTV formatted metadata. - * - * @{ - */ - /** @brief Lookup a specific metadata value based on type * - * This works for metadata from both @ref bt_audio_codec_cfg meta and @ref bt_audio_codec_cap meta. - * * - * @param[in] meta The metadata to search in. - * @param[in] meta_len The length of @p meta. - * @param[in] type The type id to look for - * @param[out] data Pointer to the data-pointer to update when item is found + * + * @param[in] codec_cfg The codec data to search in. + * @param[in] type The type id to look for + * @param[out] data Pointer to the data-pointer to update when item is found * * @retval Length of found @p data (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_val(const uint8_t meta[], size_t meta_len, uint8_t type, - const uint8_t **data); +int bt_audio_codec_cfg_meta_get_val(const struct bt_audio_codec_cfg *codec_cfg, uint8_t type, + const uint8_t **data); /** @brief Extract preferred contexts * * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval The preferred context type if positive or 0 * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found * @retval -EBADMSG if found value has invalid size */ -int bt_audio_codec_meta_get_pref_context(const uint8_t meta[], size_t meta_len); +int bt_audio_codec_cfg_meta_get_pref_context(const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract stream contexts * * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval The stream context type if positive or 0 * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found * @retval -EBADMSG if found value has invalid size */ -int bt_audio_codec_meta_get_stream_context(const uint8_t meta[], size_t meta_len); +int bt_audio_codec_cfg_meta_get_stream_context(const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract program info * * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value. * - * @param[in] meta The metadata to get the data from in. - * @param[in] meta_len The length of @p meta. + * @param[in] codec_cfg The codec data to search in. * @param[out] program_info Pointer to the UTF-8 formatted program info. * * @retval The length of the @p program_info (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_program_info(const uint8_t meta[], size_t meta_len, - const uint8_t **program_info); +int bt_audio_codec_cfg_meta_get_program_info(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **program_info); /** @brief Extract stream language * * See @ref BT_AUDIO_METADATA_TYPE_STREAM_LANG for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval The stream language if positive or 0 * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found * @retval -EBADMSG if found value has invalid size */ -int bt_audio_codec_meta_get_stream_lang(const uint8_t meta[], size_t meta_len); +int bt_audio_codec_cfg_meta_get_stream_lang(const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract CCID list * * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value. * - * @param[in] meta The metadata to get the data from in. - * @param[in] meta_len The length of @p meta. + * @param[in] codec_cfg The codec data to search in. * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs. * * @retval The length of the @p ccid_list (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_ccid_list(const uint8_t meta[], size_t meta_len, - const uint8_t **ccid_list); +int bt_audio_codec_cfg_meta_get_ccid_list(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **ccid_list); /** @brief Extract parental rating * * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval The parental rating if positive or 0 * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found * @retval -EBADMSG if found value has invalid size */ -int bt_audio_codec_meta_get_parental_rating(const uint8_t meta[], size_t meta_len); +int bt_audio_codec_cfg_meta_get_parental_rating(const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract program info URI * * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value. * - * @param[in] meta The metadata to get the data from in. - * @param[in] meta_len The length of @p meta. + * @param[in] codec_cfg The codec data to search in. * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI. * * @retval The length of the @p ccid_list (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_program_info_uri(const uint8_t meta[], size_t meta_len, - const uint8_t **program_info_uri); +int bt_audio_codec_cfg_meta_get_program_info_uri(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **program_info_uri); /** @brief Extract audio active state * * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval The preferred context type if positive or 0 * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found * @retval -EBADMSG if found value has invalid size */ -int bt_audio_codec_meta_get_audio_active_state(const uint8_t meta[], size_t meta_len); +int bt_audio_codec_cfg_meta_get_audio_active_state(const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract broadcast audio immediate rendering flag * * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value. * - * @param meta The metadata to get the data from in. - * @param meta_len The length of @p meta. + * @param codec_cfg The codec data to search in. * * @retval 0 if the flag was found * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not the flag was not found */ -int bt_audio_codec_meta_get_broadcast_audio_immediate_rendering_flag(const uint8_t meta[], - size_t meta_len); +int bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag( + const struct bt_audio_codec_cfg *codec_cfg); /** @brief Extract extended metadata * * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value. * - * @param[in] meta The metadata to get the data from in. - * @param[in] meta_len The length of @p meta. + * @param[in] codec_cfg The codec data to search in. * @param[out] extended_meta Pointer to the extended metadata. * * @retval The length of the @p ccid_list (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_extended(const uint8_t meta[], size_t meta_len, - const uint8_t **extended_meta); +int bt_audio_codec_cfg_meta_get_extended(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **extended_meta); /** @brief Extract vendor specific metadata * * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value. * - * @param[in] meta The metadata to get the data from in. - * @param[in] meta_len The length of @p meta. + * @param[in] codec_cfg The codec data to search in. * @param[out] vendor_meta Pointer to the vendor specific metadata. * * @retval The length of the @p ccid_list (may be 0) * @retval -EINVAL if arguments are invalid * @retval -ENODATA if not found */ -int bt_audio_codec_meta_get_vendor(const uint8_t meta[], size_t meta_len, - const uint8_t **vendor_meta); - -/** @} */ /* End of bt_audio_codec_meta */ +int bt_audio_codec_cfg_meta_get_vendor(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **vendor_meta); +/** @} */ /* End of bt_audio_codec_cfg */ /** * @brief Audio codec capabilities APIs @@ -982,6 +957,166 @@ int bt_audio_codec_cap_get_octets_per_frame( */ int bt_audio_codec_cap_get_max_codec_frames_per_sdu(const struct bt_audio_codec_cap *codec_cap); +/** @brief Lookup a specific metadata value based on type + * + * @param[in] codec_cap The codec data to search in. + * @param[in] type The type id to look for + * @param[out] data Pointer to the data-pointer to update when item is found + * + * @retval Length of found @p data (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_val(const struct bt_audio_codec_cap *codec_cap, uint8_t type, + const uint8_t **data); + +/** @brief Extract preferred contexts + * + * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval The preferred context type if positive or 0 + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + * @retval -EBADMSG if found value has invalid size + */ +int bt_audio_codec_cap_meta_get_pref_context(const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract stream contexts + * + * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval The stream context type if positive or 0 + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + * @retval -EBADMSG if found value has invalid size + */ +int bt_audio_codec_cap_meta_get_stream_context(const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract program info + * + * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value. + * + * @param[in] codec_cap The codec data to search in. + * @param[out] program_info Pointer to the UTF-8 formatted program info. + * + * @retval The length of the @p program_info (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_program_info(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **program_info); + +/** @brief Extract stream language + * + * See @ref BT_AUDIO_METADATA_TYPE_STREAM_LANG for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval The stream language if positive or 0 + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + * @retval -EBADMSG if found value has invalid size + */ +int bt_audio_codec_cap_meta_get_stream_lang(const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract CCID list + * + * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value. + * + * @param[in] codec_cap The codec data to search in. + * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs. + * + * @retval The length of the @p ccid_list (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_ccid_list(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **ccid_list); + +/** @brief Extract parental rating + * + * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval The parental rating if positive or 0 + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + * @retval -EBADMSG if found value has invalid size + */ +int bt_audio_codec_cap_meta_get_parental_rating(const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract program info URI + * + * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value. + * + * @param[in] codec_cap The codec data to search in. + * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI. + * + * @retval The length of the @p ccid_list (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_program_info_uri(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **program_info_uri); + +/** @brief Extract audio active state + * + * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval The preferred context type if positive or 0 + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + * @retval -EBADMSG if found value has invalid size + */ +int bt_audio_codec_cap_meta_get_audio_active_state(const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract broadcast audio immediate rendering flag + * + * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value. + * + * @param codec_cap The codec data to search in. + * + * @retval 0 if the flag was found + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not the flag was not found + */ +int bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag( + const struct bt_audio_codec_cap *codec_cap); + +/** @brief Extract extended metadata + * + * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value. + * + * @param[in] codec_cap The codec data to search in. + * @param[out] extended_meta Pointer to the extended metadata. + * + * @retval The length of the @p ccid_list (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_extended(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **extended_meta); + +/** @brief Extract vendor specific metadata + * + * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value. + * + * @param[in] codec_cap The codec data to search in. + * @param[out] vendor_meta Pointer to the vendor specific metadata. + * + * @retval The length of the @p ccid_list (may be 0) + * @retval -EINVAL if arguments are invalid + * @retval -ENODATA if not found + */ +int bt_audio_codec_cap_meta_get_vendor(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **vendor_meta); /** @} */ /* End of bt_audio_codec_cap */ #ifdef __cplusplus diff --git a/subsys/bluetooth/audio/codec.c b/subsys/bluetooth/audio/codec.c index bdcf8978bd4..c9848c2ebf3 100644 --- a/subsys/bluetooth/audio/codec.c +++ b/subsys/bluetooth/audio/codec.c @@ -409,8 +409,8 @@ int bt_audio_codec_cfg_get_frame_blocks_per_sdu(const struct bt_audio_codec_cfg #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 || \ CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE > 0 -int bt_audio_codec_meta_get_val(const uint8_t meta[], size_t meta_len, uint8_t type, - const uint8_t **data) +static int codec_meta_get_val(const uint8_t meta[], size_t meta_len, uint8_t type, + const uint8_t **data) { struct search_type_param param = { .type = type, @@ -445,7 +445,7 @@ int bt_audio_codec_meta_get_val(const uint8_t meta[], size_t meta_len, uint8_t t return param.data_len; } -int bt_audio_codec_meta_get_pref_context(const uint8_t meta[], size_t meta_len) +static int codec_meta_get_pref_context(const uint8_t meta[], size_t meta_len) { const uint8_t *data; int ret; @@ -455,8 +455,7 @@ int bt_audio_codec_meta_get_pref_context(const uint8_t meta[], size_t meta_len) return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, &data); if (data == NULL) { return -ENODATA; } @@ -468,7 +467,7 @@ int bt_audio_codec_meta_get_pref_context(const uint8_t meta[], size_t meta_len) return sys_get_le16(data); } -int bt_audio_codec_meta_get_stream_context(const uint8_t meta[], size_t meta_len) +static int codec_meta_get_stream_context(const uint8_t meta[], size_t meta_len) { const uint8_t *data; int ret; @@ -478,8 +477,7 @@ int bt_audio_codec_meta_get_stream_context(const uint8_t meta[], size_t meta_len return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, &data); if (data == NULL) { return -ENODATA; } @@ -491,8 +489,8 @@ int bt_audio_codec_meta_get_stream_context(const uint8_t meta[], size_t meta_len return sys_get_le16(data); } -int bt_audio_codec_meta_get_program_info(const uint8_t meta[], size_t meta_len, - const uint8_t **program_info) +static int codec_meta_get_program_info(const uint8_t meta[], size_t meta_len, + const uint8_t **program_info) { const uint8_t *data; int ret; @@ -507,8 +505,7 @@ int bt_audio_codec_meta_get_program_info(const uint8_t meta[], size_t meta_len, return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, &data); if (data == NULL) { return -ENODATA; } @@ -518,7 +515,7 @@ int bt_audio_codec_meta_get_program_info(const uint8_t meta[], size_t meta_len, return ret; } -int bt_audio_codec_meta_get_stream_lang(const uint8_t meta[], size_t meta_len) +static int codec_meta_get_stream_lang(const uint8_t meta[], size_t meta_len) { const uint8_t *data; int ret; @@ -528,8 +525,7 @@ int bt_audio_codec_meta_get_stream_lang(const uint8_t meta[], size_t meta_len) return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_STREAM_LANG, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_STREAM_LANG, &data); if (data == NULL) { return -ENODATA; } @@ -541,8 +537,8 @@ int bt_audio_codec_meta_get_stream_lang(const uint8_t meta[], size_t meta_len) return sys_get_le24(data); } -int bt_audio_codec_meta_get_ccid_list(const uint8_t meta[], size_t meta_len, - const uint8_t **ccid_list) +static int codec_meta_get_ccid_list(const uint8_t meta[], size_t meta_len, + const uint8_t **ccid_list) { const uint8_t *data; int ret; @@ -557,7 +553,7 @@ int bt_audio_codec_meta_get_ccid_list(const uint8_t meta[], size_t meta_len, return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_CCID_LIST, &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_CCID_LIST, &data); if (data == NULL) { return -ENODATA; } @@ -567,7 +563,7 @@ int bt_audio_codec_meta_get_ccid_list(const uint8_t meta[], size_t meta_len, return ret; } -int bt_audio_codec_meta_get_parental_rating(const uint8_t meta[], size_t meta_len) +static int codec_meta_get_parental_rating(const uint8_t meta[], size_t meta_len) { const uint8_t *data; int ret; @@ -577,8 +573,7 @@ int bt_audio_codec_meta_get_parental_rating(const uint8_t meta[], size_t meta_le return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, &data); if (data == NULL) { return -ENODATA; } @@ -590,8 +585,8 @@ int bt_audio_codec_meta_get_parental_rating(const uint8_t meta[], size_t meta_le return data[0]; } -int bt_audio_codec_meta_get_program_info_uri(const uint8_t meta[], size_t meta_len, - const uint8_t **program_info_uri) +static int codec_meta_get_program_info_uri(const uint8_t meta[], size_t meta_len, + const uint8_t **program_info_uri) { const uint8_t *data; int ret; @@ -606,8 +601,7 @@ int bt_audio_codec_meta_get_program_info_uri(const uint8_t meta[], size_t meta_l return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, &data); if (data == NULL) { return -ENODATA; } @@ -617,7 +611,7 @@ int bt_audio_codec_meta_get_program_info_uri(const uint8_t meta[], size_t meta_l return ret; } -int bt_audio_codec_meta_get_audio_active_state(const uint8_t meta[], size_t meta_len) +static int codec_meta_get_audio_active_state(const uint8_t meta[], size_t meta_len) { const uint8_t *data; int ret; @@ -627,8 +621,7 @@ int bt_audio_codec_meta_get_audio_active_state(const uint8_t meta[], size_t meta return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_AUDIO_STATE, - &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_AUDIO_STATE, &data); if (data == NULL) { return -ENODATA; } @@ -640,8 +633,7 @@ int bt_audio_codec_meta_get_audio_active_state(const uint8_t meta[], size_t meta return data[0]; } -int bt_audio_codec_meta_get_broadcast_audio_immediate_rendering_flag(const uint8_t meta[], - size_t meta_len) +static int codec_meta_get_bcast_audio_immediate_rend_flag(const uint8_t meta[], size_t meta_len) { const uint8_t *data; @@ -650,12 +642,12 @@ int bt_audio_codec_meta_get_broadcast_audio_immediate_rendering_flag(const uint8 return -EINVAL; } - return bt_audio_codec_meta_get_val(meta, meta_len, - BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE, &data); + return codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE, + &data); } -int bt_audio_codec_meta_get_extended(const uint8_t meta[], size_t meta_len, - const uint8_t **extended_meta) +static int codec_meta_get_extended(const uint8_t meta[], size_t meta_len, + const uint8_t **extended_meta) { const uint8_t *data; int ret; @@ -670,7 +662,7 @@ int bt_audio_codec_meta_get_extended(const uint8_t meta[], size_t meta_len, return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_EXTENDED, &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_EXTENDED, &data); if (data == NULL) { return -ENODATA; } @@ -680,8 +672,7 @@ int bt_audio_codec_meta_get_extended(const uint8_t meta[], size_t meta_len, return ret; } -int bt_audio_codec_meta_get_vendor(const uint8_t meta[], size_t meta_len, - const uint8_t **vendor_meta) +static int codec_meta_get_vendor(const uint8_t meta[], size_t meta_len, const uint8_t **vendor_meta) { const uint8_t *data; int ret; @@ -696,7 +687,7 @@ int bt_audio_codec_meta_get_vendor(const uint8_t meta[], size_t meta_len, return -EINVAL; } - ret = bt_audio_codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_VENDOR, &data); + ret = codec_meta_get_val(meta, meta_len, BT_AUDIO_METADATA_TYPE_VENDOR, &data); if (data == NULL) { return -ENODATA; } @@ -705,6 +696,268 @@ int bt_audio_codec_meta_get_vendor(const uint8_t meta[], size_t meta_len, return ret; } + +#if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 +int bt_audio_codec_cfg_meta_get_val(const struct bt_audio_codec_cfg *codec_cfg, uint8_t type, + const uint8_t **data) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_val(codec_cfg->meta, codec_cfg->meta_len, type, data); +} + +int bt_audio_codec_cfg_meta_get_pref_context(const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_pref_context(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_stream_context(const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_stream_context(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_program_info(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **program_info) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_program_info(codec_cfg->meta, codec_cfg->meta_len, program_info); +} + +int bt_audio_codec_cfg_meta_get_stream_lang(const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_stream_lang(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_ccid_list(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **ccid_list) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_ccid_list(codec_cfg->meta, codec_cfg->meta_len, ccid_list); +} + +int bt_audio_codec_cfg_meta_get_parental_rating(const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_parental_rating(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_program_info_uri(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **program_info_uri) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_program_info_uri(codec_cfg->meta, codec_cfg->meta_len, + program_info_uri); +} + +int bt_audio_codec_cfg_meta_get_audio_active_state(const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_audio_active_state(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag( + const struct bt_audio_codec_cfg *codec_cfg) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + LOG_ERR("codec_cfg->meta_len %zu", codec_cfg->meta_len); + + return codec_meta_get_bcast_audio_immediate_rend_flag(codec_cfg->meta, codec_cfg->meta_len); +} + +int bt_audio_codec_cfg_meta_get_extended(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **extended_meta) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_extended(codec_cfg->meta, codec_cfg->meta_len, extended_meta); +} + +int bt_audio_codec_cfg_meta_get_vendor(const struct bt_audio_codec_cfg *codec_cfg, + const uint8_t **vendor_meta) +{ + CHECKIF(codec_cfg == NULL) { + LOG_DBG("codec_cfg is NULL"); + return -EINVAL; + } + + return codec_meta_get_vendor(codec_cfg->meta, codec_cfg->meta_len, vendor_meta); +} +#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */ + +#if CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE > 0 +int bt_audio_codec_cap_meta_get_val(const struct bt_audio_codec_cap *codec_cap, uint8_t type, + const uint8_t **data) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_val(codec_cap->meta, codec_cap->meta_len, type, data); +} + +int bt_audio_codec_cap_meta_get_pref_context(const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_pref_context(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_stream_context(const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_stream_context(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_program_info(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **program_info) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_program_info(codec_cap->meta, codec_cap->meta_len, program_info); +} + +int bt_audio_codec_cap_meta_get_stream_lang(const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_stream_lang(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_ccid_list(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **ccid_list) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_ccid_list(codec_cap->meta, codec_cap->meta_len, ccid_list); +} + +int bt_audio_codec_cap_meta_get_parental_rating(const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_parental_rating(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_program_info_uri(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **program_info_uri) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_program_info_uri(codec_cap->meta, codec_cap->meta_len, + program_info_uri); +} + +int bt_audio_codec_cap_meta_get_audio_active_state(const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_audio_active_state(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag( + const struct bt_audio_codec_cap *codec_cap) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_bcast_audio_immediate_rend_flag(codec_cap->meta, codec_cap->meta_len); +} + +int bt_audio_codec_cap_meta_get_extended(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **extended_meta) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_extended(codec_cap->meta, codec_cap->meta_len, extended_meta); +} + +int bt_audio_codec_cap_meta_get_vendor(const struct bt_audio_codec_cap *codec_cap, + const uint8_t **vendor_meta) +{ + CHECKIF(codec_cap == NULL) { + LOG_DBG("codec_cap is NULL"); + return -EINVAL; + } + + return codec_meta_get_vendor(codec_cap->meta, codec_cap->meta_len, vendor_meta); +} +#endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE > 0 */ #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 || \ * CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE > 0 \ */ diff --git a/tests/bluetooth/audio/codec/prj.conf b/tests/bluetooth/audio/codec/prj.conf index 5ac78f09abc..308958c0fe3 100644 --- a/tests/bluetooth/audio/codec/prj.conf +++ b/tests/bluetooth/audio/codec/prj.conf @@ -8,6 +8,8 @@ CONFIG_BT_BAP_UNICAST_SERVER=y CONFIG_LOG=y CONFIG_BT_AUDIO_LOG_LEVEL_DBG=y CONFIG_BT_AUDIO_CODEC_LOG_LEVEL_DBG=y +CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE=15 +CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE=15 CONFIG_ASSERT=y CONFIG_ASSERT_LEVEL=2 diff --git a/tests/bluetooth/audio/codec/src/main.c b/tests/bluetooth/audio/codec/src/main.c index 28633716355..00226cd17f5 100644 --- a/tests/bluetooth/audio/codec/src/main.c +++ b/tests/bluetooth/audio/codec/src/main.c @@ -120,148 +120,151 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu) zassert_equal(ret, 1u, "unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_pref_context) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context) { - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, - BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | - BT_AUDIO_CONTEXT_TYPE_MEDIA)), - }; + const enum bt_audio_context ctx = + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA; + const struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, + BT_BYTES_LIST_LE16(ctx))}); int ret; - ret = bt_audio_codec_meta_get_pref_context(metadata, ARRAY_SIZE(metadata)); + ret = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg); zassert_equal(ret, 0x0005, "unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_stream_context) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_stream_context) { - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, - BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | - BT_AUDIO_CONTEXT_TYPE_MEDIA)), - }; + const enum bt_audio_context ctx = + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA; + const struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, + BT_BYTES_LIST_LE16(ctx))}); int ret; - ret = bt_audio_codec_meta_get_stream_context(metadata, ARRAY_SIZE(metadata)); - zassert_equal(ret, 0x0005, "Unexpected return value %d", ret); + ret = bt_audio_codec_cfg_meta_get_stream_context(&codec_cfg); + zassert_equal(ret, 0x0005, "unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_program_info) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_program_info) { const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'I', 'n', 'f', 'o'}; - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, - 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'I', 'n', 'f', 'o'), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, + 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', + 'I', 'n', 'f', 'o')}); const uint8_t *program_data; int ret; - ret = bt_audio_codec_meta_get_program_info(metadata, ARRAY_SIZE(metadata), &program_data); + ret = bt_audio_codec_cfg_meta_get_program_info(&codec_cfg, &program_data); zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data)); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_stream_lang) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_stream_lang) { const uint32_t expected_data = sys_get_le24((uint8_t[]){'e', 'n', 'g'}); - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_LANG, 'e', 'n', 'g'), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_LANG, 'e', 'n', 'g')}); int ret; - ret = bt_audio_codec_meta_get_stream_lang(metadata, ARRAY_SIZE(metadata)); + ret = bt_audio_codec_cfg_meta_get_stream_lang(&codec_cfg); zassert_equal(ret, expected_data, "Unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_ccid_list) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_ccid_list) { const uint8_t expected_data[] = {0x05, 0x10, 0x15}; - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)}); const uint8_t *ccid_list; int ret; - ret = bt_audio_codec_meta_get_ccid_list(metadata, ARRAY_SIZE(metadata), &ccid_list); + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_parental_rating) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_parental_rating) { - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, - BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE), - }; + const struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, + BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)}); int ret; - ret = bt_audio_codec_meta_get_parental_rating(metadata, ARRAY_SIZE(metadata)); + ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg); zassert_equal(ret, 0x07, "Unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_program_info_uri) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_program_info_uri) { const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'}; - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, - 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, + 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm')}); const uint8_t *program_info_uri; int ret; - ret = bt_audio_codec_meta_get_program_info_uri(metadata, ARRAY_SIZE(metadata), - &program_info_uri); + ret = bt_audio_codec_cfg_meta_get_program_info_uri(&codec_cfg, &program_info_uri); zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data)); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_audio_active_state) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_audio_active_state) { - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE, - BT_AUDIO_ACTIVE_STATE_ENABLED), - }; + const struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE, + BT_AUDIO_ACTIVE_STATE_ENABLED)}); int ret; - ret = bt_audio_codec_meta_get_audio_active_state(metadata, ARRAY_SIZE(metadata)); + ret = bt_audio_codec_cfg_meta_get_audio_active_state(&codec_cfg); zassert_equal(ret, 0x01, "Unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_broadcast_audio_immediate_rendering_flag) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag) { - const uint8_t metadata[] = {0x01, BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE}; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE)}); int ret; - ret = bt_audio_codec_meta_get_broadcast_audio_immediate_rendering_flag( - metadata, ARRAY_SIZE(metadata)); + ret = bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(&codec_cfg); zassert_equal(ret, 0, "Unexpected return value %d", ret); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_extended) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_extended) { const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03}; - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)}); const uint8_t *extended_meta; int ret; - ret = bt_audio_codec_meta_get_extended(metadata, ARRAY_SIZE(metadata), &extended_meta); + ret = bt_audio_codec_cfg_meta_get_extended(&codec_cfg, &extended_meta); zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data)); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_meta_get_vendor) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_vendor) { const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03}; - const uint8_t metadata[] = { - BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03), - }; + const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)}); const uint8_t *vendor_meta; int ret; - ret = bt_audio_codec_meta_get_vendor(metadata, ARRAY_SIZE(metadata), &vendor_meta); + ret = bt_audio_codec_cfg_meta_get_vendor(&codec_cfg, &vendor_meta); zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); zassert_mem_equal(expected_data, vendor_meta, ARRAY_SIZE(expected_data)); } @@ -339,3 +342,152 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_s ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap); zassert_equal(ret, 2, "Unexpected return value %d", ret); } + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_pref_context) +{ + const enum bt_audio_context ctx = + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA; + const struct bt_audio_codec_cap codec_cap = + BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, + BT_BYTES_LIST_LE16(ctx))}); + int ret; + + ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap); + zassert_equal(ret, 0x0005, "unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_stream_context) +{ + const enum bt_audio_context ctx = + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA; + const struct bt_audio_codec_cap codec_cap = + BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, + BT_BYTES_LIST_LE16(ctx))}); + int ret; + + ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap); + zassert_equal(ret, 0x0005, "unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info) +{ + const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', + 'I', 'n', 'f', 'o'}; + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, + 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', + 'I', 'n', 'f', 'o')}); + const uint8_t *program_data; + int ret; + + ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data)); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_stream_lang) +{ + const uint32_t expected_data = sys_get_le24((uint8_t[]){'e', 'n', 'g'}); + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_LANG, 'e', 'n', 'g')}); + int ret; + + ret = bt_audio_codec_cap_meta_get_stream_lang(&codec_cap); + zassert_equal(ret, expected_data, "Unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_ccid_list) +{ + const uint8_t expected_data[] = {0x05, 0x10, 0x15}; + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)}); + const uint8_t *ccid_list; + int ret; + + ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_parental_rating) +{ + const struct bt_audio_codec_cap codec_cap = + BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, + BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)}); + int ret; + + ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap); + zassert_equal(ret, 0x07, "Unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info_uri) +{ + const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'}; + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, + 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm')}); + const uint8_t *program_info_uri; + int ret; + + ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data)); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_audio_active_state) +{ + const struct bt_audio_codec_cap codec_cap = + BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE, + BT_AUDIO_ACTIVE_STATE_ENABLED)}); + int ret; + + ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap); + zassert_equal(ret, 0x01, "Unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag) +{ + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE)}); + int ret; + + ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap); + zassert_equal(ret, 0, "Unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_extended) +{ + const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03}; + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)}); + const uint8_t *extended_meta; + int ret; + + ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data)); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_vendor) +{ + const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03}; + const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)}); + const uint8_t *vendor_meta; + int ret; + + ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &vendor_meta); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, vendor_meta, ARRAY_SIZE(expected_data)); +}