LCOV - code coverage report
Current view: top level - zephyr/bluetooth/audio - audio.h Coverage Total Hit
Test: new.info Lines: 100.0 % 157 157
Test Date: 2025-09-05 20:47:19

            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/bluetooth.h>
      29              : #include <zephyr/bluetooth/buf.h>
      30              : #include <zephyr/bluetooth/conn.h>
      31              : #include <zephyr/bluetooth/gatt.h>
      32              : #include <zephyr/bluetooth/hci.h>
      33              : #include <zephyr/bluetooth/iso.h>
      34              : #include <zephyr/sys/atomic.h>
      35              : #include <zephyr/sys/util.h>
      36              : #include <zephyr/sys/util_macro.h>
      37              : 
      38              : #ifdef __cplusplus
      39              : extern "C" {
      40              : #endif
      41              : 
      42              : /** Size of the broadcast ID in octets */
      43            1 : #define BT_AUDIO_BROADCAST_ID_SIZE               3
      44              : /** Maximum broadcast ID value */
      45            1 : #define BT_AUDIO_BROADCAST_ID_MAX                0xFFFFFFU
      46              : /** Indicates that the server have no preference for the presentation delay */
      47            1 : #define BT_AUDIO_PD_PREF_NONE                    0x000000U
      48              : /** Maximum presentation delay in microseconds */
      49            1 : #define BT_AUDIO_PD_MAX                          0xFFFFFFU
      50              : /** Indicates that the unicast server does not have a preference for any retransmission number */
      51            1 : #define BT_AUDIO_RTN_PREF_NONE                   0xFFU
      52              : /** The minimum size of a Broadcast Name as defined by Bluetooth Assigned Numbers */
      53            1 : #define BT_AUDIO_BROADCAST_NAME_LEN_MIN          4
      54              : /** The maximum size of a Broadcast Name as defined by Bluetooth Assigned Numbers */
      55            1 : #define BT_AUDIO_BROADCAST_NAME_LEN_MAX          128
      56              : 
      57              : /** Size of the stream language value, e.g. "eng" */
      58            1 : #define BT_AUDIO_LANG_SIZE 3
      59              : 
      60              : /**
      61              :  * @brief Codec capability types
      62              :  *
      63              :  * Used to build and parse codec capabilities as specified in the PAC specification.
      64              :  * Source is assigned numbers for Generic Audio, bluetooth.com.
      65              :  */
      66            1 : enum bt_audio_codec_cap_type {
      67              :         /** Supported sampling frequencies */
      68              :         BT_AUDIO_CODEC_CAP_TYPE_FREQ = 0x01,
      69              : 
      70              :         /** Supported frame durations */
      71              :         BT_AUDIO_CODEC_CAP_TYPE_DURATION = 0x02,
      72              : 
      73              :         /** Supported audio channel counts */
      74              :         BT_AUDIO_CODEC_CAP_TYPE_CHAN_COUNT = 0x03,
      75              : 
      76              :         /** Supported octets per codec frame */
      77              :         BT_AUDIO_CODEC_CAP_TYPE_FRAME_LEN = 0x04,
      78              : 
      79              :         /** Supported maximum codec frames per SDU  */
      80              :         BT_AUDIO_CODEC_CAP_TYPE_FRAME_COUNT = 0x05,
      81              : };
      82              : 
      83              : /** @brief Supported frequencies bitfield */
      84            1 : enum bt_audio_codec_cap_freq {
      85              :         /** 8 Khz sampling frequency */
      86              :         BT_AUDIO_CODEC_CAP_FREQ_8KHZ = BIT(0),
      87              : 
      88              :         /** 11.025 Khz sampling frequency */
      89              :         BT_AUDIO_CODEC_CAP_FREQ_11KHZ = BIT(1),
      90              : 
      91              :         /** 16 Khz sampling frequency */
      92              :         BT_AUDIO_CODEC_CAP_FREQ_16KHZ = BIT(2),
      93              : 
      94              :         /** 22.05 Khz sampling frequency */
      95              :         BT_AUDIO_CODEC_CAP_FREQ_22KHZ = BIT(3),
      96              : 
      97              :         /** 24 Khz sampling frequency */
      98              :         BT_AUDIO_CODEC_CAP_FREQ_24KHZ = BIT(4),
      99              : 
     100              :         /** 32 Khz sampling frequency */
     101              :         BT_AUDIO_CODEC_CAP_FREQ_32KHZ = BIT(5),
     102              : 
     103              :         /** 44.1 Khz sampling frequency */
     104              :         BT_AUDIO_CODEC_CAP_FREQ_44KHZ = BIT(6),
     105              : 
     106              :         /** 48 Khz sampling frequency */
     107              :         BT_AUDIO_CODEC_CAP_FREQ_48KHZ = BIT(7),
     108              : 
     109              :         /** 88.2 Khz sampling frequency */
     110              :         BT_AUDIO_CODEC_CAP_FREQ_88KHZ = BIT(8),
     111              : 
     112              :         /** 96 Khz sampling frequency */
     113              :         BT_AUDIO_CODEC_CAP_FREQ_96KHZ = BIT(9),
     114              : 
     115              :         /** 176.4 Khz sampling frequency */
     116              :         BT_AUDIO_CODEC_CAP_FREQ_176KHZ = BIT(10),
     117              : 
     118              :         /** 192 Khz sampling frequency */
     119              :         BT_AUDIO_CODEC_CAP_FREQ_192KHZ = BIT(11),
     120              : 
     121              :         /** 384 Khz sampling frequency */
     122              :         BT_AUDIO_CODEC_CAP_FREQ_384KHZ = BIT(12),
     123              : 
     124              :         /** Any frequency capability */
     125              :         BT_AUDIO_CODEC_CAP_FREQ_ANY =
     126              :                 (BT_AUDIO_CODEC_CAP_FREQ_8KHZ | BT_AUDIO_CODEC_CAP_FREQ_11KHZ |
     127              :                  BT_AUDIO_CODEC_CAP_FREQ_16KHZ | BT_AUDIO_CODEC_CAP_FREQ_22KHZ |
     128              :                  BT_AUDIO_CODEC_CAP_FREQ_24KHZ | BT_AUDIO_CODEC_CAP_FREQ_32KHZ |
     129              :                  BT_AUDIO_CODEC_CAP_FREQ_44KHZ | BT_AUDIO_CODEC_CAP_FREQ_48KHZ |
     130              :                  BT_AUDIO_CODEC_CAP_FREQ_88KHZ | BT_AUDIO_CODEC_CAP_FREQ_96KHZ |
     131              :                  BT_AUDIO_CODEC_CAP_FREQ_176KHZ | BT_AUDIO_CODEC_CAP_FREQ_192KHZ |
     132              :                  BT_AUDIO_CODEC_CAP_FREQ_384KHZ),
     133              : };
     134              : 
     135              : /** @brief Supported frame durations bitfield */
     136            1 : enum bt_audio_codec_cap_frame_dur {
     137              :         /** 7.5 msec frame duration capability */
     138              :         BT_AUDIO_CODEC_CAP_DURATION_7_5 = BIT(0),
     139              : 
     140              :         /** 10 msec frame duration capability */
     141              :         BT_AUDIO_CODEC_CAP_DURATION_10 = BIT(1),
     142              : 
     143              :         /** Any frame duration capability */
     144              :         BT_AUDIO_CODEC_CAP_DURATION_ANY =
     145              :                 (BT_AUDIO_CODEC_CAP_DURATION_7_5 | BT_AUDIO_CODEC_CAP_DURATION_10),
     146              : 
     147              :         /**
     148              :          * @brief 7.5 msec preferred frame duration capability.
     149              :          *
     150              :          * This shall only be set if @ref BT_AUDIO_CODEC_CAP_DURATION_7_5 is also set, and if @ref
     151              :          * BT_AUDIO_CODEC_CAP_DURATION_PREFER_10 is not set.
     152              :          */
     153              :         BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5 = BIT(4),
     154              : 
     155              :         /**
     156              :          * @brief 10 msec preferred frame duration capability
     157              :          *
     158              :          * This shall only be set if @ref BT_AUDIO_CODEC_CAP_DURATION_10 is also set, and if @ref
     159              :          * BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5 is not set.
     160              :          */
     161              :         BT_AUDIO_CODEC_CAP_DURATION_PREFER_10 = BIT(5),
     162              : };
     163              : 
     164              : /** Supported audio capabilities channel count bitfield */
     165            1 : enum bt_audio_codec_cap_chan_count {
     166              :         /** Supporting 1 channel */
     167              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_1 = BIT(0),
     168              : 
     169              :         /** Supporting 2 channel */
     170              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_2 = BIT(1),
     171              : 
     172              :         /** Supporting 3 channel */
     173              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_3 = BIT(2),
     174              : 
     175              :         /** Supporting 4 channel */
     176              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_4 = BIT(3),
     177              : 
     178              :         /** Supporting 5 channel */
     179              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_5 = BIT(4),
     180              : 
     181              :         /** Supporting 6 channel */
     182              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_6 = BIT(5),
     183              : 
     184              :         /** Supporting 7 channel */
     185              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_7 = BIT(6),
     186              : 
     187              :         /** Supporting 8 channel */
     188              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_8 = BIT(7),
     189              : 
     190              :         /** Supporting all channels */
     191              :         BT_AUDIO_CODEC_CAP_CHAN_COUNT_ANY =
     192              :                 (BT_AUDIO_CODEC_CAP_CHAN_COUNT_1 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_2 |
     193              :                  BT_AUDIO_CODEC_CAP_CHAN_COUNT_3 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_4 |
     194              :                  BT_AUDIO_CODEC_CAP_CHAN_COUNT_5 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_6 |
     195              :                  BT_AUDIO_CODEC_CAP_CHAN_COUNT_7 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_8),
     196              : };
     197              : 
     198              : /** Minimum supported channel counts */
     199            1 : #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_MIN 1
     200              : /** Maximum supported channel counts */
     201            1 : #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_MAX 8
     202              : 
     203              : /**
     204              :  * @brief Channel count support capability
     205              :  *
     206              :  * Macro accepts variable number of channel counts.
     207              :  * The allowed channel counts are defined by specification and have to be in range from
     208              :  * @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MIN to @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MAX inclusive.
     209              :  *
     210              :  * Example to support 1 and 3 channels:
     211              :  *   BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1, 3)
     212              :  */
     213            1 : #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(...)                                                 \
     214              :         ((enum bt_audio_codec_cap_chan_count)((FOR_EACH(BIT, (|), __VA_ARGS__)) >> 1))
     215              : 
     216              : /** struct to hold minimum and maximum supported codec frame sizes */
     217            1 : struct bt_audio_codec_octets_per_codec_frame {
     218              :         /** Minimum number of octets supported per codec frame */
     219            1 :         uint16_t min;
     220              :         /** Maximum number of octets supported per codec frame */
     221            1 :         uint16_t max;
     222              : };
     223              : 
     224              : /**
     225              :  * @brief Codec configuration types
     226              :  *
     227              :  * Used to build and parse codec configurations as specified in the ASCS and BAP specifications.
     228              :  * Source is assigned numbers for Generic Audio, bluetooth.com.
     229              :  */
     230            1 : enum bt_audio_codec_cfg_type {
     231              :         /** Sampling frequency */
     232              :         BT_AUDIO_CODEC_CFG_FREQ = 0x01,
     233              : 
     234              :         /** Frame duration */
     235              :         BT_AUDIO_CODEC_CFG_DURATION = 0x02,
     236              : 
     237              :         /** Audio channel allocation */
     238              :         BT_AUDIO_CODEC_CFG_CHAN_ALLOC = 0x03,
     239              : 
     240              :         /** Octets per codec frame */
     241              :         BT_AUDIO_CODEC_CFG_FRAME_LEN = 0x04,
     242              : 
     243              :         /** Codec frame blocks per SDU */
     244              :         BT_AUDIO_CODEC_CFG_FRAME_BLKS_PER_SDU = 0x05,
     245              : };
     246              : 
     247              : /** Codec configuration sampling freqency */
     248            1 : enum bt_audio_codec_cfg_freq {
     249              :         /** 8 Khz codec sampling frequency */
     250              :         BT_AUDIO_CODEC_CFG_FREQ_8KHZ = 0x01,
     251              : 
     252              :         /** 11.025 Khz codec sampling frequency */
     253              :         BT_AUDIO_CODEC_CFG_FREQ_11KHZ = 0x02,
     254              : 
     255              :         /** 16 Khz codec sampling frequency */
     256              :         BT_AUDIO_CODEC_CFG_FREQ_16KHZ = 0x03,
     257              : 
     258              :         /** 22.05 Khz codec sampling frequency */
     259              :         BT_AUDIO_CODEC_CFG_FREQ_22KHZ = 0x04,
     260              : 
     261              :         /** 24 Khz codec sampling frequency */
     262              :         BT_AUDIO_CODEC_CFG_FREQ_24KHZ = 0x05,
     263              : 
     264              :         /** 32 Khz codec sampling frequency */
     265              :         BT_AUDIO_CODEC_CFG_FREQ_32KHZ = 0x06,
     266              : 
     267              :         /** 44.1 Khz codec sampling frequency */
     268              :         BT_AUDIO_CODEC_CFG_FREQ_44KHZ = 0x07,
     269              : 
     270              :         /** 48 Khz codec sampling frequency */
     271              :         BT_AUDIO_CODEC_CFG_FREQ_48KHZ = 0x08,
     272              : 
     273              :         /** 88.2 Khz codec sampling frequency */
     274              :         BT_AUDIO_CODEC_CFG_FREQ_88KHZ = 0x09,
     275              : 
     276              :         /** 96 Khz codec sampling frequency */
     277              :         BT_AUDIO_CODEC_CFG_FREQ_96KHZ = 0x0a,
     278              : 
     279              :         /** 176.4 Khz codec sampling frequency */
     280              :         BT_AUDIO_CODEC_CFG_FREQ_176KHZ = 0x0b,
     281              : 
     282              :         /** 192 Khz codec sampling frequency */
     283              :         BT_AUDIO_CODEC_CFG_FREQ_192KHZ = 0x0c,
     284              : 
     285              :         /** 384 Khz codec sampling frequency */
     286              :         BT_AUDIO_CODEC_CFG_FREQ_384KHZ = 0x0d,
     287              : };
     288              : 
     289              : /** Codec configuration frame duration */
     290            1 : enum bt_audio_codec_cfg_frame_dur {
     291              :         /** 7.5 msec Frame Duration configuration */
     292              :         BT_AUDIO_CODEC_CFG_DURATION_7_5 = 0x00,
     293              : 
     294              :         /** 10 msec Frame Duration configuration */
     295              :         BT_AUDIO_CODEC_CFG_DURATION_10 = 0x01,
     296              : };
     297              : 
     298              : /**
     299              :  * @brief Audio Context Type for Generic Audio
     300              :  *
     301              :  * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
     302              :  */
     303            1 : enum bt_audio_context {
     304              :         /** No context type */
     305              :         BT_AUDIO_CONTEXT_TYPE_NONE = 0,
     306              :         /**
     307              :          * Identifies audio where the use case context does not match any other defined value,
     308              :          * or where the context is unknown or cannot be determined.
     309              :          */
     310              :         BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED = BIT(0),
     311              :         /**
     312              :          * Conversation between humans, for example, in telephony or video calls, including
     313              :          * traditional cellular as well as VoIP and Push-to-Talk
     314              :          */
     315              :         BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL = BIT(1),
     316              :         /** Media, for example, music playback, radio, podcast or movie soundtrack, or tv audio */
     317              :         BT_AUDIO_CONTEXT_TYPE_MEDIA = BIT(2),
     318              :         /**
     319              :          * Audio associated with video gaming, for example gaming media; gaming effects; music
     320              :          * and in-game voice chat between participants; or a mix of all the above
     321              :          */
     322              :         BT_AUDIO_CONTEXT_TYPE_GAME = BIT(3),
     323              :         /** Instructional audio, for example, in navigation, announcements, or user guidance */
     324              :         BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL = BIT(4),
     325              :         /** Man-machine communication, for example, with voice recognition or virtual assistants */
     326              :         BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS = BIT(5),
     327              :         /**
     328              :          * Live audio, for example, from a microphone where audio is perceived both through a
     329              :          * direct acoustic path and through an LE Audio Stream
     330              :          */
     331              :         BT_AUDIO_CONTEXT_TYPE_LIVE = BIT(6),
     332              :         /**
     333              :          * Sound effects including keyboard and touch feedback; menu and user interface sounds;
     334              :          * and other system sounds
     335              :          */
     336              :         BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS = BIT(7),
     337              :         /**
     338              :          * Notification and reminder sounds; attention-seeking audio, for example,
     339              :          * in beeps signaling the arrival of a message
     340              :          */
     341              :         BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS = BIT(8),
     342              :         /**
     343              :          * Alerts the user to an incoming call, for example, an incoming telephony or video call,
     344              :          * including traditional cellular as well as VoIP and Push-to-Talk
     345              :          */
     346              :         BT_AUDIO_CONTEXT_TYPE_RINGTONE = BIT(9),
     347              :         /**
     348              :          * Alarms and timers; immediate alerts, for example, in a critical battery alarm,
     349              :          * timer expiry or alarm clock, toaster, cooker, kettle, microwave, etc.
     350              :          */
     351              :         BT_AUDIO_CONTEXT_TYPE_ALERTS = BIT(10),
     352              :         /** Emergency alarm Emergency sounds, for example, fire alarms or other urgent alerts */
     353              :         BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM = BIT(11),
     354              : };
     355              : 
     356              : /**
     357              :  * Any known context.
     358              :  */
     359            1 : #define BT_AUDIO_CONTEXT_TYPE_ANY        (BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | \
     360              :                                           BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | \
     361              :                                           BT_AUDIO_CONTEXT_TYPE_MEDIA | \
     362              :                                           BT_AUDIO_CONTEXT_TYPE_GAME | \
     363              :                                           BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL | \
     364              :                                           BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS | \
     365              :                                           BT_AUDIO_CONTEXT_TYPE_LIVE | \
     366              :                                           BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS | \
     367              :                                           BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS | \
     368              :                                           BT_AUDIO_CONTEXT_TYPE_RINGTONE | \
     369              :                                           BT_AUDIO_CONTEXT_TYPE_ALERTS | \
     370              :                                           BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM)
     371              : 
     372              : /**
     373              :  * @brief Parental rating defined by the Generic Audio assigned numbers (bluetooth.com).
     374              :  *
     375              :  * The numbering scheme is aligned with Annex F of EN 300 707 v1.2.1 which
     376              :  * defined parental rating for viewing.
     377              :  */
     378            1 : enum bt_audio_parental_rating {
     379              :         /** No rating */
     380              :         BT_AUDIO_PARENTAL_RATING_NO_RATING        = 0x00,
     381              :         /** For all ages */
     382              :         BT_AUDIO_PARENTAL_RATING_AGE_ANY          = 0x01,
     383              :         /** Recommended for listeners of age 5 and above */
     384              :         BT_AUDIO_PARENTAL_RATING_AGE_5_OR_ABOVE   = 0x02,
     385              :         /** Recommended for listeners of age 6 and above */
     386              :         BT_AUDIO_PARENTAL_RATING_AGE_6_OR_ABOVE   = 0x03,
     387              :         /** Recommended for listeners of age 7 and above */
     388              :         BT_AUDIO_PARENTAL_RATING_AGE_7_OR_ABOVE   = 0x04,
     389              :         /** Recommended for listeners of age 8 and above */
     390              :         BT_AUDIO_PARENTAL_RATING_AGE_8_OR_ABOVE   = 0x05,
     391              :         /** Recommended for listeners of age 9 and above */
     392              :         BT_AUDIO_PARENTAL_RATING_AGE_9_OR_ABOVE   = 0x06,
     393              :         /** Recommended for listeners of age 10 and above */
     394              :         BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE  = 0x07,
     395              :         /** Recommended for listeners of age 11 and above */
     396              :         BT_AUDIO_PARENTAL_RATING_AGE_11_OR_ABOVE  = 0x08,
     397              :         /** Recommended for listeners of age 12 and above */
     398              :         BT_AUDIO_PARENTAL_RATING_AGE_12_OR_ABOVE  = 0x09,
     399              :         /** Recommended for listeners of age 13 and above */
     400              :         BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE  = 0x0A,
     401              :         /** Recommended for listeners of age 14 and above */
     402              :         BT_AUDIO_PARENTAL_RATING_AGE_14_OR_ABOVE  = 0x0B,
     403              :         /** Recommended for listeners of age 15 and above */
     404              :         BT_AUDIO_PARENTAL_RATING_AGE_15_OR_ABOVE  = 0x0C,
     405              :         /** Recommended for listeners of age 16 and above */
     406              :         BT_AUDIO_PARENTAL_RATING_AGE_16_OR_ABOVE  = 0x0D,
     407              :         /** Recommended for listeners of age 17 and above */
     408              :         BT_AUDIO_PARENTAL_RATING_AGE_17_OR_ABOVE  = 0x0E,
     409              :         /** Recommended for listeners of age 18 and above */
     410              :         BT_AUDIO_PARENTAL_RATING_AGE_18_OR_ABOVE  = 0x0F
     411              : };
     412              : 
     413              : /** @brief Audio Active State defined by the Generic Audio assigned numbers (bluetooth.com). */
     414            1 : enum bt_audio_active_state {
     415              :         /** No audio data is being transmitted */
     416              :         BT_AUDIO_ACTIVE_STATE_DISABLED       = 0x00,
     417              :         /** Audio data is being transmitted */
     418              :         BT_AUDIO_ACTIVE_STATE_ENABLED        = 0x01,
     419              : };
     420              : 
     421              : /** Assisted Listening Stream defined by the Generic Audio assigned numbers (bluetooth.com). */
     422            1 : enum bt_audio_assisted_listening_stream {
     423              :         /** Unspecified audio enhancement */
     424              :         BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED = 0x00,
     425              : };
     426              : 
     427              : /**
     428              :  * @brief Codec metadata type IDs
     429              :  *
     430              :  * Metadata types defined by the Generic Audio assigned numbers (bluetooth.com).
     431              :  */
     432            1 : enum bt_audio_metadata_type {
     433              :         /**
     434              :          * @brief Preferred audio context.
     435              :          *
     436              :          * Bitfield of preferred audio contexts.
     437              :          *
     438              :          * If 0, the context type is not a preferred use case for this codec
     439              :          * configuration.
     440              :          *
     441              :          * See the BT_AUDIO_CONTEXT_* for valid values.
     442              :          */
     443              :         BT_AUDIO_METADATA_TYPE_PREF_CONTEXT = 0x01,
     444              : 
     445              :         /**
     446              :          * @brief Streaming audio context.
     447              :          *
     448              :          * Bitfield of streaming audio contexts.
     449              :          *
     450              :          * If 0, the context type is not a preferred use case for this codec
     451              :          * configuration.
     452              :          *
     453              :          * See the BT_AUDIO_CONTEXT_* for valid values.
     454              :          */
     455              :         BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT = 0x02,
     456              : 
     457              :         /** UTF-8 encoded title or summary of stream content */
     458              :         BT_AUDIO_METADATA_TYPE_PROGRAM_INFO = 0x03,
     459              : 
     460              :         /**
     461              :          * @brief Language
     462              :          *
     463              :          * 3 octet lower case language code defined by ISO 639-3
     464              :          * Possible values can be found at https://iso639-3.sil.org/code_tables/639/data
     465              :          */
     466              :         BT_AUDIO_METADATA_TYPE_LANG = 0x04,
     467              : 
     468              :         /** Array of 8-bit CCID values */
     469              :         BT_AUDIO_METADATA_TYPE_CCID_LIST = 0x05,
     470              : 
     471              :         /**
     472              :          * @brief Parental rating
     473              :          *
     474              :          * See @ref bt_audio_parental_rating for valid values.
     475              :          */
     476              :         BT_AUDIO_METADATA_TYPE_PARENTAL_RATING = 0x06,
     477              : 
     478              :         /** UTF-8 encoded URI for additional Program information */
     479              :         BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI = 0x07,
     480              : 
     481              :         /**
     482              :          * @brief Audio active state
     483              :          *
     484              :          * See @ref bt_audio_active_state for valid values.
     485              :          */
     486              :         BT_AUDIO_METADATA_TYPE_AUDIO_STATE = 0x08,
     487              : 
     488              :         /** Broadcast Audio Immediate Rendering flag  */
     489              :         BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE = 0x09,
     490              : 
     491              :         /**
     492              :          * @brief Assisted listening stream
     493              :          *
     494              :          * See @ref bt_audio_assisted_listening_stream for valid values.
     495              :          */
     496              :         BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM = 0x0A,
     497              : 
     498              :         /** UTF-8 encoded Broadcast name */
     499              :         BT_AUDIO_METADATA_TYPE_BROADCAST_NAME = 0x0B,
     500              : 
     501              :         /** Extended metadata */
     502              :         BT_AUDIO_METADATA_TYPE_EXTENDED = 0xFE,
     503              : 
     504              :         /** Vendor specific metadata */
     505              :         BT_AUDIO_METADATA_TYPE_VENDOR = 0xFF,
     506              : };
     507              : 
     508              : /**
     509              :  * @brief Helper to check whether metadata type is known by the stack.
     510              :  *
     511              :  * @note @p _type is evaluated thrice.
     512              :  */
     513            1 : #define BT_AUDIO_METADATA_TYPE_IS_KNOWN(_type)                                                     \
     514              :         (IN_RANGE((_type), BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,                                    \
     515              :                   BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE) ||                                   \
     516              :          (_type) == BT_AUDIO_METADATA_TYPE_EXTENDED || (_type) == BT_AUDIO_METADATA_TYPE_VENDOR)
     517              : 
     518              : /**
     519              :  * @name Unicast Announcement Type
     520              :  * @{
     521              :  */
     522              : /** Unicast Server is connectable and is requesting a connection. */
     523            1 : #define BT_AUDIO_UNICAST_ANNOUNCEMENT_GENERAL    0x00
     524              : /** Unicast Server is connectable but is not requesting a connection. */
     525            1 : #define BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED   0x01
     526              : /** @} */
     527              : 
     528              : /**
     529              :  * @brief Helper to declare elements of bt_audio_codec_cap arrays
     530              :  *
     531              :  * This macro is mainly for creating an array of struct bt_audio_codec_cap data arrays.
     532              :  *
     533              :  * @param _type Type of advertising data field
     534              :  * @param _bytes Variable number of single-byte parameters
     535              :  */
     536            1 : #define BT_AUDIO_CODEC_DATA(_type, _bytes...)                                                      \
     537              :         (sizeof((uint8_t)_type) + sizeof((uint8_t[]){_bytes})), (_type), _bytes
     538              : 
     539              : /**
     540              :  * @brief Helper to declare @ref bt_audio_codec_cfg
     541              :  *
     542              :  * @param _id Codec ID
     543              :  * @param _cid Company ID
     544              :  * @param _vid Vendor ID
     545              :  * @param _data Codec Specific Data in LVT format
     546              :  * @param _meta Codec Specific Metadata in LVT format
     547              :  */
     548            1 : #define BT_AUDIO_CODEC_CFG(_id, _cid, _vid, _data, _meta)                                          \
     549              :         ((struct bt_audio_codec_cfg){                                                              \
     550              :                 /* Use HCI data path as default, can be overwritten by application */              \
     551              :                 .path_id = BT_ISO_DATA_PATH_HCI,                                                   \
     552              :                 .ctlr_transcode = false,                                                           \
     553              :                 COND_CODE_1(IS_ENABLED(CONFIG_BT_BAP_UNICAST),                                     \
     554              :                             (.target_latency = BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED,         \
     555              :                              .target_phy = BT_AUDIO_CODEC_CFG_TARGET_PHY_2M,),                     \
     556              :                             ())                                                                    \
     557              :                 .id = _id,                                                                         \
     558              :                 .cid = _cid,                                                                       \
     559              :                 .vid = _vid,                                                                       \
     560              :                 .data_len = sizeof((uint8_t[])_data),                                              \
     561              :                 .data = _data,                                                                     \
     562              :                 .meta_len = sizeof((uint8_t[])_meta),                                              \
     563              :                 .meta = _meta,                                                                     \
     564              :         })
     565              : 
     566              : /**
     567              :  * @brief Helper to declare @ref bt_audio_codec_cap structure
     568              :  *
     569              :  * @param _id Codec ID
     570              :  * @param _cid Company ID
     571              :  * @param _vid Vendor ID
     572              :  * @param _data Codec Specific Data in LVT format
     573              :  * @param _meta Codec Specific Metadata in LVT format
     574              :  */
     575            1 : #define BT_AUDIO_CODEC_CAP(_id, _cid, _vid, _data, _meta)                                          \
     576              :         ((struct bt_audio_codec_cap){                                                              \
     577              :                 /* Use HCI data path as default, can be overwritten by application */              \
     578              :                 .path_id = BT_ISO_DATA_PATH_HCI,                                                   \
     579              :                 .ctlr_transcode = false,                                                           \
     580              :                 .id = (_id),                                                                       \
     581              :                 .cid = (_cid),                                                                     \
     582              :                 .vid = (_vid),                                                                     \
     583              :                 .data_len = sizeof((uint8_t[])_data),                                              \
     584              :                 .data = _data,                                                                     \
     585              :                 .meta_len = sizeof((uint8_t[])_meta),                                              \
     586              :                 .meta = _meta,                                                                     \
     587              :         })
     588              : 
     589              : /**
     590              :  * @brief Location values for BT Audio.
     591              :  *
     592              :  * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
     593              :  */
     594            1 : enum bt_audio_location {
     595              :         /** Mono Audio (no specified Audio Location) */
     596              :         BT_AUDIO_LOCATION_MONO_AUDIO = 0,
     597              :         /** Front Left */
     598              :         BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
     599              :         /** Front Right */
     600              :         BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
     601              :         /** Front Center */
     602              :         BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),
     603              :         /** Low Frequency Effects 1 */
     604              :         BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1 = BIT(3),
     605              :         /** Back Left */
     606              :         BT_AUDIO_LOCATION_BACK_LEFT = BIT(4),
     607              :         /** Back Right */
     608              :         BT_AUDIO_LOCATION_BACK_RIGHT = BIT(5),
     609              :         /** Front Left of Center */
     610              :         BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER = BIT(6),
     611              :         /** Front Right of Center */
     612              :         BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER = BIT(7),
     613              :         /** Back Center */
     614              :         BT_AUDIO_LOCATION_BACK_CENTER = BIT(8),
     615              :         /** Low Frequency Effects 2 */
     616              :         BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2 = BIT(9),
     617              :         /** Side Left */
     618              :         BT_AUDIO_LOCATION_SIDE_LEFT = BIT(10),
     619              :         /** Side Right */
     620              :         BT_AUDIO_LOCATION_SIDE_RIGHT = BIT(11),
     621              :         /** Top Front Left */
     622              :         BT_AUDIO_LOCATION_TOP_FRONT_LEFT = BIT(12),
     623              :         /** Top Front Right */
     624              :         BT_AUDIO_LOCATION_TOP_FRONT_RIGHT = BIT(13),
     625              :         /** Top Front Center */
     626              :         BT_AUDIO_LOCATION_TOP_FRONT_CENTER = BIT(14),
     627              :         /** Top Center */
     628              :         BT_AUDIO_LOCATION_TOP_CENTER = BIT(15),
     629              :         /** Top Back Left */
     630              :         BT_AUDIO_LOCATION_TOP_BACK_LEFT = BIT(16),
     631              :         /** Top Back Right */
     632              :         BT_AUDIO_LOCATION_TOP_BACK_RIGHT = BIT(17),
     633              :         /** Top Side Left */
     634              :         BT_AUDIO_LOCATION_TOP_SIDE_LEFT = BIT(18),
     635              :         /** Top Side Right */
     636              :         BT_AUDIO_LOCATION_TOP_SIDE_RIGHT = BIT(19),
     637              :         /** Top Back Center */
     638              :         BT_AUDIO_LOCATION_TOP_BACK_CENTER = BIT(20),
     639              :         /** Bottom Front Center */
     640              :         BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER = BIT(21),
     641              :         /** Bottom Front Left */
     642              :         BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT = BIT(22),
     643              :         /** Bottom Front Right */
     644              :         BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT = BIT(23),
     645              :         /** Front Left Wide */
     646              :         BT_AUDIO_LOCATION_FRONT_LEFT_WIDE = BIT(24),
     647              :         /** Front Right Wide */
     648              :         BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE = BIT(25),
     649              :         /** Left Surround */
     650              :         BT_AUDIO_LOCATION_LEFT_SURROUND = BIT(26),
     651              :         /** Right Surround */
     652              :         BT_AUDIO_LOCATION_RIGHT_SURROUND = BIT(27),
     653              : };
     654              : 
     655              : /**
     656              :  * Any known location.
     657              :  */
     658            1 : #define BT_AUDIO_LOCATION_ANY (BT_AUDIO_LOCATION_FRONT_LEFT | \
     659              :                                BT_AUDIO_LOCATION_FRONT_RIGHT | \
     660              :                                BT_AUDIO_LOCATION_FRONT_CENTER | \
     661              :                                BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1 | \
     662              :                                BT_AUDIO_LOCATION_BACK_LEFT | \
     663              :                                BT_AUDIO_LOCATION_BACK_RIGHT | \
     664              :                                BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER | \
     665              :                                BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER | \
     666              :                                BT_AUDIO_LOCATION_BACK_CENTER | \
     667              :                                BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2 | \
     668              :                                BT_AUDIO_LOCATION_SIDE_LEFT | \
     669              :                                BT_AUDIO_LOCATION_SIDE_RIGHT | \
     670              :                                BT_AUDIO_LOCATION_TOP_FRONT_LEFT | \
     671              :                                BT_AUDIO_LOCATION_TOP_FRONT_RIGHT | \
     672              :                                BT_AUDIO_LOCATION_TOP_FRONT_CENTER | \
     673              :                                BT_AUDIO_LOCATION_TOP_CENTER | \
     674              :                                BT_AUDIO_LOCATION_TOP_BACK_LEFT | \
     675              :                                BT_AUDIO_LOCATION_TOP_BACK_RIGHT | \
     676              :                                BT_AUDIO_LOCATION_TOP_SIDE_LEFT | \
     677              :                                BT_AUDIO_LOCATION_TOP_SIDE_RIGHT | \
     678              :                                BT_AUDIO_LOCATION_TOP_BACK_CENTER | \
     679              :                                BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER | \
     680              :                                BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT | \
     681              :                                BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT | \
     682              :                                BT_AUDIO_LOCATION_FRONT_LEFT_WIDE | \
     683              :                                BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE | \
     684              :                                BT_AUDIO_LOCATION_LEFT_SURROUND | \
     685              :                                BT_AUDIO_LOCATION_RIGHT_SURROUND)
     686              : 
     687              : /** @brief Codec capability structure. */
     688            1 : struct bt_audio_codec_cap {
     689              :         /** Data path ID
     690              :          *
     691              :          * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
     692              :          * vendor specific ID.
     693              :          */
     694            1 :         uint8_t path_id;
     695              :         /** Whether or not the local controller should transcode
     696              :          *
     697              :          * This effectively sets the coding format for the ISO data path to @ref
     698              :          * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
     699              :          */
     700            1 :         bool ctlr_transcode;
     701              :         /** Codec ID */
     702            1 :         uint8_t id;
     703              :         /** Codec Company ID */
     704            1 :         uint16_t cid;
     705              :         /** Codec Company Vendor ID */
     706            1 :         uint16_t vid;
     707              : #if CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
     708              :         /** Codec Specific Capabilities Data count */
     709            1 :         size_t data_len;
     710              :         /** Codec Specific Capabilities Data */
     711            1 :         uint8_t data[CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE];
     712              : #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 */
     713              : #if defined(CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE) || defined(__DOXYGEN__)
     714              :         /** Codec Specific Capabilities Metadata count */
     715            1 :         size_t meta_len;
     716              :         /** Codec Specific Capabilities Metadata */
     717            1 :         uint8_t meta[CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE];
     718              : #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE */
     719              : };
     720              : 
     721              : /**
     722              :  * @brief Codec configuration target latency
     723              :  *
     724              :  * Set by the BAP Unicast Client to provide context for the BAP Unicast Server for the server to
     725              :  * set its QoS preferences.
     726              :  */
     727            1 : enum bt_audio_codec_cfg_target_latency {
     728              :         /** Target low latency */
     729              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_LOW = 0x01,
     730              : 
     731              :         /** Target balanced latency */
     732              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED = 0x02,
     733              : 
     734              :         /** Target high latency */
     735              :         BT_AUDIO_CODEC_CFG_TARGET_LATENCY_HIGH = 0x03,
     736              : };
     737              : 
     738              : /**
     739              :  * @brief Codec configuration target PHY
     740              :  *
     741              :  * The target PHY to achieve the target latency (@ref bt_audio_codec_cfg_target_latency).
     742              :  */
     743            1 : enum bt_audio_codec_cfg_target_phy {
     744              :         /** LE 1M PHY */
     745              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_1M = 0x01,
     746              : 
     747              :         /** LE 2M PHY */
     748              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_2M = 0x02,
     749              : 
     750              :         /** LE Coded PHY */
     751              :         BT_AUDIO_CODEC_CFG_TARGET_PHY_CODED = 0x03,
     752              : };
     753              : 
     754              : /** @brief Codec specific configuration structure. */
     755            1 : struct bt_audio_codec_cfg {
     756              :         /** Data path ID
     757              :          *
     758              :          * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
     759              :          * vendor specific ID.
     760              :          */
     761            1 :         uint8_t path_id;
     762              :         /** Whether or not the local controller should transcode
     763              :          *
     764              :          * This effectively sets the coding format for the ISO data path to @ref
     765              :          * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
     766              :          */
     767            1 :         bool ctlr_transcode;
     768              : #if defined(CONFIG_BT_BAP_UNICAST)
     769              :         /** Target latency
     770              :          *
     771              :          * Unused for broadcast streams.
     772              :          */
     773              :         enum bt_audio_codec_cfg_target_latency target_latency;
     774              :         /** Target PHY
     775              :          *
     776              :          * Unused for broadcast streams.
     777              :          */
     778              :         enum bt_audio_codec_cfg_target_phy target_phy;
     779              : #endif /* CONFIG_BT_BAP_UNICAST */
     780              :         /** Codec ID */
     781            1 :         uint8_t  id;
     782              :         /** Codec Company ID */
     783            1 :         uint16_t cid;
     784              :         /** Codec Company Vendor ID */
     785            1 :         uint16_t vid;
     786              : #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
     787              :         /** Codec Specific Capabilities Data count */
     788            1 :         size_t data_len;
     789              :         /** Codec Specific Capabilities Data */
     790            1 :         uint8_t data[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE];
     791              : #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
     792              : #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 || defined(__DOXYGEN__)
     793              :         /** Codec Specific Capabilities Metadata count */
     794            1 :         size_t meta_len;
     795              :         /** Codec Specific Capabilities Metadata */
     796            1 :         uint8_t meta[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE];
     797              : #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */
     798              : };
     799              : 
     800              : /**
     801              :  * @brief Helper for parsing length-type-value data.
     802              :  *
     803              :  * @param ltv       Length-type-value (LTV) encoded data.
     804              :  * @param size      Size of the @p ltv data.
     805              :  * @param func      Callback function which will be called for each element
     806              :  *                  that's found in the data. The callback should return
     807              :  *                  true to continue parsing, or false to stop parsing.
     808              :  * @param user_data User data to be passed to the callback.
     809              :  *
     810              :  * @retval 0 All entries were parsed.
     811              :  * @retval -EINVAL The data is incorrectly encoded
     812              :  * @retval -ECANCELED Parsing was prematurely cancelled by the callback
     813              :  */
     814            1 : int bt_audio_data_parse(const uint8_t ltv[], size_t size,
     815              :                         bool (*func)(struct bt_data *data, void *user_data), void *user_data);
     816              : 
     817              : /**
     818              :  * @brief Get the value of a specific data type in an length-type-value data array
     819              :  *
     820              :  * @param[in]  ltv_data The array containing the length-type-value tuples
     821              :  * @param[in]  size The size of @p ltv_data
     822              :  * @param[in]  type The type to get the value for. May be any type, but typically either
     823              :  *             @ref bt_audio_codec_cap_type, @ref bt_audio_codec_cfg_type or
     824              :  *             @ref bt_audio_metadata_type.
     825              :  * @param[out] data Pointer to the data-pointer to update when item is found.
     826              :  *                  Any found data will be little endian.
     827              :  *
     828              :  * @retval length The length of found @p data (may be 0).
     829              :  * @retval -EINVAL Arguments are invalid
     830              :  * @retval -ENODATA Data not found
     831              :  */
     832            1 : int bt_audio_data_get_val(const uint8_t ltv_data[], size_t size, uint8_t type,
     833              :                           const uint8_t **data);
     834              : 
     835              : /**
     836              :  * @brief Function to get the number of channels from the channel allocation
     837              :  *
     838              :  * @param chan_allocation The channel allocation
     839              :  *
     840              :  * @return The number of channels
     841              :  */
     842            1 : uint8_t bt_audio_get_chan_count(enum bt_audio_location chan_allocation);
     843              : 
     844              : /** @brief Audio direction from the perspective of the BAP Unicast Server / BAP Broadcast Sink */
     845            1 : enum bt_audio_dir {
     846              :         /**
     847              :          * @brief Audio direction sink
     848              :          *
     849              :          * For a BAP Unicast Client or Broadcast Source this is considered outgoing audio (TX).
     850              :          * For a BAP Unicast Server or Broadcast Sink this is considered incoming audio (RX).
     851              :          */
     852              :         BT_AUDIO_DIR_SINK = 0x01,
     853              :         /**
     854              :          * @brief Audio direction source
     855              :          *
     856              :          * For a BAP Unicast Client or Broadcast Source this is considered incoming audio (RX).
     857              :          * For a BAP Unicast Server or Broadcast Sink this is considered outgoing audio (TX).
     858              :          */
     859              :         BT_AUDIO_DIR_SOURCE = 0x02,
     860              : };
     861              : 
     862              : /**
     863              :  * @brief Audio codec Config APIs
     864              :  * @defgroup bt_audio_codec_cfg Codec config parsing APIs
     865              :  *
     866              :  * Functions to parse codec config data when formatted as LTV wrapped into @ref bt_audio_codec_cfg.
     867              :  *
     868              :  * @{
     869              :  */
     870              : 
     871              : /**
     872              :  * @brief Convert assigned numbers frequency to frequency value.
     873              :  *
     874              :  * @param freq The assigned numbers frequency to convert.
     875              :  *
     876              :  * @retval frequency The converted frequency value in Hz.
     877              :  * @retval -EINVAL Arguments are invalid.
     878              :  */
     879            1 : int bt_audio_codec_cfg_freq_to_freq_hz(enum bt_audio_codec_cfg_freq freq);
     880              : 
     881              : /**
     882              :  * @brief Convert frequency value to assigned numbers frequency.
     883              :  *
     884              :  * @param freq_hz The frequency value to convert.
     885              :  *
     886              :  * @retval frequency The assigned numbers frequency (@ref bt_audio_codec_cfg_freq).
     887              :  * @retval -EINVAL Arguments are invalid.
     888              :  */
     889            1 : int bt_audio_codec_cfg_freq_hz_to_freq(uint32_t freq_hz);
     890              : 
     891              : /**
     892              :  * @brief Extract the frequency from a codec configuration.
     893              :  *
     894              :  * @param codec_cfg The codec configuration to extract data from.
     895              :  *
     896              :  * @retval frequency A @ref bt_audio_codec_cfg_freq value
     897              :  * @retval -EINVAL Arguments are invalid
     898              :  * @retval -ENODATA Data not found
     899              :  * @retval -EBADMSG The found value has invalid size or value
     900              :  */
     901            1 : int bt_audio_codec_cfg_get_freq(const struct bt_audio_codec_cfg *codec_cfg);
     902              : 
     903              : /**
     904              :  * @brief Set the frequency of a codec configuration.
     905              :  *
     906              :  * @param codec_cfg The codec configuration to set data for.
     907              :  * @param freq      The assigned numbers frequency to set.
     908              :  *
     909              :  * @retval data_len The @p codec_cfg.data_len on success
     910              :  * @retval -EINVAL Arguments are invalid
     911              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     912              :  */
     913            1 : int bt_audio_codec_cfg_set_freq(struct bt_audio_codec_cfg *codec_cfg,
     914              :                                 enum bt_audio_codec_cfg_freq freq);
     915              : 
     916              : /**
     917              :  * @brief Convert assigned numbers frame duration to duration in microseconds.
     918              :  *
     919              :  * @param frame_dur The assigned numbers frame duration to convert.
     920              :  *
     921              :  * @retval duration The converted frame duration value in microseconds.
     922              :  * @retval -EINVAL Arguments are invalid.
     923              :  */
     924            1 : int bt_audio_codec_cfg_frame_dur_to_frame_dur_us(enum bt_audio_codec_cfg_frame_dur frame_dur);
     925              : 
     926              : /**
     927              :  * @brief Convert frame duration in microseconds to assigned numbers frame duration.
     928              :  *
     929              :  * @param frame_dur_us The frame duration in microseconds to convert.
     930              :  *
     931              :  * @retval duration The assigned numbers frame duration (@ref bt_audio_codec_cfg_frame_dur).
     932              :  * @retval -EINVAL Arguments are invalid.
     933              :  */
     934            1 : int bt_audio_codec_cfg_frame_dur_us_to_frame_dur(uint32_t frame_dur_us);
     935              : 
     936              : /**
     937              :  * @brief Extract frame duration from BT codec config
     938              :  *
     939              :  * @param codec_cfg The codec configuration to extract data from.
     940              :  *
     941              :  * @retval frequency A @ref bt_audio_codec_cfg_frame_dur value
     942              :  * @retval -EINVAL Arguments are invalid
     943              :  * @retval -ENODATA Data not found
     944              :  * @retval -EBADMSG The found value has invalid size or value
     945              :  */
     946            1 : int bt_audio_codec_cfg_get_frame_dur(const struct bt_audio_codec_cfg *codec_cfg);
     947              : 
     948              : /**
     949              :  * @brief Set the frame duration of a codec configuration.
     950              :  *
     951              :  * @param codec_cfg  The codec configuration to set data for.
     952              :  * @param frame_dur  The assigned numbers frame duration to set.
     953              :  *
     954              :  * @retval data_len The @p codec_cfg.data_len on success
     955              :  * @retval -EINVAL Arguments are invalid
     956              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     957              :  */
     958            1 : int bt_audio_codec_cfg_set_frame_dur(struct bt_audio_codec_cfg *codec_cfg,
     959              :                                      enum bt_audio_codec_cfg_frame_dur frame_dur);
     960              : 
     961              : /**
     962              :  * @brief Extract channel allocation from BT codec config
     963              :  *
     964              :  * The value returned is a bit field representing one or more audio locations as
     965              :  * specified by @ref bt_audio_location
     966              :  * Shall match one or more of the bits set in BT_PAC_SNK_LOC/BT_PAC_SRC_LOC.
     967              :  *
     968              :  * Up to the configured @ref BT_AUDIO_CODEC_CAP_TYPE_CHAN_COUNT number of channels can be present.
     969              :  *
     970              :  * @param codec_cfg The codec configuration to extract data from.
     971              :  * @param chan_allocation Pointer to the variable to store the extracted value in.
     972              :  * @param fallback_to_default If true this function will provide the default value of
     973              :  *        @ref BT_AUDIO_LOCATION_MONO_AUDIO if the type is not found when @p codec_cfg.id is @ref
     974              :  *        BT_HCI_CODING_FORMAT_LC3.
     975              :  *
     976              :  * @retval 0 Value is found and stored in the pointer provided
     977              :  * @retval -EINVAL Arguments are invalid
     978              :  * @retval -ENODATA Data not found
     979              :  * @retval -EBADMSG The found value has invalid size or value
     980              :  */
     981            1 : int bt_audio_codec_cfg_get_chan_allocation(const struct bt_audio_codec_cfg *codec_cfg,
     982              :                                            enum bt_audio_location *chan_allocation,
     983              :                                            bool fallback_to_default);
     984              : 
     985              : /**
     986              :  * @brief Set the channel allocation of a codec configuration.
     987              :  *
     988              :  * @param codec_cfg       The codec configuration to set data for.
     989              :  * @param chan_allocation The channel allocation to set.
     990              :  *
     991              :  * @retval data_len The @p codec_cfg.data_len on success
     992              :  * @retval -EINVAL Arguments are invalid
     993              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
     994              :  */
     995            1 : int bt_audio_codec_cfg_set_chan_allocation(struct bt_audio_codec_cfg *codec_cfg,
     996              :                                            enum bt_audio_location chan_allocation);
     997              : 
     998              : /**
     999              :  * @brief Extract frame size in octets from BT codec config
    1000              :  *
    1001              :  * The overall SDU size will be octets_per_frame * blocks_per_sdu.
    1002              :  *
    1003              :  * The Bluetooth specifications are not clear about this value - it does not state that
    1004              :  * the codec shall use this SDU size only. A codec like LC3 supports variable bit-rate
    1005              :  * (per SDU) hence it might be allowed for an encoder to reduce the frame size below this
    1006              :  * value.
    1007              :  * Hence it is recommended to use the received SDU size and divide by
    1008              :  * blocks_per_sdu rather than relying on this octets_per_sdu value to be fixed.
    1009              :  *
    1010              :  * @param codec_cfg The codec configuration to extract data from.
    1011              :  *
    1012              :  * @retval frame_length Frame length in octets
    1013              :  * @retval -EINVAL Arguments are invalid
    1014              :  * @retval -ENODATA Data not found
    1015              :  * @retval -EBADMSG The found value has invalid size or value
    1016              :  */
    1017            1 : int bt_audio_codec_cfg_get_octets_per_frame(const struct bt_audio_codec_cfg *codec_cfg);
    1018              : 
    1019              : /**
    1020              :  * @brief Set the octets per codec frame of a codec configuration.
    1021              :  *
    1022              :  * @param codec_cfg        The codec configuration to set data for.
    1023              :  * @param octets_per_frame The octets per codec frame to set.
    1024              :  *
    1025              :  * @retval data_len The @p codec_cfg.data_len on success
    1026              :  * @retval -EINVAL Arguments are invalid
    1027              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1028              :  */
    1029            1 : int bt_audio_codec_cfg_set_octets_per_frame(struct bt_audio_codec_cfg *codec_cfg,
    1030              :                                             uint16_t octets_per_frame);
    1031              : 
    1032              : /**
    1033              :  * @brief Extract number of audio frame blocks in each SDU from BT codec config
    1034              :  *
    1035              :  * The overall SDU size will be octets_per_frame * frame_blocks_per_sdu * number-of-channels.
    1036              :  *
    1037              :  * If this value is not present a default value of 1 shall be used.
    1038              :  *
    1039              :  * A frame block is one or more frames that represents data for the same period of time but
    1040              :  * for different channels. If the stream have two audio channels and this value is two
    1041              :  * there will be four frames in the SDU.
    1042              :  *
    1043              :  * @param codec_cfg The codec configuration to extract data from.
    1044              :  * @param fallback_to_default If true this function will return the default value of 1
    1045              :  *         if the type is not found when @p codec_cfg.id is @ref BT_HCI_CODING_FORMAT_LC3.
    1046              :  *
    1047              :  * @retval frame_blocks_per_sdu The count of codec frame blocks in each SDU.
    1048              :  * @retval -EINVAL Arguments are invalid
    1049              :  * @retval -ENODATA Data not found
    1050              :  * @retval -EBADMSG The found value has invalid size or value
    1051              :  */
    1052            1 : int bt_audio_codec_cfg_get_frame_blocks_per_sdu(const struct bt_audio_codec_cfg *codec_cfg,
    1053              :                                                 bool fallback_to_default);
    1054              : 
    1055              : /**
    1056              :  * @brief Set the frame blocks per SDU of a codec configuration.
    1057              :  *
    1058              :  * @param codec_cfg    The codec configuration to set data for.
    1059              :  * @param frame_blocks The frame blocks per SDU to set.
    1060              :  *
    1061              :  * @retval data_len The @p codec_cfg.data_len on success
    1062              :  * @retval -EINVAL Arguments are invalid
    1063              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1064              :  */
    1065            1 : int bt_audio_codec_cfg_set_frame_blocks_per_sdu(struct bt_audio_codec_cfg *codec_cfg,
    1066              :                                                 uint8_t frame_blocks);
    1067              : 
    1068              : /**
    1069              :  * @brief Lookup a specific codec configuration value
    1070              :  *
    1071              :  * @param[in] codec_cfg The codec data to search in.
    1072              :  * @param[in] type The type id to look for
    1073              :  * @param[out] data Pointer to the data-pointer to update when item is found
    1074              :  *
    1075              :  * @retval len Length of found @p data (may be 0)
    1076              :  * @retval -EINVAL Arguments are invalid
    1077              :  * @retval -ENODATA Data not found
    1078              :  */
    1079            1 : int bt_audio_codec_cfg_get_val(const struct bt_audio_codec_cfg *codec_cfg,
    1080              :                                enum bt_audio_codec_cfg_type type, const uint8_t **data);
    1081              : 
    1082              : /**
    1083              :  * @brief Set or add a specific codec configuration value
    1084              :  *
    1085              :  * @param codec_cfg  The codec data to set the value in.
    1086              :  * @param type       The type id to set
    1087              :  * @param data       Pointer to the data-pointer to set
    1088              :  * @param data_len   Length of @p data
    1089              :  *
    1090              :  * @retval data_len The @p codec_cfg.data_len on success
    1091              :  * @retval -EINVAL Arguments are invalid
    1092              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1093              :  */
    1094            1 : int bt_audio_codec_cfg_set_val(struct bt_audio_codec_cfg *codec_cfg,
    1095              :                                enum bt_audio_codec_cfg_type type, const uint8_t *data,
    1096              :                                size_t data_len);
    1097              : 
    1098              : /**
    1099              :  * @brief Unset a specific codec configuration value
    1100              :  *
    1101              :  * The type and the value will be removed from the codec configuration.
    1102              :  *
    1103              :  * @param codec_cfg  The codec data to set the value in.
    1104              :  * @param type       The type id to unset.
    1105              :  *
    1106              :  * @retval data_len The @p codec_cfg.data_len on success
    1107              :  * @retval -EINVAL Arguments are invalid
    1108              :  */
    1109            1 : int bt_audio_codec_cfg_unset_val(struct bt_audio_codec_cfg *codec_cfg,
    1110              :                                  enum bt_audio_codec_cfg_type type);
    1111              : 
    1112              : /**
    1113              :  * @brief Lookup a specific metadata value based on type
    1114              :  *
    1115              :  *
    1116              :  * @param[in]  codec_cfg The codec data to search in.
    1117              :  * @param[in]  type      The type id to look for
    1118              :  * @param[out] data      Pointer to the data-pointer to update when item is found
    1119              :  *
    1120              :  * @retval len Length of found @p data (may be 0)
    1121              :  * @retval -EINVAL Arguments are invalid
    1122              :  * @retval -ENODATA Data not found
    1123              :  */
    1124            1 : int bt_audio_codec_cfg_meta_get_val(const struct bt_audio_codec_cfg *codec_cfg, uint8_t type,
    1125              :                                     const uint8_t **data);
    1126              : 
    1127              : /**
    1128              :  * @brief Set or add a specific codec configuration metadata value.
    1129              :  *
    1130              :  * @param codec_cfg  The codec configuration to set the value in.
    1131              :  * @param type       The type id to set.
    1132              :  * @param data       Pointer to the data-pointer to set.
    1133              :  * @param data_len   Length of @p data.
    1134              :  *
    1135              :  * @retval meta_len The @p codec_cfg.meta_len on success
    1136              :  * @retval -EINVAL Arguments are invalid
    1137              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1138              :  */
    1139            1 : int bt_audio_codec_cfg_meta_set_val(struct bt_audio_codec_cfg *codec_cfg,
    1140              :                                     enum bt_audio_metadata_type type, const uint8_t *data,
    1141              :                                     size_t data_len);
    1142              : 
    1143              : /**
    1144              :  * @brief Unset a specific codec configuration metadata value
    1145              :  *
    1146              :  * The type and the value will be removed from the codec configuration metadata.
    1147              :  *
    1148              :  * @param codec_cfg  The codec data to set the value in.
    1149              :  * @param type       The type id to unset.
    1150              :  *
    1151              :  * @retval meta_len The of @p codec_cfg.meta_len success
    1152              :  * @retval -EINVAL Arguments are invalid
    1153              :  */
    1154            1 : int bt_audio_codec_cfg_meta_unset_val(struct bt_audio_codec_cfg *codec_cfg,
    1155              :                                       enum bt_audio_metadata_type type);
    1156              : /**
    1157              :  * @brief Extract preferred contexts
    1158              :  *
    1159              :  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
    1160              :  *
    1161              :  * @param codec_cfg The codec data to search in.
    1162              :  * @param fallback_to_default If true this function will provide the default value of
    1163              :  *        @ref BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED if the type is not found when @p codec_cfg.id is
    1164              :  *        @ref BT_HCI_CODING_FORMAT_LC3.
    1165              :  *
    1166              :  * @retval context The preferred context type if positive or 0
    1167              :  * @retval -EINVAL Arguments are invalid
    1168              :  * @retval -ENODATA Data not found
    1169              :  * @retval -EBADMSG The found value has invalid size
    1170              :  */
    1171            1 : int bt_audio_codec_cfg_meta_get_pref_context(const struct bt_audio_codec_cfg *codec_cfg,
    1172              :                                              bool fallback_to_default);
    1173              : 
    1174              : /**
    1175              :  * @brief Set the preferred context of a codec configuration metadata.
    1176              :  *
    1177              :  * @param codec_cfg The codec configuration to set data for.
    1178              :  * @param ctx       The preferred context to set.
    1179              :  *
    1180              :  * @retval data_len The @p codec_cfg.data_len on success
    1181              :  * @retval -EINVAL Arguments are invalid
    1182              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1183              :  */
    1184            1 : int bt_audio_codec_cfg_meta_set_pref_context(struct bt_audio_codec_cfg *codec_cfg,
    1185              :                                              enum bt_audio_context ctx);
    1186              : 
    1187              : /**
    1188              :  * @brief Extract stream contexts
    1189              :  *
    1190              :  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
    1191              :  *
    1192              :  * @param codec_cfg The codec data to search in.
    1193              :  *
    1194              :  * @retval context The stream context type if positive or 0
    1195              :  * @retval -EINVAL Arguments are invalid
    1196              :  * @retval -ENODATA Data not found
    1197              :  * @retval -EBADMSG The found value has invalid size
    1198              :  */
    1199            1 : int bt_audio_codec_cfg_meta_get_stream_context(const struct bt_audio_codec_cfg *codec_cfg);
    1200              : 
    1201              : /**
    1202              :  * @brief Set the stream context of a codec configuration metadata.
    1203              :  *
    1204              :  * @param codec_cfg The codec configuration to set data for.
    1205              :  * @param ctx       The stream context to set.
    1206              :  *
    1207              :  * @retval data_len The @p codec_cfg.data_len on success
    1208              :  * @retval -EINVAL Arguments are invalid
    1209              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1210              :  */
    1211            1 : int bt_audio_codec_cfg_meta_set_stream_context(struct bt_audio_codec_cfg *codec_cfg,
    1212              :                                                enum bt_audio_context ctx);
    1213              : 
    1214              : /**
    1215              :  * @brief Extract program info
    1216              :  *
    1217              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
    1218              :  *
    1219              :  * @param[in]  codec_cfg    The codec data to search in.
    1220              :  * @param[out] program_info Pointer to the UTF-8 formatted program info.
    1221              :  *
    1222              :  * @retval len The length of the @p program_info (may be 0)
    1223              :  * @retval -EINVAL Arguments are invalid
    1224              :  * @retval -ENODATA Data not found
    1225              :  */
    1226            1 : int bt_audio_codec_cfg_meta_get_program_info(const struct bt_audio_codec_cfg *codec_cfg,
    1227              :                                              const uint8_t **program_info);
    1228              : 
    1229              : /**
    1230              :  * @brief Set the program info of a codec configuration metadata.
    1231              :  *
    1232              :  * @param codec_cfg        The codec configuration to set data for.
    1233              :  * @param program_info     The program info to set.
    1234              :  * @param program_info_len The length of @p program_info.
    1235              :  *
    1236              :  * @retval data_len The @p codec_cfg.data_len on success
    1237              :  * @retval -EINVAL Arguments are invalid
    1238              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1239              :  */
    1240            1 : int bt_audio_codec_cfg_meta_set_program_info(struct bt_audio_codec_cfg *codec_cfg,
    1241              :                                              const uint8_t *program_info, size_t program_info_len);
    1242              : 
    1243              : /**
    1244              :  * @brief Extract language
    1245              :  *
    1246              :  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
    1247              :  *
    1248              :  * @param[in]  codec_cfg The codec data to search in.
    1249              :  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
    1250              :  *
    1251              :  * @retval 0 Success
    1252              :  * @retval -EINVAL Arguments are invalid
    1253              :  * @retval -ENODATA Data not found
    1254              :  * @retval -EBADMSG The found value has invalid size
    1255              :  */
    1256            1 : int bt_audio_codec_cfg_meta_get_lang(const struct bt_audio_codec_cfg *codec_cfg,
    1257              :                                      const uint8_t **lang);
    1258              : 
    1259              : /**
    1260              :  * @brief Set the language of a codec configuration metadata.
    1261              :  *
    1262              :  * @param codec_cfg   The codec configuration to set data for.
    1263              :  * @param lang        The 24-bit language to set.
    1264              :  *
    1265              :  * @retval data_len The @p codec_cfg.data_len on success
    1266              :  * @retval -EINVAL Arguments are invalid
    1267              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1268              :  */
    1269            1 : int bt_audio_codec_cfg_meta_set_lang(struct bt_audio_codec_cfg *codec_cfg,
    1270              :                                      const uint8_t lang[BT_AUDIO_LANG_SIZE]);
    1271              : 
    1272              : /**
    1273              :  * @brief Extract CCID list
    1274              :  *
    1275              :  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
    1276              :  *
    1277              :  * @param[in]  codec_cfg The codec data to search in.
    1278              :  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
    1279              :  *
    1280              :  * @retval len The length of the @p ccid_list (may be 0)
    1281              :  * @retval -EINVAL Arguments are invalid
    1282              :  * @retval -ENODATA Data not found
    1283              :  */
    1284            1 : int bt_audio_codec_cfg_meta_get_ccid_list(const struct bt_audio_codec_cfg *codec_cfg,
    1285              :                                           const uint8_t **ccid_list);
    1286              : 
    1287              : /**
    1288              :  * @brief Set the CCID list of a codec configuration metadata.
    1289              :  *
    1290              :  * @param codec_cfg     The codec configuration to set data for.
    1291              :  * @param ccid_list     The program info to set.
    1292              :  * @param ccid_list_len The length of @p ccid_list.
    1293              :  *
    1294              :  * @retval data_len The @p codec_cfg.data_len on success
    1295              :  * @retval -EINVAL Arguments are invalid
    1296              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1297              :  */
    1298            1 : int bt_audio_codec_cfg_meta_set_ccid_list(struct bt_audio_codec_cfg *codec_cfg,
    1299              :                                           const uint8_t *ccid_list, size_t ccid_list_len);
    1300              : 
    1301              : /**
    1302              :  * @brief Extract parental rating
    1303              :  *
    1304              :  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
    1305              :  *
    1306              :  * @param codec_cfg The codec data to search in.
    1307              :  *
    1308              :  * @retval parental_rating The parental rating if positive or 0
    1309              :  * @retval -EINVAL Arguments are invalid
    1310              :  * @retval -ENODATA Data not found
    1311              :  * @retval -EBADMSG The found value has invalid size
    1312              :  */
    1313            1 : int bt_audio_codec_cfg_meta_get_parental_rating(const struct bt_audio_codec_cfg *codec_cfg);
    1314              : 
    1315              : /**
    1316              :  * @brief Set the parental rating of a codec configuration metadata.
    1317              :  *
    1318              :  * @param codec_cfg       The codec configuration to set data for.
    1319              :  * @param parental_rating The parental rating to set.
    1320              :  *
    1321              :  * @retval data_len The @p codec_cfg.data_len on success
    1322              :  * @retval -EINVAL Arguments are invalid
    1323              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1324              :  */
    1325            1 : int bt_audio_codec_cfg_meta_set_parental_rating(struct bt_audio_codec_cfg *codec_cfg,
    1326              :                                                 enum bt_audio_parental_rating parental_rating);
    1327              : 
    1328              : /**
    1329              :  * @brief Extract program info URI
    1330              :  *
    1331              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
    1332              :  *
    1333              :  * @param[in]  codec_cfg The codec data to search in.
    1334              :  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
    1335              :  *
    1336              :  * @retval len The length of the @p program_info_uri (may be 0)
    1337              :  * @retval -EINVAL Arguments are invalid
    1338              :  * @retval -ENODATA Data not found
    1339              :  */
    1340            1 : int bt_audio_codec_cfg_meta_get_program_info_uri(const struct bt_audio_codec_cfg *codec_cfg,
    1341              :                                                  const uint8_t **program_info_uri);
    1342              : 
    1343              : /**
    1344              :  * @brief Set the program info URI of a codec configuration metadata.
    1345              :  *
    1346              :  * @param codec_cfg            The codec configuration to set data for.
    1347              :  * @param program_info_uri     The program info URI to set.
    1348              :  * @param program_info_uri_len The length of @p program_info_uri.
    1349              :  *
    1350              :  * @retval data_len The @p codec_cfg.data_len on success
    1351              :  * @retval -EINVAL Arguments are invalid
    1352              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1353              :  */
    1354            1 : int bt_audio_codec_cfg_meta_set_program_info_uri(struct bt_audio_codec_cfg *codec_cfg,
    1355              :                                                  const uint8_t *program_info_uri,
    1356              :                                                  size_t program_info_uri_len);
    1357              : 
    1358              : /**
    1359              :  * @brief Extract audio active state
    1360              :  *
    1361              :  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
    1362              :  *
    1363              :  * @param codec_cfg The codec data to search in.
    1364              :  *
    1365              :  * @retval context The preferred context type if positive or 0
    1366              :  * @retval -EINVAL Arguments are invalid
    1367              :  * @retval -ENODATA Data not found
    1368              :  * @retval -EBADMSG The found value has invalid size
    1369              :  */
    1370            1 : int bt_audio_codec_cfg_meta_get_audio_active_state(const struct bt_audio_codec_cfg *codec_cfg);
    1371              : 
    1372              : /**
    1373              :  * @brief Set the audio active state of a codec configuration metadata.
    1374              :  *
    1375              :  * @param codec_cfg The codec configuration to set data for.
    1376              :  * @param state     The audio active state to set.
    1377              :  *
    1378              :  * @retval data_len The @p codec_cfg.data_len on success
    1379              :  * @retval -EINVAL Arguments are invalid
    1380              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1381              :  */
    1382            1 : int bt_audio_codec_cfg_meta_set_audio_active_state(struct bt_audio_codec_cfg *codec_cfg,
    1383              :                                                    enum bt_audio_active_state state);
    1384              : 
    1385              : /**
    1386              :  * @brief Extract broadcast audio immediate rendering flag
    1387              :  *
    1388              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
    1389              :  *
    1390              :  * @param codec_cfg The codec data to search in.
    1391              :  *
    1392              :  * @retval 0 The flag was found
    1393              :  * @retval -EINVAL Arguments are invalid
    1394              :  * @retval -ENODATA The flag was not found
    1395              :  */
    1396            1 : int bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(
    1397              :         const struct bt_audio_codec_cfg *codec_cfg);
    1398              : 
    1399              : /**
    1400              :  * @brief Set the broadcast audio immediate rendering flag of a codec configuration metadata.
    1401              :  *
    1402              :  * @param codec_cfg The codec configuration to set data for.
    1403              :  *
    1404              :  * @retval data_len The @p codec_cfg.data_len on success
    1405              :  * @retval -EINVAL Arguments are invalid
    1406              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1407              :  */
    1408            1 : int bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag(
    1409              :         struct bt_audio_codec_cfg *codec_cfg);
    1410              : 
    1411              : /**
    1412              :  * @brief Extract assisted listening stream
    1413              :  *
    1414              :  * See @ref BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM for more information about this value.
    1415              :  *
    1416              :  * @param codec_cfg The codec data to search in.
    1417              :  *
    1418              :  * @retval value The assisted listening stream value if positive or 0
    1419              :  * @retval -EINVAL Arguments are invalid
    1420              :  * @retval -ENODATA Data not found
    1421              :  * @retval -EBADMSG The found value has invalid size
    1422              :  */
    1423            1 : int bt_audio_codec_cfg_meta_get_assisted_listening_stream(
    1424              :         const struct bt_audio_codec_cfg *codec_cfg);
    1425              : 
    1426              : /**
    1427              :  * @brief Set the assisted listening stream value of a codec configuration metadata.
    1428              :  *
    1429              :  * @param codec_cfg The codec configuration to set data for.
    1430              :  * @param val       The assisted listening stream value to set.
    1431              :  *
    1432              :  * @retval data_len The @p codec_cap.data_len on success
    1433              :  * @retval -EINVAL Arguments are invalid
    1434              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1435              :  */
    1436            1 : int bt_audio_codec_cfg_meta_set_assisted_listening_stream(
    1437              :         struct bt_audio_codec_cfg *codec_cfg, enum bt_audio_assisted_listening_stream val);
    1438              : 
    1439              : /**
    1440              :  * @brief Extract broadcast name
    1441              :  *
    1442              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_NAME for more information about this value.
    1443              :  *
    1444              :  * @param[in]  codec_cfg      The codec data to search in.
    1445              :  * @param[out] broadcast_name Pointer to the UTF-8 formatted broadcast name.
    1446              :  *
    1447              :  * @retval length The length of the @p broadcast_name (may be 0)
    1448              :  * @retval -EINVAL Arguments are invalid
    1449              :  * @retval -ENODATA Data not found
    1450              :  */
    1451            1 : int bt_audio_codec_cfg_meta_get_broadcast_name(const struct bt_audio_codec_cfg *codec_cfg,
    1452              :                                                const uint8_t **broadcast_name);
    1453              : 
    1454              : /**
    1455              :  * @brief Set the broadcast name of a codec configuration metadata.
    1456              :  *
    1457              :  * @param codec_cfg          The codec configuration to set data for.
    1458              :  * @param broadcast_name     The broadcast name to set.
    1459              :  * @param broadcast_name_len The length of @p broadcast_name.
    1460              :  *
    1461              :  * @retval data_len The @p codec_cfg.data_len on success
    1462              :  * @retval -EINVAL Arguments are invalid
    1463              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1464              :  */
    1465            1 : int bt_audio_codec_cfg_meta_set_broadcast_name(struct bt_audio_codec_cfg *codec_cfg,
    1466              :                                                const uint8_t *broadcast_name,
    1467              :                                                size_t broadcast_name_len);
    1468              : 
    1469              : /**
    1470              :  * @brief Extract extended metadata
    1471              :  *
    1472              :  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
    1473              :  *
    1474              :  * @param[in]  codec_cfg     The codec data to search in.
    1475              :  * @param[out] extended_meta Pointer to the extended metadata.
    1476              :  *
    1477              :  * @retval len The length of the @p extended_meta (may be 0)
    1478              :  * @retval -EINVAL Arguments are invalid
    1479              :  * @retval -ENODATA Data not found
    1480              :  */
    1481            1 : int bt_audio_codec_cfg_meta_get_extended(const struct bt_audio_codec_cfg *codec_cfg,
    1482              :                                          const uint8_t **extended_meta);
    1483              : 
    1484              : /**
    1485              :  * @brief Set the extended metadata of a codec configuration metadata.
    1486              :  *
    1487              :  * @param codec_cfg         The codec configuration to set data for.
    1488              :  * @param extended_meta     The extended metadata to set.
    1489              :  * @param extended_meta_len The length of @p extended_meta.
    1490              :  *
    1491              :  * @retval data_len The @p codec_cfg.data_len on success
    1492              :  * @retval -EINVAL Arguments are invalid
    1493              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1494              :  */
    1495            1 : int bt_audio_codec_cfg_meta_set_extended(struct bt_audio_codec_cfg *codec_cfg,
    1496              :                                          const uint8_t *extended_meta, size_t extended_meta_len);
    1497              : 
    1498              : /**
    1499              :  * @brief Extract vendor specific metadata
    1500              :  *
    1501              :  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
    1502              :  *
    1503              :  * @param[in]  codec_cfg   The codec data to search in.
    1504              :  * @param[out] vendor_meta Pointer to the vendor specific metadata.
    1505              :  *
    1506              :  * @retval len The length of the @p vendor_meta (may be 0)
    1507              :  * @retval -EINVAL Arguments are invalid
    1508              :  * @retval -ENODATA Data not found
    1509              :  */
    1510            1 : int bt_audio_codec_cfg_meta_get_vendor(const struct bt_audio_codec_cfg *codec_cfg,
    1511              :                                        const uint8_t **vendor_meta);
    1512              : 
    1513              : /**
    1514              :  * @brief Set the vendor specific metadata of a codec configuration metadata.
    1515              :  *
    1516              :  * @param codec_cfg       The codec configuration to set data for.
    1517              :  * @param vendor_meta     The vendor specific metadata to set.
    1518              :  * @param vendor_meta_len The length of @p vendor_meta.
    1519              :  *
    1520              :  * @retval data_len The @p codec_cfg.data_len on success
    1521              :  * @retval -EINVAL Arguments are invalid
    1522              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1523              :  */
    1524            1 : int bt_audio_codec_cfg_meta_set_vendor(struct bt_audio_codec_cfg *codec_cfg,
    1525              :                                        const uint8_t *vendor_meta, size_t vendor_meta_len);
    1526              : /** @} */ /* End of bt_audio_codec_cfg */
    1527              : 
    1528              : /**
    1529              :  * @brief Audio codec capabilities APIs
    1530              :  * @defgroup bt_audio_codec_cap Codec capability parsing APIs
    1531              :  *
    1532              :  * Functions to parse codec capability data when formatted as LTV wrapped into @ref
    1533              :  * bt_audio_codec_cap.
    1534              :  *
    1535              :  * @{
    1536              :  */
    1537              : 
    1538              : /**
    1539              :  * @brief Lookup a specific value based on type
    1540              :  *
    1541              :  * @param[in]  codec_cap The codec data to search in.
    1542              :  * @param[in]  type The type id to look for
    1543              :  * @param[out] data Pointer to the data-pointer to update when item is found
    1544              :  *
    1545              :  * @retval len Length of found @p data (may be 0)
    1546              :  * @retval -EINVAL Arguments are invalid
    1547              :  * @retval -ENODATA Data not found
    1548              :  */
    1549            1 : int bt_audio_codec_cap_get_val(const struct bt_audio_codec_cap *codec_cap,
    1550              :                                enum bt_audio_codec_cap_type type, const uint8_t **data);
    1551              : 
    1552              : /**
    1553              :  * @brief Set or add a specific codec capability value
    1554              :  *
    1555              :  * @param codec_cap  The codec data to set the value in.
    1556              :  * @param type       The type id to set
    1557              :  * @param data       Pointer to the data-pointer to set
    1558              :  * @param data_len   Length of @p data
    1559              :  *
    1560              :  * @retval data_len The @p codec_cap.data_len on success
    1561              :  * @retval -EINVAL Arguments are invalid
    1562              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1563              :  */
    1564            1 : int bt_audio_codec_cap_set_val(struct bt_audio_codec_cap *codec_cap,
    1565              :                                enum bt_audio_codec_cap_type type, const uint8_t *data,
    1566              :                                size_t data_len);
    1567              : 
    1568              : /**
    1569              :  * @brief Unset a specific codec capability value
    1570              :  *
    1571              :  * The type and the value will be removed from the codec capability.
    1572              :  *
    1573              :  * @param codec_cap  The codec data to set the value in.
    1574              :  * @param type       The type id to unset.
    1575              :  *
    1576              :  * @retval data_len The @p codec_cap.data_len on success
    1577              :  * @retval -EINVAL Arguments are invalid
    1578              :  */
    1579            1 : int bt_audio_codec_cap_unset_val(struct bt_audio_codec_cap *codec_cap,
    1580              :                                  enum bt_audio_codec_cap_type type);
    1581              : 
    1582              : /**
    1583              :  * @brief Extract the frequency from a codec capability.
    1584              :  *
    1585              :  * @param codec_cap The codec capabilities to extract data from.
    1586              :  *
    1587              :  * @retval frequencies Bitfield of supported frequencies (@ref bt_audio_codec_cap_freq) if 0 or
    1588              :  *                     positive
    1589              :  * @retval -EINVAL Arguments are invalid
    1590              :  * @retval -ENODATA Data not found
    1591              :  * @retval -EBADMSG The found value has invalid size or value
    1592              :  */
    1593            1 : int bt_audio_codec_cap_get_freq(const struct bt_audio_codec_cap *codec_cap);
    1594              : 
    1595              : /**
    1596              :  * @brief Set the supported frequencies of a codec capability.
    1597              :  *
    1598              :  * @param codec_cap The codec capabilities to set data for.
    1599              :  * @param freq      The supported frequencies to set.
    1600              :  *
    1601              :  * @retval data_len The @p codec_cap.data_len on success
    1602              :  * @retval -EINVAL Arguments are invalid
    1603              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1604              :  */
    1605            1 : int bt_audio_codec_cap_set_freq(struct bt_audio_codec_cap *codec_cap,
    1606              :                                 enum bt_audio_codec_cap_freq freq);
    1607              : 
    1608              : /**
    1609              :  * @brief Extract the frequency from a codec capability.
    1610              :  *
    1611              :  * @param codec_cap The codec capabilities to extract data from.
    1612              :  *
    1613              :  * @retval durations Bitfield of supported frame durations if 0 or positive
    1614              :  * @retval -EINVAL Arguments are invalid
    1615              :  * @retval -ENODATA Data not found
    1616              :  * @retval -EBADMSG The found value has invalid size or value
    1617              :  */
    1618            1 : int bt_audio_codec_cap_get_frame_dur(const struct bt_audio_codec_cap *codec_cap);
    1619              : 
    1620              : /**
    1621              :  * @brief Set the frame duration of a codec capability.
    1622              :  *
    1623              :  * @param codec_cap The codec capabilities to set data for.
    1624              :  * @param frame_dur The frame duration to set.
    1625              :  *
    1626              :  * @retval data_len The @p codec_cap.data_len on success
    1627              :  * @retval -EINVAL Arguments are invalid
    1628              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1629              :  */
    1630            1 : int bt_audio_codec_cap_set_frame_dur(struct bt_audio_codec_cap *codec_cap,
    1631              :                                      enum bt_audio_codec_cap_frame_dur frame_dur);
    1632              : 
    1633              : /**
    1634              :  * @brief Extract the frequency from a codec capability.
    1635              :  *
    1636              :  * @param codec_cap The codec capabilities to extract data from.
    1637              :  * @param fallback_to_default If true this function will provide the default value of 1
    1638              :  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
    1639              :  *
    1640              :  * @retval channel_counts Number of supported channel counts if 0 or positive
    1641              :  * @retval -EINVAL Arguments are invalid
    1642              :  * @retval -ENODATA Data not found
    1643              :  * @retval -EBADMSG The found value has invalid size or value
    1644              :  */
    1645            1 : int bt_audio_codec_cap_get_supported_audio_chan_counts(const struct bt_audio_codec_cap *codec_cap,
    1646              :                                                        bool fallback_to_default);
    1647              : 
    1648              : /**
    1649              :  * @brief Set the channel count of a codec capability.
    1650              :  *
    1651              :  * @param codec_cap The codec capabilities to set data for.
    1652              :  * @param chan_count The channel count frequency to set.
    1653              :  *
    1654              :  * @retval data_len The @p codec_cap.data_len on success
    1655              :  * @retval -EINVAL Arguments are invalid
    1656              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1657              :  */
    1658            1 : int bt_audio_codec_cap_set_supported_audio_chan_counts(
    1659              :         struct bt_audio_codec_cap *codec_cap, enum bt_audio_codec_cap_chan_count chan_count);
    1660              : 
    1661              : /**
    1662              :  * @brief Extract the supported octets per codec frame from a codec capability.
    1663              :  *
    1664              :  * @param[in]  codec_cap   The codec capabilities to extract data from.
    1665              :  * @param[out] codec_frame Struct to place the resulting values in
    1666              :  *
    1667              :  * @retval 0 Success
    1668              :  * @retval -EINVAL Arguments are invalid
    1669              :  * @retval -ENODATA Data not found
    1670              :  * @retval -EBADMSG The found value has invalid size or value
    1671              :  */
    1672            1 : int bt_audio_codec_cap_get_octets_per_frame(
    1673              :         const struct bt_audio_codec_cap *codec_cap,
    1674              :         struct bt_audio_codec_octets_per_codec_frame *codec_frame);
    1675              : 
    1676              : /**
    1677              :  * @brief Set the octets per codec frame of a codec capability.
    1678              :  *
    1679              :  * @param codec_cap   The codec capabilities to set data for.
    1680              :  * @param codec_frame The octets per codec frame to set.
    1681              :  *
    1682              :  * @retval data_len The @p codec_cap.data_len on success
    1683              :  * @retval -EINVAL Arguments are invalid
    1684              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1685              :  */
    1686            1 : int bt_audio_codec_cap_set_octets_per_frame(
    1687              :         struct bt_audio_codec_cap *codec_cap,
    1688              :         const struct bt_audio_codec_octets_per_codec_frame *codec_frame);
    1689              : 
    1690              : /**
    1691              :  * @brief Extract the maximum codec frames per SDU from a codec capability.
    1692              :  *
    1693              :  * @param codec_cap The codec capabilities to extract data from.
    1694              :  * @param fallback_to_default If true this function will provide the default value of 1
    1695              :  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
    1696              :  *
    1697              :  * @retval codec_frames_per_sdu Maximum number of codec frames per SDU supported
    1698              :  * @retval -EINVAL Arguments are invalid
    1699              :  * @retval -ENODATA Data not found
    1700              :  * @retval -EBADMSG The found value has invalid size or value
    1701              :  */
    1702            1 : int bt_audio_codec_cap_get_max_codec_frames_per_sdu(const struct bt_audio_codec_cap *codec_cap,
    1703              :                                                     bool fallback_to_default);
    1704              : 
    1705              : /**
    1706              :  * @brief Set the maximum codec frames per SDU of a codec capability.
    1707              :  *
    1708              :  * @param codec_cap            The codec capabilities to set data for.
    1709              :  * @param codec_frames_per_sdu The maximum codec frames per SDU to set.
    1710              :  *
    1711              :  * @retval data_len The @p codec_cap.data_len on success
    1712              :  * @retval -EINVAL Arguments are invalid
    1713              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1714              :  */
    1715            1 : int bt_audio_codec_cap_set_max_codec_frames_per_sdu(struct bt_audio_codec_cap *codec_cap,
    1716              :                                                     uint8_t codec_frames_per_sdu);
    1717              : 
    1718              : /**
    1719              :  * @brief Lookup a specific metadata value based on type
    1720              :  *
    1721              :  * @param[in]  codec_cap The codec data to search in.
    1722              :  * @param[in]  type      The type id to look for
    1723              :  * @param[out] data      Pointer to the data-pointer to update when item is found
    1724              :  *
    1725              :  * @retval len Length of found @p data (may be 0)
    1726              :  * @retval -EINVAL Arguments are invalid
    1727              :  * @retval -ENODATA Data not found
    1728              :  */
    1729            1 : int bt_audio_codec_cap_meta_get_val(const struct bt_audio_codec_cap *codec_cap, uint8_t type,
    1730              :                                     const uint8_t **data);
    1731              : 
    1732              : /**
    1733              :  * @brief Set or add a specific codec capability metadata value.
    1734              :  *
    1735              :  * @param codec_cap  The codec capability to set the value in.
    1736              :  * @param type       The type id to set.
    1737              :  * @param data       Pointer to the data-pointer to set.
    1738              :  * @param data_len   Length of @p data.
    1739              :  *
    1740              :  * @retval meta_len The @p codec_cap.meta_len on success
    1741              :  * @retval -EINVAL Arguments are invalid
    1742              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1743              :  */
    1744            1 : int bt_audio_codec_cap_meta_set_val(struct bt_audio_codec_cap *codec_cap,
    1745              :                                     enum bt_audio_metadata_type type, const uint8_t *data,
    1746              :                                     size_t data_len);
    1747              : 
    1748              : /**
    1749              :  * @brief Unset a specific codec capability metadata value
    1750              :  *
    1751              :  * The type and the value will be removed from the codec capability metadata.
    1752              :  *
    1753              :  * @param codec_cap  The codec data to set the value in.
    1754              :  * @param type       The type id to unset.
    1755              :  *
    1756              :  * @retval meta_len The of @p codec_cap.meta_len on success
    1757              :  * @retval -EINVAL Arguments are invalid
    1758              :  */
    1759            1 : int bt_audio_codec_cap_meta_unset_val(struct bt_audio_codec_cap *codec_cap,
    1760              :                                       enum bt_audio_metadata_type type);
    1761              : 
    1762              : /**
    1763              :  * @brief Extract preferred contexts
    1764              :  *
    1765              :  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
    1766              :  *
    1767              :  * @param codec_cap The codec data to search in.
    1768              :  *
    1769              :  * @retval The preferred context type if positive or 0
    1770              :  * @retval -EINVAL Arguments are invalid
    1771              :  * @retval -ENODATA Data not found
    1772              :  * @retval -EBADMSG The found value has invalid size
    1773              :  */
    1774            1 : int bt_audio_codec_cap_meta_get_pref_context(const struct bt_audio_codec_cap *codec_cap);
    1775              : 
    1776              : /**
    1777              :  * @brief Set the preferred context of a codec capability metadata.
    1778              :  *
    1779              :  * @param codec_cap The codec capability to set data for.
    1780              :  * @param ctx       The preferred context to set.
    1781              :  *
    1782              :  * @retval data_len The @p codec_cap.data_len on success
    1783              :  * @retval -EINVAL Arguments are invalid
    1784              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1785              :  */
    1786            1 : int bt_audio_codec_cap_meta_set_pref_context(struct bt_audio_codec_cap *codec_cap,
    1787              :                                              enum bt_audio_context ctx);
    1788              : 
    1789              : /**
    1790              :  * @brief Extract stream contexts
    1791              :  *
    1792              :  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
    1793              :  *
    1794              :  * @param codec_cap The codec data to search in.
    1795              :  *
    1796              :  * @retval context The stream context type if positive or 0
    1797              :  * @retval -EINVAL Arguments are invalid
    1798              :  * @retval -ENODATA Data not found
    1799              :  * @retval -EBADMSG The found value has invalid size
    1800              :  */
    1801            1 : int bt_audio_codec_cap_meta_get_stream_context(const struct bt_audio_codec_cap *codec_cap);
    1802              : 
    1803              : /**
    1804              :  * @brief Set the stream context of a codec capability metadata.
    1805              :  *
    1806              :  * @param codec_cap The codec capability to set data for.
    1807              :  * @param ctx       The stream context to set.
    1808              :  *
    1809              :  * @retval data_len The @p codec_cap.data_len on success
    1810              :  * @retval -EINVAL Arguments are invalid
    1811              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1812              :  */
    1813            1 : int bt_audio_codec_cap_meta_set_stream_context(struct bt_audio_codec_cap *codec_cap,
    1814              :                                                enum bt_audio_context ctx);
    1815              : 
    1816              : /**
    1817              :  * @brief Extract program info
    1818              :  *
    1819              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
    1820              :  *
    1821              :  * @param[in]  codec_cap    The codec data to search in.
    1822              :  * @param[out] program_info Pointer to the UTF-8 formatted program info.
    1823              :  *
    1824              :  * @retval len The length of the @p program_info (may be 0)
    1825              :  * @retval -EINVAL Arguments are invalid
    1826              :  * @retval -ENODATA Data not found
    1827              :  */
    1828            1 : int bt_audio_codec_cap_meta_get_program_info(const struct bt_audio_codec_cap *codec_cap,
    1829              :                                              const uint8_t **program_info);
    1830              : 
    1831              : /**
    1832              :  * @brief Set the program info of a codec capability metadata.
    1833              :  *
    1834              :  * @param codec_cap        The codec capability to set data for.
    1835              :  * @param program_info     The program info to set.
    1836              :  * @param program_info_len The length of @p program_info.
    1837              :  *
    1838              :  * @retval data_len The @p codec_cap.data_len on success
    1839              :  * @retval -EINVAL Arguments are invalid
    1840              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1841              :  */
    1842            1 : int bt_audio_codec_cap_meta_set_program_info(struct bt_audio_codec_cap *codec_cap,
    1843              :                                              const uint8_t *program_info, size_t program_info_len);
    1844              : 
    1845              : /**
    1846              :  * @brief Extract language
    1847              :  *
    1848              :  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
    1849              :  *
    1850              :  * @param[in]  codec_cap The codec data to search in.
    1851              :  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
    1852              :  *
    1853              :  * @retval 0 Success
    1854              :  * @retval -EINVAL Arguments are invalid
    1855              :  * @retval -ENODATA Data not found
    1856              :  * @retval -EBADMSG The found value has invalid size
    1857              :  */
    1858            1 : int bt_audio_codec_cap_meta_get_lang(const struct bt_audio_codec_cap *codec_cap,
    1859              :                                      const uint8_t **lang);
    1860              : 
    1861              : /**
    1862              :  * @brief Set the language of a codec capability metadata.
    1863              :  *
    1864              :  * @param codec_cap   The codec capability to set data for.
    1865              :  * @param lang        The 24-bit language to set.
    1866              :  *
    1867              :  * @retval data_len The @p codec_cap.data_len on success
    1868              :  * @retval -EINVAL Arguments are invalid
    1869              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1870              :  */
    1871            1 : int bt_audio_codec_cap_meta_set_lang(struct bt_audio_codec_cap *codec_cap,
    1872              :                                      const uint8_t lang[BT_AUDIO_LANG_SIZE]);
    1873              : 
    1874              : /**
    1875              :  * @brief Extract CCID list
    1876              :  *
    1877              :  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
    1878              :  *
    1879              :  * @param[in]  codec_cap The codec data to search in.
    1880              :  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
    1881              :  *
    1882              :  * @retval len The length of the @p ccid_list (may be 0)
    1883              :  * @retval -EINVAL Arguments are invalid
    1884              :  * @retval -ENODATA Data not found
    1885              :  */
    1886            1 : int bt_audio_codec_cap_meta_get_ccid_list(const struct bt_audio_codec_cap *codec_cap,
    1887              :                                           const uint8_t **ccid_list);
    1888              : 
    1889              : /**
    1890              :  * @brief Set the CCID list of a codec capability metadata.
    1891              :  *
    1892              :  * @param codec_cap     The codec capability to set data for.
    1893              :  * @param ccid_list     The program info to set.
    1894              :  * @param ccid_list_len The length of @p ccid_list.
    1895              :  *
    1896              :  * @retval data_len The @p codec_cap.data_len on success
    1897              :  * @retval -EINVAL Arguments are invalid
    1898              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1899              :  */
    1900            1 : int bt_audio_codec_cap_meta_set_ccid_list(struct bt_audio_codec_cap *codec_cap,
    1901              :                                           const uint8_t *ccid_list, size_t ccid_list_len);
    1902              : 
    1903              : /**
    1904              :  * @brief Extract parental rating
    1905              :  *
    1906              :  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
    1907              :  *
    1908              :  * @param codec_cap The codec data to search in.
    1909              :  *
    1910              :  * @retval The parental rating if positive or 0
    1911              :  * @retval -EINVAL Arguments are invalid
    1912              :  * @retval -ENODATA Data not found
    1913              :  * @retval -EBADMSG The found value has invalid size
    1914              :  */
    1915            1 : int bt_audio_codec_cap_meta_get_parental_rating(const struct bt_audio_codec_cap *codec_cap);
    1916              : 
    1917              : /**
    1918              :  * @brief Set the parental rating of a codec capability metadata.
    1919              :  *
    1920              :  * @param codec_cap       The codec capability to set data for.
    1921              :  * @param parental_rating The parental rating to set.
    1922              :  *
    1923              :  * @retval data_len The @p codec_cap.data_len on success
    1924              :  * @retval -EINVAL Arguments are invalid
    1925              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1926              :  */
    1927            1 : int bt_audio_codec_cap_meta_set_parental_rating(struct bt_audio_codec_cap *codec_cap,
    1928              :                                                 enum bt_audio_parental_rating parental_rating);
    1929              : 
    1930              : /**
    1931              :  * @brief Extract program info URI
    1932              :  *
    1933              :  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
    1934              :  *
    1935              :  * @param[in]  codec_cap        The codec data to search in.
    1936              :  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
    1937              :  *
    1938              :  * @retval len The length of the @p program_info_uri (may be 0)
    1939              :  * @retval -EINVAL Arguments are invalid
    1940              :  * @retval -ENODATA Data not found
    1941              :  */
    1942            1 : int bt_audio_codec_cap_meta_get_program_info_uri(const struct bt_audio_codec_cap *codec_cap,
    1943              :                                                  const uint8_t **program_info_uri);
    1944              : 
    1945              : /**
    1946              :  * @brief Set the program info URI of a codec capability metadata.
    1947              :  *
    1948              :  * @param codec_cap            The codec capability to set data for.
    1949              :  * @param program_info_uri     The program info URI to set.
    1950              :  * @param program_info_uri_len The length of @p program_info_uri.
    1951              :  *
    1952              :  * @retval data_len The @p codec_cap.data_len on success
    1953              :  * @retval -EINVAL Arguments are invalid
    1954              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1955              :  */
    1956            1 : int bt_audio_codec_cap_meta_set_program_info_uri(struct bt_audio_codec_cap *codec_cap,
    1957              :                                                  const uint8_t *program_info_uri,
    1958              :                                                  size_t program_info_uri_len);
    1959              : 
    1960              : /**
    1961              :  * @brief Extract audio active state
    1962              :  *
    1963              :  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
    1964              :  *
    1965              :  * @param codec_cap The codec data to search in.
    1966              :  *
    1967              :  * @retval context The preferred context type if positive or 0
    1968              :  * @retval -EINVAL Arguments are invalid
    1969              :  * @retval -ENODATA Data not found
    1970              :  * @retval -EBADMSG The found value has invalid size
    1971              :  */
    1972            1 : int bt_audio_codec_cap_meta_get_audio_active_state(const struct bt_audio_codec_cap *codec_cap);
    1973              : 
    1974              : /**
    1975              :  * @brief Set the audio active state of a codec capability metadata.
    1976              :  *
    1977              :  * @param codec_cap The codec capability to set data for.
    1978              :  * @param state     The audio active state to set.
    1979              :  *
    1980              :  * @retval data_len The @p codec_cap.data_len on success
    1981              :  * @retval -EINVAL Arguments are invalid
    1982              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    1983              :  */
    1984            1 : int bt_audio_codec_cap_meta_set_audio_active_state(struct bt_audio_codec_cap *codec_cap,
    1985              :                                                    enum bt_audio_active_state state);
    1986              : 
    1987              : /**
    1988              :  * @brief Extract broadcast audio immediate rendering flag
    1989              :  *
    1990              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
    1991              :  *
    1992              :  * @param codec_cap The codec data to search in.
    1993              :  *
    1994              :  * @retval 0 The flag was found
    1995              :  * @retval -EINVAL Arguments are invalid
    1996              :  * @retval -ENODATA The flag was not found
    1997              :  */
    1998            1 : int bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(
    1999              :         const struct bt_audio_codec_cap *codec_cap);
    2000              : 
    2001              : /**
    2002              :  * @brief Set the broadcast audio immediate rendering flag of a codec capability metadata.
    2003              :  *
    2004              :  * @param codec_cap The codec capability to set data for.
    2005              :  *
    2006              :  * @retval data_len The @p codec_cap.data_len on success
    2007              :  * @retval -EINVAL Arguments are invalid
    2008              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    2009              :  */
    2010            1 : int bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag(
    2011              :         struct bt_audio_codec_cap *codec_cap);
    2012              : 
    2013              : /**
    2014              :  * @brief Extract assisted listening stream
    2015              :  *
    2016              :  * See @ref BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM for more information about this value.
    2017              :  *
    2018              :  * @param codec_cap The codec data to search in.
    2019              :  *
    2020              :  * @retval value The assisted listening stream value if positive or 0
    2021              :  * @retval -EINVAL Arguments are invalid
    2022              :  * @retval -ENODATA Data not found
    2023              :  * @retval -EBADMSG The found value has invalid size
    2024              :  */
    2025            1 : int bt_audio_codec_cap_meta_get_assisted_listening_stream(
    2026              :         const struct bt_audio_codec_cap *codec_cap);
    2027              : 
    2028              : /**
    2029              :  * @brief Set the assisted listening stream value of a codec capability metadata.
    2030              :  *
    2031              :  * @param codec_cap The codec capability to set data for.
    2032              :  * @param val       The assisted listening stream value to set.
    2033              :  *
    2034              :  * @retval data_len The @p codec_cap.data_len on success
    2035              :  * @retval -EINVAL Arguments are invalid
    2036              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    2037              :  */
    2038            1 : int bt_audio_codec_cap_meta_set_assisted_listening_stream(
    2039              :         struct bt_audio_codec_cap *codec_cap, enum bt_audio_assisted_listening_stream val);
    2040              : 
    2041              : /**
    2042              :  * @brief Extract broadcast name
    2043              :  *
    2044              :  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_NAME for more information about this value.
    2045              :  *
    2046              :  * @param[in]  codec_cap      The codec data to search in.
    2047              :  * @param[out] broadcast_name Pointer to the UTF-8 formatted broadcast name.
    2048              :  *
    2049              :  * @retval length The length of the @p broadcast_name (may be 0)
    2050              :  * @retval -EINVAL Arguments are invalid
    2051              :  * @retval -ENODATA Data not found
    2052              :  */
    2053            1 : int bt_audio_codec_cap_meta_get_broadcast_name(const struct bt_audio_codec_cap *codec_cap,
    2054              :                                                const uint8_t **broadcast_name);
    2055              : 
    2056              : /**
    2057              :  * @brief Set the broadcast name of a codec capability metadata.
    2058              :  *
    2059              :  * @param codec_cap          The codec capability to set data for.
    2060              :  * @param broadcast_name     The broadcast name to set.
    2061              :  * @param broadcast_name_len The length of @p broadcast_name.
    2062              :  *
    2063              :  * @retval data_len The @p codec_cap.data_len on success
    2064              :  * @retval -EINVAL Arguments are invalid
    2065              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    2066              :  */
    2067            1 : int bt_audio_codec_cap_meta_set_broadcast_name(struct bt_audio_codec_cap *codec_cap,
    2068              :                                                const uint8_t *broadcast_name,
    2069              :                                                size_t broadcast_name_len);
    2070              : /**
    2071              :  * @brief Extract extended metadata
    2072              :  *
    2073              :  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
    2074              :  *
    2075              :  * @param[in]  codec_cap     The codec data to search in.
    2076              :  * @param[out] extended_meta Pointer to the extended metadata.
    2077              :  *
    2078              :  * @retval len The length of the @p extended_meta (may be 0)
    2079              :  * @retval -EINVAL Arguments are invalid
    2080              :  * @retval -ENODATA Data not found
    2081              :  */
    2082            1 : int bt_audio_codec_cap_meta_get_extended(const struct bt_audio_codec_cap *codec_cap,
    2083              :                                          const uint8_t **extended_meta);
    2084              : 
    2085              : /**
    2086              :  * @brief Set the extended metadata of a codec capability metadata.
    2087              :  *
    2088              :  * @param codec_cap         The codec capability to set data for.
    2089              :  * @param extended_meta     The extended metadata to set.
    2090              :  * @param extended_meta_len The length of @p extended_meta.
    2091              :  *
    2092              :  * @retval data_len The @p codec_cap.data_len on success
    2093              :  * @retval -EINVAL Arguments are invalid
    2094              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    2095              :  */
    2096            1 : int bt_audio_codec_cap_meta_set_extended(struct bt_audio_codec_cap *codec_cap,
    2097              :                                          const uint8_t *extended_meta, size_t extended_meta_len);
    2098              : 
    2099              : /**
    2100              :  * @brief Extract vendor specific metadata
    2101              :  *
    2102              :  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
    2103              :  *
    2104              :  * @param[in]  codec_cap   The codec data to search in.
    2105              :  * @param[out] vendor_meta Pointer to the vendor specific metadata.
    2106              :  *
    2107              :  * @retval len The length of the @p vendor_meta (may be 0)
    2108              :  * @retval -EINVAL Arguments are invalid
    2109              :  * @retval -ENODATA Data not found
    2110              :  */
    2111            1 : int bt_audio_codec_cap_meta_get_vendor(const struct bt_audio_codec_cap *codec_cap,
    2112              :                                        const uint8_t **vendor_meta);
    2113              : 
    2114              : /**
    2115              :  * @brief Set the vendor specific metadata of a codec capability metadata.
    2116              :  *
    2117              :  * @param codec_cap       The codec capability to set data for.
    2118              :  * @param vendor_meta     The vendor specific metadata to set.
    2119              :  * @param vendor_meta_len The length of @p vendor_meta.
    2120              :  *
    2121              :  * @retval data_len The @p codec_cap.data_len on success
    2122              :  * @retval -EINVAL Arguments are invalid
    2123              :  * @retval -ENOMEM The new value could not be set or added due to lack of memory
    2124              :  */
    2125            1 : int bt_audio_codec_cap_meta_set_vendor(struct bt_audio_codec_cap *codec_cap,
    2126              :                                        const uint8_t *vendor_meta, size_t vendor_meta_len);
    2127              : 
    2128              : /** @} */ /* End of bt_audio_codec_cap */
    2129              : 
    2130              : /**
    2131              :  * @brief Assigned numbers to string API
    2132              :  * @defgroup bt_audio_to_str Assigned numbers to string API
    2133              :  *
    2134              :  * Functions to return string representation of Bluetooth Audio assigned number values.
    2135              :  *
    2136              :  * @{
    2137              :  */
    2138              : 
    2139              : /**
    2140              :  * @brief Returns a string representation of a specific @ref bt_audio_context bit
    2141              :  *
    2142              :  * If @p context contains multiple bits, it will return "Unknown context"
    2143              :  *
    2144              :  * @param context A single context bit
    2145              :  *
    2146              :  * @return String representation of the supplied bit
    2147              :  */
    2148            1 : static inline char *bt_audio_context_bit_to_str(enum bt_audio_context context)
    2149              : {
    2150              :         switch (context) {
    2151              :         case BT_AUDIO_CONTEXT_TYPE_NONE:
    2152              :                 return "None";
    2153              :         case BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED:
    2154              :                 return "Unspecified";
    2155              :         case BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL:
    2156              :                 return "Conversational";
    2157              :         case BT_AUDIO_CONTEXT_TYPE_MEDIA:
    2158              :                 return "Media";
    2159              :         case BT_AUDIO_CONTEXT_TYPE_GAME:
    2160              :                 return "Game";
    2161              :         case BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL:
    2162              :                 return "Instructional";
    2163              :         case BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS:
    2164              :                 return "Voice assistant";
    2165              :         case BT_AUDIO_CONTEXT_TYPE_LIVE:
    2166              :                 return "Live";
    2167              :         case BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS:
    2168              :                 return "Sound effects";
    2169              :         case BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS:
    2170              :                 return "Notifications";
    2171              :         case BT_AUDIO_CONTEXT_TYPE_RINGTONE:
    2172              :                 return "Ringtone";
    2173              :         case BT_AUDIO_CONTEXT_TYPE_ALERTS:
    2174              :                 return "Alerts";
    2175              :         case BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM:
    2176              :                 return "Emergency alarm";
    2177              :         default:
    2178              :                 return "Unknown context";
    2179              :         }
    2180              : }
    2181              : 
    2182              : /**
    2183              :  * @brief Returns a string representation of a @ref bt_audio_parental_rating value
    2184              :  *
    2185              :  * @param parental_rating The parental rating value
    2186              :  *
    2187              :  * @return String representation of the supplied parental rating value
    2188              :  */
    2189            1 : static inline char *bt_audio_parental_rating_to_str(enum bt_audio_parental_rating parental_rating)
    2190              : {
    2191              :         switch (parental_rating) {
    2192              :         case BT_AUDIO_PARENTAL_RATING_NO_RATING:
    2193              :                 return "No rating";
    2194              :         case BT_AUDIO_PARENTAL_RATING_AGE_ANY:
    2195              :                 return "Any";
    2196              :         case BT_AUDIO_PARENTAL_RATING_AGE_5_OR_ABOVE:
    2197              :                 return "Age 5 or above";
    2198              :         case BT_AUDIO_PARENTAL_RATING_AGE_6_OR_ABOVE:
    2199              :                 return "Age 6 or above";
    2200              :         case BT_AUDIO_PARENTAL_RATING_AGE_7_OR_ABOVE:
    2201              :                 return "Age 7 or above";
    2202              :         case BT_AUDIO_PARENTAL_RATING_AGE_8_OR_ABOVE:
    2203              :                 return "Age 8 or above";
    2204              :         case BT_AUDIO_PARENTAL_RATING_AGE_9_OR_ABOVE:
    2205              :                 return "Age 9 or above";
    2206              :         case BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE:
    2207              :                 return "Age 10 or above";
    2208              :         case BT_AUDIO_PARENTAL_RATING_AGE_11_OR_ABOVE:
    2209              :                 return "Age 11 or above";
    2210              :         case BT_AUDIO_PARENTAL_RATING_AGE_12_OR_ABOVE:
    2211              :                 return "Age 12 or above";
    2212              :         case BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE:
    2213              :                 return "Age 13 or above";
    2214              :         case BT_AUDIO_PARENTAL_RATING_AGE_14_OR_ABOVE:
    2215              :                 return "Age 14 or above";
    2216              :         case BT_AUDIO_PARENTAL_RATING_AGE_15_OR_ABOVE:
    2217              :                 return "Age 15 or above";
    2218              :         case BT_AUDIO_PARENTAL_RATING_AGE_16_OR_ABOVE:
    2219              :                 return "Age 16 or above";
    2220              :         case BT_AUDIO_PARENTAL_RATING_AGE_17_OR_ABOVE:
    2221              :                 return "Age 17 or above";
    2222              :         case BT_AUDIO_PARENTAL_RATING_AGE_18_OR_ABOVE:
    2223              :                 return "Age 18 or above";
    2224              :         default:
    2225              :                 return "Unknown rating";
    2226              :         }
    2227              : }
    2228              : 
    2229              : /**
    2230              :  * @brief Returns a string representation of a @ref bt_audio_active_state value
    2231              :  *
    2232              :  * @param state The active state value
    2233              :  *
    2234              :  * @return String representation of the supplied active state value
    2235              :  */
    2236            1 : static inline char *bt_audio_active_state_to_str(enum bt_audio_active_state state)
    2237              : {
    2238              :         switch (state) {
    2239              :         case BT_AUDIO_ACTIVE_STATE_DISABLED:
    2240              :                 return "Disabled";
    2241              :         case BT_AUDIO_ACTIVE_STATE_ENABLED:
    2242              :                 return "Enabled";
    2243              :         default:
    2244              :                 return "Unknown active state";
    2245              :         }
    2246              : }
    2247              : 
    2248              : /**
    2249              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_freq bit
    2250              :  *
    2251              :  * If @p freq contains multiple bits, it will return "Unknown supported frequency"
    2252              :  *
    2253              :  * @param freq A single frequency bit
    2254              :  *
    2255              :  * @return String representation of the supplied bit
    2256              :  */
    2257            1 : static inline char *bt_audio_codec_cap_freq_bit_to_str(enum bt_audio_codec_cap_freq freq)
    2258              : {
    2259              :         switch (freq) {
    2260              :         case BT_AUDIO_CODEC_CAP_FREQ_8KHZ:
    2261              :                 return "8000 Hz";
    2262              :         case BT_AUDIO_CODEC_CAP_FREQ_11KHZ:
    2263              :                 return "11025 Hz";
    2264              :         case BT_AUDIO_CODEC_CAP_FREQ_16KHZ:
    2265              :                 return "16000 Hz";
    2266              :         case BT_AUDIO_CODEC_CAP_FREQ_22KHZ:
    2267              :                 return "22050 Hz";
    2268              :         case BT_AUDIO_CODEC_CAP_FREQ_24KHZ:
    2269              :                 return "24000 Hz";
    2270              :         case BT_AUDIO_CODEC_CAP_FREQ_32KHZ:
    2271              :                 return "32000 Hz";
    2272              :         case BT_AUDIO_CODEC_CAP_FREQ_44KHZ:
    2273              :                 return "44100 Hz";
    2274              :         case BT_AUDIO_CODEC_CAP_FREQ_48KHZ:
    2275              :                 return "48000 Hz";
    2276              :         case BT_AUDIO_CODEC_CAP_FREQ_88KHZ:
    2277              :                 return "88200 Hz";
    2278              :         case BT_AUDIO_CODEC_CAP_FREQ_96KHZ:
    2279              :                 return "96000 Hz";
    2280              :         case BT_AUDIO_CODEC_CAP_FREQ_176KHZ:
    2281              :                 return "176400 Hz";
    2282              :         case BT_AUDIO_CODEC_CAP_FREQ_192KHZ:
    2283              :                 return "192000 Hz";
    2284              :         case BT_AUDIO_CODEC_CAP_FREQ_384KHZ:
    2285              :                 return "384000 Hz";
    2286              :         default:
    2287              :                 return "Unknown supported frequency";
    2288              :         }
    2289              : }
    2290              : 
    2291              : /**
    2292              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_frame_dur bit
    2293              :  *
    2294              :  * If @p frame_dur contains multiple bits, it will return "Unknown frame duration"
    2295              :  *
    2296              :  * @param frame_dur A single frame duration bit
    2297              :  *
    2298              :  * @return String representation of the supplied bit
    2299              :  */
    2300              : static inline char *
    2301            1 : bt_audio_codec_cap_frame_dur_bit_to_str(enum bt_audio_codec_cap_frame_dur frame_dur)
    2302              : {
    2303              :         switch (frame_dur) {
    2304              :         case BT_AUDIO_CODEC_CAP_DURATION_7_5:
    2305              :                 return "7.5 ms";
    2306              :         case BT_AUDIO_CODEC_CAP_DURATION_10:
    2307              :                 return "10 ms";
    2308              :         case BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5:
    2309              :                 return "7.5 ms preferred";
    2310              :         case BT_AUDIO_CODEC_CAP_DURATION_PREFER_10:
    2311              :                 return "10 ms preferred";
    2312              :         default:
    2313              :                 return "Unknown frame duration";
    2314              :         }
    2315              : }
    2316              : 
    2317              : /**
    2318              :  * @brief Returns a string representation of a specific @ref bt_audio_codec_cap_chan_count bit
    2319              :  *
    2320              :  * If @p chan_count contains multiple bits, it will return "Unknown channel count"
    2321              :  *
    2322              :  * @param chan_count A single frame channel count bit
    2323              :  *
    2324              :  * @return String representation of the supplied bit
    2325              :  */
    2326              : static inline char *
    2327            1 : bt_audio_codec_cap_chan_count_bit_to_str(enum bt_audio_codec_cap_chan_count chan_count)
    2328              : {
    2329              :         switch (chan_count) {
    2330              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_1:
    2331              :                 return "1 channel";
    2332              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_2:
    2333              :                 return "2 channels";
    2334              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_3:
    2335              :                 return "3 channels";
    2336              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_4:
    2337              :                 return "4 channels";
    2338              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_5:
    2339              :                 return "5 channels";
    2340              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_6:
    2341              :                 return "6 channels";
    2342              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_7:
    2343              :                 return "7 channels";
    2344              :         case BT_AUDIO_CODEC_CAP_CHAN_COUNT_8:
    2345              :                 return "8 channels";
    2346              :         default:
    2347              :                 return "Unknown channel count";
    2348              :         }
    2349              : }
    2350              : 
    2351              : /**
    2352              :  * @brief Returns a string representation of a specific @ref bt_audio_location bit
    2353              :  *
    2354              :  * If @p location contains multiple bits, it will return "Unknown location"
    2355              :  *
    2356              :  * @param location A single location bit
    2357              :  *
    2358              :  * @return String representation of the supplied bit
    2359              :  */
    2360            1 : static inline char *bt_audio_location_bit_to_str(enum bt_audio_location location)
    2361              : {
    2362              :         switch (location) {
    2363              :         case BT_AUDIO_LOCATION_MONO_AUDIO:
    2364              :                 return "Mono";
    2365              :         case BT_AUDIO_LOCATION_FRONT_LEFT:
    2366              :                 return "Front left";
    2367              :         case BT_AUDIO_LOCATION_FRONT_RIGHT:
    2368              :                 return "Front right";
    2369              :         case BT_AUDIO_LOCATION_FRONT_CENTER:
    2370              :                 return "Front center";
    2371              :         case BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1:
    2372              :                 return "Low frequency effects 1";
    2373              :         case BT_AUDIO_LOCATION_BACK_LEFT:
    2374              :                 return "Back left";
    2375              :         case BT_AUDIO_LOCATION_BACK_RIGHT:
    2376              :                 return "Back right";
    2377              :         case BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER:
    2378              :                 return "Front left of center";
    2379              :         case BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER:
    2380              :                 return "Front right of center";
    2381              :         case BT_AUDIO_LOCATION_BACK_CENTER:
    2382              :                 return "Back center";
    2383              :         case BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2:
    2384              :                 return "Low frequency effects 2";
    2385              :         case BT_AUDIO_LOCATION_SIDE_LEFT:
    2386              :                 return "Side left";
    2387              :         case BT_AUDIO_LOCATION_SIDE_RIGHT:
    2388              :                 return "Side right";
    2389              :         case BT_AUDIO_LOCATION_TOP_FRONT_LEFT:
    2390              :                 return "Top front left";
    2391              :         case BT_AUDIO_LOCATION_TOP_FRONT_RIGHT:
    2392              :                 return "Top front right";
    2393              :         case BT_AUDIO_LOCATION_TOP_FRONT_CENTER:
    2394              :                 return "Top front center";
    2395              :         case BT_AUDIO_LOCATION_TOP_CENTER:
    2396              :                 return "Top center";
    2397              :         case BT_AUDIO_LOCATION_TOP_BACK_LEFT:
    2398              :                 return "Top back left";
    2399              :         case BT_AUDIO_LOCATION_TOP_BACK_RIGHT:
    2400              :                 return "Top back right";
    2401              :         case BT_AUDIO_LOCATION_TOP_SIDE_LEFT:
    2402              :                 return "Top side left";
    2403              :         case BT_AUDIO_LOCATION_TOP_SIDE_RIGHT:
    2404              :                 return "Top side right";
    2405              :         case BT_AUDIO_LOCATION_TOP_BACK_CENTER:
    2406              :                 return "Top back center";
    2407              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER:
    2408              :                 return "Bottom front center";
    2409              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT:
    2410              :                 return "Bottom front left";
    2411              :         case BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT:
    2412              :                 return "Bottom front right";
    2413              :         case BT_AUDIO_LOCATION_FRONT_LEFT_WIDE:
    2414              :                 return "Front left wide";
    2415              :         case BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE:
    2416              :                 return "Front right wde";
    2417              :         case BT_AUDIO_LOCATION_LEFT_SURROUND:
    2418              :                 return "Left surround";
    2419              :         case BT_AUDIO_LOCATION_RIGHT_SURROUND:
    2420              :                 return "Right surround";
    2421              :         default:
    2422              :                 return "Unknown location";
    2423              :         }
    2424              : }
    2425              : 
    2426              : /** @} */ /* End of bt_audio_to_str */
    2427              : #ifdef __cplusplus
    2428              : }
    2429              : #endif
    2430              : 
    2431              : /** @} */ /* end of bt_audio */
    2432              : 
    2433              : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_H_ */
        

Generated by: LCOV version 2.0-1