1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AVRCP_TG_NOTIFICATION_H 17 #define AVRCP_TG_NOTIFICATION_H 18 19 #include<deque> 20 #include "avrcp_tg_packet.h" 21 #include "avrcp_tg_vendor.h" 22 #include"packet.h" 23 24 namespace OHOS { 25 namespace bluetooth { 26 /** 27 * @brief This enumeration declares the values of the "EVENT ID". 28 * @see Audio/Video Remote Control 1.6.2 Section 28 Appendix H: list of defined notification events. 29 */ 30 enum AvrcTgEventId : uint32_t { 31 AVRC_TG_EVENT_ID_PLAYBACK_STATUS_CHANGED = 0x01, // Change in playback status of the current track. 32 AVRC_TG_EVENT_ID_TRACK_CHANGED, // Change of current track. 33 AVRC_TG_EVENT_ID_TRACK_REACHED_END, // Reached end of a track. 34 AVRC_TG_EVENT_ID_TRACK_REACHED_START, // Reached start of a track. 35 // Change in playback position. Returned after the specified playback notification change notification interval. 36 AVRC_TG_EVENT_ID_PLAYBACK_POS_CHANGED, 37 AVRC_TG_EVENT_ID_BATT_STATUS_CHANGED, // Change in battery status. 38 AVRC_TG_EVENT_ID_SYSTEM_STATUS_CHANGED, // Change in system status. 39 AVRC_TG_EVENT_ID_PLAYER_APPLICATION_SETTING_CHANGED, // Change in player application setting. 40 AVRC_TG_EVENT_ID_NOW_PLAYING_CONTENT_CHANGED, // The content of the Now Playing list has changed. 41 AVRC_TG_EVENT_ID_AVAILABLE_PLAYERS_CHANGED, // The available players have changed 42 AVRC_TG_EVENT_ID_ADDRESSED_PLAYER_CHANGED, // The Addressed Player has been changed. 43 AVRC_TG_EVENT_ID_UIDS_CHANGED, // The UIDs have changed. 44 AVRC_TG_EVENT_ID_VOLUME_CHANGED, // The volume has been changed locally on the TG. 45 AVRC_TG_EVENT_ID_RESERVED = 0x0E, 46 }; 47 48 /** 49 * @brief This enumeration declares the values of the <b>NOTIFICATION</b> commands. 50 */ 51 enum AvrcTgNotify { 52 AVRC_TG_NOTIFY_NUM_OF_PACKETS = 0x01, // The number of the packets. 53 AVRC_TG_NOTIFY_PARAMETER_LENGTH = 0x0000, // The length of the "Parameter Length". 54 AVRC_TG_NOTIFY_PLAYER_ID = 0xFFFF, // The value of the "Player Id". 55 AVRC_TG_NOTIFY_PLAYBACK_POSITION = 0xFFFFFFFF, // The value of the "Playback position". 56 AVRC_TG_NOTIFY_EVENT_ID_OFFSET = 0x0A, // The offset of the "Event ID". 57 AVRC_TG_NOTIFY_EVENT_ID_SIZE = 0x01, // The size of the "Event ID". 58 AVRC_TG_NOTIFY_EVENT_ID_PLAYBACK_STATUS_SIZE = 0x01, // The size of the "PlayStatus". 59 AVRC_TG_NOTIFY_EVENT_UID_SIZE = 0x08, // The size of the "Identifier". 60 AVRC_TG_NOTIFY_EVENT_PLAYBACK_POSITION_SIZE = 0x04, // The size of the "Playback position". 61 AVRC_TG_NOTIFY_EVENT_PLAYER_ID_SIZE = 0x02, // The size of the "Player Id". 62 AVRC_TG_NOTIFY_EVENT_UID_COUNTER_SIZE = 0x02, // The size of the "UID Counter". 63 AVRC_TG_NOTIFY_EVENT_ID_VOLUME_SIZE = 0x01, // The size of the "Absolute Volume". 64 }; 65 66 /** 67 * @brief This class provides a set of methods of assemble / disassemble the packet of the <b>NOTIFICATION</b> 68 * command. 69 * @see Audio/Video Remote Control 1.6.2 Section 6.7.2 RegisterNotification. 70 */ 71 class AvrcTgNotifyPacket : public AvrcTgVendorPacket { 72 public: 73 /** 74 * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance. 75 */ 76 AvrcTgNotifyPacket(uint8_t eventId, uint8_t crCode, uint8_t label); 77 78 /** 79 * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance. 80 */ 81 AvrcTgNotifyPacket(Packet *pkt, uint8_t label); 82 83 /** 84 * @brief A destructor used to delete the <b>AvrcCtNotifyPacket</b> instance. 85 */ 86 virtual ~AvrcTgNotifyPacket(); 87 88 /** 89 * @brief Assembles the operands behind the "Packet Type" of the frame. 90 * 91 * @details Command frame:<br> 92 * msb lsb<br> 93 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 94 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 95 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 96 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 97 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 98 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 99 * @param[in] pkt The frame packet. 100 * @return The frame packet. 101 */ 102 Packet *AssembleParameters(Packet *pkt) override; 103 104 /** 105 * @brief Disassembles the operands behind the "Packet Type" of the frame. 106 * 107 * @details Response frame:<br> 108 * msb lsb<br> 109 * 0 0 0 0 | 0 0 0 0 ctype 4 bits<br> 110 * Subunit type 5 bits 0 0 0 0 0 | 0 0 0 Subunit ID 3 bits<br> 111 * 0 0 0 0 | 0 0 0 0 Opcode 1 octets<br> 112 * 0 0 0 0 | 0 0 0 0 Company ID : Bluetooth SIG registered CompanyID 3 octets<br> 113 * 0 0 0 0 | 0 0 0 0 PDU ID 1 octets<br> 114 * Reserved 7 bits 0 0 0 0 0 0 0 | 0 Packet Type 1 bits<br> 115 * 116 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 117 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 118 * 0 0 0 0 | 0 0 0 0 Playback interval 4 octets<br> 119 * @param[in] buffer The buffer of the frame. 120 * @return The result of the method execution. 121 * @retval true The packet is valid. 122 * @retval false The packet is invalid. 123 */ 124 bool DisassembleParameters(uint8_t *buffer) override; 125 126 /** 127 * @brief Gets the number of the packets. 128 * 129 * @return The number of the packets. 130 */ 131 uint16_t GetNumberOfPackets(void) override; 132 133 /** 134 * @brief Gets the maximum number of values for the "PlayerApplicationSettingValueID". 135 * 136 * @return The maximum number of values for the "PlayerApplicationSettingValueID". 137 */ 138 uint16_t GetAvailableParameterSize(void) const; 139 140 /** 141 * @brief Initializes for <b>EVENT_PLAYBACK_STATUS_CHANGED</b> 142 * 143 * @param[in] playStatus Indicates the current status of playback. 144 */ InitPlaybackStatusChanged(uint8_t playStatus)145 void InitPlaybackStatusChanged(uint8_t playStatus) 146 { 147 playStatus_ = playStatus; 148 } 149 150 /** 151 * @brief Initializes for <b>EVENT_TRACK_CHANGED</b> 152 * 153 * @param[in] Identifier Unique Identifier to identify an element on TG, as is used for GetElementAttribute command 154 * in case Browsing is not supported and GetItemAttribute command in case Browsing is supported. 155 */ InitTrackChanged(uint64_t identifier)156 void InitTrackChanged(uint64_t identifier) 157 { 158 uid_ = identifier; 159 } 160 161 /** 162 * @brief Initializes for <b>EVENT_PLAYBACK_POS_CHANGED</b> 163 * 164 * @param[in] playbackPos Current playback position in millisecond. 165 */ InitPlaybackPosChanged(uint32_t playbackPos)166 void InitPlaybackPosChanged(uint32_t playbackPos) 167 { 168 playbackPos_ = playbackPos; 169 } 170 171 /** 172 * @brief Initializes for <b>EVENT_PLAYER_APPLICATION_SETTING_CHANGED</b> 173 * 174 * @param[in] attributes Player application setting attribute ID for which the value is returned. 175 * @param[in] values Currently set Player Application Setting value on the TG for the above attributes. 176 */ InitPlayerApplicationSettingChanged(const std::deque<uint8_t> & attributes,const std::deque<uint8_t> & values)177 void InitPlayerApplicationSettingChanged(const std::deque<uint8_t> &attributes, const std::deque<uint8_t> &values) 178 { 179 attributes_ = attributes; 180 values_ = values; 181 } 182 183 /** 184 * @brief Initializes for <b>EVENT_ADDRESSED_PLAYER_CHANGED</b> 185 * 186 * @param[in] playerId The player id. 187 * @param[in] uidCounter The uid counter. 188 */ InitAddressedPlayerChanged(uint16_t playerId,uint16_t uidCounter)189 void InitAddressedPlayerChanged(uint16_t playerId, uint16_t uidCounter) 190 { 191 playerId_ = playerId; 192 uidCounter_ = uidCounter; 193 } 194 195 /** 196 * @brief Initializes for <b>EVENT_UIDS_CHANGED</b> 197 * 198 * @param[in] uidCounter The uid counter. 199 */ InitUidsChanged(uint16_t uidCounter)200 void InitUidsChanged(uint16_t uidCounter) 201 { 202 uidCounter_ = uidCounter; 203 } 204 205 /** 206 * @brief Initializes for <b>EVENT_VOLUME_CHANGED</b> 207 * 208 * @param[in] volume The absolute volume. 209 */ InitVolumeChanged(uint8_t volume)210 void InitVolumeChanged(uint8_t volume) 211 { 212 volume_ = volume; 213 } 214 215 /** 216 * @brief Gets the "EventID". 217 * 218 * @return The value of the "EventID". 219 */ GetEventId(void)220 uint8_t GetEventId(void) const 221 { 222 return eventId_; 223 } 224 225 /** 226 * @brief Gets the "Playback interval". 227 * 228 * @return The value of the "Playback interval". 229 */ GetPlaybackInterval(void)230 uint8_t GetPlaybackInterval(void) const 231 { 232 return interval_; 233 } 234 235 /** 236 * @brief Checks the event id is valid or not. 237 * 238 * @return The result of the method execution. 239 * @retval true The event id is valid. 240 * @retval false The event id is invalid. 241 */ 242 bool IsValidEventId(void) const; 243 244 /** 245 * @brief Checks the event id is supported or not. 246 * 247 * @return The result of the method execution. 248 * @retval true The event id is supported. 249 * @retval false The event id is unsupported. 250 */ 251 bool IsSupportedEventId(void) const; 252 253 private: 254 uint8_t eventId_ {AVRC_TG_EVENT_ID_RESERVED}; // The value of the "EventID". 255 uint32_t interval_ {AVRC_PLAYBACK_INTERVAL_1_SEC}; // The value of the "Playback interval". 256 uint8_t playStatus_ {AVRC_PLAY_STATUS_ERROR}; // The value of the "PlayStatus". 257 uint64_t uid_ {AVRC_TG_VENDOR_UID}; // The value of the "Identifier". 258 uint32_t playbackPos_ {AVRC_TG_NOTIFY_PLAYBACK_POSITION}; // The value of the "Playback position". 259 std::deque<uint8_t> attributes_ {}; 260 // The value of the "PlayerApplicationSettingAttributeID". 261 std::deque<uint8_t> values_ {}; // The value of the "PlayerApplicationSettingValueID". 262 uint16_t playerId_ {AVRC_TG_NOTIFY_PLAYER_ID}; // The value of the "Player Id". 263 uint16_t uidCounter_ {AVRC_TG_VENDOR_UID_COUNTER}; // The value of the "UID Counter". 264 uint8_t volume_ {AVRC_ABSOLUTE_VOLUME_INVALID}; // The value of the "Absolute Volume". 265 266 /** 267 * @brief Disassembles the operands behind the "Packet Type" of the frame. 268 * 269 * @details Response frame:<br> 270 * msb lsb<br> 271 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 272 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 273 * 0 0 0 0 | 0 0 0 0 PlayStatus 1 octets<br> 274 * @param[in] pkt The frame packet. 275 */ 276 void AssemblePlaybackStatusChanged(Packet *pkt); 277 278 /** 279 * @brief Disassembles the operands behind the "Packet Type" of the frame. 280 * 281 * @details Response frame:<br> 282 * msb lsb<br> 283 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 284 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 285 * 0 0 0 0 | 0 0 0 0 Identifier 8 octets<br> 286 * @param[in] pkt The frame packet. 287 */ 288 void AssembleTrackChanged(Packet *pkt); 289 290 /** 291 * @brief Disassembles the operands behind the "Packet Type" of the frame. 292 * 293 * @details Response frame:<br> 294 * msb lsb<br> 295 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 296 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 297 * 0 0 0 0 | 0 0 0 0 Playback position 4 octets<br> 298 * @param[in] pkt The frame packet. 299 */ 300 void AssemblePlaybackPosChanged(Packet *pkt); 301 302 /** 303 * @brief Disassembles the operands behind the "Packet Type" of the frame. 304 * 305 * @details Response frame:<br> 306 * msb lsb<br> 307 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 308 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 309 * 0 0 0 0 | 0 0 0 0 NumPlayerApplicationSettingAttributeID 1 octets<br> 310 * 0 0 0 0 | 0 0 0 0 PlayerApplicationSettingAttributeID 1 1 octets<br> 311 * 0 0 0 0 | 0 0 0 0 PlayerApplicationSettingValueID 1 1 octets<br> 312 * 0 0 0 0 | 0 0 0 0 PlayerApplicationSettingAttributeID n 1 octets<br> 313 * 0 0 0 0 | 0 0 0 0 PlayerApplicationSettingValueID n 1 octets<br> 314 * @param[in] pkt The frame packet. 315 */ 316 void AssemblePlayerApplicationSettingChanged(Packet *pkt); 317 318 /** 319 * @brief Disassembles the operands behind the "Packet Type" of the frame. 320 * 321 * @details Response frame:<br> 322 * msb lsb<br> 323 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 324 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 325 * 0 0 0 0 | 0 0 0 0 Player Id 2 octets<br> 326 * 0 0 0 0 | 0 0 0 0 UID Counter 2 octets<br> 327 * @param[in] pkt The frame packet. 328 */ 329 void AssembleAddressedPlayerChanged(Packet *pkt); 330 331 /** 332 * @brief Disassembles the operands behind the "Packet Type" of the frame. 333 * 334 * @details Response frame:<br> 335 * msb lsb<br> 336 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 337 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 338 * 0 0 0 0 | 0 0 0 0 UID Counter 2 octets<br> 339 * @param[in] pkt The frame packet. 340 */ 341 void AssembleUidsChanged(Packet *pkt); 342 343 /** 344 * @brief Disassembles the operands behind the "Packet Type" of the frame. 345 * 346 * @details Response frame:<br> 347 * msb lsb<br> 348 * 0 0 0 0 | 0 0 0 0 Parameter Length 2 octets<br> 349 * 0 0 0 0 | 0 0 0 0 EventID 1 octets<br> 350 * 0 0 0 0 | 0 0 0 0 Absolute Volume 1 octets<br> 351 * @param[in] pkt The frame packet. 352 */ 353 void AssembleVolumeChanged(Packet *pkt); 354 355 void AssembleCommonChanged(Packet *pkt); 356 /** 357 * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance. 358 */ 359 AvrcTgNotifyPacket() = delete; 360 }; 361 } // namespace bluetooth 362 } // namespace OHOS 363 364 #endif // !AVRCP_TG_NOTIFICATION_H