1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /**
17 * @file avrcp_ct_internal.h
18 *
19 * @brief Declares macros of the AVRCP CT service.
20 */
21
22 #ifndef AVRCP_CT_INTERNAL_H
23 #define AVRCP_CT_INTERNAL_H
24
25 #include <cmath>
26 #include <cstring>
27 #include <deque>
28 #include <functional>
29 #include <list>
30 #include <map>
31 #include <memory>
32 #include <queue>
33 #include <vector>
34
35 #include "avctp.h"
36 #include "base_def.h"
37 #include "btstack.h"
38 #include "interface_profile.h"
39 #include "log.h"
40 #include "log_util.h"
41 #include "message.h"
42 #include "packet.h"
43 #include "raw_address.h"
44 #include "timer.h"
45
46 namespace OHOS {
47 namespace bluetooth {
48 /// The macro used to safely delete the pointer to an object created by[new].
49 template<typename T>
AvrcpCtSafeDelete(T * p)50 void AvrcpCtSafeDelete(T *p)
51 {
52 if (p != nullptr) {
53 delete p;
54 p = nullptr;
55 }
56 }
57
58 /// The macro used to safely delete the pointer to an array of the object created by[new].
59 template<typename T>
AvrcpCtSafeDeleteArray(T * p,int length)60 void AvrcpCtSafeDeleteArray(T *p, int length)
61 {
62 if (p != nullptr && length > 0) {
63 delete[] p;
64 p = nullptr;
65 }
66 }
67 /// The default address of the bluetooth device.
68 static const std::string AVRC_CT_DEFAULT_BLUETOOTH_ADDRESS = "00:00:00:00:00:00";
69 /// The Version of AVRCP Profile is 1.6.
70 static const uint16_t AVRC_CT_PROFILE_REV_1_6 = 0x0106;
71 /// The default mtu size of the control channel.
72 /// 512 bytes is the smallest mtu.
73 static const int AVRC_CT_DEFAULT_CONTROL_MTU_SIZE = 512;
74 /// The default mtu size of the browse channel.
75 static const int AVRC_CT_DEFAULT_BROWSE_MTU_SIZE = 335;
76 /// The default max fragments of the control channel.
77 static const int AVRC_CT_DEFAULT_MAX_FRAGMENTS = 20;
78 /// The default Bluetooth SIG company ID.
79 static const int AVRC_CT_DEFAULT_BLUETOOTH_SIG_COMPANY_ID = 0x001958;
80 /// The AVRCP TG shall return its response frame within 100 milliseconds counting from the receipt of the command
81 /// frame.
82 /// Therefor, add an additional 1000 milliseconds, and use it as the timer for preventing that the AVRCP TG has not
83 /// a
84 /// response.
85 static const int AVRC_CT_TIMER_T_RCP = 100;
86
87 /// The AVRCP TG shall return its response frame within 200 milliseconds counting from the receipt of the command
88 /// frame.
89 /// Therefor, add an additional 1000 milliseconds, and use it as the timer for preventing that the AVRCP TG has not
90 /// a
91 /// response.
92 static const int AVRC_CT_TIMER_T_MTC = 200;
93
94 /// The AVRCP TG shall return its response frame within 1000 milliseconds counting from the receipt of the command
95 /// frame. Therefor, add an additional 1000 milliseconds, and use it as the timer for preventing that the AVRCP TG
96 /// has
97 /// not a response.
98 static const int AVRC_CT_TIMER_T_MTP = 1000;
99
100 /// A command with the pressed value is valid for two seconds from the time when a target sends back a response of
101 /// the
102 /// command.
103 /// @see AV/C Panel Subunit Specification 1.23 Section 9.4 PASS THROUGH control command.
104 static const int AVRC_CT_TIMER_PASS_THROUGH = 2000;
105
106 /// The default size of the command queue.
107 /// This means how many commands can be cached for a connection.
108 static const int AVRC_CT_DEFAULT_SIZE_OF_QUEUE = 20;
109
110 /// The maximum of number of device connections
111 static const int AVRC_CT_DEFAULT_MAX_OF_CONN = 6;
112 /**
113 * @brief This enumeration declares applicable to service class UUIDs that are registered into the SDP.
114 */
115 using AvrcCtServiceClassUUIDs = enum {
116 /// A/V remote control target.
117 AVRC_CT_AV_REMOTE_CONTROL_TARGET = 0x110C,
118 /// A/V remote control.
119 /// NOTE: Used as both Service Class Identifier and Profile Identifier.
120 AVRC_CT_AV_REMOTE_CONTROL = 0x110E,
121 /// A/V remote control controller.
122 /// NOTE: The AVRCP specification v1.3 and later require that 0x110E also be included in the ServiceClassIDList
123 /// before 0x110F for backwards compatibility.
124 AVRC_CT_AV_REMOTE_CONTROL_CONTROLLER = 0x110F,
125 };
126
127 /**
128 * @brief This enumeration declares the values of the moving bit
129 */
130 enum AvrcCtFeatureMoveBit {
131 AVRC_CT_FEATURE_MOVE_BIT_1 = 0x01,
132 AVRC_CT_FEATURE_MOVE_BIT_2 = 0x02,
133 AVRC_CT_FEATURE_MOVE_BIT_3 = 0x03,
134 AVRC_CT_FEATURE_MOVE_BIT_6 = 0x06,
135 AVRC_CT_FEATURE_MOVE_BIT_7 = 0x07,
136 AVRC_CT_FEATURE_MOVE_BIT_8 = 0x08,
137 AVRC_CT_FEATURE_MOVE_BIT_9 = 0x09,
138 AVRC_CT_FEATURE_MOVE_BIT_16 = 0x10,
139 AVRC_CT_FEATURE_MOVE_BIT_17 = 0x11,
140 AVRC_CT_FEATURE_MOVE_BIT_18 = 0x12,
141 AVRC_CT_FEATURE_MOVE_BIT_19 = 0x13,
142 AVRC_CT_FEATURE_MOVE_BIT_20 = 0x14,
143 AVRC_CT_FEATURE_MOVE_BIT_21 = 0x15,
144 AVRC_CT_FEATURE_MOVE_BIT_22 = 0x16,
145 AVRC_CT_FEATURE_MOVE_BIT_23 = 0x17,
146 AVRC_CT_FEATURE_MOVE_BIT_24 = 0x18,
147 AVRC_CT_FEATURE_MOVE_BIT_25 = 0x19,
148 };
149
150 /**
151 * @brief This enumeration declares features that are supported by the AVRCP CT profile.
152 *
153 * @detail Some of the features will be registered into the SDP.
154 * @see Audio/Video Remote Control 1.6.2 Section 8 Service discovery interoperability requirements ->
155 * Table 8.2: Service record for TG.
156 */
157 using AvrcCtFeatures = enum {
158 /// Invalid value.
159 AVRC_CT_FEATURE_INVALID_FEATURE = 0x0000,
160
161 /// Supported category 1: player/recorder.
162 AVRC_CT_FEATURE_CATEGORY_1 = 0x0001,
163 /// Supported category 2: monitor/amplifier.
164 AVRC_CT_FEATURE_CATEGORY_2 = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_1),
165 /// Supported category 3: tuner.
166 AVRC_CT_FEATURE_CATEGORY_3 = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_2),
167 /// Supported category 4: menu.
168 AVRC_CT_FEATURE_CATEGORY_4 = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_3),
169 /// Supported browsing.
170 /// This in the SDP record shall only be supported if browsing of the "Media Player Virtual File system" is
171 /// supported.
172 AVRC_CT_FEATURE_BROWSING = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_6),
173 /// Supported cover art GetImageProperties.
174 AVRC_CT_FEATURE_COVER_ART_IMAGE_PROPERTIES = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_7),
175 /// Supported cover art GetImage.
176 AVRC_CT_FEATURE_COVER_ART_IMAGE = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_8),
177 /// Supported covert art GetLinkedThumbnail.
178 AVRC_CT_FEATURE_COVER_ART_THUMBNAIL = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_9),
179
180 /// Supported the key operation.
181 AVRC_CT_FEATURE_KEY_OPERATION = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_16),
182 /// Supported the absolute volume.
183 AVRC_CT_FEATURE_ABSOLUTE_VOLUME = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_17),
184 /// Supported the notification of "PLAYBACK_STATUS_CHANGED"
185 AVRC_CT_FEATURE_NOTIFY_PLAYBACK_STATUS_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_18),
186 /// Supported the notification of "TRACK_REACHED_END"
187 AVRC_CT_FEATURE_NOTIFY_TRACK_REACHED_END = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_19),
188 /// Supported the notification of "TRACK_REACHED_START"
189 AVRC_CT_FEATURE_NOTIFY_TRACK_REACHED_START = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_20),
190 /// Supported the notification of "PLAYBACK_POSITION_CHANGED"
191 AVRC_CT_FEATURE_NOTIFY_PLAYBACK_POSITION_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_21),
192 /// Supported the notification of "PLAYER_SETTING_CHANGED"
193 AVRC_CT_FEATURE_NOTIFY_PLAYER_SETTING_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_22),
194 /// Supported the notification of "NOW_PLAYING_CONTENT_CHANGED"
195 AVRC_CT_FEATURE_NOTIFY_NOW_PLAYING_CONTENT_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_23),
196 /// Supported the notification of "UIDS_CHANGED"
197 AVRC_CT_FEATURE_NOTIFY_UIDS_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_24),
198 /// Supported the notification of "ABSOLUTE_VOLUME_CHANGED"
199 AVRC_CT_FEATURE_NOTIFY_ABSOLUTE_VOLUME_CHANGED = (AVRC_CT_FEATURE_CATEGORY_1 << AVRC_CT_FEATURE_MOVE_BIT_25),
200 };
201 } // namespace bluetooth
202 } // namespace OHOS
203
204 #endif // !AVRCP_CT_INTERNAL_H
205