1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. * Description: BT A2DP-SRC module. 14 */ 15 16 /** 17 * @addtogroup bluetooth_bts_a2dp_source A2DP SRC API 18 * @ingroup bluetooth 19 * @{ 20 */ 21 22 #ifndef BTS_A2DP_SOURCE_H 23 #define BTS_A2DP_SOURCE_H 24 25 #include "bts_def.h" 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /** 31 * @if Eng 32 * @brief Setting of A2dp codec priority. 33 * @else 34 * @brief A2dp 编码格式优先级设置。 35 * @endif 36 */ 37 #define A2DP_CODEC_PRIORITY_DISABLED (-1) 38 #define A2DP_CODEC_PRIORITY_DEFAULT 0 39 #define A2DP_CODEC_PRIORITY_HIGHEST (1000 * 1000) 40 41 /** 42 * @if Eng 43 * @brief Sample rate of a2dp. 44 * @else 45 * @brief A2dp 采样率。 46 * @endif 47 */ 48 #define A2DP_CODEC_SAMPLE_RATE_NONE 0x00 49 #define A2DP_CODEC_SAMPLE_RATE_44100 (0x01 << 0) 50 #define A2DP_CODEC_SAMPLE_RATE_48000 (0x01 << 1) 51 #define A2DP_CODEC_SAMPLE_RATE_88200 (0x01 << 2) 52 #define A2DP_CODEC_SAMPLE_RATE_96000 (0x01 << 3) 53 #define A2DP_CODEC_SAMPLE_RATE_176400 (0x01 << 4) 54 #define A2DP_CODEC_SAMPLE_RATE_192000 (0x01 << 5) 55 56 /** 57 * @if Eng 58 * @brief Sample bit of a2dp sample rate. 59 * @else 60 * @brief A2dp 的采样比特位。 61 * @endif 62 */ 63 #define A2DP_CODEC_BITS_PER_SAMPLE_NONE 0x00 64 #define A2DP_CODEC_BITS_PER_SAMPLE_16 (0x01 << 0) 65 #define A2DP_CODEC_BITS_PER_SAMPLE_24 (0x01 << 1) 66 #define A2DP_CODEC_BITS_PER_SAMPLE_32 (0x01 << 2) 67 68 /** 69 * @if Eng 70 * @brief Channel mode of a2dp NONE. 71 * @else 72 * @brief A2dp声道模式NONE。 73 * @endif 74 */ 75 #define A2DP_CODEC_CHANNEL_MODE_NONE 0x00 76 77 /** 78 * @if Eng 79 * @brief Channel mode of a2dp MONO. 80 * @else 81 * @brief A2dp声道模式MONO。 82 * @endif 83 */ 84 #define A2DP_CODEC_CHANNEL_MODE_MONO (0x01 << 0) 85 /** 86 * @if Eng 87 * @brief Channel mode of a2dp STEREO. 88 * @else 89 * @brief A2dp声道模式STEREO。 90 * @endif 91 */ 92 #define A2DP_CODEC_CHANNEL_MODE_STEREO (0x01 << 1) 93 94 /** 95 * @if Eng 96 * @brief Enum of a2dp codec type. 97 * @else 98 * @brief A2dp编码格式类型。 99 * @endif 100 */ 101 typedef enum { 102 A2DP_CODEC_TYPE_SBC = 0x00, /*!< @if Eng SBC codec type. 103 @else 编码格式类型为SBC。 @endif */ 104 A2DP_CODEC_TYPE_AAC, /*!< @if Eng AAC codec type. 105 @else 编码格式类型为AAC。 @endif */ 106 A2DP_CODEC_TYPE_APTX, /*!< @if Eng APTX codec type. 107 @else 编码格式类型为APTX。 @endif */ 108 A2DP_CODEC_TYPE_APTX_HD, /*!< @if Eng APTX_HD codec type. 109 @else 编码格式类型为APTX_HD。 @endif */ 110 A2DP_CODEC_TYPE_LDAC, /*!< @if Eng LDAC codec type. 111 @else 编码格式类型为LDAC。 @endif */ 112 A2DP_CODEC_TYPE_LHDC, /*!< @if Eng LHDC codec type. 113 @else 编码格式类型为LHDC。 @endif */ 114 A2DP_CODEC_TYPE_LC3, /*!< @if Eng LC3 codec type. 115 @else 编码格式类型为LC3。 @endif */ 116 A2DP_CODEC_TYPE_L2HC, /*!< @if Eng L2HC codec type. 117 @else 编码格式类型为L2HC。 @endif */ 118 A2DP_CODEC_TYPE_INVALID = 0xF4240, /*!< @if Eng Invalid codec type. 119 @else 无效编码格式类型。 @endif */ 120 } a2dp_codec_type_t; 121 122 /** 123 * @if Eng 124 * @brief Enum of a2dp optional codec support state define. 125 * @else 126 * @brief A2dp配置编码格式支持状态。 127 * @endif 128 */ 129 typedef enum { 130 A2DP_OPTIONAL_CODEC_NOT_SUPPORT = 0x00, /*!< @if Eng Not support optional codec. 131 @else 不支持设置编码格式类型。 @endif */ 132 A2DP_OPTIONAL_CODEC_SUPPORT, /*!< @if Eng Support optional codec. 133 @else 支持设置编码格式类型。 @endif */ 134 A2DP_OPTIONAL_CODEC_SUPPORT_UNKNOWN, /*!< @if Eng Support user define codec. 135 @else 支持用户定义编码格式类型。 @endif */ 136 } a2dp_optional_codec_support_state_t; 137 138 /** 139 * @if Eng 140 * @brief Enum of a2dp src codec configuration information. 141 * @else 142 * @brief A2dp src配置编码格式参数。 143 * @endif 144 */ 145 typedef struct { 146 int codec_priority; /*!< @if Eng Codec priority. 147 @else 编码格式优先级。 @endif */ 148 unsigned int codec_type; /*!< @if Eng Codec type. 149 @else 编码格式类型。 @endif */ 150 unsigned char sample_rate; /*!< @if Eng Codec sample rate. 151 @else 编码器采样率。 @endif */ 152 unsigned char bits_per_sample; /*!< @if Eng Codec bits per sampl. 153 @else 采样比特位。 @endif */ 154 unsigned char channel_mode; /*!< @if Eng Codec channel mode. 155 @else 声道模式。 @endif */ 156 unsigned long codec_specific1; /*!< @if Eng Codec specific value 1. 157 @else 自定义参数1。 @endif */ 158 unsigned long codec_specific2; /*!< @if Eng Codec specific value 2. 159 @else 自定义参数2。 @endif */ 160 unsigned long codec_specific3; /*!< @if Eng Codec specific value 3. 161 @else 自定义参数3。 @endif */ 162 unsigned long codec_specific4; /*!< @if Eng Codec specific value 4. 163 @else 自定义参数4。 @endif */ 164 } a2dp_codec_info_t; 165 166 167 /** 168 * @if Eng 169 * @brief Callback invoked in response to a2dp src connection state changed. 170 * @par Description: 171 * When registered, the bts uses this callback to deliver a2dp connect stat info updated 172 * after connection state updated. 173 * @attention 1. This function is called in bts context, should not be blocked or do long time waiting. 174 * @attention 2. The memories of <devices> are requested and freed by the bts automatically. 175 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 176 * @param [in] conn_state A2dp src connection state. See @ref int 177 * @retval No return value. See @ref void 178 * @else 179 * @brief a2dp src连接状态改变回调函数。 180 * @par 说明: 181 * 注册该回调函数之后,BTS每次完成a2dp状态更新后调用该接口反馈结果给上层。 182 * @attention 1. 该回调函数运行于bts线程,不能阻塞或长时间等待。 183 * @attention 2. <devices>由bts申请内存,也由bts释放,回调中不应释放。 184 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 185 * @param [in] conn_state A2dp src的连接状态。参考 @ref int 186 * @retval 无返回值。 参考 @ref void 187 * @endif 188 * @par Dependency: 189 * @li bts_a2dp_source.h 190 * @see a2dp_src_callbacks_t 191 */ 192 typedef void (*a2dp_src_connect_state_changed_callback)(bd_addr_t *bd_addr, int conn_state); 193 194 /** 195 * @if Eng 196 * @brief Callback invoked in response to a2dp playing state changed. 197 * @par Description: 198 * When registered, the bts uses this callback to deliver a2dp playing stat after playing state updated. 199 * @attention 1. This function is called in bts context, should not be blocked or do long time waiting. 200 * @attention 2. The memories of <devices> are requested and freed by the bts automatically. 201 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 202 * @param [in] playing_state A2dp src playingState state. See @ref int 203 * @retval No return value. See @ref void 204 * @else 205 * @brief A2dp src播放状态改变回调函数。 206 * @par 说明: 207 * 注册该回调函数之后,BTS每次完成a2dp状态更新后调用该接口反馈结果给上层。 208 * @attention 1. 该回调函数运行于bts线程,不能阻塞或长时间等待。 209 * @attention 2. <devices>由bts申请内存,也由bts释放,回调中不应释放。 210 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 211 * @param [in] playing_state A2dp src的播放状态。参考 @ref int 212 * @retval 无返回值。参考 @ref void 213 * @endif 214 * @par Dependency: 215 * @li bts_a2dp_source.h 216 * @see a2dp_src_callbacks_t 217 */ 218 typedef void (*a2dp_src_playing_state_changed_callback)(bd_addr_t *bd_addr, int playing_state); 219 220 /** 221 * @if Eng 222 * @brief Callback invoked in response to a2dp codec information changed. 223 * @par Description: 224 * When registered, the bts uses this callback to deliver a2dp codec information 225 * after codec information changed. 226 * @attention 1. This function is called in bts context, should not be blocked or do long time waiting. 227 * @attention 2. The memories of <devices> are requested and freed by the bts automatically. 228 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 229 * @param [in] info A poniter of device's codec information. See @ref a2dp_codec_info_t 230 * @retval No return value. See @ref void 231 * @else 232 * @brief A2dp 编码格式改变回调函数。 233 * @par 说明: 234 * 注册该回调函数之后,BTS每次完成a2dp状态更新后调用该接口反馈结果给上层。 235 * @attention 1. 该回调函数运行于bts线程,不能阻塞或长时间等待。 236 * @attention 2. <devices>由bts申请内存,也由bts释放,回调中不应释放。 237 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 238 * @param [in] info A2dp 的编码格式信息。参考 @ref a2dp_codec_info_t 239 * @retval 无返回值。参考 @ref void 240 * @endif 241 * @par Dependency: 242 * @li bts_a2dp_source.h 243 * @see a2dp_src_callbacks_t 244 */ 245 typedef void (*a2dp_src_configuration_changed_callback)(bd_addr_t *bd_addr, a2dp_codec_info_t *info); 246 247 /** 248 * @if Eng 249 * @brief Struct of a2dp src callback function. 250 * @else 251 * @brief A2dp src回调接口定义。 252 * @endif 253 */ 254 typedef struct { 255 a2dp_src_connect_state_changed_callback connectstate_changed_cb; 256 a2dp_src_playing_state_changed_callback playing_state_changed_cb; 257 a2dp_src_configuration_changed_callback configuration_changed_cb; 258 } a2dp_src_callbacks_t; 259 260 /** 261 * @if Eng 262 * @brief Use this funtion to get device connection state by address. 263 * @par Description: 264 * Use this funtion to get device connection state by address. 265 266 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 267 * @retval Return connecting/connected/disconnecting/disconnected. See @ref profile_connect_state_t 268 * @else 269 * @brief 通过设备地址查询设备连接状态。 270 * @par 说明: 271 * 通过设备地址查询设备连接状态。 272 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 273 * @retval 返回值为正在连接,已连接,正在断开连接,已断开连接。参考 @ref profile_connect_state_t 274 * @endif 275 * @par Dependency: 276 * @li bts_a2dp_source.h 277 */ 278 int a2dp_src_get_device_connect_state(const bd_addr_t *bd_addr); 279 280 /** 281 * @if Eng 282 * @brief Use this funtion to get device playing state by address when target device is on connected state. 283 * @par Description: 284 * Use this funtion to get device playing state by address when target device is on connected state. 285 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 286 * @retval Return not playing/is playing. See @ref a2dp_playing_state_t 287 * @else 288 * @brief 当对端设备已经连接时,通过设备地址查询对端蓝牙设备播放状态。 289 * @par 说明: 290 * 当对端设备已经连接时,通过设备地址查询对端蓝牙设备播放状态。 291 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 292 * @retval 返回值为未播放/正在播放。参考 @ref a2dp_playing_state_t 293 * @endif 294 * @par Dependency: 295 * @li bts_a2dp_source.h 296 */ 297 int a2dp_src_get_playing_state(const bd_addr_t *bd_addr); 298 299 /** 300 * @if Eng 301 * @brief Use this funtion to connect to the peer bluetooth device by address. 302 * @par Description: 303 * Use this funtion to connect to the peer bluetooth device by address. 304 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 305 * @retval #ERRCODE_BT_SUCCESS Success. 306 * @retval Other Failure. For details, see @ref errcode_bt_t 307 * @else 308 * @brief 与对端设备建立a2dp连接。 309 * @par 说明: 310 * 与对端设备建立a2dp连接。 311 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 312 * @retval #ERRCODE_BT_SUCCESS 成功。 313 * @retval Other 失败,参考 @ref errcode_bt_t 314 * @endif 315 * @par Dependency: 316 * @li bts_a2dp_source.h 317 */ 318 int a2dp_src_connect(const bd_addr_t *bd_addr); 319 320 /** 321 * @if Eng 322 * @brief Use this funtion to disconnect to the peer bluetooth device by address. 323 * @par Description: 324 * Use this funtion to disconnect to the peer bluetooth device by address. 325 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 326 * @retval #ERRCODE_BT_SUCCESS Success. 327 * @retval Other Failure. For details, see @ref errcode_bt_t 328 * @else 329 * @brief 与对端设备断开a2dp连接。 330 * @par 说明: 331 * 与对端设备断开a2dp连接。 332 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 333 * @retval #ERRCODE_BT_SUCCESS 成功。 334 * @retval Other 失败,参考 @ref errcode_bt_t 335 * @endif 336 * @par Dependency: 337 * @li bts_a2dp_source.h 338 */ 339 int a2dp_src_disconnect(const bd_addr_t *bd_addr); 340 341 /** 342 * @if Eng 343 * @brief Use this funtion to get active device address. 344 * @par Description: 345 * Use this funtion to get active device address. 346 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 347 * @retval NOT NULL Success. 348 * @retval NULL Failure. For details, see @ref errcode_bt_t 349 * @else 350 * @brief 查询对端活跃蓝牙设备的地址。 351 * @par 说明: 352 * 查询对端活跃蓝牙设备的地址。 353 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 354 * @retval NOT NULL 成功。 355 * @retval NULL 失败,参考 @ref errcode_bt_t 356 * @endif 357 * @par Dependency: 358 * @li bts_a2dp_source.h 359 */ 360 bd_addr_t a2dp_src_get_active_device(void); 361 362 /** 363 * @if Eng 364 * @brief Use this funtion to set the status of Audio start streaming. 365 * @par Description: 366 * Use this funtion to set the status of Audio start streaming. 367 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 368 * @retval #ERRCODE_BT_SUCCESS Success. 369 * @retval Other Failure. For details, see @ref errcode_bt_t 370 * @else 371 * @brief 设置蓝牙音乐的播放为start状态。 372 * @par 说明: 373 * 设置蓝牙音乐的播放为start状态。 374 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 375 * @retval #ERRCODE_BT_SUCCESS 成功。 376 * @retval Other 失败,参考 @ref errcode_bt_t 377 * @endif 378 * @par Dependency: 379 * @li bts_a2dp_source.h 380 */ 381 int a2dp_src_start_playing(const bd_addr_t *bd_addr); 382 383 /** 384 * @if Eng 385 * @brief Use this funtion to set the status of Audio suspend streaming. 386 * @par Description: 387 * Use this funtion to set the status of Audio suspend streaming. 388 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 389 * @retval #ERRCODE_BT_SUCCESS Success. 390 * @retval Other Failure. For details, see @ref errcode_bt_t 391 * @else 392 * @brief 设置蓝牙音乐的播放为suspend状态。 393 * @par 说明: 394 * 设置蓝牙音乐的播放为suspend状态。 395 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 396 * @retval #ERRCODE_BT_SUCCESS 成功。 397 * @retval Other 失败,参考 @ref errcode_bt_t 398 * @endif 399 * @par Dependency: 400 * @li bts_a2dp_source.h 401 */ 402 int a2dp_src_suspend_playing(const bd_addr_t *bd_addr); 403 404 /** 405 * @if Eng 406 * @brief Use this funtion to set the status of Audio stop streaming. 407 * @par Description: 408 * Use this funtion to set the status of Audio stop streaming. 409 * @param [in] bd_addr A poniter of the peer bluetooth device addresss. See @ref bd_addr_t 410 * @retval #ERRCODE_BT_SUCCESS Success. 411 * @retval Other Failure. For details, see @ref errcode_bt_t 412 * @else 413 * @brief 设置蓝牙音乐的播放为stop状态。 414 * @par 说明: 415 * 设置蓝牙音乐的播放为stop状态。 416 * @param [in] bd_addr 对端蓝牙设备的地址信息。参考 @ref bd_addr_t 417 * @retval #ERRCODE_BT_SUCCESS 成功。 418 * @retval Other 失败,参考 @ref errcode_bt_t 419 * @endif 420 * @par Dependency: 421 * @li bts_a2dp_source.h 422 */ 423 int a2dp_src_stop_playing(const bd_addr_t *bd_addr); 424 425 /** 426 * @if Eng 427 * @brief Use this funtion to register callback function of framework. 428 * @par Description: 429 * Use this funtion to register callback function of framework. 430 * @param [in] func A poniter of the callback function. See @ref a2dp_src_callbacks_t 431 * @retval #ERRCODE_BT_SUCCESS Success. 432 * @retval Other Failure. For details, see @ref errcode_bt_t 433 * @else 434 * @brief 注册上层应用的回调。 435 * @par 说明: 436 * 注册上层应用的回调。 437 * @param [in] func 回调函数指针。参考 @ref a2dp_src_callbacks_t 438 * @retval #ERRCODE_BT_SUCCESS 成功。 439 * @retval Other 失败,参考 @ref errcode_bt_t 440 * @endif 441 * @par Dependency: 442 * @li bts_a2dp_source.h 443 */ 444 int a2dp_src_register_callbacks(a2dp_src_callbacks_t *func); 445 446 /** 447 * @if Eng 448 * @brief Use this funtion to deregister callback function of framework. 449 * @par Description: 450 * Use this funtion to deregister callback function of framework. 451 * @param [in] func A poniter of the callback function. See @ref a2dp_src_callbacks_t 452 * @retval #ERRCODE_BT_SUCCESS Success. 453 * @retval Other Failure. For details, see @ref errcode_bt_t 454 * @else 455 * @brief 去注册上层应用的回调。 456 * @par 说明: 457 * 去注册上层应用的回调。 458 * @param [in] func 回调函数指针。参考 @ref a2dp_src_callbacks_t 459 * @retval #ERRCODE_BT_SUCCESS 成功。 460 * @retval Other 失败,参考 @ref errcode_bt_t 461 * @endif 462 * @par Dependency: 463 * @li bts_a2dp_source.h 464 */ 465 int a2dp_src_deregister_callbacks(a2dp_src_callbacks_t *func); 466 467 /** 468 * @} 469 */ 470 471 #ifdef __cplusplus 472 } 473 #endif 474 #endif /* BTS_A2DP_SOURCE_H */ 475