FreeRDP
include/freerdp/server/shadow.h
1 
20 #ifndef FREERDP_SERVER_SHADOW_H
21 #define FREERDP_SERVER_SHADOW_H
22 
23 #include <freerdp/api.h>
24 #include <freerdp/types.h>
25 
26 #include <freerdp/freerdp.h>
27 #include <freerdp/settings.h>
28 #include <freerdp/listener.h>
29 
30 #include <freerdp/channels/wtsvc.h>
31 #include <freerdp/channels/channels.h>
32 
33 #include <freerdp/server/encomsp.h>
34 #include <freerdp/server/remdesk.h>
35 #include <freerdp/server/rdpsnd.h>
36 #if defined(CHANNEL_AUDIN_SERVER)
37 #include <freerdp/server/audin.h>
38 #endif
39 #include <freerdp/server/rdpgfx.h>
40 
41 #include <freerdp/codec/color.h>
42 #include <freerdp/codec/region.h>
43 
44 #include <winpr/crt.h>
45 #include <winpr/synch.h>
46 #include <winpr/collections.h>
47 #include <winpr/cmdline.h>
48 
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54  typedef struct rdp_shadow_client rdpShadowClient;
55  typedef struct rdp_shadow_server rdpShadowServer;
56  typedef struct rdp_shadow_screen rdpShadowScreen;
57  typedef struct rdp_shadow_surface rdpShadowSurface;
58  typedef struct rdp_shadow_encoder rdpShadowEncoder;
59  typedef struct rdp_shadow_capture rdpShadowCapture;
60  typedef struct rdp_shadow_subsystem rdpShadowSubsystem;
61  typedef struct rdp_shadow_multiclient_event rdpShadowMultiClientEvent;
62 
63  typedef struct S_RDP_SHADOW_ENTRY_POINTS RDP_SHADOW_ENTRY_POINTS;
64  typedef int (*pfnShadowSubsystemEntry)(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
65 
66  typedef rdpShadowSubsystem* (*pfnShadowSubsystemNew)(void);
67  typedef void (*pfnShadowSubsystemFree)(rdpShadowSubsystem* subsystem);
68 
69  typedef int (*pfnShadowSubsystemInit)(rdpShadowSubsystem* subsystem);
70  typedef int (*pfnShadowSubsystemUninit)(rdpShadowSubsystem* subsystem);
71 
72  typedef int (*pfnShadowSubsystemStart)(rdpShadowSubsystem* subsystem);
73  typedef int (*pfnShadowSubsystemStop)(rdpShadowSubsystem* subsystem);
74 
75  typedef UINT32 (*pfnShadowEnumMonitors)(MONITOR_DEF* monitors, UINT32 maxMonitors);
76 
77  typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
78  const char* user, const char* domain,
79  const char* password);
80  typedef BOOL (*pfnShadowClientConnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client);
81  typedef void (*pfnShadowClientDisconnect)(rdpShadowSubsystem* subsystem,
82  rdpShadowClient* client);
83  typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem,
84  rdpShadowClient* client);
85 
86  typedef BOOL (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem,
87  rdpShadowClient* client, UINT32 flags);
88  typedef BOOL (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
89  UINT16 flags, UINT8 code);
90  typedef BOOL (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem,
91  rdpShadowClient* client, UINT16 flags,
92  UINT16 code);
93  typedef BOOL (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
94  UINT16 flags, UINT16 x, UINT16 y);
95  typedef BOOL (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem,
96  rdpShadowClient* client, UINT16 flags, UINT16 x,
97  UINT16 y);
98 
99  typedef BOOL (*pfnShadowChannelAudinServerReceiveSamples)(rdpShadowSubsystem* subsystem,
100  rdpShadowClient* client,
101  const AUDIO_FORMAT* format,
102  wStream* data);
103 
105  {
106  rdpContext context;
107 
108  HANDLE thread;
109  BOOL activated;
110  BOOL first_frame;
111  BOOL inLobby;
112  BOOL mayView;
113  BOOL mayInteract;
114  BOOL suppressOutput;
115  UINT16 surfaceId;
116  wMessageQueue* MsgQueue;
117  CRITICAL_SECTION lock;
118  REGION16 invalidRegion;
119  rdpShadowServer* server;
120  rdpShadowEncoder* encoder;
121  rdpShadowSubsystem* subsystem;
122 
123  UINT32 pointerX;
124  UINT32 pointerY;
125 
126  HANDLE vcm;
127  EncomspServerContext* encomsp;
128  RemdeskServerContext* remdesk;
129  RdpsndServerContext* rdpsnd;
130 #if defined(CHANNEL_AUDIN_SERVER)
131  audin_server_context* audin;
132 #endif
133  RdpgfxServerContext* rdpgfx;
134 
135  BOOL resizeRequested;
136  UINT32 resizeWidth;
137  UINT32 resizeHeight;
138  BOOL areGfxCapsReady;
139  };
140 
142  {
143  void* ext;
144  HANDLE thread;
145  HANDLE StopEvent;
146  wArrayList* clients;
147  rdpSettings* settings;
148  rdpShadowScreen* screen;
149  rdpShadowSurface* surface;
150  rdpShadowSurface* lobby;
151  rdpShadowCapture* capture;
152  rdpShadowSubsystem* subsystem;
153 
154  DWORD port;
155  BOOL mayView;
156  BOOL mayInteract;
157  BOOL shareSubRect;
158  BOOL authentication;
159  UINT32 selectedMonitor;
160  RECTANGLE_16 subRect;
161 
162  /* Codec settings */
163  RLGR_MODE rfxMode; /* unused */
164  H264_RATECONTROL_MODE h264RateControlMode;
165  UINT32 h264BitRate;
166  UINT32 h264FrameRate;
167  UINT32 h264QP;
168 
169  char* ipcSocket;
170  char* ConfigPath;
171  char* CertificateFile;
172  char* PrivateKeyFile;
173  CRITICAL_SECTION lock;
174  freerdp_listener* listener;
175 
176  size_t maxClientsConnected;
177  };
178 
180  {
181  rdpShadowServer* server;
182 
183  UINT16 x;
184  UINT16 y;
185  UINT32 width;
186  UINT32 height;
187  UINT32 scanline;
188  DWORD format;
189  BYTE* data;
190 
191  CRITICAL_SECTION lock;
192  REGION16 invalidRegion;
193  };
194 
196  {
197  pfnShadowSubsystemNew New;
198  pfnShadowSubsystemFree Free;
199 
200  pfnShadowSubsystemInit Init;
201  pfnShadowSubsystemUninit Uninit;
202 
203  pfnShadowSubsystemStart Start;
204  pfnShadowSubsystemStop Stop;
205 
206  pfnShadowEnumMonitors EnumMonitors;
207  };
208 
210  {
211  RDP_SHADOW_ENTRY_POINTS ep;
212  HANDLE event;
213  UINT32 numMonitors;
214  UINT32 captureFrameRate;
215  UINT32 selectedMonitor;
216  MONITOR_DEF monitors[16];
217  MONITOR_DEF virtualScreen;
218 
219  /* This event indicates that we have graphic change */
220  /* such as screen update and resize. It should not be */
221  /* used by subsystem implementation directly */
222  rdpShadowMultiClientEvent* updateEvent;
223 
224  wMessagePipe* MsgPipe;
225  UINT32 pointerX;
226  UINT32 pointerY;
227 
228  AUDIO_FORMAT* rdpsndFormats;
229  size_t nRdpsndFormats;
230  AUDIO_FORMAT* audinFormats;
231  size_t nAudinFormats;
232 
233  pfnShadowSynchronizeEvent SynchronizeEvent;
234  pfnShadowKeyboardEvent KeyboardEvent;
235  pfnShadowUnicodeKeyboardEvent UnicodeKeyboardEvent;
236  pfnShadowMouseEvent MouseEvent;
237  pfnShadowExtendedMouseEvent ExtendedMouseEvent;
238  pfnShadowChannelAudinServerReceiveSamples AudinServerReceiveSamples;
239 
240  pfnShadowAuthenticate Authenticate;
241  pfnShadowClientConnect ClientConnect;
242  pfnShadowClientDisconnect ClientDisconnect;
243  pfnShadowClientCapabilities ClientCapabilities;
244 
245  rdpShadowServer* server;
246  };
247 
248 /* Definition of message between subsystem and clients */
249 #define SHADOW_MSG_IN_REFRESH_REQUEST_ID 1001
250 
251  typedef struct S_SHADOW_MSG_OUT SHADOW_MSG_OUT;
252  typedef void (*MSG_OUT_FREE_FN)(UINT32 id,
253  SHADOW_MSG_OUT* msg); /* function to free SHADOW_MSG_OUT */
254 
256  {
257  int refCount;
258  MSG_OUT_FREE_FN Free;
259  };
260 
261 #define SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID 2001
262 #define SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID 2002
263 #define SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES_ID 2003
264 #define SHADOW_MSG_OUT_AUDIO_OUT_VOLUME_ID 2004
265 
266  typedef struct
267  {
268  SHADOW_MSG_OUT common;
269  UINT32 xPos;
270  UINT32 yPos;
272 
273  typedef struct
274  {
275  SHADOW_MSG_OUT common;
276  UINT32 xHot;
277  UINT32 yHot;
278  UINT32 width;
279  UINT32 height;
280  UINT32 lengthAndMask;
281  UINT32 lengthXorMask;
282  BYTE* xorMaskData;
283  BYTE* andMaskData;
285 
286  typedef struct
287  {
288  SHADOW_MSG_OUT common;
289  AUDIO_FORMAT* audio_format;
290  void* buf;
291  size_t nFrames;
292  UINT16 wTimestamp;
294 
295  typedef struct
296  {
297  SHADOW_MSG_OUT common;
298  UINT16 left;
299  UINT16 right;
301 
302  FREERDP_API void shadow_subsystem_set_entry_builtin(const char* name);
303  FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry);
304 
305  FREERDP_API WINPR_DEPRECATED_VAR(
306  "[since 3.4.0] Use shadow_subsystem_pointer_convert_alpha_pointer_data_to_format instead",
307  int shadow_subsystem_pointer_convert_alpha_pointer_data(
308  const BYTE* WINPR_RESTRICT pixels, BOOL premultiplied, UINT32 width, UINT32 height,
309  SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor));
310 
324  FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
325  const BYTE* WINPR_RESTRICT pixels, UINT32 format, BOOL premultiplied, UINT32 width,
326  UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor);
327 
328  FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** argv,
329  COMMAND_LINE_ARGUMENT_A* cargs);
330  FREERDP_API int shadow_server_command_line_status_print(rdpShadowServer* server, int argc,
331  char** argv, int status,
332  COMMAND_LINE_ARGUMENT_A* cargs);
333 
334  FREERDP_API int shadow_server_start(rdpShadowServer* server);
335  FREERDP_API int shadow_server_stop(rdpShadowServer* server);
336 
337  FREERDP_API int shadow_server_init(rdpShadowServer* server);
338  FREERDP_API int shadow_server_uninit(rdpShadowServer* server);
339 
340  FREERDP_API UINT32 shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors);
341 
342  FREERDP_API void shadow_server_free(rdpShadowServer* server);
343 
344  WINPR_ATTR_MALLOC(shadow_server_free, 1)
345  FREERDP_API rdpShadowServer* shadow_server_new(void);
346 
347  FREERDP_API int shadow_capture_align_clip_rect(RECTANGLE_16* rect, const RECTANGLE_16* clip);
348 
349  FREERDP_API WINPR_DEPRECATED_VAR(
350  "[since 3.4.0] Use shadow_capture_compare_with_format",
351  int shadow_capture_compare(const BYTE* WINPR_RESTRICT pData1, UINT32 nStep1, UINT32 nWidth,
352  UINT32 nHeight, const BYTE* WINPR_RESTRICT pData2, UINT32 nStep2,
353  RECTANGLE_16* WINPR_RESTRICT rect));
354 
371  FREERDP_API int shadow_capture_compare_with_format(const BYTE* WINPR_RESTRICT pData1,
372  UINT32 format1, UINT32 nStep1, UINT32 nWidth,
373  UINT32 nHeight,
374  const BYTE* WINPR_RESTRICT pData2,
375  UINT32 format2, UINT32 nStep2,
376  RECTANGLE_16* WINPR_RESTRICT rect);
377 
378  FREERDP_API void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem);
379 
380  FREERDP_API BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type,
381  SHADOW_MSG_OUT* msg, void* lParam);
382  FREERDP_API int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type,
383  SHADOW_MSG_OUT* msg, void* lParam);
384  FREERDP_API int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode);
385 
386  FREERDP_API UINT32 shadow_encoder_preferred_fps(rdpShadowEncoder* encoder);
387  FREERDP_API UINT32 shadow_encoder_inflight_frames(rdpShadowEncoder* encoder);
388 
389  FREERDP_API BOOL shadow_screen_resize(rdpShadowScreen* screen);
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 
395 #endif /* FREERDP_SERVER_SHADOW_H */