1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 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. 14 */ 15 16 /** 17 * @file interface_profile_a2dp_src.h 18 * 19 * @brief A2dp codec configuration information of a2dp source 20 * 21 * @since 6 22 */ 23 24 #ifndef INTERFACE_PROFILE_A2DP_SRC_H 25 #define INTERFACE_PROFILE_A2DP_SRC_H 26 27 #include "interface_profile.h" 28 29 namespace OHOS { 30 namespace bluetooth { 31 struct A2dpSrcCodecInfo { 32 // Codec priority 33 uint32_t codecPriority; 34 35 // Codec type 36 uint8_t codecType; 37 38 // Codec sample 39 uint32_t sampleRate; 40 41 // Codec bits per sample 42 uint32_t bitsPerSample; 43 44 // Codec channel mode 45 uint8_t channelMode; 46 47 // Codec specific value1 48 uint64_t codecSpecific1; 49 50 // Codec specific value2 51 uint64_t codecSpecific2; 52 53 // Codec specific value3 54 uint64_t codecSpecific3; 55 56 // Codec specific value4 57 uint64_t codecSpecific4; 58 }; 59 60 /** 61 * @brief The codec configuration and capability information of a2dp source 62 * 63 * @since 6.0 64 */ 65 struct A2dpSrcCodecStatus { 66 // current codec information 67 A2dpSrcCodecInfo codecInfo {}; 68 69 // local codec information 70 std::vector<A2dpSrcCodecInfo> codecInfoLocalCap {}; 71 72 // Local device and peer confirmed codec information 73 std::vector<A2dpSrcCodecInfo> codecInfoConfirmedCap {}; 74 }; 75 76 /** 77 * @brief Callback function api of A2DP service, including connection, disconnection. 78 * 79 * @since 6.0 80 */ 81 class IA2dpObserver { 82 public: 83 /** 84 * @brief A destructor used to delete the A2DP Service Observer instance. 85 * 86 * @since 6.0 87 */ 88 virtual ~IA2dpObserver() = default; 89 90 /** 91 * @brief The callback function after device's playing state changed. 92 * 93 * @param device the remote bluetooth device. 94 * @param playingState the playing state after changing. 95 * @param error the error information. 96 * @since 6.0 97 */ OnPlayingStatusChaned(const RawAddress & device,int playingState,int error)98 virtual void OnPlayingStatusChaned(const RawAddress &device, int playingState, int error) {}; 99 100 /** 101 * @brief The callback function after device's codec information changed. 102 * 103 * @param device the remote bluetooth device. 104 * @param info the device's codec information. 105 * @param error the error information. 106 * @since 6.0 107 */ OnConfigurationChanged(const RawAddress & device,const A2dpSrcCodecInfo & info,int error)108 virtual void OnConfigurationChanged(const RawAddress &device, const A2dpSrcCodecInfo &info, int error) {}; 109 110 /** 111 * @brief ConnectionState Changed observer. 112 * @param device bluetooth device address. 113 * @param state Connection state. 114 * @since 6.0 115 */ OnConnectionStateChanged(const RawAddress & remoteAddr,int state)116 virtual void OnConnectionStateChanged(const RawAddress &remoteAddr, int state) {}; 117 118 /** 119 * @brief Media stack Changed observer. 120 * @param device bluetooth device address. 121 * @param state Action on the device. 122 * @since 11.0 123 */ OnMediaStackChanged(const RawAddress & remoteAddr,int action)124 virtual void OnMediaStackChanged(const RawAddress &remoteAddr, int action) {}; 125 126 /** 127 * @brief virtual device changed observer. 128 * @param action add or remove virtual device. 129 * @param address address on the virtual device. 130 * @since 12.0 131 */ OnVirtualDeviceChanged(int32_t action,std::string address)132 virtual void OnVirtualDeviceChanged(int32_t action, std::string address) {}; 133 134 /** 135 * @brief hdap ConnectionState Changed observer. 136 * @param device bluetooth device address. 137 * @param state Connection state. 138 * @param info the device's codec information 139 * @since 12.0 140 */ OnCaptureConnectionStateChanged(const RawAddress & remoteAddr,int state,const A2dpSrcCodecInfo & info)141 virtual void OnCaptureConnectionStateChanged(const RawAddress &remoteAddr, int state, 142 const A2dpSrcCodecInfo &info) {}; 143 }; 144 145 /** 146 * @brief This class provides functions called by Framework API. 147 * 148 * @since 6.0 149 */ 150 class IProfileA2dp : public IProfile { 151 public: 152 /** 153 * @brief Get a2dp source service instance. 154 * 155 * @return Returns an instance of a2dp source service. 156 * @since 6.0 157 */ 158 static IProfileA2dp *GetSrcProfile(); 159 160 /** 161 * @brief Get a2dp sink service instance. 162 * 163 * @return Returns an instance of a2dp sink service. 164 * @since 6.0 165 */ 166 static IProfileA2dp *GetSnkProfile(); 167 168 /** 169 * @brief Get devices by connection states. 170 * 171 * @param states The connection states of the bluetooth device. 172 * @return Returns devices that match the connection states. 173 * @since 6.0 174 */ 175 virtual std::vector<RawAddress> GetDevicesByStates(std::vector<int> &states) const = 0; 176 177 /** 178 * @brief Get device connection state by address. 179 * 180 * @param device The address of the peer bluetooth device. 181 * @return Returns <b>A2DP_DISCONNECTED</b> if device connect state is disconnected; 182 * Returns <b>A2DP_DISCONNECTING</b> if device connect state is disconnecting; 183 * Returns <b>A2DP_CONNECTED</b> if device connect state is connected; 184 * Returns <b>A2DP_CONNECTING</b> if device connect state is connecting; 185 * Returns <b>A2DP_INVALID_STATUS</b> if target device is not in device list; 186 * @since 6.0 187 */ 188 virtual int GetDeviceState(const RawAddress &device) const = 0; 189 190 /** 191 * @brief Get device playing state by address when target device is on connected. 192 * 193 * @param device The address of the peer bluetooth device. 194 * @return Returns <b>1</b> if device is on playing; 195 * Returns <b>0</b> if device is not on playing; 196 * @since 6.0 197 */ 198 virtual int GetPlayingState(const RawAddress &device, int &state) const = 0; 199 200 /** 201 * @brief Set target device as active device. 202 * 203 * @param device The address of the peer bluetooth device. 204 * @return Returns <b>RET_NO_ERROR</b> Target device has already been active, or perform normal setting processing. 205 * Returns <b>RET_BAD_STATUS</b> Target device is not on connected, or set fails. 206 * @since 6.0 207 */ 208 virtual int SetActiveSinkDevice(const RawAddress &device) = 0; 209 210 /** 211 * @brief Get active device. 212 * @return Returns active device. 213 * @since 6.0 214 */ 215 virtual const RawAddress &GetActiveSinkDevice() const = 0; 216 217 /** 218 * @brief Set connection strategy for peer bluetooth device. 219 * If peer device is connected and the policy is set not allowed,then perform disconnect operation. 220 * If peer device is disconnected and the policy is set allowed,then perform connect operation. 221 * 222 * @param device The address of the peer bluetooth device. 223 * @param strategy The device connect strategy. 224 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 225 * Returns <b>RET_BAD_STATUS</b> if the operation fails. 226 * @since 6.0 227 */ 228 virtual int SetConnectStrategy(const RawAddress &device, int strategy) = 0; 229 230 /** 231 * @brief Get connection strategy of peer bluetooth device. 232 * 233 * @param device The address of the peer bluetooth device. 234 * @return Returns <b>CONNECTION_ALLOWED</b> if the peer device is allowed to connect. 235 * Returns <b>CONNECTION_FORBIDDEN</b> if the peer device is not allowed to connect. 236 * Returns <b>CONNECTION_UNKNOWN</b> if the connection policy is unknown. 237 * @since 6.0 238 */ 239 virtual int GetConnectStrategy(const RawAddress &device) const = 0; 240 241 /** 242 * @brief Send delay reporting. 243 * 244 * @param device The address of the peer bluetooth device. 245 * @param delayValue The delay value. 246 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 247 * Returns <b>RET_BAD_STATUS</b> if the operation fails. 248 */ 249 virtual int SendDelay(const RawAddress &device, uint16_t delayValue) = 0; 250 251 /** 252 * @brief Get codec status information of connected device. 253 * 254 * @param device The address of the bluetooth device. 255 * @return Returns codec status information of connected device. 256 * @since 6.0 257 */ 258 virtual A2dpSrcCodecStatus GetCodecStatus(const RawAddress &device) const = 0; 259 260 /** 261 * @brief Set the codec encoding preferences of the specified device. 262 * 263 * @param device The address of the bluetooth device. 264 * @param info The codec encoding information. 265 * @return Return 266 * @since 6.0 267 */ 268 virtual int SetCodecPreference(const RawAddress &device, const A2dpSrcCodecInfo &info) = 0; 269 270 /** 271 * @brief Set whether enables the optional codec. 272 * 273 * @param device The address of the bluetooth device. 274 * @param isEnable Set true if enables the optional codec and set optional codec's priority high. 275 * Set false if disables the optional codec and set optional codec's priority low. 276 * @since 6.0 277 */ 278 virtual void SwitchOptionalCodecs(const RawAddress &device, bool isEnable) = 0; 279 280 /** 281 * @brief Get whether the peer bluetooth device supports optional codec. 282 * 283 * @param device The address of the bluetooth device. 284 * @return Returns <b>A2DP_OPTIONAL_SUPPORT</b> The device supports optional codec. 285 * Returns <b>A2DP_OPTIONAL_NOT_SUPPORT</b> The device doesn't support optional codec. 286 * Returns <b>A2DP_OPTIONAL_SUPPORT_UNKNOWN</b> Don't know if the device support optional codec. 287 * @since 6.0 288 */ 289 virtual int GetOptionalCodecsSupportState(const RawAddress &device) const = 0; 290 291 /** 292 * @brief Audio start streaming. 293 * 294 * @param device The address of the bluetooth device. 295 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 296 * Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list. 297 * @since 6.0 298 */ 299 virtual int StartPlaying(const RawAddress &device) = 0; 300 301 /** 302 * @brief Audio suspend streaming. 303 * 304 * @param device The address of the bluetooth device. 305 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 306 * Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list. 307 * @since 6.0 308 */ 309 virtual int SuspendPlaying(const RawAddress &device) = 0; 310 311 /** 312 * @brief Audio stop streaming. 313 * 314 * @param device The address of the bluetooth device. 315 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 316 * Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list. 317 * @since 6.0 318 */ 319 virtual int StopPlaying(const RawAddress &device) = 0; 320 321 /** 322 * @brief Register observer function of framework. 323 * 324 * @param observer The observer function pointer of framework. 325 * @since 6.0 326 */ 327 virtual void RegisterObserver(IA2dpObserver *observer) = 0; 328 329 /** 330 * @brief Deregister observer function of framework. 331 * 332 * @since 6.0 333 */ 334 virtual void DeregisterObserver(IA2dpObserver *observer) = 0; 335 336 /** 337 * @brief Send frame data. 338 * @param[in] data: The address of the data 339 * @param[in] size: The size of the data 340 * @since 6.0 341 */ 342 virtual int WriteFrame(const uint8_t *data, uint32_t size) = 0; 343 344 /** 345 * @brief Get the current rendered position. 346 * @param device The address of the bluetooth device. 347 * @param[out] delayValue: The delayed time 348 * @param[out] sendDataSize: The size of the data sent 349 * @param[out] timeStamp: The time of the current position 350 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 351 * @since 6.0 352 */ 353 virtual int GetRenderPosition(const RawAddress &device, uint32_t &delayValue, uint64_t &sendDataSize, 354 uint32_t &timeStamp) = 0; 355 356 /** 357 * @brief update a2dp virtual device. 358 * 359 * @param actiion 0:add, 1:remove. 360 * @param address address of virtual device 361 * @since 12.0 362 */ UpdateVirtualDevice(int32_t action,const std::string & address)363 virtual void UpdateVirtualDevice(int32_t action, const std::string &address) {}; 364 365 /** 366 * @brief get a2dp virtual device list. 367 * 368 * @param devices address of virtual device list. 369 * @since 12.0 370 */ GetVirtualDeviceList(std::vector<std::string> & devices)371 virtual void GetVirtualDeviceList(std::vector<std::string> &devices) {}; 372 }; 373 /** 374 * @brief This class provides functions called by Framework API for a2dp source. 375 * 376 * @since 6.0 377 */ 378 class IProfileA2dpSrc : public IProfileA2dp {}; 379 } // namespace bluetooth 380 } // namespace OHOS 381 382 #endif // INTERFACE_PROFILE_A2DP_SRC_H