LCOV - code coverage report
Current view: top level - zephyr/bluetooth/classic - a2dp.h Coverage Total Hit
Test: new.info Lines: 95.3 % 85 81
Test Date: 2025-09-25 19:22:35

            Line data    Source code
       1            1 : /** @file
       2              :  * @brief Advanced Audio Distribution Profile header.
       3              :  */
       4              : 
       5              : /*
       6              :  * Copyright (c) 2015-2016 Intel Corporation
       7              :  * Copyright 2024 NXP
       8              :  *
       9              :  * SPDX-License-Identifier: Apache-2.0
      10              :  */
      11              : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
      12              : #define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
      13              : 
      14              : #include <stdint.h>
      15              : 
      16              : #include <zephyr/bluetooth/bluetooth.h>
      17              : #include <zephyr/bluetooth/l2cap.h>
      18              : #include <zephyr/bluetooth/classic/avdtp.h>
      19              : 
      20              : #ifdef __cplusplus
      21              : extern "C" {
      22              : #endif
      23              : 
      24              : /** SBC IE length */
      25            1 : #define BT_A2DP_SBC_IE_LENGTH      (4U)
      26              : /** MPEG1,2 IE length */
      27            1 : #define BT_A2DP_MPEG_1_2_IE_LENGTH (4U)
      28              : /** MPEG2,4 IE length */
      29            1 : #define BT_A2DP_MPEG_2_4_IE_LENGTH (6U)
      30              : /** The max IE (Codec Info Element) length */
      31            1 : #define BT_A2DP_MAX_IE_LENGTH      (8U)
      32              : 
      33              : /** @brief define the audio endpoint
      34              :  *  @param _role BT_AVDTP_SOURCE or BT_AVDTP_SINK.
      35              :  *  @param _codec value of enum bt_a2dp_codec_id.
      36              :  *  @param _capability the codec capability.
      37              :  */
      38            1 : #define BT_A2DP_EP_INIT(_role, _codec, _capability)                                                \
      39              :         {                                                                                          \
      40              :                 .codec_type = _codec,                                                              \
      41              :                 .sep = {.sep_info = {.media_type = BT_AVDTP_AUDIO, .tsep = _role}},                \
      42              :                 .codec_cap = _capability, .stream = NULL,                                          \
      43              :         }
      44              : 
      45              : /** @brief define the audio sink endpoint
      46              :  *  @param _codec value of enum bt_a2dp_codec_id.
      47              :  *  @param _capability the codec capability.
      48              :  */
      49            1 : #define BT_A2DP_SINK_EP_INIT(_codec, _capability)                                                  \
      50              :         BT_A2DP_EP_INIT(BT_AVDTP_SINK, _codec, _capability)
      51              : 
      52              : /** @brief define the audio source endpoint
      53              :  *  @param _codec value of enum bt_a2dp_codec_id.
      54              :  *  @param _capability the codec capability.
      55              :  */
      56            1 : #define BT_A2DP_SOURCE_EP_INIT(_codec, _capability)                                                \
      57              :         BT_A2DP_EP_INIT(BT_AVDTP_SOURCE, _codec, _capability)
      58              : 
      59              : /** @brief define the SBC sink endpoint that can be used as
      60              :  * bt_a2dp_register_endpoint's parameter.
      61              :  *
      62              :  * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SINK_EP_DEFAULT
      63              :  * is more convenient for user to register SBC endpoint.
      64              :  *
      65              :  *  @param _name unique structure name postfix.
      66              :  *  @param _freq sbc codec frequency.
      67              :  *               for example: A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000
      68              :  *  @param _ch_mode sbc codec channel mode.
      69              :  *               for example: A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO
      70              :  *  @param _blk_len sbc codec block length.
      71              :  *               for example: A2DP_SBC_BLK_LEN_16
      72              :  *  @param _subband sbc codec subband.
      73              :  *               for example: A2DP_SBC_SUBBAND_8
      74              :  *  @param _alloc_mthd sbc codec allocate method.
      75              :  *               for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
      76              :  *  @param _min_bitpool sbc codec min bit pool. for example: 18
      77              :  *  @param _max_bitpool sbc codec max bit pool. for example: 35
      78              :  *  @
      79              :  */
      80              : #define BT_A2DP_SBC_SINK_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd, _min_bitpool, \
      81            1 :                             _max_bitpool)                                                          \
      82              :         static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = {                                \
      83              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
      84              :                 .codec_ie = {_freq | _ch_mode, _blk_len | _subband | _alloc_mthd, _min_bitpool,    \
      85              :                              _max_bitpool}};                                                       \
      86              :         static struct bt_a2dp_ep _name =                                                           \
      87              :                 BT_A2DP_SINK_EP_INIT(BT_A2DP_SBC, (&bt_a2dp_ep_cap_ie##_name))
      88              : 
      89              : /** @brief define the SBC source endpoint that can be used as bt_a2dp_register_endpoint's
      90              :  * parameter.
      91              :  *
      92              :  * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SOURCE_EP_DEFAULT
      93              :  * is more convenient for user to register SBC endpoint.
      94              :  *
      95              :  *  @param _name the endpoint variable name.
      96              :  *  @param _freq sbc codec frequency.
      97              :  *               for example: A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000
      98              :  *  @param _ch_mode sbc codec channel mode.
      99              :  *               for example: A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO
     100              :  *  @param _blk_len sbc codec block length.
     101              :  *               for example: A2DP_SBC_BLK_LEN_16
     102              :  *  @param _subband sbc codec subband.
     103              :  *               for example: A2DP_SBC_SUBBAND_8
     104              :  *  @param _alloc_mthd sbc codec allocate method.
     105              :  *               for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
     106              :  *  @param _min_bitpool sbc codec min bit pool. for example: 18
     107              :  *  @param _max_bitpool sbc codec max bit pool. for example: 35
     108              :  */
     109              : #define BT_A2DP_SBC_SOURCE_EP(_name, _freq, _ch_mode, _blk_len, _subband, _alloc_mthd,             \
     110            1 :                               _min_bitpool, _max_bitpool)                                          \
     111              :         static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = {                                \
     112              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
     113              :                 .codec_ie = {_freq | _ch_mode, _blk_len | _subband | _alloc_mthd, _min_bitpool,    \
     114              :                              _max_bitpool}};                                                       \
     115              :         static struct bt_a2dp_ep _name =                                                           \
     116              :                 BT_A2DP_SOURCE_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
     117              : 
     118              : /** @brief define the default SBC sink endpoint that can be used as
     119              :  * bt_a2dp_register_endpoint's parameter.
     120              :  *
     121              :  * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SINK_EP_DEFAULT
     122              :  * is more convenient for user to register SBC endpoint.
     123              :  *
     124              :  *  @param _name the endpoint variable name.
     125              :  */
     126            1 : #define BT_A2DP_SBC_SINK_EP_DEFAULT(_name)                                                         \
     127              :         static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = {                                \
     128              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
     129              :                 .codec_ie = {A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000 |                 \
     130              :                                      A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO |              \
     131              :                                      A2DP_SBC_CH_MODE_JOINT,                                       \
     132              :                              A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 |                            \
     133              :                                      A2DP_SBC_ALLOC_MTHD_LOUDNESS,                                 \
     134              :                              18U, 35U}};                                                           \
     135              :         static struct bt_a2dp_ep _name =                                                           \
     136              :                 BT_A2DP_SINK_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
     137              : 
     138              : /** @brief define the default SBC source endpoint that can be used as bt_a2dp_register_endpoint's
     139              :  * parameter.
     140              :  *
     141              :  * SBC is mandatory as a2dp specification, BT_A2DP_SBC_SOURCE_EP_DEFAULT
     142              :  * is more convenient for user to register SBC endpoint.
     143              :  *
     144              :  *  @param _name the endpoint variable name.
     145              :  */
     146            1 : #define BT_A2DP_SBC_SOURCE_EP_DEFAULT(_name)                                                       \
     147              :         static struct bt_a2dp_codec_ie bt_a2dp_ep_cap_ie##_name = {                                \
     148              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
     149              :                 .codec_ie = {A2DP_SBC_SAMP_FREQ_44100 | A2DP_SBC_SAMP_FREQ_48000 |                 \
     150              :                                      A2DP_SBC_CH_MODE_MONO | A2DP_SBC_CH_MODE_STREO |              \
     151              :                                      A2DP_SBC_CH_MODE_JOINT,                                       \
     152              :                              A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 |                            \
     153              :                                      A2DP_SBC_ALLOC_MTHD_LOUDNESS,                                 \
     154              :                              18U, 35U},                                                            \
     155              :         };                                                                                         \
     156              :         static struct bt_a2dp_ep _name =                                                           \
     157              :                 BT_A2DP_SOURCE_EP_INIT(BT_A2DP_SBC, &bt_a2dp_ep_cap_ie##_name)
     158              : 
     159              : /** @brief define the SBC default configuration.
     160              :  *
     161              :  *  @param _name unique structure name postfix.
     162              :  *  @param _freq_cfg sbc codec frequency.
     163              :  *               for example: A2DP_SBC_SAMP_FREQ_44100
     164              :  *  @param _ch_mode_cfg sbc codec channel mode.
     165              :  *               for example: A2DP_SBC_CH_MODE_JOINT
     166              :  *  @param _blk_len_cfg sbc codec block length.
     167              :  *               for example: A2DP_SBC_BLK_LEN_16
     168              :  *  @param _subband_cfg sbc codec subband.
     169              :  *               for example: A2DP_SBC_SUBBAND_8
     170              :  *  @param _alloc_mthd_cfg sbc codec allocate method.
     171              :  *               for example: A2DP_SBC_ALLOC_MTHD_LOUDNESS
     172              :  *  @param _min_bitpool_cfg sbc codec min bit pool. for example: 18
     173              :  *  @param _max_bitpool_cfg sbc codec max bit pool. for example: 35
     174              :  */
     175              : #define BT_A2DP_SBC_EP_CFG(_name, _freq_cfg, _ch_mode_cfg, _blk_len_cfg, _subband_cfg,             \
     176            1 :                            _alloc_mthd_cfg, _min_bitpool_cfg, _max_bitpool_cfg)                    \
     177              :         static struct bt_a2dp_codec_ie bt_a2dp_codec_ie##_name = {                                 \
     178              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
     179              :                 .codec_ie = {_freq_cfg | _ch_mode_cfg,                                             \
     180              :                              _blk_len_cfg | _subband_cfg | _alloc_mthd_cfg, _min_bitpool_cfg,      \
     181              :                              _max_bitpool_cfg},                                                    \
     182              :         };                                                                                         \
     183              :         struct bt_a2dp_codec_cfg _name = {                                                         \
     184              :                 .codec_config = &bt_a2dp_codec_ie##_name,                                          \
     185              :         }
     186              : 
     187              : /** @brief define the SBC default configuration.
     188              :  *
     189              :  *  @param _name unique structure name postfix.
     190              :  *  @param _freq_cfg the frequency to configure the remote same codec type endpoint.
     191              :  */
     192            1 : #define BT_A2DP_SBC_EP_CFG_DEFAULT(_name, _freq_cfg)                                               \
     193              :         static struct bt_a2dp_codec_ie bt_a2dp_codec_ie##_name = {                                 \
     194              :                 .len = BT_A2DP_SBC_IE_LENGTH,                                                      \
     195              :                 .codec_ie = {_freq_cfg | A2DP_SBC_CH_MODE_JOINT,                                   \
     196              :                              A2DP_SBC_BLK_LEN_16 | A2DP_SBC_SUBBAND_8 |                            \
     197              :                                      A2DP_SBC_ALLOC_MTHD_LOUDNESS,                                 \
     198              :                              18U, 35U},                                                            \
     199              :         };                                                                                         \
     200              :         struct bt_a2dp_codec_cfg _name = {                                                         \
     201              :                 .codec_config = &bt_a2dp_codec_ie##_name,                                          \
     202              :         }
     203              : 
     204              : /**
     205              :  * @brief A2DP error code
     206              :  */
     207            1 : enum bt_a2dp_err_code {
     208              :         /** Media Codec Type is not valid */
     209              :         BT_A2DP_INVALID_CODEC_TYPE = 0xC1,
     210              :         /** Media Codec Type is not supported */
     211              :         BT_A2DP_NOT_SUPPORTED_CODEC_TYPE = 0xC2,
     212              :         /** Sampling Frequency is not valid or multiple values have been selected */
     213              :         BT_A2DP_INVALID_SAMPLING_FREQUENCY = 0xC3,
     214              :         /** Sampling Frequency is not supported */
     215              :         BT_A2DP_NOT_SUPPORTED_SAMPLING_FREQUENCY = 0xC4,
     216              :         /** Channel Mode is not valid or multiple values have been selected */
     217              :         BT_A2DP_INVALID_CHANNEL_MODE = 0xC5,
     218              :         /** Channel Mode is not supported */
     219              :         BT_A2DP_NOT_SUPPORTED_CHANNEL_MODE = 0xC6,
     220              :         /** None or multiple values have been selected for Number of Subbands */
     221              :         BT_A2DP_INVALID_SUBBANDS = 0xC7,
     222              :         /** Number of Subbands is not supported */
     223              :         BT_A2DP_NOT_SUPPORTED_SUBBANDS = 0xC8,
     224              :         /** None or multiple values have been selected for Allocation Method */
     225              :         BT_A2DP_INVALID_ALLOCATION_METHOD = 0xC9,
     226              :         /** Allocation Method is not supported */
     227              :         BT_A2DP_NOT_SUPPORTED_ALLOCATION_METHOD = 0xCA,
     228              :         /** Minimum Bitpool Value is not valid */
     229              :         BT_A2DP_INVALID_MINIMUM_BITPOOL_VALUE = 0xCB,
     230              :         /** Minimum Bitpool Value is not supported */
     231              :         BT_A2DP_NOT_SUPPORTED_MINIMUM_BITPOOL_VALUE = 0xCC,
     232              :         /** Maximum Bitpool Value is not valid */
     233              :         BT_A2DP_INVALID_MAXIMUM_BITPOOL_VALUE = 0xCD,
     234              :         /** Maximum Bitpool Value is not supported */
     235              :         BT_A2DP_NOT_SUPPORTED_MAXIMUM_BITPOOL_VALUE = 0xCE,
     236              :         /** None or multiple values have been selected for Layer */
     237              :         BT_A2DP_INVALID_LAYER = 0xCF,
     238              :         /** Layer is not supported */
     239              :         BT_A2DP_NOT_SUPPORTED_LAYER = 0xD0,
     240              :         /** CRC is not supported */
     241              :         BT_A2DP_NOT_SUPPORTED_CRC = 0xD1,
     242              :         /** MPF-2 is not supported */
     243              :         BT_A2DP_NOT_SUPPORTED_MPF = 0xD2,
     244              :         /** VBR is not supported */
     245              :         BT_A2DP_NOT_SUPPORTED_VBR = 0xD3,
     246              :         /** None or multiple values have been selected for Bit Rate */
     247              :         BT_A2DP_INVALID_BIT_RATE = 0xD4,
     248              :         /** Bit Rate is not supported */
     249              :         BT_A2DP_NOT_SUPPORTED_BIT_RATE = 0xD5,
     250              :         /** Either 1) Object type is not valid or
     251              :          * 2) None or multiple values have been selected for Object Type
     252              :          */
     253              :         BT_A2DP_INVALID_OBJECT_TYPE = 0xD6,
     254              :         /** Object Type is not supported */
     255              :         BT_A2DP_NOT_SUPPORTED_OBJECT_TYPE = 0xD7,
     256              :         /** Either 1) Channels is not valid or
     257              :          * 2) None or multiple values have been selected for Channels
     258              :          */
     259              :         BT_A2DP_INVALID_CHANNELS = 0xD8,
     260              :         /** Channels is not supported */
     261              :         BT_A2DP_NOT_SUPPORTED_CHANNELS = 0xD9,
     262              :         /** Version is not valid */
     263              :         BT_A2DP_INVALID_VERSION = 0xDA,
     264              :         /** Version is not supported */
     265              :         BT_A2DP_NOT_SUPPORTED_VERSION = 0xDB,
     266              :         /** Maximum SUL is not acceptable for the Decoder in the SNK */
     267              :         BT_A2DP_NOT_SUPPORTED_MAXIMUM_SUL = 0xDC,
     268              :         /** None or multiple values have been selected for Block Length */
     269              :         BT_A2DP_INVALID_BLOCK_LENGTH = 0xDD,
     270              :         /** The requested CP Type is not supported */
     271              :         BT_A2DP_INVALID_CP_TYPE = 0xE0,
     272              :         /** The format of Content Protection Service Capability/Content
     273              :          * Protection Scheme Dependent Data is not correct
     274              :          */
     275              :         BT_A2DP_INVALID_CP_FORMAT = 0xE1,
     276              :         /** The codec parameter is invalid.
     277              :          * Used if a more specific error code does not exist for the codec in use
     278              :          */
     279              :         BT_A2DP_INVALID_CODEC_PARAMETER = 0xE2,
     280              :         /** The codec parameter is not supported.
     281              :          * Used if a more specific error code does not exist for the codec in use
     282              :          */
     283              :         BT_A2DP_NOT_SUPPORTED_CODEC_PARAMETER = 0xE3,
     284              :         /** Combination of Object Type and DRC is invalid */
     285              :         BT_A2DP_INVALID_DRC = 0xE4,
     286              :         /** DRC is not supported */
     287              :         BT_A2DP_NOT_SUPPORTED_DRC = 0xE5,
     288              : };
     289              : 
     290              : /** @brief Codec Type */
     291            1 : enum bt_a2dp_codec_type {
     292              :         /** Codec SBC */
     293              :         BT_A2DP_SBC = 0x00,
     294              :         /** Codec MPEG-1 */
     295              :         BT_A2DP_MPEG1 = 0x01,
     296              :         /** Codec MPEG-2 */
     297              :         BT_A2DP_MPEG2 = 0x02,
     298              :         /** Codec MPEG-D */
     299              :         BT_A2DP_MPEGD = 0x03,
     300              :         /** Codec ATRAC */
     301              :         BT_A2DP_ATRAC = 0x04,
     302              :         /** Codec Non-A2DP */
     303              :         BT_A2DP_VENDOR = 0xff
     304              : };
     305              : 
     306              : /** @brief A2DP structure */
     307              : struct bt_a2dp;
     308              : 
     309              : /* Internal to pass build */
     310              : struct bt_a2dp_stream;
     311              : 
     312              : /** @brief codec information elements for the endpoint */
     313            1 : struct bt_a2dp_codec_ie {
     314              :         /** Length of codec_cap */
     315            1 :         uint8_t len;
     316              :         /** codec information element */
     317            1 :         uint8_t codec_ie[BT_A2DP_MAX_IE_LENGTH];
     318              : };
     319              : 
     320              : /** @brief The endpoint configuration */
     321            1 : struct bt_a2dp_codec_cfg {
     322              :         /** The media codec configuration content */
     323            1 :         struct bt_a2dp_codec_ie *codec_config;
     324              : };
     325              : 
     326              : /** @brief Stream End Point */
     327            1 : struct bt_a2dp_ep {
     328              :         /** Code Type @ref bt_a2dp_codec_type */
     329            1 :         uint8_t codec_type;
     330              :         /** Capabilities */
     331            1 :         struct bt_a2dp_codec_ie *codec_cap;
     332              :         /** AVDTP Stream End Point Identifier */
     333            1 :         struct bt_avdtp_sep sep;
     334              :         /* Internally used stream object pointer */
     335            0 :         struct bt_a2dp_stream *stream;
     336              : };
     337              : 
     338            0 : struct bt_a2dp_ep_info {
     339              :         /** Code Type @ref bt_a2dp_codec_type */
     340            1 :         uint8_t codec_type;
     341              :         /** Codec capabilities, if SBC, use function of a2dp_codec_sbc.h to parse it */
     342            1 :         struct bt_a2dp_codec_ie codec_cap;
     343              :         /** Stream End Point Information */
     344            1 :         struct bt_avdtp_sep_info *sep_info;
     345              : };
     346              : 
     347              : /** @brief Helper enum to be used as return value of bt_a2dp_discover_ep_cb.
     348              :  *  The value informs the caller to perform further pending actions or stop them.
     349              :  */
     350            0 : enum {
     351              :         BT_A2DP_DISCOVER_EP_STOP = 0,
     352              :         BT_A2DP_DISCOVER_EP_CONTINUE,
     353              : };
     354              : 
     355              : /** @typedef bt_a2dp_discover_ep_cb
     356              :  *
     357              :  *  @brief Called when a stream endpoint is discovered.
     358              :  *
     359              :  *  A function of this type is given by the user to the bt_a2dp_discover_param
     360              :  *  object. It'll be called on each valid stream endpoint discovery completion.
     361              :  *  When no more endpoint then NULL is passed to the user. Otherwise user can get
     362              :  *  valid endpoint information from parameter info, user can set parameter ep to
     363              :  *  get the endpoint after the callback is return.
     364              :  *  The returned function value allows the user to control retrieving follow-up
     365              :  *  endpoints if any. If the user doesn't want to read more endpoints since
     366              :  *  current found endpoints fulfill its requirements then should return
     367              :  *  BT_A2DP_DISCOVER_EP_STOP. Otherwise returned value means
     368              :  *  more subcall iterations are allowable.
     369              :  *
     370              :  *  @param a2dp a2dp connection object identifying a2dp connection to queried remote.
     371              :  *  @param info Object pointing to the information of the callbacked endpoint.
     372              :  *  @param ep If the user want to use this found endpoint, user can set value to it
     373              :  *  to get the endpoint that can be used further in other A2DP APIs. It is NULL if info
     374              :  *  is NULL (no more endpoint is found).
     375              :  *
     376              :  *  @return BT_A2DP_DISCOVER_EP_STOP in case of no more need to continue discovery
     377              :  *  for next endpoint. By returning BT_A2DP_DISCOVER_EP_STOP user allows this
     378              :  *  discovery continuation.
     379              :  */
     380            1 : typedef uint8_t (*bt_a2dp_discover_ep_cb)(struct bt_a2dp *a2dp, struct bt_a2dp_ep_info *info,
     381              :                                           struct bt_a2dp_ep **ep);
     382              : 
     383            0 : struct bt_a2dp_discover_param {
     384              :         /** discover callback */
     385            1 :         bt_a2dp_discover_ep_cb cb;
     386              :         /** The discovered endpoint info that is callbacked by cb */
     387            1 :         struct bt_a2dp_ep_info info;
     388              :         /** The max count of remote endpoints that can be got,
     389              :          *  it save endpoint info internally.
     390              :          */
     391            1 :         struct bt_avdtp_sep_info *seps_info;
     392              :         /** The AVDTP version of the peer's A2DP sdp service.
     393              :          *  Stack uses it to determine using get_all_cap or get_cap cmd. When both
     394              :          *  versions are v1.3 or bigger version, get_all_cap is used, otherwise
     395              :          *  get_cap is used.
     396              :          *  It is the same value of the avdtp sepcificaiton's version value.
     397              :          *  For example: 0x0103 means version 1.3
     398              :          *  If the value is 0 (unknown), stack process it as less than v1.3
     399              :          */
     400            1 :         uint16_t avdtp_version;
     401              :         /** The max count of seps (stream endpoint) that can be got in this call route */
     402            1 :         uint8_t sep_count;
     403              : };
     404              : 
     405              : /** @brief The connecting callback */
     406            1 : struct bt_a2dp_cb {
     407              :         /** @brief A a2dp connection has been established.
     408              :          *
     409              :          *  This callback notifies the application of a a2dp connection.
     410              :          *  It means the AVDTP L2CAP connection.
     411              :          *  In case the err parameter is non-zero it means that the
     412              :          *  connection establishment failed.
     413              :          *
     414              :          *  @param a2dp a2dp connection object.
     415              :          *  @param err error code.
     416              :          */
     417            1 :         void (*connected)(struct bt_a2dp *a2dp, int err);
     418              :         /** @brief A a2dp connection has been disconnected.
     419              :          *
     420              :          *  This callback notifies the application that a a2dp connection
     421              :          *  has been disconnected.
     422              :          *
     423              :          *  @param a2dp a2dp connection object.
     424              :          */
     425            1 :         void (*disconnected)(struct bt_a2dp *a2dp);
     426              :         /**
     427              :          * @brief Endpoint config request callback
     428              :          *
     429              :          * The callback is called whenever an endpoint is requested to be
     430              :          * configured.
     431              :          *
     432              :          *  @param a2dp a2dp connection object.
     433              :          *  @param[in]  ep        Local Audio Endpoint being configured.
     434              :          *  @param[in]  codec_cfg Codec configuration.
     435              :          *  @param[out] stream    Pointer to stream that will be configured for the endpoint.
     436              :          *  @param[out] rsp_err_code  give the error code if response error.
     437              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     438              :          *
     439              :          * @return 0 in case of success or negative value in case of error.
     440              :          */
     441            1 :         int (*config_req)(struct bt_a2dp *a2dp, struct bt_a2dp_ep *ep,
     442              :                           struct bt_a2dp_codec_cfg *codec_cfg, struct bt_a2dp_stream **stream,
     443              :                           uint8_t *rsp_err_code);
     444              :         /**
     445              :          * @brief Endpoint config request callback
     446              :          *
     447              :          * The callback is called whenever an endpoint is requested to be
     448              :          * reconfigured.
     449              :          *
     450              :          *  @param[in] stream    Pointer to stream object.
     451              :          *  @param[out] rsp_err_code  give the error code if response error.
     452              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     453              :          *
     454              :          * @return 0 in case of success or negative value in case of error.
     455              :          */
     456            1 :         int (*reconfig_req)(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *codec_cfg,
     457              :                             uint8_t *rsp_err_code);
     458              :         /** @brief Callback function for bt_a2dp_stream_config() and bt_a2dp_stream_reconfig()
     459              :          *
     460              :          *  Called when the codec configure operation is completed.
     461              :          *
     462              :          *  @param[in] stream    Pointer to stream object.
     463              :          *  @param[in] rsp_err_code the remote responded error code
     464              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     465              :          */
     466            1 :         void (*config_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     467              :         /**
     468              :          * @brief Stream establishment request callback
     469              :          *
     470              :          * The callback is called whenever an stream is requested to be
     471              :          * established (open cmd and create the stream l2cap channel).
     472              :          *
     473              :          *  @param[in] stream    Pointer to stream object.
     474              :          *  @param[out] rsp_err_code  give the error code if response error.
     475              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     476              :          *
     477              :          * @return 0 in case of success or negative value in case of error.
     478              :          */
     479            1 :         int (*establish_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
     480              :         /** @brief Callback function for bt_a2dp_stream_establish()
     481              :          *
     482              :          *  Called when the establishment operation is completed.
     483              :          *  (open cmd and create the stream l2cap channel).
     484              :          *
     485              :          *  @param[in] stream    Pointer to stream object.
     486              :          *  @param[in] rsp_err_code the remote responded error code
     487              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     488              :          */
     489            1 :         void (*establish_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     490              :         /**
     491              :          * @brief Stream release request callback
     492              :          *
     493              :          * The callback is called whenever an stream is requested to be
     494              :          * released (release cmd and release the l2cap channel)
     495              :          *
     496              :          *  @param[in] stream    Pointer to stream object.
     497              :          *  @param[out] rsp_err_code  give the error code if response error.
     498              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     499              :          *
     500              :          * @return 0 in case of success or negative value in case of error.
     501              :          */
     502            1 :         int (*release_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
     503              :         /** @brief Callback function for bt_a2dp_stream_release()
     504              :          *
     505              :          *  Called when the release operation is completed.
     506              :          *  (release cmd and release the l2cap channel)
     507              :          *
     508              :          *  @param[in] stream    Pointer to stream object.
     509              :          *  @param[in] rsp_err_code the remote responded error code
     510              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     511              :          */
     512            1 :         void (*release_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     513              :         /**
     514              :          * @brief Stream start request callback
     515              :          *
     516              :          * The callback is called whenever an stream is requested to be
     517              :          * started.
     518              :          *
     519              :          *  @param[in] stream    Pointer to stream object.
     520              :          *  @param[out] rsp_err_code  give the error code if response error.
     521              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     522              :          *
     523              :          * @return 0 in case of success or negative value in case of error.
     524              :          */
     525            1 :         int (*start_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
     526              :         /** @brief Callback function for bt_a2dp_stream_start()
     527              :          *
     528              :          *  Called when the start operation is completed.
     529              :          *
     530              :          *  @param[in] stream    Pointer to stream object.
     531              :          *  @param[in] rsp_err_code the remote responded error code
     532              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     533              :          */
     534            1 :         void (*start_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     535              :         /**
     536              :          * @brief Stream suspend request callback
     537              :          *
     538              :          * The callback is called whenever an stream is requested to be
     539              :          * suspended.
     540              :          *
     541              :          *  @param[in] stream    Pointer to stream object.
     542              :          *  @param[out] rsp_err_code  give the error code if response error.
     543              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     544              :          *
     545              :          * @return 0 in case of success or negative value in case of error.
     546              :          */
     547            1 :         int (*suspend_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
     548              :         /** @brief Callback function for bt_a2dp_stream_suspend()
     549              :          *
     550              :          *  Called when the suspend operation is completed.
     551              :          *
     552              :          *  @param[in] stream    Pointer to stream object.
     553              :          *  @param[in] rsp_err_code the remote responded error code
     554              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     555              :          */
     556            1 :         void (*suspend_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     557              :         /**
     558              :          * @brief Stream abort request callback
     559              :          *
     560              :          * The callback is called whenever an stream is requested to be
     561              :          * aborted.
     562              :          *
     563              :          *  @param[in] stream    Pointer to stream object.
     564              :          *  @param[out] rsp_err_code  give the error code if response error.
     565              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     566              :          *
     567              :          * @return 0 in case of success or negative value in case of error.
     568              :          */
     569            1 :         int (*abort_req)(struct bt_a2dp_stream *stream, uint8_t *rsp_err_code);
     570              :         /** @brief Callback function for bt_a2dp_stream_abort()
     571              :          *
     572              :          *  Called when the abort operation is completed.
     573              :          *
     574              :          *  @param[in] stream    Pointer to stream object.
     575              :          *  @param[in] rsp_err_code the remote responded error code
     576              :          *                          bt_a2dp_err_code or bt_avdtp_err_code
     577              :          */
     578            1 :         void (*abort_rsp)(struct bt_a2dp_stream *stream, uint8_t rsp_err_code);
     579              : };
     580              : 
     581              : /** @brief A2DP Connect.
     582              :  *
     583              :  *  This function is to be called after the conn parameter is obtained by
     584              :  *  performing a GAP procedure. The API is to be used to establish A2DP
     585              :  *  connection between devices.
     586              :  *  This function only establish AVDTP L2CAP Signaling connection.
     587              :  *  After connection success, the callback that is registered by
     588              :  *  bt_a2dp_register_connect_callback is called.
     589              :  *
     590              :  *  @param conn Pointer to bt_conn structure.
     591              :  *
     592              :  *  @return pointer to struct bt_a2dp in case of success or NULL in case
     593              :  *  of error.
     594              :  */
     595            1 : struct bt_a2dp *bt_a2dp_connect(struct bt_conn *conn);
     596              : 
     597              : /** @brief disconnect l2cap a2dp
     598              :  *
     599              :  * This function close AVDTP L2CAP Signaling connection.
     600              :  * It closes the AVDTP L2CAP Media connection too if it is established.
     601              :  *
     602              :  *  @param a2dp The a2dp instance.
     603              :  *
     604              :  *  @return 0 in case of success and error code in case of error.
     605              :  */
     606            1 : int bt_a2dp_disconnect(struct bt_a2dp *a2dp);
     607              : 
     608              : /** @brief Endpoint Registration.
     609              :  *
     610              :  *  @param ep Pointer to bt_a2dp_ep structure.
     611              :  *  @param media_type Media type that the Endpoint is, #bt_avdtp_media_type.
     612              :  *  @param sep_type Stream endpoint type, #bt_avdtp_sep_type.
     613              :  *
     614              :  *  @return 0 in case of success and error code in case of error.
     615              :  */
     616            1 : int bt_a2dp_register_ep(struct bt_a2dp_ep *ep, uint8_t media_type, uint8_t sep_type);
     617              : 
     618              : /** @brief register callback.
     619              :  *
     620              :  *  The cb is called when bt_a2dp_connect is called or it is operated by remote device.
     621              :  *
     622              :  *  @param cb The callback function.
     623              :  *
     624              :  *  @return 0 in case of success and error code in case of error.
     625              :  */
     626            1 : int bt_a2dp_register_cb(struct bt_a2dp_cb *cb);
     627              : 
     628              : /** @brief Obtain the ACL connection corresponding to A2DP.
     629              :  *
     630              :  *  @param a2dp The A2DP instance.
     631              :  *
     632              :  *  @return Connection object associated with the A2DP context. The caller gets a new
     633              :  *  reference to the connection object which must be released with bt_conn_unref()
     634              :  *  once done using the object.
     635              :  */
     636            1 : struct bt_conn *bt_a2dp_get_conn(struct bt_a2dp *a2dp);
     637              : 
     638              : /** @brief Discover remote endpoints.
     639              :  *
     640              :  *  @param a2dp The a2dp instance.
     641              :  *  @param param the discover used param.
     642              :  *
     643              :  *  @return 0 in case of success and error code in case of error.
     644              :  */
     645            1 : int bt_a2dp_discover(struct bt_a2dp *a2dp, struct bt_a2dp_discover_param *param);
     646              : 
     647              : /** @brief A2DP Stream */
     648            1 : struct bt_a2dp_stream {
     649              :         /** local endpoint */
     650            1 :         struct bt_a2dp_ep *local_ep;
     651              :         /** remote endpoint */
     652            1 :         struct bt_a2dp_ep *remote_ep;
     653              :         /** remote endpoint's Stream End Point ID */
     654            1 :         uint8_t remote_ep_id;
     655              :         /** Audio stream operations */
     656            1 :         struct bt_a2dp_stream_ops *ops;
     657              :         /** the a2dp connection */
     658            1 :         struct bt_a2dp *a2dp;
     659              :         /** the stream current configuration */
     660            1 :         struct bt_a2dp_codec_ie codec_config;
     661              : };
     662              : 
     663              : /** @brief The stream endpoint related operations */
     664            1 : struct bt_a2dp_stream_ops {
     665              :         /**
     666              :          * @brief Stream configured callback
     667              :          *
     668              :          * The callback is called whenever an Audio Stream has been configured or reconfigured.
     669              :          *
     670              :          * @param stream Stream object that has been configured.
     671              :          */
     672            1 :         void (*configured)(struct bt_a2dp_stream *stream);
     673              :         /**
     674              :          * @brief Stream establishment callback
     675              :          *
     676              :          * The callback is called whenever an Audio Stream has been established.
     677              :          *
     678              :          * @param stream Stream object that has been established.
     679              :          */
     680            1 :         void (*established)(struct bt_a2dp_stream *stream);
     681              :         /**
     682              :          * @brief Stream release callback
     683              :          *
     684              :          * The callback is called whenever an Audio Stream has been released.
     685              :          * After released, the stream becomes invalid.
     686              :          *
     687              :          * @param stream Stream object that has been released.
     688              :          */
     689            1 :         void (*released)(struct bt_a2dp_stream *stream);
     690              :         /**
     691              :          * @brief Stream start callback
     692              :          *
     693              :          * The callback is called whenever an Audio Stream has been started.
     694              :          *
     695              :          * @param stream Stream object that has been started.
     696              :          */
     697            1 :         void (*started)(struct bt_a2dp_stream *stream);
     698              :         /**
     699              :          * @brief Stream suspend callback
     700              :          *
     701              :          * The callback is called whenever an Audio Stream has been suspended.
     702              :          *
     703              :          * @param stream Stream object that has been suspended.
     704              :          */
     705            1 :         void (*suspended)(struct bt_a2dp_stream *stream);
     706              :         /**
     707              :          * @brief Stream abort callback
     708              :          *
     709              :          * The callback is called whenever an Audio Stream has been aborted.
     710              :          * After aborted, the stream becomes invalid.
     711              :          *
     712              :          * @param stream Stream object that has been aborted.
     713              :          */
     714            1 :         void (*aborted)(struct bt_a2dp_stream *stream);
     715              : #if defined(CONFIG_BT_A2DP_SINK)
     716              :         /** @brief the media streaming data, only for sink
     717              :          *
     718              :          *  @param buf the data buf
     719              :          *  @param seq_num the sequence number
     720              :          *  @param ts the time stamp
     721              :          */
     722              :         void (*recv)(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
     723              :                      uint32_t ts);
     724              : #endif
     725              : #if defined(CONFIG_BT_A2DP_SOURCE)
     726              :         /**
     727              :          * @brief Stream audio HCI sent callback
     728              :          *
     729              :          * This callback will be called once the controller marks the SDU
     730              :          * as completed. When the controller does so is implementation
     731              :          * dependent. It could be after the SDU is enqueued for transmission,
     732              :          * or after it is sent on air or flushed.
     733              :          *
     734              :          * This callback is only used if the ISO data path is HCI.
     735              :          *
     736              :          * @param stream Stream object.
     737              :          */
     738              :         void (*sent)(struct bt_a2dp_stream *stream);
     739              : #endif
     740              : };
     741              : 
     742              : /**
     743              :  * @brief Register Audio callbacks for a stream.
     744              :  *
     745              :  * Register Audio callbacks for a stream.
     746              :  *
     747              :  * @param stream Stream object.
     748              :  * @param ops    Stream operations structure.
     749              :  */
     750            1 : void bt_a2dp_stream_cb_register(struct bt_a2dp_stream *stream, struct bt_a2dp_stream_ops *ops);
     751              : 
     752              : /** @brief configure endpoint.
     753              :  *
     754              :  *  bt_a2dp_discover can be used to find remote's endpoints.
     755              :  *  This function to configure the selected endpoint that is found by
     756              :  *  bt_a2dp_discover.
     757              :  *  This function sends AVDTP_SET_CONFIGURATION.
     758              :  *
     759              :  *  @param a2dp The a2dp instance.
     760              :  *  @param stream Stream object.
     761              :  *  @param local_ep The configured endpoint that is registered.
     762              :  *  @param remote_ep The remote endpoint.
     763              :  *  @param config The config to configure the endpoint.
     764              :  *
     765              :  *  @return 0 in case of success and error code in case of error.
     766              :  */
     767            1 : int bt_a2dp_stream_config(struct bt_a2dp *a2dp, struct bt_a2dp_stream *stream,
     768              :                           struct bt_a2dp_ep *local_ep, struct bt_a2dp_ep *remote_ep,
     769              :                           struct bt_a2dp_codec_cfg *config);
     770              : 
     771              : /** @brief establish a2dp streamer.
     772              :  *
     773              :  * This function sends the AVDTP_OPEN command and create the l2cap channel.
     774              :  *
     775              :  *  @param stream The stream object.
     776              :  *
     777              :  *  @return 0 in case of success and error code in case of error.
     778              :  */
     779            1 : int bt_a2dp_stream_establish(struct bt_a2dp_stream *stream);
     780              : 
     781              : /** @brief release a2dp streamer.
     782              :  *
     783              :  * This function sends the AVDTP_CLOSE command and release the l2cap channel.
     784              :  * After release, the stream becomes invalid.
     785              :  *
     786              :  *  @param stream The stream object.
     787              :  *
     788              :  *  @return 0 in case of success and error code in case of error.
     789              :  */
     790            1 : int bt_a2dp_stream_release(struct bt_a2dp_stream *stream);
     791              : 
     792              : /** @brief start a2dp streamer.
     793              :  *
     794              :  * This function sends the AVDTP_START command.
     795              :  *
     796              :  *  @param stream The stream object.
     797              :  *
     798              :  *  @return 0 in case of success and error code in case of error.
     799              :  */
     800            1 : int bt_a2dp_stream_start(struct bt_a2dp_stream *stream);
     801              : 
     802              : /** @brief suspend a2dp streamer.
     803              :  *
     804              :  * This function sends the AVDTP_SUSPEND command.
     805              :  *
     806              :  *  @param stream The stream object.
     807              :  *
     808              :  *  @return 0 in case of success and error code in case of error.
     809              :  */
     810            1 : int bt_a2dp_stream_suspend(struct bt_a2dp_stream *stream);
     811              : 
     812              : /** @brief re-configure a2dp streamer
     813              :  *
     814              :  * This function sends the AVDTP_RECONFIGURE command.
     815              :  *
     816              :  *  @param stream The stream object.
     817              :  *  @param config The config to configure the stream.
     818              :  *
     819              :  *  @return 0 in case of success and error code in case of error.
     820              :  */
     821            1 : int bt_a2dp_stream_reconfig(struct bt_a2dp_stream *stream, struct bt_a2dp_codec_cfg *config);
     822              : 
     823              : /** @brief abort a2dp streamer.
     824              :  *
     825              :  * This function sends the AVDTP_ABORT command.
     826              :  * After abort, the stream becomes invalid.
     827              :  *
     828              :  *  @param stream The stream object.
     829              :  *
     830              :  *  @return 0 in case of success and error code in case of error.
     831              :  */
     832            1 : int bt_a2dp_stream_abort(struct bt_a2dp_stream *stream);
     833              : 
     834              : /** @brief get the stream l2cap mtu
     835              :  *
     836              :  *  @param stream The stream object.
     837              :  *
     838              :  *  @return mtu value
     839              :  */
     840            1 : uint32_t bt_a2dp_get_mtu(struct bt_a2dp_stream *stream);
     841              : 
     842              : /** @brief send a2dp media data
     843              :  *
     844              :  * Only A2DP source side can call this function.
     845              :  *
     846              :  *  @param stream The stream object.
     847              :  *  @param buf  The data.
     848              :  *  @param seq_num The sequence number.
     849              :  *  @param ts The time stamp.
     850              :  *
     851              :  *  @return 0 in case of success and error code in case of error.
     852              :  */
     853            1 : int bt_a2dp_stream_send(struct bt_a2dp_stream *stream, struct net_buf *buf, uint16_t seq_num,
     854              :                         uint32_t ts);
     855              : 
     856              : /**
     857              :  * @brief Allocate a net_buf for bt_a2dp_stream_send
     858              :  *
     859              :  * This function allocates a buffer from the specified pool, reserves
     860              :  * sufficient headroom for protocol headers required by L2CAP over Bluetooth, fills
     861              :  * the AVDTP header.
     862              :  *
     863              :  * @param pool    The buffer pool to allocate from.
     864              :  * @param timeout Non-negative waiting period to obtain a buffer or one of
     865              :  *                the special values K_NO_WAIT and K_FOREVER.
     866              :  *
     867              :  * @return A newly allocated net_buf.
     868              :  */
     869            1 : struct net_buf *bt_a2dp_stream_create_pdu(struct net_buf_pool *pool, k_timeout_t timeout);
     870              : 
     871              : #ifdef __cplusplus
     872              : }
     873              : #endif
     874              : 
     875              : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ */
        

Generated by: LCOV version 2.0-1