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 /** 136 * @brief This class provides functions called by Framework API. 137 * 138 * @since 6.0 139 */ 140 class IProfileA2dp : public IProfile { 141 public: 142 /** 143 * @brief Get a2dp source service instance. 144 * 145 * @return Returns an instance of a2dp source service. 146 * @since 6.0 147 */ 148 static IProfileA2dp *GetSrcProfile(); 149 150 /** 151 * @brief Get a2dp sink service instance. 152 * 153 * @return Returns an instance of a2dp sink service. 154 * @since 6.0 155 */ 156 static IProfileA2dp *GetSnkProfile(); 157 158 /** 159 * @brief Get devices by connection states. 160 * 161 * @param states The connection states of the bluetooth device. 162 * @return Returns devices that match the connection states. 163 * @since 6.0 164 */ 165 virtual std::vector<RawAddress> GetDevicesByStates(std::vector<int> &states) const = 0; 166 167 /** 168 * @brief Get device connection state by address. 169 * 170 * @param device The address of the peer bluetooth device. 171 * @return Returns <b>A2DP_DISCONNECTED</b> if device connect state is disconnected; 172 * Returns <b>A2DP_DISCONNECTING</b> if device connect state is disconnecting; 173 * Returns <b>A2DP_CONNECTED</b> if device connect state is connected; 174 * Returns <b>A2DP_CONNECTING</b> if device connect state is connecting; 175 * Returns <b>A2DP_INVALID_STATUS</b> if target device is not in device list; 176 * @since 6.0 177 */ 178 virtual int GetDeviceState(const RawAddress &device) const = 0; 179 180 /** 181 * @brief Get device playing state by address when target device is on connected. 182 * 183 * @param device The address of the peer bluetooth device. 184 * @return Returns <b>1</b> if device is on playing; 185 * Returns <b>0</b> if device is not on playing; 186 * @since 6.0 187 */ 188 virtual int GetPlayingState(const RawAddress &device, int &state) const = 0; 189 190 /** 191 * @brief Set target device as active device. 192 * 193 * @param device The address of the peer bluetooth device. 194 * @return Returns <b>RET_NO_ERROR</b> Target device has already been active, or perform normal setting processing. 195 * Returns <b>RET_BAD_STATUS</b> Target device is not on connected, or set fails. 196 * @since 6.0 197 */ 198 virtual int SetActiveSinkDevice(const RawAddress &device) = 0; 199 200 /** 201 * @brief Get active device. 202 * @return Returns active device. 203 * @since 6.0 204 */ 205 virtual const RawAddress &GetActiveSinkDevice() const = 0; 206 207 /** 208 * @brief Set connection strategy for peer bluetooth device. 209 * If peer device is connected and the policy is set not allowed,then perform disconnect operation. 210 * If peer device is disconnected and the policy is set allowed,then perform connect operation. 211 * 212 * @param device The address of the peer bluetooth device. 213 * @param strategy The device connect strategy. 214 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 215 * Returns <b>RET_BAD_STATUS</b> if the operation fails. 216 * @since 6.0 217 */ 218 virtual int SetConnectStrategy(const RawAddress &device, int strategy) = 0; 219 220 /** 221 * @brief Get connection strategy of peer bluetooth device. 222 * 223 * @param device The address of the peer bluetooth device. 224 * @return Returns <b>CONNECTION_ALLOWED</b> if the peer device is allowed to connect. 225 * Returns <b>CONNECTION_FORBIDDEN</b> if the peer device is not allowed to connect. 226 * Returns <b>CONNECTION_UNKNOWN</b> if the connection policy is unknown. 227 * @since 6.0 228 */ 229 virtual int GetConnectStrategy(const RawAddress &device) const = 0; 230 231 /** 232 * @brief Send delay reporting. 233 * 234 * @param device The address of the peer bluetooth device. 235 * @param delayValue The delay value. 236 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 237 * Returns <b>RET_BAD_STATUS</b> if the operation fails. 238 */ 239 virtual int SendDelay(const RawAddress &device, uint16_t delayValue) = 0; 240 241 /** 242 * @brief Get codec status information of connected device. 243 * 244 * @param device The address of the bluetooth device. 245 * @return Returns codec status information of connected device. 246 * @since 6.0 247 */ 248 virtual A2dpSrcCodecStatus GetCodecStatus(const RawAddress &device) const = 0; 249 250 /** 251 * @brief Set the codec encoding preferences of the specified device. 252 * 253 * @param device The address of the bluetooth device. 254 * @param info The codec encoding information. 255 * @return Return 256 * @since 6.0 257 */ 258 virtual int SetCodecPreference(const RawAddress &device, const A2dpSrcCodecInfo &info) = 0; 259 260 /** 261 * @brief Set whether enables the optional codec. 262 * 263 * @param device The address of the bluetooth device. 264 * @param isEnable Set true if enables the optional codec and set optional codec's priority high. 265 * Set false if disables the optional codec and set optional codec's priority low. 266 * @since 6.0 267 */ 268 virtual void SwitchOptionalCodecs(const RawAddress &device, bool isEnable) = 0; 269 270 /** 271 * @brief Get whether the peer bluetooth device supports optional codec. 272 * 273 * @param device The address of the bluetooth device. 274 * @return Returns <b>A2DP_OPTIONAL_SUPPORT</b> The device supports optional codec. 275 * Returns <b>A2DP_OPTIONAL_NOT_SUPPORT</b> The device doesn't support optional codec. 276 * Returns <b>A2DP_OPTIONAL_SUPPORT_UNKNOWN</b> Don't know if the device support optional codec. 277 * @since 6.0 278 */ 279 virtual int GetOptionalCodecsSupportState(const RawAddress &device) const = 0; 280 281 /** 282 * @brief Audio start streaming. 283 * 284 * @param device The address of the bluetooth device. 285 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 286 * Returns <b>RET_BAD_STATUS</b> if the operation fails, or device is not in device list. 287 * @since 6.0 288 */ 289 virtual int StartPlaying(const RawAddress &device) = 0; 290 291 /** 292 * @brief Audio suspend 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 SuspendPlaying(const RawAddress &device) = 0; 300 301 /** 302 * @brief Audio stop 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 StopPlaying(const RawAddress &device) = 0; 310 311 /** 312 * @brief Register observer function of framework. 313 * 314 * @param observer The observer function pointer of framework. 315 * @since 6.0 316 */ 317 virtual void RegisterObserver(IA2dpObserver *observer) = 0; 318 319 /** 320 * @brief Deregister observer function of framework. 321 * 322 * @since 6.0 323 */ 324 virtual void DeregisterObserver(IA2dpObserver *observer) = 0; 325 326 /** 327 * @brief Send frame data. 328 * @param[in] data: The address of the data 329 * @param[in] size: The size of the data 330 * @since 6.0 331 */ 332 virtual int WriteFrame(const uint8_t *data, uint32_t size) = 0; 333 334 /** 335 * @brief Get the current rendered position. 336 * @param device The address of the bluetooth device. 337 * @param[out] delayValue: The delayed time 338 * @param[out] sendDataSize: The size of the data sent 339 * @param[out] timeStamp: The time of the current position 340 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 341 * @since 6.0 342 */ 343 virtual int GetRenderPosition(const RawAddress &device, uint32_t &delayValue, uint64_t &sendDataSize, 344 uint32_t &timeStamp) = 0; 345 346 /** 347 * @brief update a2dp virtual device. 348 * 349 * @param actiion 0:add, 1:remove. 350 * @param address address of virtual device 351 * @since 12.0 352 */ UpdateVirtualDevice(int32_t action,const std::string & address)353 virtual void UpdateVirtualDevice(int32_t action, const std::string &address) {}; 354 355 /** 356 * @brief get a2dp virtual device list. 357 * 358 * @param devices address of virtual device list. 359 * @since 12.0 360 */ GetVirtualDeviceList(std::vector<std::string> & devices)361 virtual void GetVirtualDeviceList(std::vector<std::string> &devices) {}; 362 }; 363 /** 364 * @brief This class provides functions called by Framework API for a2dp source. 365 * 366 * @since 6.0 367 */ 368 class IProfileA2dpSrc : public IProfileA2dp {}; 369 } // namespace bluetooth 370 } // namespace OHOS 371 372 #endif // INTERFACE_PROFILE_A2DP_SRC_H