1 /*
2  * Copyright (c) 2022-2024 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 OHOS_DSCREEN_CONSTANTS_H
17 #define OHOS_DSCREEN_CONSTANTS_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <unistd.h>
22 
23 namespace OHOS {
24 namespace DistributedHardware {
25 enum RpcEventType {
26     NOTIFY_SINK_SETUP = 1,
27     NOTIFY_SOURCE_SETUP_RESULT = 2,
28 };
29 
30 enum DScreenState {
31     DISABLED,
32     ENABLED,
33     DISABLING,
34     ENABLING,
35     CONNECTING,
36     CONNECTED,
37     DISCONNECTING,
38 };
39 
40 enum TaskType {
41     TASK_ENABLE,
42     TASK_DISABLE,
43     TASK_CONNECT,
44     TASK_DISCONNECT,
45 };
46 
47 enum CodecType : uint8_t {
48     VIDEO_CODEC_TYPE_VIDEO_H264 = 0,
49     VIDEO_CODEC_TYPE_VIDEO_H265 = 1,
50     VIDEO_CODEC_TYPE_VIDEO_MPEG4 = 2,
51 };
52 
53 enum VideoFormat : uint8_t {
54     VIDEO_DATA_FORMAT_YUVI420 = 0,
55     VIDEO_DATA_FORMAT_NV12 = 1,
56     VIDEO_DATA_FORMAT_NV21 = 2,
57     VIDEO_DATA_FORMAT_RGBA8888 = 3,
58 };
59 
60 enum DataType : uint8_t {
61     VIDEO_FULL_SCREEN_DATA = 0,
62     VIDEO_PART_SCREEN_DATA = 1,
63 };
64 
65 enum DScreenMsgType : uint32_t {
66     START_MIRROR = 0,
67     START_MIRROR_SUCCESS = 1,
68     START_MIRROR_FAIL = 2,
69     STOP_MIRROR = 3,
70 };
71 
72 enum DScreenEventType : uint32_t {
73     ENGINE_ERROR = 0,
74     TRANS_CHANNEL_CLOSED = 1,
75 };
76 
77 struct VideoData {
78     uint8_t *data;
79     size_t size;
80     uint32_t width;
81     uint32_t height;
82     int64_t timestamp;
83     std::string format;
84 };
85 
86 /* Screen package name */
87 const std::string PKG_NAME = "ohos.dhardware.dscreen";
88 
89 /* Screen data session name */
90 const std::string DATA_SESSION_NAME = "ohos.dhardware.dscreen.data";
91 const std::string JPEG_SESSION_NAME = "ohos.dhardware.dscreen.jpeg";
92 
93 /* Screen dump data file path name */
94 const std::string DUMP_FILE_PATH = "/data/data/dscreen";
95 
96 /* YUV */
97 constexpr int32_t YR_PARAM = 66;
98 constexpr int32_t YG_PARAM = 129;
99 constexpr int32_t YB_PARAM = 25;
100 constexpr int32_t UR_PARAM = 38;
101 constexpr int32_t UG_PARAM = 74;
102 constexpr int32_t UB_PARAM = 112;
103 constexpr int32_t VG_PARAM = 94;
104 constexpr int32_t VB_PARAM = 18;
105 constexpr int32_t YA_PARAM = 16;
106 constexpr int32_t UA_PARAM = 128;
107 constexpr int32_t YUV_PARAM = 255;
108 constexpr int32_t MOVEBITS = 8;
109 
110 /* RGBA */
111 constexpr uint32_t RGBA_CHROMA = 4;
112 constexpr uint32_t RGB_CHROMA = 3;
113 constexpr uint32_t ONE = 1;
114 constexpr uint32_t TWO = 2;
115 constexpr uint32_t THREE = 3;
116 constexpr uint32_t ZERO = 0;
117 constexpr uint32_t ALIGNEDBITS = 32;
118 
119 /* Screen byte alignment size*/
120 constexpr uint32_t BYTE_ALIGNMENT = 32;
121 constexpr uint32_t BYTE_ALIGNMENT_CALCULATION = 31;
122 
123 /* Screen session name max len */
124 constexpr uint32_t DSCREEN_MAX_SESSION_NAME_LEN = 50;
125 
126 constexpr uint32_t DSCREEN_MAX_DEVICE_ID_LEN = 100;
127 
128 /* Screen data received max length */
129 constexpr uint32_t DSCREEN_MAX_RECV_DATA_LEN = 104857600;
130 
131 /* Screen max video data width */
132 constexpr uint32_t DSCREEN_MAX_VIDEO_DATA_WIDTH = 2560;
133 
134 /* Screen max video data height */
135 constexpr uint32_t DSCREEN_MAX_VIDEO_DATA_HEIGHT = 2772;
136 
137 /* Screen max screen data width */
138 constexpr uint32_t DSCREEN_MAX_SCREEN_DATA_WIDTH = 2560;
139 
140 /* Screen max screen data height */
141 constexpr uint32_t DSCREEN_MAX_SCREEN_DATA_HEIGHT = 2772;
142 
143 /* Screen max display data width */
144 constexpr uint32_t DSCREEN_MAX_DISPLAY_DATA_WIDTH = 2560;
145 
146 /* Screen max display data height */
147 constexpr uint32_t DSCREEN_MAX_DISPLAY_DATA_HEIGHT = 2772;
148 
149 /* Screen dump data max file size */
150 constexpr uint32_t DUMP_FILE_MAX_SIZE = 295 * 1024 * 1024;
151 
152 /* YUV420 buffer size max size */
153 constexpr int64_t MAX_YUV420_BUFFER_SIZE = 2560 * 1600 * (3 / 2) * 2;
154 constexpr int32_t DSCREEN_MAX_LEN = 4096;
155 
156 constexpr int32_t INVALID_WINDOW_ID = -1;
157 constexpr int32_t STRIDE_ALIGNMENT = 0x8;
158 constexpr int32_t SURFACE_SYNC_FENCE_TIMEOUT = 100;
159 
160 const std::string DSCREEN_LOG_TITLE_TAG = "DSCREEN";
161 const std::string DSCREEN_PREFIX = "DISTRIBUTED_SCREEN";
162 const std::string SCREEN_PREFIX = "SCREEN";
163 const std::string DSCREEN_VERSION = "1.0";
164 const std::string DSCREEN_PROCESS_NAME = "dscreen";
165 const std::string SEPERATOR = "#";
166 const std::string KEY_VERSION = "screenVersion";
167 const std::string KEY_DISPLAY_ID = "displayId";
168 const std::string KEY_SCREEN_ID = "screenId";
169 const std::string KEY_DISPLAY_RECT = "displayRect";
170 const std::string KEY_SCREEN_RECT = "screenRect";
171 const std::string KEY_POINT_START_X = "startX";
172 const std::string KEY_POINT_START_Y = "startY";
173 const std::string KEY_POINT_DIRTY_X = "dirtyX";
174 const std::string KEY_POINT_DIRTY_Y = "dirtyY";
175 const std::string KEY_POINT_DIRTY_W = "dirtyW";
176 const std::string KEY_POINT_DIRTY_H = "dirtyH";
177 const std::string KEY_POINT_DIRTY_SIZE = "dirtySize";
178 const std::string KEY_WIDTH = "width";
179 const std::string KEY_HEIGHT = "height";
180 const std::string KEY_SCREEN_WIDTH = "screenWidth";
181 const std::string KEY_SCREEN_HEIGHT = "screenHeight";
182 const std::string KEY_VIDEO_WIDTH = "videoWidth";
183 const std::string KEY_VIDEO_HEIGHT = "videoHeight";
184 const std::string KEY_COLOR_FORMAT = "colorFormat";
185 const std::string KEY_FPS = "fps";
186 const std::string KEY_CODECTYPE = "codecType";
187 const std::string SCREEN_CLIENT_WINDOW = "screenClientWindow";
188 const std::string KEY_DEV_ID = "devId";
189 const std::string KEY_DH_ID = "dhId";
190 const std::string KEY_ERR_CODE = "errCode";
191 const std::string KEY_ERR_CONTENT = "errContent";
192 const std::string KEY_VIDEO_PARAM = "videoParam";
193 const std::string KEY_MAPRELATION = "mapRelation";
194 const std::string KEY_PARTIALREFRESH = "PartialRefresh";
195 const std::string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc";
196 const std::string CODEC_NAME_H265 = "OMX_hisi_video_encoder_hevc";
197 const std::string CODEC_NAME_MPEG4 = "avenc_mpeg4";
198 // Publish massage
199 const std::string SOURCE_WIN_ID = "sourceWinId";
200 const std::string SOURCE_DEV_ID = "sourceDevId";
201 const std::string SINK_DEV_ID = "sinkDevId";
202 const std::string SOURCE_WIN_WIDTH = "sourceWinWidth";
203 const std::string SOURCE_WIN_HEIGHT = "sourceWinHeight";
204 const std::string SINK_SHOW_WIN_ID = "sinkShowWinId";
205 const std::string SINK_PROJ_SHOW_WIDTH = "sinkProjShowWidth";
206 const std::string SINK_PROJ_SHOW_HEIGHT = "sinkProjShowHeight";
207 const std::string SINK_WIN_SHOW_X = "sinkWinShowX";
208 const std::string SINK_WIN_SHOW_Y = "sinkWinShowY";
209 constexpr const char* PARTIAL_REFRESH_PARAM = "persist.distributedhardware.dscreen.partial.refresh.enable";
210 
211 constexpr int32_t DSCREEN_MIN_VERSION = 1;
212 constexpr int32_t AV_TRANS_SUPPORTED_VERSION = 3;
213 constexpr int32_t PARTIAL_REFRESH_ENABLED_VALUE = 1;
214 constexpr uint32_t MAX_MESSAGES_LEN = 40 * 1024 * 1024;
215 constexpr float DEFAULT_DENSITY = 2.0;
216 constexpr int32_t DEFAULT_SCREEN_FLAGS = 0;
217 constexpr double DEFAULT_FPS = 60.0;
218 constexpr uint32_t DIRTY_MAX_SIZE = 10;
219 constexpr uint32_t DIRTY_MAX_BUF_SIZE = 1560000;
220 constexpr uint32_t DIRTY_MAX_IMAGE_DATA_SIZE = 780000;
221 constexpr uint8_t DEFAULT_CODECTYPE = VIDEO_CODEC_TYPE_VIDEO_H264;
222 constexpr uint8_t DEFAULT_VIDEO_FORMAT = VIDEO_DATA_FORMAT_NV12;
223 constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807;
224 constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID = 4808;
225 constexpr uint64_t SCREEN_ID_INVALID = -1ULL;
226 constexpr uint64_t SCREEN_ID_DEFAULT = 0;
227 constexpr int32_t SCREEN_LOADSA_TIMEOUT_MS = 10000;
228 constexpr size_t DID_MAX_SIZE = 256;
229 constexpr size_t PARAM_MAX_SIZE = 50 * 1024 * 1024;
230 constexpr uint8_t SESSION_WAIT_SECONDS = 5;
231 constexpr uint8_t DATA_WAIT_SECONDS = 1;
232 constexpr size_t DATA_QUEUE_MAX_SIZE = 1000;
233 constexpr uint32_t DECODE_WAIT_MILLISECONDS = 5000;
234 constexpr size_t DATA_BUFFER_MAX_SIZE = 10 * 1024 * 1024;
235 constexpr uint8_t TASK_WAIT_SECONDS = 1;
236 constexpr int32_t JPEG_QUALITY = 80;
237 constexpr uint32_t BIT_RATE = 12000000;
238 constexpr int32_t WAIT_TIMEOUT_MS = 5000;
239 constexpr uint32_t SYSTEM_PARAM_VALUE_SIZE = 50;
240 constexpr uint64_t WATCHDOG_INTERVAL_TIME_MS = 20 * 1000;
241 constexpr uint64_t WATCHDOG_DELAY_TIME_MS = 5 * 1000;
242 constexpr int32_t INVALID_SESSION_ID = -1;
243 } // namespace DistributedHardware
244 } // namespace OHOS
245 #endif