1 /* 2 * Copyright (C) 2021 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 bluetooth_avrcp_tg.h 18 * 19 * @brief Declares the class of the AVRCP target framework, including attributes and methods. 20 * 21 * @since 6 22 */ 23 24 #ifndef BLUETOOTH_AVRCP_TG_H 25 #define BLUETOOTH_AVRCP_TG_H 26 27 #include <vector> 28 29 #include "bluetooth_def.h" 30 #include "bluetooth_types.h" 31 #include "bluetooth_remote_device.h" 32 33 namespace OHOS { 34 namespace Bluetooth { 35 /** 36 * @brief This class provides a set of methods for operating the AVRCP target. 37 * 38 * @since 6 39 */ 40 class BLUETOOTH_API AvrcpTarget { 41 public: 42 /** 43 * @brief This abstract class declares a set of methods for observing the <b>AvrcpTarget::IObserver</b> class. 44 * 45 * @since 6 46 */ 47 class IObserver { 48 public: 49 /** 50 * @brief A constructor used to create an <b>AvrcpController::IObserver</b> instance. 51 * 52 * @since 6 53 */ 54 IObserver() = default; 55 56 /** 57 * @brief A destructor used to delete the <b>AvrcpController::IObserver</b> instance. 58 * 59 * @since 6 60 */ 61 virtual ~IObserver() = default; 62 63 /** 64 * @brief Observes the state of the connection. 65 * 66 * @param[in] device The bluetooth device. 67 * @param[in] state The connection state. Refer to <b>BTConnectState</b>. 68 * 69 * @since 6 70 */ 71 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state) = 0; 72 }; 73 74 /** 75 * @brief Gets the static instance of the <b>AvrcpTarget</b> class. 76 * 77 * @return The static instance. 78 * 79 * @since 6 80 */ 81 static AvrcpTarget *GetProfile(void); 82 83 /****************************************************************** 84 * REGISTER / UNREGISTER OBSERVER * 85 ******************************************************************/ 86 87 /** 88 * @brief Registers the observer. 89 * 90 * @param[in] observer The pointer to the <b>AvrcpTarget::IObserver</b>. 91 * @since 6 92 */ 93 void RegisterObserver(std::shared_ptr<AvrcpTarget::IObserver> observer); 94 95 /** 96 * @brief Unregisters the observer. 97 * 98 * @param[in] observer The pointer to the <b>AvrcpTarget::IObserver</b>. 99 * @since 6 100 */ 101 void UnregisterObserver(std::shared_ptr<AvrcpTarget::IObserver> observer); 102 103 /****************************************************************** 104 * CONNECTION * 105 ******************************************************************/ 106 107 /** 108 * @brief Sets the active device. 109 * 110 * @detail Only one CT can interact witch TG. 111 * 112 * @since 6 113 */ 114 void SetActiveDevice(const BluetoothRemoteDevice &device); 115 116 /** 117 * @brief Gets the connected devices. 118 * 119 * @return The list of the instance of the <b>BluetoothRemoteDevice</b> class. 120 * 121 * @since 6 122 */ 123 std::vector<BluetoothRemoteDevice> GetConnectedDevices(void); 124 125 /** 126 * @brief Gets the devices of the specified states. 127 * 128 * @param[in] states The connection states. Refer to <b>BTConnectState</b>. 129 * @return The list of the instance of the <b>BluetoothRemoteDevice</b> class. 130 * 131 * @since 6 132 */ 133 std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states); 134 135 /** 136 * @brief Gets the connection state of the specified bluetooth device. 137 * 138 * @param[in] rawAddr The address of the bluetooth device. 139 * @return The connection state. Refer to <b>BTConnectState</b>. 140 * 141 * @since 6 142 */ 143 int GetDeviceState(const BluetoothRemoteDevice &device); 144 145 /** 146 * @brief Connects to the AVRCP CT service. 147 * 148 * @param[in] device The bluetooth device. 149 * @return The result of the method execution. 150 * @retval true command send success. 151 * @retval false command seend failed. 152 * 153 * @since 6 154 */ 155 bool Connect(const BluetoothRemoteDevice &device); 156 157 /** 158 * @brief Disconnects from the AVRCP CT service. 159 * 160 * @param[in] device The bluetooth device. 161 * @return The result of the method execution. 162 * @retval true command send success. 163 * @retval false command seend failed. 164 * 165 * @since 6 166 */ 167 bool Disconnect(const BluetoothRemoteDevice &device); 168 /****************************************************************** 169 * NOTIFICATION * 170 ******************************************************************/ 171 172 /** 173 * @brief Notifies the playback status is changed. 174 * 175 * @param[in] uid The unique ID of media item. 176 * @param[in] playbackPos Current playback position in millisecond. 177 * 178 * @since 6 179 */ 180 void NotifyPlaybackStatusChanged(uint8_t playStatus, uint32_t playbackPos); 181 182 /** 183 * @brief Notifies the track is changed. 184 * 185 * @param[in] uid The unique ID of media item. 186 * @param[in] playbackPos Current playback position in millisecond. 187 * 188 * @since 6 189 */ 190 void NotifyTrackChanged(uint64_t uid, uint32_t playbackPos); 191 192 /** 193 * @brief Notifies the track reached end is changed. 194 * 195 * @param[in] playbackPos Current playback position in millisecond. 196 * 197 * @since 6 198 */ 199 void NotifyTrackReachedEnd(uint32_t playbackPos); 200 201 /** 202 * @brief Notifies the track reached start is changed. 203 * 204 * @param[in] playbackPos Current playback position in millisecond. 205 * 206 * @since 6 207 */ 208 void NotifyTrackReachedStart(uint32_t playbackPos); 209 210 /** 211 * @brief Notifies the player application setting is changed. 212 * 213 * @param[in] playbackPos Current playback position in millisecond. 214 * 215 * @since 6 216 */ 217 void NotifyPlaybackPosChanged(uint32_t playbackPos); 218 219 /** 220 * @brief Notifies the player application setting is changed. 221 * 222 * @since 6 223 */ 224 void NotifyPlayerAppSettingChanged(const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values); 225 226 /** 227 * @brief Notifies the addressed player is changed. 228 * 229 * @since 6 230 */ 231 void NotifyNowPlayingContentChanged(void); 232 233 /** 234 * @brief Notifies that has the available player. 235 * 236 * @since 6 237 */ 238 void NotifyAvailablePlayersChanged(void); 239 240 /** 241 * @brief Notifies the addressed player is changed. 242 * 243 * @param[in] playerId The unique media player id. 244 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 245 * 246 * @since 6 247 */ 248 void NotifyAddressedPlayerChanged(uint16_t playerId, uint16_t uidCounter); 249 250 /** 251 * @brief Notifies the uids is changed. 252 * 253 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 254 * 255 * @since 6 256 */ 257 void NotifyUidChanged(uint16_t uidCounter); 258 259 /** 260 * @brief Notifies the absolute volume is changed. 261 * 262 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 263 * 264 * @since 6 265 */ 266 void NotifyVolumeChanged(uint8_t volume); 267 268 /** 269 * @brief The external process calls the A2dpsrc profile interface before the Bluetooth process starts. At this 270 * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the 271 * A2dpsrc proflie. 272 */ 273 void Init(); 274 275 /** 276 * @brief audio set device absolute volume. 277 * 278 * @param[in] device The remote device. 279 * @param[in] volumeLevel device absolute volume. 280 * @return error code 281 * @since 6 282 */ 283 int32_t SetDeviceAbsoluteVolume(const BluetoothRemoteDevice &device, int32_t volumeLevel); 284 285 /** 286 * @brief set device absolute ability. 287 * 288 * @param[in] device The remote device. 289 * @param[in] ability device absolute ability see {DeviceAbsVolumeAbility}. 290 * @return error code 291 * @since 6 292 */ 293 int32_t SetDeviceAbsVolumeAbility(const BluetoothRemoteDevice &device, int32_t ability); 294 295 /** 296 * @brief get device absolute volume ability. 297 * 298 * @param[in] device The remote device. 299 * @param[out] ability device absolute ability see {DeviceAbsVolumeAbility}. 300 * @return error code 301 * @since 6 302 */ 303 int32_t GetDeviceAbsVolumeAbility(const BluetoothRemoteDevice &device, int32_t &ability); 304 305 private: 306 /** 307 * @brief A constructor used to create an <b>AvrcpTarget</b> instance. 308 * 309 * @since 6 310 */ 311 AvrcpTarget(); 312 313 /** 314 * @brief A destructor used to delete the <b>AvrcpTarget</b> instance. 315 * 316 * @since 6 317 */ 318 ~AvrcpTarget(); 319 320 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AvrcpTarget); 321 BLUETOOTH_DECLARE_IMPL(); 322 }; 323 } // namespace Bluetooth 324 } // namespace OHOS 325 326 #endif // !BLUETOOTH_AVRCP_TG_H 327