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_CT_SERVICE_H 17 #define AVRCP_CT_SERVICE_H 18 19 #include <atomic> 20 21 #include "bt_def.h" 22 #include "context.h" 23 #include "interface_profile_avrcp_ct.h" 24 25 #include "avrcp_ct_gap.h" 26 #include "avrcp_ct_internal.h" 27 #include "avrcp_ct_profile.h" 28 #include "avrcp_ct_sdp.h" 29 30 namespace OHOS { 31 namespace bluetooth { 32 /** 33 * @brief This enumeration declares the states of the AVRCP TG service. 34 */ 35 enum AvrcCtServiceState : uint8_t { 36 AVRC_CT_SERVICE_STATE_INVALID, 37 AVRC_CT_SERVICE_STATE_ENABLING, 38 AVRC_CT_SERVICE_STATE_ENABLED, 39 AVRC_CT_SERVICE_STATE_DISABLING, 40 AVRC_CT_SERVICE_STATE_DISABLED, 41 }; 42 43 /** 44 * @brief This class provides a set of methods related to the role of the controller described in the Audio/Video Remote 45 * Control profile. 46 */ 47 class AvrcpCtService : public IProfileAvrcpCt, public utility::Context { 48 public: 49 /** 50 * @brief A constructor used to create an <b>AvrcpCtService</b> instance. 51 */ 52 AvrcpCtService(); 53 54 /** 55 * @brief A destructor used to delete the <b>AvrcpCtService</b> instance. 56 */ 57 ~AvrcpCtService(); 58 59 utility::Context *GetContext() override; 60 61 /****************************************************************** 62 * REGISTER / UNREGISTER OBSERVER * 63 ******************************************************************/ 64 65 /** 66 * @brief Registers the observer. 67 * 68 * @param observer The instance of the struct <b>IProfileAvrcpCt::Observer</b>. 69 */ 70 void RegisterObserver(IObserver *observer) override; 71 72 /** 73 * @brief Unregisters the observer. 74 */ 75 void UnregisterObserver(void) override; 76 77 /****************************************************************** 78 * ENABLE / DISABLE * 79 ******************************************************************/ 80 81 /** 82 * @brief Enables the AVRCP CT service. 83 * 84 * @details Switch to the thread of the AVRCP CT service in this method. 85 * @return The result of the method execution. 86 * @retval true Execute success. 87 * @retval false Execute failure. 88 */ 89 void Enable(void) override; 90 91 /** 92 * @brief Disables the AVRCP CT service. 93 * 94 * @detail Switch to the thread of the AVRCP CT service in this method. 95 * @return The result of the method execution. 96 * @retval true Execute success. 97 * @retval false Execute failure. 98 */ 99 void Disable(void) override; 100 101 /** 102 * @brief Checks whether the AVRCP CT service is enabled. 103 * 104 * @return The result of the method execution. 105 * @retval true The service is enabled. 106 * @retval false The service is disabled. 107 */ 108 bool IsEnabled(void) override; 109 110 /****************************************************************** 111 * CONNECTION * 112 ******************************************************************/ 113 114 /** 115 * @brief Useless. 116 */ GetConnectDevices(void)117 std::list<RawAddress> GetConnectDevices(void) override 118 { 119 std::list<RawAddress> rawAddrs; 120 return rawAddrs; 121 } 122 123 /** 124 * @brief Gets the connected devices. 125 * 126 * @return The list of the instance of the <b>RawAddress</b> class. 127 */ 128 std::vector<RawAddress> GetConnectedDevices(void) override; 129 130 /** 131 * @brief Gets the devices of the specified states. 132 * 133 * @param[in] states The connection states. Refer to <b>BTConnectState</b>. 134 * @return The list of the instance of the <b>RawAddress</b> class. 135 */ 136 std::vector<RawAddress> GetDevicesByStates(const std::vector<int> &states) override; 137 138 /** 139 * @brief Gets the connection state of the specified bluetooth device. 140 * 141 * @param[in] rawAddr The address of the bluetooth device. 142 * @return The connection state. Refer to <b>BTConnectState</b>. 143 */ 144 int GetDeviceState(const RawAddress &rawAddr) override; 145 146 /** 147 * @brief Gets the max number of the connection. 148 * 149 * @return The max number of the connection. 150 */ 151 int GetMaxConnectNum(void) override; 152 153 /** 154 * @brief Connects to the AVRCP TG service. 155 * 156 * @details Switch to the thread of the AVRCP CT service in this method. 157 * @param[in] rawAddr The address of the bluetooth device. 158 * @return The result of the method execution. 159 * @retval RET_NO_ERROR Execute success. 160 * @retval RET_NO_SUPPORT Not support. 161 * @retval RET_BAD_STATUS Execute failure. 162 */ 163 int Connect(const RawAddress &rawAddr) override; 164 165 /** 166 * @brief Disconnects from the AVRCP TG service. 167 * 168 * @details Switch to the thread of the AVRCP CT service in this method. 169 * @param[in] rawAddr The address of the bluetooth device. 170 * @return The result of the method execution. 171 * @retval RET_NO_ERROR Execute success. 172 * @retval RET_NO_SUPPORT Not support. 173 * @retval RET_BAD_STATUS Execute failure. 174 */ 175 int Disconnect(const RawAddress &rawAddr) override; 176 177 /** 178 * @brief Gets the connect states. 179 * 180 * @return The connect states. 181 */ 182 int GetConnectState(void) override; 183 184 /****************************************************************** 185 * BUTTON OPERATION * 186 ******************************************************************/ 187 188 /** 189 * @brief Presses the button. 190 * 191 * @details Switch to the thread of the AVRCP CT service in this method. 192 * @param[in] rawAddr The address of the bluetooth device. 193 * @param[in] button The value of the key operation. Refer to <b>AvrcKeyOperation</b> 194 * @return The result of the method execution. 195 * @retval RET_NO_ERROR Execute success. 196 * @retval RET_NO_SUPPORT Not support. 197 * @retval RET_BAD_STATUS Execute failure. 198 */ 199 int PressButton(const RawAddress &rawAddr, uint8_t button) override; 200 201 /** 202 * @brief Releases the button. 203 * 204 * @details Switch to the thread of the AVRCP CT service in this method. 205 * @param[in] rawAddr The address of the bluetooth device. 206 * @param[in] button The value of the key operation. Refer to <b>AvrcKeyOperation</b> 207 * @return The result of the method execution. 208 * @retval RET_NO_ERROR Execute success. 209 * @retval RET_NO_SUPPORT Not support. 210 * @retval RET_BAD_STATUS Execute failure. 211 */ 212 int ReleaseButton(const RawAddress &rawAddr, uint8_t button) override; 213 214 /****************************************************************** 215 * UNIT INFO / SUB UNIT INFO * 216 ******************************************************************/ 217 218 /** 219 * @brief Gets the unit information. 220 * 221 * @details Switch to the thread of the AVRCP CT service in this method. 222 * @param[in] rawAddr The address of the bluetooth device. 223 * @return The result of the method execution. 224 * @retval RET_NO_ERROR Execute success. 225 * @retval RET_NO_SUPPORT Not support. 226 * @retval RET_BAD_STATUS Execute failure. 227 */ 228 int GetUnitInfo(const RawAddress &rawAddr) override; 229 230 /** 231 * @brief Gets the sub unit information. 232 * 233 * @details Switch to the thread of the AVRCP CT service in this method. 234 * @param[in] rawAddr The address of the bluetooth device. 235 * @return The result of the method execution. 236 * @retval RET_NO_ERROR Execute success. 237 * @retval RET_NO_SUPPORT Not support. 238 * @retval RET_BAD_STATUS Execute failure. 239 */ 240 int GetSubUnitInfo(const RawAddress &rawAddr) override; 241 242 /****************************************************************** 243 * Media Player Selection * 244 ******************************************************************/ 245 246 /** 247 * @brief Informs to which media player wishes to control. 248 * 249 * @details Switch to the thread of the AVRCP CT service in this method. 250 * @param[in] rawAddr The address of the bluetooth device. 251 * @param[in] playerId The unique media player id. 252 * @return The result of the method execution. 253 * @retval RET_NO_ERROR Execute success. 254 * @retval RET_NO_SUPPORT Not Support. 255 * @retval RET_BAD_STATUS Execute failure. 256 */ 257 int SetAddressedPlayer(const RawAddress &rawAddr, uint16_t playerId) override; 258 259 /** 260 * @brief Informs to which player browsing commands should be routed. 261 * 262 * @details Switch to the thread of the AVRCP CT service in this method. 263 * @param[in] rawAddr The address of the bluetooth device. 264 * @param[in] playerId The unique media player id. 265 * @return The result of the method execution. 266 * @retval RET_NO_ERROR Execute success. 267 * @retval RET_NO_SUPPORT Not Support. 268 * @retval RET_BAD_STATUS Execute failure. 269 */ 270 int SetBrowsedPlayer(const RawAddress &rawAddr, uint16_t playerId) override; 271 272 /****************************************************************** 273 * Capabilities * 274 ******************************************************************/ 275 276 /** 277 * @brief Get the supported companies by remote device. 278 * 279 * @details This is sent by CT to get the capabilities of the peer device. 280 * @param[in] rawAddr The address of the bluetooth device. 281 * @param[in] capabilityId Specific capability requested. 282 * @return The result of the method execution. 283 * @retval RET_NO_ERROR Execute success. 284 * @retval RET_NO_SUPPORT Not Support. 285 * @retval RET_BAD_STATUS Execute failure. 286 */ 287 int GetSupportedCompanies(const RawAddress &rawAddr) override; 288 289 /** 290 * @brief Get the supported events by remote device. 291 * 292 * @details This is sent by CT to get the capabilities of the peer device. 293 * @param[in] rawAddr The address of the bluetooth device. 294 * @param[in] capabilityId Specific capability requested. 295 * @return The result of the method execution. 296 * @retval RET_NO_ERROR Execute success. 297 * @retval RET_NO_SUPPORT Not Support. 298 * @retval RET_BAD_STATUS Execute failure. 299 */ 300 int GetSupportedEvents(const RawAddress &rawAddr) override; 301 302 /****************************************************************** 303 * PLAYER APPLICATION SETTINGS * 304 ******************************************************************/ 305 306 /** 307 * @brief Gets the attribute of the player application. 308 * 309 * @details Switch to the thread of the AVRCP CT service in this method. 310 * @param[in] rawAddr The address of the bluetooth device. 311 * @return The result of the method execution. 312 * @retval RET_NO_ERROR Execute success. 313 * @retval RET_NO_SUPPORT Not Support. 314 * @retval RET_BAD_STATUS Execute failure. 315 */ 316 int GetPlayerAppSettingAttributes(const RawAddress &rawAddr) override; 317 318 /** 319 * @brief Gets the values of the specified attribute of the player application. 320 * 321 * @details Switch to the thread of the AVRCP CT service in this method. 322 * @param[in] rawAddr The address of the bluetooth device. 323 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 324 * @return The result of the method execution. 325 * @retval RET_NO_ERROR Execute success. 326 * @retval RET_NO_SUPPORT Not Support. 327 * @retval RET_BAD_STATUS Execute failure. 328 */ 329 int GetPlayerAppSettingValues(const RawAddress &rawAddr, uint8_t attribute) override; 330 331 /** 332 * @brief Gets the current set values on the target for the provided player application setting attributes list. 333 * 334 * @details Switch to the thread of the AVRCP CT service in this method. 335 * @param[in] rawAddr The address of the bluetooth device. 336 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 337 * @return The result of the method execution. 338 * @retval RET_NO_ERROR Execute success. 339 * @retval RET_NO_SUPPORT Not Support. 340 * @retval RET_BAD_STATUS Execute failure. 341 */ 342 int GetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes) override; 343 344 /** 345 * @brief Sets the player application setting list of player application setting values on the target device for the 346 * corresponding defined list of AvrcPlayerAttribute. 347 * 348 * @details Switch to the thread of the AVRCP CT service in this method. 349 * @param[in] rawAddr The address of the bluetooth device. 350 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 351 * @param[in] values The value of the player application setting attribute. 352 * @return The result of the method execution. 353 * @retval RET_NO_ERROR Execute success. 354 * @retval RET_NO_SUPPORT Not Support. 355 * @retval RET_BAD_STATUS Execute failure. 356 */ 357 int SetPlayerAppSettingCurrentValue( 358 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values) override; 359 360 /** 361 * @brief provide supported player application setting attribute displayable text. 362 * 363 * @details Switch to the thread of the AVRCP CT service in this method. 364 * @param[in] rawAddr The address of the bluetooth device. 365 * @param[in] attributes The attribute of the player application settings. 366 * @return The result of the method execution. 367 * @retval RET_NO_ERROR Execute success. 368 * @retval RET_NO_SUPPORT Not Support. 369 * @retval RET_BAD_STATUS Execute failure. 370 */ 371 int GetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes) override; 372 373 /** 374 * @brief request the target device to provide target supported player application setting value displayable text. 375 * 376 * @details Switch to the thread of the AVRCP CT service in this method. 377 * @param[in] rawAddr The address of the bluetooth device. 378 * @param[in] attributeId Player application setting attribute ID. 379 * @param[in] values Player application setting value ID. 380 * @return The result of the method execution. 381 * @retval RET_NO_ERROR Execute success. 382 * @retval RET_NO_SUPPORT Not Support. 383 * @retval RET_BAD_STATUS Execute failure. 384 */ 385 int GetPlayerAppSettingValueText( 386 const RawAddress &rawAddr, uint8_t attributeId, const std::vector<uint8_t> &values) override; 387 388 /****************************************************************** 389 * MEDIA INFORMATION PDUS * 390 ******************************************************************/ 391 392 /** 393 * @brief Requests the TG to provide the attributes of the element specified in the parameter. 394 * 395 * @details Switch to the thread of the AVRCP CT service in this function. 396 * @param[in] rawAddr The address of the bluetooth device. 397 * @param[in] identifier Unique identifier to identify an element on TG 398 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved 399 * @c RET_NO_ERROR : The action is successful. 400 * @c RET_NO_SUPPORT : The action is not supported. 401 * @c RET_BAD_STATUS : The action is failed. 402 */ 403 int GetElementAttributes( 404 const RawAddress &rawAddr, uint64_t identifier, const std::vector<uint32_t> &attributes) override; 405 406 /****************************************************************** 407 * PLAY * 408 ******************************************************************/ 409 410 /** 411 * @brief Gets the play status. 412 * 413 * @details Switch to the thread of the AVRCP CT service in this method. 414 * @param[in] rawAddr The address of the bluetooth device. 415 * @return The result of the method execution. 416 * @retval RET_NO_ERROR Execute success. 417 * @retval RET_NO_SUPPORT Not support. 418 * @retval RET_BAD_STATUS Execute failure. 419 */ 420 int GetPlayStatus(const RawAddress &rawAddr) override; 421 422 /** 423 * @brief Starts playing an item indicated by the UID. 424 * 425 * @details Switch to the thread of the AVRCP CT service in this method. 426 * @param[in] rawAddr The address of the bluetooth device. 427 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 428 * @param[in] uid The unique ID of media item. 429 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 430 * @return The result of the method execution. 431 * @retval RET_NO_ERROR Execute success. 432 * @retval RET_NO_SUPPORT Not support. 433 * @retval RET_BAD_STATUS Execute failure. 434 */ 435 int PlayItem(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter) override; 436 437 /** 438 * @brief Adds an item indicated by the UID to the Now Playing queue. 439 * 440 * @details Switch to the thread of the AVRCP CT service in this method. 441 * @param[in] rawAddr The address of the bluetooth device. 442 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 443 * @param[in] uid The UID of the media element item or folder item. 444 * @param[in] uidCounter The UID Counter. 445 * @return The result of the method execution. 446 * @retval RET_NO_ERROR Execute success. 447 * @retval RET_NO_SUPPORT Not support. 448 * @retval RET_BAD_STATUS Execute failure. 449 */ 450 int AddToNowPlaying(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter) override; 451 452 /****************************************************************** 453 * CONTINUING RESPONSE / ABORT CONTINUING RESPONSE * 454 ******************************************************************/ 455 456 /** 457 * @brief Requests continuing response. 458 * 459 * @details Switch to the thread of the AVRCP CT service in this method. 460 * @param[in] rawAddr The address of the bluetooth device. 461 * @param[in] pduId The PDU ID which wants to request. 462 * @return The result of the method execution. 463 * @retval RET_NO_ERROR Execute success. 464 * @retval RET_NO_SUPPORT Not support. 465 * @retval RET_BAD_STATUS Execute failure. 466 */ 467 int RequestContinuingResponse(const RawAddress &rawAddr, uint8_t pduId) override; 468 469 /** 470 * @brief Aborts continuing response. 471 * 472 * @details Switch to the thread of the AVRCP CT service in this method. 473 * @param[in] rawAddr The address of the bluetooth device. 474 * @param[in] pduId The PDU ID which wants to abort. 475 * @return The result of the method execution. 476 * @retval RET_NO_ERROR Execute success. 477 * @retval RET_NO_SUPPORT Not support. 478 * @retval RET_BAD_STATUS Execute failure. 479 */ 480 int AbortContinuingResponse(const RawAddress &rawAddr, uint8_t pduId) override; 481 482 /****************************************************************** 483 * OPERATE THE VIRTUAL FILE SYSTEM * 484 ******************************************************************/ 485 486 /** 487 * @brief Navigates one level up or down in the virtual file system. 488 * 489 * @details Switch to the thread of the AVRCP CT service in this method. 490 * @param[in] rawAddr The address of the bluetooth device. 491 * @param[in] uidCounter The value of the uid counter. 492 * @param[in] direction The flag of the navigation. Refer to <b>AvrcFolderDirection</b>. 493 * @param[in] folderUid The UID of the folder to navigate to. This may be retrieved via a GetFolderItems command. 494 * If the navigation command is Folder Up this field is reserved. 495 * @return The result of the method execution. 496 * @retval RET_NO_ERROR Execute success. 497 * @retval RET_NO_SUPPORT Not support. 498 * @retval RET_BAD_STATUS Execute failure. 499 */ 500 int ChangePath(const RawAddress &rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid) override; 501 502 /** 503 * @brief Retrieves a listing of the contents of a folder. 504 * 505 * @details Switch to the thread of the AVRCP CT service in this method. 506 * @param[in] rawAddr The address of the bluetooth device. 507 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 508 * @param[in] startItem The offset within the listing of the item, which should be the first returned item. The 509 * first element in the listing is at offset 0. 510 * @param[in] endItem The offset within the listing of the item which should be the final returned item. If this 511 * is set to a value beyond what is available, the TG shall return items from the provided Start Item index to the 512 * index of the final item. If the End Item index is smaller than the Start Item index, the TG shall return an 513 * error. If CT requests too many items, TG can respond with a sub-set of the requested items. 514 * @param[in] attributes The list of media attributes. 515 * @return The result of the method execution. 516 * @retval RET_NO_ERROR Execute success. 517 * @retval RET_NO_SUPPORT Not support. 518 * @retval RET_BAD_STATUS Execute failure. 519 */ 520 int GetFolderItems(const RawAddress &rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem, 521 const std::vector<uint32_t> &attributes) override; 522 523 /** 524 * @brief Retrieves the metadata attributes for a particular media element item or folder item. 525 * 526 * @details Switch to the thread of the AVRCP CT service in this method. 527 * @param[in] rawAddr The address of the bluetooth device. 528 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 529 * @param[in] uid The UID of the media element item or folder item. 530 * @param[in] uidCounter The UID Counter. 531 * @param[in] attributes The list of media attributes. 532 * @return The result of the method execution. 533 * @retval RET_NO_ERROR Execute success. 534 * @retval RET_NO_SUPPORT Not support. 535 * @retval RET_BAD_STATUS Execute failure. 536 */ 537 int GetItemAttributes(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, 538 const std::vector<uint32_t> &attributes) override; 539 540 /** 541 * @brief Gets the number of items in the selected folder at the selected scope. 542 * 543 * @details Switch to the thread of the AVRCP CT service in this method. 544 * @param[in] rawAddr The address of the bluetooth device. 545 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 546 * @return The result of the method execution. 547 * @retval RET_NO_ERROR Execute success. 548 * @retval RET_NO_SUPPORT Not support. 549 * @retval RET_BAD_STATUS Execute failure. 550 */ 551 int GetTotalNumberOfItems(const RawAddress &rawAddr, uint8_t scope) override; 552 553 /****************************************************************** 554 * ABSOLUTE VOLUME * 555 ******************************************************************/ 556 557 /** 558 * @brief Sets an absolute volume to be used by the rendering device. 559 * 560 * @details Switch to the thread of the AVRCP CT service in this method. 561 * @param[in] rawAddr The address of the bluetooth device. 562 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 563 * @return The result of the method execution. 564 * @retval RET_NO_ERROR Execute success. 565 * @retval RET_NO_SUPPORT Not support. 566 * @retval RET_BAD_STATUS Execute failure. 567 */ 568 int SetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume) override; 569 570 /****************************************************************** 571 * NOTIFICATION * 572 ******************************************************************/ 573 574 /** 575 * @brief Enables for receiving notifications asynchronously based on specific events occurring. 576 * 577 * @details Switch to the thread of the AVRCP CT service in this method. 578 * @param[in] rawAddr The address of the bluetooth device. 579 * @param[in] events The event for which the requires notification. Refer to <b>AvrcEventId</b>. 580 * @param[in] interval The specifies the time interval (in seconds) at which the change in playback position will be 581 * notified. 582 * @return The result of the method execution. 583 * @retval RET_NO_ERROR Execute success. 584 * @retval RET_NO_SUPPORT Not support. 585 * @retval RET_BAD_STATUS Execute failure. 586 */ 587 int EnableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events, 588 uint8_t interval = AVRC_PLAYBACK_INTERVAL_1_SEC) override; 589 590 /** 591 * @brief Disables for receiving notifications asynchronously based on specific events occurring. 592 * 593 * @details Switch to the thread of the AVRCP CT service in this method. 594 * @param[in] rawAddr The address of the bluetooth device. 595 * @param[in] events The event for which the requires notification. Refer to <b>AvrcEventId</b>. 596 * @return The result of the method execution. 597 * @retval RET_NO_ERROR Execute success. 598 * @retval RET_NO_SUPPORT Not support. 599 * @retval RET_BAD_STATUS Execute failure. 600 */ 601 int DisableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events) override; 602 603 private: 604 /// using a local lock_guard to lock mutex guarantees unlocking on destruction / exception: 605 std::mutex mutex_ {}; 606 /// The maximum connection of device. 607 int maxConnection_ {AVRC_CT_DEFAULT_MAX_OF_CONN}; 608 /// current connection num. 609 int currentConn_ = 0; 610 /// The flag is used to indicate that the state of the AVRCP CT service. 611 std::atomic_uint8_t state_ {AVRC_CT_SERVICE_STATE_DISABLED}; 612 /// The features supported by the AVRCP CT service. 613 uint16_t features_ {AVRC_CT_FEATURE_INVALID_FEATURE}; 614 615 /// The observer registered by the AVRCP CT framework. 616 /// @see AvrcCtProfile::Observer 617 IObserver *myObserver_ {nullptr}; 618 /// The shared pointer to the observer registered into the AVRCP CT profile. 619 /// @see AvrcCtProfile::Observer 620 std::unique_ptr<AvrcCtProfile::Observer> pfObserver_ {nullptr}; 621 622 /// The unique pointer to an object of the AvrcCtGapManager class. 623 /// @see AvrcCtGapManager 624 std::unique_ptr<AvrcCtGapManager> gapManager_ {nullptr}; 625 /// A unique pointer to an object of the AvrcCtSdpManager class. 626 /// @see AvrcCtSdpManager 627 std::unique_ptr<AvrcCtSdpManager> sdpManager_ {nullptr}; 628 /// The unique pointer to an object of the AvrcCtProfile class. 629 /// @see AvrcCtProfile 630 std::unique_ptr<AvrcCtProfile> profile_ {nullptr}; 631 /****************************************************************** 632 * ENABLE / DISABLE * 633 ******************************************************************/ 634 635 /** 636 * @brief Enables the AVRCP CT service. 637 */ 638 void EnableNative(void); 639 640 /** 641 * @brief Disables the AVRCP CT service. 642 */ 643 void DisableNative(void); 644 645 /** 646 * @brief Enables the AVRCP CT profile. 647 * 648 * @return The result of the method execution. 649 * @retval true Execute success. 650 * @retval false Execute failure. 651 */ 652 int EnableProfile(void); 653 654 /** 655 * @brief Disables the AVRCP CT profile. 656 * 657 * @return The result of the method execution. 658 * @retval true Execute success. 659 * @retval false Execute failure. 660 */ 661 int DisableProfile(void) const; 662 663 /** 664 * @brief Informs the profile is disabled. 665 * 666 * @param[in] result The result of the disable. 667 */ 668 void OnProfileDisabled(int result = RET_NO_ERROR); 669 670 /** 671 * @brief Registers security requirements into the GAP. 672 * 673 * @return The result of the method execution. 674 * @retval RET_NO_ERROR Execute success. 675 * @retval RET_BAD_STATUS Execute failure. 676 */ 677 int RegisterSecurity(void); 678 679 /** 680 * @brief Unregisters security requirements from the GAP. 681 * 682 * @return The result of the method execution. 683 * @retval RET_NO_ERROR Execute success. 684 * @retval RET_BAD_STATUS Execute failure. 685 */ 686 int UnregisterSecurity(void); 687 688 /** 689 * @brief Registers the service record into the SDP. 690 * 691 * @return The result of the method execution. 692 * @retval RET_NO_ERROR Execute success. 693 * @retval RET_BAD_STATUS Execute failure. 694 */ 695 int RegisterService(void); 696 697 /** 698 * @brief Unregisters the service record from the SDP. 699 */ 700 int UnregisterService(void); 701 702 /** 703 * @brief Checks whether the AVRCP CT service is disabled. 704 * 705 * @return The result of the method execution. 706 * @retval true The service is disabled. 707 * @retval false The service is not disabled. 708 */ 709 bool IsDisabled(void); 710 711 /** 712 * @brief Sets the flag of the service enabled or not. 713 * 714 * @param[in] state The state of the service. 715 */ 716 void SetServiceState(uint8_t state); 717 718 void InitFeatures(); 719 720 /****************************************************************** 721 * CONNECTION * 722 ******************************************************************/ 723 724 /** 725 * @brief Connects to the AVRCP TG service. 726 * 727 * @param[in] rawAddr The address of the bluetooth device. 728 */ 729 void ConnectNative(RawAddress rawAddr); 730 731 /** 732 * @brief Disconnects from the AVRCP TG service. 733 * 734 * @param[in] rawAddr The address of the bluetooth device. 735 */ 736 void DisconnectNative(RawAddress rawAddr); 737 738 /** 739 * @brief Informs the connection state was changed. 740 * 741 * @param[in] rawAddr The address of the bluetooth device. 742 * @param[in] state The connection state. Refer to <b>BTConnectState</b>. 743 */ 744 void OnConnectionStateChanged(const RawAddress &rawAddr, int state) const; 745 746 /** 747 * @brief Accepts the active connection. 748 * 749 * @param[in] rawAddr The address of the peer bluetooth device. 750 */ 751 void AcceptActiveConnect(const RawAddress &rawAddr); 752 753 /** 754 * @brief Rejects the active connection. 755 * 756 * @param[in] rawAddr The address of the peer bluetooth device. 757 */ 758 void RejectActiveConnect(const RawAddress &rawAddr) const; 759 760 /** 761 * @brief Finds the service record from the SDP. 762 * 763 * @param[in] rawAddr The address of the bluetooth device. 764 * @return The result of the method execution. 765 * @retval RET_NO_ERROR Execute success. 766 * @retval RET_BAD_STATUS Execute failure. 767 */ 768 int FindTgService(const RawAddress &rawAddr) const; 769 770 /** 771 * @brief The callback function that receives the search result return from the SDP. 772 * 773 * @param[in] btAddr The address of the peer Bluetooth device. 774 * @param[in] handleArray The list of handle to a qualifying service. 775 * @param[in] handleCount The number of handle to a qualifying service. 776 * @param[in] context The context is used to send the event in the callback. 777 */ 778 static void FindTgServiceCallback( 779 const BtAddr *btAddr, const uint32_t *handleArray, uint16_t handleCount, void *context); 780 781 /****************************************************************** 782 * BUTTON OPERATION * 783 ******************************************************************/ 784 785 /** 786 * @brief Presses the button. 787 * 788 * @param[in] rawAddr The address of the bluetooth device. 789 * @param[in] button The code of the button pressed. 790 */ 791 void PressButtonNative(RawAddress rawAddr, uint8_t button); 792 793 /** 794 * @brief Releases the button. 795 * 796 * @param[in] rawAddr The address of the bluetooth device. 797 * @param[in] button The code of the button released. 798 */ 799 void ReleaseButtonNative(RawAddress rawAddr, uint8_t button); 800 801 /** 802 * @brief Informs to the result of pressing button that receives from the peer device. 803 * 804 * @param[in] rawAddr The address of the bluetooth device. 805 * @param[in] button The code of the key operation. 806 * @param[in] result The result of the execution.<br> 807 * @a RET_NO_ERROR : Execute success.<br> 808 * @a RET_NO_SUPPORT : Not support.<br> 809 * @a RET_BAD_STATUS : Execute failure. 810 */ 811 void OnButtonPressed(const RawAddress &rawAddr, uint8_t button, int result) const; 812 813 /** 814 * @brief Informs to the result of releasing button that receives from the peer device. 815 * 816 * @param[in] rawAddr The address of the bluetooth device. 817 * @param[in] button The code of the button released. 818 * @param[in] result The result of the execution.<br> 819 * @a RET_NO_ERROR : Execute success.<br> 820 * @a RET_NO_SUPPORT : Not support.<br> 821 * @a RET_BAD_STATUS : Execute failure. 822 */ 823 void OnButtonReleased(const RawAddress &rawAddr, uint8_t button, int result) const; 824 825 /****************************************************************** 826 * UNIT INFO / SUB UNIT INFO * 827 ******************************************************************/ 828 829 /** 830 * @brief Gets the unit information. 831 * 832 * @param[in] rawAddr The address of the bluetooth device. 833 */ 834 void UnitInfoNative(RawAddress rawAddr); 835 836 /** 837 * @brief Gets the sub unit information. 838 * 839 * @param[in] rawAddr The address of the bluetooth device. 840 */ 841 void SubUnitInfoNative(RawAddress rawAddr); 842 843 /****************************************************************** 844 * Media Player Selection * 845 ******************************************************************/ 846 847 /** 848 * @brief Informs which media player wishes to control. 849 * 850 * @param[in] rawAddr The address of the bluetooth device. 851 * @param[in] playerId The unique media player id. 852 */ 853 void SetAddressedPlayerNative(RawAddress rawAddr, uint16_t playerId); 854 855 /** 856 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 857 * 858 * @param[in] rawAddr The address of the bluetooth device. 859 * @param[in] result The result of the execution.<br> 860 * @a RET_NO_ERROR : Execute success.<br> 861 * @a RET_NO_SUPPORT : Not support.<br> 862 * @a RET_BAD_STATUS : Execute failure. 863 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 864 * @a AVRC_ES_CODE_NO_ERROR<br> 865 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 866 * @a AVRC_ES_CODE_UID_CHANGED<br> 867 * @a AVRC_ES_CODE_INVALID_PLAYER_ID 868 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 869 */ 870 void OnSetAddressedPlayer(const RawAddress &rawAddr, int result, int detail) const; 871 872 /** 873 * @brief Informs to which player browsing commands should be routed. 874 * 875 * @param[in] rawAddr The address of the bluetooth device. 876 * @param[in] playerId The unique media player id. 877 */ 878 void SetBrowsedPlayerNative(RawAddress rawAddr, uint16_t playerId); 879 880 /** 881 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 882 * 883 * @param[in] rawAddr The address of the bluetooth device. 884 * @param[in] uidCounter The value of the uid counter. 885 * @param[in] numOfItems The number of items in the directory. 886 * @param[in] folderNames The current browsed path of the player. The first element in folderNames is the parent 887 * folder. The root folder has no name. The names are in UTF-8. 888 * @param[in] result The result of the execution.<br> 889 * @a RET_NO_ERROR : Execute success.<br> 890 * @a RET_NO_SUPPORT : Not support.<br> 891 * @a RET_BAD_STATUS : Execute failure. 892 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 893 * @a AVRC_ES_CODE_NO_ERROR<br> 894 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 895 * @a AVRC_ES_CODE_UID_CHANGED<br> 896 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 897 * @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br> 898 * @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br> 899 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 900 */ 901 void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, 902 const std::vector<std::string> &folderNames, int result, int detail) const; 903 904 /****************************************************************** 905 * Capabilities * 906 ******************************************************************/ 907 908 /** 909 * @brief Get the capabilities supported by remote device. 910 * 911 * @details This is sent by CT to get the capabilities of the peer device 912 * @param[in] rawAddr The address of the bluetooth device. 913 * @param[in] capabilityId Specific capability requested 914 */ 915 void GetCapabilitiesNative(RawAddress rawAddr, uint8_t capabilityId); 916 917 /** 918 * @brief Responds the data of the <b>GetCapabilities</b>. 919 * 920 * @param[in] addr The address of the bluetooth device. 921 * @param[in] companies The list of CompanyID. 922 * @param[in] events The list of EventIDs 923 * @param[in] result The result of the execution.<br> 924 * @a RET_NO_ERROR : Execute success.<br> 925 * @a RET_NO_SUPPORT : Not support.<br> 926 * @a RET_BAD_STATUS : Execute failure. 927 */ 928 void OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies, 929 const std::vector<uint8_t> &events, int result) const; 930 /****************************************************************** 931 * PLAYER APPLICATION SETTINGS * 932 ******************************************************************/ 933 934 /** 935 * @brief Gets the attributes of the player application. 936 * 937 * @param[in] rawAddr The address of the bluetooth device. 938 */ 939 void GetPlayerAppSettingAttributesNative(RawAddress rawAddr); 940 941 /** 942 * @brief Responds the data of the <b>GetPlayerAppSettingAttributes</b>. 943 * 944 * @param[in] rawAddr The address of the bluetooth device. 945 * @param[in] attributes The attribute of player application. 946 * @param[in] result The result of the execution.<br> 947 * @a RET_NO_ERROR : Execute success.<br> 948 * @a RET_NO_SUPPORT : Not support.<br> 949 * @a RET_BAD_STATUS : Execute failure. 950 */ 951 952 void OnGetPlayerAppSettingAttribtues( 953 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, int result) const; 954 955 /** 956 * @brief Gets the values of the specified attribute of the player application. 957 * 958 * @param[in] rawAddr The address of the bluetooth device. 959 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 960 */ 961 void GetPlayerAppSettingValuesNative(RawAddress rawAddr, uint8_t attribute); 962 963 /** 964 * @brief Responds the data of the <b>GetPlayerAppSettingValues</b>. 965 * 966 * @param[in] rawAddr The address of the bluetooth device. 967 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 968 * @param[in] values The values associated witch the attribute. 969 * @param[in] result The result of the execution.<br> 970 * @a RET_NO_ERROR : Execute success.<br> 971 * @a RET_NO_SUPPORT : Not support.<br> 972 * @a RET_BAD_STATUS : Execute failure. 973 */ 974 void OnGetPlayerAppSettingValues( 975 const RawAddress &rawAddr, uint8_t attribute, const std::vector<uint8_t> &values, int result) const; 976 977 /** 978 * @brief Gets the current set values on the target for the provided player application setting attributes list. 979 * 980 * @param[in] rawAddr The address of the bluetooth device. 981 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 982 * @return The result of the method execution. 983 * @retval RET_NO_ERROR Execute success. 984 * @retval RET_NO_SUPPORT Not Support. 985 * @retval RET_BAD_STATUS Execute failure. 986 */ 987 void GetPlayerAppSettingCurrentValueNative(RawAddress rawAddr, std::vector<uint8_t> attributes); 988 989 /** 990 * @brief Responds the data of the <b>GetCurrentPlayerAppSettingValue</b>. 991 * 992 * @param[in] rawAddr The address of the bluetooth device. 993 * @param[in] attributes The attributes of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 994 * @param[in] values The values associated witch the attribute. 995 * @param[in] result The result of the execution.<br> 996 * @a RET_NO_ERROR : Execute success.<br> 997 * @a RET_NO_SUPPORT : Not support.<br> 998 * @a RET_BAD_STATUS : Execute failure. 999 */ 1000 void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 1001 const std::vector<uint8_t> &values, int result) const; 1002 1003 /** 1004 * @brief Sets the player application setting list of player application setting values on the target device for the 1005 * corresponding defined list of AvrcPlayerAttribute. 1006 * 1007 * @param[in] rawAddr The address of the bluetooth device. 1008 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 1009 * @param[in] values The value of the player application setting attribute. 1010 */ 1011 void SetPlayerAppSettingCurrentValueNative( 1012 RawAddress rawAddr, std::vector<uint8_t> attributes, std::vector<uint8_t> values); 1013 1014 /** 1015 * @brief Responds the data of the <b>SetPlayerAppSettingCurrentValue</b>. 1016 * 1017 * @param[in] rawAddr The address of the bluetooth device. 1018 * @param[in] result The result of the execution.<br> 1019 * @a RET_NO_ERROR : Execute success.<br> 1020 * @a RET_NO_SUPPORT : Not support.<br> 1021 * @a RET_BAD_STATUS : Execute failure. 1022 */ 1023 void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result) const; 1024 1025 /** 1026 * @brief provide supported player application setting attribute displayable text. 1027 * 1028 * @param[in] rawAddr The address of the bluetooth device. 1029 * @param[in] attributes The attribute of the player application settings. 1030 */ 1031 void GetPlayerAppSettingAttributeTextNative(RawAddress rawAddr, std::vector<uint8_t> attributes); 1032 1033 /** 1034 * @brief Responds the data of the <b>GetPlayerApplicationSettingAttributeText</b>. 1035 * 1036 * @param[in] rawAddr The address of the bluetooth device. 1037 * @param[in] attributes The attribute of the player application settings. 1038 * @param[in] attrStr The values associated witch the attribute. 1039 * @param[in] result The result of the execution.<br> 1040 * @a RET_NO_ERROR : Execute success.<br> 1041 * @a RET_NO_SUPPORT : Not support.<br> 1042 * @a RET_BAD_STATUS : Execute failure. 1043 */ 1044 void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 1045 const std::vector<std::string> &attrStr, int result) const; 1046 1047 /** 1048 * @brief request the target device to provide target supported player application setting value displayable text 1049 * 1050 * @details Switch to the thread of the AVRCP CT service in this method. 1051 * @param[in] rawAddr The address of the bluetooth device. 1052 * @param[in] attributeId Player application setting attribute ID. 1053 * @param[in] values Player application setting value ID. 1054 */ 1055 void GetPlayerAppSettingValueTextNative(RawAddress rawAddr, uint8_t attributeId, std::vector<uint8_t> values); 1056 1057 /** 1058 * @brief Responds the data of the <b>GetPlayerApplicationSettingValueText</b>. 1059 * 1060 * @param[in] rawAddr The address of the bluetooth device. 1061 * @param[in] values Player application setting value ID. 1062 * @param[in] valueStr Specifies the value string of player application setting value. 1063 * @param[in] result The result of the execution.<br> 1064 * @a RET_NO_ERROR : Execute success.<br> 1065 * @a RET_NO_SUPPORT : Not support.<br> 1066 * @a RET_BAD_STATUS : Execute failure. 1067 */ 1068 void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, const std::vector<uint8_t> &values, 1069 const std::vector<std::string> &valueStr, int result) const; 1070 1071 /****************************************************************** 1072 * MEDIA INFORMATION PDUS * 1073 ******************************************************************/ 1074 1075 /** 1076 * @brief Requests the TG to provide the attributes of the element specified in the parameter. 1077 * 1078 * @details Switch to the thread of the AVRCP CT service in this function. 1079 * @param[in] rawAddr The address of the bluetooth device. 1080 * @param[in] identifier Unique identifier to identify an element on TG 1081 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved 1082 */ 1083 void GetElementAttributesNative(RawAddress rawAddr, uint64_t identifier, std::vector<uint32_t> attributes); 1084 1085 /** 1086 * @brief Responds the data of the <b>GetElementAttribtues</b>. 1087 * 1088 * @param[in] rawAddr The address of the bluetooth device. 1089 * @param[in] attributes The attributes of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 1090 * @param[in] values The values associated witch the attribute.Refer to <b>GetElementAttribtues</b>. 1091 * @param[in] result The result of the execution.<br> 1092 * @a RET_NO_ERROR : Execute success.<br> 1093 * @a RET_NO_SUPPORT : Not support.<br> 1094 * @a RET_BAD_STATUS : Execute failure. 1095 */ 1096 void OnGetElementAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes, 1097 const std::vector<std::string> &values, int result) const; 1098 1099 /****************************************************************** 1100 * PLAY * 1101 ******************************************************************/ 1102 1103 /** 1104 * @brief Gets the play status. 1105 * 1106 * @param[in] rawAddr The address of the bluetooth device. 1107 */ 1108 void GetPlayStatusNative(RawAddress rawAddr); 1109 1110 /** 1111 * @brief Responds the data of the <b>GetPlayStatus</b>. 1112 * 1113 * @param[in] rawAddr The address of the bluetooth device. 1114 * @param[in] songLength The total length of the playing song in milliseconds. 1115 * @param[in] songPosition The current position of the playing in milliseconds elapsed. 1116 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 1117 * @param[in] result The result of the execution.<br> 1118 * @a RET_NO_ERROR : Execute success.<br> 1119 * @a RET_NO_SUPPORT : Not support.<br> 1120 * @a RET_BAD_STATUS : Execute failure. 1121 */ 1122 void OnGetPlayStatus( 1123 const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result) const; 1124 1125 /** 1126 * @brief Starts playing an item indicated by the UID. 1127 * 1128 * @details Switch to the thread of the AVRCP CT service in this method. 1129 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1130 * @param[in] rawAddr The address of the bluetooth device. 1131 * @param[in] uid The unique ID of media item. 1132 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 1133 * @return The result of the method execution. 1134 * @retval RET_NO_ERROR Execute success. 1135 * @retval RET_NO_SUPPORT Not support. 1136 * @retval RET_BAD_STATUS Execute failure. 1137 */ 1138 void PlayItemNative(RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter); 1139 1140 /** 1141 * @brief Responds the data of the <b>PlayItem</b>. 1142 * 1143 * @param[in] rawAddr The address of the bluetooth device. 1144 * @param[in] result The result of the execution.<br> 1145 * @a RET_NO_ERROR : Execute success.<br> 1146 * @a RET_NO_SUPPORT : Not support.<br> 1147 * @a RET_BAD_STATUS : Execute failure. 1148 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1149 * @a AVRC_ES_CODE_INVALID_COMMAND<br> 1150 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1151 * @a AVRC_ES_CODE_INVALID_PARAMETER<br> 1152 * @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br> 1153 * @a AVRC_ES_CODE_NO_ERROR<br> 1154 * @a AVRC_ES_CODE_UID_CHANGED<br> 1155 * @a AVRC_ES_CODE_RESERVED<br> 1156 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1157 * @a AVRC_ES_CODE_INVALID_SCOPE 1158 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 1159 * @a AVRC_ES_CODE_MEDIA_IN_USE 1160 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1161 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 1162 */ 1163 void OnPlayItem(const RawAddress &rawAddr, int result, int detail) const; 1164 1165 /** 1166 * @brief Adds an item indicated by the UID to the Now Playing queue. 1167 * 1168 * @param[in] rawAddr The address of the bluetooth device. 1169 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1170 * @param[in] uid The UID of the media element item or folder item. 1171 * @param[in] uidCounter The UID Counter. 1172 * @return The result of the method execution. 1173 * @retval RET_NO_ERROR Execute success. 1174 * @retval RET_NO_SUPPORT Not support. 1175 * @retval RET_BAD_STATUS Execute failure. 1176 */ 1177 void AddToNowPlayingNative(RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter); 1178 1179 /** 1180 * @brief Responds the data of the <b>AddToNowPlaying</b>. 1181 * 1182 * @param[in] rawAddr The address of the bluetooth device. 1183 * @param[in] result The result of the execution.<br> 1184 * @a RET_NO_ERROR : Execute success.<br> 1185 * @a RET_NO_SUPPORT : Not support.<br> 1186 * @a RET_BAD_STATUS : Execute failure. 1187 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1188 * @a AVRC_ES_CODE_NO_ERROR<br> 1189 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1190 * @a AVRC_ES_CODE_UID_CHANGED<br> 1191 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1192 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1193 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br> 1194 * @a AVRC_ES_CODE_MEDIA_IN_USE<br> 1195 * @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br> 1196 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1197 */ 1198 void OnAddToNowPlaying(const RawAddress &rawAddr, int result, int detail) const; 1199 1200 /****************************************************************** 1201 * CONTINUING RESPONSE / ABORT CONTINUING RESPONSE * 1202 ******************************************************************/ 1203 1204 /** 1205 * @brief Requests continuing response. 1206 * 1207 * @param[in] rawAddr The address of the bluetooth device. 1208 * @param[in] pduId The PDU ID which wants to request. 1209 */ 1210 void RequestContinuingResponseNative(RawAddress rawAddr, uint8_t pduId); 1211 1212 /** 1213 * @brief Aborts continuing response. 1214 * 1215 * @details Switch to the thread of the AVRCP CT service in this method. 1216 * @param[in] rawAddr The address of the bluetooth device. 1217 * @param[in] pduId The PDU ID which wants to abort. 1218 */ 1219 void AbortContinuingResponseNative(RawAddress rawAddr, uint8_t pduId); 1220 1221 /****************************************************************** 1222 * OPERATE THE VIRTUAL FILE SYSTEM * 1223 ******************************************************************/ 1224 1225 /** 1226 * @brief Navigates one level up or down in the virtual file system. 1227 * 1228 * @param[in] rawAddr The address of the bluetooth device. 1229 * @param[in] uidCounter The value of the uid counter. 1230 * @param[in] direction The flag of the navigation. Refer to <b>AvrcFolderDirection</b>. 1231 * @param[in] folderUid The UID of the folder to navigate to. This may be retrieved via a GetFolderItems command. 1232 * If the navigation command is Folder Up this field is reserved. 1233 */ 1234 void ChangePathNative(RawAddress rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid); 1235 1236 /** 1237 * @brief Responds the data of the <b>ChangePath</b>. 1238 * 1239 * @param[in] rawAddr The address of the bluetooth device. 1240 * @param[in] numOfItems The number of items in the directory. 1241 * @param[in] result The result of the execution.<br> 1242 * @a RET_NO_ERROR : Execute success.<br> 1243 * @a RET_NO_SUPPORT : Not support.<br> 1244 * @a RET_BAD_STATUS : Execute failure. 1245 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1246 * @a AVRC_ES_CODE_NO_ERROR<br> 1247 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1248 * @a AVRC_ES_CODE_UID_CHANGED<br> 1249 * @a AVRC_ES_CODE_INVALID_DIRECTION<br> 1250 * @a AVRC_ES_CODE_NOT_A_DIRECTORY<br> 1251 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1252 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1253 */ 1254 void OnChangePath(const RawAddress &rawAddr, uint32_t numOfItems, int result, int detail) const; 1255 1256 /** 1257 * @brief Retrieves a listing of the contents of a folder. 1258 * 1259 * @param[in] rawAddr The address of the bluetooth device. 1260 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1261 * @param[in] startItem The offset within the listing of the item, which should be the first returned item. The 1262 * first element in the listing is at offset 0. 1263 * @param[in] endItem The offset within the listing of the item which should be the final returned item. If this 1264 * is set to a value beyond what is available, the TG shall return items from the provided Start Item index to the 1265 * index of the final item. If the End Item index is smaller than the Start Item index, the TG shall return an 1266 * error. If CT requests too many items, TG can respond with a sub-set of the requested items. 1267 * @param[in] attributes The list of media attributes. 1268 */ 1269 void GetFolderItemsNative( 1270 RawAddress rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem, std::vector<uint32_t> attributes); 1271 1272 /** 1273 * @brief Responds the data of the <b>GetFolderItems</b>. 1274 * 1275 * @param[in] rawAddr The address of the bluetooth device. 1276 * @param[in] scope The scope in which media content navigation may take place. Refer to 1277 * <b>AvrcMediaScope</b>. 1278 * @param[in] uidCounter The UID Counter. 1279 * @param[in] mpItems The list of <b>AvrcCtMpItem</b> class. 1280 * @param[in] mpItems The list of <b>AvrcCtMeItem</b> class. 1281 * @param[in] result The result of the execution.<br> 1282 * @a RET_NO_ERROR : Execute success.<br> 1283 * @a RET_NO_SUPPORT : Not support.<br> 1284 * @a RET_BAD_STATUS : Execute failure. 1285 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1286 * @a AVRC_ES_CODE_NO_ERROR<br> 1287 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1288 * @a AVRC_ES_CODE_UID_CHANGED<br> 1289 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1290 * @a AVRC_ES_CODE_RANGE_OUT_OF_BOUNDS<br> 1291 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1292 */ 1293 void OnGetFolderItems(const RawAddress &rawAddr, uint8_t scope, uint16_t uidCounter, 1294 const std::vector<AvrcMpItem> &mpItems, const std::vector<AvrcMeItem> &meItems, int result, int detail) const; 1295 1296 /** 1297 * @brief Retrieves the metadata attributes for a particular media element item or folder item. 1298 * 1299 * @param[in] rawAddr The address of the bluetooth device. 1300 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1301 * @param[in] uid The UID of the media element item or folder item. 1302 * @param[in] uidCounter The UID Counter. 1303 * @param[in] attributes The list of media attributes. 1304 */ 1305 void GetItemAttributesNative( 1306 RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, std::vector<uint32_t> attributes); 1307 1308 /** 1309 * @brief Responds the data of the <b>GetItemAttributes</b>. 1310 * 1311 * @param[in] rawAddr The address of the bluetooth device. 1312 * @param[in] attributes The list of media attributes. 1313 * @param[in] values The list of the value of this attribute. 1314 * @param[in] result The result of the execution.<br> 1315 * @a RET_NO_ERROR : Execute success.<br> 1316 * @a RET_NO_SUPPORT : Not support.<br> 1317 * @a RET_BAD_STATUS : Execute failure. 1318 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1319 * @a AVRC_ES_CODE_NO_ERROR<br> 1320 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1321 * @a AVRC_ES_CODE_UID_CHANGED<br> 1322 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 1323 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 1324 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1325 */ 1326 void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes, 1327 const std::vector<std::string> &values, int result, int detail) const; 1328 1329 /** 1330 * @brief Gets the Number of Items in the selected folder at the selected scope. 1331 * 1332 * @param[in] rawAddr The address of the bluetooth device. 1333 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 1334 */ 1335 void GetTotalNumberOfItemsNative(RawAddress rawAddr, uint8_t scope); 1336 1337 /** 1338 * @brief Responds the data of the <b>GetTotalNumberOfItems</b>. 1339 * 1340 * @param[in] rawAddr The address of the bluetooth device. 1341 * @param[in] uidCounter The value of the uid counter. 1342 * @param[in] numOfItems The number of items in the directory. 1343 * @param[in] result The result of the execution.<br> 1344 * @a RET_NO_ERROR : Execute success.<br> 1345 * @a RET_NO_SUPPORT : Not support.<br> 1346 * @a RET_BAD_STATUS : Execute failure. 1347 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 1348 * @a AVRC_ES_CODE_NO_ERROR<br> 1349 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 1350 * @a AVRC_ES_CODE_UID_CHANGED<br> 1351 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 1352 */ 1353 void OnGetTotalNumberOfItems( 1354 const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, int result, int detail) const; 1355 1356 /****************************************************************** 1357 * ABSOLUTE VOLUME * 1358 ******************************************************************/ 1359 1360 /** 1361 * @brief Sets an absolute volume to be used by the rendering device. 1362 * 1363 * @param[in] rawAddr The address of the bluetooth device. 1364 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1365 */ 1366 void SetAbsoluteVolumeNative(RawAddress rawAddr, uint8_t volume); 1367 1368 /** 1369 * @brief Responds the data of the <b>SetAbsoluteVolume</b>. 1370 * 1371 * @param[in] rawAddr The address of the bluetooth device. 1372 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1373 * @param[in] result The result of the execution.<br> 1374 * @a RET_NO_ERROR : Execute success.<br> 1375 * @a RET_NO_SUPPORT : Not support.<br> 1376 * @a RET_BAD_STATUS : Execute failure. 1377 */ 1378 void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result) const; 1379 1380 /****************************************************************** 1381 * NOTIFICATION * 1382 ******************************************************************/ 1383 1384 /** 1385 * @brief Enables for receiving notifications asynchronously based on specific events occurring. 1386 * 1387 * @details Switch to the thread of the AVRCP CT service in this method. 1388 * @param[in] rawAddr The address of the bluetooth device. 1389 * @param[in] events The event for which the requires notification. Refer to <b>AvrcEventId</b>. 1390 * @param[in] interval The specifies the time interval (in seconds) at which the change in playback position will be 1391 * notified. 1392 */ 1393 void EnableNotificationNative(RawAddress rawAddr, std::vector<uint8_t> events, uint8_t interval); 1394 1395 /** 1396 * @brief Disables for receiving notifications asynchronously based on specific events occurring. 1397 * 1398 * @param[in] rawAddr The address of the bluetooth device.d 1399 * @param[in] events The event for which the requires notification. Refer to <b>AvrcEventId</b>. 1400 */ 1401 void DisableNotificationNative(RawAddress rawAddr, std::vector<uint8_t> events); 1402 1403 /** 1404 * @brief Responds the data of the notification <b>EVENT_PLAYBACK_STATUS_CHANGED</b>. 1405 * 1406 * @param[in] rawAddr The address of the bluetooth device. 1407 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 1408 * @param[in] result The result of the execution.<br> 1409 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1410 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1411 */ 1412 void OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result) const; 1413 1414 /** 1415 * @brief Responds the data of the notification <b>EVENT_TRACK_CHANGED</b>. 1416 * 1417 * @param[in] rawAddr The address of the bluetooth device. 1418 * @param[in] uid The unique ID of media item. 1419 * @param[in] result The result of the execution.<br> 1420 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1421 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1422 */ 1423 void OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result) const; 1424 1425 /** 1426 * @brief Responds the data of the notification <b>EVENT_TRACK_REACHED_END</b>. 1427 * 1428 * @param[in] rawAddr The address of the bluetooth device. 1429 * @param[in] result The result of the execution.<br> 1430 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1431 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1432 */ 1433 void OnTrackReachedEnd(const RawAddress &rawAddr, int result) const; 1434 1435 /** 1436 * @brief Responds the data of the notification <b>EVENT_TRACK_REACHED_START</b>. 1437 * 1438 * @param[in] rawAddr The address of the bluetooth device. 1439 * @param[in] result The result of the execution.<br> 1440 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1441 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1442 */ 1443 void OnTrackReachedStart(const RawAddress &rawAddr, int result) const; 1444 1445 /** 1446 * @brief Responds the data of the notification <b>EVENT_PLAYBACK_POS_CHANGED</b>. 1447 * 1448 * @param[in] rawAddr The address of the bluetooth device. 1449 * @param[in] playbackPos Current playback position in millisecond. 1450 * @param[in] result The result of the execution.<br> 1451 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1452 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1453 */ 1454 void OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result) const; 1455 1456 /** 1457 * @brief Responds the data of the notification <b>EVENT_PLAYER_APPLICATION_SETTING_CHANGED</b>. 1458 * 1459 * @param[in] rawAddr The address of the bluetooth device. 1460 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 1461 * @param[in] values The values associated witch the attribute. 1462 * @param[in] result The result of the execution.<br> 1463 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1464 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1465 */ 1466 void OnPlayerApplicationSettingChanged(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 1467 const std::vector<uint8_t> &values, int result) const; 1468 1469 /** 1470 * @brief Responds the data of the notification <b>EVENT_NOW_PLAYING_CONTENT_CHANGED</b>. 1471 * 1472 * @param[in] rawAddr The address of the bluetooth device. 1473 * @param[in] result The result of the execution.<br> 1474 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1475 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1476 */ 1477 void OnNowPlayingContentChanged(const RawAddress &rawAddr, int result) const; 1478 1479 /** 1480 * @brief Responds the data of the notification <b>EVENT_AVAILABLE_PLAYERS_CHANGED</b>. 1481 * 1482 * @param[in] rawAddr The address of the bluetooth device. 1483 * @param[in] result The result of the execution.<br> 1484 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1485 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1486 */ 1487 void OnAvailablePlayersChanged(const RawAddress &rawAddr, int result) const; 1488 1489 /** 1490 * @brief Responds the data of the notification <b>EVENT_ADDRESSED_PLAYER_CHANGED</b>. 1491 * 1492 * @param[in] rawAddr The address of the bluetooth device. 1493 * @param[in] playerId The unique media player id. 1494 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 1495 * @param[in] result The result of the execution.<br> 1496 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1497 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1498 */ 1499 void OnAddressedPlayerChanged(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result) const; 1500 1501 /** 1502 * @brief Responds the data of the notification <b>EVENT_UIDS_CHANGED</b>. 1503 * 1504 * @param[in] rawAddr The address of the bluetooth device. 1505 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 1506 * @param[in] result The result of the execution.<br> 1507 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1508 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1509 */ 1510 void OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result) const; 1511 1512 /** 1513 * @brief Responds the data of the notification <b>EVENT_VOLUME_CHANGED</b>. 1514 * 1515 * @param[in] rawAddr The address of the bluetooth device. 1516 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 1517 * @param[in] result The result of the execution.<br> 1518 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 1519 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 1520 */ 1521 void OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result) const; 1522 1523 /** 1524 * @brief Processes events received from the AVCTP. 1525 * 1526 * @param[in] rawAddr The address of the bluetooth device. 1527 * @param[in] connectId The ID of the connection. 1528 * @param[in] event The event from the underlying module. 1529 * @param[in] result The result of the event. 1530 * @param[in] context The context is used to send the event in the callback. 1531 */ 1532 void ProcessChannelEvent(RawAddress rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context); 1533 1534 /** 1535 * @brief Processes messages received from the AVCTP. 1536 * 1537 * @param[in] connectId The ID of the connection. 1538 * @param[in] label The label used to distinguish between different calls to the same function. 1539 * @param[in] crType The type used to distinguish between the command frame and the response frame. 1540 * @param[in] chType The type used to distinguish the message returned from the control channel or the browse 1541 * channel. 1542 * @param[in] pkt The message sent by the peer bluetooth device. 1543 * @param[in] context The context is used to send the message in the callback. 1544 */ 1545 void ProcessChannelMessage( 1546 uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context); 1547 1548 /** 1549 * @brief Receives events from the AVCT protocol. 1550 * 1551 * @detail This function is the callback function registered into the AVCTP. 1552 * @param[in] connectId The ID of the connection. 1553 * @param[in] event The event from the underlying module. 1554 * @param[in] result The result of the event. 1555 * @param[in] btAddr The address of the bluetooth device. 1556 * @param[in] context The context is used to send the event in the callback. 1557 */ 1558 static void ChannelEventCallback( 1559 uint8_t connectId, uint8_t event, uint16_t result, const BtAddr *btAddr, void *context); 1560 1561 /** 1562 * @brief The callback function is registered into the AVCTP. 1563 * 1564 * @param[in] connectId The ID of the connection. 1565 * @param[in] label The label used to distinguish between different calls to the same function. 1566 * @param[in] crType The type used to distinguish between the command frame and the response frame. 1567 * @param[in] chType The type used to distinguish the message returned from the control channel or the browse 1568 * channel. 1569 * @param[in] pkt The message sent by the peer bluetooth device. 1570 * @param[in] context The context is used to send the message in the callback. 1571 */ 1572 static void ChannelMessageCallback( 1573 uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context); 1574 1575 bool CheckConnectionNum(); 1576 DecConnectionNum()1577 inline void DecConnectionNum() 1578 { 1579 if (currentConn_-- < 0) { 1580 currentConn_ = 0; 1581 } 1582 } 1583 1584 BT_DISALLOW_COPY_AND_ASSIGN(AvrcpCtService); 1585 }; 1586 } // namespace bluetooth 1587 } // namespace OHOS 1588 1589 #endif // !AVRCP_TG_SERVICE_H 1590