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