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