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 #ifndef AVRCP_TG_SERVICE_H 17 #define AVRCP_TG_SERVICE_H 18 19 #include <atomic> 20 #include <deque> 21 #include "avrcp_tg_gap.h" 22 #include "avrcp_tg_internal.h" 23 #include "avrcp_tg_profile.h" 24 #include "avrcp_tg_sdp.h" 25 #include "bt_def.h" 26 #include "context.h" 27 #include "interface_profile_avrcp_tg.h" 28 #include "raw_address.h" 29 #include "stub/media_service.h" 30 #ifdef AVRCP_AVSESSION 31 #include "avsession_manager.h" 32 #include "avsession_errors.h" 33 #endif 34 namespace OHOS { 35 namespace bluetooth { 36 /** 37 * @brief This enumeration declares the states of the AVRCP TG service. 38 */ 39 enum AvrcTgServiceState : uint8_t { 40 AVRC_TG_SERVICE_STATE_INVALID = 0x00, 41 AVRC_TG_SERVICE_STATE_ENABLING, 42 AVRC_TG_SERVICE_STATE_ENABLED, 43 AVRC_TG_SERVICE_STATE_DISABLING, 44 AVRC_TG_SERVICE_STATE_DISABLED, 45 }; 46 47 /** 48 * @brief This class provides a set of methods related to the role of the target described in the Audio/Video Remote 49 * Control profile. 50 */ 51 class AvrcpTgService : public IProfileAvrcpTg, public utility::Context { 52 public: 53 /** 54 * @brief This class implement the <b>stub::MediaService::IObserver</b> interface for observing the state change. 55 */ 56 class ObserverImpl : public stub::MediaService::IObserver { 57 public: 58 /** 59 * @brief A constructor used to create an <b>ObserverImpl</b> instance. 60 */ 61 ObserverImpl() = default; 62 63 /** 64 * @brief A destructor used to delete the <b>ObserverImpl</b> instance. 65 */ 66 ~ObserverImpl() = default; 67 68 void OnConnectionStateChanged(const std::string &addr, int state) override; 69 void OnPressButton(const std::string &addr, uint8_t button) override; 70 void OnReleaseButton(const std::string &addr, uint8_t button) override; 71 72 /** 73 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 74 * 75 * @param[in] addr The address of the bluetooth device. 76 * @param[in] label The label which is used to distinguish different call. 77 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 78 * @a AVRC_ES_CODE_NO_ERROR<br> 79 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 80 * @a AVRC_ES_CODE_UID_CHANGED<br> 81 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 82 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 83 */ 84 void OnSetAddressedPlayer(const std::string &addr, uint8_t label, int status) override; 85 86 /** 87 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 88 * 89 * @param[in] addr The address of the bluetooth device. 90 * @param[in] uidCounter The value of the uid counter. 91 * @param[in] numOfItems The number of items in the directory. 92 * @param[in] folderNames The current browsed path of the player. The first element in folderNames is the parent 93 * folder. The root folder has no name. The names are in UTF-8. 94 * @param[in] label The label which is used to distinguish different call. 95 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 96 * @a AVRC_ES_CODE_NO_ERROR<br> 97 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 98 * @a AVRC_ES_CODE_UID_CHANGED<br> 99 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 100 * @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br> 101 * @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br> 102 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 103 */ 104 void OnSetBrowsedPlayer(const std::string &addr, uint16_t uidCounter, uint32_t numOfItems, 105 const std::vector<std::string> &folderNames, uint8_t label, int status) override; 106 107 /** 108 * @brief Responds the data of the <b>OnGetPlayerAppSettingAttributes</b>. 109 * 110 * @param[in] addr The address of the bluetooth device. 111 * @param[in] The attribute of the player application settings. 112 * @param[in] label The label which is used to distinguish different call. 113 */ 114 void OnGetPlayerAppSettingAttributes( 115 const std::string &addr, const std::deque<uint8_t> &attributes, uint8_t label) override; 116 117 /** 118 * @brief Responds the data of the <b>GetPlayerAppSettingValues</b>. 119 * 120 * @param[in] addr The address of the bluetooth device. 121 * @param[in] values The values associated witch the attribute. 122 * @param[in] label The label which is used to distinguish different call. 123 */ 124 void OnGetPlayerAppSettingValues( 125 const std::string &addr, const std::deque<uint8_t> &values, uint8_t label) override; 126 127 /** 128 * @brief Responds the data of the <b>GetCurrentPlayerAppSettingValue</b>. 129 * 130 * @param[in] addr The address of the bluetooth device. 131 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 132 * @param[in] values The values associated witch the attribute. 133 * @param[in] label The label which is used to distinguish different call. 134 * @param[in] context The context which is used to distinguish different purpose. 135 */ 136 void OnGetPlayerAppSettingCurrentValue(const std::string &addr, const std::deque<uint8_t> &attributes, 137 const std::deque<uint8_t> &values, uint8_t label, uint8_t context) override; 138 139 /** 140 * @brief Responds the data of the <b>SetSetPlayerAppSettingCurrentValue</b>. 141 * 142 * @param[in] addr The address of the bluetooth device. 143 * @param[in] label The label which is used to distinguish different call. 144 */ 145 void OnSetPlayerAppSettingCurrentValue(const std::string &addr, uint8_t label) override; 146 147 /** 148 * @brief Responds the data of the <b>GetPlayerAppSettingAttributeTest</b>. 149 * 150 * @param[in] addr The address of the bluetooth device. 151 * @param[in] attributes The attribute of the player application settings. 152 * @param[in] attrStr The values associated witch the attribute. 153 * @param[in] label The label which is used to distinguish different call. 154 */ 155 void OnGetPlayerAppSettingAttributeText(const std::string &addr, const std::vector<uint8_t> &attributes, 156 const std::vector<std::string> &attrStr, uint8_t label) override; 157 158 /** 159 * @brief Responds the data of the <b>GetPlayerAppSettingValueText</b>. 160 * 161 * @param[in] addr The address of the bluetooth device. 162 * @param[in] values Player application setting value ID. 163 * @param[in] valueStr Specifies the value string of player application setting value. 164 * @param[in] label The label which is used to distinguish different call. 165 */ 166 void OnGetPlayerAppSettingValueText(const std::string &addr, const std::vector<uint8_t> &values, 167 const std::vector<std::string> &valueStr, uint8_t label) override; 168 169 /** 170 * @brief Responds the data of the <b>GetElementAttributes</b>. 171 * 172 * @details Switch to the thread of the AVRCP CT service in this function. 173 * @param[in] rawAddr The address of the bluetooth device. 174 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved. 175 * @param[in] values The list of the value of this attribute. 176 * @param[in] label The label which is used to distinguish different call. 177 */ 178 void OnGetElementAttributes(const std::string &addr, const std::vector<uint32_t> &attribtues, 179 const std::vector<std::string> &values, uint8_t label) override; 180 181 /** 182 * @brief Responds the data of the <b>GetPlayStatus</b>. 183 * 184 * @param[in] addr The address of the bluetooth device. 185 * @param[in] songLength The total length of the playing song in milliseconds. 186 * @param[in] songPosition The current position of the playing in milliseconds elapsed. 187 * @param[in] playStatus The current status of playing. Refer to <b>bluetooth::AvrcPlayStatus</b>. 188 * @param[in] label The label which is used to distinguish different call. 189 * @param[in] context The context which is used to distinguish different purpose. 190 */ 191 void OnGetPlayStatus(const std::string &addr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, 192 uint8_t label, uint8_t context) override; 193 194 /** 195 * @brief Responds the data of the <b>PlayItem</b>. 196 * 197 * @param[in] addr The address of the bluetooth device. 198 * @param[in] label The label which is used to distinguish different call. 199 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 200 * @a AVRC_ES_CODE_INVALID_COMMAND<br> 201 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 202 * @a AVRC_ES_CODE_INVALID_PARAMETER<br> 203 * @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br> 204 * @a AVRC_ES_CODE_NO_ERROR<br> 205 * @a AVRC_ES_CODE_UID_CHANGED<br> 206 * @a AVRC_ES_CODE_RESERVED<br> 207 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 208 * @a AVRC_ES_CODE_INVALID_SCOPE 209 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 210 * @a AVRC_ES_CODE_MEDIA_IN_USE 211 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 212 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 213 */ 214 void OnPlayItem(const std::string &addr, uint8_t label, int status) override; 215 216 /** 217 * @brief Responds the data of the <b>AddToNowPlaying</b>. 218 * 219 * @param[in] addr The address of the bluetooth device. 220 * @param[in] label The label which is used to distinguish different call. 221 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 222 * @a AVRC_ES_CODE_NO_ERROR<br> 223 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 224 * @a AVRC_ES_CODE_UID_CHANGED<br> 225 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 226 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 227 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br> 228 * @a AVRC_ES_CODE_MEDIA_IN_USE<br> 229 * @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br> 230 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 231 */ 232 void OnAddToNowPlaying(const std::string &addr, uint8_t label, int status) override; 233 234 /** 235 * @brief Responds the data of the <b>ChangePath</b>. 236 * 237 * @param[in] addr The address of the bluetooth device. 238 * @param[in] numOfItems The number of items in the directory. 239 * @param[in] label The label which is used to distinguish different call. 240 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 241 * @a AVRC_ES_CODE_NO_ERROR<br> 242 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 243 * @a AVRC_ES_CODE_UID_CHANGED<br> 244 * @a AVRC_ES_CODE_INVALID_DIRECTION<br> 245 * @a AVRC_ES_CODE_NOT_A_DIRECTORY<br> 246 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 247 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 248 */ 249 void OnChangePath(const std::string &addr, uint32_t numOfItems, uint8_t label, int status) override; 250 251 /** 252 * @brief Responds the data of the <b>GetFolderItems</b>. 253 * 254 * @param[in] addr The address of the bluetooth device. 255 * @param[in] uidCounter The value of the uid counter. 256 * @param[in] items The list of media player. 257 * @param[in] label The label which is used to distinguish different call. 258 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 259 * @a AVRC_ES_CODE_NO_ERROR<br> 260 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 261 * @a AVRC_ES_CODE_UID_CHANGED<br> 262 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 263 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 264 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 265 */ 266 void OnGetMediaPlayers(const std::string &addr, uint16_t uidCounter, 267 const std::vector<stub::MediaService::MediaPlayer> &items, uint8_t label, int status) override; 268 269 /** 270 * @brief Responds the data of the <b>GetFolderItems</b>. 271 * 272 * @param[in] addr The address of the bluetooth device. 273 * @param[in] uidCounter The value of the uid counter. 274 * @param[in] items The list of media items. 275 * @param[in] label The label which is used to distinguish different call. 276 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 277 * @a AVRC_ES_CODE_NO_ERROR<br> 278 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 279 * @a AVRC_ES_CODE_UID_CHANGED<br> 280 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 281 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 282 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 283 */ 284 void OnGetFolderItems(const std::string &addr, uint16_t uidCounter, 285 const std::vector<stub::MediaService::MediaItem> &items, uint8_t label, int status) override; 286 287 /** 288 * @brief Responds the data of the <b>GetItemAttributes</b>. 289 * 290 * @param[in] addr The address of the bluetooth device. 291 * @param[in] attributes The list of media attributes. 292 * @param[in] values The list of the value of this attribute. 293 * @param[in] label The label which is used to distinguish different call. 294 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 295 * @a AVRC_ES_CODE_NO_ERROR<br> 296 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 297 * @a AVRC_ES_CODE_UID_CHANGED<br> 298 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 299 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 300 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 301 */ 302 void OnGetItemAttributes(const std::string &addr, const std::vector<uint32_t> &attributes, 303 const std::vector<std::string> &values, uint8_t label, int status) override; 304 305 /** 306 * @brief Responds the data of the <b>GetTotalNumberOfItems</b>. 307 * 308 * @param[in] addr The address of the bluetooth device. 309 * @param[in] uidCounter The value of the uid counter. 310 * @param[in] numOfItems The number of items in the directory. 311 * @param[in] label The label which is used to distinguish different call. 312 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 313 * @a AVRC_ES_CODE_NO_ERROR<br> 314 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 315 * @a AVRC_ES_CODE_UID_CHANGED<br> 316 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 317 */ 318 void OnGetTotalNumberOfItems( 319 const std::string &addr, uint16_t uidCounter, uint32_t numOfItems, uint8_t label, int status) override; 320 321 /** 322 * @brief Responds the data of the <b>SetAbsoluteVolume</b>. 323 * 324 * @param[in] addr The address of the bluetooth device. 325 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 326 * @param[in] label The label which is used to distinguish different call. 327 */ 328 void OnSetAbsoluteVolume(const std::string &addr, uint8_t volume, uint8_t label) override; 329 330 void OnGetSelectedTrack(const std::string &addr, uint64_t uid, uint8_t label) override; 331 332 void OnGetAddressedPlayer( 333 const std::string &addr, uint16_t playerId, uint16_t uidCounter, uint8_t label) override; 334 335 void OnGetUidCounter(const std::string &addr, uint16_t uidCounter, uint8_t label) override; 336 337 void OnGetCurrentAbsoluteVolume(const std::string &addr, uint8_t volume, uint8_t label) override; 338 339 private: 340 IProfileAvrcpTg *GetService(void); 341 }; 342 #ifdef AVRCP_AVSESSION 343 /** 344 * @brief This class implement the <b>SessionListender</b> interface for observing the state change. 345 */ 346 class AVSessionObserverImpl : public OHOS::AVSession::SessionListener { 347 public: 348 /** 349 * @brief A constructor used to create an <b>AVSessionObserverImpl</b> instance. 350 */ 351 AVSessionObserverImpl() = default; 352 353 /** 354 * @brief A destructor used to delete the <b>AVSessionObserverImpl</b> instance. 355 */ 356 ~AVSessionObserverImpl() = default; 357 358 void OnSessionCreate(const OHOS::AVSession::AVSessionDescriptor& descriptor) override; 359 void OnSessionRelease(const OHOS::AVSession::AVSessionDescriptor& descriptor) override; 360 void OnTopSessionChange(const OHOS::AVSession::AVSessionDescriptor& descriptor) override; 361 private: 362 IProfileAvrcpTg *GetService(void); 363 }; 364 365 /** 366 * @brief This class implement the <b>SessionListender</b> interface for observing the state change. 367 */ 368 class AVControllerObserverImpl : public OHOS::AVSession::AVControllerCallback { 369 public: 370 /** 371 * @brief A constructor used to create an <b>AVControllerObserverImpl</b> instance. 372 */ 373 AVControllerObserverImpl() = default; 374 375 /** 376 * @brief A destructor used to delete the <b>AVControllerObserverImpl</b> instance. 377 */ 378 ~AVControllerObserverImpl() = default; 379 380 void OnSessionDestroy() override; 381 void OnPlaybackStateChange(const OHOS::AVSession::AVPlaybackState &state) override; 382 void OnMetaDataChange(const OHOS::AVSession::AVMetaData &data) override; 383 void OnActiveStateChange(bool isActive) override; 384 void OnValidCommandChange(const std::vector<int32_t> &cmds) override; OnOutputDeviceChange(const OHOS::AVSession::OutputDeviceInfo & outputDeviceInfo)385 void OnOutputDeviceChange(const OHOS::AVSession::OutputDeviceInfo &outputDeviceInfo) override {}; 386 private: 387 IProfileAvrcpTg *GetService(void); 388 }; 389 #endif 390 /** 391 * @brief A constructor used to create an <b>AvrcpTgService</b> instance. 392 */ 393 AvrcpTgService(); 394 395 /** 396 * @brief A destructor used to delete the <b>AvrcpTgService</b> instance. 397 */ 398 ~AvrcpTgService(); 399 400 utility::Context *GetContext() override; 401 402 /****************************************************************** 403 * REGISTER / UNREGISTER OBSERVER * 404 ******************************************************************/ 405 406 /** 407 * @brief Registers the observer. 408 * 409 * @param[in] observer The pointer to the instance of the <b>AvrcTgProfile::IObserver</b>. 410 */ 411 void RegisterObserver(IObserver *observer) override; 412 413 /** 414 * @brief Unregisters the observer. 415 */ 416 void UnregisterObserver(void) override; 417 418 /****************************************************************** 419 * ENABLE / DISABLE * 420 ******************************************************************/ 421 422 /** 423 * @brief Enables the AVRCP TG service. 424 * 425 * @details Switch to the thread of the AVRCP TG service in this method. 426 * @return The result of the method execution. 427 * @retval true Execute success. 428 * @retval false Execute failure. 429 */ 430 void Enable(void) override; 431 432 /** 433 * @brief Disables the AVRCP TG service. 434 * 435 * @detail Switch to the thread of the AVRCP TG service in this method. 436 * @return The result of the method execution. 437 * @retval true Execute success. 438 * @retval false Execute failure. 439 */ 440 void Disable(void) override; 441 442 /** 443 * @brief Checks whether the AVRCP TG service is enabled. 444 * 445 * @return The result of the method execution. 446 * @retval true The service is enabled. 447 * @retval false The service is not enabled. 448 */ 449 bool IsEnabled(void) override; 450 451 /****************************************************************** 452 * CONNECTION * 453 ******************************************************************/ 454 455 /** 456 * @brief Sets the active device. 457 * 458 * @detail Only one CT can interact witch TG. 459 */ 460 void SetActiveDevice(const RawAddress &rawAddr) override; 461 462 /** 463 * @brief Gets the devices of the specified states. 464 * 465 * @param[in] states The connection states. Refer to <b>BTConnectState</b>. 466 * @return The list of the instance of the <b>RawAddress</b> class. 467 */ GetConnectDevices(void)468 std::list<RawAddress> GetConnectDevices(void) override 469 { 470 std::list<RawAddress> rawAddrs; 471 return rawAddrs; 472 }; 473 474 /** 475 * @brief Gets the connected devices. 476 * 477 * @return The list of the instance of the <b>RawAddress</b> class. 478 */ 479 std::vector<RawAddress> GetConnectedDevices(void) override; 480 481 /** 482 * @brief Gets the devices of the specified states. 483 * 484 * @param[in] states The connection states. Refer to <b>BTConnectState</b>. 485 * @return The list of the instance of the <b>RawAddress</b> class. 486 */ 487 std::vector<RawAddress> GetDevicesByStates(const std::vector<int> &states) override; 488 489 /** 490 * @brief Gets the connection state of the specified bluetooth device. 491 * 492 * @param[in] rawAddr The address of the bluetooth device. 493 * @return The connection state. Refer to <b>BTConnectState</b>. 494 */ 495 int GetDeviceState(const RawAddress &rawAddr) override; 496 497 /** 498 * @brief Gets the maximum number of connections. 499 * 500 * @return The maximum number of connections. 501 */ 502 int GetMaxConnectNum(void) override; 503 504 /** 505 * @brief Connects to the AVRCP TG service. 506 * 507 * @details Switch to the thread of the AVRCP TG service in this method. 508 * @param[in] rawAddr The address of the bluetooth device. 509 * @return The result of the method execution. 510 * @retval BT_SUCCESS Execute success. 511 * @retval RET_NO_SUPPORT The method is not supported. 512 * @retval RET_BAD_STATUS Execute failure. 513 */ 514 int Connect(const RawAddress &rawAddr) override; 515 516 /** 517 * @brief Disconnects from the AVRCP TG service. 518 * 519 * @details Switch to the thread of the AVRCP TG service in this method. 520 * @param[in] rawAddr The address of the bluetooth device. 521 * @return The result of the method execution. 522 * @retval BT_SUCCESS Execute success. 523 * @retval RET_NO_SUPPORT The method is not supported. 524 * @retval RET_BAD_STATUS Execute failure. 525 */ 526 int Disconnect(const RawAddress &rawAddr) override; 527 528 /** 529 * @brief Gets the connection states. 530 * 531 * @return The connection states. The values are in bits. 532 */ 533 int GetConnectState(void) override; 534 535 /****************************************************************** 536 * Media Player Selection * 537 ******************************************************************/ 538 539 /** 540 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 541 * 542 * @details Switch to the thread of the AVRCP TG service in this function. 543 * @param[in] rawAddr The address of the bluetooth device. 544 * @param[in] label The label which is used to distinguish different call. 545 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 546 * @a AVRC_ES_CODE_NO_ERROR<br> 547 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 548 * @a AVRC_ES_CODE_UID_CHANGED<br> 549 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 550 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 551 */ 552 void OnSetAddressedPlayer(const RawAddress &rawAddr, uint8_t label, int status) override; 553 554 /** 555 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 556 * 557 * @details Switch to the thread of the AVRCP TG service in this function. 558 * @param[in] rawAddr The address of the bluetooth device. 559 * @param[in] uidCounter The value of the uid counter. 560 * @param[in] numOfItems The number of items in the directory. 561 * @param[in] folderNames The current browsed path of the player. The first element in folderNames is the parent 562 * folder. The root folder has no name. The names are in UTF-8. 563 * @param[in] label The label which is used to distinguish different call. 564 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 565 * @a AVRC_ES_CODE_NO_ERROR<br> 566 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 567 * @a AVRC_ES_CODE_UID_CHANGED<br> 568 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 569 * @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br> 570 * @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br> 571 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 572 */ 573 void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, 574 const std::vector<std::string> &folderNames, uint8_t label, int status) override; 575 576 /****************************************************************** 577 * PLAYER APPLICATION SETTINGS * 578 ******************************************************************/ 579 580 /** 581 * @brief Responds the data of the <b>GetPlayerAppSettingAttributes</b>. 582 * 583 * @details Switch to the thread of the AVRCP TG service in this function. 584 * @param[in] rawAddr The address of the bluetooth device. 585 * @param[in] attributes The attribute of player application settings. 586 * @param[in] label The label which is used to distinguish different call. 587 */ 588 void OnGetPlayerAppSettingAttributes( 589 const RawAddress &rawAddr, const std::deque<uint8_t> &attributes, uint8_t label) override; 590 591 /** 592 * @brief Responds the data of the <b>GetPlayerAppSettingValues</b>. 593 * 594 * @details Switch to the thread of the AVRCP TG service in this function. 595 * @param[in] rawAddr The address of the bluetooth device. 596 * @param[in] values The values associated witch the attribute. 597 * @param[in] label The label which is used to distinguish different call. 598 */ 599 void OnGetPlayerAppSettingValues( 600 const RawAddress &rawAddr, const std::deque<uint8_t> &values, uint8_t label) override; 601 602 /** 603 * @brief Responds the data of the <b>GetCurrentPlayerAppSettingValue</b>. 604 * 605 * @details Switch to the thread of the AVRCP TG service in this function. 606 * @param[in] rawAddr The address of the bluetooth device. 607 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 608 * @param[in] values The values associated witch the attribute. 609 * @param[in] label The label which is used to distinguish different call. 610 * @param[in] context The context which is used to distinguish different purpose. 611 */ 612 void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::deque<uint8_t> &attributes, 613 const std::deque<uint8_t> &values, uint8_t label, uint8_t context) override; 614 615 /** 616 * @brief Responds the data of the <b>SetPlayerAppSettingCurrentValue</b>. 617 * 618 * @details Switch to the thread of the AVRCP TG service in this function. 619 * @param[in] rawAddr The address of the bluetooth device. 620 * @param[in] label The label which is used to distinguish different call. 621 */ 622 void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, uint8_t label) override; 623 624 /** 625 * @brief Responds the data of the <b>GetPlayerAppSettingAttributeTest</b>. 626 * 627 * @param[in] rawAddr The address of the bluetooth device. 628 * @param[in] attributes The attribute of the player application settings. 629 * @param[in] attrStr The values associated witch the attribute. 630 * @param[in] label The label which is used to distinguish different call. 631 */ 632 void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 633 const std::vector<std::string> &attrStr, uint8_t label) override; 634 635 /** 636 * @brief Responds the data of the <b>GetPlayerAppSettingValueText</b>. 637 * 638 * @param[in] addr The address of the bluetooth device. 639 * @param[in] values Player application setting value ID. 640 * @param[in] valueStr Specifies the value string of player application setting value. 641 * @param[in] label The label which is used to distinguish different call. 642 */ 643 void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, const std::vector<uint8_t> &values, 644 const std::vector<std::string> &valueStr, uint8_t label) override; 645 646 /****************************************************************** 647 * MEDIA INFORMATION PDUS * 648 ******************************************************************/ 649 650 /** 651 * @brief Responds the data of the <b>GetElementAttributes</b>. 652 * 653 * @details Switch to the thread of the AVRCP CT service in this function. 654 * @param[in] rawAddr The address of the bluetooth device. 655 * @param[in] attributes Specifies the attribute ID forthe attributes to be retrieved. 656 * @param[in] values The list of the value of this attribute. 657 * @param[in] label The label which is used to distinguish different call. 658 */ 659 void OnGetElementAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attribtues, 660 const std::vector<std::string> &values, uint8_t label) override; 661 662 /****************************************************************** 663 * PLAY * 664 ******************************************************************/ 665 666 /** 667 * @brief Responds the data of the <b>GetPlayStatus</b>. 668 * 669 * @details Switch to the thread of the AVRCP TG service in this function. 670 * @param[in] rawAddr The address of the bluetooth device. 671 * @param[in] songLength The total length of the playing song in milliseconds. 672 * @param[in] songPosition The current position of the playing in milliseconds elapsed. 673 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 674 * @param[in] label The label which is used to distinguish different call. 675 * @param[in] context The context which is used to distinguish different purpose. * @param[in] context The 676 * context which is used to distinguish different purpose. * @param[in] context The context which is used 677 * to distinguish different purpose. 678 */ 679 void OnGetPlayStatus(const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, 680 uint8_t label, uint8_t context) override; 681 682 /** 683 * @brief Sends the response of the <b>PlayItem</b>. 684 * 685 * @details Switch to the thread of the AVRCP TG service in this function. 686 * @param[in] rawAddr The address of the bluetooth device. 687 * @param[in] label The label which is used to distinguish different call. 688 * @param[in] status The current status of media. 689 * @a AVRC_ES_CODE_INVALID_COMMAND<br> 690 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 691 * @a AVRC_ES_CODE_INVALID_PARAMETER<br> 692 * @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br> 693 * @a AVRC_ES_CODE_NO_ERROR<br> 694 * @a AVRC_ES_CODE_UID_CHANGED<br> 695 * @a AVRC_ES_CODE_RESERVED<br> 696 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 697 * @a AVRC_ES_CODE_INVALID_SCOPE 698 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 699 * @a AVRC_ES_CODE_MEDIA_IN_USE 700 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 701 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 702 */ 703 void OnPlayItem(const RawAddress &rawAddr, uint8_t label, int status) override; 704 705 /** 706 * @brief Responds the data of the <b>AddToNowPlaying</b>. 707 * 708 * @details Switch to the thread of the AVRCP TG service in this function. 709 * @param[in] rawAddr The address of the bluetooth device. 710 * @param[in] label The label which is used to distinguish different call. 711 * @param[in] status The status of the method execution. Refer to <b>AvrcEsCode</b>.<br> 712 * @a AVRC_ES_CODE_NO_ERROR<br> 713 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 714 * @a AVRC_ES_CODE_UID_CHANGED<br> 715 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 716 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 717 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br> 718 * @a AVRC_ES_CODE_MEDIA_IN_USE<br> 719 * @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br> 720 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 721 */ 722 void OnAddToNowPlaying(const RawAddress &rawAddr, uint8_t label, int status) override; 723 724 /****************************************************************** 725 * OPERATE THE VIRTUAL FILE SYSTEM * 726 ******************************************************************/ 727 728 /** 729 * @brief Responds the data of the <b>ChangePath</b>. 730 * 731 * @details Switch to the thread of the AVRCP TG service in this function. 732 * @param[in] rawAddr The address of the bluetooth device. 733 * @param[in] numOfItems The number of items in the directory. 734 * @param[in] label The label which is used to distinguish different call. 735 * @param[in] status The status of the method execution. Refer to <b>AvrcEsCode</b>.<br> 736 * @a AVRC_ES_CODE_NO_ERROR<br> 737 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 738 * @a AVRC_ES_CODE_UID_CHANGED<br> 739 * @a AVRC_ES_CODE_INVALID_DIRECTION<br> 740 * @a AVRC_ES_CODE_NOT_A_DIRECTORY<br> 741 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 742 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 743 */ 744 void OnChangePath(const RawAddress &rawAddr, uint32_t numOfItems, uint8_t label, int status) override; 745 746 /** 747 * @brief Responds the data of the <b>GetFolderItems</b>. 748 * 749 * @details Switch to the thread of the AVRCP TG service in this function. 750 * @param[in] rawAddr The address of the bluetooth device. 751 * @param[in] uidCounter The value of the uid counter. 752 * @param[in] items The list of media player. 753 * @param[in] label The label which is used to distinguish different call. 754 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 755 * @a AVRC_ES_CODE_NO_ERROR<br> 756 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 757 * @a AVRC_ES_CODE_UID_CHANGED<br> 758 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 759 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 760 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 761 */ 762 void OnGetMediaPlayers(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMpItem> &items, 763 uint8_t label, int status) override; 764 765 /** 766 * @brief Responds the data of the <b>GetFolderItems</b>. 767 * 768 * @details Switch to the thread of the AVRCP TG service in this function. 769 * @param[in] rawAddr The address of the bluetooth device. 770 * @param[in] uidCounter The value of the uid counter. 771 * @param[in] items The list of media items. 772 * @param[in] label The label which is used to distinguish different call. 773 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 774 * @a AVRC_ES_CODE_NO_ERROR<br> 775 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 776 * @a AVRC_ES_CODE_UID_CHANGED<br> 777 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 778 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 779 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 780 */ 781 void OnGetFolderItems(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMeItem> &items, 782 uint8_t label, int status) override; 783 784 /** 785 * @brief Responds the data of the <b>GetItemAttributes</b>. 786 * 787 * @details Switch to the thread of the AVRCP TG service in this function. 788 * @param[in] rawAddr The address of the bluetooth device. 789 * @param[in] attributes The list of media attributes. 790 * @param[in] values The list of the value of this attribute. 791 * @param[in] label The label which is used to distinguish different call. 792 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 793 * @a AVRC_ES_CODE_NO_ERROR<br> 794 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 795 * @a AVRC_ES_CODE_UID_CHANGED<br> 796 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 797 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 798 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 799 */ 800 void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes, 801 const std::vector<std::string> &values, uint8_t label, int status) override; 802 803 /** 804 * @brief Responds the data of the <b>GetTotalNumberOfItems</b>. 805 * 806 * @details Switch to the thread of the AVRCP TG service in this function. 807 * @param[in] rawAddr The address of the bluetooth device. 808 * @param[in] uidCounter The value of the uid counter. 809 * @param[in] numOfItems The number of items in the directory. 810 * @param[in] label The label which is used to distinguish different call. 811 * @param[in] status The status of the method execution. Refer to <b>AvrcEsCode</b>.<br> 812 * @a AVRC_ES_CODE_NO_ERROR<br> 813 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 814 * @a AVRC_ES_CODE_UID_CHANGED<br> 815 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 816 */ 817 void OnGetTotalNumberOfItems( 818 const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, uint8_t label, int status) override; 819 820 /****************************************************************** 821 * ABSOLUTE VOLUME * 822 ******************************************************************/ 823 824 /** 825 * @brief Responds the data of the <b>SetAbsoluteVolume</b>. 826 * 827 * @details Switch to the thread of the AVRCP TG service in this function. 828 * @param[in] rawAddr The address of the bluetooth device. 829 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 830 * @param[in] label The label which is used to distinguish different call. 831 */ 832 void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, uint8_t label) override; 833 834 /****************************************************************** 835 * NOTIFICATION * 836 ******************************************************************/ 837 838 void OnGetSelectedTrack(const RawAddress &rawAddr, uint64_t uid, uint8_t label) override; 839 840 void OnGetAddressedPlayer( 841 const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label) override; 842 843 void OnGetUidCounter(const RawAddress &rawAddr, uint16_t uidCounter, uint8_t label) override; 844 845 void OnGetCurrentAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, uint8_t label) override; 846 847 /** 848 * @brief Notifies the playback status is changed. 849 * 850 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 851 * @param[in] playbackPos Current playback position in millisecond. 852 * @param[in] label The label which is used to distinguish different call. 853 */ 854 void NotifyPlaybackStatusChanged( 855 uint8_t playStatus, uint32_t playbackPos, uint8_t label = AVRC_DEFAULT_LABEL) override; 856 857 /** 858 * @brief Notifies the track reached end is changed. 859 * 860 * @param[in] uid The unique ID of media item. 861 * @param[in] playbackPos Current playback position in millisecond. 862 * @param[in] label The label which is used to distinguish different call. 863 */ 864 void NotifyTrackChanged(uint64_t uid, uint32_t playbackPos, uint8_t label = AVRC_DEFAULT_LABEL) override; 865 866 /** 867 * @brief Notifies the track reached end is changed. 868 * 869 * @param[in] playbackPos Current playback position in millisecond. 870 * @param[in] label The label which is used to distinguish different call. 871 */ 872 void NotifyTrackReachedEnd(uint32_t playbackPos, uint8_t label = AVRC_DEFAULT_LABEL) override; 873 874 /** 875 * @brief Notifies the track reached start is changed. 876 * 877 * @param[in] playbackPos Current playback position in millisecond. 878 * @param[in] label The label which is used to distinguish different call. 879 */ 880 void NotifyTrackReachedStart(uint32_t playbackPos, uint8_t label = AVRC_DEFAULT_LABEL) override; 881 882 /** 883 * @brief Notifies the player application setting is changed. 884 * 885 * @param[in] playbackPos Current playback position in millisecond. 886 * @param[in] label The label which is used to distinguish different call. 887 */ 888 void NotifyPlaybackPosChanged(uint32_t playbackPos, uint8_t label = AVRC_DEFAULT_LABEL) override; 889 890 /** 891 * @brief Notifies the player application setting is changed. 892 * 893 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 894 * @param[in] values The values associated witch the attribute. 895 * @param[in] label The label which is used to distinguish different call. 896 */ 897 void NotifyPlayerAppSettingChanged(const std::deque<uint8_t> &attributes, const std::deque<uint8_t> &values, 898 uint8_t label = AVRC_DEFAULT_LABEL) override; 899 900 /** 901 * @brief Notifies the now playing content is changed. 902 * 903 * @param[in] label The label which is used to distinguish different call. 904 */ 905 void NotifyNowPlayingContentChanged(uint8_t label = AVRC_DEFAULT_LABEL) override; 906 907 /** 908 * @brief Notifies the addressed player is changed. 909 * 910 * @param[in] label The label which is used to distinguish different call. 911 */ 912 void NotifyAvailablePlayersChanged(uint8_t label = AVRC_DEFAULT_LABEL) override; 913 914 /** 915 * @brief Notifies the addressed player is changed. 916 * 917 * @param[in] playerId The unique media player id. 918 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 919 * @param[in] label The label which is used to distinguish different call. 920 */ 921 void NotifyAddressedPlayerChanged( 922 uint16_t playerId, uint16_t uidCounter, uint8_t label = AVRC_DEFAULT_LABEL) override; 923 924 /** 925 * @brief Notifies the uids is changed. 926 * 927 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 928 * @param[in] label The label which is used to distinguish different call. 929 */ 930 void NotifyUidChanged(uint16_t uidCounter, uint8_t label = AVRC_DEFAULT_LABEL) override; 931 932 /** 933 * @brief Notifies the absolute volume is changed. 934 * 935 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 936 * @param[in] label The label which is used to distinguish different call. 937 */ 938 void NotifyVolumeChanged(uint8_t volume, uint8_t label = AVRC_DEFAULT_LABEL) override; 939 940 /** 941 * @brief Notifies the AVSession is created. 942 */ 943 void OnSessionCreate(std::string sessionId) override; 944 945 /** 946 * @brief Notifies the AVSession is released. 947 */ 948 void OnSessionRelease(std::string sessionId) override; 949 950 /** 951 * @brief Notifies the TopAVSession is changed. 952 */ 953 void OnTopSessionChange(std::string sessionId) override; 954 955 /** 956 * @brief Notifies the playback state is changed. 957 */ 958 void OnPlaybackStateChange(const int32_t state) override; 959 960 private: 961 /// The flag is used to indicate that the state of the AVRCP TG service. 962 std::atomic_uint8_t state_ {AVRC_TG_SERVICE_STATE_DISABLED}; 963 964 /// The maximum connection of device. 965 int maxConnection_ {AVRC_TG_DEFAULT_MAX_OF_CONN}; 966 /// current connection num. 967 int currentConn_ = 0; 968 969 /// The features supported by the AVRCP TG service. 970 uint16_t features_ {AVRC_TG_FEATURE_INVALID_FEATURE}; 971 972 /// using a local lock_guard to lock mutex guarantees unlocking on destruction / exception: 973 std::recursive_mutex mutex_ {}; 974 #ifdef AVRCP_AVSESSION 975 /// The pointer to the instance of the <b>SessionListener</b> struct. 976 std::shared_ptr<OHOS::AVSession::SessionListener> avSessionObserver_ {nullptr}; 977 978 /// The pointer to the instance of the <b>AVControllerCallback</b> struct. 979 std::shared_ptr<OHOS::AVSession::AVControllerCallback> avControllerObserver_ {nullptr}; 980 981 /// The instance of the <b>AVSessionDescriptor</b>. 982 std::vector<OHOS::AVSession::AVSessionDescriptor> avSessionDescriptor_ {}; 983 984 /// The pointer to the instance of the <b>AVSessionController</b> class. 985 std::shared_ptr<OHOS::AVSession::AVSessionController> avSessionController_ {nullptr}; 986 #endif 987 /// The unique pointer to the instance of the <b>stub::MedisService::IObserver</b> struct. 988 std::unique_ptr<stub::MediaService::IObserver> mdObserver_ {nullptr}; 989 990 /// The pointer to the instance of the <b>AvrcpTgService::IObserver</b> class. 991 IObserver *myObserver_ {nullptr}; 992 /// The unique pointer to the instance of the <b>AvrcTgProfile::Observer</b> struct. 993 std::unique_ptr<AvrcTgProfile::Observer> pfObserver_ {nullptr}; 994 995 /// The unique pointer to the instance of the <b>AvrcTgGapManager</b> class. 996 std::unique_ptr<AvrcTgGapManager> gapManager_ {nullptr}; 997 /// The unique pointer to the instance of the <b>AvrcTgSdpManager</b> class. 998 std::unique_ptr<AvrcTgSdpManager> sdpManager_ {nullptr}; 999 /// The unique pointer to the instance of the <b>AvrcTgProfile</b> class. 1000 std::unique_ptr<AvrcTgProfile> profile_ {nullptr}; 1001 1002 /****************************************************************** 1003 * ENABLE / DISABLE * 1004 ******************************************************************/ 1005 1006 /** 1007 * @brief Enables the AVRCP TG service. 1008 * 1009 * @return The result of the method execution. 1010 * @retval true Execute success. 1011 * @retval false Execute failure. 1012 */ 1013 void EnableNative(void); 1014 1015 /** 1016 * @brief Disables the AVRCP TG service. 1017 * 1018 * @return The result of the method execution. 1019 * @retval true Execute success. 1020 * @retval false Execute failure. 1021 */ 1022 void DisableNative(void); 1023 1024 #ifdef AVRCP_AVSESSION 1025 /** 1026 * @brief Registers AVSessionControl. 1027 * 1028 * @return void. 1029 */ 1030 void RegisterAvSessionControl(void); 1031 #endif 1032 1033 /** 1034 * @brief Registers security requirements into the GAP. 1035 * 1036 * @return The result of the method execution. 1037 * @retval BT_SUCCESS Execute success. 1038 * @retval RET_BAD_STATUS Execute failure. 1039 */ 1040 int RegisterSecurity(void); 1041 1042 /** 1043 * @brief Unregisters security requirements from the GAP. 1044 * 1045 * @return The result of the method execution. 1046 * @retval BT_SUCCESS Execute success. 1047 * @retval RET_BAD_STATUS Execute failure. 1048 */ 1049 int UnregisterSecurity(void); 1050 1051 /** 1052 * @brief Register a record of the AVRCP TG service into the SDP. 1053 * 1054 * @return The result of the method execution. 1055 * @retval BT_SUCCESS Execute success. 1056 * @retval RET_BAD_STATUS Execute failure. 1057 */ 1058 int RegisterService(void); 1059 1060 /** 1061 * @brief Unregister a record of the AVRCP TG service from the SDP. 1062 * 1063 * @return The result of the method execution. 1064 * @retval BT_SUCCESS Execute success. 1065 * @retval RET_BAD_STATUS Execute failure. 1066 */ 1067 int UnregisterService(void); 1068 1069 /** 1070 * @brief Enables the AVRCP TG profile. 1071 * 1072 * @return The result of the method execution. 1073 * @retval BT_SUCCESS Execute success. 1074 * @retval RET_BAD_STATUS Execute failure. 1075 */ 1076 int EnableProfile(void); 1077 1078 /** 1079 * @brief Disables the AVRCP TG profile. 1080 * 1081 * @return The result of the method execution. 1082 * @retval BT_SUCCESS Execute success. 1083 * @retval RET_BAD_STATUS Execute failure. 1084 */ 1085 int DisableProfile(void) const; 1086 1087 /** 1088 * @brief Informs that the AVRCP TG profile is disabled. 1089 * 1090 * @param[in] result The result of the method execution. 1091 */ 1092 void OnProfileDisabled(int result = BT_SUCCESS); 1093 1094 /** 1095 * @brief Checks whether the AVRCP TG service is disabled. 1096 * 1097 * @return The result of the method execution. 1098 * @retval true The service is disabled. 1099 * @retval false The service is not disabled. 1100 */ 1101 bool IsDisabled(void); 1102 1103 /** 1104 * @brief Sets the flag of the service enabled or not. 1105 * 1106 * @param[in] state The state of the service. 1107 */ 1108 void SetServiceState(uint8_t state); 1109 1110 void InitFeatures(); 1111 1112 /****************************************************************** 1113 * CONNECTION * 1114 ******************************************************************/ 1115 /** 1116 * @brief Connects to the AVRCP CT service. 1117 * 1118 * @param[in] rawAddr The address of the bluetooth device. 1119 */ 1120 void ConnectNative(RawAddress rawAddr); 1121 1122 /** 1123 * @brief Disconnects from the AVRCP TG service. 1124 * 1125 * @param[in] rawAddr The address of the bluetooth device. 1126 */ 1127 void DisconnectNative(RawAddress rawAddr); 1128 1129 /** 1130 * @brief Informs that the connection state is changed. 1131 * 1132 * @param[in] rawAddr The address of the bluetooth device. 1133 * @param[in] state The connection state. Refer to <b>BTConnectState</b>. 1134 */ 1135 void OnConnectionStateChanged(const RawAddress &rawAddr, int state); 1136 1137 /** 1138 * @brief Accepts the active connection. 1139 * 1140 * @param[in] rawAddr The address of the peer bluetooth device. 1141 */ 1142 void AcceptActiveConnect(const RawAddress &rawAddr); 1143 1144 /** 1145 * @brief Accepts the passive connection. 1146 * 1147 * @param[in] rawAddr The address of the bluetooth device. 1148 */ 1149 void AcceptPassiveConnect(const RawAddress &rawAddr); 1150 1151 /** 1152 * @brief Rejects the passive connection. 1153 * 1154 * @param[in] rawAddr The address of the bluetooth device. 1155 */ 1156 void RejectPassiveConnect(const RawAddress &rawAddr); 1157 1158 /** 1159 * @brief Finds the AVRCP TG record of the specified device. 1160 * 1161 * @param[in] rawAddr The address of the peer bluetooth device. 1162 */ 1163 void FindCtService(const RawAddress &rawAddr); 1164 1165 /** 1166 * @brief The callback function, which register into the SDP for receiving the search result. 1167 * 1168 * @param[in] btAddr The address of the peer Bluetooth device. 1169 * @param[in] handleArray The list of handle to a qualifying service. 1170 * @param[in] handleCount The number of handle to a qualifying service. 1171 * @param[in] context The context is used to send the event in the callback. 1172 */ 1173 static void FindCtServiceCallback( 1174 const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleCount, void *context); 1175 1176 /****************************************************************** 1177 * PASS THROUGH COMMAND * 1178 ******************************************************************/ 1179 1180 /** 1181 * @brief Informs that the button is pressed. 1182 * 1183 * @param[in] rawAddr The address of the bluetooth device. 1184 * @param[in] button The value of the key operation. 1185 * @param[in] label The label which is used to distinguish different call. 1186 */ 1187 void OnButtonPressed(const RawAddress &rawAddr, uint8_t button, uint8_t label) const; 1188 1189 /** 1190 * @brief Informs that the button is released. 1191 * 1192 * @param[in] rawAddr The address of the bluetooth device. 1193 * @param[in] button The value of the key operation. 1194 * @param[in] label The label which is used to distinguish different call. 1195 */ 1196 void OnButtonReleased(const RawAddress &rawAddr, uint8_t button, uint8_t label) const; 1197 1198 /** 1199 * @brief Informs that the button is held. 1200 * 1201 * @param[in] rawAddr The address of the bluetooth device. 1202 * @param[in] button The value of the key operation. 1203 * @param[in] label The label which is used to distinguish different call. 1204 */ 1205 void HoldButton(const RawAddress &rawAddr, uint8_t button, uint8_t label) const; 1206 1207 /****************************************************************** 1208 * Media Player Selection * 1209 ******************************************************************/ 1210 1211 /** 1212 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 1213 * 1214 * @param[in] rawAddr The address of the bluetooth device. 1215 * @param[in] playerId The unique media player id. 1216 * @param[in] uidCounter The value of the uid counter. 1217 * @param[in] label The label which is used to distinguish different call. 1218 * @return The result of the method execution. 1219 * @retval BT_SUCCESS Execute success. 1220 * @retval RET_NO_SUPPORT Not Support. 1221 * @retval RET_BAD_STATUS Execute failure. 1222 */ 1223 void SetAddressedPlayer(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label) const; 1224 1225 /** 1226 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 1227 * 1228 * @param[in] rawAddr The address of the bluetooth device. 1229 * @param[in] label The label which is used to distinguish different call. 1230 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1231 * @a AVRC_ES_CODE_NO_ERROR<br> 1232 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1233 * @a AVRC_ES_CODE_UID_CHANGED<br> 1234 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 1235 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1236 */ 1237 void OnSetAddressedPlayerNative(RawAddress rawAddr, uint8_t label, int status); 1238 1239 /** 1240 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 1241 * 1242 * @param[in] rawAddr The address of the bluetooth device. 1243 * @param[in] playerId The unique media player id. 1244 * @param[in] uidCounter The value of the uid counter. 1245 * @param[in] label The label which is used to distinguish different call. 1246 * @return The result of the method execution. 1247 * @retval BT_SUCCESS Execute success. 1248 * @retval RET_NO_SUPPORT Not Support. 1249 * @retval RET_BAD_STATUS Execute failure. 1250 */ 1251 void SetBrowsedPlayer(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label) const; 1252 1253 /** 1254 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 1255 * 1256 * @param[in] rawAddr The address of the bluetooth device. 1257 * @param[in] uidCounter The value of the uid counter. 1258 * @param[in] numOfItems The number of items in the directory. 1259 * @param[in] folderNames The current browsed path of the player. The first element in folderNames is the parent 1260 * folder. The root folder has no name. The names are in UTF-8. 1261 * @param[in] label The label which is used to distinguish different call. 1262 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1263 * @a AVRC_ES_CODE_NO_ERROR<br> 1264 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1265 * @a AVRC_ES_CODE_UID_CHANGED<br> 1266 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 1267 * @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br> 1268 * @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br> 1269 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1270 */ 1271 void OnSetBrowsedPlayerNative(RawAddress rawAddr, uint16_t uidCounter, uint32_t numOfItems, 1272 std::vector<std::string> folderNames, uint8_t label, int status); 1273 1274 /****************************************************************** 1275 * Capabilities * 1276 ******************************************************************/ 1277 1278 /** 1279 * @brief Get the capabilities supported by remote device. 1280 * 1281 * @details This is sent by CT to get the capabilities of the peer device. 1282 * @param[in] rawAddr The address of the bluetooth device. 1283 * @param[in] label The label which is used to distinguish different call. 1284 */ 1285 void GetCapabilities(const RawAddress &rawAddr, uint8_t label); 1286 1287 /****************************************************************** 1288 * PLAYER APPLICATION SETTINGS * 1289 ******************************************************************/ 1290 1291 /** 1292 * @brief Gets the attribute of the player application. 1293 * 1294 * @param[in] rawAddr The address of the bluetooth device. 1295 * @param[in] attributes The attribute of the player application setting. Refer to <b>AvrcPlayerAttributes</b>. 1296 * @param[in] label The label which is used to distinguish different call. 1297 */ 1298 void GetPlayerAppSettingAttributes(const RawAddress &rawAddr, uint8_t label) const; 1299 1300 /** 1301 * @brief Responds the data of the <b>GetPlayerAppSettingAttributes</b>. 1302 * 1303 * @param[in] rawAddr The address of the bluetooth device. 1304 * @param[in] attributes The attribute of the player application settings. 1305 * @param[in] label The label which is used to distinguish different call. 1306 */ 1307 void OnGetPlayerAppSettingAttributesNative(RawAddress rawAddr, std::deque<uint8_t> attributes, uint8_t label); 1308 1309 /** 1310 * @brief Gets the values of the specified attribute of the player application. 1311 * 1312 * @param[in] rawAddr The address of the bluetooth device. 1313 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 1314 * @param[in] label The label which is used to distinguish different call. 1315 */ 1316 void GetPlayerAppSettingValues(const RawAddress &rawAddr, uint8_t attribute, uint8_t label) const; 1317 1318 /** 1319 * @brief Responds the data of the <b>GetPlayerAppSettingValues</b>. 1320 * 1321 * @param[in] rawAddr The address of the bluetooth device. 1322 * @param[in] values The values associated witch the attribute. 1323 * @param[in] label The label which is used to distinguish different call. 1324 */ 1325 void OnGetPlayerAppSettingValuesNative(RawAddress rawAddr, std::deque<uint8_t> values, uint8_t label); 1326 1327 /** 1328 * @brief Gets the current set values on the target for the provided player application setting attributes list. 1329 * 1330 * @param[in] rawAddr The address of the bluetooth device. 1331 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 1332 * @param[in] label The label which is used to distinguish different call. 1333 * @param[in] context The context which is used to distinguish different purpose. 1334 */ 1335 void GetPlayerAppSettingCurrentValue( 1336 const RawAddress &rawAddr, const std::deque<uint8_t> &attributes, uint8_t label, uint8_t context) const; 1337 1338 /** 1339 * @brief Responds the data of the <b>GetCurrentPlayerAppSettingValue</b>. 1340 * 1341 * @param[in] rawAddr The address of the bluetooth device. 1342 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 1343 * @param[in] values The values associated witch the attribute. 1344 * @param[in] label The label which is used to distinguish different call. 1345 * @param[in] context The context which is used to distinguish different purpose. 1346 */ 1347 void OnGetCurrentPlayerAppSettingValueNative( 1348 RawAddress rawAddr, std::deque<uint8_t> attributes, std::deque<uint8_t> values, uint8_t label, uint8_t context); 1349 1350 /** 1351 * @brief Sets the player application setting list of player application setting values on the target device for the 1352 * corresponding defined list of AvrcPlayerAttribute. 1353 * 1354 * @param[in] rawAddr The address of the bluetooth device. 1355 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 1356 * @param[in] values The value of the player application setting attribute. 1357 * @param[in] label The label which is used to distinguish different call. 1358 */ 1359 void SetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::deque<uint8_t> &attributes, 1360 const std::deque<uint8_t> &values, uint8_t label) const; 1361 1362 /** 1363 * @brief Responds the data of the <b>SetPlayerAppSettingCurrentValue</b>. 1364 * 1365 * @param[in] rawAddr The address of the bluetooth device. 1366 * @param[in] label The label which is used to distinguish different call. 1367 */ 1368 void OnSetPlayerAppSettingCurrentValueNative(RawAddress rawAddr, uint8_t label); 1369 1370 /** 1371 * @@brief provide supported player application setting attribute displayable text. 1372 * 1373 * @param[in] rawAddr The address of the bluetooth device. 1374 * @param[in] attributes The attribute of the player application settings. 1375 * @param[in] label The label which is used to distinguish different call. 1376 */ 1377 void GetPlayerAppSettingAttributeText( 1378 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, uint8_t label) const; 1379 1380 /** 1381 * @brief Responds the data of the <b>GetPlayerAppSettingAttributeText</b>. 1382 * 1383 * @param[in] rawAddr The address of the bluetooth device. 1384 * @param[in] attributes The attribute of the player application settings. 1385 * @param[in] attrStr The values associated witch the attribute. 1386 * @param[in] label The label which is used to distinguish different call. 1387 */ 1388 void OnGetPlayerAppSettingAttributeTextNative( 1389 RawAddress rawAddr, std::vector<uint8_t> attributes, std::vector<std::string> attrStr, uint8_t label); 1390 1391 /** 1392 * @@brief provide supported player application setting attribute displayable text. 1393 * 1394 * @param[in] rawAddr The address of the bluetooth device. 1395 * @param[in] attributes The attribute of the player application settings. 1396 * @param[in] label The label which is used to distinguish different call. 1397 */ 1398 void GetPlayerAppSettingValueText( 1399 const RawAddress &rawAddr, uint8_t attributeId, const std::vector<uint8_t> &values, uint8_t label) const; 1400 1401 /** 1402 * @brief Responds the data of the <b>GetPlayerAppSettingValueText</b>. 1403 * 1404 * @param[in] addr The address of the bluetooth device. 1405 * @param[in] values Player application setting value ID. 1406 * @param[in] valueStr Specifies the value string of player application setting value. 1407 * @param[in] label The label which is used to distinguish different call. 1408 */ 1409 void OnGetPlayerAppSettingValueTextNative( 1410 RawAddress rawAddr, std::vector<uint8_t> values, std::vector<std::string> valueStr, uint8_t label); 1411 1412 /****************************************************************** 1413 * MEDIA INFORMATION PDUS * 1414 ******************************************************************/ 1415 1416 /** 1417 * @brief Requests the TG to provide the attributes of the element specified in the parameter. 1418 * 1419 * @details Switch to the thread of the AVRCP CT service in this function. 1420 * @param[in] rawAddr The address of the bluetooth device. 1421 * @param[in] identifier Unique identifier to identify an element on TG 1422 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved 1423 * @param[in] label The label which is used to distinguish different call. 1424 */ 1425 void GetElementAttributes( 1426 const RawAddress &rawAddr, uint64_t identifier, const std::vector<uint32_t> &attributes, uint8_t label) const; 1427 1428 /** 1429 * @brief Responds the data of the <b>GetElementAttributes</b>. 1430 * 1431 * @details Switch to the thread of the AVRCP CT service in this function. 1432 * @param[in] rawAddr The address of the bluetooth device. 1433 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved. 1434 * @param[in] values The list of the value of this attribute. 1435 * @param[in] label The label which is used to distinguish different call. 1436 */ 1437 void OnGetElementAttributesNative( 1438 RawAddress rawAddr, std::vector<uint32_t> attributes, std::vector<std::string> values, uint8_t label); 1439 1440 /****************************************************************** 1441 * PLAY * 1442 ******************************************************************/ 1443 1444 /** 1445 * @brief Gets the play status. 1446 * 1447 * @param[in] rawAddr The address of the bluetooth device. 1448 * @param[in] label The label which is used to distinguish different call. 1449 * @param[in] context The context which is used to distinguish different purpose. 1450 */ 1451 void GetPlayStatus(const RawAddress &rawAddr, uint8_t label, uint8_t context) const; 1452 1453 /** 1454 * @brief Responds the data of the <b>GetPlayStatus</b>. 1455 * 1456 * @param[in] rawAddr The address of the bluetooth device. 1457 * @param[in] songLength The total length of the playing song in milliseconds. 1458 * @param[in] songPosition The current position of the playing in milliseconds elapsed. 1459 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 1460 * @param[in] label The label which is used to distinguish different call. 1461 * @param[in] context The context which is used to distinguish different purpose. 1462 */ 1463 void OnGetPlayStatusNative(RawAddress rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, 1464 uint8_t label, uint8_t context); 1465 1466 /** 1467 * @brief Informs that receive the command of the <b>PlayItem</b>. 1468 * 1469 * @param[in] rawAddr The address of the bluetooth device. 1470 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1471 * @param[in] uid The UID of the media element item or folder item. 1472 * @param[in] uidCounter The UID Counter. 1473 * @param[in] label The label which is used to distinguish different call. 1474 */ 1475 void PlayItem(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, uint8_t label) const; 1476 1477 /** 1478 * @brief Sends the response of the <b>PlayItem</b>. 1479 * 1480 * @param[in] rawAddr The address of the bluetooth device. 1481 * @param[in] label The label which is used to distinguish different call. 1482 * @param[in] status The current status of media. 1483 * @a AVRC_ES_CODE_INVALID_COMMAND<br> 1484 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1485 * @a AVRC_ES_CODE_INVALID_PARAMETER<br> 1486 * @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br> 1487 * @a AVRC_ES_CODE_NO_ERROR<br> 1488 * @a AVRC_ES_CODE_UID_CHANGED<br> 1489 * @a AVRC_ES_CODE_RESERVED<br> 1490 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1491 * @a AVRC_ES_CODE_INVALID_SCOPE 1492 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 1493 * @a AVRC_ES_CODE_MEDIA_IN_USE 1494 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1495 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 1496 */ 1497 void OnPlayItemNative(RawAddress rawAddr, uint8_t label, int status); 1498 1499 /** 1500 * @brief Adds an item indicated by the UID to the Now Playing queue. 1501 * 1502 * @param[in] rawAddr The address of the bluetooth device. 1503 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1504 * @param[in] uid The UID of the media element item or folder item. 1505 * @param[in] uidCounter The UID Counter. 1506 * @param[in] label The label which is used to distinguish different call. 1507 */ 1508 void AddToNowPlaying(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, 1509 uint8_t label) const; 1510 1511 /** 1512 * @brief Responds the data of the <b>AddToNowPlaying</b>. 1513 * 1514 * @param[in] rawAddr The address of the bluetooth device. 1515 * @param[in] label The label which is used to distinguish different call. 1516 * @param[in] status The status of the method execution. Refer to <b>AvrcEsCode</b>.<br> 1517 * @a AVRC_ES_CODE_NO_ERROR<br> 1518 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1519 * @a AVRC_ES_CODE_UID_CHANGED<br> 1520 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1521 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1522 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br> 1523 * @a AVRC_ES_CODE_MEDIA_IN_USE<br> 1524 * @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br> 1525 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1526 */ 1527 void OnAddToNowPlayingNative(RawAddress rawAddr, uint8_t label, int status); 1528 1529 /****************************************************************** 1530 * OPERATE THE VIRTUAL FILE SYSTEM * 1531 ******************************************************************/ 1532 1533 /** 1534 * @brief Navigates one level up or down in the virtual file system. 1535 * 1536 * @param[in] rawAddr The address of the bluetooth device. 1537 * @param[in] uidCounter The value of the uid counter. 1538 * @param[in] direction The flag of the navigation. Refer to <b>bluetooth::AvrcFolderDirection</b>. 1539 * @param[in] folderUid The UID of the folder to navigate to. This may be retrieved via a GetFolderItems command. 1540 * If the navigation command is Folder Up this field is reserved. 1541 * @param[in] label The label which is used to distinguish different call. 1542 */ 1543 void ChangePath( 1544 const RawAddress &rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid, uint8_t label) const; 1545 1546 /** 1547 * @brief Responds the data of the <b>ChangePath</b>. 1548 * 1549 * @param[in] rawAddr The address of the bluetooth device. 1550 * @param[in] numOfItems The number of items in the directory. 1551 * @param[in] label The label which is used to distinguish different call. 1552 * @param[in] status The status of the method execution. Refer to <b>AvrcEsCode</b>.<br> 1553 * @a AVRC_ES_CODE_INTERNAL_ERROR : Internal Error.<br> 1554 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1555 * @a AVRC_ES_CODE_UID_CHANGED : The UID is changed<br> 1556 * @a AVRC_ES_CODE_INVALID_DIRECTION : The Direction parameter is invalid.<br> 1557 * @a AVRC_ES_CODE_NOT_A_DIRECTORY : The UID provided does not refer to a folder item.<br> 1558 * @a AVRC_ES_CODE_DOES_NOT_EXIST : The UID provided does not refer to any currently valid 1559 * item.<br> 1560 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS : No available players. 1561 */ 1562 void OnChangePathNative(RawAddress rawAddr, uint32_t numOfItems, uint8_t label, int status); 1563 1564 /** 1565 * @brief Retrieves a listing of the contents of a folder. 1566 * 1567 * @param[in] rawAddr The address of the bluetooth device. 1568 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1569 * @param[in] startItem The offset within the listing of the item, which should be the first returned item. The 1570 * first element in the listing is at offset 0. 1571 * @param[in] endItem The offset within the listing of the item which should be the final returned item. If this 1572 * is set to a value beyond what is available, the TG shall return items from the provided Start Item index to the 1573 * index of the final item. If the End Item index is smaller than the Start Item index, the TG shall return an 1574 * error. If CT requests too many items, TG can respond with a sub-set of the requested items. 1575 * @param[in] attributes The list of media attributes. 1576 * @param[in] label The label which is used to distinguish different call. 1577 * @return The result of the method execution. 1578 * @retval BT_SUCCESS Execute success. 1579 * @retval RET_NO_SUPPORT Not support. 1580 * @retval RET_BAD_STATUS Execute failure. 1581 */ 1582 void GetFolderItems(const RawAddress &rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem, 1583 const std::vector<uint32_t> &attributes, uint8_t label) const; 1584 1585 /** 1586 * @brief Responds the data of the <b>GetFolderItems</b>. 1587 * 1588 * @details Switch to the thread of the AVRCP TG service in this function. 1589 * @param[in] rawAddr The address of the bluetooth device. 1590 * @param[in] uidCounter The value of the uid counter. 1591 * @param[in] items The list of media player. 1592 * @param[in] label The label which is used to distinguish different call. 1593 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1594 * @a AVRC_ES_CODE_NO_ERROR<br> 1595 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1596 * @a AVRC_ES_CODE_UID_CHANGED<br> 1597 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1598 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1599 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1600 */ 1601 void OnGetMediaPlayersNative( 1602 RawAddress rawAddr, uint16_t uidCounter, std::vector<AvrcMpItem> items, uint8_t label, int status); 1603 1604 /** 1605 * @brief Responds the data of the <b>GetFolderItems</b>. 1606 * 1607 * @details Switch to the thread of the AVRCP TG service in this function. 1608 * @param[in] rawAddr The address of the bluetooth device. 1609 * @param[in] uidCounter The value of the uid counter. 1610 * @param[in] items The list of media items. 1611 * @param[in] label The label which is used to distinguish different call. 1612 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1613 * @a AVRC_ES_CODE_NO_ERROR<br> 1614 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1615 * @a AVRC_ES_CODE_UID_CHANGED<br> 1616 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1617 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1618 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1619 */ 1620 void OnGetFolderItemsNative( 1621 RawAddress rawAddr, uint16_t uidCounter, std::vector<AvrcMeItem> items, uint8_t label, int status); 1622 1623 /** 1624 * @brief Retrieves the metadata attributes for a particular media element item or folder item. 1625 * 1626 * @param[in] rawAddr The address of the bluetooth device. 1627 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1628 * @param[in] uid The UID of the media element item or folder item. 1629 * @param[in] uidCounter The UID Counter. 1630 * @param[in] attributes The list of media attributes. 1631 * @param[in] label The label which is used to distinguish different call. 1632 */ 1633 void GetItemAttributes(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, 1634 std::vector<uint32_t> attributes, uint8_t label) const; 1635 1636 /** 1637 * @brief Responds the data of the <b>GetItemAttributes</b>. 1638 * 1639 * @param[in] rawAddr The address of the bluetooth device. 1640 * @param[in] attributes The list of media attributes. 1641 * @param[in] values The list of the value of this attribute. 1642 * @param[in] label The label which is used to distinguish different call. 1643 * @param[in] status The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1644 * @a AVRC_ES_CODE_NO_ERROR<br> 1645 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1646 * @a AVRC_ES_CODE_UID_CHANGED<br> 1647 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1648 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1649 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1650 */ 1651 void OnGetItemAttributesNative(RawAddress rawAddr, std::vector<uint32_t> attributes, 1652 std::vector<std::string> values, uint8_t label, int status); 1653 1654 /** 1655 * @brief Gets the number of items in the selected folder at the selected scope. 1656 * 1657 * @param[in] rawAddr The address of the bluetooth device. 1658 * @param[in] scope The scope in which media content navigation may take place. Refer to 1659 * <b>AvrcMediaScope</b>. 1660 * @param[in] label The label which is used to distinguish different call. 1661 */ 1662 void GetTotalNumberOfItems(const RawAddress &rawAddr, uint8_t scope, uint8_t label) const; 1663 1664 /** 1665 * @brief Responds the data of the <b>GetTotalNumberOfItems</b>. 1666 * 1667 * @param[in] rawAddr The address of the bluetooth device. 1668 * @param[in] uidCounter The value of the uid counter. 1669 * @param[in] numOfItems The number of items in the directory. 1670 * @param[in] label The label which is used to distinguish different call. 1671 * @param[in] response The response of calling the <b>ChangePath</b>.<br> 1672 * @a AVRC_ES_CODE_INTERNAL_ERROR : Internal Error.<br> 1673 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1674 * @a AVRC_ES_CODE_UID_CHANGED : The UID is changed<br> 1675 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS : No available players. 1676 */ 1677 void OnGetTotalNumberOfItemsNative( 1678 RawAddress rawAddr, uint16_t uidCounter, uint32_t numOfItems, uint8_t label, int status); 1679 1680 /****************************************************************** 1681 * ABSOLUTE VOLUME * 1682 ******************************************************************/ 1683 1684 /** 1685 * @brief Sets an absolute volume to be used by the rendering device. 1686 * 1687 * @param[in] rawAddr The address of the bluetooth device. 1688 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1689 * @param[in] label The label which is used to distinguish different call. 1690 */ 1691 void SetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, uint8_t label) const; 1692 1693 /** 1694 * @brief Responds the data of the <b>SetAbsoluteVolume</b>. 1695 * 1696 * @param[in] rawAddr The address of the bluetooth device. 1697 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1698 * @param[in] label The label which is used to distinguish different call. 1699 */ 1700 void OnSetAbsoluteVolumeNative(RawAddress rawAddr, uint8_t volume, uint8_t label); 1701 1702 /****************************************************************** 1703 * NOTIFICATION * 1704 ******************************************************************/ 1705 1706 /** 1707 * @brief Responds the command of the <b>EVENT_TRACK_CHANGED</b>. 1708 * 1709 * @param[in] rawAddr The address of the bluetooth device. 1710 * @param[in] label The label which is used to distinguish different call. 1711 */ 1712 void GetSelectedTrack(const RawAddress &rawAddr, uint8_t label) const; 1713 1714 void OnGetSelectedTrackNative(RawAddress rawAddr, uint64_t uid, uint8_t label); 1715 1716 /** 1717 * @brief Responds the command of the <b>EVENT_ADDRESSED_PLAYER_CHANGED</b>. 1718 * 1719 * @param[in] rawAddr The address of the bluetooth device. 1720 * @param[in] label The label which is used to distinguish different call. 1721 */ 1722 void GetAddressedPlayer(const RawAddress &rawAddr, uint8_t label) const; 1723 1724 void OnGetAddressedPlayerNative(RawAddress rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label); 1725 1726 void GetUidCounter(const RawAddress &rawAddr, uint8_t label) const; 1727 1728 void OnGetUidCounterNative(const RawAddress &rawAddr, uint16_t uidCounter, uint8_t label); 1729 1730 void GetCurrentAbsoluteVolume(const RawAddress &rawAddr, uint8_t label)const; 1731 1732 void OnGetCurrentAbsoluteVolumeNative(const RawAddress &rawAddr, uint8_t volume, uint8_t label); 1733 1734 /** 1735 * AVSession 1736 */ 1737 void OnPlaybackStateChangeNative(int32_t state); 1738 1739 /** 1740 * @brief Notifies the playback status is changed. 1741 * 1742 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 1743 * @param[in] playbackPos Current playback position in millisecond. 1744 * @param[in] label The label which is used to distinguish different call. 1745 */ 1746 void NotifyPlaybackStatusChangedNative(uint8_t playStatus, uint32_t playbackPos, uint8_t label); 1747 1748 /** 1749 * @brief Notifies the track reached end is changed. 1750 * 1751 * @param[in] uid The unique ID of media item. 1752 * @param[in] playbackPos Current playback position in millisecond. 1753 * @param[in] label The label which is used to distinguish different call. 1754 */ 1755 void NotifyTrackChangedNative(uint64_t uid, uint32_t playbackPos, uint8_t label); 1756 1757 /** 1758 * @brief Notifies the track reached end is changed. 1759 * 1760 * @param[in] playbackPos Current playback position in millisecond. 1761 * @param[in] label The label which is used to distinguish different call. 1762 */ 1763 void NotifyTrackReachedEndNative(uint32_t playbackPos, uint8_t label); 1764 1765 /** 1766 * @brief Notifies the track reached start is changed. 1767 * 1768 * @param[in] playbackPos Current playback position in millisecond. 1769 * @param[in] label The label which is used to distinguish different call. 1770 */ 1771 void NotifyTrackReachedStartNative(uint32_t playbackPos, uint8_t label); 1772 1773 /** 1774 * @brief Notifies the player application setting is changed. 1775 * 1776 * @param[in] playbackPos Current playback position in millisecond. 1777 * @param[in] label The label which is used to distinguish different call. 1778 */ 1779 void NotifyPlaybackPosChangedNative(uint32_t playbackPos, uint8_t label); 1780 1781 /** 1782 * @brief Notifies the player application setting is changed. 1783 * 1784 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 1785 * @param[in] values The values associated witch the attribute. 1786 * @param[in] label The label which is used to distinguish different call. 1787 */ 1788 void NotifyPlayerAppSettingChangedNative(std::deque<uint8_t> attributes, std::deque<uint8_t> values, uint8_t label); 1789 1790 /** 1791 * @brief Notifies the now playing content is changed. 1792 * 1793 * @param[in] label The label which is used to distinguish different call. 1794 */ 1795 void NotifyNowPlayingContentChangedNative(uint8_t label); 1796 1797 /** 1798 * @brief Notifies the addressed player is changed. 1799 * 1800 * @param[in] label The label which is used to distinguish different call. 1801 */ 1802 void NotifyAvailablePlayersChangedNative(uint8_t label); 1803 1804 /** 1805 * @brief Notifies the addressed player is changed. 1806 * 1807 * @param[in] playerId The unique media player id. 1808 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 1809 * @param[in] label The label which is used to distinguish different call. 1810 */ 1811 void NotifyAddressedPlayerChangedNative(uint16_t playerId, uint16_t uidCounter, uint8_t label); 1812 1813 /** 1814 * @brief Notifies the uids is changed. 1815 * 1816 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 1817 * @param[in] label The label which is used to distinguish different call. 1818 */ 1819 void NotifyUidChangedNative(uint16_t uidCounter, uint8_t label); 1820 1821 /** 1822 * @brief Notifies the absolute volume is changed. 1823 * 1824 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1825 * @param[in] label The label which is used to distinguish different call. 1826 */ 1827 void NotifyVolumeChangedNative(uint8_t volume, uint8_t label); 1828 1829 /** 1830 * @brief Sets the specified the time interval(in seconds). 1831 * 1832 * @param[in] rawAddr The address of the bluetooth device. 1833 * @param[in] interval The specifies the time interval (in seconds) at which the change in playback position 1834 * will be notified. If the song is being forwarded / rewound, a notification will be received whenever the 1835 * playback position will change by this value. 1836 */ 1837 void SetPlaybackInterval(const RawAddress &rawAddr, uint32_t interval) const; 1838 1839 /** 1840 * @brief Processes events received from the AVCTP. 1841 * 1842 * @param[in] rawAddr The address of the bluetooth device. 1843 * @param[in] connectId The ID of the connection. 1844 * @param[in] event The event from the underlying module. 1845 * @param[in] result The result of the event. 1846 * @param[in] context The context is used to send the event in the callback. 1847 */ 1848 void ProcessChannelEvent(RawAddress rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context); 1849 1850 /** 1851 * @brief Processes messages received from the AVCTP. 1852 * 1853 * @param[in] connectId The ID of the connection. 1854 * @param[in] label The label used to distinguish between different calls to the same function. 1855 * @param[in] crType The type used to distinguish between the command frame and the response frame. 1856 * @param[in] chType The type used to distinguish the message returned from the control channel or the browse 1857 * channel. 1858 * @param[in] pkt The message sent by the peer bluetooth device. 1859 * @param[in] context The context is used to send the message in the callback. 1860 */ 1861 void ProcessChannelMessage( 1862 uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context); 1863 1864 /** 1865 * @brief The callback function for receiving the events, which register into the AVCTP. 1866 * 1867 * @detail This function is the callback function registered into the AVCTP. 1868 * @param[in] connectId The ID of the connection. 1869 * @param[in] event The event from the underlying module. 1870 * @param[in] result The result of the event. 1871 * @param[in] btAddr The address of the bluetooth device. 1872 * @param[in] context The context is used to send the event in the callback. 1873 */ 1874 static void ChannelEventCallback( 1875 uint8_t connectId, uint8_t event, uint16_t result, const BtAddr *btAddr, void *context); 1876 1877 /** 1878 * @brief The callback function for receiving the messages, which register into the AVCTP. 1879 * 1880 * @param[in] connectId The ID of the connection. 1881 * @param[in] label The label used to distinguish between different calls to the same function. 1882 * @param[in] crType The type used to distinguish between the command frame and the response frame. 1883 * @param[in] chType The type used to distinguish the message returned from the control channel or the browse 1884 * channel. 1885 * @param[in] pkt The message sent by the peer bluetooth device. 1886 * @param[in] context The context is used to send the message in the callback. 1887 */ 1888 static void ChannelMessageCallback( 1889 uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context); 1890 1891 bool CheckConnectionNum(); 1892 DecConnectionNum()1893 inline void DecConnectionNum() 1894 { 1895 if (currentConn_-- < 0) { 1896 currentConn_ = 0; 1897 } 1898 } 1899 1900 uint8_t ConvertPlayState(const int32_t state) const; 1901 1902 BT_DISALLOW_COPY_AND_ASSIGN(AvrcpTgService); 1903 }; 1904 } // namespace bluetooth 1905 } // namespace OHOS 1906 1907 #endif // !AVRCP_TG_SERVICE_H 1908