1 /*
2  * Copyright (c) 2022-2023 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 dump data max file size */
144 constexpr uint32_t DUMP_FILE_MAX_SIZE = 295 * 1024 * 1024;
145 
146 /* YUV420 buffer size max size */
147 constexpr int64_t MAX_YUV420_BUFFER_SIZE = 2560 * 1600 * (3 / 2) * 2;
148 constexpr int32_t DSCREEN_MAX_LEN = 4096;
149 
150 constexpr int32_t INVALID_WINDOW_ID = -1;
151 constexpr int32_t STRIDE_ALIGNMENT = 0x8;
152 constexpr int32_t SURFACE_SYNC_FENCE_TIMEOUT = 100;
153 
154 const std::string DSCREEN_LOG_TITLE_TAG = "DSCREEN";
155 const std::string DSCREEN_PREFIX = "DISTRIBUTED_SCREEN";
156 const std::string SCREEN_PREFIX = "SCREEN";
157 const std::string DSCREEN_VERSION = "1.0";
158 const std::string DSCREEN_PROCESS_NAME = "dscreen";
159 const std::string SEPERATOR = "#";
160 const std::string KEY_VERSION = "screenVersion";
161 const std::string KEY_DISPLAY_ID = "displayId";
162 const std::string KEY_SCREEN_ID = "screenId";
163 const std::string KEY_DISPLAY_RECT = "displayRect";
164 const std::string KEY_SCREEN_RECT = "screenRect";
165 const std::string KEY_POINT_START_X = "startX";
166 const std::string KEY_POINT_START_Y = "startY";
167 const std::string KEY_POINT_DIRTY_X = "dirtyX";
168 const std::string KEY_POINT_DIRTY_Y = "dirtyY";
169 const std::string KEY_POINT_DIRTY_W = "dirtyW";
170 const std::string KEY_POINT_DIRTY_H = "dirtyH";
171 const std::string KEY_POINT_DIRTY_SIZE = "dirtySize";
172 const std::string KEY_WIDTH = "width";
173 const std::string KEY_HEIGHT = "height";
174 const std::string KEY_SCREEN_WIDTH = "screenWidth";
175 const std::string KEY_SCREEN_HEIGHT = "screenHeight";
176 const std::string KEY_VIDEO_WIDTH = "videoWidth";
177 const std::string KEY_VIDEO_HEIGHT = "videoHeight";
178 const std::string KEY_COLOR_FORMAT = "colorFormat";
179 const std::string KEY_FPS = "fps";
180 const std::string KEY_CODECTYPE = "codecType";
181 const std::string SCREEN_CLIENT_WINDOW = "screenClientWindow";
182 const std::string KEY_DEV_ID = "devId";
183 const std::string KEY_DH_ID = "dhId";
184 const std::string KEY_ERR_CODE = "errCode";
185 const std::string KEY_ERR_CONTENT = "errContent";
186 const std::string KEY_VIDEO_PARAM = "videoParam";
187 const std::string KEY_MAPRELATION = "mapRelation";
188 const std::string KEY_PARTIALREFREAH = "PartialRefresh";
189 const std::string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc";
190 const std::string CODEC_NAME_H265 = "OMX_hisi_video_encoder_hevc";
191 const std::string CODEC_NAME_MPEG4 = "avenc_mpeg4";
192 // Publish massage
193 const std::string SOURCE_WIN_ID = "sourceWinId";
194 const std::string SOURCE_DEV_ID = "sourceDevId";
195 const std::string SINK_DEV_ID = "sinkDevId";
196 const std::string SOURCE_WIN_WIDTH = "sourceWinWidth";
197 const std::string SOURCE_WIN_HEIGHT = "sourceWinHeight";
198 const std::string SINK_SHOW_WIN_ID = "sinkShowWinId";
199 const std::string SINK_PROJ_SHOW_WIDTH = "sinkProjShowWidth";
200 const std::string SINK_PROJ_SHOW_HEIGHT = "sinkProjShowHeight";
201 const std::string SINK_WIN_SHOW_X = "sinkWinShowX";
202 const std::string SINK_WIN_SHOW_Y = "sinkWinShowY";
203 constexpr const char* PARTIAL_REFRESH_PARAM = "persist.distributedhardware.dscreen.partial.refresh.enable";
204 
205 constexpr int32_t DSCREEN_MIN_VERSION = 1;
206 constexpr int32_t AV_TRANS_SUPPORTED_VERSION = 3;
207 constexpr int32_t PARTIAL_REFRESH_ENABLED_VALUE = 1;
208 constexpr uint32_t MAX_MESSAGES_LEN = 40 * 1024 * 1024;
209 constexpr float DEFAULT_DENSITY = 2.0;
210 constexpr int32_t DEFAULT_SCREEN_FLAGS = 0;
211 constexpr double DEFAULT_FPS = 60.0;
212 constexpr int32_t DIRTY_MAX_SIZE = 10;
213 constexpr uint8_t DEFAULT_CODECTYPE = VIDEO_CODEC_TYPE_VIDEO_H264;
214 constexpr uint8_t DEFAULT_VIDEO_FORMAT = VIDEO_DATA_FORMAT_NV12;
215 constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807;
216 constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID = 4808;
217 constexpr uint64_t SCREEN_ID_INVALID = -1ULL;
218 constexpr uint64_t SCREEN_ID_DEFAULT = 0;
219 constexpr int32_t SCREEN_LOADSA_TIMEOUT_MS = 10000;
220 constexpr size_t DID_MAX_SIZE = 256;
221 constexpr size_t PARAM_MAX_SIZE = 50 * 1024 * 1024;
222 constexpr uint8_t SESSION_WAIT_SECONDS = 5;
223 constexpr uint8_t DATA_WAIT_SECONDS = 1;
224 constexpr size_t DATA_QUEUE_MAX_SIZE = 1000;
225 constexpr uint32_t DECODE_WAIT_MILLISECONDS = 5000;
226 constexpr size_t DATA_BUFFER_MAX_SIZE = 10 * 1024 * 1024;
227 constexpr uint8_t TASK_WAIT_SECONDS = 1;
228 constexpr int32_t JPEG_QUALITY = 80;
229 constexpr uint32_t BIT_RATE = 12000000;
230 constexpr int32_t WAIT_TIMEOUT_MS = 5000;
231 constexpr uint32_t SYSTEM_PARAM_VALUE_SIZE = 50;
232 constexpr uint64_t WATCHDOG_INTERVAL_TIME_MS = 20 * 1000;
233 constexpr uint64_t WATCHDOG_DELAY_TIME_MS = 5 * 1000;
234 constexpr int32_t INVALID_SESSION_ID = -1;
235 } // namespace DistributedHardware
236 } // namespace OHOS
237 #endif