LCOV - code coverage report
Current view: top level - zephyr/bluetooth/audio - audio.h Coverage Total Hit
Test: new.info Lines: 100.0 % 138 138
Test Date: 2025-09-25 19:22:35

            Line data    Source code
       1            1 : /**
       2              :  * @file
       3              :  * @brief Bluetooth Audio handling
       4              :  */
       5              : 
       6              : /*
       7              :  * Copyright (c) 2020 Intel Corporation
       8              :  * Copyright (c) 2020-2024 Nordic Semiconductor ASA
       9              :  *
      10              :  * SPDX-License-Identifier: Apache-2.0
      11              :  */
      12              : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_
      13              : #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_
      14              : 
      15              : /**
      16              :  * @brief Bluetooth Audio
      17              :  * @defgroup bt_audio Bluetooth Audio
      18              :  * @ingroup bluetooth
      19              :  * @{
      20              :  */
      21              : 
      22              : #include <stdbool.h>
      23              : #include <stddef.h>
      24              : #include <stdint.h>
      25              : 
      26              : #include <zephyr/autoconf.h>
      27              : #include <zephyr/bluetooth/audio/lc3.h>
      28              : #include <zephyr/bluetooth/assigned_numbers.h>
      29              : #include <zephyr/bluetooth/bluetooth.h>
      30              : #include <zephyr/bluetooth/buf.h>
      31              : #include <zephyr/bluetooth/conn.h>
      32              : #include <zephyr/bluetooth/gatt.h>
      33              : #include <zephyr/bluetooth/hci.h>
      34              : #include <zephyr/bluetooth/iso.h>
      35              : #include <zephyr/sys/atomic.h>
      36              : #include <zephyr/sys/util.h>
      37              : #include <zephyr/sys/util_macro.h>
      38              : 
      39              : #ifdef __cplusplus
      40              : extern "C" {
      41              : #endif
      42              : 
      43              : /** Size of the broadcast ID in octets */
      44            1 : #define BT_AUDIO_BROADCAST_ID_SIZE               3
      45              : /** Maximum broadcast ID value */
      46            1 : #define BT_AUDIO_BROADCAST_ID_MAX                0xFFFFFFU
      47              : /** Indicates that the server have no preference for the presentation delay */
      48            1 : #define BT_AUDIO_PD_PREF_NONE                    0x000000U
      49              : /** Maximum presentation delay in microseconds */
      50            1 : #define BT_AUDIO_PD_MAX                          0xFFFFFFU
      51              : /** Indicates that the unicast server does not have a preference for any retransmission number */
      52            1 : #define BT_AUDIO_RTN_PREF_NONE                   0xFFU
      53              : 
      54              : /** Size of the stream language value, e.g. "eng" */
      55            1 : #define BT_AUDIO_LANG_SIZE 3
      56              : 
      57              : /**
      58              :  * @brief Channel count support capability
      59              :  *
      60              :  * Macro accepts variable number of channel counts.
      61              :  * The allowed channel counts are defined by specification and have to be in range from
      62              :  * @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MIN to @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MAX inclusive.
      63              :  *
      64              :  * Example to support 1 and 3 channels:
      65              :  *   BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1, 3)
      66              :  */
      67            1 : #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(...)                                                 \
      68              :         ((enum bt_audio_codec_cap_chan_count)((FOR_EACH(BIT, (|), __VA_ARGS__)) >> 1))
      69              : 
      70              : /** struct to hold minimum and maximum supported codec frame sizes */
      71            1 : struct bt_audio_codec_octets_per_codec_frame {
      72              :         /** Minimum number of octets supported per codec frame */
      73            1 :         uint16_t min;
      74              :         /** Maximum number of octets supported per codec frame */
      75            1 :         uint16_t max;
      76              : };
      77              : 
      78              : /**
      79              :  * @brief Helper to check whether metadata type is known by the stack.
      80              :  *
      81              :  * @note @p _type is evaluated thrice.
      82              :  */
      83            1 : #define BT_AUDIO_METADATA_TYPE_IS_KNOWN(_type)                                                     \
      84              :         (IN_RANGE((_type), BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,                                    \
      85              :                   BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE) ||                                   \
      86              :          (_type) == BT_AUDIO_METADATA_TYPE_EXTENDED || (_type) == BT_AUDIO_METADATA_TYPE_VENDOR)
      87              : 
      88              : /**
      89              :  * @name Unicast Announcement Type
      90              :  * @{
      91              :  */
      92              : /** Unicast Server is connectable and is requesting a connection. */
      93            1 : #define BT_AUDIO_UNICAST_ANNOUNCEMENT_GENERAL    0x00
      94              : /** Unicast Server is connectable but is not requesting a connection. */
      95            1 : #define BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED   0x01
      96              : /** @} */
      97              : 
      98              : /**
      99              :  * @brief Helper to declare elements of bt_audio_codec_cap arrays
     100              :  *
     101              :  * This macro is mainly for creating an array of struct bt_audio_codec_cap data arrays.
     102              :  *
     103              :  * @param _type Type of advertising data field
     104              :  * @param _bytes Variable number of single-byte parameters
     105              :  */
     106            1 : #define BT_AUDIO_CODEC_DATA(_type, _bytes...)                                                      \
     107              :         (sizeof((uint8_t)_type) + sizeof((uint8_t[]){_bytes})), (_type), _bytes
     108              : 
     109              : /**
     110              :  * @brief Helper to declare @ref bt_audio_codec_cfg
     111              :  *
     112              :  * @param _id Codec ID
     113              :  * @param _cid Company ID
     114              :  * @param _vid Vendor ID
     115              :  * @param _data Codec Specific Data in LVT format
     116              :  * @param _meta Codec Specific Metadata in LVT format
     117              :  */
     118            1 : #define BT_AUDIO_CODEC_CFG(_id, _cid, _vid, _data, _meta)                                          \
     119              :         ((struct bt_audio_codec_cfg){                                                              \
     120              :                 /* Use HCI data path as default, can be overwritten by application */              \
     121              :                 .path_id = BT_ISO_DATA_PATH_HCI,                                                   \
     122              :                 .ctlr_transcode = false,                                                           \
     123              :                 COND_CODE_1(IS_ENABLED(CONFIG_BT_BAP_UNICAST),                                     \
     124              :                             (.target_latency = BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED,         \
     125              :                              .target_phy = BT_AUDIO_CODEC_CFG_TARGET_PHY_2M,),                     \
     126              :                             ())                                                                    \
     127              :                 .id = _id,                                                                         \
     128              :                 .cid = _cid,                                                                       \
     129              :                 .vid = _vid,                                                                       \
     130              :                 .data_len = sizeof((uint8_t[])_data),                                              \
     131              :                 .data = _data,                                                                     \
     132              :                 .meta_len = sizeof((uint8_t[])_meta),                                              \
     133              :                 .meta = _meta,                                                                     \
     134              :         })
     135              : 
     136              : /**
     137              :  * @brief Helper to declare @ref bt_audio_codec_cap structure
     138              :  *
     139              :  * @param _id Codec ID
     140              :  * @param _cid Company ID
     141              :  * @param _vid Vendor ID
     142              :  * @param _data Codec Specific Data in LVT format
     143              :  * @param _meta Codec Specific Metadata in LVT format
     144              :  */
     145            1 : #define BT_AUDIO_CODEC_CAP(_id, _cid, _vid, _data, _meta)                                          \
     146              :         ((struct bt_audio_codec_cap){                                                              \
     147              :                 /* Use HCI data path as default, can be overwritten by application */              \
     148              :                 .path_id = BT_ISO_DATA_PATH_HCI,                                                   \
     149              :                 .ctlr_transcode = false,                                                           \
     150              :                 .id = (_id),                                                                       \
     151              :                 .cid = (_cid),                                                                     \
     152              :                 .vid = (_vid),                                                                     \
     153              :                 .data_len = sizeof((uint8_t[])_data),                                              \
     154              :                 .data = _data,                                                                     \
     155              :                 .meta_len = sizeof((uint8_t[])_meta),                                              \
     156              :                 .meta = _meta,                                                                     \
     157              :         })
     158              : 
     159              : /** @brief Codec capability structure. */
     160            1 : struct bt_audio_codec_cap {
     161              :         /** Data path ID
     162              :          *
     163              :          * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
     164              :          * vendor specific ID.
     165              :          */
     166            1 :         uint8_t path_id;
     167              :         /** Whether or not the local controller should transcode
     168              :          *
     169              :          * This effectively sets the coding format for the ISO data path to @ref
     170              :          * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
     171              :          */
     172            1 :         bool ctlr_transcode;
     173              :         /** Codec ID */
     174            1 :         uint8_t id;
     175              :         /** Codec Company ID */
     176            1 :         uint16_t cid;
     177              :         /** Codec Company Vendor ID */
     178            1 :         uint16_t vid;
     179              : #if CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
     180              :         /** Codec Specific Capabilities Data count */
     181            1 :         size_t data_len;
     182              :         /** Codec Specific Capabilities Data */
     183            1 :         uint8_t data[CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE];
     184              : #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 */
     185              : #if defined(CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE) || defined(__DOXYGEN__)
     186              :         /** Codec Specific Capabilities Metadata count */
     187            1 :         size_t meta_len;
     188              :         /** Codec Specific Capabilities Metadata */
     189            1 :         uint8_t meta[CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE];
     190              : #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE */
     191              : };
     192              : 
     193              : /**
     194              :  * @brief Codec configuration target latency
     195              :  *
     196              :  * Set by the BAP Unicast Client to provide context for the BAP Unicast Server for the server to
     197              :  * set its QoS preferences.
     198              :  */
     199            1 : enum bt_audio_codec_cfg_target_latency {
     200              :         /** Target low latency */
     201              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_LOW = 0x01,
     202              : 
     203              :         /** Target balanced latency */
     204              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED = 0x02,
     205              : 
     206              :         /** Target high latency */
     207              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_HIGH = 0x03,
     208              : };
     209              : 
     210              : /**
     211              :  * @brief Codec configuration target PHY
     212              :  *
     213              :  * The target PHY to achieve the target latency (@ref bt_audio_codec_cfg_target_latency).
     214              :  */
     215            1 : enum bt_audio_codec_cfg_target_phy {
     216              :         /** LE 1M PHY */
     217              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_1M = 0x01,
     218              : 
     219              :         /** LE 2M PHY */
     220              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_2M = 0x02,
     221              : 
     222              :         /** LE Coded PHY */
     223              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_CODED = 0x03,
     224              : };
     225              : 
     226              : /** @brief Codec specific configuration structure. */
     227            1 : struct bt_audio_codec_cfg {
     228              :         /** Data path ID
     229              :          *
     230              :          * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
     231              :          * vendor specific ID.
     232              :          */
     233            1 :         uint8_t path_id;
     234              :         /** Whether or not the local controller should transcode
     235              :          *
     236              :          * This effectively sets the coding format for the ISO data path to @ref
     237              :          * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
     238              :          */
     239            1 :         bool ctlr_transcode;
     240              : #if defined(CONFIG_BT_BAP_UNICAST)
     241              :         /** Target latency
     242              :          *
     243              :          * Unused for broadcast streams.
     244              :          */
     245              :         enum bt_audio_codec_cfg_target_latency target_latency;
     246              :         /** Target PHY
     247              :          *
     248              :          * Unused for broadcast streams.
     249              :          */
     250              :         enum bt_audio_codec_cfg_target_phy target_phy;
     251              : #endif /* CONFIG_BT_BAP_UNICAST */
     252              :         /** Codec ID */
     253            1 :         uint8_t  id;
     254              :         /** Codec Company ID */
     255            1 :         uint16_t cid;
     256              :         /** Codec Company Vendor ID */
     257            1 :         uint16_t vid;
     258              : #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
     259              :         /** Codec Specific Capabilities Data count */
     260            1 :         size_t data_len;
     261              :         /** Codec Specific Capabilities Data */
     262            1 :         uint8_t data[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE];
     263              : #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
     264              : #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 || defined(__DOXYGEN__)
     265              :         /** Codec Specific Capabilities Metadata count */
     266            1 :         size_t meta_len;
     267              :         /** Codec Specific Capabilities Metadata */
     268            1 :         uint8_t meta[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE];
     269              : #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */
     270              : };
     271              : 
     272              : /**
     273              :  * @brief Helper for parsing length-type-value data.
     274              :  *
     275              :  * @param ltv       Length-type-value (LTV) encoded data.
     276              :  * @param size      Size of the @p ltv data.
     277              :  * @param func      Callback function which will be called for each element
     278              :  *                  that's found in the data. The callback should return
     279              :  *                  true to continue parsing, or false to stop parsing.
     280              :  * @param user_data User data to be passed to the callback.
     281              :  *
     282              :  * @retval 0 All entries were parsed.
     283              :  * @retval -EINVAL The data is incorrectly encoded
     284              :  * @retval -ECANCELED Parsing was prematurely cancelled by the callback
     285              :  */
     286            1 : int bt_audio_data_parse(const uint8_t ltv[], size_t size,
     287              :                         bool (*func)(struct bt_data *data, void *user_data), void *user_data);
     288              : 
     289              : /**
     290              :  * @brief Get the value of a specific data type in an length-type-value data array
     291              :  *
     292              :  * @param[in]  ltv_data The array containing the length-type-value tuples
     293              :  * @param[in]  size The size of @p ltv_data
     294              :  * @param[in]  type The type to get the value for. May be any type, but typically either
     295              :  *             @ref bt_audio_codec_cap_type, @ref bt_audio_codec_cfg_type or
     296              :  *             @ref bt_audio_metadata_type.
     297              :  * @param[out] data Pointer to the data-pointer to update when item is found.
     298              :  *                  Any found data will be little endian.
     299              :  *
     300              :  * @retval length The length of found @p data (may be 0).
     301              :  * @retval -EINVAL Arguments are invalid
     302              :  * @retval -ENODATA Data not found
     303              :  */
     304            1 : int bt_audio_data_get_val(const uint8_t ltv_data[], size_t size, uint8_t type,
     305              :                           const uint8_t **data);
     306              : 
     307              : /**
     308              :  * @brief Function to get the number of channels from the channel allocation
     309              :  *
     310              :  * @param chan_allocation The channel allocation
     311              :  *
     312              :  * @return The number of channels
     313              :  */
     314            1 : uint8_t bt_audio_get_chan_count(enum bt_audio_location chan_allocation);
     315              : 
     316              : /** @brief Audio direction from the perspective of the BAP Unicast Server / BAP Broadcast Sink */
     317            1 : enum bt_audio_dir {
     318              :         /**
     319              :          * @brief Audio direction sink
     320              :          *
     321              :          * For a BAP Unicast Client or Broadcast Source this is considered outgoing audio (TX).
     322              :          * For a BAP Unicast Server or Broadcast Sink this is considered incoming audio (RX).
     323              :          */
     324              :         BT_AUDIO_DIR_SINK = 0x01,
     325              :         /**
     326              :          * @brief Audio direction source
     327              :          *
     328              :          * For a BAP Unicast Client or Broadcast Source this is considered incoming audio (RX).
     329              :          * For a BAP Unicast Server or Broadcast Sink this is considered outgoing audio (TX).
     330              :          */
     331              :         BT_AUDIO_DIR_SOURCE = 0x02,
     332              : };
     333              : 
     334              : /**
     335              :  * @brief Audio codec Config APIs
     336              :  * @defgroup bt_audio_codec_cfg Codec config parsing APIs
     337              :  *
     338              :  * Functions to parse codec config data when formatted as LTV wrapped into @ref bt_audio_codec_cfg.
     339              :  *
     340              :  * @{
     341              :  */
     342              : 
     343              : /**
     344              :  * @brief Convert assigned numbers frequency to frequency value.
     345              :  *
     346              :  * @param freq The assigned numbers frequency to convert.
     347              :  *
     348              :  * @retval frequency The converted frequency value in Hz.
     349              :  * @retval -EINVAL Arguments are invalid.
     350              :  */
     351            1 : int bt_audio_codec_cfg_freq_to_freq_hz(enum bt_audio_codec_cfg_freq freq);
     352              : 
     353              : /**
     354              :  * @brief Convert frequency value to assigned numbers frequency.
     355              :  *
     356              :  * @param freq_hz The frequency value to convert.
     357              :  *
     358              :  * @retval frequency The assigned numbers frequency (@ref bt_audio_codec_cfg_freq).
     359              :  * @retval -EINVAL Arguments are invalid.
     360              :  */
     361            1 : int bt_audio_codec_cfg_freq_hz_to_freq(uint32_t freq_hz);
     362              : 
     363              : /**
     364              :  * @brief Extract the frequency from a codec configuration.
     365              :  *
     366              :  * @param codec_cfg The codec configuration to extract data from.
     367              :  *
     368              :  * @retval frequency A @ref bt_audio_codec_cfg_freq value
     369              :  * @retval -EINVAL Arguments are invalid
     370              :  * @retval -ENODATA Data not found
     371              :  * @retval -EBADMSG The found value has invalid size or value
     372              :  */
     373            1 : int bt_audio_codec_cfg_get_freq(const struct bt_audio_codec_cfg *codec_cfg);
     374              : 
     375              : /**
     376              :  * @brief Set the frequency of a codec configuration.
     377              :  *
     378              :  * @param codec_cfg The codec configuration to set data for.
     379              :  * @param freq      The assigned numbers frequency to set.
     380              :  *
     381              :  * @retval data_len The @p codec_cfg.data_len on success
     382              :  * @retval -EINVAL Arguments are invalid
     383              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     384              :  */
     385            1 : int bt_audio_codec_cfg_set_freq(struct bt_audio_codec_cfg *codec_cfg,
     386              :                                 enum bt_audio_codec_cfg_freq freq);
     387              : 
     388              : /**
     389              :  * @brief Convert assigned numbers frame duration to duration in microseconds.
     390              :  *
     391              :  * @param frame_dur The assigned numbers frame duration to convert.
     392              :  *
     393              :  * @retval duration The converted frame duration value in microseconds.
     394              :  * @retval -EINVAL Arguments are invalid.
     395              :  */
     396            1 : int bt_audio_codec_cfg_frame_dur_to_frame_dur_us(enum bt_audio_codec_cfg_frame_dur frame_dur);
     397              : 
     398              : /**
     399              :  * @brief Convert frame duration in microseconds to assigned numbers frame duration.
     400              :  *
     401              :  * @param frame_dur_us The frame duration in microseconds to convert.
     402              :  *
     403              :  * @retval duration The assigned numbers frame duration (@ref bt_audio_codec_cfg_frame_dur).
     404              :  * @retval -EINVAL Arguments are invalid.
     405              :  */
     406            1 : int bt_audio_codec_cfg_frame_dur_us_to_frame_dur(uint32_t frame_dur_us);
     407              : 
     408              : /**
     409              :  * @brief Extract frame duration from BT codec config
     410              :  *
     411              :  * @param codec_cfg The codec configuration to extract data from.
     412              :  *
     413              :  * @retval frequency A @ref bt_audio_codec_cfg_frame_dur value
     414              :  * @retval -EINVAL Arguments are invalid
     415              :  * @retval -ENODATA Data not found
     416              :  * @retval -EBADMSG The found value has invalid size or value
     417              :  */
     418            1 : int bt_audio_codec_cfg_get_frame_dur(const struct bt_audio_codec_cfg *codec_cfg);
     419              : 
     420              : /**
     421              :  * @brief Set the frame duration of a codec configuration.
     422              :  *
     423              :  * @param codec_cfg  The codec configuration to set data for.
     424              :  * @param frame_dur  The assigned numbers frame duration to set.
     425              :  *
     426              :  * @retval data_len The @p codec_cfg.data_len on success
     427              :  * @retval -EINVAL Arguments are invalid
     428              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     429              :  */
     430            1 : int bt_audio_codec_cfg_set_frame_dur(struct bt_audio_codec_cfg *codec_cfg,
     431              :                                      enum bt_audio_codec_cfg_frame_dur frame_dur);
     432              : 
     433              : /**
     434              :  * @brief Extract channel allocation from BT codec config
     435              :  *
     436              :  * The value returned is a bit field representing one or more audio locations as
     437              :  * specified by @ref bt_audio_location
     438              :  * Shall match one or more of the bits set in BT_PAC_SNK_LOC/BT_PAC_SRC_LOC.
     439              :  *
     440              :  * Up to the configured @ref BT_AUDIO_CODEC_CAP_TYPE_CHAN_COUNT number of channels can be present.
     441              :  *
     442              :  * @param codec_cfg The codec configuration to extract data from.
     443              :  * @param chan_allocation Pointer to the variable to store the extracted value in.
     444              :  * @param fallback_to_default If true this function will provide the default value of
     445              :  *        @ref BT_AUDIO_LOCATION_MONO_AUDIO if the type is not found when @p codec_cfg.id is @ref
     446              :  *        BT_HCI_CODING_FORMAT_LC3.
     447              :  *
     448              :  * @retval 0 Value is found and stored in the pointer provided
     449              :  * @retval -EINVAL Arguments are invalid
     450              :  * @retval -ENODATA Data not found
     451              :  * @retval -EBADMSG The found value has invalid size or value
     452              :  */
     453            1 : int bt_audio_codec_cfg_get_chan_allocation(const struct bt_audio_codec_cfg *codec_cfg,
     454              :                                            enum bt_audio_location *chan_allocation,
     455              :                                            bool fallback_to_default);
     456              : 
     457              : /**
     458              :  * @brief Set the channel allocation of a codec configuration.
     459              :  *
     460              :  * @param codec_cfg       The codec configuration to set data for.
     461              :  * @param chan_allocation The channel allocation to set.
     462              :  *
     463              :  * @retval data_len The @p codec_cfg.data_len on success
     464              :  * @retval -EINVAL Arguments are invalid
     465              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     466              :  */
     467            1 : int bt_audio_codec_cfg_set_chan_allocation(struct bt_audio_codec_cfg *codec_cfg,
     468              :                                            enum bt_audio_location chan_allocation);
     469              : 
     470              : /**
     471              :  * @brief Extract frame size in octets from BT codec config
     472              :  *
     473              :  * The overall SDU size will be octets_per_frame * blocks_per_sdu.
     474              :  *
     475              :  * The Bluetooth specifications are not clear about this value - it does not state that
     476              :  * the codec shall use this SDU size only. A codec like LC3 supports variable bit-rate
     477              :  * (per SDU) hence it might be allowed for an encoder to reduce the frame size below this
     478              :  * value.
     479              :  * Hence it is recommended to use the received SDU size and divide by
     480              :  * blocks_per_sdu rather than relying on this octets_per_sdu value to be fixed.
     481              :  *
     482              :  * @param codec_cfg The codec configuration to extract data from.
     483              :  *
     484              :  * @retval frame_length Frame length in octets
     485              :  * @retval -EINVAL Arguments are invalid
     486              :  * @retval -ENODATA Data not found
     487              :  * @retval -EBADMSG The found value has invalid size or value
     488              :  */
     489            1 : int bt_audio_codec_cfg_get_octets_per_frame(const struct bt_audio_codec_cfg *codec_cfg);
     490              : 
     491              : /**
     492              :  * @brief Set the octets per codec frame of a codec configuration.
     493              :  *
     494              :  * @param codec_cfg        The codec configuration to set data for.
     495              :  * @param octets_per_frame The octets per codec frame to set.
     496              :  *
     497              :  * @retval data_len The @p codec_cfg.data_len on success
     498              :  * @retval -EINVAL Arguments are invalid
     499              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     500              :  */
     501            1 : int bt_audio_codec_cfg_set_octets_per_frame(struct bt_audio_codec_cfg *codec_cfg,
     502              :                                             uint16_t octets_per_frame);
     503              : 
     504              : /**
     505              :  * @brief Extract number of audio frame blocks in each SDU from BT codec config
     506              :  *
     507              :  * The overall SDU size will be octets_per_frame * frame_blocks_per_sdu * number-of-channels.
     508              :  *
     509              :  * If this value is not present a default value of 1 shall be used.
     510              :  *
     511              :  * A frame block is one or more frames that represents data for the same period of time but
     512              :  * for different channels. If the stream have two audio channels and this value is two
     513              :  * there will be four frames in the SDU.
     514              :  *
     515              :  * @param codec_cfg The codec configuration to extract data from.
     516              :  * @param fallback_to_default If true this function will return the default value of 1
     517              :  *         if the type is not found when @p codec_cfg.id is @ref BT_HCI_CODING_FORMAT_LC3.
     518              :  *
     519              :  * @retval frame_blocks_per_sdu The count of codec frame blocks in each SDU.
     520              :  * @retval -EINVAL Arguments are invalid
     521              :  * @retval -ENODATA Data not found
     522              :  * @retval -EBADMSG The found value has invalid size or value
     523              :  */
     524            1 : int bt_audio_codec_cfg_get_frame_blocks_per_sdu(const struct bt_audio_codec_cfg *codec_cfg,
     525              :                                                 bool fallback_to_default);
     526              : 
     527              : /**
     528              :  * @brief Set the frame blocks per SDU of a codec configuration.
     529              :  *
     530              :  * @param codec_cfg    The codec configuration to set data for.
     531              :  * @param frame_blocks The frame blocks per SDU to set.
     532              :  *
     533              :  * @retval data_len The @p codec_cfg.data_len on success
     534              :  * @retval -EINVAL Arguments are invalid
     535              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     536              :  */
     537            1 : int bt_audio_codec_cfg_set_frame_blocks_per_sdu(struct bt_audio_codec_cfg *codec_cfg,
     538              :                                                 uint8_t frame_blocks);
     539              : 
     540              : /**
     541              :  * @brief Lookup a specific codec configuration value
     542              :  *
     543              :  * @param[in] codec_cfg The codec data to search in.
     544              :  * @param[in] type The type id to look for
     545              :  * @param[out] data Pointer to the data-pointer to update when item is found
     546              :  *
     547              :  * @retval len Length of found @p data (may be 0)
     548              :  * @retval -EINVAL Arguments are invalid
     549              :  * @retval -ENODATA Data not found
     550              :  */
     551            1 : int bt_audio_codec_cfg_get_val(const struct bt_audio_codec_cfg *codec_cfg,
     552              :                                enum bt_audio_codec_cfg_type type, const uint8_t **data);
     553              : 
     554              : /**
     555              :  * @brief Set or add a specific codec configuration value
     556              :  *
     557              :  * @param codec_cfg  The codec data to set the value in.
     558              :  * @param type       The type id to set
     559              :  * @param data       Pointer to the data-pointer to set
     560              :  * @param data_len   Length of @p data
     561              :  *
     562              :  * @retval data_len The @p codec_cfg.data_len on success
     563              :  * @retval -EINVAL Arguments are invalid
     564              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     565              :  */
     566            1 : int bt_audio_codec_cfg_set_val(struct bt_audio_codec_cfg *codec_cfg,
     567              :                                enum bt_audio_codec_cfg_type type, const uint8_t *data,
     568              :                                size_t data_len);
     569              : 
     570              : /**
     571              :  * @brief Unset a specific codec configuration value
     572              :  *
     573              :  * The type and the value will be removed from the codec configuration.
     574              :  *
     575              :  * @param codec_cfg  The codec data to set the value in.
     576              :  * @param type       The type id to unset.
     577              :  *
     578              :  * @retval data_len The @p codec_cfg.data_len on success
     579              :  * @retval -EINVAL Arguments are invalid
     580              :  */
     581            1 : int bt_audio_codec_cfg_unset_val(struct bt_audio_codec_cfg *codec_cfg,
     582              :                                  enum bt_audio_codec_cfg_type type);
     583              : 
     584              : /**
     585              :  * @brief Lookup a specific metadata value based on type
     586              :  *
     587              :  *
     588              :  * @param[in]  codec_cfg The codec data to search in.
     589              :  * @param[in]  type      The type id to look for
     590              :  * @param[out] data      Pointer to the data-pointer to update when item is found
     591              :  *
     592              :  * @retval len Length of found @p data (may be 0)
     593              :  * @retval -EINVAL Arguments are invalid
     594              :  * @retval -ENODATA Data not found
     595              :  */
     596            1 : int bt_audio_codec_cfg_meta_get_val(const struct bt_audio_codec_cfg *codec_cfg, uint8_t type,
     597              :                                     const uint8_t **data);
     598              : 
     599              : /**
     600              :  * @brief Set or add a specific codec configuration metadata value.
     601              :  *
     602              :  * @param codec_cfg  The codec configuration to set the value in.
     603              :  * @param type       The type id to set.
     604              :  * @param data       Pointer to the data-pointer to set.
     605              :  * @param data_len   Length of @p data.
     606              :  *
     607              :  * @retval meta_len The @p codec_cfg.meta_len on success
     608              :  * @retval -EINVAL Arguments are invalid
     609              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     610              :  */
     611            1 : int bt_audio_codec_cfg_meta_set_val(struct bt_audio_codec_cfg *codec_cfg,
     612              :                                     enum bt_audio_metadata_type type, const uint8_t *data,
     613              :                                     size_t data_len);
     614              : 
     615              : /**
     616              :  * @brief Unset a specific codec configuration metadata value
     617              :  *
     618              :  * The type and the value will be removed from the codec configuration metadata.
     619              :  *
     620              :  * @param codec_cfg  The codec data to set the value in.
     621              :  * @param type       The type id to unset.
     622              :  *
     623              :  * @retval meta_len The of @p codec_cfg.meta_len success
     624              :  * @retval -EINVAL Arguments are invalid
     625              :  */
     626            1 : int bt_audio_codec_cfg_meta_unset_val(struct bt_audio_codec_cfg *codec_cfg,
     627              :                                       enum bt_audio_metadata_type type);
     628              : /**
     629              :  * @brief Extract preferred contexts
     630              :  *
     631              :  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
     632              :  *
     633              :  * @param codec_cfg The codec data to search in.
     634              :  * @param fallback_to_default If true this function will provide the default value of
     635              :  *        @ref BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED if the type is not found when @p codec_cfg.id is
     636              :  *        @ref BT_HCI_CODING_FORMAT_LC3.
     637              :  *
     638              :  * @retval context The preferred context type if positive or 0
     639              :  * @retval -EINVAL Arguments are invalid
     640              :  * @retval -ENODATA Data not found
     641              :  * @retval -EBADMSG The found value has invalid size
     642              :  */
     643            1 : int bt_audio_codec_cfg_meta_get_pref_context(const struct bt_audio_codec_cfg *codec_cfg,
     644              :                                              bool fallback_to_default);
     645              : 
     646              : /**
     647              :  * @brief Set the preferred context of a codec configuration metadata.
     648              :  *
     649              :  * @param codec_cfg The codec configuration to set data for.
     650              :  * @param ctx       The preferred context to set.
     651              :  *
     652              :  * @retval data_len The @p codec_cfg.data_len on success
     653              :  * @retval -EINVAL Arguments are invalid
     654              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     655              :  */
     656            1 : int bt_audio_codec_cfg_meta_set_pref_context(struct bt_audio_codec_cfg *codec_cfg,
     657              :                                              enum bt_audio_context ctx);
     658              : 
     659              : /**
     660              :  * @brief Extract stream contexts
     661              :  *
     662              :  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
     663              :  *
     664              :  * @param codec_cfg The codec data to search in.
     665              :  *
     666              :  * @retval context The stream context type if positive or 0
     667              :  * @retval -EINVAL Arguments are invalid
     668              :  * @retval -ENODATA Data not found
     669              :  * @retval -EBADMSG The found value has invalid size
     670              :  */
     671            1 : int bt_audio_codec_cfg_meta_get_stream_context(const struct bt_audio_codec_cfg *codec_cfg);
     672              : 
     673              : /**
     674              :  * @brief Set the stream context of a codec configuration metadata.
     675              :  *
     676              :  * @param codec_cfg The codec configuration to set data for.
     677              :  * @param ctx       The stream context to set.
     678              :  *
     679              :  * @retval data_len The @p codec_cfg.data_len on success
     680              :  * @retval -EINVAL Arguments are invalid
     681              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     682              :  */
     683            1 : int bt_audio_codec_cfg_meta_set_stream_context(struct bt_audio_codec_cfg *codec_cfg,
     684              :                                                enum bt_audio_context ctx);
     685              : 
     686              : /**
     687              :  * @brief Extract program info
     688              :  *
     689              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
     690              :  *
     691              :  * @param[in]  codec_cfg    The codec data to search in.
     692              :  * @param[out] program_info Pointer to the UTF-8 formatted program info.
     693              :  *
     694              :  * @retval len The length of the @p program_info (may be 0)
     695              :  * @retval -EINVAL Arguments are invalid
     696              :  * @retval -ENODATA Data not found
     697              :  */
     698            1 : int bt_audio_codec_cfg_meta_get_program_info(const struct bt_audio_codec_cfg *codec_cfg,
     699              :                                              const uint8_t **program_info);
     700              : 
     701              : /**
     702              :  * @brief Set the program info of a codec configuration metadata.
     703              :  *
     704              :  * @param codec_cfg        The codec configuration to set data for.
     705              :  * @param program_info     The program info to set.
     706              :  * @param program_info_len The length of @p program_info.
     707              :  *
     708              :  * @retval data_len The @p codec_cfg.data_len on success
     709              :  * @retval -EINVAL Arguments are invalid
     710              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     711              :  */
     712            1 : int bt_audio_codec_cfg_meta_set_program_info(struct bt_audio_codec_cfg *codec_cfg,
     713              :                                              const uint8_t *program_info, size_t program_info_len);
     714              : 
     715              : /**
     716              :  * @brief Extract language
     717              :  *
     718              :  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
     719              :  *
     720              :  * @param[in]  codec_cfg The codec data to search in.
     721              :  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
     722              :  *
     723              :  * @retval 0 Success
     724              :  * @retval -EINVAL Arguments are invalid
     725              :  * @retval -ENODATA Data not found
     726              :  * @retval -EBADMSG The found value has invalid size
     727              :  */
     728            1 : int bt_audio_codec_cfg_meta_get_lang(const struct bt_audio_codec_cfg *codec_cfg,
     729              :                                      const uint8_t **lang);
     730              : 
     731              : /**
     732              :  * @brief Set the language of a codec configuration metadata.
     733              :  *
     734              :  * @param codec_cfg   The codec configuration to set data for.
     735              :  * @param lang        The 24-bit language to set.
     736              :  *
     737              :  * @retval data_len The @p codec_cfg.data_len on success
     738              :  * @retval -EINVAL Arguments are invalid
     739              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     740              :  */
     741            1 : int bt_audio_codec_cfg_meta_set_lang(struct bt_audio_codec_cfg *codec_cfg,
     742              :                                      const uint8_t lang[BT_AUDIO_LANG_SIZE]);
     743              : 
     744              : /**
     745              :  * @brief Extract CCID list
     746              :  *
     747              :  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
     748              :  *
     749              :  * @param[in]  codec_cfg The codec data to search in.
     750              :  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
     751              :  *
     752              :  * @retval len The length of the @p ccid_list (may be 0)
     753              :  * @retval -EINVAL Arguments are invalid
     754              :  * @retval -ENODATA Data not found
     755              :  */
     756            1 : int bt_audio_codec_cfg_meta_get_ccid_list(const struct bt_audio_codec_cfg *codec_cfg,
     757              :                                           const uint8_t **ccid_list);
     758              : 
     759              : /**
     760              :  * @brief Set the CCID list of a codec configuration metadata.
     761              :  *
     762              :  * @param codec_cfg     The codec configuration to set data for.
     763              :  * @param ccid_list     The program info to set.
     764              :  * @param ccid_list_len The length of @p ccid_list.
     765              :  *
     766              :  * @retval data_len The @p codec_cfg.data_len on success
     767              :  * @retval -EINVAL Arguments are invalid
     768              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     769              :  */
     770            1 : int bt_audio_codec_cfg_meta_set_ccid_list(struct bt_audio_codec_cfg *codec_cfg,
     771              :                                           const uint8_t *ccid_list, size_t ccid_list_len);
     772              : 
     773              : /**
     774              :  * @brief Extract parental rating
     775              :  *
     776              :  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
     777              :  *
     778              :  * @param codec_cfg The codec data to search in.
     779              :  *
     780              :  * @retval parental_rating The parental rating if positive or 0
     781              :  * @retval -EINVAL Arguments are invalid
     782              :  * @retval -ENODATA Data not found
     783              :  * @retval -EBADMSG The found value has invalid size
     784              :  */
     785            1 : int bt_audio_codec_cfg_meta_get_parental_rating(const struct bt_audio_codec_cfg *codec_cfg);
     786              : 
     787              : /**
     788              :  * @brief Set the parental rating of a codec configuration metadata.
     789              :  *
     790              :  * @param codec_cfg       The codec configuration to set data for.
     791              :  * @param parental_rating The parental rating to set.
     792              :  *
     793              :  * @retval data_len The @p codec_cfg.data_len on success
     794              :  * @retval -EINVAL Arguments are invalid
     795              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     796              :  */
     797            1 : int bt_audio_codec_cfg_meta_set_parental_rating(struct bt_audio_codec_cfg *codec_cfg,
     798              :                                                 enum bt_audio_parental_rating parental_rating);
     799              : 
     800              : /**
     801              :  * @brief Extract program info URI
     802              :  *
     803              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
     804              :  *
     805              :  * @param[in]  codec_cfg The codec data to search in.
     806              :  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
     807              :  *
     808              :  * @retval len The length of the @p program_info_uri (may be 0)
     809              :  * @retval -EINVAL Arguments are invalid
     810              :  * @retval -ENODATA Data not found
     811              :  */
     812            1 : int bt_audio_codec_cfg_meta_get_program_info_uri(const struct bt_audio_codec_cfg *codec_cfg,
     813              :                                                  const uint8_t **program_info_uri);
     814              : 
     815              : /**
     816              :  * @brief Set the program info URI of a codec configuration metadata.
     817              :  *
     818              :  * @param codec_cfg            The codec configuration to set data for.
     819              :  * @param program_info_uri     The program info URI to set.
     820              :  * @param program_info_uri_len The length of @p program_info_uri.
     821              :  *
     822              :  * @retval data_len The @p codec_cfg.data_len on success
     823              :  * @retval -EINVAL Arguments are invalid
     824              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     825              :  */
     826            1 : int bt_audio_codec_cfg_meta_set_program_info_uri(struct bt_audio_codec_cfg *codec_cfg,
     827              :                                                  const uint8_t *program_info_uri,
     828              :                                                  size_t program_info_uri_len);
     829              : 
     830              : /**
     831              :  * @brief Extract audio active state
     832              :  *
     833              :  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
     834              :  *
     835              :  * @param codec_cfg The codec data to search in.
     836              :  *
     837              :  * @retval context The preferred context type if positive or 0
     838              :  * @retval -EINVAL Arguments are invalid
     839              :  * @retval -ENODATA Data not found
     840              :  * @retval -EBADMSG The found value has invalid size
     841              :  */
     842            1 : int bt_audio_codec_cfg_meta_get_audio_active_state(const struct bt_audio_codec_cfg *codec_cfg);
     843              : 
     844              : /**
     845              :  * @brief Set the audio active state of a codec configuration metadata.
     846              :  *
     847              :  * @param codec_cfg The codec configuration to set data for.
     848              :  * @param state     The audio active state to set.
     849              :  *
     850              :  * @retval data_len The @p codec_cfg.data_len on success
     851              :  * @retval -EINVAL Arguments are invalid
     852              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     853              :  */
     854            1 : int bt_audio_codec_cfg_meta_set_audio_active_state(struct bt_audio_codec_cfg *codec_cfg,
     855              :                                                    enum bt_audio_active_state state);
     856              : 
     857              : /**
     858              :  * @brief Extract broadcast audio immediate rendering flag
     859              :  *
     860              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
     861              :  *
     862              :  * @param codec_cfg The codec data to search in.
     863              :  *
     864              :  * @retval 0 The flag was found
     865              :  * @retval -EINVAL Arguments are invalid
     866              :  * @retval -ENODATA The flag was not found
     867              :  */
     868            1 : int bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(
     869              :         const struct bt_audio_codec_cfg *codec_cfg);
     870              : 
     871              : /**
     872              :  * @brief Set the broadcast audio immediate rendering flag of a codec configuration metadata.
     873              :  *
     874              :  * @param codec_cfg The codec configuration to set data for.
     875              :  *
     876              :  * @retval data_len The @p codec_cfg.data_len on success
     877              :  * @retval -EINVAL Arguments are invalid
     878              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     879              :  */
     880            1 : int bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag(
     881              :         struct bt_audio_codec_cfg *codec_cfg);
     882              : 
     883              : /**
     884              :  * @brief Extract assisted listening stream
     885              :  *
     886              :  * See @ref BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM for more information about this value.
     887              :  *
     888              :  * @param codec_cfg The codec data to search in.
     889              :  *
     890              :  * @retval value The assisted listening stream value if positive or 0
     891              :  * @retval -EINVAL Arguments are invalid
     892              :  * @retval -ENODATA Data not found
     893              :  * @retval -EBADMSG The found value has invalid size
     894              :  */
     895            1 : int bt_audio_codec_cfg_meta_get_assisted_listening_stream(
     896              :         const struct bt_audio_codec_cfg *codec_cfg);
     897              : 
     898              : /**
     899              :  * @brief Set the assisted listening stream value of a codec configuration metadata.
     900              :  *
     901              :  * @param codec_cfg The codec configuration to set data for.
     902              :  * @param val       The assisted listening stream value to set.
     903              :  *
     904              :  * @retval data_len The @p codec_cap.data_len on success
     905              :  * @retval -EINVAL Arguments are invalid
     906              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     907              :  */
     908            1 : int bt_audio_codec_cfg_meta_set_assisted_listening_stream(
     909              :         struct bt_audio_codec_cfg *codec_cfg, enum bt_audio_assisted_listening_stream val);
     910              : 
     911              : /**
     912              :  * @brief Extract broadcast name
     913              :  *
     914              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_NAME for more information about this value.
     915              :  *
     916              :  * @param[in]  codec_cfg      The codec data to search in.
     917              :  * @param[out] broadcast_name Pointer to the UTF-8 formatted broadcast name.
     918              :  *
     919              :  * @retval length The length of the @p broadcast_name (may be 0)
     920              :  * @retval -EINVAL Arguments are invalid
     921              :  * @retval -ENODATA Data not found
     922              :  */
     923            1 : int bt_audio_codec_cfg_meta_get_broadcast_name(const struct bt_audio_codec_cfg *codec_cfg,
     924              :                                                const uint8_t **broadcast_name);
     925              : 
     926              : /**
     927              :  * @brief Set the broadcast name of a codec configuration metadata.
     928              :  *
     929              :  * @param codec_cfg          The codec configuration to set data for.
     930              :  * @param broadcast_name     The broadcast name to set.
     931              :  * @param broadcast_name_len The length of @p broadcast_name.
     932              :  *
     933              :  * @retval data_len The @p codec_cfg.data_len on success
     934              :  * @retval -EINVAL Arguments are invalid
     935              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     936              :  */
     937            1 : int bt_audio_codec_cfg_meta_set_broadcast_name(struct bt_audio_codec_cfg *codec_cfg,
     938              :                                                const uint8_t *broadcast_name,
     939              :                                                size_t broadcast_name_len);
     940              : 
     941              : /**
     942              :  * @brief Extract extended metadata
     943              :  *
     944              :  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
     945              :  *
     946              :  * @param[in]  codec_cfg     The codec data to search in.
     947              :  * @param[out] extended_meta Pointer to the extended metadata.
     948              :  *
     949              :  * @retval len The length of the @p extended_meta (may be 0)
     950              :  * @retval -EINVAL Arguments are invalid
     951              :  * @retval -ENODATA Data not found
     952              :  */
     953            1 : int bt_audio_codec_cfg_meta_get_extended(const struct bt_audio_codec_cfg *codec_cfg,
     954              :                                          const uint8_t **extended_meta);
     955              : 
     956              : /**
     957              :  * @brief Set the extended metadata of a codec configuration metadata.
     958              :  *
     959              :  * @param codec_cfg         The codec configuration to set data for.
     960              :  * @param extended_meta     The extended metadata to set.
     961              :  * @param extended_meta_len The length of @p extended_meta.
     962              :  *
     963              :  * @retval data_len The @p codec_cfg.data_len on success
     964              :  * @retval -EINVAL Arguments are invalid
     965              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     966              :  */
     967            1 : int bt_audio_codec_cfg_meta_set_extended(struct bt_audio_codec_cfg *codec_cfg,
     968              :                                          const uint8_t *extended_meta, size_t extended_meta_len);
     969              : 
     970              : /**
     971              :  * @brief Extract vendor specific metadata
     972              :  *
     973              :  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
     974              :  *
     975              :  * @param[in]  codec_cfg   The codec data to search in.
     976              :  * @param[out] vendor_meta Pointer to the vendor specific metadata.
     977              :  *
     978              :  * @retval len The length of the @p vendor_meta (may be 0)
     979              :  * @retval -EINVAL Arguments are invalid
     980              :  * @retval -ENODATA Data not found
     981              :  */
     982            1 : int bt_audio_codec_cfg_meta_get_vendor(const struct bt_audio_codec_cfg *codec_cfg,
     983              :                                        const uint8_t **vendor_meta);
     984              : 
     985              : /**
     986              :  * @brief Set the vendor specific metadata of a codec configuration metadata.
     987              :  *
     988              :  * @param codec_cfg       The codec configuration to set data for.
     989              :  * @param vendor_meta     The vendor specific metadata to set.
     990              :  * @param vendor_meta_len The length of @p vendor_meta.
     991              :  *
     992              :  * @retval data_len The @p codec_cfg.data_len on success
     993              :  * @retval -EINVAL Arguments are invalid
     994              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     995              :  */
     996            1 : int bt_audio_codec_cfg_meta_set_vendor(struct bt_audio_codec_cfg *codec_cfg,
     997              :                                        const uint8_t *vendor_meta, size_t vendor_meta_len);
     998              : /** @} */ /* End of bt_audio_codec_cfg */
     999              : 
    1000              : /**
    1001              :  * @brief Audio codec capabilities APIs
    1002              :  * @defgroup bt_audio_codec_cap Codec capability parsing APIs
    1003              :  *
    1004              :  * Functions to parse codec capability data when formatted as LTV wrapped into @ref
    1005              :  * bt_audio_codec_cap.
    1006              :  *
    1007              :  * @{
    1008              :  */
    1009              : 
    1010              : /**
    1011              :  * @brief Lookup a specific value based on type
    1012              :  *
    1013              :  * @param[in]  codec_cap The codec data to search in.
    1014              :  * @param[in]  type The type id to look for
    1015              :  * @param[out] data Pointer to the data-pointer to update when item is found
    1016              :  *
    1017              :  * @retval len Length of found @p data (may be 0)
    1018              :  * @retval -EINVAL Arguments are invalid
    1019              :  * @retval -ENODATA Data not found
    1020              :  */
    1021            1 : int bt_audio_codec_cap_get_val(const struct bt_audio_codec_cap *codec_cap,
    1022              :                                enum bt_audio_codec_cap_type type, const uint8_t **data);
    1023              : 
    1024              : /**
    1025              :  * @brief Set or add a specific codec capability value
    1026              :  *
    1027              :  * @param codec_cap  The codec data to set the value in.
    1028              :  * @param type       The type id to set
    1029              :  * @param data       Pointer to the data-pointer to set
    1030              :  * @param data_len   Length of @p data
    1031              :  *
    1032              :  * @retval data_len The @p codec_cap.data_len on success
    1033              :  * @retval -EINVAL Arguments are invalid
    1034              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1035              :  */
    1036            1 : int bt_audio_codec_cap_set_val(struct bt_audio_codec_cap *codec_cap,
    1037              :                                enum bt_audio_codec_cap_type type, const uint8_t *data,
    1038              :                                size_t data_len);
    1039              : 
    1040              : /**
    1041              :  * @brief Unset a specific codec capability value
    1042              :  *
    1043              :  * The type and the value will be removed from the codec capability.
    1044              :  *
    1045              :  * @param codec_cap  The codec data to set the value in.
    1046              :  * @param type       The type id to unset.
    1047              :  *
    1048              :  * @retval data_len The @p codec_cap.data_len on success
    1049              :  * @retval -EINVAL Arguments are invalid
    1050              :  */
    1051            1 : int bt_audio_codec_cap_unset_val(struct bt_audio_codec_cap *codec_cap,
    1052              :                                  enum bt_audio_codec_cap_type type);
    1053              : 
    1054              : /**
    1055              :  * @brief Extract the frequency from a codec capability.
    1056              :  *
    1057              :  * @param codec_cap The codec capabilities to extract data from.
    1058              :  *
    1059              :  * @retval frequencies Bitfield of supported frequencies (@ref bt_audio_codec_cap_freq) if 0 or
    1060              :  *                     positive
    1061              :  * @retval -EINVAL Arguments are invalid
    1062              :  * @retval -ENODATA Data not found
    1063              :  * @retval -EBADMSG The found value has invalid size or value
    1064              :  */
    1065            1 : int bt_audio_codec_cap_get_freq(const struct bt_audio_codec_cap *codec_cap);
    1066              : 
    1067              : /**
    1068              :  * @brief Set the supported frequencies of a codec capability.
    1069              :  *
    1070              :  * @param codec_cap The codec capabilities to set data for.
    1071              :  * @param freq      The supported frequencies to set.
    1072              :  *
    1073              :  * @retval data_len The @p codec_cap.data_len on success
    1074              :  * @retval -EINVAL Arguments are invalid
    1075              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1076              :  */
    1077            1 : int bt_audio_codec_cap_set_freq(struct bt_audio_codec_cap *codec_cap,
    1078              :                                 enum bt_audio_codec_cap_freq freq);
    1079              : 
    1080              : /**
    1081              :  * @brief Extract the frequency from a codec capability.
    1082              :  *
    1083              :  * @param codec_cap The codec capabilities to extract data from.
    1084              :  *
    1085              :  * @retval durations Bitfield of supported frame durations if 0 or positive
    1086              :  * @retval -EINVAL Arguments are invalid
    1087              :  * @retval -ENODATA Data not found
    1088              :  * @retval -EBADMSG The found value has invalid size or value
    1089              :  */
    1090            1 : int bt_audio_codec_cap_get_frame_dur(const struct bt_audio_codec_cap *codec_cap);
    1091              : 
    1092              : /**
    1093              :  * @brief Set the frame duration of a codec capability.
    1094              :  *
    1095              :  * @param codec_cap The codec capabilities to set data for.
    1096              :  * @param frame_dur The frame duration to set.
    1097              :  *
    1098              :  * @retval data_len The @p codec_cap.data_len on success
    1099              :  * @retval -EINVAL Arguments are invalid
    1100              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1101              :  */
    1102            1 : int bt_audio_codec_cap_set_frame_dur(struct bt_audio_codec_cap *codec_cap,
    1103              :                                      enum bt_audio_codec_cap_frame_dur frame_dur);
    1104              : 
    1105              : /**
    1106              :  * @brief Extract the frequency from a codec capability.
    1107              :  *
    1108              :  * @param codec_cap The codec capabilities to extract data from.
    1109              :  * @param fallback_to_default If true this function will provide the default value of 1
    1110              :  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
    1111              :  *
    1112              :  * @retval channel_counts Number of supported channel counts if 0 or positive
    1113              :  * @retval -EINVAL Arguments are invalid
    1114              :  * @retval -ENODATA Data not found
    1115              :  * @retval -EBADMSG The found value has invalid size or value
    1116              :  */
    1117            1 : int bt_audio_codec_cap_get_supported_audio_chan_counts(const struct bt_audio_codec_cap *codec_cap,
    1118              :                                                        bool fallback_to_default);
    1119              : 
    1120              : /**
    1121              :  * @brief Set the channel count of a codec capability.
    1122              :  *
    1123              :  * @param codec_cap The codec capabilities to set data for.
    1124              :  * @param chan_count The channel count frequency to set.
    1125              :  *
    1126              :  * @retval data_len The @p codec_cap.data_len on success
    1127              :  * @retval -EINVAL Arguments are invalid
    1128              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1129              :  */
    1130            1 : int bt_audio_codec_cap_set_supported_audio_chan_counts(
    1131              :         struct bt_audio_codec_cap *codec_cap, enum bt_audio_codec_cap_chan_count chan_count);
    1132              : 
    1133              : /**
    1134              :  * @brief Extract the supported octets per codec frame from a codec capability.
    1135              :  *
    1136              :  * @param[in]  codec_cap   The codec capabilities to extract data from.
    1137              :  * @param[out] codec_frame Struct to place the resulting values in
    1138              :  *
    1139              :  * @retval 0 Success
    1140              :  * @retval -EINVAL Arguments are invalid
    1141              :  * @retval -ENODATA Data not found
    1142              :  * @retval -EBADMSG The found value has invalid size or value
    1143              :  */
    1144            1 : int bt_audio_codec_cap_get_octets_per_frame(
    1145              :         const struct bt_audio_codec_cap *codec_cap,
    1146              :         struct bt_audio_codec_octets_per_codec_frame *codec_frame);
    1147              : 
    1148              : /**
    1149              :  * @brief Set the octets per codec frame of a codec capability.
    1150              :  *
    1151              :  * @param codec_cap   The codec capabilities to set data for.
    1152              :  * @param codec_frame The octets per codec frame to set.
    1153              :  *
    1154              :  * @retval data_len The @p codec_cap.data_len on success
    1155              :  * @retval -EINVAL Arguments are invalid
    1156              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1157              :  */
    1158            1 : int bt_audio_codec_cap_set_octets_per_frame(
    1159              :         struct bt_audio_codec_cap *codec_cap,
    1160              :         const struct bt_audio_codec_octets_per_codec_frame *codec_frame);
    1161              : 
    1162              : /**
    1163              :  * @brief Extract the maximum codec frames per SDU from a codec capability.
    1164              :  *
    1165              :  * @param codec_cap The codec capabilities to extract data from.
    1166              :  * @param fallback_to_default If true this function will provide the default value of 1
    1167              :  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
    1168              :  *
    1169              :  * @retval codec_frames_per_sdu Maximum number of codec frames per SDU supported
    1170              :  * @retval -EINVAL Arguments are invalid
    1171              :  * @retval -ENODATA Data not found
    1172              :  * @retval -EBADMSG The found value has invalid size or value
    1173              :  */
    1174            1 : int bt_audio_codec_cap_get_max_codec_frames_per_sdu(const struct bt_audio_codec_cap *codec_cap,
    1175              :                                                     bool fallback_to_default);
    1176              : 
    1177              : /**
    1178              :  * @brief Set the maximum codec frames per SDU of a codec capability.
    1179              :  *
    1180              :  * @param codec_cap            The codec capabilities to set data for.
    1181              :  * @param codec_frames_per_sdu The maximum codec frames per SDU to set.
    1182              :  *
    1183              :  * @retval data_len The @p codec_cap.data_len on success
    1184              :  * @retval -EINVAL Arguments are invalid
    1185              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1186              :  */
    1187            1 : int bt_audio_codec_cap_set_max_codec_frames_per_sdu(struct bt_audio_codec_cap *codec_cap,
    1188              :                                                     uint8_t codec_frames_per_sdu);
    1189              : 
    1190              : /**
    1191              :  * @brief Lookup a specific metadata value based on type
    1192              :  *
    1193              :  * @param[in]  codec_cap The codec data to search in.
    1194              :  * @param[in]  type      The type id to look for
    1195              :  * @param[out] data      Pointer to the data-pointer to update when item is found
    1196              :  *
    1197              :  * @retval len Length of found @p data (may be 0)
    1198              :  * @retval -EINVAL Arguments are invalid
    1199              :  * @retval -ENODATA Data not found
    1200              :  */
    1201            1 : int bt_audio_codec_cap_meta_get_val(const struct bt_audio_codec_cap *codec_cap, uint8_t type,
    1202              :                                     const uint8_t **data);
    1203              : 
    1204              : /**
    1205              :  * @brief Set or add a specific codec capability metadata value.
    1206              :  *
    1207              :  * @param codec_cap  The codec capability to set the value in.
    1208              :  * @param type       The type id to set.
    1209              :  * @param data       Pointer to the data-pointer to set.
    1210              :  * @param data_len   Length of @p data.
    1211              :  *
    1212              :  * @retval meta_len The @p codec_cap.meta_len on success
    1213              :  * @retval -EINVAL Arguments are invalid
    1214              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1215              :  */
    1216            1 : int bt_audio_codec_cap_meta_set_val(struct bt_audio_codec_cap *codec_cap,
    1217              :                                     enum bt_audio_metadata_type type, const uint8_t *data,
    1218              :                                     size_t data_len);
    1219              : 
    1220              : /**
    1221              :  * @brief Unset a specific codec capability metadata value
    1222              :  *
    1223              :  * The type and the value will be removed from the codec capability metadata.
    1224              :  *
    1225              :  * @param codec_cap  The codec data to set the value in.
    1226              :  * @param type       The type id to unset.
    1227              :  *
    1228              :  * @retval meta_len The of @p codec_cap.meta_len on success
    1229              :  * @retval -EINVAL Arguments are invalid
    1230              :  */
    1231            1 : int bt_audio_codec_cap_meta_unset_val(struct bt_audio_codec_cap *codec_cap,
    1232              :                                       enum bt_audio_metadata_type type);
    1233              : 
    1234              : /**
    1235              :  * @brief Extract preferred contexts
    1236              :  *
    1237              :  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
    1238              :  *
    1239              :  * @param codec_cap The codec data to search in.
    1240              :  *
    1241              :  * @retval The preferred context type if positive or 0
    1242              :  * @retval -EINVAL Arguments are invalid
    1243              :  * @retval -ENODATA Data not found
    1244              :  * @retval -EBADMSG The found value has invalid size
    1245              :  */
    1246            1 : int bt_audio_codec_cap_meta_get_pref_context(const struct bt_audio_codec_cap *codec_cap);
    1247              : 
    1248              : /**
    1249              :  * @brief Set the preferred context of a codec capability metadata.
    1250              :  *
    1251              :  * @param codec_cap The codec capability to set data for.
    1252              :  * @param ctx       The preferred context to set.
    1253              :  *
    1254              :  * @retval data_len The @p codec_cap.data_len on success
    1255              :  * @retval -EINVAL Arguments are invalid
    1256              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1257              :  */
    1258            1 : int bt_audio_codec_cap_meta_set_pref_context(struct bt_audio_codec_cap *codec_cap,
    1259              :                                              enum bt_audio_context ctx);
    1260              : 
    1261              : /**
    1262              :  * @brief Extract stream contexts
    1263              :  *
    1264              :  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
    1265              :  *
    1266              :  * @param codec_cap The codec data to search in.
    1267              :  *
    1268              :  * @retval context The stream context type if positive or 0
    1269              :  * @retval -EINVAL Arguments are invalid
    1270              :  * @retval -ENODATA Data not found
    1271              :  * @retval -EBADMSG The found value has invalid size
    1272              :  */
    1273            1 : int bt_audio_codec_cap_meta_get_stream_context(const struct bt_audio_codec_cap *codec_cap);
    1274              : 
    1275              : /**
    1276              :  * @brief Set the stream context of a codec capability metadata.
    1277              :  *
    1278              :  * @param codec_cap The codec capability to set data for.
    1279              :  * @param ctx       The stream context to set.
    1280              :  *
    1281              :  * @retval data_len The @p codec_cap.data_len on success
    1282              :  * @retval -EINVAL Arguments are invalid
    1283              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1284              :  */
    1285            1 : int bt_audio_codec_cap_meta_set_stream_context(struct bt_audio_codec_cap *codec_cap,
    1286              :                                                enum bt_audio_context ctx);
    1287              : 
    1288              : /**
    1289              :  * @brief Extract program info
    1290              :  *
    1291              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
    1292              :  *
    1293              :  * @param[in]  codec_cap    The codec data to search in.
    1294              :  * @param[out] program_info Pointer to the UTF-8 formatted program info.
    1295              :  *
    1296              :  * @retval len The length of the @p program_info (may be 0)
    1297              :  * @retval -EINVAL Arguments are invalid
    1298              :  * @retval -ENODATA Data not found
    1299              :  */
    1300            1 : int bt_audio_codec_cap_meta_get_program_info(const struct bt_audio_codec_cap *codec_cap,
    1301              :                                              const uint8_t **program_info);
    1302              : 
    1303              : /**
    1304              :  * @brief Set the program info of a codec capability metadata.
    1305              :  *
    1306              :  * @param codec_cap        The codec capability to set data for.
    1307              :  * @param program_info     The program info to set.
    1308              :  * @param program_info_len The length of @p program_info.
    1309              :  *
    1310              :  * @retval data_len The @p codec_cap.data_len on success
    1311              :  * @retval -EINVAL Arguments are invalid
    1312              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1313              :  */
    1314            1 : int bt_audio_codec_cap_meta_set_program_info(struct bt_audio_codec_cap *codec_cap,
    1315              :                                              const uint8_t *program_info, size_t program_info_len);
    1316              : 
    1317              : /**
    1318              :  * @brief Extract language
    1319              :  *
    1320              :  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
    1321              :  *
    1322              :  * @param[in]  codec_cap The codec data to search in.
    1323              :  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
    1324              :  *
    1325              :  * @retval 0 Success
    1326              :  * @retval -EINVAL Arguments are invalid
    1327              :  * @retval -ENODATA Data not found
    1328              :  * @retval -EBADMSG The found value has invalid size
    1329              :  */
    1330            1 : int bt_audio_codec_cap_meta_get_lang(const struct bt_audio_codec_cap *codec_cap,
    1331              :                                      const uint8_t **lang);
    1332              : 
    1333              : /**
    1334              :  * @brief Set the language of a codec capability metadata.
    1335              :  *
    1336              :  * @param codec_cap   The codec capability to set data for.
    1337              :  * @param lang        The 24-bit language to set.
    1338              :  *
    1339              :  * @retval data_len The @p codec_cap.data_len on success
    1340              :  * @retval -EINVAL Arguments are invalid
    1341              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1342              :  */
    1343            1 : int bt_audio_codec_cap_meta_set_lang(struct bt_audio_codec_cap *codec_cap,
    1344              :                                      const uint8_t lang[BT_AUDIO_LANG_SIZE]);
    1345              : 
    1346              : /**
    1347              :  * @brief Extract CCID list
    1348              :  *
    1349              :  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
    1350              :  *
    1351              :  * @param[in]  codec_cap The codec data to search in.
    1352              :  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
    1353              :  *
    1354              :  * @retval len The length of the @p ccid_list (may be 0)
    1355              :  * @retval -EINVAL Arguments are invalid
    1356              :  * @retval -ENODATA Data not found
    1357              :  */
    1358            1 : int bt_audio_codec_cap_meta_get_ccid_list(const struct bt_audio_codec_cap *codec_cap,
    1359              :                                           const uint8_t **ccid_list);
    1360              : 
    1361              : /**
    1362              :  * @brief Set the CCID list of a codec capability metadata.
    1363              :  *
    1364              :  * @param codec_cap     The codec capability to set data for.
    1365              :  * @param ccid_list     The program info to set.
    1366              :  * @param ccid_list_len The length of @p ccid_list.
    1367              :  *
    1368              :  * @retval data_len The @p codec_cap.data_len on success
    1369              :  * @retval -EINVAL Arguments are invalid
    1370              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1371              :  */
    1372            1 : int bt_audio_codec_cap_meta_set_ccid_list(struct bt_audio_codec_cap *codec_cap,
    1373              :                                           const uint8_t *ccid_list, size_t ccid_list_len);
    1374              : 
    1375              : /**
    1376              :  * @brief Extract parental rating
    1377              :  *
    1378              :  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
    1379              :  *
    1380              :  * @param codec_cap The codec data to search in.
    1381              :  *
    1382              :  * @retval The parental rating if positive or 0
    1383              :  * @retval -EINVAL Arguments are invalid
    1384              :  * @retval -ENODATA Data not found
    1385              :  * @retval -EBADMSG The found value has invalid size
    1386              :  */
    1387            1 : int bt_audio_codec_cap_meta_get_parental_rating(const struct bt_audio_codec_cap *codec_cap);
    1388              : 
    1389              : /**
    1390              :  * @brief Set the parental rating of a codec capability metadata.
    1391              :  *
    1392              :  * @param codec_cap       The codec capability to set data for.
    1393              :  * @param parental_rating The parental rating to set.
    1394              :  *
    1395              :  * @retval data_len The @p codec_cap.data_len on success
    1396              :  * @retval -EINVAL Arguments are invalid
    1397              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1398              :  */
    1399            1 : int bt_audio_codec_cap_meta_set_parental_rating(struct bt_audio_codec_cap *codec_cap,
    1400              :                                                 enum bt_audio_parental_rating parental_rating);
    1401              : 
    1402              : /**
    1403              :  * @brief Extract program info URI
    1404              :  *
    1405              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
    1406              :  *
    1407              :  * @param[in]  codec_cap        The codec data to search in.
    1408              :  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
    1409              :  *
    1410              :  * @retval len The length of the @p program_info_uri (may be 0)
    1411              :  * @retval -EINVAL Arguments are invalid
    1412              :  * @retval -ENODATA Data not found
    1413              :  */
    1414            1 : int bt_audio_codec_cap_meta_get_program_info_uri(const struct bt_audio_codec_cap *codec_cap,
    1415              :                                                  const uint8_t **program_info_uri);
    1416              : 
    1417              : /**
    1418              :  * @brief Set the program info URI of a codec capability metadata.
    1419              :  *
    1420              :  * @param codec_cap            The codec capability to set data for.
    1421              :  * @param program_info_uri     The program info URI to set.
    1422              :  * @param program_info_uri_len The length of @p program_info_uri.
    1423              :  *
    1424              :  * @retval data_len The @p codec_cap.data_len on success
    1425              :  * @retval -EINVAL Arguments are invalid
    1426              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1427              :  */
    1428            1 : int bt_audio_codec_cap_meta_set_program_info_uri(struct bt_audio_codec_cap *codec_cap,
    1429              :                                                  const uint8_t *program_info_uri,
    1430              :                                                  size_t program_info_uri_len);
    1431              : 
    1432              : /**
    1433              :  * @brief Extract audio active state
    1434              :  *
    1435              :  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
    1436              :  *
    1437              :  * @param codec_cap The codec data to search in.
    1438              :  *
    1439              :  * @retval context The preferred context type if positive or 0
    1440              :  * @retval -EINVAL Arguments are invalid
    1441              :  * @retval -ENODATA Data not found
    1442              :  * @retval -EBADMSG The found value has invalid size
    1443              :  */
    1444            1 : int bt_audio_codec_cap_meta_get_audio_active_state(const struct bt_audio_codec_cap *codec_cap);
    1445              : 
    1446              : /**
    1447              :  * @brief Set the audio active state of a codec capability metadata.
    1448              :  *
    1449              :  * @param codec_cap The codec capability to set data for.
    1450              :  * @param state     The audio active state to set.
    1451              :  *
    1452              :  * @retval data_len The @p codec_cap.data_len on success
    1453              :  * @retval -EINVAL Arguments are invalid
    1454              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1455              :  */
    1456            1 : int bt_audio_codec_cap_meta_set_audio_active_state(struct bt_audio_codec_cap *codec_cap,
    1457              :                                                    enum bt_audio_active_state state);
    1458              : 
    1459              : /**
    1460              :  * @brief Extract broadcast audio immediate rendering flag
    1461              :  *
    1462              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
    1463              :  *
    1464              :  * @param codec_cap The codec data to search in.
    1465              :  *
    1466              :  * @retval 0 The flag was found
    1467              :  * @retval -EINVAL Arguments are invalid
    1468              :  * @retval -ENODATA The flag was not found
    1469              :  */
    1470            1 : int bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(
    1471              :         const struct bt_audio_codec_cap *codec_cap);
    1472              : 
    1473              : /**
    1474              :  * @brief Set the broadcast audio immediate rendering flag of a codec capability metadata.
    1475              :  *
    1476              :  * @param codec_cap The codec capability to set data for.
    1477              :  *
    1478              :  * @retval data_len The @p codec_cap.data_len on success
    1479              :  * @retval -EINVAL Arguments are invalid
    1480              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1481              :  */
    1482            1 : int bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag(
    1483              :         struct bt_audio_codec_cap *codec_cap);
    1484              : 
    1485              : /**
    1486              :  * @brief Extract assisted listening stream
    1487              :  *
    1488              :  * See @ref BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM for more information about this value.
    1489              :  *
    1490              :  * @param codec_cap The codec data to search in.
    1491              :  *
    1492              :  * @retval value The assisted listening stream value if positive or 0
    1493              :  * @retval -EINVAL Arguments are invalid
    1494              :  * @retval -ENODATA Data not found
    1495              :  * @retval -EBADMSG The found value has invalid size
    1496              :  */
    1497            1 : int bt_audio_codec_cap_meta_get_assisted_listening_stream(
    1498              :         const struct bt_audio_codec_cap *codec_cap);
    1499              : 
    1500              : /**
    1501              :  * @brief Set the assisted listening stream value of a codec capability metadata.
    1502              :  *
    1503              :  * @param codec_cap The codec capability to set data for.
    1504              :  * @param val       The assisted listening stream value to set.
    1505              :  *
    1506              :  * @retval data_len The @p codec_cap.data_len on success
    1507              :  * @retval -EINVAL Arguments are invalid
    1508              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1509              :  */
    1510            1 : int bt_audio_codec_cap_meta_set_assisted_listening_stream(
    1511              :         struct bt_audio_codec_cap *codec_cap, enum bt_audio_assisted_listening_stream val);
    1512              : 
    1513              : /**
    1514              :  * @brief Extract broadcast name
    1515              :  *
    1516              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_NAME for more information about this value.
    1517              :  *
    1518              :  * @param[in]  codec_cap      The codec data to search in.
    1519              :  * @param[out] broadcast_name Pointer to the UTF-8 formatted broadcast name.
    1520              :  *
    1521              :  * @retval length The length of the @p broadcast_name (may be 0)
    1522              :  * @retval -EINVAL Arguments are invalid
    1523              :  * @retval -ENODATA Data not found
    1524              :  */
    1525            1 : int bt_audio_codec_cap_meta_get_broadcast_name(const struct bt_audio_codec_cap *codec_cap,
    1526              :                                                const uint8_t **broadcast_name);
    1527              : 
    1528              : /**
    1529              :  * @brief Set the broadcast name of a codec capability metadata.
    1530              :  *
    1531              :  * @param codec_cap          The codec capability to set data for.
    1532              :  * @param broadcast_name     The broadcast name to set.
    1533              :  * @param broadcast_name_len The length of @p broadcast_name.
    1534              :  *
    1535              :  * @retval data_len The @p codec_cap.data_len on success
    1536              :  * @retval -EINVAL Arguments are invalid
    1537              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1538              :  */
    1539            1 : int bt_audio_codec_cap_meta_set_broadcast_name(struct bt_audio_codec_cap *codec_cap,
    1540              :                                                const uint8_t *broadcast_name,
    1541              :                                                size_t broadcast_name_len);
    1542              : /**
    1543              :  * @brief Extract extended metadata
    1544              :  *
    1545              :  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
    1546              :  *
    1547              :  * @param[in]  codec_cap     The codec data to search in.
    1548              :  * @param[out] extended_meta Pointer to the extended metadata.
    1549              :  *
    1550              :  * @retval len The length of the @p extended_meta (may be 0)
    1551              :  * @retval -EINVAL Arguments are invalid
    1552              :  * @retval -ENODATA Data not found
    1553              :  */
    1554            1 : int bt_audio_codec_cap_meta_get_extended(const struct bt_audio_codec_cap *codec_cap,
    1555              :                                          const uint8_t **extended_meta);
    1556              : 
    1557              : /**
    1558              :  * @brief Set the extended metadata of a codec capability metadata.
    1559              :  *
    1560              :  * @param codec_cap         The codec capability to set data for.
    1561              :  * @param extended_meta     The extended metadata to set.
    1562              :  * @param extended_meta_len The length of @p extended_meta.
    1563              :  *
    1564              :  * @retval data_len The @p codec_cap.data_len on success
    1565              :  * @retval -EINVAL Arguments are invalid
    1566              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1567              :  */
    1568            1 : int bt_audio_codec_cap_meta_set_extended(struct bt_audio_codec_cap *codec_cap,
    1569              :                                          const uint8_t *extended_meta, size_t extended_meta_len);
    1570              : 
    1571              : /**
    1572              :  * @brief Extract vendor specific metadata
    1573              :  *
    1574              :  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
    1575              :  *
    1576              :  * @param[in]  codec_cap   The codec data to search in.
    1577              :  * @param[out] vendor_meta Pointer to the vendor specific metadata.
    1578              :  *
    1579              :  * @retval len The length of the @p vendor_meta (may be 0)
    1580              :  * @retval -EINVAL Arguments are invalid
    1581              :  * @retval -ENODATA Data not found
    1582              :  */
    1583            1 : int bt_audio_codec_cap_meta_get_vendor(const struct bt_audio_codec_cap *codec_cap,
    1584              :                                        const uint8_t **vendor_meta);
    1585              : 
    1586              : /**
    1587              :  * @brief Set the vendor specific metadata of a codec capability metadata.
    1588              :  *
    1589              :  * @param codec_cap       The codec capability to set data for.
    1590              :  * @param vendor_meta     The vendor specific metadata to set.
    1591              :  * @param vendor_meta_len The length of @p vendor_meta.
    1592              :  *
    1593              :  * @retval data_len The @p codec_cap.data_len on success
    1594              :  * @retval -EINVAL Arguments are invalid
    1595              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1596              :  */
    1597            1 : int bt_audio_codec_cap_meta_set_vendor(struct bt_audio_codec_cap *codec_cap,
    1598              :                                        const uint8_t *vendor_meta, size_t vendor_meta_len);
    1599              : 
    1600              : /** @} */ /* End of bt_audio_codec_cap */
    1601              : 
    1602              : /**
    1603              :  * @brief Assigned numbers to string API
    1604              :  * @defgroup bt_audio_to_str Assigned numbers to string API
    1605              :  *
    1606              :  * Functions to return string representation of Bluetooth Audio assigned number values.
    1607              :  *
    1608              :  * @{
    1609              :  */
    1610              : 
    1611              : /**
    1612              :  * @brief Returns a string representation of a specific @ref bt_audio_context bit
    1613              :  *
    1614              :  * If @p context contains multiple bits, it will return "Unknown context"
    1615              :  *
    1616              :  * @param context A single context bit
    1617              :  *
    1618              :  * @return String representation of the supplied bit
    1619              :  */
    1620            1 : static inline char *bt_audio_context_bit_to_str(enum bt_audio_context context)
    1621              : {
    1622              :         switch (context) {
    1623              :         case BT_AUDIO_CONTEXT_TYPE_NONE:
    1624              :                 return "None";
    1625              :         case BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED:
    1626              :                 return "Unspecified";
    1627              :         case BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL:
    1628              :                 return "Conversational";
    1629              :         case BT_AUDIO_CONTEXT_TYPE_MEDIA:
    1630              :                 return "Media";
    1631              :         case BT_AUDIO_CONTEXT_TYPE_GAME:
    1632              :                 return "Game";
    1633              :         case BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL:
    1634              :                 return "Instructional";
    1635              :         case BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS:
    1636              :                 return "Voice assistant";
    1637              :         case BT_AUDIO_CONTEXT_TYPE_LIVE:
    1638              :                 return "Live";
    1639              :         case BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS:
    1640              :                 return "Sound effects";
    1641              :         case BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS:
    1642              :                 return "Notifications";
    1643              :         case BT_AUDIO_CONTEXT_TYPE_RINGTONE:
    1644              :                 return "Ringtone";
    1645              :         case BT_AUDIO_CONTEXT_TYPE_ALERTS:
    1646              :                 return "Alerts";
    1647              :         case BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM:
    1648              :                 return "Emergency alarm";
    1649              :         default:
    1650              :                 return "Unknown context";
    1651              :         }
    1652              : }
    1653              : 
    1654              : /**
    1655              :  * @brief Returns a string representation of a @ref bt_audio_parental_rating value
    1656              :  *
    1657              :  * @param parental_rating The parental rating value
    1658              :  *
    1659              :  * @return String representation of the supplied parental rating value
    1660              :  */
    1661            1 : static inline char *bt_audio_parental_rating_to_str(enum bt_audio_parental_rating parental_rating)
    1662              : {
    1663              :         switch (parental_rating) {
    1664              :         case BT_AUDIO_PARENTAL_RATING_NO_RATING:
    1665              :                 return "No rating";
    1666              :         case BT_AUDIO_PARENTAL_RATING_AGE_ANY:
    1667              :                 return "Any";
    1668              :         case BT_AUDIO_PARENTAL_RATING_AGE_5_OR_ABOVE:
    1669              :                 return "Age 5 or above";
    1670              :         case BT_AUDIO_PARENTAL_RATING_AGE_6_OR_ABOVE:
    1671              :                 return "Age 6 or above";
    1672              :         case BT_AUDIO_PARENTAL_RATING_AGE_7_OR_ABOVE:
    1673              :                 return "Age 7 or above";
    1674              :         case BT_AUDIO_PARENTAL_RATING_AGE_8_OR_ABOVE:
    1675              :                 return "Age 8 or above";
    1676              :         case BT_AUDIO_PARENTAL_RATING_AGE_9_OR_ABOVE:
    1677              :                 return "Age 9 or above";
    1678              :         case BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE:
    1679              :                 return "Age 10 or above";
    1680              :         case BT_AUDIO_PARENTAL_RATING_AGE_11_OR_ABOVE:
    1681              :                 return "Age 11 or above";
    1682              :         case BT_AUDIO_PARENTAL_RATING_AGE_12_OR_ABOVE:
    1683              :                 return "Age 12 or above";
    1684              :         case BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE:
    1685              :                 return "Age 13 or above";
    1686              :         case BT_AUDIO_PARENTAL_RATING_AGE_14_OR_ABOVE:
    1687              :                 return "Age 14 or above";
    1688              :         case BT_AUDIO_PARENTAL_RATING_AGE_15_OR_ABOVE:
    1689              :                 return "Age 15 or above";
    1690              :         case BT_AUDIO_PARENTAL_RATING_AGE_16_OR_ABOVE:
    1691              :                 return "Age 16 or above";
    1692              :         case BT_AUDIO_PARENTAL_RATING_AGE_17_OR_ABOVE:
    1693              :                 return "Age 17 or above";
    1694              :         case BT_AUDIO_PARENTAL_RATING_AGE_18_OR_ABOVE:
    1695              :                 return "Age 18 or above";
    1696              :         default:
    1697              :                 return "Unknown rating";
    1698              :         }
    1699              : }
    1700              : 
    1701              : /**
    1702              :  * @brief Returns a string representation of a @ref bt_audio_active_state value
    1703              :  *
    1704              :  * @param state The active state value
    1705              :  *
    1706              :  * @return String representation of the supplied active state value
    1707              :  */
    1708            1 : static inline char *bt_audio_active_state_to_str(enum bt_audio_active_state state)
    1709              : {
    1710              :         switch (state) {
    1711              :         case BT_AUDIO_ACTIVE_STATE_DISABLED:
    1712              :                 return "Disabled";
    1713              :         case BT_AUDIO_ACTIVE_STATE_ENABLED:
    1714              :                 return "Enabled";
    1715              :         default:
    1716              :                 return "Unknown active state";
    1717              :         }
    1718              : }
    1719              : 
    1720              : /**
    1721              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_freq bit
    1722              :  *
    1723              :  * If @p freq contains multiple bits, it will return "Unknown supported frequency"
    1724              :  *
    1725              :  * @param freq A single frequency bit
    1726              :  *
    1727              :  * @return String representation of the supplied bit
    1728              :  */
    1729            1 : static inline char *bt_audio_codec_cap_freq_bit_to_str(enum bt_audio_codec_cap_freq freq)
    1730              : {
    1731              :         switch (freq) {
    1732              :         case BT_AUDIO_CODEC_CAP_FREQ_8KHZ:
    1733              :                 return "8000 Hz";
    1734              :         case BT_AUDIO_CODEC_CAP_FREQ_11KHZ:
    1735              :                 return "11025 Hz";
    1736              :         case BT_AUDIO_CODEC_CAP_FREQ_16KHZ:
    1737              :                 return "16000 Hz";
    1738              :         case BT_AUDIO_CODEC_CAP_FREQ_22KHZ:
    1739              :                 return "22050 Hz";
    1740              :         case BT_AUDIO_CODEC_CAP_FREQ_24KHZ:
    1741              :                 return "24000 Hz";
    1742              :         case BT_AUDIO_CODEC_CAP_FREQ_32KHZ:
    1743              :                 return "32000 Hz";
    1744              :         case BT_AUDIO_CODEC_CAP_FREQ_44KHZ:
    1745              :                 return "44100 Hz";
    1746              :         case BT_AUDIO_CODEC_CAP_FREQ_48KHZ:
    1747              :                 return "48000 Hz";
    1748              :         case BT_AUDIO_CODEC_CAP_FREQ_88KHZ:
    1749              :                 return "88200 Hz";
    1750              :         case BT_AUDIO_CODEC_CAP_FREQ_96KHZ:
    1751              :                 return "96000 Hz";
    1752              :         case BT_AUDIO_CODEC_CAP_FREQ_176KHZ:
    1753              :                 return "176400 Hz";
    1754              :         case BT_AUDIO_CODEC_CAP_FREQ_192KHZ:
    1755              :                 return "192000 Hz";
    1756              :         case BT_AUDIO_CODEC_CAP_FREQ_384KHZ:
    1757              :                 return "384000 Hz";
    1758              :         default:
    1759              :                 return "Unknown supported frequency";
    1760              :         }
    1761              : }
    1762              : 
    1763              : /**
    1764              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_frame_dur bit
    1765              :  *
    1766              :  * If @p frame_dur contains multiple bits, it will return "Unknown frame duration"
    1767              :  *
    1768              :  * @param frame_dur A single frame duration bit
    1769              :  *
    1770              :  * @return String representation of the supplied bit
    1771              :  */
    1772              : static inline char *
    1773            1 : bt_audio_codec_cap_frame_dur_bit_to_str(enum bt_audio_codec_cap_frame_dur frame_dur)
    1774              : {
    1775              :         switch (frame_dur) {
    1776              :         case BT_AUDIO_CODEC_CAP_DURATION_7_5:
    1777              :                 return "7.5 ms";
    1778              :         case BT_AUDIO_CODEC_CAP_DURATION_10:
    1779              :                 return "10 ms";
    1780              :         case BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5:
    1781              :                 return "7.5 ms preferred";
    1782              :         case BT_AUDIO_CODEC_CAP_DURATION_PREFER_10:
    1783              :                 return "10 ms preferred";
    1784              :         default:
    1785              :                 return "Unknown frame duration";
    1786              :         }
    1787              : }
    1788              : 
    1789              : /**
    1790              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_chan_count bit
    1791              :  *
    1792              :  * If @p chan_count contains multiple bits, it will return "Unknown channel count"
    1793              :  *
    1794              :  * @param chan_count A single frame channel count bit
    1795              :  *
    1796              :  * @return String representation of the supplied bit
    1797              :  */
    1798              : static inline char *
    1799            1 : bt_audio_codec_cap_chan_count_bit_to_str(enum bt_audio_codec_cap_chan_count chan_count)
    1800              : {
    1801              :         switch (chan_count) {
    1802              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_1:
    1803              :                 return "1 channel";
    1804              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_2:
    1805              :                 return "2 channels";
    1806              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_3:
    1807              :                 return "3 channels";
    1808              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_4:
    1809              :                 return "4 channels";
    1810              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_5:
    1811              :                 return "5 channels";
    1812              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_6:
    1813              :                 return "6 channels";
    1814              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_7:
    1815              :                 return "7 channels";
    1816              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_8:
    1817              :                 return "8 channels";
    1818              :         default:
    1819              :                 return "Unknown channel count";
    1820              :         }
    1821              : }
    1822              : 
    1823              : /**
    1824              :  * @brief Returns a string representation of a specific @ref bt_audio_location bit
    1825              :  *
    1826              :  * If @p location contains multiple bits, it will return "Unknown location"
    1827              :  *
    1828              :  * @param location A single location bit
    1829              :  *
    1830              :  * @return String representation of the supplied bit
    1831              :  */
    1832            1 : static inline char *bt_audio_location_bit_to_str(enum bt_audio_location location)
    1833              : {
    1834              :         switch (location) {
    1835              :         case BT_AUDIO_LOCATION_MONO_AUDIO:
    1836              :                 return "Mono";
    1837              :         case BT_AUDIO_LOCATION_FRONT_LEFT:
    1838              :                 return "Front left";
    1839              :         case BT_AUDIO_LOCATION_FRONT_RIGHT:
    1840              :                 return "Front right";
    1841              :         case BT_AUDIO_LOCATION_FRONT_CENTER:
    1842              :                 return "Front center";
    1843              :         case BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1:
    1844              :                 return "Low frequency effects 1";
    1845              :         case BT_AUDIO_LOCATION_BACK_LEFT:
    1846              :                 return "Back left";
    1847              :         case BT_AUDIO_LOCATION_BACK_RIGHT:
    1848              :                 return "Back right";
    1849              :         case BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER:
    1850              :                 return "Front left of center";
    1851              :         case BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER:
    1852              :                 return "Front right of center";
    1853              :         case BT_AUDIO_LOCATION_BACK_CENTER:
    1854              :                 return "Back center";
    1855              :         case BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2:
    1856              :                 return "Low frequency effects 2";
    1857              :         case BT_AUDIO_LOCATION_SIDE_LEFT:
    1858              :                 return "Side left";
    1859              :         case BT_AUDIO_LOCATION_SIDE_RIGHT:
    1860              :                 return "Side right";
    1861              :         case BT_AUDIO_LOCATION_TOP_FRONT_LEFT:
    1862              :                 return "Top front left";
    1863              :         case BT_AUDIO_LOCATION_TOP_FRONT_RIGHT:
    1864              :                 return "Top front right";
    1865              :         case BT_AUDIO_LOCATION_TOP_FRONT_CENTER:
    1866              :                 return "Top front center";
    1867              :         case BT_AUDIO_LOCATION_TOP_CENTER:
    1868              :                 return "Top center";
    1869              :         case BT_AUDIO_LOCATION_TOP_BACK_LEFT:
    1870              :                 return "Top back left";
    1871              :         case BT_AUDIO_LOCATION_TOP_BACK_RIGHT:
    1872              :                 return "Top back right";
    1873              :         case BT_AUDIO_LOCATION_TOP_SIDE_LEFT:
    1874              :                 return "Top side left";
    1875              :         case BT_AUDIO_LOCATION_TOP_SIDE_RIGHT:
    1876              :                 return "Top side right";
    1877              :         case BT_AUDIO_LOCATION_TOP_BACK_CENTER:
    1878              :                 return "Top back center";
    1879              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER:
    1880              :                 return "Bottom front center";
    1881              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT:
    1882              :                 return "Bottom front left";
    1883              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT:
    1884              :                 return "Bottom front right";
    1885              :         case BT_AUDIO_LOCATION_FRONT_LEFT_WIDE:
    1886              :                 return "Front left wide";
    1887              :         case BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE:
    1888              :                 return "Front right wde";
    1889              :         case BT_AUDIO_LOCATION_LEFT_SURROUND:
    1890              :                 return "Left surround";
    1891              :         case BT_AUDIO_LOCATION_RIGHT_SURROUND:
    1892              :                 return "Right surround";
    1893              :         default:
    1894              :                 return "Unknown location";
    1895              :         }
    1896              : }
    1897              : 
    1898              : /** @} */ /* End of bt_audio_to_str */
    1899              : #ifdef __cplusplus
    1900              : }
    1901              : #endif
    1902              : 
    1903              : /** @} */ /* end of bt_audio */
    1904              : 
    1905              : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_H_ */
        

Generated by: LCOV version 2.0-1