• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CT_NOTIFICATION_H
17 #define AVRCP_CT_NOTIFICATION_H
18 
19 #include "avrcp_ct_packet.h"
20 #include "avrcp_ct_vendor.h"
21 
22 namespace OHOS {
23 namespace bluetooth {
24 /**
25  * @brief This enumeration declares the values of the "EVENT ID".
26  * @see Audio/Video Remote Control 1.6.2 Section 28 Appendix H: list of defined notification events.
27  */
28 enum AvrcCtEventId : uint32_t {
29     AVRC_CT_EVENT_ID_PLAYBACK_STATUS_CHANGED = 0x01,  // Change in playback status of the current track.
30     AVRC_CT_EVENT_ID_TRACK_CHANGED,                   // Change of current track.
31     AVRC_CT_EVENT_ID_TRACK_REACHED_END,               // Reached end of a track.
32     AVRC_CT_EVENT_ID_TRACK_REACHED_START,             // Reached start of a track.
33     // Change in playback position. Returned after the specified playback notification change notification interval.
34     AVRC_CT_EVENT_ID_PLAYBACK_POS_CHANGED,
35     AVRC_CT_EVENT_ID_BATT_STATUS_CHANGED,                 // Change in battery status.
36     AVRC_CT_EVENT_ID_SYSTEM_STATUS_CHANGED,               // Change in system status.
37     AVRC_CT_EVENT_ID_PLAYER_APPLICATION_SETTING_CHANGED,  // Change in player application setting.
38     AVRC_CT_EVENT_ID_NOW_PLAYING_CONTENT_CHANGED,         // The content of the Now Playing list has changed.
39     AVRC_CT_EVENT_ID_AVAILABLE_PLAYERS_CHANGED,           // The available players have changed
40     AVRC_CT_EVENT_ID_ADDRESSED_PLAYER_CHANGED,            // The Addressed Player has been changed.
41     AVRC_CT_EVENT_ID_UIDS_CHANGED,                        // The UIDs have changed.
42     AVRC_CT_EVENT_ID_VOLUME_CHANGED,                      // The volume has been changed locally on the TG.
43     AVRC_CT_EVENT_ID_RESERVED = 0x0E,
44 };
45 
46 /**
47  * @brief This enumeration declares the values of the <b>NOTIFICATION</b> commands.
48  */
49 enum AvrcCtNotify {
50     AVRC_CT_NOTIFY_PARAMETER_LENGTH = 0x0005,       // The length of the "Parameter Length".
51     AVRC_CT_NOTIFY_PLAYER_ID = 0xFFFF,              // The value of the "Player Id".
52     AVRC_CT_NOTIFY_PLAYBACK_POSITION = 0xFFFFFFFF,  // The value of the "Playback position".
53     AVRC_CT_NOTIFY_EVENT_ID_OFFSET = 0x0A,          // The offset of the "Event ID".
54     AVRC_CT_NOTIFY_EVENT_ID_SIZE = 0x01,            // The size of the "Event ID".
55 };
56 
57 /**
58  * @brief This class provides a set of methods of assemble / disassemble the packet of the <b>NOTIFICATION</b>
59  * command.
60  * @see Audio/Video Remote Control 1.6.2 Section 6.7.2 RegisterNotification.
61  */
62 class AvrcCtNotifyPacket : public AvrcCtVendorPacket {
63 public:
64     /**
65      * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance.
66      */
67     explicit AvrcCtNotifyPacket(uint8_t eventId, uint32_t interval = AVRC_PLAYBACK_INTERVAL_1_SEC);
68 
69     /**
70      * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance.
71      */
72     explicit AvrcCtNotifyPacket(Packet *pkt);
73 
74     /**
75      * @brief A destructor used to delete the <b>AvrcCtNotifyPacket</b> instance.
76      */
77     virtual ~AvrcCtNotifyPacket();
78 
79     /**
80      * @brief Assembles the operands behind the "Packet Type" of the frame.
81      *
82      * @details Command frame:<br>
83      *                        msb           lsb<br>
84      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
85      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
86      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
87      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
88      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
89      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
90      *
91      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
92      *                        0 0 0 0 | 0 0 0 0     EventID                                             1 octets<br>
93      *                        0 0 0 0 | 0 0 0 0     Playback interval                                   4 octets<br>
94      * @param[in] pkt The frame packet.
95      * @return The frame packet.
96      */
97     Packet *AssembleParameters(Packet *pkt) override;
98 
99     /**
100      * @brief Disassembles the operands behind the "Packet Type" of the frame.
101      *
102      * @details Response frame:<br>
103      *                        msb           lsb<br>
104      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
105      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
106      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
107      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
108      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
109      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
110      *
111      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
112      *                        0 0 0 0 | 0 0 0 0     EventID                                             1 octets<br>
113      * @param[in] buffer The buffer of the frame.
114      * @return The result of the method execution.
115      * @retval true  The packet is valid.
116      * @retval false The packet is invalid.
117      */
118     bool DisassembleParameters(uint8_t *buffer) override;
119 
120     /**
121      * @brief Gets the "Packet Type".
122      *
123      * @return The value of the "Packet Type".
124      */
GetPacketType(void)125     uint8_t GetPacketType(void) const
126     {
127         return packetType_;
128     }
129 
130     /**
131      * @brief Clears the "PlayerApplicationSettingAttributeID".
132      *
133      * @return The values of the "PlayerApplicationSettingValueID".
134      */
ClearAttributes(void)135     void ClearAttributes(void)
136     {
137         attributes_.clear();
138     }
139 
140     /**
141      * @brief Gets the "EventID".
142      *
143      * @return The value of the "EventID".
144      */
GetEventId(void)145     uint8_t GetEventId(void) const
146     {
147         return eventId_;
148     }
149 
150     /**
151      * @brief Gets the "PlayStatus".
152      *
153      * @return The value of the "PlayStatus".
154      */
GetPlayStatus(void)155     uint8_t GetPlayStatus(void) const
156     {
157         return playStatus_;
158     }
159 
160     /**
161      * @brief Gets the "Identifier".
162      *
163      * @return The value of the "Identifier".
164      */
GetUid(void)165     uint64_t GetUid(void) const
166     {
167         return uid_;
168     }
169 
170     /**
171      * @brief Gets the "Playback position".
172      *
173      * @return The value of the "Playback position".
174      */
GetPlaybackPosition(void)175     uint32_t GetPlaybackPosition(void) const
176     {
177         return playbackPos_;
178     }
179 
180     /**
181      * @brief Gets the "PlayerApplicationSettingAttributeID".
182      *
183      * @return The value of the "PlayerApplicationSettingAttributeID".
184      */
GetAttributes(void)185     const std::vector<uint8_t> &GetAttributes(void) const
186     {
187         return attributes_;
188     }
189 
190     /**
191      * @brief Gets the "PlayerApplicationSettingValueID".
192      *
193      * @return The value of the "PlayerApplicationSettingValueID".
194      */
GetValues(void)195     const std::vector<uint8_t> &GetValues(void) const
196     {
197         return values_;
198     }
199 
200     /**
201      * @brief Gets the "Player Id".
202      *
203      * @return The value of the "Player Id".
204      */
GetPlayerId(void)205     uint16_t GetPlayerId(void) const
206     {
207         return playerId_;
208     }
209 
210     /**
211      * @brief Gets the "UID Counter".
212      *
213      * @return The value of the "UID Counter".
214      */
GetUidCounter(void)215     uint16_t GetUidCounter(void) const
216     {
217         return uidCounter_;
218     }
219 
220     /**
221      * @brief Gets the absolute volume.
222      *
223      * @return The value of the "Absolute Volume".
224      */
GetAbsoluteVolume(void)225     uint8_t GetAbsoluteVolume(void) const
226     {
227         return volume_;
228     }
229 
230 private:
231     uint8_t eventId_ {AVRC_CT_EVENT_ID_RESERVED};              // The value of the "EventID".
232     uint32_t interval_ {AVRC_PLAYBACK_INTERVAL_1_SEC};         // The value of the "Playback interval".
233     uint8_t playStatus_ {AVRC_PLAY_STATUS_ERROR};              // The value of the "PlayStatus".
234     uint64_t uid_ {AVRC_CT_VENDOR_UID};                        // The value of the "Identifier".
235     uint32_t playbackPos_ {AVRC_CT_NOTIFY_PLAYBACK_POSITION};  // The value of the "Playback position".
236     std::vector<uint8_t> attributes_ {};
237     // The value of the "PlayerApplicationSettingAttributeID".
238     std::vector<uint8_t> values_ {};                           // The value of the "PlayerApplicationSettingValueID".
239     uint16_t playerId_ {AVRC_CT_NOTIFY_PLAYER_ID};             // The value of the "Player Id".
240     uint16_t uidCounter_ {AVRC_CT_VENDOR_UID_COUNTER};         // The value of the "UID Counter".
241     uint8_t volume_ {AVRC_ABSOLUTE_VOLUME_INVALID};            // The value of the "Absolute Volume".
242 
243     /**
244      * @brief Disassembles the operands behind the "Packet Type" of the frame.
245      *
246      * @details Response frame:<br>
247      *                        msb           lsb<br>
248      *                        0 0 0 0 | 0 0 0 0     PlayStatus                                          1 octets<br>
249      * @param[in] buffer The buffer of the frame.
250      * @return The result of the method execution.
251      * @retval true  The packet is valid.
252      * @retval false The packet is invalid.
253      */
254     bool DisassemblePlaybackStatus(uint8_t *buffer);
255 
256     /**
257      * @brief Disassembles the operands behind the "Packet Type" of the frame.
258      *
259      * @details Response frame:<br>
260      *                        msb           lsb<br>
261      *                        0 0 0 0 | 0 0 0 0     Identifier                                          8 octets<br>
262      * @param[in] buffer The buffer of the frame.
263      * @return The result of the method execution.
264      * @retval true  The packet is valid.
265      * @retval false The packet is invalid.
266      */
267     bool DisassembleTrackChanged(uint8_t *buffer);
268 
269     /**
270      * @brief Disassembles the operands behind the "Packet Type" of the frame.
271      *
272      * @details Response frame:<br>
273      *                        msb           lsb<br>
274      *                        0 0 0 0 | 0 0 0 0     Playback position                                   4 octets<br>
275      * @param[in] buffer The buffer of the frame.
276      * @return The result of the method execution.
277      * @retval true  The packet is valid.
278      * @retval false The packet is invalid.
279      */
280     bool DisassemblePlaybackPosChanged(uint8_t *buffer);
281 
282     /**
283      * @brief Disassembles the operands behind the "Packet Type" of the frame.
284      *
285      * @details Response frame:<br>
286      *                        msb           lsb<br>
287      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingAttributeID              1 octets<br>
288      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID 1               1 octets<br>
289      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID 1                   1 octets<br>
290      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID n               1 octets<br>
291      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID n                   1 octets<br>
292      * @param[in] buffer The buffer of the frame.
293      * @return The result of the method execution.
294      * @retval true  The packet is valid.
295      * @retval false The packet is invalid.
296      */
297     bool DisassemblePlayerApplicationSettingChanged(uint8_t *buffer);
298 
299     /**
300      * @brief Disassembles the operands behind the "Packet Type" of the frame.
301      *
302      * @details Response frame:<br>
303      *                        msb           lsb<br>
304      *                        0 0 0 0 | 0 0 0 0     Player Id                                           2 octets<br>
305      *                        0 0 0 0 | 0 0 0 0     UID Counter                                         2 octets<br>
306      * @param[in] buffer The buffer of the frame.
307      * @return The result of the method execution.
308      * @retval true  The packet is valid.
309      * @retval false The packet is invalid.
310      */
311     bool DisassembleAddressedPlayerChanged(uint8_t *buffer);
312 
313     /**
314      * @brief Disassembles the operands behind the "Packet Type" of the frame.
315      *
316      * @details Response frame:<br>
317      *                        msb           lsb<br>
318      *                        0 0 0 0 | 0 0 0 0     UID Counter                                         2 octets<br>
319      * @param[in] buffer The buffer of the frame.
320      * @return The result of the method execution.
321      * @retval true  The packet is valid.
322      * @retval false The packet is invalid.
323      */
324     bool DisassembleUidsChanged(uint8_t *buffer);
325 
326     /**
327      * @brief Disassembles the operands behind the "Packet Type" of the frame.
328      *
329      * @details Response frame:<br>
330      *                        msb           lsb<br>
331      *                        0 0 0 0 | 0 0 0 0     Absolute Volume                                     1 octets<br>
332      * @param[in] buffer The buffer of the frame.
333      * @return The result of the method execution.
334      * @retval true  The packet is valid.
335      * @retval false The packet is invalid.
336      */
337     bool DisassembleVolumeChanged(uint8_t *buffer);
338 
339     /**
340      * @brief A constructor used to create an <b>AvrcCtNotifyPacket</b> instance.
341      */
342     AvrcCtNotifyPacket() = delete;
343 };
344 }  // namespace bluetooth
345 }  // namespace OHOS
346 
347 #endif  // !AVRCP_CT_NOTIFICATION_H