Kitxuuu commited on
Commit
3f1d7ac
·
verified ·
1 Parent(s): 4f85dc1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. local-test-freerdp-full-01/afc-freerdp/docs/mingw-example/build_ia32.sh +4 -0
  2. local-test-freerdp-full-01/afc-freerdp/docs/mingw-example/toolchain/meson/aarch64.txt +15 -0
  3. local-test-freerdp-full-01/afc-freerdp/server/Mac/CMakeLists.txt +77 -0
  4. local-test-freerdp-full-01/afc-freerdp/server/Mac/ModuleOptions.cmake +3 -0
  5. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_audin.c +64 -0
  6. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_audin.h +33 -0
  7. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_event.c +219 -0
  8. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_event.h +75 -0
  9. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_info.c +231 -0
  10. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_info.h +49 -0
  11. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_input.h +36 -0
  12. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_interface.c +0 -0
  13. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_interface.h +106 -0
  14. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_mountain_lion.c +269 -0
  15. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_mountain_lion.h +38 -0
  16. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_peer.c +485 -0
  17. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_peer.h +33 -0
  18. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_rdpsnd.c +200 -0
  19. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_rdpsnd.h +58 -0
  20. local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_types.h +33 -0
  21. local-test-freerdp-full-01/afc-freerdp/server/Mac/mfreerdp.c +108 -0
  22. local-test-freerdp-full-01/afc-freerdp/server/Mac/mfreerdp.h +28 -0
  23. local-test-freerdp-full-01/afc-freerdp/server/Sample/CMakeLists.txt +63 -0
  24. local-test-freerdp-full-01/afc-freerdp/server/Sample/ModuleOptions.cmake +3 -0
  25. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_ainput.c +92 -0
  26. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_ainput.h +37 -0
  27. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_audin.c +112 -0
  28. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_audin.h +35 -0
  29. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_encomsp.c +43 -0
  30. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_encomsp.h +31 -0
  31. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_rdpsnd.c +62 -0
  32. local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_rdpsnd.h +31 -0
  33. local-test-freerdp-full-01/afc-freerdp/server/Sample/sfreerdp.c +1472 -0
  34. local-test-freerdp-full-01/afc-freerdp/server/Sample/sfreerdp.h +76 -0
  35. local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.ppm +5572 -0
  36. local-test-freerdp-full-01/afc-freerdp/server/Windows/CMakeLists.txt +82 -0
  37. local-test-freerdp-full-01/afc-freerdp/server/Windows/ModuleOptions.cmake +3 -0
  38. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_directsound.c +219 -0
  39. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_directsound.h +13 -0
  40. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_dxgi.c +486 -0
  41. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_dxgi.h +41 -0
  42. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_info.c +402 -0
  43. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_info.h +46 -0
  44. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_input.c +223 -0
  45. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_input.h +36 -0
  46. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_interface.c +341 -0
  47. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_interface.h +140 -0
  48. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_mirage.c +361 -0
  49. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_mirage.h +219 -0
  50. local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_peer.c +414 -0
local-test-freerdp-full-01/afc-freerdp/docs/mingw-example/build_ia32.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ export ARCH=i686
4
+ . ./_build.sh
local-test-freerdp-full-01/afc-freerdp/docs/mingw-example/toolchain/meson/aarch64.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [binaries]
2
+ c = 'aarch64-w64-mingw32-gcc'
3
+ cpp = 'aarch64-w64-mingw32-g++'
4
+ ar = 'aarch64-w64-mingw32-ar'
5
+ ld = 'aarch64-w64-mingw32-ld'
6
+ strip = 'aarch64-w64-mingw32-strip'
7
+
8
+ [host_machine]
9
+ system = 'windows'
10
+ cpu_family = 'aarch64'
11
+ cpu = 'native'
12
+ endian = 'little'
13
+
14
+ [properties]
15
+ platform = 'generic_aarch64'
local-test-freerdp-full-01/afc-freerdp/server/Mac/CMakeLists.txt ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Mac OS X Server cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ set(MODULE_NAME "mfreerdp-server")
19
+ set(MODULE_PREFIX "FREERDP_SERVER_MAC")
20
+
21
+ find_library(AUDIO_TOOL AudioToolbox)
22
+ find_library(CORE_AUDIO CoreAudio)
23
+ find_library(CORE_VIDEO CoreVideo)
24
+ find_library(APP_SERVICES ApplicationServices)
25
+ find_library(IOKIT IOKit)
26
+ find_library(IOSURFACE IOSurface)
27
+ find_library(CARBON Carbon)
28
+
29
+ set(${MODULE_PREFIX}_SRCS
30
+ mfreerdp.c
31
+ mfreerdp.h
32
+ mf_interface.c
33
+ mf_interface.h
34
+ mf_event.c
35
+ mf_event.h
36
+ mf_peer.c
37
+ mf_peer.h
38
+ mf_info.c
39
+ mf_info.h
40
+ mf_input.c
41
+ mf_input.h
42
+ mf_mountain_lion.c
43
+ mf_mountain_lion.h
44
+ )
45
+
46
+ if(CHANNEL_AUDIN_SERVER)
47
+ set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} mf_audin.c mf_audin.h)
48
+ endif()
49
+
50
+ if(CHANNEL_RDPSND_SERVER)
51
+ set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} mf_rdpsnd.c mf_rdpsnd.h)
52
+
53
+ endif()
54
+
55
+ add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
56
+ if(WITH_BINARY_VERSIONING)
57
+ set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_NAME}${FREERDP_API_VERSION}")
58
+ endif()
59
+
60
+ set(${MODULE_PREFIX}_LIBS
61
+ ${${MODULE_PREFIX}_LIBS}
62
+ freerdp-server
63
+ ${AUDIO_TOOL}
64
+ ${CORE_AUDIO}
65
+ ${CORE_VIDEO}
66
+ ${APP_SERVICES}
67
+ ${IOKIT}
68
+ ${IOSURFACE}
69
+ ${CARBON}
70
+ )
71
+
72
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp)
73
+
74
+ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
75
+ install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
76
+
77
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Mac")
local-test-freerdp-full-01/afc-freerdp/server/Mac/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_SERVER_NAME "mfreerdp-server")
2
+ set(FREERDP_SERVER_PLATFORM "X11")
3
+ set(FREERDP_SERVER_VENDOR "FreeRDP")
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_audin.c ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server (Audio Input)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2015 Thincast Technologies GmbH
7
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
8
+ * Copyright 2023 Pascal Nowack <[email protected]>
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ #include <freerdp/config.h>
24
+
25
+ #include "mfreerdp.h"
26
+
27
+ #include "mf_audin.h"
28
+ #include "mf_interface.h"
29
+
30
+ #include <freerdp/server/server-common.h>
31
+ #include <freerdp/log.h>
32
+ #define TAG SERVER_TAG("mac")
33
+
34
+ static UINT mf_peer_audin_data(audin_server_context* audin, const SNDIN_DATA* data)
35
+ {
36
+ /* TODO: Implement */
37
+ WINPR_ASSERT(audin);
38
+ WINPR_ASSERT(data);
39
+
40
+ WLog_WARN(TAG, "not implemented");
41
+ WLog_DBG(TAG, "receive %" PRIdz " bytes.", Stream_Length(data->Data));
42
+ return CHANNEL_RC_OK;
43
+ }
44
+
45
+ BOOL mf_peer_audin_init(mfPeerContext* context)
46
+ {
47
+ WINPR_ASSERT(context);
48
+
49
+ context->audin = audin_server_context_new(context->vcm);
50
+ context->audin->rdpcontext = &context->_p;
51
+ context->audin->userdata = context;
52
+
53
+ context->audin->Data = mf_peer_audin_data;
54
+
55
+ return audin_server_set_formats(context->audin, -1, NULL);
56
+ }
57
+
58
+ void mf_peer_audin_uninit(mfPeerContext* context)
59
+ {
60
+ WINPR_ASSERT(context);
61
+
62
+ audin_server_context_free(context->audin);
63
+ context->audin = NULL;
64
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_audin.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server (Audio Input)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2013 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_MAC_AUDIN_H
22
+ #define FREERDP_SERVER_MAC_AUDIN_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/listener.h>
26
+
27
+ #include "mf_types.h"
28
+ #include "mfreerdp.h"
29
+
30
+ BOOL mf_peer_audin_init(mfPeerContext* context);
31
+ void mf_peer_audin_uninit(mfPeerContext* context);
32
+
33
+ #endif /* FREERDP_SERVER_MAC_AUDIN_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_event.c ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * OS X Server Event Handling
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <errno.h>
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include <string.h>
26
+ #include <unistd.h>
27
+
28
+ #include "mf_event.h"
29
+
30
+ #include <freerdp/log.h>
31
+ #define TAG SERVER_TAG("mac")
32
+
33
+ static int mf_is_event_set(mfEventQueue* event_queue)
34
+ {
35
+ fd_set rfds;
36
+ int num_set;
37
+ struct timeval time = { 0 };
38
+
39
+ FD_ZERO(&rfds);
40
+ FD_SET(event_queue->pipe_fd[0], &rfds);
41
+ num_set = select(event_queue->pipe_fd[0] + 1, &rfds, 0, 0, &time);
42
+
43
+ return (num_set == 1);
44
+ }
45
+
46
+ static void mf_signal_event(mfEventQueue* event_queue)
47
+ {
48
+ int length;
49
+
50
+ length = write(event_queue->pipe_fd[1], "sig", 4);
51
+
52
+ if (length != 4)
53
+ WLog_ERR(TAG, "mf_signal_event: error");
54
+ }
55
+
56
+ static void mf_set_event(mfEventQueue* event_queue)
57
+ {
58
+ int length;
59
+
60
+ length = write(event_queue->pipe_fd[1], "sig", 4);
61
+
62
+ if (length != 4)
63
+ WLog_ERR(TAG, "mf_set_event: error");
64
+ }
65
+
66
+ static void mf_clear_events(mfEventQueue* event_queue)
67
+ {
68
+ int length;
69
+
70
+ while (mf_is_event_set(event_queue))
71
+ {
72
+ length = read(event_queue->pipe_fd[0], &length, 4);
73
+
74
+ if (length != 4)
75
+ WLog_ERR(TAG, "mf_clear_event: error");
76
+ }
77
+ }
78
+
79
+ static void mf_clear_event(mfEventQueue* event_queue)
80
+ {
81
+ int length;
82
+
83
+ length = read(event_queue->pipe_fd[0], &length, 4);
84
+
85
+ if (length != 4)
86
+ WLog_ERR(TAG, "mf_clear_event: error");
87
+ }
88
+
89
+ void mf_event_push(mfEventQueue* event_queue, mfEvent* event)
90
+ {
91
+ pthread_mutex_lock(&(event_queue->mutex));
92
+
93
+ if (event_queue->count >= event_queue->size)
94
+ {
95
+ event_queue->size *= 2;
96
+ event_queue->events =
97
+ (mfEvent**)realloc((void*)event_queue->events, sizeof(mfEvent*) * event_queue->size);
98
+ }
99
+
100
+ event_queue->events[(event_queue->count)++] = event;
101
+
102
+ pthread_mutex_unlock(&(event_queue->mutex));
103
+
104
+ mf_set_event(event_queue);
105
+ }
106
+
107
+ mfEvent* mf_event_peek(mfEventQueue* event_queue)
108
+ {
109
+ mfEvent* event;
110
+
111
+ pthread_mutex_lock(&(event_queue->mutex));
112
+
113
+ if (event_queue->count < 1)
114
+ event = NULL;
115
+ else
116
+ event = event_queue->events[0];
117
+
118
+ pthread_mutex_unlock(&(event_queue->mutex));
119
+
120
+ return event;
121
+ }
122
+
123
+ mfEvent* mf_event_pop(mfEventQueue* event_queue)
124
+ {
125
+ mfEvent* event;
126
+
127
+ pthread_mutex_lock(&(event_queue->mutex));
128
+
129
+ if (event_queue->count < 1)
130
+ return NULL;
131
+
132
+ /* remove event signal */
133
+ mf_clear_event(event_queue);
134
+
135
+ event = event_queue->events[0];
136
+ (event_queue->count)--;
137
+
138
+ memmove(&event_queue->events[0], &event_queue->events[1], event_queue->count * sizeof(void*));
139
+
140
+ pthread_mutex_unlock(&(event_queue->mutex));
141
+
142
+ return event;
143
+ }
144
+
145
+ mfEventRegion* mf_event_region_new(int x, int y, int width, int height)
146
+ {
147
+ mfEventRegion* event_region = malloc(sizeof(mfEventRegion));
148
+
149
+ if (event_region != NULL)
150
+ {
151
+ event_region->x = x;
152
+ event_region->y = y;
153
+ event_region->width = width;
154
+ event_region->height = height;
155
+ }
156
+
157
+ return event_region;
158
+ }
159
+
160
+ void mf_event_region_free(mfEventRegion* event_region)
161
+ {
162
+ free(event_region);
163
+ }
164
+
165
+ mfEvent* mf_event_new(int type)
166
+ {
167
+ mfEvent* event = malloc(sizeof(mfEvent));
168
+ if (!event)
169
+ return NULL;
170
+ event->type = type;
171
+ return event;
172
+ }
173
+
174
+ void mf_event_free(mfEvent* event)
175
+ {
176
+ free(event);
177
+ }
178
+
179
+ mfEventQueue* mf_event_queue_new()
180
+ {
181
+ mfEventQueue* event_queue = malloc(sizeof(mfEventQueue));
182
+
183
+ if (event_queue != NULL)
184
+ {
185
+ event_queue->pipe_fd[0] = -1;
186
+ event_queue->pipe_fd[1] = -1;
187
+
188
+ event_queue->size = 16;
189
+ event_queue->count = 0;
190
+ event_queue->events = (mfEvent**)malloc(sizeof(mfEvent*) * event_queue->size);
191
+
192
+ if (pipe(event_queue->pipe_fd) < 0)
193
+ {
194
+ free(event_queue);
195
+ return NULL;
196
+ }
197
+
198
+ pthread_mutex_init(&(event_queue->mutex), NULL);
199
+ }
200
+
201
+ return event_queue;
202
+ }
203
+
204
+ void mf_event_queue_free(mfEventQueue* event_queue)
205
+ {
206
+ if (event_queue->pipe_fd[0] != -1)
207
+ {
208
+ close(event_queue->pipe_fd[0]);
209
+ event_queue->pipe_fd[0] = -1;
210
+ }
211
+
212
+ if (event_queue->pipe_fd[1] != -1)
213
+ {
214
+ close(event_queue->pipe_fd[1]);
215
+ event_queue->pipe_fd[1] = -1;
216
+ }
217
+
218
+ pthread_mutex_destroy(&(event_queue->mutex));
219
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_event.h ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * OS X Server Event Handling
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_EVENT_H
21
+ #define FREERDP_SERVER_MAC_EVENT_H
22
+
23
+ typedef struct mf_event mfEvent;
24
+ typedef struct mf_event_queue mfEventQueue;
25
+ typedef struct mf_event_region mfEventRegion;
26
+
27
+ #include <pthread.h>
28
+ #include "mfreerdp.h"
29
+
30
+ //#include "mf_peer.h"
31
+
32
+ enum mf_event_type
33
+ {
34
+ FREERDP_SERVER_MAC_EVENT_TYPE_REGION,
35
+ FREERDP_SERVER_MAC_EVENT_TYPE_FRAME_TICK
36
+ };
37
+
38
+ struct mf_event
39
+ {
40
+ int type;
41
+ };
42
+
43
+ struct mf_event_queue
44
+ {
45
+ int size;
46
+ int count;
47
+ int pipe_fd[2];
48
+ mfEvent** events;
49
+ pthread_mutex_t mutex;
50
+ };
51
+
52
+ struct mf_event_region
53
+ {
54
+ int type;
55
+
56
+ int x;
57
+ int y;
58
+ int width;
59
+ int height;
60
+ };
61
+
62
+ void mf_event_push(mfEventQueue* event_queue, mfEvent* event);
63
+ mfEvent* mf_event_peek(mfEventQueue* event_queue);
64
+ mfEvent* mf_event_pop(mfEventQueue* event_queue);
65
+
66
+ mfEventRegion* mf_event_region_new(int x, int y, int width, int height);
67
+ void mf_event_region_free(mfEventRegion* event_region);
68
+
69
+ mfEvent* mf_event_new(int type);
70
+ void mf_event_free(mfEvent* event);
71
+
72
+ mfEventQueue* mf_event_queue_new(void);
73
+ void mf_event_queue_free(mfEventQueue* event_queue);
74
+
75
+ #endif /* FREERDP_SERVER_MAC_EVENT_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_info.c ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <stdlib.h>
23
+ #include <errno.h>
24
+
25
+ #include "mf_info.h"
26
+ #include "mf_mountain_lion.h"
27
+
28
+ #define MF_INFO_DEFAULT_FPS 30
29
+ #define MF_INFO_MAXPEERS 32
30
+
31
+ static mfInfo* mfInfoInstance = NULL;
32
+
33
+ int mf_info_lock(mfInfo* mfi)
34
+ {
35
+ int status = pthread_mutex_lock(&mfi->mutex);
36
+
37
+ switch (status)
38
+ {
39
+ case 0:
40
+ return TRUE;
41
+ break;
42
+
43
+ default:
44
+ return -1;
45
+ break;
46
+ }
47
+
48
+ return 1;
49
+ }
50
+
51
+ int mf_info_try_lock(mfInfo* mfi, UINT32 ms)
52
+ {
53
+ int status = pthread_mutex_trylock(&mfi->mutex);
54
+
55
+ switch (status)
56
+ {
57
+ case 0:
58
+ return TRUE;
59
+ break;
60
+
61
+ case EBUSY:
62
+ return FALSE;
63
+ break;
64
+
65
+ default:
66
+ return -1;
67
+ break;
68
+ }
69
+
70
+ return 1;
71
+ }
72
+
73
+ int mf_info_unlock(mfInfo* mfi)
74
+ {
75
+ int status = pthread_mutex_unlock(&mfi->mutex);
76
+
77
+ switch (status)
78
+ {
79
+ case 0:
80
+ return TRUE;
81
+ break;
82
+
83
+ default:
84
+ return -1;
85
+ break;
86
+ }
87
+
88
+ return 1;
89
+ }
90
+
91
+ static mfInfo* mf_info_init(void)
92
+ {
93
+ mfInfo* mfi;
94
+
95
+ mfi = (mfInfo*)calloc(1, sizeof(mfInfo));
96
+
97
+ if (mfi != NULL)
98
+ {
99
+ pthread_mutex_init(&mfi->mutex, NULL);
100
+
101
+ mfi->peers = (freerdp_peer**)calloc(MF_INFO_MAXPEERS, sizeof(freerdp_peer*));
102
+ if (!mfi->peers)
103
+ {
104
+ free(mfi);
105
+ return NULL;
106
+ }
107
+
108
+ mfi->framesPerSecond = MF_INFO_DEFAULT_FPS;
109
+ mfi->input_disabled = FALSE;
110
+ }
111
+
112
+ return mfi;
113
+ }
114
+
115
+ mfInfo* mf_info_get_instance(void)
116
+ {
117
+ if (mfInfoInstance == NULL)
118
+ mfInfoInstance = mf_info_init();
119
+
120
+ return mfInfoInstance;
121
+ }
122
+
123
+ void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context)
124
+ {
125
+ if (mf_info_lock(mfi) > 0)
126
+ {
127
+ int peerId;
128
+
129
+ if (mfi->peerCount == MF_INFO_MAXPEERS)
130
+ {
131
+ mf_info_unlock(mfi);
132
+ return;
133
+ }
134
+
135
+ context->info = mfi;
136
+
137
+ if (mfi->peerCount == 0)
138
+ {
139
+ mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale);
140
+ mf_mlion_screen_updates_init();
141
+ mf_mlion_start_getting_screen_updates();
142
+ }
143
+
144
+ peerId = 0;
145
+
146
+ for (int i = 0; i < MF_INFO_MAXPEERS; ++i)
147
+ {
148
+ // empty index will be our peer id
149
+ if (mfi->peers[i] == NULL)
150
+ {
151
+ peerId = i;
152
+ break;
153
+ }
154
+ }
155
+
156
+ mfi->peers[peerId] = ((rdpContext*)context)->peer;
157
+ mfi->peers[peerId]->pId = peerId;
158
+ mfi->peerCount++;
159
+
160
+ mf_info_unlock(mfi);
161
+ }
162
+ }
163
+
164
+ void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context)
165
+ {
166
+ if (mf_info_lock(mfi) > 0)
167
+ {
168
+ int peerId;
169
+
170
+ peerId = ((rdpContext*)context)->peer->pId;
171
+ mfi->peers[peerId] = NULL;
172
+ mfi->peerCount--;
173
+
174
+ if (mfi->peerCount == 0)
175
+ mf_mlion_stop_getting_screen_updates();
176
+
177
+ mf_info_unlock(mfi);
178
+ }
179
+ }
180
+
181
+ BOOL mf_info_have_updates(mfInfo* mfi)
182
+ {
183
+ if (mfi->framesWaiting == 0)
184
+ return FALSE;
185
+
186
+ return TRUE;
187
+ }
188
+
189
+ void mf_info_update_changes(mfInfo* mfi)
190
+ {
191
+ }
192
+
193
+ void mf_info_find_invalid_region(mfInfo* mfi)
194
+ {
195
+ mf_mlion_get_dirty_region(&mfi->invalid);
196
+ }
197
+
198
+ void mf_info_clear_invalid_region(mfInfo* mfi)
199
+ {
200
+ mf_mlion_clear_dirty_region();
201
+ mfi->invalid.height = 0;
202
+ mfi->invalid.width = 0;
203
+ }
204
+
205
+ void mf_info_invalidate_full_screen(mfInfo* mfi)
206
+ {
207
+ mfi->invalid.x = 0;
208
+ mfi->invalid.y = 0;
209
+ mfi->invalid.height = mfi->servscreen_height;
210
+ mfi->invalid.width = mfi->servscreen_width;
211
+ }
212
+
213
+ BOOL mf_info_have_invalid_region(mfInfo* mfi)
214
+ {
215
+ if (mfi->invalid.width * mfi->invalid.height == 0)
216
+ return FALSE;
217
+
218
+ return TRUE;
219
+ }
220
+
221
+ void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch)
222
+ {
223
+ *width = mfi->invalid.width / mfi->scale;
224
+ *height = mfi->invalid.height / mfi->scale;
225
+ *pitch = mfi->servscreen_width * mfi->scale * 4;
226
+
227
+ mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width,
228
+ *height, pBits);
229
+
230
+ *pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y);
231
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_info.h ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_INFO_H
21
+ #define FREERDP_SERVER_MAC_INFO_H
22
+
23
+ #define FREERDP_SERVER_MAC_INFO_DEFAULT_FPS 1
24
+ #define FREERDP_SERVER_MAC_INFO_MAXPEERS 1
25
+
26
+ #include <winpr/wtypes.h>
27
+ #include <freerdp/codec/rfx.h>
28
+
29
+ #include "mf_interface.h"
30
+
31
+ int mf_info_lock(mfInfo* mfi);
32
+ int mf_info_try_lock(mfInfo* mfi, UINT32 ms);
33
+ int mf_info_unlock(mfInfo* mfi);
34
+
35
+ mfInfo* mf_info_get_instance(void);
36
+ void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context);
37
+ void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context);
38
+
39
+ BOOL mf_info_have_updates(mfInfo* mfi);
40
+ void mf_info_update_changes(mfInfo* mfi);
41
+ void mf_info_find_invalid_region(mfInfo* mfi);
42
+ void mf_info_clear_invalid_region(mfInfo* mfi);
43
+ void mf_info_invalidate_full_screen(mfInfo* mfi);
44
+ BOOL mf_info_have_invalid_region(mfInfo* mfi);
45
+ void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch);
46
+ // BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM
47
+ // dwData);
48
+
49
+ #endif /* FREERDP_SERVER_MAC_INFO_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_input.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server (Input)
4
+ *
5
+ * Copyright 2013 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_INPUT_H
21
+ #define FREERDP_SERVER_MAC_INPUT_H
22
+
23
+ #include "mf_interface.h"
24
+
25
+ BOOL mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code);
26
+ BOOL mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
27
+ BOOL mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
28
+ BOOL mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
29
+
30
+ // dummy versions
31
+ BOOL mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
32
+ BOOL mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
33
+ BOOL mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
34
+ BOOL mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
35
+
36
+ #endif /* FREERDP_SERVER_MAC_INPUT_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_interface.c ADDED
File without changes
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_interface.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_MAC_INTERFACE_H
22
+ #define FREERDP_SERVER_MAC_INTERFACE_H
23
+
24
+ #include <pthread.h>
25
+
26
+ #include <freerdp/config.h>
27
+ #include <freerdp/codec/rfx.h>
28
+ #include <freerdp/codec/nsc.h>
29
+ #include <freerdp/listener.h>
30
+ #include <freerdp/freerdp.h>
31
+
32
+ #include <winpr/crt.h>
33
+
34
+ #ifdef WITH_SERVER_CHANNELS
35
+ #include <freerdp/channels/wtsvc.h>
36
+ #endif
37
+
38
+ #ifdef CHANNEL_RDPSND_SERVER
39
+ #include <freerdp/server/rdpsnd.h>
40
+ #include "mf_rdpsnd.h"
41
+ #endif
42
+
43
+ #ifdef CHANNEL_AUDIN_SERVER
44
+ #include <freerdp/server/audin.h>
45
+ #include "mf_audin.h"
46
+ #endif
47
+
48
+ #include "mf_types.h"
49
+
50
+ struct mf_peer_context
51
+ {
52
+ rdpContext _p;
53
+
54
+ mfInfo* info;
55
+ wStream* s;
56
+ BOOL activated;
57
+ UINT32 frame_id;
58
+ BOOL audin_open;
59
+ RFX_CONTEXT* rfx_context;
60
+ NSC_CONTEXT* nsc_context;
61
+
62
+ #ifdef WITH_SERVER_CHANNELS
63
+ HANDLE vcm;
64
+ #endif
65
+
66
+ #ifdef CHANNEL_AUDIN_SERVER
67
+ audin_server_context* audin;
68
+ #endif
69
+
70
+ #ifdef CHANNEL_RDPSND_SERVER
71
+ RdpsndServerContext* rdpsnd;
72
+ #endif
73
+ };
74
+
75
+ struct mf_info
76
+ {
77
+ // STREAM* s;
78
+
79
+ // screen and monitor info
80
+ UINT32 screenID;
81
+ UINT32 virtscreen_width;
82
+ UINT32 virtscreen_height;
83
+ UINT32 servscreen_width;
84
+ UINT32 servscreen_height;
85
+ UINT32 servscreen_xoffset;
86
+ UINT32 servscreen_yoffset;
87
+
88
+ int bitsPerPixel;
89
+ int peerCount;
90
+ int activePeerCount;
91
+ int framesPerSecond;
92
+ freerdp_peer** peers;
93
+ unsigned int framesWaiting;
94
+ UINT32 scale;
95
+
96
+ RFX_RECT invalid;
97
+ pthread_mutex_t mutex;
98
+
99
+ BOOL mouse_down_left;
100
+ BOOL mouse_down_right;
101
+ BOOL mouse_down_other;
102
+ BOOL input_disabled;
103
+ BOOL force_all_disconnect;
104
+ };
105
+
106
+ #endif /* FREERDP_SERVER_MAC_INTERFACE_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_mountain_lion.c ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * OS X Server Event Handling
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <dispatch/dispatch.h>
21
+ #include <CoreGraphics/CoreGraphics.h>
22
+ #include <CoreVideo/CoreVideo.h>
23
+ #include <IOKit/IOKitLib.h>
24
+ #include <IOSurface/IOSurface.h>
25
+
26
+ #include "mf_mountain_lion.h"
27
+
28
+ dispatch_semaphore_t region_sem;
29
+ dispatch_semaphore_t data_sem;
30
+ dispatch_queue_t screen_update_q;
31
+ CGDisplayStreamRef stream;
32
+
33
+ CGDisplayStreamUpdateRef lastUpdate = NULL;
34
+
35
+ BYTE* localBuf = NULL;
36
+
37
+ BOOL ready = FALSE;
38
+
39
+ void (^streamHandler)(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef,
40
+ CGDisplayStreamUpdateRef) = ^(CGDisplayStreamFrameStatus status,
41
+ uint64_t displayTime, IOSurfaceRef frameSurface,
42
+ CGDisplayStreamUpdateRef updateRef) {
43
+ dispatch_semaphore_wait(region_sem, DISPATCH_TIME_FOREVER);
44
+
45
+ // may need to move this down
46
+ if (ready == TRUE)
47
+ {
48
+
49
+ RFX_RECT rect;
50
+ unsigned long offset_beg;
51
+ unsigned long stride;
52
+
53
+ rect.x = 0;
54
+ rect.y = 0;
55
+ rect.width = 0;
56
+ rect.height = 0;
57
+ mf_mlion_peek_dirty_region(&rect);
58
+
59
+ // lock surface
60
+ IOSurfaceLock(frameSurface, kIOSurfaceLockReadOnly, NULL);
61
+ // get pointer
62
+ void* baseAddress = IOSurfaceGetBaseAddress(frameSurface);
63
+ // copy region
64
+
65
+ stride = IOSurfaceGetBytesPerRow(frameSurface);
66
+ // memcpy(localBuf, baseAddress + offset_beg, surflen);
67
+ for (int i = 0; i < rect.height; i++)
68
+ {
69
+ offset_beg = (stride * (rect.y + i) + (rect.x * 4));
70
+ memcpy(localBuf + offset_beg, baseAddress + offset_beg, rect.width * 4);
71
+ }
72
+
73
+ // unlock surface
74
+ IOSurfaceUnlock(frameSurface, kIOSurfaceLockReadOnly, NULL);
75
+
76
+ ready = FALSE;
77
+ dispatch_semaphore_signal(data_sem);
78
+ }
79
+
80
+ if (status != kCGDisplayStreamFrameStatusFrameComplete)
81
+ {
82
+ switch (status)
83
+ {
84
+ case kCGDisplayStreamFrameStatusFrameIdle:
85
+ break;
86
+
87
+ case kCGDisplayStreamFrameStatusStopped:
88
+ break;
89
+
90
+ case kCGDisplayStreamFrameStatusFrameBlank:
91
+ break;
92
+
93
+ default:
94
+ break;
95
+ }
96
+ }
97
+ else if (lastUpdate == NULL)
98
+ {
99
+ CFRetain(updateRef);
100
+ lastUpdate = updateRef;
101
+ }
102
+ else
103
+ {
104
+ CGDisplayStreamUpdateRef tmpRef;
105
+ tmpRef = lastUpdate;
106
+ lastUpdate = CGDisplayStreamUpdateCreateMergedUpdate(tmpRef, updateRef);
107
+ CFRelease(tmpRef);
108
+ }
109
+
110
+ dispatch_semaphore_signal(region_sem);
111
+ };
112
+
113
+ int mf_mlion_display_info(UINT32* disp_width, UINT32* disp_height, UINT32* scale)
114
+ {
115
+ CGDirectDisplayID display_id;
116
+
117
+ display_id = CGMainDisplayID();
118
+
119
+ CGDisplayModeRef mode = CGDisplayCopyDisplayMode(display_id);
120
+
121
+ size_t pixelWidth = CGDisplayModeGetPixelWidth(mode);
122
+ // size_t pixelHeight = CGDisplayModeGetPixelHeight(mode);
123
+
124
+ size_t wide = CGDisplayPixelsWide(display_id);
125
+ size_t high = CGDisplayPixelsHigh(display_id);
126
+
127
+ CGDisplayModeRelease(mode);
128
+
129
+ *disp_width = wide; // pixelWidth;
130
+ *disp_height = high; // pixelHeight;
131
+ *scale = pixelWidth / wide;
132
+
133
+ return 0;
134
+ }
135
+
136
+ int mf_mlion_screen_updates_init()
137
+ {
138
+ CGDirectDisplayID display_id;
139
+
140
+ display_id = CGMainDisplayID();
141
+
142
+ screen_update_q = dispatch_queue_create("mfreerdp.server.screenUpdate", NULL);
143
+
144
+ region_sem = dispatch_semaphore_create(1);
145
+ data_sem = dispatch_semaphore_create(1);
146
+
147
+ UINT32 pixelWidth;
148
+ UINT32 pixelHeight;
149
+ UINT32 scale;
150
+
151
+ mf_mlion_display_info(&pixelWidth, &pixelHeight, &scale);
152
+
153
+ localBuf = malloc(pixelWidth * pixelHeight * 4);
154
+ if (!localBuf)
155
+ return -1;
156
+
157
+ CFDictionaryRef opts;
158
+
159
+ void* keys[2];
160
+ void* values[2];
161
+
162
+ keys[0] = (void*)kCGDisplayStreamShowCursor;
163
+ values[0] = (void*)kCFBooleanFalse;
164
+
165
+ opts = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, 1,
166
+ NULL, NULL);
167
+
168
+ stream = CGDisplayStreamCreateWithDispatchQueue(display_id, pixelWidth, pixelHeight, 'BGRA',
169
+ opts, screen_update_q, streamHandler);
170
+
171
+ CFRelease(opts);
172
+
173
+ return 0;
174
+ }
175
+
176
+ int mf_mlion_start_getting_screen_updates()
177
+ {
178
+ CGError err;
179
+
180
+ err = CGDisplayStreamStart(stream);
181
+
182
+ if (err != kCGErrorSuccess)
183
+ {
184
+ return 1;
185
+ }
186
+
187
+ return 0;
188
+ }
189
+ int mf_mlion_stop_getting_screen_updates()
190
+ {
191
+ CGError err;
192
+
193
+ err = CGDisplayStreamStop(stream);
194
+
195
+ if (err != kCGErrorSuccess)
196
+ {
197
+ return 1;
198
+ }
199
+
200
+ return 0;
201
+ }
202
+
203
+ int mf_mlion_get_dirty_region(RFX_RECT* invalid)
204
+ {
205
+ dispatch_semaphore_wait(region_sem, DISPATCH_TIME_FOREVER);
206
+
207
+ if (lastUpdate != NULL)
208
+ {
209
+ mf_mlion_peek_dirty_region(invalid);
210
+ }
211
+
212
+ dispatch_semaphore_signal(region_sem);
213
+
214
+ return 0;
215
+ }
216
+
217
+ int mf_mlion_peek_dirty_region(RFX_RECT* invalid)
218
+ {
219
+ size_t num_rects;
220
+ CGRect dirtyRegion;
221
+
222
+ const CGRect* rects =
223
+ CGDisplayStreamUpdateGetRects(lastUpdate, kCGDisplayStreamUpdateDirtyRects, &num_rects);
224
+
225
+ if (num_rects == 0)
226
+ {
227
+ return 0;
228
+ }
229
+
230
+ dirtyRegion = *rects;
231
+ for (size_t i = 0; i < num_rects; i++)
232
+ {
233
+ dirtyRegion = CGRectUnion(dirtyRegion, *(rects + i));
234
+ }
235
+
236
+ invalid->x = dirtyRegion.origin.x;
237
+ invalid->y = dirtyRegion.origin.y;
238
+ invalid->height = dirtyRegion.size.height;
239
+ invalid->width = dirtyRegion.size.width;
240
+
241
+ return 0;
242
+ }
243
+
244
+ int mf_mlion_clear_dirty_region()
245
+ {
246
+ dispatch_semaphore_wait(region_sem, DISPATCH_TIME_FOREVER);
247
+
248
+ CFRelease(lastUpdate);
249
+ lastUpdate = NULL;
250
+
251
+ dispatch_semaphore_signal(region_sem);
252
+
253
+ return 0;
254
+ }
255
+
256
+ int mf_mlion_get_pixelData(long x, long y, long width, long height, BYTE** pxData)
257
+ {
258
+ dispatch_semaphore_wait(region_sem, DISPATCH_TIME_FOREVER);
259
+ ready = TRUE;
260
+ dispatch_semaphore_wait(data_sem, DISPATCH_TIME_FOREVER);
261
+ dispatch_semaphore_signal(region_sem);
262
+
263
+ // this second wait allows us to block until data is copied... more on this later
264
+ dispatch_semaphore_wait(data_sem, DISPATCH_TIME_FOREVER);
265
+ *pxData = localBuf;
266
+ dispatch_semaphore_signal(data_sem);
267
+
268
+ return 0;
269
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_mountain_lion.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * OS X Server Event Handling
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_MLION_H
21
+ #define FREERDP_SERVER_MAC_MLION_H
22
+
23
+ #include <freerdp/codec/rfx.h>
24
+
25
+ int mf_mlion_display_info(UINT32* disp_width, UINT32* dispHeight, UINT32* scale);
26
+
27
+ int mf_mlion_screen_updates_init(void);
28
+
29
+ int mf_mlion_start_getting_screen_updates(void);
30
+ int mf_mlion_stop_getting_screen_updates(void);
31
+
32
+ int mf_mlion_get_dirty_region(RFX_RECT* invalid);
33
+ int mf_mlion_peek_dirty_region(RFX_RECT* invalid);
34
+ int mf_mlion_clear_dirty_region(void);
35
+
36
+ int mf_mlion_get_pixelData(long x, long y, long width, long height, BYTE** pxData);
37
+
38
+ #endif /* FREERDP_SERVER_MAC_MLION_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_peer.c ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <freerdp/listener.h>
23
+ #include <freerdp/codec/rfx.h>
24
+ #include <winpr/stream.h>
25
+ #include <freerdp/peer.h>
26
+ #include <freerdp/codec/color.h>
27
+
28
+ #include <winpr/crt.h>
29
+ #include <winpr/assert.h>
30
+
31
+ #include "mf_peer.h"
32
+ #include "mf_info.h"
33
+ #include "mf_input.h"
34
+ #include "mf_event.h"
35
+ #include "mf_rdpsnd.h"
36
+ #include "mf_audin.h"
37
+
38
+ #include <mach/clock.h>
39
+ #include <mach/mach.h>
40
+ #include <dispatch/dispatch.h>
41
+
42
+ #include "OpenGL/OpenGL.h"
43
+ #include "OpenGL/gl.h"
44
+
45
+ #include "CoreVideo/CoreVideo.h"
46
+
47
+ #include <freerdp/log.h>
48
+ #define TAG SERVER_TAG("mac")
49
+
50
+ // refactor these
51
+ static int info_last_sec = 0;
52
+ static int info_last_nsec = 0;
53
+
54
+ static dispatch_source_t info_timer;
55
+ static dispatch_queue_t info_queue;
56
+
57
+ static mfEventQueue* info_event_queue;
58
+
59
+ static CGLContextObj glContext;
60
+ static CGContextRef bmp;
61
+ static CGImageRef img;
62
+
63
+ static void mf_peer_context_free(freerdp_peer* client, rdpContext* context);
64
+
65
+ static BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
66
+ {
67
+ if (info_event_queue->pipe_fd[0] == -1)
68
+ return TRUE;
69
+
70
+ rfds[*rcount] = (void*)(long)info_event_queue->pipe_fd[0];
71
+ (*rcount)++;
72
+ return TRUE;
73
+ }
74
+
75
+ static void mf_peer_rfx_update(freerdp_peer* client)
76
+ {
77
+ // check
78
+ mfInfo* mfi = mf_info_get_instance();
79
+ mf_info_find_invalid_region(mfi);
80
+
81
+ if (mf_info_have_invalid_region(mfi) == false)
82
+ {
83
+ return;
84
+ }
85
+
86
+ long width;
87
+ long height;
88
+ int pitch;
89
+ BYTE* dataBits = NULL;
90
+ mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch);
91
+ mf_info_clear_invalid_region(mfi);
92
+ // encode
93
+ wStream* s;
94
+ RFX_RECT rect;
95
+ rdpUpdate* update;
96
+ mfPeerContext* mfp;
97
+ SURFACE_BITS_COMMAND cmd = { 0 };
98
+
99
+ WINPR_ASSERT(client);
100
+
101
+ mfp = (mfPeerContext*)client->context;
102
+ WINPR_ASSERT(mfp);
103
+
104
+ update = client->context->update;
105
+ WINPR_ASSERT(update);
106
+
107
+ s = mfp->s;
108
+ WINPR_ASSERT(s);
109
+
110
+ Stream_Clear(s);
111
+ Stream_SetPosition(s, 0);
112
+ UINT32 x = mfi->invalid.x / mfi->scale;
113
+ UINT32 y = mfi->invalid.y / mfi->scale;
114
+ rect.x = 0;
115
+ rect.y = 0;
116
+ rect.width = width;
117
+ rect.height = height;
118
+
119
+ rfx_context_reset(mfp->rfx_context, mfi->servscreen_width, mfi->servscreen_height);
120
+
121
+ if (!(rfx_compose_message(mfp->rfx_context, s, &rect, 1, (BYTE*)dataBits, rect.width,
122
+ rect.height, pitch)))
123
+ {
124
+ return;
125
+ }
126
+
127
+ cmd.destLeft = x;
128
+ cmd.destTop = y;
129
+ cmd.destRight = x + rect.width;
130
+ cmd.destBottom = y + rect.height;
131
+ cmd.bmp.bpp = 32;
132
+ cmd.bmp.codecID = 3;
133
+ cmd.bmp.width = rect.width;
134
+ cmd.bmp.height = rect.height;
135
+ cmd.bmp.bitmapDataLength = Stream_GetPosition(s);
136
+ cmd.bmp.bitmapData = Stream_Buffer(s);
137
+ // send
138
+ update->SurfaceBits(update->context, &cmd);
139
+ // clean up... maybe?
140
+ }
141
+
142
+ static BOOL mf_peer_check_fds(freerdp_peer* client)
143
+ {
144
+ mfPeerContext* context = (mfPeerContext*)client->context;
145
+ mfEvent* event;
146
+
147
+ if (context->activated == FALSE)
148
+ return TRUE;
149
+
150
+ event = mf_event_peek(info_event_queue);
151
+
152
+ if (event != NULL)
153
+ {
154
+ if (event->type == FREERDP_SERVER_MAC_EVENT_TYPE_REGION)
155
+ {
156
+ }
157
+ else if (event->type == FREERDP_SERVER_MAC_EVENT_TYPE_FRAME_TICK)
158
+ {
159
+ event = mf_event_pop(info_event_queue);
160
+ mf_peer_rfx_update(client);
161
+ mf_event_free(event);
162
+ }
163
+ }
164
+
165
+ return TRUE;
166
+ }
167
+
168
+ /* Called when we have a new peer connecting */
169
+ static BOOL mf_peer_context_new(freerdp_peer* client, rdpContext* context)
170
+ {
171
+ rdpSettings* settings;
172
+ mfPeerContext* peer = (mfPeerContext*)context;
173
+
174
+ WINPR_ASSERT(client);
175
+ WINPR_ASSERT(context);
176
+
177
+ settings = context->settings;
178
+ WINPR_ASSERT(settings);
179
+
180
+ if (!(peer->info = mf_info_get_instance()))
181
+ return FALSE;
182
+
183
+ if (!(peer->rfx_context = rfx_context_new_ex(
184
+ TRUE, freerdp_settings_get_uint32(settings, FreeRDP_ThreadingFlags))))
185
+ goto fail;
186
+
187
+ rfx_context_reset(peer->rfx_context,
188
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
189
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
190
+ rfx_context_set_mode(peer->rfx_context, RLGR3);
191
+ rfx_context_set_pixel_format(peer->rfx_context, PIXEL_FORMAT_BGRA32);
192
+
193
+ if (!(peer->s = Stream_New(NULL, 0xFFFF)))
194
+ goto fail;
195
+
196
+ peer->vcm = WTSOpenServerA((LPSTR)client->context);
197
+
198
+ if (!peer->vcm || (peer->vcm == INVALID_HANDLE_VALUE))
199
+ goto fail;
200
+
201
+ mf_info_peer_register(peer->info, peer);
202
+ return TRUE;
203
+ fail:
204
+ mf_peer_context_free(client, context);
205
+ return FALSE;
206
+ }
207
+
208
+ /* Called after a peer disconnects */
209
+ static void mf_peer_context_free(freerdp_peer* client, rdpContext* context)
210
+ {
211
+ mfPeerContext* peer = (mfPeerContext*)context;
212
+ if (context)
213
+ {
214
+ mf_info_peer_unregister(peer->info, peer);
215
+ dispatch_suspend(info_timer);
216
+ Stream_Free(peer->s, TRUE);
217
+ rfx_context_free(peer->rfx_context);
218
+ // nsc_context_free(peer->nsc_context);
219
+ #ifdef CHANNEL_AUDIN_SERVER
220
+
221
+ mf_peer_audin_uninit(peer);
222
+
223
+ #endif
224
+ #ifdef CHANNEL_RDPSND_SERVER
225
+ mf_peer_rdpsnd_stop();
226
+
227
+ if (peer->rdpsnd)
228
+ rdpsnd_server_context_free(peer->rdpsnd);
229
+
230
+ #endif
231
+ WTSCloseServer(peer->vcm);
232
+ }
233
+ }
234
+
235
+ /* Called when a new client connects */
236
+ static BOOL mf_peer_init(freerdp_peer* client)
237
+ {
238
+ client->ContextSize = sizeof(mfPeerContext);
239
+ client->ContextNew = mf_peer_context_new;
240
+ client->ContextFree = mf_peer_context_free;
241
+
242
+ if (!freerdp_peer_context_new(client))
243
+ return FALSE;
244
+
245
+ info_event_queue = mf_event_queue_new();
246
+ info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL);
247
+ info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue);
248
+
249
+ if (info_timer)
250
+ {
251
+ // DEBUG_WARN( "created timer\n");
252
+ dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC,
253
+ 100ull * NSEC_PER_MSEC);
254
+ dispatch_source_set_event_handler(info_timer, ^{
255
+ // DEBUG_WARN( "dispatch\n");
256
+ mfEvent* event = mf_event_new(FREERDP_SERVER_MAC_EVENT_TYPE_FRAME_TICK);
257
+ mf_event_push(info_event_queue, (mfEvent*)event);
258
+ });
259
+ dispatch_resume(info_timer);
260
+ }
261
+
262
+ return TRUE;
263
+ }
264
+
265
+ static BOOL mf_peer_post_connect(freerdp_peer* client)
266
+ {
267
+ mfInfo* mfi = mf_info_get_instance();
268
+
269
+ WINPR_ASSERT(client);
270
+
271
+ mfPeerContext* context = (mfPeerContext*)client->context;
272
+ WINPR_ASSERT(context);
273
+
274
+ rdpSettings* settings = client->context->settings;
275
+ WINPR_ASSERT(settings);
276
+
277
+ mfi->scale = 1;
278
+ // mfi->servscreen_width = 2880 / mfi->scale;
279
+ // mfi->servscreen_height = 1800 / mfi->scale;
280
+ UINT32 bitsPerPixel = 32;
281
+
282
+ if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) != mfi->servscreen_width) ||
283
+ (freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) != mfi->servscreen_height))
284
+ {
285
+ }
286
+
287
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, mfi->servscreen_width))
288
+ return FALSE;
289
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, mfi->servscreen_height))
290
+ return FALSE;
291
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, bitsPerPixel))
292
+ return FALSE;
293
+
294
+ WINPR_ASSERT(client->context->update);
295
+ WINPR_ASSERT(client->context->update->DesktopResize);
296
+ client->context->update->DesktopResize(client->context);
297
+
298
+ mfi->mouse_down_left = FALSE;
299
+ mfi->mouse_down_right = FALSE;
300
+ mfi->mouse_down_other = FALSE;
301
+ #ifdef CHANNEL_RDPSND_SERVER
302
+
303
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
304
+ {
305
+ mf_peer_rdpsnd_init(context); /* Audio Output */
306
+ }
307
+
308
+ #endif
309
+ /* Dynamic Virtual Channels */
310
+ #ifdef CHANNEL_AUDIN_SERVER
311
+ mf_peer_audin_init(context); /* Audio Input */
312
+ #endif
313
+ return TRUE;
314
+ }
315
+
316
+ static BOOL mf_peer_activate(freerdp_peer* client)
317
+ {
318
+ WINPR_ASSERT(client);
319
+
320
+ mfPeerContext* context = (mfPeerContext*)client->context;
321
+ WINPR_ASSERT(context);
322
+
323
+ rdpSettings* settings = client->context->settings;
324
+ WINPR_ASSERT(settings);
325
+
326
+ rfx_context_reset(context->rfx_context,
327
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
328
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
329
+ context->activated = TRUE;
330
+ return TRUE;
331
+ }
332
+
333
+ static BOOL mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
334
+ {
335
+ return TRUE;
336
+ }
337
+
338
+ static BOOL mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
339
+ {
340
+ bool state_down = FALSE;
341
+
342
+ if (flags == KBD_FLAGS_DOWN)
343
+ {
344
+ state_down = TRUE;
345
+ }
346
+ return TRUE;
347
+ }
348
+
349
+ static BOOL mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
350
+ {
351
+ return FALSE;
352
+ }
353
+
354
+ static BOOL mf_peer_suppress_output(rdpContext* context, BYTE allow, const RECTANGLE_16* area)
355
+ {
356
+ return FALSE;
357
+ }
358
+
359
+ static void* mf_peer_main_loop(void* arg)
360
+ {
361
+ mfPeerContext* context;
362
+ rdpSettings* settings;
363
+ rdpInput* input;
364
+ rdpUpdate* update;
365
+ freerdp_peer* client = (freerdp_peer*)arg;
366
+
367
+ if (!mf_peer_init(client))
368
+ goto fail;
369
+
370
+ const mf_server_info* info = client->ContextExtra;
371
+ WINPR_ASSERT(info);
372
+
373
+ WINPR_ASSERT(client->context);
374
+
375
+ settings = client->context->settings;
376
+ WINPR_ASSERT(settings);
377
+
378
+ /* Initialize the real server settings here */
379
+ rdpPrivateKey* key = freerdp_key_new_from_file(info->key);
380
+ if (!key)
381
+ goto fail;
382
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1))
383
+ goto fail;
384
+ rdpCertificate* cert = freerdp_certificate_new_from_file(info->cert);
385
+ if (!cert)
386
+ goto fail;
387
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1))
388
+ goto fail;
389
+
390
+ if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE))
391
+ goto fail;
392
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE))
393
+ goto fail;
394
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32))
395
+ goto fail;
396
+
397
+ if (!freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE))
398
+ goto fail;
399
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RefreshRect, FALSE))
400
+ goto fail;
401
+
402
+ client->PostConnect = mf_peer_post_connect;
403
+ client->Activate = mf_peer_activate;
404
+
405
+ input = client->context->input;
406
+ WINPR_ASSERT(input);
407
+
408
+ input->SynchronizeEvent = mf_peer_synchronize_event;
409
+ input->KeyboardEvent = mf_input_keyboard_event; // mf_peer_keyboard_event;
410
+ input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event;
411
+ input->MouseEvent = mf_input_mouse_event;
412
+ input->ExtendedMouseEvent = mf_input_extended_mouse_event;
413
+
414
+ update = client->context->update;
415
+ WINPR_ASSERT(update);
416
+
417
+ // update->RefreshRect = mf_peer_refresh_rect;
418
+ update->SuppressOutput = mf_peer_suppress_output;
419
+
420
+ WINPR_ASSERT(client->Initialize);
421
+ const BOOL rc = client->Initialize(client);
422
+ if (!rc)
423
+ goto fail;
424
+ context = (mfPeerContext*)client->context;
425
+
426
+ while (1)
427
+ {
428
+ DWORD status;
429
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
430
+ DWORD count = client->GetEventHandles(client, handles, ARRAYSIZE(handles));
431
+
432
+ if ((count == 0) || (count == MAXIMUM_WAIT_OBJECTS))
433
+ {
434
+ WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
435
+ break;
436
+ }
437
+
438
+ handles[count++] = WTSVirtualChannelManagerGetEventHandle(context->vcm);
439
+
440
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
441
+ if (status == WAIT_FAILED)
442
+ {
443
+ WLog_ERR(TAG, "WaitForMultipleObjects failed");
444
+ break;
445
+ }
446
+
447
+ if (client->CheckFileDescriptor(client) != TRUE)
448
+ {
449
+ break;
450
+ }
451
+
452
+ if ((mf_peer_check_fds(client)) != TRUE)
453
+ {
454
+ break;
455
+ }
456
+
457
+ if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
458
+ {
459
+ break;
460
+ }
461
+ }
462
+
463
+ client->Disconnect(client);
464
+ freerdp_peer_context_free(client);
465
+ fail:
466
+ freerdp_peer_free(client);
467
+ return NULL;
468
+ }
469
+
470
+ BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
471
+ {
472
+ pthread_t th;
473
+
474
+ WINPR_ASSERT(instance);
475
+ WINPR_ASSERT(client);
476
+
477
+ client->ContextExtra = instance->info;
478
+ if (pthread_create(&th, 0, mf_peer_main_loop, client) == 0)
479
+ {
480
+ pthread_detach(th);
481
+ return TRUE;
482
+ }
483
+
484
+ return FALSE;
485
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_peer.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_PEER_H
21
+ #define FREERDP_SERVER_MAC_PEER_H
22
+
23
+ #include "mf_interface.h"
24
+
25
+ typedef struct
26
+ {
27
+ const char* cert;
28
+ const char* key;
29
+ } mf_server_info;
30
+
31
+ BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client);
32
+
33
+ #endif /* FREERDP_SERVER_MAC_PEER_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_rdpsnd.c ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server (Audio Output)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2015 Thincast Technologies GmbH
7
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <freerdp/server/rdpsnd.h>
25
+
26
+ #include "mf_info.h"
27
+ #include "mf_rdpsnd.h"
28
+ #include "mf_interface.h"
29
+
30
+ #include <winpr/sysinfo.h>
31
+ #include <freerdp/server/server-common.h>
32
+ #include <freerdp/log.h>
33
+ #define TAG SERVER_TAG("mac")
34
+
35
+ AQRecorderState recorderState;
36
+
37
+ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
38
+ {
39
+ OSStatus status;
40
+ BOOL formatAgreed = FALSE;
41
+ AUDIO_FORMAT* agreedFormat = NULL;
42
+ // we should actually loop through the list of client formats here
43
+ // and see if we can send the client something that it supports...
44
+ WLog_DBG(TAG, "Client supports the following %d formats: ", context->num_client_formats);
45
+
46
+ int i = 0;
47
+ for (; i < context->num_client_formats; i++)
48
+ {
49
+ /* TODO: improve the way we agree on a format */
50
+ for (int j = 0; j < context->num_server_formats; j++)
51
+ {
52
+ if ((context->client_formats[i].wFormatTag == context->server_formats[j].wFormatTag) &&
53
+ (context->client_formats[i].nChannels == context->server_formats[j].nChannels) &&
54
+ (context->client_formats[i].nSamplesPerSec ==
55
+ context->server_formats[j].nSamplesPerSec))
56
+ {
57
+ WLog_DBG(TAG, "agreed on format!");
58
+ formatAgreed = TRUE;
59
+ agreedFormat = (AUDIO_FORMAT*)&context->server_formats[j];
60
+ break;
61
+ }
62
+ }
63
+
64
+ if (formatAgreed == TRUE)
65
+ break;
66
+ }
67
+
68
+ if (formatAgreed == FALSE)
69
+ {
70
+ WLog_DBG(TAG, "Could not agree on a audio format with the server");
71
+ return;
72
+ }
73
+
74
+ context->SelectFormat(context, i);
75
+ context->SetVolume(context, 0x7FFF, 0x7FFF);
76
+
77
+ switch (agreedFormat->wFormatTag)
78
+ {
79
+ case WAVE_FORMAT_ALAW:
80
+ recorderState.dataFormat.mFormatID = kAudioFormatDVIIntelIMA;
81
+ break;
82
+
83
+ case WAVE_FORMAT_PCM:
84
+ recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
85
+ break;
86
+
87
+ default:
88
+ recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
89
+ break;
90
+ }
91
+
92
+ recorderState.dataFormat.mSampleRate = agreedFormat->nSamplesPerSec;
93
+ recorderState.dataFormat.mFormatFlags =
94
+ kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
95
+ recorderState.dataFormat.mBytesPerPacket = 4;
96
+ recorderState.dataFormat.mFramesPerPacket = 1;
97
+ recorderState.dataFormat.mBytesPerFrame = 4;
98
+ recorderState.dataFormat.mChannelsPerFrame = agreedFormat->nChannels;
99
+ recorderState.dataFormat.mBitsPerChannel = agreedFormat->wBitsPerSample;
100
+ recorderState.snd_context = context;
101
+ status =
102
+ AudioQueueNewInput(&recorderState.dataFormat, mf_peer_rdpsnd_input_callback, &recorderState,
103
+ NULL, kCFRunLoopCommonModes, 0, &recorderState.queue);
104
+
105
+ if (status != noErr)
106
+ {
107
+ WLog_DBG(TAG, "Failed to create a new Audio Queue. Status code: %" PRId32 "", status);
108
+ }
109
+
110
+ UInt32 dataFormatSize = sizeof(recorderState.dataFormat);
111
+ AudioQueueGetProperty(recorderState.queue, kAudioConverterCurrentInputStreamDescription,
112
+ &recorderState.dataFormat, &dataFormatSize);
113
+ mf_rdpsnd_derive_buffer_size(recorderState.queue, &recorderState.dataFormat, 0.05,
114
+ &recorderState.bufferByteSize);
115
+
116
+ for (size_t x = 0; x < SND_NUMBUFFERS; ++x)
117
+ {
118
+ AudioQueueAllocateBuffer(recorderState.queue, recorderState.bufferByteSize,
119
+ &recorderState.buffers[x]);
120
+ AudioQueueEnqueueBuffer(recorderState.queue, recorderState.buffers[x], 0, NULL);
121
+ }
122
+
123
+ recorderState.currentPacket = 0;
124
+ recorderState.isRunning = true;
125
+ AudioQueueStart(recorderState.queue, NULL);
126
+ }
127
+
128
+ BOOL mf_peer_rdpsnd_init(mfPeerContext* context)
129
+ {
130
+ context->rdpsnd = rdpsnd_server_context_new(context->vcm);
131
+ context->rdpsnd->rdpcontext = &context->_p;
132
+ context->rdpsnd->data = context;
133
+ context->rdpsnd->num_server_formats =
134
+ server_rdpsnd_get_formats(&context->rdpsnd->server_formats);
135
+
136
+ if (context->rdpsnd->num_server_formats > 0)
137
+ context->rdpsnd->src_format = &context->rdpsnd->server_formats[0];
138
+
139
+ context->rdpsnd->Activated = mf_peer_rdpsnd_activated;
140
+ context->rdpsnd->Initialize(context->rdpsnd, TRUE);
141
+ return TRUE;
142
+ }
143
+
144
+ BOOL mf_peer_rdpsnd_stop(void)
145
+ {
146
+ recorderState.isRunning = false;
147
+ AudioQueueStop(recorderState.queue, true);
148
+ return TRUE;
149
+ }
150
+
151
+ void mf_peer_rdpsnd_input_callback(void* inUserData, AudioQueueRef inAQ,
152
+ AudioQueueBufferRef inBuffer, const AudioTimeStamp* inStartTime,
153
+ UInt32 inNumberPacketDescriptions,
154
+ const AudioStreamPacketDescription* inPacketDescs)
155
+ {
156
+ OSStatus status;
157
+ AQRecorderState* rState;
158
+ rState = inUserData;
159
+
160
+ if (inNumberPacketDescriptions == 0 && rState->dataFormat.mBytesPerPacket != 0)
161
+ {
162
+ inNumberPacketDescriptions =
163
+ inBuffer->mAudioDataByteSize / rState->dataFormat.mBytesPerPacket;
164
+ }
165
+
166
+ if (rState->isRunning == 0)
167
+ {
168
+ return;
169
+ }
170
+
171
+ rState->snd_context->SendSamples(rState->snd_context, inBuffer->mAudioData,
172
+ inBuffer->mAudioDataByteSize / 4,
173
+ (UINT16)(GetTickCount() & 0xffff));
174
+ status = AudioQueueEnqueueBuffer(rState->queue, inBuffer, 0, NULL);
175
+
176
+ if (status != noErr)
177
+ {
178
+ WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %" PRId32 "", status);
179
+ }
180
+ }
181
+
182
+ void mf_rdpsnd_derive_buffer_size(AudioQueueRef audioQueue,
183
+ AudioStreamBasicDescription* ASBDescription, Float64 seconds,
184
+ UInt32* outBufferSize)
185
+ {
186
+ static const int maxBufferSize = 0x50000;
187
+ int maxPacketSize = ASBDescription->mBytesPerPacket;
188
+
189
+ if (maxPacketSize == 0)
190
+ {
191
+ UInt32 maxVBRPacketSize = sizeof(maxPacketSize);
192
+ AudioQueueGetProperty(audioQueue, kAudioQueueProperty_MaximumOutputPacketSize,
193
+ // in Mac OS X v10.5, instead use
194
+ // kAudioConverterPropertyMaximumOutputPacketSize
195
+ &maxPacketSize, &maxVBRPacketSize);
196
+ }
197
+
198
+ Float64 numBytesForTime = ASBDescription->mSampleRate * maxPacketSize * seconds;
199
+ *outBufferSize = (UInt32)(numBytesForTime < maxBufferSize ? numBytesForTime : maxBufferSize);
200
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_rdpsnd.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server (Audio Output)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_MAC_RDPSND_H
21
+ #define FREERDP_SERVER_MAC_RDPSND_H
22
+
23
+ #include <CoreAudio/CoreAudio.h>
24
+ #include <AudioToolbox/AudioToolbox.h>
25
+
26
+ #include <freerdp/freerdp.h>
27
+ #include <freerdp/listener.h>
28
+ #include <freerdp/server/rdpsnd.h>
29
+
30
+ #include "mf_types.h"
31
+ #include "mfreerdp.h"
32
+
33
+ void mf_rdpsnd_derive_buffer_size(AudioQueueRef audioQueue,
34
+ AudioStreamBasicDescription* ASBDescription, Float64 seconds,
35
+ UInt32* outBufferSize);
36
+
37
+ void mf_peer_rdpsnd_input_callback(void* inUserData, AudioQueueRef inAQ,
38
+ AudioQueueBufferRef inBuffer, const AudioTimeStamp* inStartTime,
39
+ UInt32 inNumberPacketDescriptions,
40
+ const AudioStreamPacketDescription* inPacketDescs);
41
+
42
+ #define SND_NUMBUFFERS 3
43
+ typedef struct
44
+ {
45
+ AudioStreamBasicDescription dataFormat;
46
+ AudioQueueRef queue;
47
+ AudioQueueBufferRef buffers[SND_NUMBUFFERS];
48
+ AudioFileID audioFile;
49
+ UInt32 bufferByteSize;
50
+ SInt64 currentPacket;
51
+ bool isRunning;
52
+ RdpsndServerContext* snd_context;
53
+ } AQRecorderState;
54
+
55
+ BOOL mf_peer_rdpsnd_init(mfPeerContext* context);
56
+ BOOL mf_peer_rdpsnd_stop(void);
57
+
58
+ #endif /* FREERDP_SERVER_MAC_RDPSND_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mf_types.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ * Copyright 2023 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_MAC_TYPES_H
22
+ #define FREERDP_SERVER_MAC_TYPES_H
23
+
24
+ #include <pthread.h>
25
+
26
+ #include <freerdp/config.h>
27
+
28
+ #include <winpr/crt.h>
29
+
30
+ typedef struct mf_info mfInfo;
31
+ typedef struct mf_peer_context mfPeerContext;
32
+
33
+ #endif /* FREERDP_SERVER_MAC_TYPES_H */
local-test-freerdp-full-01/afc-freerdp/server/Mac/mfreerdp.c ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include <string.h>
26
+ #include <errno.h>
27
+ #include <pthread.h>
28
+ #include <signal.h>
29
+ #include <sys/time.h>
30
+
31
+ #include <CoreGraphics/CGEvent.h>
32
+
33
+ #include <winpr/crt.h>
34
+ #include <winpr/wtsapi.h>
35
+ #include <winpr/assert.h>
36
+
37
+ #include <freerdp/freerdp.h>
38
+ #include <freerdp/constants.h>
39
+ #include <freerdp/channels/wtsvc.h>
40
+ #include <freerdp/channels/channels.h>
41
+ #include <freerdp/server/server-common.h>
42
+
43
+ #include "mfreerdp.h"
44
+ #include "mf_peer.h"
45
+
46
+ #include <freerdp/log.h>
47
+ #define TAG SERVER_TAG("mac")
48
+
49
+ static void mf_server_main_loop(freerdp_listener* instance)
50
+ {
51
+ WINPR_ASSERT(instance);
52
+ WINPR_ASSERT(instance->GetEventHandles);
53
+ WINPR_ASSERT(instance->CheckFileDescriptor);
54
+
55
+ while (1)
56
+ {
57
+ DWORD status;
58
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
59
+ DWORD count = instance->GetEventHandles(instance, handles, ARRAYSIZE(handles));
60
+
61
+ if (count == 0)
62
+ {
63
+ WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
64
+ break;
65
+ }
66
+
67
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
68
+ if (status == WAIT_FAILED)
69
+ {
70
+ WLog_ERR(TAG, "WaitForMultipleObjects failed");
71
+ break;
72
+ }
73
+
74
+ if (instance->CheckFileDescriptor(instance) != TRUE)
75
+ {
76
+ break;
77
+ }
78
+ }
79
+
80
+ instance->Close(instance);
81
+ }
82
+
83
+ int main(int argc, char* argv[])
84
+ {
85
+ freerdp_server_warn_unmaintained(argc, argv);
86
+ mf_server_info info = { .key = "server.key", .cert = "server.crt" };
87
+
88
+ freerdp_listener* instance;
89
+
90
+ signal(SIGPIPE, SIG_IGN);
91
+
92
+ WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
93
+
94
+ if (!(instance = freerdp_listener_new()))
95
+ return 1;
96
+
97
+ instance->info = &info;
98
+ instance->PeerAccepted = mf_peer_accepted;
99
+
100
+ if (instance->Open(instance, NULL, 3389))
101
+ {
102
+ mf_server_main_loop(instance);
103
+ }
104
+
105
+ freerdp_listener_free(instance);
106
+
107
+ return 0;
108
+ }
local-test-freerdp-full-01/afc-freerdp/server/Mac/mfreerdp.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Mac OS X Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_MAC_FREERDP_H
22
+ #define FREERDP_SERVER_MAC_FREERDP_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/listener.h>
26
+ #include <freerdp/codec/rfx.h>
27
+
28
+ #endif /* FREERDP_SERVER_MAC_FREERDP_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/CMakeLists.txt ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Sample Server cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ set(MODULE_NAME "sfreerdp-server")
19
+ set(MODULE_PREFIX "FREERDP_SERVER_SAMPLE")
20
+
21
+ set(SRCS
22
+ sfreerdp.c
23
+ sfreerdp.h
24
+ sf_audin.c
25
+ sf_audin.h
26
+ sf_rdpsnd.c
27
+ sf_rdpsnd.h
28
+ sf_encomsp.c
29
+ sf_encomsp.h
30
+ )
31
+
32
+ if(CHANNEL_AINPUT_SERVER)
33
+ list(APPEND SRCS sf_ainput.c sf_ainput.h)
34
+ endif()
35
+
36
+ option(SAMPLE_USE_VENDOR_PRODUCT_CONFIG_DIR "Use <vendor>/<product> path for resources" OFF)
37
+ set(SAMPLE_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR})
38
+ if(SAMPLE_USE_VENDOR_PRODUCT_CONFIG_DIR)
39
+ string(APPEND SAMPLE_RESOURCE_ROOT "/${VENDOR}")
40
+ endif()
41
+ string(APPEND SAMPLE_RESOURCE_ROOT "/${PRODUCT}")
42
+
43
+ if(WITH_RESOURCE_VERSIONING)
44
+ string(APPEND SAMPLE_RESOURCE_ROOT "${FREERDP_VERSION_MAJOR}")
45
+ endif()
46
+ string(APPEND SAMPLE_RESOURCE_ROOT "/images")
47
+
48
+ set(SAMPLE_ICONS test_icon.bmp test_icon.png test_icon.jpg test_icon.webp)
49
+ install(FILES ${SAMPLE_ICONS} DESTINATION ${SAMPLE_RESOURCE_ROOT})
50
+
51
+ # We need this in runtime path for TestConnect
52
+ file(COPY test_icon.bmp DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
53
+
54
+ addtargetwithresourcefile(${MODULE_NAME} TRUE "${FREERDP_VERSION}" SRCS)
55
+
56
+ target_compile_definitions(${MODULE_NAME} PRIVATE SAMPLE_RESOURCE_ROOT="${SAMPLE_RESOURCE_ROOT}")
57
+ list(APPEND LIBS freerdp-server)
58
+ list(APPEND LIBS winpr freerdp)
59
+
60
+ target_link_libraries(${MODULE_NAME} ${LIBS})
61
+ install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
62
+
63
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Sample")
local-test-freerdp-full-01/afc-freerdp/server/Sample/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_SERVER_NAME "sfreerdp-server")
2
+ set(FREERDP_SERVER_PLATFORM "Sample")
3
+ set(FREERDP_SERVER_VENDOR "FreeRDP")
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_ainput.c ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP: A Remote Desktop Protocol Implementation
4
+ * FreeRDP Sample Server (Advanced Input)
5
+ *
6
+ * Copyright 2022 Armin Novak <[email protected]>
7
+ * Copyright 2022 Thincast Technologies GmbH
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <winpr/assert.h>
25
+
26
+ #include "sfreerdp.h"
27
+
28
+ #include "sf_ainput.h"
29
+
30
+ #include <freerdp/server/server-common.h>
31
+ #include <freerdp/server/ainput.h>
32
+
33
+ #include <freerdp/log.h>
34
+ #define TAG SERVER_TAG("sample.ainput")
35
+
36
+ /**
37
+ * Function description
38
+ *
39
+ * @return 0 on success, otherwise a Win32 error code
40
+ */
41
+ static UINT sf_peer_ainput_mouse_event(ainput_server_context* context, UINT64 timestamp,
42
+ UINT64 flags, INT32 x, INT32 y)
43
+ {
44
+ /* TODO: Implement */
45
+ WINPR_ASSERT(context);
46
+
47
+ WLog_WARN(TAG, "not implemented: 0x%08" PRIx64 ", 0x%08" PRIx64 ", %" PRId32 "x%" PRId32,
48
+ timestamp, flags, x, y);
49
+ return CHANNEL_RC_OK;
50
+ }
51
+
52
+ void sf_peer_ainput_init(testPeerContext* context)
53
+ {
54
+ WINPR_ASSERT(context);
55
+
56
+ context->ainput = ainput_server_context_new(context->vcm);
57
+ WINPR_ASSERT(context->ainput);
58
+
59
+ context->ainput->rdpcontext = &context->_p;
60
+ context->ainput->data = context;
61
+
62
+ context->ainput->MouseEvent = sf_peer_ainput_mouse_event;
63
+ }
64
+
65
+ BOOL sf_peer_ainput_start(testPeerContext* context)
66
+ {
67
+ if (!context || !context->ainput || !context->ainput->Open)
68
+ return FALSE;
69
+
70
+ return context->ainput->Open(context->ainput) == CHANNEL_RC_OK;
71
+ }
72
+
73
+ BOOL sf_peer_ainput_stop(testPeerContext* context)
74
+ {
75
+ if (!context || !context->ainput || !context->ainput->Close)
76
+ return FALSE;
77
+
78
+ return context->ainput->Close(context->ainput) == CHANNEL_RC_OK;
79
+ }
80
+
81
+ BOOL sf_peer_ainput_running(testPeerContext* context)
82
+ {
83
+ if (!context || !context->ainput || !context->ainput->IsOpen)
84
+ return FALSE;
85
+
86
+ return context->ainput->IsOpen(context->ainput);
87
+ }
88
+
89
+ void sf_peer_ainput_uninit(testPeerContext* context)
90
+ {
91
+ ainput_server_context_free(context->ainput);
92
+ }
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_ainput.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Advanced Input)
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ * Copyright 2022 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_SAMPLE_SF_AINPUT_H
22
+ #define FREERDP_SERVER_SAMPLE_SF_AINPUT_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/listener.h>
26
+ #include <freerdp/server/ainput.h>
27
+
28
+ #include "sfreerdp.h"
29
+
30
+ void sf_peer_ainput_init(testPeerContext* context);
31
+ void sf_peer_ainput_uninit(testPeerContext* context);
32
+
33
+ BOOL sf_peer_ainput_running(testPeerContext* context);
34
+ BOOL sf_peer_ainput_start(testPeerContext* context);
35
+ BOOL sf_peer_ainput_stop(testPeerContext* context);
36
+
37
+ #endif /* FREERDP_SERVER_SAMPLE_SF_AINPUT_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_audin.c ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Audio Input)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2015 Thincast Technologies GmbH
7
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
8
+ * Copyright 2023 Pascal Nowack <[email protected]>
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ #include <freerdp/config.h>
24
+
25
+ #include <winpr/assert.h>
26
+
27
+ #include "sfreerdp.h"
28
+
29
+ #include "sf_audin.h"
30
+
31
+ #include <freerdp/server/server-common.h>
32
+ #include <freerdp/log.h>
33
+ #define TAG SERVER_TAG("sample")
34
+
35
+ #if defined(CHANNEL_AUDIN_SERVER)
36
+
37
+ static UINT sf_peer_audin_data(audin_server_context* audin, const SNDIN_DATA* data)
38
+ {
39
+ /* TODO: Implement */
40
+ WINPR_ASSERT(audin);
41
+ WINPR_ASSERT(data);
42
+
43
+ WLog_WARN(TAG, "not implemented");
44
+ WLog_DBG(TAG, "receive %" PRIdz " bytes.", Stream_Length(data->Data));
45
+ return CHANNEL_RC_OK;
46
+ }
47
+
48
+ #endif
49
+
50
+ BOOL sf_peer_audin_init(testPeerContext* context)
51
+ {
52
+ WINPR_ASSERT(context);
53
+ #if defined(CHANNEL_AUDIN_SERVER)
54
+ context->audin = audin_server_context_new(context->vcm);
55
+ WINPR_ASSERT(context->audin);
56
+
57
+ context->audin->rdpcontext = &context->_p;
58
+ context->audin->userdata = context;
59
+
60
+ context->audin->Data = sf_peer_audin_data;
61
+
62
+ return audin_server_set_formats(context->audin, -1, NULL);
63
+ #else
64
+ return TRUE;
65
+ #endif
66
+ }
67
+
68
+ BOOL sf_peer_audin_start(testPeerContext* context)
69
+ {
70
+ #if defined(CHANNEL_AUDIN_SERVER)
71
+ if (!context || !context->audin || !context->audin->Open)
72
+ return FALSE;
73
+
74
+ return context->audin->Open(context->audin);
75
+ #else
76
+ return FALSE;
77
+ #endif
78
+ }
79
+
80
+ BOOL sf_peer_audin_stop(testPeerContext* context)
81
+ {
82
+ #if defined(CHANNEL_AUDIN_SERVER)
83
+ if (!context || !context->audin || !context->audin->Close)
84
+ return FALSE;
85
+
86
+ return context->audin->Close(context->audin);
87
+ #else
88
+ return FALSE;
89
+ #endif
90
+ }
91
+
92
+ BOOL sf_peer_audin_running(testPeerContext* context)
93
+ {
94
+ #if defined(CHANNEL_AUDIN_SERVER)
95
+ if (!context || !context->audin || !context->audin->IsOpen)
96
+ return FALSE;
97
+
98
+ return context->audin->IsOpen(context->audin);
99
+ #else
100
+ return FALSE;
101
+ #endif
102
+ }
103
+
104
+ void sf_peer_audin_uninit(testPeerContext* context)
105
+ {
106
+ WINPR_ASSERT(context);
107
+
108
+ #if defined(CHANNEL_AUDIN_SERVER)
109
+ audin_server_context_free(context->audin);
110
+ context->audin = NULL;
111
+ #endif
112
+ }
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_audin.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Audio Input)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_SAMPLE_SF_AUDIN_H
21
+ #define FREERDP_SERVER_SAMPLE_SF_AUDIN_H
22
+
23
+ #include <freerdp/freerdp.h>
24
+ #include <freerdp/listener.h>
25
+
26
+ #include "sfreerdp.h"
27
+
28
+ BOOL sf_peer_audin_init(testPeerContext* context);
29
+ void sf_peer_audin_uninit(testPeerContext* context);
30
+
31
+ BOOL sf_peer_audin_running(testPeerContext* context);
32
+ BOOL sf_peer_audin_start(testPeerContext* context);
33
+ BOOL sf_peer_audin_stop(testPeerContext* context);
34
+
35
+ #endif /* FREERDP_SERVER_SAMPLE_SF_AUDIN_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_encomsp.c ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Lync Multiparty)
4
+ *
5
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2015 Thincast Technologies GmbH
7
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <winpr/assert.h>
25
+
26
+ #include "sf_encomsp.h"
27
+
28
+ BOOL sf_peer_encomsp_init(testPeerContext* context)
29
+ {
30
+ WINPR_ASSERT(context);
31
+
32
+ context->encomsp = encomsp_server_context_new(context->vcm);
33
+ if (!context->encomsp)
34
+ return FALSE;
35
+
36
+ context->encomsp->rdpcontext = &context->_p;
37
+
38
+ WINPR_ASSERT(context->encomsp->Start);
39
+ if (context->encomsp->Start(context->encomsp) != CHANNEL_RC_OK)
40
+ return FALSE;
41
+
42
+ return TRUE;
43
+ }
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_encomsp.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Lync Multiparty)
4
+ *
5
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_SAMPLE_SF_ENCOMSP_H
21
+ #define FREERDP_SERVER_SAMPLE_SF_ENCOMSP_H
22
+
23
+ #include <freerdp/freerdp.h>
24
+ #include <freerdp/listener.h>
25
+ #include <freerdp/server/encomsp.h>
26
+
27
+ #include "sfreerdp.h"
28
+
29
+ BOOL sf_peer_encomsp_init(testPeerContext* context);
30
+
31
+ #endif /* FREERDP_SERVER_SAMPLE_SF_ENCOMSP_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_rdpsnd.c ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Audio Output)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2015 Thincast Technologies GmbH
7
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <winpr/assert.h>
25
+
26
+ #include "sf_rdpsnd.h"
27
+
28
+ #include <freerdp/server/server-common.h>
29
+ #include <freerdp/log.h>
30
+ #define TAG SERVER_TAG("sample")
31
+
32
+ static void sf_peer_rdpsnd_activated(RdpsndServerContext* context)
33
+ {
34
+ WINPR_UNUSED(context);
35
+ WINPR_ASSERT(context);
36
+ WLog_DBG(TAG, "RDPSND Activated");
37
+ }
38
+
39
+ BOOL sf_peer_rdpsnd_init(testPeerContext* context)
40
+ {
41
+ WINPR_ASSERT(context);
42
+
43
+ context->rdpsnd = rdpsnd_server_context_new(context->vcm);
44
+ WINPR_ASSERT(context->rdpsnd);
45
+ context->rdpsnd->rdpcontext = &context->_p;
46
+ context->rdpsnd->data = context;
47
+ context->rdpsnd->num_server_formats =
48
+ server_rdpsnd_get_formats(&context->rdpsnd->server_formats);
49
+
50
+ if (context->rdpsnd->num_server_formats > 0)
51
+ context->rdpsnd->src_format = &context->rdpsnd->server_formats[0];
52
+
53
+ context->rdpsnd->Activated = sf_peer_rdpsnd_activated;
54
+
55
+ WINPR_ASSERT(context->rdpsnd->Initialize);
56
+ if (context->rdpsnd->Initialize(context->rdpsnd, TRUE) != CHANNEL_RC_OK)
57
+ {
58
+ return FALSE;
59
+ }
60
+
61
+ return TRUE;
62
+ }
local-test-freerdp-full-01/afc-freerdp/server/Sample/sf_rdpsnd.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server (Audio Output)
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_SAMPLE_SF_RDPSND_H
21
+ #define FREERDP_SERVER_SAMPLE_SF_RDPSND_H
22
+
23
+ #include <freerdp/freerdp.h>
24
+ #include <freerdp/listener.h>
25
+ #include <freerdp/server/rdpsnd.h>
26
+
27
+ #include "sfreerdp.h"
28
+
29
+ BOOL sf_peer_rdpsnd_init(testPeerContext* context);
30
+
31
+ #endif /* FREERDP_SERVER_SAMPLE_SF_RDPSND_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/sfreerdp.c ADDED
@@ -0,0 +1,1472 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Test Server
4
+ *
5
+ * Copyright 2011 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2011 Vic Lee
7
+ * Copyright 2014 Norbert Federa <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <errno.h>
25
+ #include <signal.h>
26
+
27
+ #include <winpr/winpr.h>
28
+ #include <winpr/crt.h>
29
+ #include <winpr/cast.h>
30
+ #include <winpr/assert.h>
31
+ #include <winpr/ssl.h>
32
+ #include <winpr/synch.h>
33
+ #include <winpr/file.h>
34
+ #include <winpr/string.h>
35
+ #include <winpr/path.h>
36
+ #include <winpr/image.h>
37
+ #include <winpr/winsock.h>
38
+
39
+ #include <freerdp/streamdump.h>
40
+ #include <freerdp/transport_io.h>
41
+
42
+ #include <freerdp/channels/wtsvc.h>
43
+ #include <freerdp/channels/channels.h>
44
+ #include <freerdp/channels/drdynvc.h>
45
+
46
+ #include <freerdp/freerdp.h>
47
+ #include <freerdp/constants.h>
48
+ #include <freerdp/server/rdpsnd.h>
49
+ #include <freerdp/settings.h>
50
+
51
+ #include "sf_ainput.h"
52
+ #include "sf_audin.h"
53
+ #include "sf_rdpsnd.h"
54
+ #include "sf_encomsp.h"
55
+
56
+ #include "sfreerdp.h"
57
+
58
+ #include <freerdp/log.h>
59
+ #define TAG SERVER_TAG("sample")
60
+
61
+ #define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1
62
+ #define SAMPLE_SERVER_DEFAULT_WIDTH 1024
63
+ #define SAMPLE_SERVER_DEFAULT_HEIGHT 768
64
+
65
+ struct server_info
66
+ {
67
+ BOOL test_dump_rfx_realtime;
68
+ const char* test_pcap_file;
69
+ const char* replay_dump;
70
+ const char* cert;
71
+ const char* key;
72
+ };
73
+
74
+ static void test_peer_context_free(freerdp_peer* client, rdpContext* ctx)
75
+ {
76
+ testPeerContext* context = (testPeerContext*)ctx;
77
+
78
+ WINPR_UNUSED(client);
79
+
80
+ if (context)
81
+ {
82
+ winpr_image_free(context->image, TRUE);
83
+ if (context->debug_channel_thread)
84
+ {
85
+ WINPR_ASSERT(context->stopEvent);
86
+ (void)SetEvent(context->stopEvent);
87
+ (void)WaitForSingleObject(context->debug_channel_thread, INFINITE);
88
+ (void)CloseHandle(context->debug_channel_thread);
89
+ }
90
+
91
+ Stream_Free(context->s, TRUE);
92
+ free(context->bg_data);
93
+ rfx_context_free(context->rfx_context);
94
+ nsc_context_free(context->nsc_context);
95
+
96
+ if (context->debug_channel)
97
+ (void)WTSVirtualChannelClose(context->debug_channel);
98
+
99
+ sf_peer_audin_uninit(context);
100
+
101
+ #if defined(CHANNEL_AINPUT_SERVER)
102
+ sf_peer_ainput_uninit(context);
103
+ #endif
104
+
105
+ rdpsnd_server_context_free(context->rdpsnd);
106
+ encomsp_server_context_free(context->encomsp);
107
+
108
+ WTSCloseServer(context->vcm);
109
+ }
110
+ }
111
+
112
+ static BOOL test_peer_context_new(freerdp_peer* client, rdpContext* ctx)
113
+ {
114
+ testPeerContext* context = (testPeerContext*)ctx;
115
+
116
+ WINPR_ASSERT(client);
117
+ WINPR_ASSERT(context);
118
+ WINPR_ASSERT(ctx->settings);
119
+
120
+ context->image = winpr_image_new();
121
+ if (!context->image)
122
+ goto fail;
123
+ if (!(context->rfx_context = rfx_context_new_ex(
124
+ TRUE, freerdp_settings_get_uint32(ctx->settings, FreeRDP_ThreadingFlags))))
125
+ goto fail;
126
+
127
+ if (!rfx_context_reset(context->rfx_context, SAMPLE_SERVER_DEFAULT_WIDTH,
128
+ SAMPLE_SERVER_DEFAULT_HEIGHT))
129
+ goto fail;
130
+
131
+ const UINT32 rlgr = freerdp_settings_get_uint32(ctx->settings, FreeRDP_RemoteFxRlgrMode);
132
+ rfx_context_set_mode(context->rfx_context, rlgr);
133
+
134
+ if (!(context->nsc_context = nsc_context_new()))
135
+ goto fail;
136
+
137
+ if (!(context->s = Stream_New(NULL, 65536)))
138
+ goto fail;
139
+
140
+ context->icon_x = UINT32_MAX;
141
+ context->icon_y = UINT32_MAX;
142
+ context->vcm = WTSOpenServerA((LPSTR)client->context);
143
+
144
+ if (!context->vcm || context->vcm == INVALID_HANDLE_VALUE)
145
+ goto fail;
146
+
147
+ return TRUE;
148
+ fail:
149
+ test_peer_context_free(client, ctx);
150
+ return FALSE;
151
+ }
152
+
153
+ static BOOL test_peer_init(freerdp_peer* client)
154
+ {
155
+ WINPR_ASSERT(client);
156
+
157
+ client->ContextSize = sizeof(testPeerContext);
158
+ client->ContextNew = test_peer_context_new;
159
+ client->ContextFree = test_peer_context_free;
160
+ return freerdp_peer_context_new(client);
161
+ }
162
+
163
+ static wStream* test_peer_stream_init(testPeerContext* context)
164
+ {
165
+ WINPR_ASSERT(context);
166
+ WINPR_ASSERT(context->s);
167
+
168
+ Stream_Clear(context->s);
169
+ Stream_SetPosition(context->s, 0);
170
+ return context->s;
171
+ }
172
+
173
+ static void test_peer_begin_frame(freerdp_peer* client)
174
+ {
175
+ rdpUpdate* update = NULL;
176
+ SURFACE_FRAME_MARKER fm = { 0 };
177
+ testPeerContext* context = NULL;
178
+
179
+ WINPR_ASSERT(client);
180
+ WINPR_ASSERT(client->context);
181
+
182
+ update = client->context->update;
183
+ WINPR_ASSERT(update);
184
+
185
+ context = (testPeerContext*)client->context;
186
+ WINPR_ASSERT(context);
187
+
188
+ fm.frameAction = SURFACECMD_FRAMEACTION_BEGIN;
189
+ fm.frameId = context->frame_id;
190
+ WINPR_ASSERT(update->SurfaceFrameMarker);
191
+ update->SurfaceFrameMarker(update->context, &fm);
192
+ }
193
+
194
+ static void test_peer_end_frame(freerdp_peer* client)
195
+ {
196
+ rdpUpdate* update = NULL;
197
+ SURFACE_FRAME_MARKER fm = { 0 };
198
+ testPeerContext* context = NULL;
199
+
200
+ WINPR_ASSERT(client);
201
+
202
+ context = (testPeerContext*)client->context;
203
+ WINPR_ASSERT(context);
204
+
205
+ update = client->context->update;
206
+ WINPR_ASSERT(update);
207
+
208
+ fm.frameAction = SURFACECMD_FRAMEACTION_END;
209
+ fm.frameId = context->frame_id;
210
+ WINPR_ASSERT(update->SurfaceFrameMarker);
211
+ update->SurfaceFrameMarker(update->context, &fm);
212
+ context->frame_id++;
213
+ }
214
+
215
+ static BOOL stream_surface_bits_supported(const rdpSettings* settings)
216
+ {
217
+ const UINT32 supported =
218
+ freerdp_settings_get_uint32(settings, FreeRDP_SurfaceCommandsSupported);
219
+ return ((supported & SURFCMDS_STREAM_SURFACE_BITS) != 0);
220
+ }
221
+
222
+ static BOOL test_peer_draw_background(freerdp_peer* client)
223
+ {
224
+ size_t size = 0;
225
+ wStream* s = NULL;
226
+ RFX_RECT rect;
227
+ BYTE* rgb_data = NULL;
228
+ const rdpSettings* settings = NULL;
229
+ rdpUpdate* update = NULL;
230
+ SURFACE_BITS_COMMAND cmd = { 0 };
231
+ testPeerContext* context = NULL;
232
+ BOOL ret = FALSE;
233
+ const UINT32 colorFormat = PIXEL_FORMAT_RGB24;
234
+ const size_t bpp = FreeRDPGetBytesPerPixel(colorFormat);
235
+
236
+ WINPR_ASSERT(client);
237
+ context = (testPeerContext*)client->context;
238
+ WINPR_ASSERT(context);
239
+
240
+ settings = client->context->settings;
241
+ WINPR_ASSERT(settings);
242
+
243
+ update = client->context->update;
244
+ WINPR_ASSERT(update);
245
+
246
+ const BOOL RemoteFxCodec = freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec);
247
+ if (!RemoteFxCodec && !freerdp_settings_get_bool(settings, FreeRDP_NSCodec))
248
+ return FALSE;
249
+
250
+ WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) <= UINT16_MAX);
251
+ WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) <= UINT16_MAX);
252
+
253
+ s = test_peer_stream_init(context);
254
+ rect.x = 0;
255
+ rect.y = 0;
256
+ rect.width = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
257
+ rect.height = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
258
+ size = bpp * rect.width * rect.height;
259
+
260
+ if (!(rgb_data = malloc(size)))
261
+ {
262
+ WLog_ERR(TAG, "Problem allocating memory");
263
+ return FALSE;
264
+ }
265
+
266
+ memset(rgb_data, 0xA0, size);
267
+
268
+ if (RemoteFxCodec && stream_surface_bits_supported(settings))
269
+ {
270
+ WLog_DBG(TAG, "Using RemoteFX codec");
271
+ rfx_context_set_pixel_format(context->rfx_context, colorFormat);
272
+
273
+ WINPR_ASSERT(bpp <= UINT16_MAX);
274
+ if (!rfx_compose_message(context->rfx_context, s, &rect, 1, rgb_data, rect.width,
275
+ rect.height, (UINT32)(bpp * rect.width)))
276
+ {
277
+ goto out;
278
+ }
279
+
280
+ const UINT32 RemoteFxCodecId =
281
+ freerdp_settings_get_uint32(settings, FreeRDP_RemoteFxCodecId);
282
+ WINPR_ASSERT(RemoteFxCodecId <= UINT16_MAX);
283
+ cmd.bmp.codecID = (UINT16)RemoteFxCodecId;
284
+ cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
285
+ }
286
+ else
287
+ {
288
+ WLog_DBG(TAG, "Using NSCodec");
289
+ nsc_context_set_parameters(context->nsc_context, NSC_COLOR_FORMAT, colorFormat);
290
+
291
+ WINPR_ASSERT(bpp <= UINT16_MAX);
292
+ nsc_compose_message(context->nsc_context, s, rgb_data, rect.width, rect.height,
293
+ (UINT32)(bpp * rect.width));
294
+ const UINT32 NSCodecId = freerdp_settings_get_uint32(settings, FreeRDP_NSCodecId);
295
+ WINPR_ASSERT(NSCodecId <= UINT16_MAX);
296
+ cmd.bmp.codecID = (UINT16)NSCodecId;
297
+ cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
298
+ }
299
+
300
+ cmd.destLeft = 0;
301
+ cmd.destTop = 0;
302
+ cmd.destRight = rect.width;
303
+ cmd.destBottom = rect.height;
304
+ cmd.bmp.bpp = 32;
305
+ cmd.bmp.flags = 0;
306
+ cmd.bmp.width = rect.width;
307
+ cmd.bmp.height = rect.height;
308
+ WINPR_ASSERT(Stream_GetPosition(s) <= UINT32_MAX);
309
+ cmd.bmp.bitmapDataLength = (UINT32)Stream_GetPosition(s);
310
+ cmd.bmp.bitmapData = Stream_Buffer(s);
311
+ test_peer_begin_frame(client);
312
+ update->SurfaceBits(update->context, &cmd);
313
+ test_peer_end_frame(client);
314
+ ret = TRUE;
315
+ out:
316
+ free(rgb_data);
317
+ return ret;
318
+ }
319
+
320
+ static int open_icon(wImage* img)
321
+ {
322
+ char* paths[] = { SAMPLE_RESOURCE_ROOT, "." };
323
+ const char* names[] = { "test_icon.webp", "test_icon.png", "test_icon.jpg", "test_icon.bmp" };
324
+
325
+ for (size_t x = 0; x < ARRAYSIZE(paths); x++)
326
+ {
327
+ const char* path = paths[x];
328
+ if (!winpr_PathFileExists(path))
329
+ continue;
330
+
331
+ for (size_t y = 0; y < ARRAYSIZE(names); y++)
332
+ {
333
+ const char* name = names[y];
334
+ char* file = GetCombinedPath(path, name);
335
+ int rc = winpr_image_read(img, file);
336
+ free(file);
337
+ if (rc > 0)
338
+ return rc;
339
+ }
340
+ }
341
+ WLog_ERR(TAG, "Unable to open test icon");
342
+ return -1;
343
+ }
344
+
345
+ static BOOL test_peer_load_icon(freerdp_peer* client)
346
+ {
347
+ testPeerContext* context = NULL;
348
+ rdpSettings* settings = NULL;
349
+
350
+ WINPR_ASSERT(client);
351
+
352
+ context = (testPeerContext*)client->context;
353
+ WINPR_ASSERT(context);
354
+
355
+ settings = client->context->settings;
356
+ WINPR_ASSERT(settings);
357
+
358
+ if (!freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec) &&
359
+ !freerdp_settings_get_bool(settings, FreeRDP_NSCodec))
360
+ {
361
+ WLog_ERR(TAG, "Client doesn't support RemoteFX or NSCodec");
362
+ return FALSE;
363
+ }
364
+
365
+ int rc = open_icon(context->image);
366
+ if (rc <= 0)
367
+ goto out_fail;
368
+
369
+ /* background with same size, which will be used to erase the icon from old position */
370
+ if (!(context->bg_data = calloc(context->image->height, 3ULL * context->image->width)))
371
+ goto out_fail;
372
+
373
+ memset(context->bg_data, 0xA0, 3ULL * context->image->height * context->image->width);
374
+ return TRUE;
375
+ out_fail:
376
+ context->bg_data = NULL;
377
+ return FALSE;
378
+ }
379
+
380
+ static void test_peer_draw_icon(freerdp_peer* client, UINT32 x, UINT32 y)
381
+ {
382
+ wStream* s = NULL;
383
+ RFX_RECT rect;
384
+ rdpUpdate* update = NULL;
385
+ rdpSettings* settings = NULL;
386
+ SURFACE_BITS_COMMAND cmd = { 0 };
387
+ testPeerContext* context = NULL;
388
+
389
+ WINPR_ASSERT(client);
390
+
391
+ context = (testPeerContext*)client->context;
392
+ WINPR_ASSERT(context);
393
+
394
+ update = client->context->update;
395
+ WINPR_ASSERT(update);
396
+
397
+ settings = client->context->settings;
398
+ WINPR_ASSERT(settings);
399
+
400
+ if (freerdp_settings_get_bool(settings, FreeRDP_DumpRemoteFx))
401
+ return;
402
+
403
+ if (context->image->width < 1 || !context->activated)
404
+ return;
405
+
406
+ rect.x = 0;
407
+ rect.y = 0;
408
+
409
+ rect.width = WINPR_ASSERTING_INT_CAST(UINT16, context->image->width);
410
+ rect.height = WINPR_ASSERTING_INT_CAST(UINT16, context->image->height);
411
+
412
+ const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
413
+ const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
414
+ if (context->icon_x + context->image->width > w)
415
+ return;
416
+ if (context->icon_y + context->image->height > h)
417
+ return;
418
+ if (x + context->image->width > w)
419
+ return;
420
+ if (y + context->image->height > h)
421
+ return;
422
+
423
+ test_peer_begin_frame(client);
424
+
425
+ const BOOL RemoteFxCodec = freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec);
426
+ if (RemoteFxCodec && stream_surface_bits_supported(settings))
427
+ {
428
+ const UINT32 RemoteFxCodecId =
429
+ freerdp_settings_get_uint32(settings, FreeRDP_RemoteFxCodecId);
430
+ WINPR_ASSERT(RemoteFxCodecId <= UINT16_MAX);
431
+ cmd.bmp.codecID = (UINT16)RemoteFxCodecId;
432
+ cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
433
+ }
434
+ else
435
+ {
436
+ const UINT32 NSCodecId = freerdp_settings_get_uint32(settings, FreeRDP_NSCodecId);
437
+ WINPR_ASSERT(NSCodecId <= UINT16_MAX);
438
+ cmd.bmp.codecID = (UINT16)NSCodecId;
439
+ cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
440
+ }
441
+
442
+ if (context->icon_x != UINT32_MAX)
443
+ {
444
+ const UINT32 colorFormat = PIXEL_FORMAT_RGB24;
445
+ const UINT32 bpp = FreeRDPGetBytesPerPixel(colorFormat);
446
+ s = test_peer_stream_init(context);
447
+
448
+ if (RemoteFxCodec)
449
+ {
450
+ rfx_context_set_pixel_format(context->rfx_context, colorFormat);
451
+ rfx_compose_message(context->rfx_context, s, &rect, 1, context->bg_data, rect.width,
452
+ rect.height, rect.width * bpp);
453
+ }
454
+ else
455
+ {
456
+ nsc_context_set_parameters(context->nsc_context, NSC_COLOR_FORMAT, colorFormat);
457
+ nsc_compose_message(context->nsc_context, s, context->bg_data, rect.width, rect.height,
458
+ rect.width * bpp);
459
+ }
460
+
461
+ cmd.destLeft = context->icon_x;
462
+ cmd.destTop = context->icon_y;
463
+ cmd.destRight = context->icon_x + rect.width;
464
+ cmd.destBottom = context->icon_y + rect.height;
465
+ cmd.bmp.bpp = 32;
466
+ cmd.bmp.flags = 0;
467
+ cmd.bmp.width = rect.width;
468
+ cmd.bmp.height = rect.height;
469
+ cmd.bmp.bitmapDataLength = (UINT32)Stream_GetPosition(s);
470
+ cmd.bmp.bitmapData = Stream_Buffer(s);
471
+ WINPR_ASSERT(update->SurfaceBits);
472
+ update->SurfaceBits(update->context, &cmd);
473
+ }
474
+
475
+ s = test_peer_stream_init(context);
476
+
477
+ {
478
+ const UINT32 colorFormat =
479
+ context->image->bitsPerPixel > 24 ? PIXEL_FORMAT_BGRA32 : PIXEL_FORMAT_BGR24;
480
+
481
+ if (RemoteFxCodec)
482
+ {
483
+ rfx_context_set_pixel_format(context->rfx_context, colorFormat);
484
+ rfx_compose_message(context->rfx_context, s, &rect, 1, context->image->data, rect.width,
485
+ rect.height, context->image->scanline);
486
+ }
487
+ else
488
+ {
489
+ nsc_context_set_parameters(context->nsc_context, NSC_COLOR_FORMAT, colorFormat);
490
+ nsc_compose_message(context->nsc_context, s, context->image->data, rect.width,
491
+ rect.height, context->image->scanline);
492
+ }
493
+ }
494
+
495
+ cmd.destLeft = x;
496
+ cmd.destTop = y;
497
+ cmd.destRight = x + rect.width;
498
+ cmd.destBottom = y + rect.height;
499
+ cmd.bmp.bpp = 32;
500
+ cmd.bmp.width = rect.width;
501
+ cmd.bmp.height = rect.height;
502
+ cmd.bmp.bitmapDataLength = (UINT32)Stream_GetPosition(s);
503
+ cmd.bmp.bitmapData = Stream_Buffer(s);
504
+ WINPR_ASSERT(update->SurfaceBits);
505
+ update->SurfaceBits(update->context, &cmd);
506
+ context->icon_x = x;
507
+ context->icon_y = y;
508
+ test_peer_end_frame(client);
509
+ }
510
+
511
+ static BOOL test_sleep_tsdiff(UINT32* old_sec, UINT32* old_usec, UINT32 new_sec, UINT32 new_usec)
512
+ {
513
+ INT64 sec = 0;
514
+ INT64 usec = 0;
515
+
516
+ WINPR_ASSERT(old_sec);
517
+ WINPR_ASSERT(old_usec);
518
+
519
+ if ((*old_sec == 0) && (*old_usec == 0))
520
+ {
521
+ *old_sec = new_sec;
522
+ *old_usec = new_usec;
523
+ return TRUE;
524
+ }
525
+
526
+ sec = new_sec - *old_sec;
527
+ usec = new_usec - *old_usec;
528
+
529
+ if ((sec < 0) || ((sec == 0) && (usec < 0)))
530
+ {
531
+ WLog_ERR(TAG, "Invalid time stamp detected.");
532
+ return FALSE;
533
+ }
534
+
535
+ *old_sec = new_sec;
536
+ *old_usec = new_usec;
537
+
538
+ while (usec < 0)
539
+ {
540
+ usec += 1000000;
541
+ sec--;
542
+ }
543
+
544
+ if (sec > 0)
545
+ Sleep((DWORD)sec * 1000);
546
+
547
+ if (usec > 0)
548
+ USleep((DWORD)usec);
549
+
550
+ return TRUE;
551
+ }
552
+
553
+ static BOOL tf_peer_dump_rfx(freerdp_peer* client)
554
+ {
555
+ BOOL rc = FALSE;
556
+ wStream* s = NULL;
557
+ UINT32 prev_seconds = 0;
558
+ UINT32 prev_useconds = 0;
559
+ rdpUpdate* update = NULL;
560
+ rdpPcap* pcap_rfx = NULL;
561
+ pcap_record record = { 0 };
562
+ struct server_info* info = NULL;
563
+
564
+ WINPR_ASSERT(client);
565
+ WINPR_ASSERT(client->context);
566
+
567
+ info = client->ContextExtra;
568
+ WINPR_ASSERT(info);
569
+
570
+ s = Stream_New(NULL, 512);
571
+
572
+ if (!s)
573
+ return FALSE;
574
+
575
+ update = client->context->update;
576
+ WINPR_ASSERT(update);
577
+
578
+ pcap_rfx = pcap_open(info->test_pcap_file, FALSE);
579
+ if (!pcap_rfx)
580
+ goto fail;
581
+
582
+ prev_seconds = prev_useconds = 0;
583
+
584
+ while (pcap_has_next_record(pcap_rfx))
585
+ {
586
+ if (!pcap_get_next_record_header(pcap_rfx, &record))
587
+ break;
588
+
589
+ if (!Stream_EnsureCapacity(s, record.length))
590
+ break;
591
+
592
+ record.data = Stream_Buffer(s);
593
+ pcap_get_next_record_content(pcap_rfx, &record);
594
+ Stream_SetPosition(s, Stream_Capacity(s));
595
+
596
+ if (info->test_dump_rfx_realtime &&
597
+ test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec,
598
+ record.header.ts_usec) == FALSE)
599
+ break;
600
+
601
+ WINPR_ASSERT(update->SurfaceCommand);
602
+ update->SurfaceCommand(update->context, s);
603
+
604
+ WINPR_ASSERT(client->CheckFileDescriptor);
605
+ if (client->CheckFileDescriptor(client) != TRUE)
606
+ break;
607
+ }
608
+
609
+ rc = TRUE;
610
+ fail:
611
+ Stream_Free(s, TRUE);
612
+ pcap_close(pcap_rfx);
613
+ return rc;
614
+ }
615
+
616
+ static DWORD WINAPI tf_debug_channel_thread_func(LPVOID arg)
617
+ {
618
+ void* fd = NULL;
619
+ void* buffer = NULL;
620
+ DWORD BytesReturned = 0;
621
+ ULONG written = 0;
622
+ testPeerContext* context = (testPeerContext*)arg;
623
+
624
+ WINPR_ASSERT(context);
625
+ if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer,
626
+ &BytesReturned) == TRUE)
627
+ {
628
+ fd = *((void**)buffer);
629
+ WTSFreeMemory(buffer);
630
+
631
+ if (!(context->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd)))
632
+ return 0;
633
+ }
634
+
635
+ wStream* s = Stream_New(NULL, 4096);
636
+ if (!s)
637
+ goto fail;
638
+
639
+ if (!WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test1", 5, &written))
640
+ goto fail;
641
+
642
+ while (1)
643
+ {
644
+ DWORD status = 0;
645
+ DWORD nCount = 0;
646
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
647
+
648
+ handles[nCount++] = context->event;
649
+ handles[nCount++] = freerdp_abort_event(&context->_p);
650
+ handles[nCount++] = context->stopEvent;
651
+ status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
652
+ switch (status)
653
+ {
654
+ case WAIT_OBJECT_0:
655
+ break;
656
+ default:
657
+ goto fail;
658
+ }
659
+
660
+ Stream_SetPosition(s, 0);
661
+
662
+ if (WTSVirtualChannelRead(context->debug_channel, 0, Stream_BufferAs(s, char),
663
+ (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
664
+ {
665
+ if (BytesReturned == 0)
666
+ break;
667
+
668
+ if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
669
+ break;
670
+
671
+ if (WTSVirtualChannelRead(context->debug_channel, 0, Stream_BufferAs(s, char),
672
+ (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
673
+ {
674
+ /* should not happen */
675
+ break;
676
+ }
677
+ }
678
+
679
+ Stream_SetPosition(s, BytesReturned);
680
+ WLog_DBG(TAG, "got %" PRIu32 " bytes", BytesReturned);
681
+ }
682
+ fail:
683
+ Stream_Free(s, TRUE);
684
+ return 0;
685
+ }
686
+
687
+ static BOOL tf_peer_post_connect(freerdp_peer* client)
688
+ {
689
+ testPeerContext* context = NULL;
690
+ rdpSettings* settings = NULL;
691
+
692
+ WINPR_ASSERT(client);
693
+
694
+ context = (testPeerContext*)client->context;
695
+ WINPR_ASSERT(context);
696
+
697
+ settings = client->context->settings;
698
+ WINPR_ASSERT(settings);
699
+
700
+ /**
701
+ * This callback is called when the entire connection sequence is done, i.e. we've received the
702
+ * Font List PDU from the client and sent out the Font Map PDU.
703
+ * The server may start sending graphics output and receiving keyboard/mouse input after this
704
+ * callback returns.
705
+ */
706
+ WLog_DBG(TAG, "Client %s is activated (osMajorType %" PRIu32 " osMinorType %" PRIu32 ")",
707
+ client->local ? "(local)" : client->hostname,
708
+ freerdp_settings_get_uint32(settings, FreeRDP_OsMajorType),
709
+ freerdp_settings_get_uint32(settings, FreeRDP_OsMinorType));
710
+
711
+ if (freerdp_settings_get_bool(settings, FreeRDP_AutoLogonEnabled))
712
+ {
713
+ const char* Username = freerdp_settings_get_string(settings, FreeRDP_Username);
714
+ const char* Domain = freerdp_settings_get_string(settings, FreeRDP_Domain);
715
+ WLog_DBG(TAG, " and wants to login automatically as %s\\%s", Domain ? Domain : "",
716
+ Username);
717
+ /* A real server may perform OS login here if NLA is not executed previously. */
718
+ }
719
+
720
+ WLog_DBG(TAG, "");
721
+ WLog_DBG(TAG, "Client requested desktop: %" PRIu32 "x%" PRIu32 "x%" PRIu32 "",
722
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
723
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
724
+ freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
725
+ #if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1)
726
+
727
+ if (!rfx_context_reset(context->rfx_context,
728
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
729
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
730
+ return FALSE;
731
+
732
+ WLog_DBG(TAG, "Using resolution requested by client.");
733
+ #else
734
+ client->freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) =
735
+ context->rfx_context->width;
736
+ client->freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) =
737
+ context->rfx_context->height;
738
+ WLog_DBG(TAG, "Resizing client to %" PRIu32 "x%" PRIu32 "",
739
+ client->freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
740
+ client->freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
741
+ client->update->DesktopResize(client->update->context);
742
+ #endif
743
+
744
+ /* A real server should tag the peer as activated here and start sending updates in main loop.
745
+ */
746
+ if (!test_peer_load_icon(client))
747
+ {
748
+ WLog_DBG(TAG, "Unable to load icon");
749
+ return FALSE;
750
+ }
751
+
752
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpdbg"))
753
+ {
754
+ context->debug_channel = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpdbg");
755
+
756
+ if (context->debug_channel != NULL)
757
+ {
758
+ WLog_DBG(TAG, "Open channel rdpdbg.");
759
+
760
+ if (!(context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
761
+ {
762
+ WLog_ERR(TAG, "Failed to create stop event");
763
+ return FALSE;
764
+ }
765
+
766
+ if (!(context->debug_channel_thread =
767
+ CreateThread(NULL, 0, tf_debug_channel_thread_func, (void*)context, 0, NULL)))
768
+ {
769
+ WLog_ERR(TAG, "Failed to create debug channel thread");
770
+ (void)CloseHandle(context->stopEvent);
771
+ context->stopEvent = NULL;
772
+ return FALSE;
773
+ }
774
+ }
775
+ }
776
+
777
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, RDPSND_CHANNEL_NAME))
778
+ {
779
+ sf_peer_rdpsnd_init(context); /* Audio Output */
780
+ }
781
+
782
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, ENCOMSP_SVC_CHANNEL_NAME))
783
+ {
784
+ sf_peer_encomsp_init(context); /* Lync Multiparty */
785
+ }
786
+
787
+ /* Dynamic Virtual Channels */
788
+ sf_peer_audin_init(context); /* Audio Input */
789
+
790
+ #if defined(CHANNEL_AINPUT_SERVER)
791
+ sf_peer_ainput_init(context);
792
+ #endif
793
+
794
+ /* Return FALSE here would stop the execution of the peer main loop. */
795
+ return TRUE;
796
+ }
797
+
798
+ static BOOL tf_peer_activate(freerdp_peer* client)
799
+ {
800
+ testPeerContext* context = NULL;
801
+ struct server_info* info = NULL;
802
+ rdpSettings* settings = NULL;
803
+
804
+ WINPR_ASSERT(client);
805
+
806
+ context = (testPeerContext*)client->context;
807
+ WINPR_ASSERT(context);
808
+
809
+ settings = client->context->settings;
810
+ WINPR_ASSERT(settings);
811
+
812
+ info = client->ContextExtra;
813
+ WINPR_ASSERT(info);
814
+
815
+ context->activated = TRUE;
816
+ // PACKET_COMPR_TYPE_8K;
817
+ // PACKET_COMPR_TYPE_64K;
818
+ // PACKET_COMPR_TYPE_RDP6;
819
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_CompressionLevel, PACKET_COMPR_TYPE_RDP8))
820
+ return FALSE;
821
+
822
+ if (info->test_pcap_file != NULL)
823
+ {
824
+ if (!freerdp_settings_set_bool(settings, FreeRDP_DumpRemoteFx, TRUE))
825
+ return FALSE;
826
+
827
+ if (!tf_peer_dump_rfx(client))
828
+ return FALSE;
829
+ }
830
+ else
831
+ test_peer_draw_background(client);
832
+
833
+ return TRUE;
834
+ }
835
+
836
+ static BOOL tf_peer_synchronize_event(rdpInput* input, UINT32 flags)
837
+ {
838
+ WINPR_UNUSED(input);
839
+ WINPR_ASSERT(input);
840
+ WLog_DBG(TAG, "Client sent a synchronize event (flags:0x%" PRIX32 ")", flags);
841
+ return TRUE;
842
+ }
843
+
844
+ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
845
+ {
846
+ freerdp_peer* client = NULL;
847
+ rdpUpdate* update = NULL;
848
+ rdpContext* context = NULL;
849
+ testPeerContext* tcontext = NULL;
850
+ rdpSettings* settings = NULL;
851
+
852
+ WINPR_ASSERT(input);
853
+
854
+ context = input->context;
855
+ WINPR_ASSERT(context);
856
+
857
+ client = context->peer;
858
+ WINPR_ASSERT(client);
859
+
860
+ settings = context->settings;
861
+ WINPR_ASSERT(settings);
862
+
863
+ update = context->update;
864
+ WINPR_ASSERT(update);
865
+
866
+ tcontext = (testPeerContext*)context;
867
+ WINPR_ASSERT(tcontext);
868
+
869
+ WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%04" PRIX16 " code:0x%04" PRIX8 ")", flags,
870
+ code);
871
+
872
+ if (((flags & KBD_FLAGS_RELEASE) == 0) && (code == RDP_SCANCODE_KEY_G)) /* 'g' key */
873
+ {
874
+ if (freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) != 800)
875
+ {
876
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 800))
877
+ return FALSE;
878
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 600))
879
+ return FALSE;
880
+ }
881
+ else
882
+ {
883
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth,
884
+ SAMPLE_SERVER_DEFAULT_WIDTH))
885
+ return FALSE;
886
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight,
887
+ SAMPLE_SERVER_DEFAULT_HEIGHT))
888
+ return FALSE;
889
+ }
890
+
891
+ if (!rfx_context_reset(tcontext->rfx_context,
892
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
893
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
894
+ return FALSE;
895
+
896
+ WINPR_ASSERT(update->DesktopResize);
897
+ update->DesktopResize(update->context);
898
+ tcontext->activated = FALSE;
899
+ }
900
+ else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_C) /* 'c' key */
901
+ {
902
+ if (tcontext->debug_channel)
903
+ {
904
+ ULONG written = 0;
905
+ if (!WTSVirtualChannelWrite(tcontext->debug_channel, (PCHAR) "test2", 5, &written))
906
+ return FALSE;
907
+ }
908
+ }
909
+ else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_X) /* 'x' key */
910
+ {
911
+ WINPR_ASSERT(client->Close);
912
+ client->Close(client);
913
+ }
914
+ else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_R) /* 'r' key */
915
+ {
916
+ tcontext->audin_open = !tcontext->audin_open;
917
+ }
918
+ #if defined(CHANNEL_AINPUT_SERVER)
919
+ else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_I) /* 'i' key */
920
+ {
921
+ tcontext->ainput_open = !tcontext->ainput_open;
922
+ }
923
+ #endif
924
+ else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_S) /* 's' key */
925
+ {
926
+ }
927
+
928
+ return TRUE;
929
+ }
930
+
931
+ static BOOL tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
932
+ {
933
+ WINPR_UNUSED(input);
934
+ WINPR_ASSERT(input);
935
+
936
+ WLog_DBG(TAG,
937
+ "Client sent a unicode keyboard event (flags:0x%04" PRIX16 " code:0x%04" PRIX16 ")",
938
+ flags, code);
939
+ return TRUE;
940
+ }
941
+
942
+ static BOOL tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
943
+ {
944
+ WINPR_UNUSED(flags);
945
+ WINPR_ASSERT(input);
946
+ WINPR_ASSERT(input->context);
947
+
948
+ // WLog_DBG(TAG, "Client sent a mouse event (flags:0x%04"PRIX16" pos:%"PRIu16",%"PRIu16")",
949
+ // flags, x, y);
950
+ test_peer_draw_icon(input->context->peer, x + 10, y);
951
+ return TRUE;
952
+ }
953
+
954
+ static BOOL tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
955
+ {
956
+ WINPR_UNUSED(flags);
957
+ WINPR_ASSERT(input);
958
+ WINPR_ASSERT(input->context);
959
+
960
+ // WLog_DBG(TAG, "Client sent an extended mouse event (flags:0x%04"PRIX16"
961
+ // pos:%"PRIu16",%"PRIu16")", flags, x, y);
962
+ test_peer_draw_icon(input->context->peer, x + 10, y);
963
+ return TRUE;
964
+ }
965
+
966
+ static BOOL tf_peer_refresh_rect(rdpContext* context, BYTE count, const RECTANGLE_16* areas)
967
+ {
968
+ WINPR_UNUSED(context);
969
+ WINPR_ASSERT(context);
970
+ WINPR_ASSERT(areas || (count == 0));
971
+
972
+ WLog_DBG(TAG, "Client requested to refresh:");
973
+
974
+ for (BYTE i = 0; i < count; i++)
975
+ {
976
+ WLog_DBG(TAG, " (%" PRIu16 ", %" PRIu16 ") (%" PRIu16 ", %" PRIu16 ")", areas[i].left,
977
+ areas[i].top, areas[i].right, areas[i].bottom);
978
+ }
979
+
980
+ return TRUE;
981
+ }
982
+
983
+ static BOOL tf_peer_suppress_output(rdpContext* context, BYTE allow, const RECTANGLE_16* area)
984
+ {
985
+ WINPR_UNUSED(context);
986
+
987
+ if (allow > 0)
988
+ {
989
+ WINPR_ASSERT(area);
990
+ WLog_DBG(TAG,
991
+ "Client restore output (%" PRIu16 ", %" PRIu16 ") (%" PRIu16 ", %" PRIu16 ").",
992
+ area->left, area->top, area->right, area->bottom);
993
+ }
994
+ else
995
+ {
996
+ WLog_DBG(TAG, "Client minimized and suppress output.");
997
+ }
998
+
999
+ return TRUE;
1000
+ }
1001
+
1002
+ static int hook_peer_write_pdu(rdpTransport* transport, wStream* s)
1003
+ {
1004
+ UINT64 ts = 0;
1005
+ wStream* ls = NULL;
1006
+ UINT64 last_ts = 0;
1007
+ const struct server_info* info = NULL;
1008
+ freerdp_peer* client = NULL;
1009
+ testPeerContext* peerCtx = NULL;
1010
+ size_t offset = 0;
1011
+ UINT32 flags = 0;
1012
+ rdpContext* context = transport_get_context(transport);
1013
+
1014
+ WINPR_ASSERT(context);
1015
+ WINPR_ASSERT(s);
1016
+
1017
+ client = context->peer;
1018
+ WINPR_ASSERT(client);
1019
+
1020
+ peerCtx = (testPeerContext*)client->context;
1021
+ WINPR_ASSERT(peerCtx);
1022
+ WINPR_ASSERT(peerCtx->io.WritePdu);
1023
+
1024
+ info = client->ContextExtra;
1025
+ WINPR_ASSERT(info);
1026
+
1027
+ /* Let the client authenticate.
1028
+ * After that is done, we stop the normal operation and send
1029
+ * a previously recorded session PDU by PDU to the client.
1030
+ *
1031
+ * This is fragile and the connecting client needs to use the same
1032
+ * configuration as the one that recorded the session!
1033
+ */
1034
+ WINPR_ASSERT(info);
1035
+ CONNECTION_STATE state = freerdp_get_state(context);
1036
+ if (state < CONNECTION_STATE_NEGO)
1037
+ return peerCtx->io.WritePdu(transport, s);
1038
+
1039
+ ls = Stream_New(NULL, 4096);
1040
+ if (!ls)
1041
+ goto fail;
1042
+
1043
+ while (stream_dump_get(context, &flags, ls, &offset, &ts) > 0)
1044
+ {
1045
+ int rc = 0;
1046
+ /* Skip messages from client. */
1047
+ if (flags & STREAM_MSG_SRV_TX)
1048
+ {
1049
+ if ((last_ts > 0) && (ts > last_ts))
1050
+ {
1051
+ UINT64 diff = ts - last_ts;
1052
+ while (diff > 0)
1053
+ {
1054
+ UINT32 d = diff > UINT32_MAX ? UINT32_MAX : (UINT32)diff;
1055
+ diff -= d;
1056
+ Sleep(d);
1057
+ }
1058
+ }
1059
+ last_ts = ts;
1060
+ rc = peerCtx->io.WritePdu(transport, ls);
1061
+ if (rc < 0)
1062
+ goto fail;
1063
+ }
1064
+ Stream_SetPosition(ls, 0);
1065
+ }
1066
+
1067
+ fail:
1068
+ Stream_Free(ls, TRUE);
1069
+ return -1;
1070
+ }
1071
+
1072
+ static DWORD WINAPI test_peer_mainloop(LPVOID arg)
1073
+ {
1074
+ BOOL rc = 0;
1075
+ DWORD error = CHANNEL_RC_OK;
1076
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
1077
+ DWORD count = 0;
1078
+ DWORD status = 0;
1079
+ testPeerContext* context = NULL;
1080
+ struct server_info* info = NULL;
1081
+ rdpSettings* settings = NULL;
1082
+ rdpInput* input = NULL;
1083
+ rdpUpdate* update = NULL;
1084
+ freerdp_peer* client = (freerdp_peer*)arg;
1085
+
1086
+ WINPR_ASSERT(client);
1087
+
1088
+ info = client->ContextExtra;
1089
+ WINPR_ASSERT(info);
1090
+
1091
+ if (!test_peer_init(client))
1092
+ {
1093
+ freerdp_peer_free(client);
1094
+ return 0;
1095
+ }
1096
+
1097
+ /* Initialize the real server settings here */
1098
+ WINPR_ASSERT(client->context);
1099
+ settings = client->context->settings;
1100
+ WINPR_ASSERT(settings);
1101
+ if (info->replay_dump)
1102
+ {
1103
+ if (!freerdp_settings_set_bool(settings, FreeRDP_TransportDumpReplay, TRUE) ||
1104
+ !freerdp_settings_set_string(settings, FreeRDP_TransportDumpFile, info->replay_dump))
1105
+ goto fail;
1106
+ }
1107
+
1108
+ rdpPrivateKey* key = freerdp_key_new_from_file(info->key);
1109
+ if (!key)
1110
+ goto fail;
1111
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1))
1112
+ goto fail;
1113
+ rdpCertificate* cert = freerdp_certificate_new_from_file(info->cert);
1114
+ if (!cert)
1115
+ goto fail;
1116
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1))
1117
+ goto fail;
1118
+
1119
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE))
1120
+ goto fail;
1121
+ if (!freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE))
1122
+ goto fail;
1123
+ if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE))
1124
+ goto fail;
1125
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel,
1126
+ ENCRYPTION_LEVEL_CLIENT_COMPATIBLE))
1127
+ goto fail;
1128
+ /* ENCRYPTION_LEVEL_HIGH; */
1129
+ /* ENCRYPTION_LEVEL_LOW; */
1130
+ /* ENCRYPTION_LEVEL_FIPS; */
1131
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE))
1132
+ goto fail;
1133
+ if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE) ||
1134
+ !freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32))
1135
+ goto fail;
1136
+
1137
+ if (!freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE))
1138
+ goto fail;
1139
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RefreshRect, TRUE))
1140
+ goto fail;
1141
+
1142
+ client->PostConnect = tf_peer_post_connect;
1143
+ client->Activate = tf_peer_activate;
1144
+
1145
+ WINPR_ASSERT(client->context);
1146
+ input = client->context->input;
1147
+ WINPR_ASSERT(input);
1148
+
1149
+ input->SynchronizeEvent = tf_peer_synchronize_event;
1150
+ input->KeyboardEvent = tf_peer_keyboard_event;
1151
+ input->UnicodeKeyboardEvent = tf_peer_unicode_keyboard_event;
1152
+ input->MouseEvent = tf_peer_mouse_event;
1153
+ input->ExtendedMouseEvent = tf_peer_extended_mouse_event;
1154
+
1155
+ update = client->context->update;
1156
+ WINPR_ASSERT(update);
1157
+
1158
+ update->RefreshRect = tf_peer_refresh_rect;
1159
+ update->SuppressOutput = tf_peer_suppress_output;
1160
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize,
1161
+ 0xFFFFFF /* FIXME */))
1162
+ goto fail;
1163
+
1164
+ WINPR_ASSERT(client->Initialize);
1165
+ rc = client->Initialize(client);
1166
+ if (!rc)
1167
+ goto fail;
1168
+
1169
+ context = (testPeerContext*)client->context;
1170
+ WINPR_ASSERT(context);
1171
+
1172
+ if (info->replay_dump)
1173
+ {
1174
+ const rdpTransportIo* cb = freerdp_get_io_callbacks(client->context);
1175
+ rdpTransportIo replay;
1176
+
1177
+ WINPR_ASSERT(cb);
1178
+ replay = *cb;
1179
+ context->io = *cb;
1180
+ replay.WritePdu = hook_peer_write_pdu;
1181
+ freerdp_set_io_callbacks(client->context, &replay);
1182
+ }
1183
+
1184
+ WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname);
1185
+
1186
+ while (error == CHANNEL_RC_OK)
1187
+ {
1188
+ count = 0;
1189
+ {
1190
+ WINPR_ASSERT(client->GetEventHandles);
1191
+ DWORD tmp = client->GetEventHandles(client, &handles[count], 32 - count);
1192
+
1193
+ if (tmp == 0)
1194
+ {
1195
+ WLog_ERR(TAG, "Failed to get FreeRDP transport event handles");
1196
+ break;
1197
+ }
1198
+
1199
+ count += tmp;
1200
+ }
1201
+
1202
+ HANDLE channelHandle = WTSVirtualChannelManagerGetEventHandle(context->vcm);
1203
+ handles[count++] = channelHandle;
1204
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
1205
+
1206
+ if (status == WAIT_FAILED)
1207
+ {
1208
+ WLog_ERR(TAG, "WaitForMultipleObjects failed (errno: %d)", errno);
1209
+ break;
1210
+ }
1211
+
1212
+ WINPR_ASSERT(client->CheckFileDescriptor);
1213
+ if (client->CheckFileDescriptor(client) != TRUE)
1214
+ break;
1215
+
1216
+ if (WaitForSingleObject(channelHandle, 0) != WAIT_OBJECT_0)
1217
+ continue;
1218
+
1219
+ if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
1220
+ break;
1221
+
1222
+ /* Handle dynamic virtual channel initializations */
1223
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, DRDYNVC_SVC_CHANNEL_NAME))
1224
+ {
1225
+ switch (WTSVirtualChannelManagerGetDrdynvcState(context->vcm))
1226
+ {
1227
+ case DRDYNVC_STATE_NONE:
1228
+ break;
1229
+
1230
+ case DRDYNVC_STATE_INITIALIZED:
1231
+ break;
1232
+
1233
+ case DRDYNVC_STATE_READY:
1234
+
1235
+ /* Here is the correct state to start dynamic virtual channels */
1236
+ if (sf_peer_audin_running(context) != context->audin_open)
1237
+ {
1238
+ if (!sf_peer_audin_running(context))
1239
+ sf_peer_audin_start(context);
1240
+ else
1241
+ sf_peer_audin_stop(context);
1242
+ }
1243
+
1244
+ #if defined(CHANNEL_AINPUT_SERVER)
1245
+ if (sf_peer_ainput_running(context) != context->ainput_open)
1246
+ {
1247
+ if (!sf_peer_ainput_running(context))
1248
+ sf_peer_ainput_start(context);
1249
+ else
1250
+ sf_peer_ainput_stop(context);
1251
+ }
1252
+ #endif
1253
+
1254
+ break;
1255
+
1256
+ case DRDYNVC_STATE_FAILED:
1257
+ default:
1258
+ break;
1259
+ }
1260
+ }
1261
+ }
1262
+
1263
+ WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname);
1264
+
1265
+ WINPR_ASSERT(client->Disconnect);
1266
+ client->Disconnect(client);
1267
+ fail:
1268
+ freerdp_peer_context_free(client);
1269
+ freerdp_peer_free(client);
1270
+ return error;
1271
+ }
1272
+
1273
+ static BOOL test_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
1274
+ {
1275
+ HANDLE hThread = NULL;
1276
+ struct server_info* info = NULL;
1277
+
1278
+ WINPR_UNUSED(instance);
1279
+
1280
+ WINPR_ASSERT(instance);
1281
+ WINPR_ASSERT(client);
1282
+
1283
+ info = instance->info;
1284
+ client->ContextExtra = info;
1285
+
1286
+ if (!(hThread = CreateThread(NULL, 0, test_peer_mainloop, (void*)client, 0, NULL)))
1287
+ return FALSE;
1288
+
1289
+ (void)CloseHandle(hThread);
1290
+ return TRUE;
1291
+ }
1292
+
1293
+ static void test_server_mainloop(freerdp_listener* instance)
1294
+ {
1295
+ HANDLE handles[32] = { 0 };
1296
+ DWORD count = 0;
1297
+ DWORD status = 0;
1298
+
1299
+ WINPR_ASSERT(instance);
1300
+ while (1)
1301
+ {
1302
+ WINPR_ASSERT(instance->GetEventHandles);
1303
+ count = instance->GetEventHandles(instance, handles, 32);
1304
+
1305
+ if (0 == count)
1306
+ {
1307
+ WLog_ERR(TAG, "Failed to get FreeRDP event handles");
1308
+ break;
1309
+ }
1310
+
1311
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
1312
+
1313
+ if (WAIT_FAILED == status)
1314
+ {
1315
+ WLog_ERR(TAG, "select failed");
1316
+ break;
1317
+ }
1318
+
1319
+ WINPR_ASSERT(instance->CheckFileDescriptor);
1320
+ if (instance->CheckFileDescriptor(instance) != TRUE)
1321
+ {
1322
+ WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
1323
+ break;
1324
+ }
1325
+ }
1326
+
1327
+ WINPR_ASSERT(instance->Close);
1328
+ instance->Close(instance);
1329
+ }
1330
+
1331
+ static const struct
1332
+ {
1333
+ const char spcap[7];
1334
+ const char sfast[7];
1335
+ const char sport[7];
1336
+ const char slocal_only[13];
1337
+ const char scert[7];
1338
+ const char skey[6];
1339
+ } options = { "--pcap=", "--fast", "--port=", "--local-only", "--cert=", "--key=" };
1340
+
1341
+ WINPR_PRAGMA_DIAG_PUSH
1342
+ WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
1343
+ WINPR_ATTR_FORMAT_ARG(2, 0)
1344
+ static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char* what, size_t size)
1345
+ {
1346
+ char buffer[32] = { 0 };
1347
+ strncpy(buffer, what, MIN(size, sizeof(buffer) - 1));
1348
+ (void)fprintf(fp, fmt, buffer);
1349
+ }
1350
+ WINPR_PRAGMA_DIAG_POP
1351
+
1352
+ static int usage(const char* app, const char* invalid)
1353
+ {
1354
+ FILE* fp = stdout;
1355
+
1356
+ (void)fprintf(fp, "Invalid argument '%s'\n", invalid);
1357
+ (void)fprintf(fp, "Usage: %s <arg>[ <arg> ...]\n", app);
1358
+ (void)fprintf(fp, "Arguments:\n");
1359
+ print_entry(fp, "\t%s<pcap file>\n", options.spcap, sizeof(options.spcap));
1360
+ print_entry(fp, "\t%s<cert file>\n", options.scert, sizeof(options.scert));
1361
+ print_entry(fp, "\t%s<key file>\n", options.skey, sizeof(options.skey));
1362
+ print_entry(fp, "\t%s\n", options.sfast, sizeof(options.sfast));
1363
+ print_entry(fp, "\t%s<port>\n", options.sport, sizeof(options.sport));
1364
+ print_entry(fp, "\t%s\n", options.slocal_only, sizeof(options.slocal_only));
1365
+ return -1;
1366
+ }
1367
+
1368
+ int main(int argc, char* argv[])
1369
+ {
1370
+ int rc = -1;
1371
+ BOOL started = FALSE;
1372
+ WSADATA wsaData = { 0 };
1373
+ freerdp_listener* instance = NULL;
1374
+ char* file = NULL;
1375
+ char name[MAX_PATH] = { 0 };
1376
+ long port = 3389;
1377
+ BOOL localOnly = FALSE;
1378
+ struct server_info info = { 0 };
1379
+ const char* app = argv[0];
1380
+
1381
+ info.test_dump_rfx_realtime = TRUE;
1382
+
1383
+ errno = 0;
1384
+
1385
+ for (int i = 1; i < argc; i++)
1386
+ {
1387
+ char* arg = argv[i];
1388
+
1389
+ if (strncmp(arg, options.sfast, sizeof(options.sfast)) == 0)
1390
+ info.test_dump_rfx_realtime = FALSE;
1391
+ else if (strncmp(arg, options.sport, sizeof(options.sport)) == 0)
1392
+ {
1393
+ const char* sport = &arg[sizeof(options.sport)];
1394
+ port = strtol(sport, NULL, 10);
1395
+
1396
+ if ((port < 1) || (port > UINT16_MAX) || (errno != 0))
1397
+ return usage(app, arg);
1398
+ }
1399
+ else if (strncmp(arg, options.slocal_only, sizeof(options.slocal_only)) == 0)
1400
+ localOnly = TRUE;
1401
+ else if (strncmp(arg, options.spcap, sizeof(options.spcap)) == 0)
1402
+ {
1403
+ info.test_pcap_file = &arg[sizeof(options.spcap)];
1404
+ if (!winpr_PathFileExists(info.test_pcap_file))
1405
+ return usage(app, arg);
1406
+ }
1407
+ else if (strncmp(arg, options.scert, sizeof(options.scert)) == 0)
1408
+ {
1409
+ info.cert = &arg[sizeof(options.scert)];
1410
+ if (!winpr_PathFileExists(info.cert))
1411
+ return usage(app, arg);
1412
+ }
1413
+ else if (strncmp(arg, options.skey, sizeof(options.skey)) == 0)
1414
+ {
1415
+ info.key = &arg[sizeof(options.skey)];
1416
+ if (!winpr_PathFileExists(info.key))
1417
+ return usage(app, arg);
1418
+ }
1419
+ else
1420
+ return usage(app, arg);
1421
+ }
1422
+
1423
+ WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
1424
+ winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
1425
+ instance = freerdp_listener_new();
1426
+
1427
+ if (!instance)
1428
+ return -1;
1429
+
1430
+ if (!info.cert)
1431
+ info.cert = "server.crt";
1432
+ if (!info.key)
1433
+ info.key = "server.key";
1434
+
1435
+ instance->info = (void*)&info;
1436
+ instance->PeerAccepted = test_peer_accepted;
1437
+
1438
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
1439
+ goto fail;
1440
+
1441
+ /* Open the server socket and start listening. */
1442
+ (void)sprintf_s(name, sizeof(name), "tfreerdp-server.%ld", port);
1443
+ file = GetKnownSubPath(KNOWN_PATH_TEMP, name);
1444
+
1445
+ if (!file)
1446
+ goto fail;
1447
+
1448
+ if (localOnly)
1449
+ {
1450
+ WINPR_ASSERT(instance->OpenLocal);
1451
+ started = instance->OpenLocal(instance, file);
1452
+ }
1453
+ else
1454
+ {
1455
+ WINPR_ASSERT(instance->Open);
1456
+ started = instance->Open(instance, NULL, (UINT16)port);
1457
+ }
1458
+
1459
+ if (started)
1460
+ {
1461
+ /* Entering the server main loop. In a real server the listener can be run in its own
1462
+ * thread. */
1463
+ test_server_mainloop(instance);
1464
+ }
1465
+
1466
+ rc = 0;
1467
+ fail:
1468
+ free(file);
1469
+ freerdp_listener_free(instance);
1470
+ WSACleanup();
1471
+ return rc;
1472
+ }
local-test-freerdp-full-01/afc-freerdp/server/Sample/sfreerdp.h ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Sample Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_SAMPLE_SFREERDP_SERVER_H
21
+ #define FREERDP_SERVER_SAMPLE_SFREERDP_SERVER_H
22
+
23
+ #include <freerdp/freerdp.h>
24
+ #include <freerdp/listener.h>
25
+ #include <freerdp/codec/rfx.h>
26
+ #include <freerdp/codec/nsc.h>
27
+ #include <freerdp/channels/wtsvc.h>
28
+ #if defined(CHANNEL_AINPUT_SERVER)
29
+ #include <freerdp/server/ainput.h>
30
+ #endif
31
+ #if defined(CHANNEL_AUDIN_SERVER)
32
+ #include <freerdp/server/audin.h>
33
+ #endif
34
+ #include <freerdp/server/rdpsnd.h>
35
+ #include <freerdp/server/encomsp.h>
36
+ #include <freerdp/transport_io.h>
37
+
38
+ #include <winpr/crt.h>
39
+ #include <winpr/synch.h>
40
+ #include <winpr/thread.h>
41
+ #include <winpr/image.h>
42
+
43
+ struct test_peer_context
44
+ {
45
+ rdpContext _p;
46
+
47
+ RFX_CONTEXT* rfx_context;
48
+ NSC_CONTEXT* nsc_context;
49
+ wStream* s;
50
+ BYTE* bg_data;
51
+ UINT32 icon_x;
52
+ UINT32 icon_y;
53
+ BOOL activated;
54
+ HANDLE event;
55
+ HANDLE stopEvent;
56
+ HANDLE vcm;
57
+ void* debug_channel;
58
+ HANDLE debug_channel_thread;
59
+ #if defined(CHANNEL_AUDIN_SERVER)
60
+ audin_server_context* audin;
61
+ #endif
62
+ BOOL audin_open;
63
+ #if defined(CHANNEL_AINPUT_SERVER)
64
+ ainput_server_context* ainput;
65
+ BOOL ainput_open;
66
+ #endif
67
+ UINT32 frame_id;
68
+ RdpsndServerContext* rdpsnd;
69
+ EncomspServerContext* encomsp;
70
+
71
+ rdpTransportIo io;
72
+ wImage* image;
73
+ };
74
+ typedef struct test_peer_context testPeerContext;
75
+
76
+ #endif /* FREERDP_SERVER_SAMPLE_SFREERDP_SERVER_H */
local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.ppm ADDED
local-test-freerdp-full-01/afc-freerdp/server/Windows/CMakeLists.txt ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Windows Server cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ set(MODULE_NAME "wfreerdp-server")
19
+ set(MODULE_PREFIX "FREERDP_SERVER_WINDOWS")
20
+
21
+ include(WarnUnmaintained)
22
+ warn_unmaintained(${MODULE_NAME})
23
+
24
+ include_directories(.)
25
+
26
+ set(${MODULE_PREFIX}_SRCS
27
+ wf_update.c
28
+ wf_update.h
29
+ wf_dxgi.c
30
+ wf_dxgi.h
31
+ wf_input.c
32
+ wf_input.h
33
+ wf_interface.c
34
+ wf_interface.h
35
+ wf_mirage.c
36
+ wf_mirage.h
37
+ wf_peer.c
38
+ wf_peer.h
39
+ wf_settings.c
40
+ wf_settings.h
41
+ wf_info.c
42
+ wf_info.h
43
+ )
44
+
45
+ if(CHANNEL_RDPSND AND NOT WITH_RDPSND_DSOUND)
46
+ set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} wf_rdpsnd.c wf_rdpsnd.h wf_wasapi.c wf_wasapi.h)
47
+ endif()
48
+
49
+ if(CHANNEL_RDPSND AND WITH_RDPSND_DSOUND)
50
+ set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} wf_rdpsnd.c wf_rdpsnd.h wf_directsound.c wf_directsound.h)
51
+ endif()
52
+
53
+ if(WITH_SERVER_INTERFACE)
54
+ addtargetwithresourcefile(${MODULE_NAME} FALSE "${FREERDP_VERSION}" ${MODULE_PREFIX}_SRCS)
55
+ target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
56
+ else()
57
+ list(APPEND ${MODULE_PREFIX}_SRCS cli/wfreerdp.c cli/wfreerdp.h)
58
+ addtargetwithresourcefile(${MODULE_NAME} TRUE "${FREERDP_VERSION}" ${MODULE_PREFIX}_SRCS)
59
+ endif()
60
+
61
+ if(NOT CMAKE_WINDOWS_VERSION STREQUAL "WINXP")
62
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} d3d11 dxgi)
63
+ endif()
64
+
65
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} dsound)
66
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-server freerdp)
67
+
68
+ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
69
+
70
+ if(WITH_SERVER_INTERFACE)
71
+ install(TARGETS ${MODULE_NAME} COMPONENT libraries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
72
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
73
+ )
74
+ else()
75
+ install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
76
+ endif()
77
+
78
+ if(WITH_SERVER_INTERFACE)
79
+ add_subdirectory(cli)
80
+ endif()
81
+
82
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Windows")
local-test-freerdp-full-01/afc-freerdp/server/Windows/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_SERVER_NAME "wfreerdp-server")
2
+ set(FREERDP_SERVER_PLATFORM "Windows")
3
+ set(FREERDP_SERVER_VENDOR "FreeRDP")
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_directsound.c ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include "wf_directsound.h"
2
+ #include "wf_interface.h"
3
+ #include "wf_info.h"
4
+ #include "wf_rdpsnd.h"
5
+
6
+ #include <winpr/windows.h>
7
+
8
+ #define INITGUID
9
+ #include <initguid.h>
10
+ #include <objbase.h>
11
+
12
+ #define CINTERFACE 1
13
+ #include <mmsystem.h>
14
+ #include <dsound.h>
15
+
16
+ #include <freerdp/log.h>
17
+ #define TAG SERVER_TAG("windows")
18
+
19
+ IDirectSoundCapture8* cap;
20
+ IDirectSoundCaptureBuffer8* capBuf;
21
+ DSCBUFFERDESC dscbd;
22
+ DWORD lastPos;
23
+ wfPeerContext* latestPeer;
24
+
25
+ int wf_rdpsnd_set_latest_peer(wfPeerContext* peer)
26
+ {
27
+ latestPeer = peer;
28
+ return 0;
29
+ }
30
+
31
+ int wf_directsound_activate(RdpsndServerContext* context)
32
+ {
33
+ HRESULT hr;
34
+ wfInfo* wfi;
35
+ HANDLE hThread;
36
+
37
+ LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
38
+
39
+ wfi = wf_info_get_instance();
40
+ if (!wfi)
41
+ {
42
+ WLog_ERR(TAG, "Failed to wfi instance");
43
+ return 1;
44
+ }
45
+ WLog_DBG(TAG, "RDPSND (direct sound) Activated");
46
+ hr = DirectSoundCaptureCreate8(NULL, &cap, NULL);
47
+
48
+ if (FAILED(hr))
49
+ {
50
+ WLog_ERR(TAG, "Failed to create sound capture device");
51
+ return 1;
52
+ }
53
+
54
+ WLog_INFO(TAG, "Created sound capture device");
55
+ dscbd.dwSize = sizeof(DSCBUFFERDESC);
56
+ dscbd.dwFlags = 0;
57
+ dscbd.dwBufferBytes = wfi->agreed_format->nAvgBytesPerSec;
58
+ dscbd.dwReserved = 0;
59
+ dscbd.lpwfxFormat = wfi->agreed_format;
60
+ dscbd.dwFXCount = 0;
61
+ dscbd.lpDSCFXDesc = NULL;
62
+
63
+ hr = cap->lpVtbl->CreateCaptureBuffer(cap, &dscbd, &pDSCB, NULL);
64
+
65
+ if (FAILED(hr))
66
+ {
67
+ WLog_ERR(TAG, "Failed to create capture buffer");
68
+ }
69
+
70
+ WLog_INFO(TAG, "Created capture buffer");
71
+ hr = pDSCB->lpVtbl->QueryInterface(pDSCB, &IID_IDirectSoundCaptureBuffer8, (LPVOID*)&capBuf);
72
+ if (FAILED(hr))
73
+ {
74
+ WLog_ERR(TAG, "Failed to QI capture buffer");
75
+ }
76
+ WLog_INFO(TAG, "Created IDirectSoundCaptureBuffer8");
77
+ pDSCB->lpVtbl->Release(pDSCB);
78
+ lastPos = 0;
79
+
80
+ if (!(hThread = CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL)))
81
+ {
82
+ WLog_ERR(TAG, "Failed to create direct sound thread");
83
+ return 1;
84
+ }
85
+ (void)CloseHandle(hThread);
86
+
87
+ return 0;
88
+ }
89
+
90
+ static DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
91
+ {
92
+ HRESULT hr;
93
+ DWORD beg = 0;
94
+ DWORD end = 0;
95
+ DWORD diff, rate;
96
+ wfPeerContext* context;
97
+ wfInfo* wfi;
98
+
99
+ VOID* pbCaptureData = NULL;
100
+ DWORD dwCaptureLength = 0;
101
+ VOID* pbCaptureData2 = NULL;
102
+ DWORD dwCaptureLength2 = 0;
103
+ VOID* pbPlayData = NULL;
104
+ DWORD dwReadPos = 0;
105
+ LONG lLockSize = 0;
106
+
107
+ wfi = wf_info_get_instance();
108
+ if (!wfi)
109
+ {
110
+ WLog_ERR(TAG, "Failed get instance");
111
+ return 1;
112
+ }
113
+
114
+ context = (wfPeerContext*)lpParam;
115
+ rate = 1000 / 24;
116
+ WLog_INFO(TAG, "Trying to start capture");
117
+ hr = capBuf->lpVtbl->Start(capBuf, DSCBSTART_LOOPING);
118
+ if (FAILED(hr))
119
+ {
120
+ WLog_ERR(TAG, "Failed to start capture");
121
+ }
122
+ WLog_INFO(TAG, "Capture started");
123
+
124
+ while (1)
125
+ {
126
+
127
+ end = GetTickCount();
128
+ diff = end - beg;
129
+
130
+ if (diff < rate)
131
+ {
132
+ Sleep(rate - diff);
133
+ }
134
+
135
+ beg = GetTickCount();
136
+
137
+ if (wf_rdpsnd_lock() > 0)
138
+ {
139
+ // check for main exit condition
140
+ if (wfi->snd_stop == TRUE)
141
+ {
142
+ wf_rdpsnd_unlock();
143
+ break;
144
+ }
145
+
146
+ hr = capBuf->lpVtbl->GetCurrentPosition(capBuf, NULL, &dwReadPos);
147
+ if (FAILED(hr))
148
+ {
149
+ WLog_ERR(TAG, "Failed to get read pos");
150
+ wf_rdpsnd_unlock();
151
+ break;
152
+ }
153
+
154
+ lLockSize = dwReadPos - lastPos; // dscbd.dwBufferBytes;
155
+ if (lLockSize < 0)
156
+ lLockSize += dscbd.dwBufferBytes;
157
+
158
+ // WLog_DBG(TAG, "Last, read, lock = [%"PRIu32", %"PRIu32", %"PRId32"]\n", lastPos,
159
+ // dwReadPos, lLockSize);
160
+
161
+ if (lLockSize == 0)
162
+ {
163
+ wf_rdpsnd_unlock();
164
+ continue;
165
+ }
166
+
167
+ hr = capBuf->lpVtbl->Lock(capBuf, lastPos, lLockSize, &pbCaptureData, &dwCaptureLength,
168
+ &pbCaptureData2, &dwCaptureLength2, 0L);
169
+ if (FAILED(hr))
170
+ {
171
+ WLog_ERR(TAG, "Failed to lock sound capture buffer");
172
+ wf_rdpsnd_unlock();
173
+ break;
174
+ }
175
+
176
+ // fwrite(pbCaptureData, 1, dwCaptureLength, pFile);
177
+ // fwrite(pbCaptureData2, 1, dwCaptureLength2, pFile);
178
+
179
+ // FIXME: frames = bytes/(bytespersample * channels)
180
+
181
+ context->rdpsnd->SendSamples(context->rdpsnd, pbCaptureData, dwCaptureLength / 4,
182
+ (UINT16)(beg & 0xffff));
183
+ context->rdpsnd->SendSamples(context->rdpsnd, pbCaptureData2, dwCaptureLength2 / 4,
184
+ (UINT16)(beg & 0xffff));
185
+
186
+ hr = capBuf->lpVtbl->Unlock(capBuf, pbCaptureData, dwCaptureLength, pbCaptureData2,
187
+ dwCaptureLength2);
188
+ if (FAILED(hr))
189
+ {
190
+ WLog_ERR(TAG, "Failed to unlock sound capture buffer");
191
+ wf_rdpsnd_unlock();
192
+ return 0;
193
+ }
194
+
195
+ // TODO keep track of location in buffer
196
+ lastPos += dwCaptureLength;
197
+ lastPos %= dscbd.dwBufferBytes;
198
+ lastPos += dwCaptureLength2;
199
+ lastPos %= dscbd.dwBufferBytes;
200
+
201
+ wf_rdpsnd_unlock();
202
+ }
203
+ }
204
+
205
+ WLog_INFO(TAG, "Trying to stop sound capture");
206
+ hr = capBuf->lpVtbl->Stop(capBuf);
207
+ if (FAILED(hr))
208
+ {
209
+ WLog_ERR(TAG, "Failed to stop capture");
210
+ }
211
+
212
+ WLog_INFO(TAG, "Capture stopped");
213
+ capBuf->lpVtbl->Release(capBuf);
214
+ cap->lpVtbl->Release(cap);
215
+
216
+ lastPos = 0;
217
+
218
+ return 0;
219
+ }
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_directsound.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef FREERDP_SERVER_WIN_DSOUND_H
2
+ #define FREERDP_SERVER_WIN_DSOUND_H
3
+
4
+ #include <freerdp/server/rdpsnd.h>
5
+ #include "wf_interface.h"
6
+
7
+ int wf_rdpsnd_set_latest_peer(wfPeerContext* peer);
8
+
9
+ int wf_directsound_activate(RdpsndServerContext* context);
10
+
11
+ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam);
12
+
13
+ #endif /* FREERDP_SERVER_WIN_DSOUND_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_dxgi.c ADDED
@@ -0,0 +1,486 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include "wf_interface.h"
23
+
24
+ #ifdef WITH_DXGI_1_2
25
+
26
+ #define CINTERFACE
27
+
28
+ #include <D3D11.h>
29
+ #include <dxgi1_2.h>
30
+
31
+ #include <tchar.h>
32
+ #include "wf_dxgi.h"
33
+
34
+ #include <freerdp/log.h>
35
+ #define TAG SERVER_TAG("windows")
36
+
37
+ /* Driver types supported */
38
+ D3D_DRIVER_TYPE DriverTypes[] = {
39
+ D3D_DRIVER_TYPE_HARDWARE,
40
+ D3D_DRIVER_TYPE_WARP,
41
+ D3D_DRIVER_TYPE_REFERENCE,
42
+ };
43
+ UINT NumDriverTypes = ARRAYSIZE(DriverTypes);
44
+
45
+ /* Feature levels supported */
46
+ D3D_FEATURE_LEVEL FeatureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1,
47
+ D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_1 };
48
+
49
+ UINT NumFeatureLevels = ARRAYSIZE(FeatureLevels);
50
+
51
+ D3D_FEATURE_LEVEL FeatureLevel;
52
+
53
+ ID3D11Device* gDevice = NULL;
54
+ ID3D11DeviceContext* gContext = NULL;
55
+ IDXGIOutputDuplication* gOutputDuplication = NULL;
56
+ ID3D11Texture2D* gAcquiredDesktopImage = NULL;
57
+
58
+ IDXGISurface* surf;
59
+ ID3D11Texture2D* sStage;
60
+
61
+ DXGI_OUTDUPL_FRAME_INFO FrameInfo;
62
+
63
+ int wf_dxgi_init(wfInfo* wfi)
64
+ {
65
+ gAcquiredDesktopImage = NULL;
66
+
67
+ if (wf_dxgi_createDevice(wfi) != 0)
68
+ {
69
+ return 1;
70
+ }
71
+
72
+ if (wf_dxgi_getDuplication(wfi) != 0)
73
+ {
74
+ return 1;
75
+ }
76
+
77
+ return 0;
78
+ }
79
+
80
+ int wf_dxgi_createDevice(wfInfo* wfi)
81
+ {
82
+ HRESULT status;
83
+ UINT DriverTypeIndex;
84
+
85
+ for (DriverTypeIndex = 0; DriverTypeIndex < NumDriverTypes; ++DriverTypeIndex)
86
+ {
87
+ status = D3D11CreateDevice(NULL, DriverTypes[DriverTypeIndex], NULL, 0, FeatureLevels,
88
+ NumFeatureLevels, D3D11_SDK_VERSION, &gDevice, &FeatureLevel,
89
+ &gContext);
90
+ if (SUCCEEDED(status))
91
+ break;
92
+
93
+ WLog_INFO(TAG, "D3D11CreateDevice returned [%ld] for Driver Type %d", status,
94
+ DriverTypes[DriverTypeIndex]);
95
+ }
96
+
97
+ if (FAILED(status))
98
+ {
99
+ WLog_ERR(TAG, "Failed to create device in InitializeDx");
100
+ return 1;
101
+ }
102
+
103
+ return 0;
104
+ }
105
+
106
+ int wf_dxgi_getDuplication(wfInfo* wfi)
107
+ {
108
+ HRESULT status;
109
+ UINT dTop, i = 0;
110
+ DXGI_OUTPUT_DESC desc = { 0 };
111
+ IDXGIOutput* pOutput;
112
+ IDXGIDevice* DxgiDevice = NULL;
113
+ IDXGIAdapter* DxgiAdapter = NULL;
114
+ IDXGIOutput* DxgiOutput = NULL;
115
+ IDXGIOutput1* DxgiOutput1 = NULL;
116
+
117
+ status = gDevice->lpVtbl->QueryInterface(gDevice, &IID_IDXGIDevice, (void**)&DxgiDevice);
118
+
119
+ if (FAILED(status))
120
+ {
121
+ WLog_ERR(TAG, "Failed to get QI for DXGI Device");
122
+ return 1;
123
+ }
124
+
125
+ status = DxgiDevice->lpVtbl->GetParent(DxgiDevice, &IID_IDXGIAdapter, (void**)&DxgiAdapter);
126
+ DxgiDevice->lpVtbl->Release(DxgiDevice);
127
+ DxgiDevice = NULL;
128
+
129
+ if (FAILED(status))
130
+ {
131
+ WLog_ERR(TAG, "Failed to get parent DXGI Adapter");
132
+ return 1;
133
+ }
134
+
135
+ pOutput = NULL;
136
+
137
+ while (DxgiAdapter->lpVtbl->EnumOutputs(DxgiAdapter, i, &pOutput) != DXGI_ERROR_NOT_FOUND)
138
+ {
139
+ DXGI_OUTPUT_DESC* pDesc = &desc;
140
+
141
+ status = pOutput->lpVtbl->GetDesc(pOutput, pDesc);
142
+
143
+ if (FAILED(status))
144
+ {
145
+ WLog_ERR(TAG, "Failed to get description");
146
+ return 1;
147
+ }
148
+
149
+ WLog_INFO(TAG, "Output %u: [%s] [%d]", i, pDesc->DeviceName, pDesc->AttachedToDesktop);
150
+
151
+ if (pDesc->AttachedToDesktop)
152
+ dTop = i;
153
+
154
+ pOutput->lpVtbl->Release(pOutput);
155
+ ++i;
156
+ }
157
+
158
+ dTop = wfi->screenID;
159
+
160
+ status = DxgiAdapter->lpVtbl->EnumOutputs(DxgiAdapter, dTop, &DxgiOutput);
161
+ DxgiAdapter->lpVtbl->Release(DxgiAdapter);
162
+ DxgiAdapter = NULL;
163
+
164
+ if (FAILED(status))
165
+ {
166
+ WLog_ERR(TAG, "Failed to get output");
167
+ return 1;
168
+ }
169
+
170
+ status =
171
+ DxgiOutput->lpVtbl->QueryInterface(DxgiOutput, &IID_IDXGIOutput1, (void**)&DxgiOutput1);
172
+ DxgiOutput->lpVtbl->Release(DxgiOutput);
173
+ DxgiOutput = NULL;
174
+
175
+ if (FAILED(status))
176
+ {
177
+ WLog_ERR(TAG, "Failed to get IDXGIOutput1");
178
+ return 1;
179
+ }
180
+
181
+ status =
182
+ DxgiOutput1->lpVtbl->DuplicateOutput(DxgiOutput1, (IUnknown*)gDevice, &gOutputDuplication);
183
+ DxgiOutput1->lpVtbl->Release(DxgiOutput1);
184
+ DxgiOutput1 = NULL;
185
+
186
+ if (FAILED(status))
187
+ {
188
+ if (status == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE)
189
+ {
190
+ WLog_ERR(
191
+ TAG,
192
+ "There is already the maximum number of applications using the Desktop Duplication "
193
+ "API running, please close one of those applications and then try again.");
194
+ return 1;
195
+ }
196
+
197
+ WLog_ERR(TAG, "Failed to get duplicate output. Status = %ld", status);
198
+ return 1;
199
+ }
200
+
201
+ return 0;
202
+ }
203
+
204
+ int wf_dxgi_cleanup(wfInfo* wfi)
205
+ {
206
+ if (wfi->framesWaiting > 0)
207
+ {
208
+ wf_dxgi_releasePixelData(wfi);
209
+ }
210
+
211
+ if (gAcquiredDesktopImage)
212
+ {
213
+ gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
214
+ gAcquiredDesktopImage = NULL;
215
+ }
216
+
217
+ if (gOutputDuplication)
218
+ {
219
+ gOutputDuplication->lpVtbl->Release(gOutputDuplication);
220
+ gOutputDuplication = NULL;
221
+ }
222
+
223
+ if (gContext)
224
+ {
225
+ gContext->lpVtbl->Release(gContext);
226
+ gContext = NULL;
227
+ }
228
+
229
+ if (gDevice)
230
+ {
231
+ gDevice->lpVtbl->Release(gDevice);
232
+ gDevice = NULL;
233
+ }
234
+
235
+ return 0;
236
+ }
237
+
238
+ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
239
+ {
240
+ HRESULT status = 0;
241
+ UINT i = 0;
242
+ UINT DataBufferSize = 0;
243
+ BYTE* DataBuffer = NULL;
244
+ IDXGIResource* DesktopResource = NULL;
245
+
246
+ if (wfi->framesWaiting > 0)
247
+ {
248
+ wf_dxgi_releasePixelData(wfi);
249
+ }
250
+
251
+ if (gAcquiredDesktopImage)
252
+ {
253
+ gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
254
+ gAcquiredDesktopImage = NULL;
255
+ }
256
+
257
+ status = gOutputDuplication->lpVtbl->AcquireNextFrame(gOutputDuplication, timeout, &FrameInfo,
258
+ &DesktopResource);
259
+
260
+ if (status == DXGI_ERROR_WAIT_TIMEOUT)
261
+ {
262
+ return 1;
263
+ }
264
+
265
+ if (FAILED(status))
266
+ {
267
+ if (status == DXGI_ERROR_ACCESS_LOST)
268
+ {
269
+ WLog_ERR(TAG, "Failed to acquire next frame with status=%ld", status);
270
+ WLog_ERR(TAG, "Trying to reinitialize due to ACCESS LOST...");
271
+
272
+ if (gAcquiredDesktopImage)
273
+ {
274
+ gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
275
+ gAcquiredDesktopImage = NULL;
276
+ }
277
+
278
+ if (gOutputDuplication)
279
+ {
280
+ gOutputDuplication->lpVtbl->Release(gOutputDuplication);
281
+ gOutputDuplication = NULL;
282
+ }
283
+
284
+ wf_dxgi_getDuplication(wfi);
285
+
286
+ return 1;
287
+ }
288
+ else
289
+ {
290
+ WLog_ERR(TAG, "Failed to acquire next frame with status=%ld", status);
291
+ status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
292
+
293
+ if (FAILED(status))
294
+ {
295
+ WLog_ERR(TAG, "Failed to release frame with status=%ld", status);
296
+ }
297
+
298
+ return 1;
299
+ }
300
+ }
301
+
302
+ status = DesktopResource->lpVtbl->QueryInterface(DesktopResource, &IID_ID3D11Texture2D,
303
+ (void**)&gAcquiredDesktopImage);
304
+ DesktopResource->lpVtbl->Release(DesktopResource);
305
+ DesktopResource = NULL;
306
+
307
+ if (FAILED(status))
308
+ {
309
+ return 1;
310
+ }
311
+
312
+ wfi->framesWaiting = FrameInfo.AccumulatedFrames;
313
+
314
+ if (FrameInfo.AccumulatedFrames == 0)
315
+ {
316
+ status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
317
+
318
+ if (FAILED(status))
319
+ {
320
+ WLog_ERR(TAG, "Failed to release frame with status=%ld", status);
321
+ }
322
+ }
323
+
324
+ return 0;
325
+ }
326
+
327
+ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid)
328
+ {
329
+ HRESULT status;
330
+ D3D11_BOX Box;
331
+ DXGI_MAPPED_RECT mappedRect;
332
+ D3D11_TEXTURE2D_DESC tDesc;
333
+
334
+ tDesc.Width = (invalid->right - invalid->left);
335
+ tDesc.Height = (invalid->bottom - invalid->top);
336
+ tDesc.MipLevels = 1;
337
+ tDesc.ArraySize = 1;
338
+ tDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
339
+ tDesc.SampleDesc.Count = 1;
340
+ tDesc.SampleDesc.Quality = 0;
341
+ tDesc.Usage = D3D11_USAGE_STAGING;
342
+ tDesc.BindFlags = 0;
343
+ tDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
344
+ tDesc.MiscFlags = 0;
345
+
346
+ Box.top = invalid->top;
347
+ Box.left = invalid->left;
348
+ Box.right = invalid->right;
349
+ Box.bottom = invalid->bottom;
350
+ Box.front = 0;
351
+ Box.back = 1;
352
+
353
+ status = gDevice->lpVtbl->CreateTexture2D(gDevice, &tDesc, NULL, &sStage);
354
+
355
+ if (FAILED(status))
356
+ {
357
+ WLog_ERR(TAG, "Failed to create staging surface");
358
+ exit(1);
359
+ return 1;
360
+ }
361
+
362
+ gContext->lpVtbl->CopySubresourceRegion(gContext, (ID3D11Resource*)sStage, 0, 0, 0, 0,
363
+ (ID3D11Resource*)gAcquiredDesktopImage, 0, &Box);
364
+
365
+ status = sStage->lpVtbl->QueryInterface(sStage, &IID_IDXGISurface, (void**)&surf);
366
+
367
+ if (FAILED(status))
368
+ {
369
+ WLog_ERR(TAG, "Failed to QI staging surface");
370
+ exit(1);
371
+ return 1;
372
+ }
373
+
374
+ surf->lpVtbl->Map(surf, &mappedRect, DXGI_MAP_READ);
375
+
376
+ if (FAILED(status))
377
+ {
378
+ WLog_ERR(TAG, "Failed to map staging surface");
379
+ exit(1);
380
+ return 1;
381
+ }
382
+
383
+ *data = mappedRect.pBits;
384
+ *pitch = mappedRect.Pitch;
385
+
386
+ return 0;
387
+ }
388
+
389
+ int wf_dxgi_releasePixelData(wfInfo* wfi)
390
+ {
391
+ HRESULT status;
392
+
393
+ surf->lpVtbl->Unmap(surf);
394
+ surf->lpVtbl->Release(surf);
395
+ surf = NULL;
396
+ sStage->lpVtbl->Release(sStage);
397
+ sStage = NULL;
398
+
399
+ status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
400
+
401
+ if (FAILED(status))
402
+ {
403
+ WLog_ERR(TAG, "Failed to release frame");
404
+ return 1;
405
+ }
406
+
407
+ wfi->framesWaiting = 0;
408
+
409
+ return 0;
410
+ }
411
+
412
+ int wf_dxgi_getInvalidRegion(RECT* invalid)
413
+ {
414
+ HRESULT status;
415
+ UINT dirty;
416
+ UINT BufSize;
417
+ RECT* pRect;
418
+ BYTE* DirtyRects;
419
+ UINT DataBufferSize = 0;
420
+ BYTE* DataBuffer = NULL;
421
+
422
+ if (FrameInfo.AccumulatedFrames == 0)
423
+ {
424
+ return 1;
425
+ }
426
+
427
+ if (FrameInfo.TotalMetadataBufferSize)
428
+ {
429
+
430
+ if (FrameInfo.TotalMetadataBufferSize > DataBufferSize)
431
+ {
432
+ if (DataBuffer)
433
+ {
434
+ free(DataBuffer);
435
+ DataBuffer = NULL;
436
+ }
437
+
438
+ DataBuffer = (BYTE*)malloc(FrameInfo.TotalMetadataBufferSize);
439
+
440
+ if (!DataBuffer)
441
+ {
442
+ DataBufferSize = 0;
443
+ WLog_ERR(TAG, "Failed to allocate memory for metadata");
444
+ exit(1);
445
+ }
446
+
447
+ DataBufferSize = FrameInfo.TotalMetadataBufferSize;
448
+ }
449
+
450
+ BufSize = FrameInfo.TotalMetadataBufferSize;
451
+
452
+ status = gOutputDuplication->lpVtbl->GetFrameMoveRects(
453
+ gOutputDuplication, BufSize, (DXGI_OUTDUPL_MOVE_RECT*)DataBuffer, &BufSize);
454
+
455
+ if (FAILED(status))
456
+ {
457
+ WLog_ERR(TAG, "Failed to get frame move rects");
458
+ return 1;
459
+ }
460
+
461
+ DirtyRects = DataBuffer + BufSize;
462
+ BufSize = FrameInfo.TotalMetadataBufferSize - BufSize;
463
+
464
+ status = gOutputDuplication->lpVtbl->GetFrameDirtyRects(gOutputDuplication, BufSize,
465
+ (RECT*)DirtyRects, &BufSize);
466
+
467
+ if (FAILED(status))
468
+ {
469
+ WLog_ERR(TAG, "Failed to get frame dirty rects");
470
+ return 1;
471
+ }
472
+ dirty = BufSize / sizeof(RECT);
473
+
474
+ pRect = (RECT*)DirtyRects;
475
+
476
+ for (UINT i = 0; i < dirty; ++i)
477
+ {
478
+ UnionRect(invalid, invalid, pRect);
479
+ ++pRect;
480
+ }
481
+ }
482
+
483
+ return 0;
484
+ }
485
+
486
+ #endif
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_dxgi.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_WIN_DXGI_H
21
+ #define FREERDP_SERVER_WIN_DXGI_H
22
+
23
+ #include "wf_interface.h"
24
+
25
+ int wf_dxgi_init(wfInfo* context);
26
+
27
+ int wf_dxgi_createDevice(wfInfo* context);
28
+
29
+ int wf_dxgi_getDuplication(wfInfo* context);
30
+
31
+ int wf_dxgi_cleanup(wfInfo* context);
32
+
33
+ int wf_dxgi_nextFrame(wfInfo* context, UINT timeout);
34
+
35
+ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid);
36
+
37
+ int wf_dxgi_releasePixelData(wfInfo* context);
38
+
39
+ int wf_dxgi_getInvalidRegion(RECT* invalid);
40
+
41
+ #endif /* FREERDP_SERVER_WIN_DXGI_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_info.c ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <stdlib.h>
23
+
24
+ #include <freerdp/build-config.h>
25
+
26
+ #include <winpr/tchar.h>
27
+ #include <winpr/windows.h>
28
+
29
+ #include "wf_info.h"
30
+ #include "wf_update.h"
31
+ #include "wf_mirage.h"
32
+ #include "wf_dxgi.h"
33
+
34
+ #include <freerdp/log.h>
35
+ #define TAG SERVER_TAG("windows")
36
+
37
+ #define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Server"
38
+
39
+ static wfInfo* wfInfoInstance = NULL;
40
+ static int _IDcount = 0;
41
+
42
+ BOOL wf_info_lock(wfInfo* wfi)
43
+ {
44
+ DWORD dRes;
45
+ dRes = WaitForSingleObject(wfi->mutex, INFINITE);
46
+
47
+ switch (dRes)
48
+ {
49
+ case WAIT_ABANDONED:
50
+ case WAIT_OBJECT_0:
51
+ return TRUE;
52
+
53
+ case WAIT_TIMEOUT:
54
+ return FALSE;
55
+
56
+ case WAIT_FAILED:
57
+ WLog_ERR(TAG, "wf_info_lock failed with 0x%08lX", GetLastError());
58
+ return FALSE;
59
+ }
60
+
61
+ return FALSE;
62
+ }
63
+
64
+ BOOL wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds)
65
+ {
66
+ DWORD dRes;
67
+ dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds);
68
+
69
+ switch (dRes)
70
+ {
71
+ case WAIT_ABANDONED:
72
+ case WAIT_OBJECT_0:
73
+ return TRUE;
74
+
75
+ case WAIT_TIMEOUT:
76
+ return FALSE;
77
+
78
+ case WAIT_FAILED:
79
+ WLog_ERR(TAG, "wf_info_try_lock failed with 0x%08lX", GetLastError());
80
+ return FALSE;
81
+ }
82
+
83
+ return FALSE;
84
+ }
85
+
86
+ BOOL wf_info_unlock(wfInfo* wfi)
87
+ {
88
+ if (!ReleaseMutex(wfi->mutex))
89
+ {
90
+ WLog_ERR(TAG, "wf_info_unlock failed with 0x%08lX", GetLastError());
91
+ return FALSE;
92
+ }
93
+
94
+ return TRUE;
95
+ }
96
+
97
+ wfInfo* wf_info_init()
98
+ {
99
+ wfInfo* wfi;
100
+ wfi = (wfInfo*)calloc(1, sizeof(wfInfo));
101
+
102
+ if (wfi != NULL)
103
+ {
104
+ HKEY hKey;
105
+ LONG status;
106
+ DWORD dwType;
107
+ DWORD dwSize;
108
+ DWORD dwValue;
109
+ wfi->mutex = CreateMutex(NULL, FALSE, NULL);
110
+
111
+ if (wfi->mutex == NULL)
112
+ {
113
+ WLog_ERR(TAG, "CreateMutex error: %lu", GetLastError());
114
+ free(wfi);
115
+ return NULL;
116
+ }
117
+
118
+ wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL);
119
+
120
+ if (!wfi->updateSemaphore)
121
+ {
122
+ WLog_ERR(TAG, "CreateSemaphore error: %lu", GetLastError());
123
+ (void)CloseHandle(wfi->mutex);
124
+ free(wfi);
125
+ return NULL;
126
+ }
127
+
128
+ wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL);
129
+
130
+ if (!wfi->updateThread)
131
+ {
132
+ WLog_ERR(TAG, "Failed to create update thread");
133
+ (void)CloseHandle(wfi->mutex);
134
+ (void)CloseHandle(wfi->updateSemaphore);
135
+ free(wfi);
136
+ return NULL;
137
+ }
138
+
139
+ wfi->peers =
140
+ (freerdp_peer**)calloc(FREERDP_SERVER_WIN_INFO_MAXPEERS, sizeof(freerdp_peer*));
141
+
142
+ if (!wfi->peers)
143
+ {
144
+ WLog_ERR(TAG, "Failed to allocate memory for peer");
145
+ (void)CloseHandle(wfi->mutex);
146
+ (void)CloseHandle(wfi->updateSemaphore);
147
+ (void)CloseHandle(wfi->updateThread);
148
+ free(wfi);
149
+ return NULL;
150
+ }
151
+
152
+ // Set FPS
153
+ wfi->framesPerSecond = FREERDP_SERVER_WIN_INFO_DEFAULT_FPS;
154
+ status =
155
+ RegOpenKeyExA(HKEY_LOCAL_MACHINE, SERVER_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
156
+
157
+ if (status == ERROR_SUCCESS)
158
+ {
159
+ if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*)&dwValue,
160
+ &dwSize) == ERROR_SUCCESS)
161
+ wfi->framesPerSecond = dwValue;
162
+ }
163
+
164
+ RegCloseKey(hKey);
165
+ // Set input toggle
166
+ wfi->input_disabled = FALSE;
167
+ status =
168
+ RegOpenKeyExA(HKEY_LOCAL_MACHINE, SERVER_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
169
+
170
+ if (status == ERROR_SUCCESS)
171
+ {
172
+ if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*)&dwValue,
173
+ &dwSize) == ERROR_SUCCESS)
174
+ {
175
+ if (dwValue != 0)
176
+ wfi->input_disabled = TRUE;
177
+ }
178
+ }
179
+
180
+ RegCloseKey(hKey);
181
+ }
182
+
183
+ return wfi;
184
+ }
185
+
186
+ wfInfo* wf_info_get_instance()
187
+ {
188
+ if (wfInfoInstance == NULL)
189
+ wfInfoInstance = wf_info_init();
190
+
191
+ return wfInfoInstance;
192
+ }
193
+
194
+ BOOL wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
195
+ {
196
+ int peerId = 0;
197
+
198
+ if (!wfi || !context)
199
+ return FALSE;
200
+
201
+ if (!wf_info_lock(wfi))
202
+ return FALSE;
203
+
204
+ if (wfi->peerCount == FREERDP_SERVER_WIN_INFO_MAXPEERS)
205
+ goto fail_peer_count;
206
+
207
+ context->info = wfi;
208
+
209
+ if (!(context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
210
+ goto fail_update_event;
211
+
212
+ // get the offset of the top left corner of selected screen
213
+ EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
214
+ _IDcount = 0;
215
+ #ifdef WITH_DXGI_1_2
216
+
217
+ if (wfi->peerCount == 0)
218
+ if (wf_dxgi_init(wfi) != 0)
219
+ goto fail_driver_init;
220
+
221
+ #else
222
+
223
+ if (!wf_mirror_driver_activate(wfi))
224
+ goto fail_driver_init;
225
+
226
+ #endif
227
+
228
+ // look through the array of peers until an empty slot
229
+ for (int i = 0; i < FREERDP_SERVER_WIN_INFO_MAXPEERS; ++i)
230
+ {
231
+ // empty index will be our peer id
232
+ if (wfi->peers[i] == NULL)
233
+ {
234
+ peerId = i;
235
+ break;
236
+ }
237
+ }
238
+
239
+ wfi->peers[peerId] = ((rdpContext*)context)->peer;
240
+ wfi->peers[peerId]->pId = peerId;
241
+ wfi->peerCount++;
242
+ WLog_INFO(TAG, "Registering Peer: id=%d #=%d", peerId, wfi->peerCount);
243
+ wf_info_unlock(wfi);
244
+ wfreerdp_server_peer_callback_event(peerId, FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_CONNECT);
245
+ return TRUE;
246
+ fail_driver_init:
247
+ (void)CloseHandle(context->updateEvent);
248
+ context->updateEvent = NULL;
249
+ fail_update_event:
250
+ fail_peer_count:
251
+ context->socketClose = TRUE;
252
+ wf_info_unlock(wfi);
253
+ return FALSE;
254
+ }
255
+
256
+ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
257
+ {
258
+ if (wf_info_lock(wfi))
259
+ {
260
+ int peerId;
261
+ peerId = ((rdpContext*)context)->peer->pId;
262
+ wfi->peers[peerId] = NULL;
263
+ wfi->peerCount--;
264
+ (void)CloseHandle(context->updateEvent);
265
+ WLog_INFO(TAG, "Unregistering Peer: id=%d, #=%d", peerId, wfi->peerCount);
266
+ #ifdef WITH_DXGI_1_2
267
+
268
+ if (wfi->peerCount == 0)
269
+ wf_dxgi_cleanup(wfi);
270
+
271
+ #endif
272
+ wf_info_unlock(wfi);
273
+ wfreerdp_server_peer_callback_event(peerId,
274
+ FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_DISCONNECT);
275
+ }
276
+ }
277
+
278
+ BOOL wf_info_have_updates(wfInfo* wfi)
279
+ {
280
+ #ifdef WITH_DXGI_1_2
281
+
282
+ if (wfi->framesWaiting == 0)
283
+ return FALSE;
284
+
285
+ #else
286
+
287
+ if (wfi->nextUpdate == wfi->lastUpdate)
288
+ return FALSE;
289
+
290
+ #endif
291
+ return TRUE;
292
+ }
293
+
294
+ void wf_info_update_changes(wfInfo* wfi)
295
+ {
296
+ #ifdef WITH_DXGI_1_2
297
+ wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000);
298
+ #else
299
+ GETCHANGESBUF* buf;
300
+ buf = (GETCHANGESBUF*)wfi->changeBuffer;
301
+ wfi->nextUpdate = buf->buffer->counter;
302
+ #endif
303
+ }
304
+
305
+ void wf_info_find_invalid_region(wfInfo* wfi)
306
+ {
307
+ #ifdef WITH_DXGI_1_2
308
+ wf_dxgi_getInvalidRegion(&wfi->invalid);
309
+ #else
310
+ GETCHANGESBUF* buf;
311
+ buf = (GETCHANGESBUF*)wfi->changeBuffer;
312
+
313
+ for (ULONG i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF)
314
+ {
315
+ LPRECT lpR = &buf->buffer->pointrect[i].rect;
316
+
317
+ // need to make sure we only get updates from the selected screen
318
+ if ((lpR->left >= wfi->servscreen_xoffset) &&
319
+ (lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width)) &&
320
+ (lpR->top >= wfi->servscreen_yoffset) &&
321
+ (lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height)))
322
+ {
323
+ UnionRect(&wfi->invalid, &wfi->invalid, lpR);
324
+ }
325
+ else
326
+ {
327
+ continue;
328
+ }
329
+ }
330
+
331
+ #endif
332
+
333
+ if (wfi->invalid.left < 0)
334
+ wfi->invalid.left = 0;
335
+
336
+ if (wfi->invalid.top < 0)
337
+ wfi->invalid.top = 0;
338
+
339
+ if (wfi->invalid.right >= wfi->servscreen_width)
340
+ wfi->invalid.right = wfi->servscreen_width - 1;
341
+
342
+ if (wfi->invalid.bottom >= wfi->servscreen_height)
343
+ wfi->invalid.bottom = wfi->servscreen_height - 1;
344
+
345
+ // WLog_DBG(TAG, "invalid region: (%"PRId32", %"PRId32"), (%"PRId32", %"PRId32")",
346
+ // wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom);
347
+ }
348
+
349
+ void wf_info_clear_invalid_region(wfInfo* wfi)
350
+ {
351
+ wfi->lastUpdate = wfi->nextUpdate;
352
+ SetRectEmpty(&wfi->invalid);
353
+ }
354
+
355
+ void wf_info_invalidate_full_screen(wfInfo* wfi)
356
+ {
357
+ SetRect(&wfi->invalid, 0, 0, wfi->servscreen_width, wfi->servscreen_height);
358
+ }
359
+
360
+ BOOL wf_info_have_invalid_region(wfInfo* wfi)
361
+ {
362
+ return IsRectEmpty(&wfi->invalid);
363
+ }
364
+
365
+ void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch)
366
+ {
367
+ *width = (wfi->invalid.right - wfi->invalid.left);
368
+ *height = (wfi->invalid.bottom - wfi->invalid.top);
369
+ #ifdef WITH_DXGI_1_2
370
+ wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid);
371
+ #else
372
+ {
373
+ long offset;
374
+ GETCHANGESBUF* changes;
375
+ changes = (GETCHANGESBUF*)wfi->changeBuffer;
376
+ *width += 1;
377
+ *height += 1;
378
+ offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4);
379
+ *pBits = ((BYTE*)(changes->Userbuffer)) + offset;
380
+ *pitch = wfi->virtscreen_width * 4;
381
+ }
382
+ #endif
383
+ }
384
+
385
+ BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor,
386
+ LPARAM dwData)
387
+ {
388
+ wfInfo* wfi;
389
+ wfi = wf_info_get_instance();
390
+
391
+ if (!wfi)
392
+ return FALSE;
393
+
394
+ if (_IDcount == wfi->screenID)
395
+ {
396
+ wfi->servscreen_xoffset = lprcMonitor->left;
397
+ wfi->servscreen_yoffset = lprcMonitor->top;
398
+ }
399
+
400
+ _IDcount++;
401
+ return TRUE;
402
+ }
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_info.h ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Corey Clayton <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_WIN_INFO_H
21
+ #define FREERDP_SERVER_WIN_INFO_H
22
+
23
+ #include "wf_interface.h"
24
+
25
+ #define FREERDP_SERVER_WIN_INFO_DEFAULT_FPS 24
26
+ #define FREERDP_SERVER_WIN_INFO_MAXPEERS 32
27
+
28
+ BOOL wf_info_lock(wfInfo* wfi);
29
+ BOOL wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds);
30
+ BOOL wf_info_unlock(wfInfo* wfi);
31
+
32
+ wfInfo* wf_info_get_instance(void);
33
+ BOOL wf_info_peer_register(wfInfo* wfi, wfPeerContext* context);
34
+ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context);
35
+
36
+ BOOL wf_info_have_updates(wfInfo* wfi);
37
+ void wf_info_update_changes(wfInfo* wfi);
38
+ void wf_info_find_invalid_region(wfInfo* wfi);
39
+ void wf_info_clear_invalid_region(wfInfo* wfi);
40
+ void wf_info_invalidate_full_screen(wfInfo* wfi);
41
+ BOOL wf_info_have_invalid_region(wfInfo* wfi);
42
+ void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch);
43
+ BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor,
44
+ LPARAM dwData);
45
+
46
+ #endif /* FREERDP_SERVER_WIN_INFO_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_input.c ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <winpr/windows.h>
23
+
24
+ #include "wf_input.h"
25
+ #include "wf_info.h"
26
+
27
+ BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
28
+ {
29
+ INPUT keyboard_event;
30
+ WINPR_UNUSED(input);
31
+ keyboard_event.type = INPUT_KEYBOARD;
32
+ keyboard_event.u.ki.wVk = 0;
33
+ keyboard_event.u.ki.wScan = code;
34
+ keyboard_event.u.ki.dwFlags = KEYEVENTF_SCANCODE;
35
+ keyboard_event.u.ki.dwExtraInfo = 0;
36
+ keyboard_event.u.ki.time = 0;
37
+
38
+ if (flags & KBD_FLAGS_RELEASE)
39
+ keyboard_event.u.ki.dwFlags |= KEYEVENTF_KEYUP;
40
+
41
+ if (flags & KBD_FLAGS_EXTENDED)
42
+ keyboard_event.u.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
43
+
44
+ SendInput(1, &keyboard_event, sizeof(INPUT));
45
+ return TRUE;
46
+ }
47
+
48
+ BOOL wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
49
+ {
50
+ INPUT keyboard_event;
51
+ WINPR_UNUSED(input);
52
+ keyboard_event.type = INPUT_KEYBOARD;
53
+ keyboard_event.u.ki.wVk = 0;
54
+ keyboard_event.u.ki.wScan = code;
55
+ keyboard_event.u.ki.dwFlags = KEYEVENTF_UNICODE;
56
+ keyboard_event.u.ki.dwExtraInfo = 0;
57
+ keyboard_event.u.ki.time = 0;
58
+
59
+ if (flags & KBD_FLAGS_RELEASE)
60
+ keyboard_event.u.ki.dwFlags |= KEYEVENTF_KEYUP;
61
+
62
+ SendInput(1, &keyboard_event, sizeof(INPUT));
63
+ return TRUE;
64
+ }
65
+
66
+ BOOL wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
67
+ {
68
+ INPUT mouse_event = { 0 };
69
+ float width, height;
70
+ WINPR_UNUSED(input);
71
+
72
+ WINPR_ASSERT(input);
73
+ mouse_event.type = INPUT_MOUSE;
74
+
75
+ if (flags & PTR_FLAGS_WHEEL)
76
+ {
77
+ mouse_event.u.mi.dwFlags = MOUSEEVENTF_WHEEL;
78
+ mouse_event.u.mi.mouseData = flags & WheelRotationMask;
79
+
80
+ if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
81
+ mouse_event.u.mi.mouseData *= -1;
82
+
83
+ SendInput(1, &mouse_event, sizeof(INPUT));
84
+ }
85
+ else
86
+ {
87
+ wfInfo* wfi;
88
+ wfi = wf_info_get_instance();
89
+
90
+ if (!wfi)
91
+ return FALSE;
92
+
93
+ // width and height of primary screen (even in multimon setups
94
+ width = (float)GetSystemMetrics(SM_CXSCREEN);
95
+ height = (float)GetSystemMetrics(SM_CYSCREEN);
96
+ x += wfi->servscreen_xoffset;
97
+ y += wfi->servscreen_yoffset;
98
+ mouse_event.u.mi.dx = (LONG)((float)x * (65535.0f / width));
99
+ mouse_event.u.mi.dy = (LONG)((float)y * (65535.0f / height));
100
+ mouse_event.u.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
101
+
102
+ if (flags & PTR_FLAGS_MOVE)
103
+ {
104
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_MOVE;
105
+ SendInput(1, &mouse_event, sizeof(INPUT));
106
+ }
107
+
108
+ mouse_event.u.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
109
+
110
+ if (flags & PTR_FLAGS_BUTTON1)
111
+ {
112
+ if (flags & PTR_FLAGS_DOWN)
113
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
114
+ else
115
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
116
+
117
+ SendInput(1, &mouse_event, sizeof(INPUT));
118
+ }
119
+ else if (flags & PTR_FLAGS_BUTTON2)
120
+ {
121
+ if (flags & PTR_FLAGS_DOWN)
122
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
123
+ else
124
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
125
+
126
+ SendInput(1, &mouse_event, sizeof(INPUT));
127
+ }
128
+ else if (flags & PTR_FLAGS_BUTTON3)
129
+ {
130
+ if (flags & PTR_FLAGS_DOWN)
131
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
132
+ else
133
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
134
+
135
+ SendInput(1, &mouse_event, sizeof(INPUT));
136
+ }
137
+ }
138
+
139
+ return TRUE;
140
+ }
141
+
142
+ BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
143
+ {
144
+ if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
145
+ {
146
+ INPUT mouse_event = { 0 };
147
+ mouse_event.type = INPUT_MOUSE;
148
+
149
+ if (flags & PTR_FLAGS_MOVE)
150
+ {
151
+ float width, height;
152
+ wfInfo* wfi;
153
+ wfi = wf_info_get_instance();
154
+
155
+ if (!wfi)
156
+ return FALSE;
157
+
158
+ // width and height of primary screen (even in multimon setups
159
+ width = (float)GetSystemMetrics(SM_CXSCREEN);
160
+ height = (float)GetSystemMetrics(SM_CYSCREEN);
161
+ x += wfi->servscreen_xoffset;
162
+ y += wfi->servscreen_yoffset;
163
+ mouse_event.u.mi.dx = (LONG)((float)x * (65535.0f / width));
164
+ mouse_event.u.mi.dy = (LONG)((float)y * (65535.0f / height));
165
+ mouse_event.u.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
166
+ SendInput(1, &mouse_event, sizeof(INPUT));
167
+ }
168
+
169
+ mouse_event.u.mi.dx = mouse_event.u.mi.dy = mouse_event.u.mi.dwFlags = 0;
170
+
171
+ if (flags & PTR_XFLAGS_DOWN)
172
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_XDOWN;
173
+ else
174
+ mouse_event.u.mi.dwFlags |= MOUSEEVENTF_XUP;
175
+
176
+ if (flags & PTR_XFLAGS_BUTTON1)
177
+ mouse_event.u.mi.mouseData = XBUTTON1;
178
+ else if (flags & PTR_XFLAGS_BUTTON2)
179
+ mouse_event.u.mi.mouseData = XBUTTON2;
180
+
181
+ SendInput(1, &mouse_event, sizeof(INPUT));
182
+ }
183
+ else
184
+ {
185
+ wf_peer_mouse_event(input, flags, x, y);
186
+ }
187
+
188
+ return TRUE;
189
+ }
190
+
191
+ BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT8 code)
192
+ {
193
+ WINPR_UNUSED(input);
194
+ WINPR_UNUSED(flags);
195
+ WINPR_UNUSED(code);
196
+ return TRUE;
197
+ }
198
+
199
+ BOOL wf_peer_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
200
+ {
201
+ WINPR_UNUSED(input);
202
+ WINPR_UNUSED(flags);
203
+ WINPR_UNUSED(code);
204
+ return TRUE;
205
+ }
206
+
207
+ BOOL wf_peer_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
208
+ {
209
+ WINPR_UNUSED(input);
210
+ WINPR_UNUSED(flags);
211
+ WINPR_UNUSED(x);
212
+ WINPR_UNUSED(y);
213
+ return TRUE;
214
+ }
215
+
216
+ BOOL wf_peer_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
217
+ {
218
+ WINPR_UNUSED(input);
219
+ WINPR_UNUSED(flags);
220
+ WINPR_UNUSED(x);
221
+ WINPR_UNUSED(y);
222
+ return TRUE;
223
+ }
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_input.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_SERVER_WIN_INPUT_H
21
+ #define FREERDP_SERVER_WIN_INPUT_H
22
+
23
+ #include "wf_interface.h"
24
+
25
+ BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code);
26
+ BOOL wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
27
+ BOOL wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
28
+ BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
29
+
30
+ // dummy versions
31
+ BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT8 code);
32
+ BOOL wf_peer_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
33
+ BOOL wf_peer_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
34
+ BOOL wf_peer_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
35
+
36
+ #endif /* FREERDP_SERVER_WIN_INPUT_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_interface.c ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include <winpr/tchar.h>
24
+ #include <winpr/windows.h>
25
+ #include <winpr/winsock.h>
26
+ #include <winpr/assert.h>
27
+
28
+ #include <freerdp/freerdp.h>
29
+ #include <freerdp/listener.h>
30
+ #include <freerdp/constants.h>
31
+ #include <freerdp/channels/wtsvc.h>
32
+ #include <freerdp/channels/channels.h>
33
+ #include <freerdp/build-config.h>
34
+
35
+ #include "wf_peer.h"
36
+ #include "wf_settings.h"
37
+ #include "wf_info.h"
38
+
39
+ #include "wf_interface.h"
40
+
41
+ #include <freerdp/log.h>
42
+ #define TAG SERVER_TAG("windows")
43
+
44
+ #define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Server"
45
+
46
+ static cbCallback cbEvent = NULL;
47
+
48
+ int get_screen_info(int id, _TCHAR* name, size_t length, int* width, int* height, int* bpp)
49
+ {
50
+ DISPLAY_DEVICE dd = { 0 };
51
+
52
+ dd.cb = sizeof(DISPLAY_DEVICE);
53
+
54
+ if (EnumDisplayDevices(NULL, id, &dd, 0) != 0)
55
+ {
56
+ HDC dc;
57
+
58
+ if (name != NULL)
59
+ _stprintf_s(name, length, _T("%s (%s)"), dd.DeviceName, dd.DeviceString);
60
+
61
+ dc = CreateDC(dd.DeviceName, NULL, NULL, NULL);
62
+ *width = GetDeviceCaps(dc, HORZRES);
63
+ *height = GetDeviceCaps(dc, VERTRES);
64
+ *bpp = GetDeviceCaps(dc, BITSPIXEL);
65
+ // ReleaseDC(NULL, dc);
66
+ DeleteDC(dc);
67
+ }
68
+ else
69
+ {
70
+ return 0;
71
+ }
72
+
73
+ return 1;
74
+ }
75
+
76
+ void set_screen_id(int id)
77
+ {
78
+ wfInfo* wfi;
79
+
80
+ wfi = wf_info_get_instance();
81
+ if (!wfi)
82
+ return;
83
+ wfi->screenID = id;
84
+
85
+ return;
86
+ }
87
+
88
+ static DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
89
+ {
90
+ freerdp_listener* instance;
91
+ wfInfo* wfi;
92
+
93
+ wfi = wf_info_get_instance();
94
+ if (!wfi)
95
+ {
96
+ WLog_ERR(TAG, "Failed to get instance");
97
+ return -1;
98
+ }
99
+
100
+ wfi->force_all_disconnect = FALSE;
101
+
102
+ instance = (freerdp_listener*)lpParam;
103
+ WINPR_ASSERT(instance);
104
+ WINPR_ASSERT(instance->GetEventHandles);
105
+ WINPR_ASSERT(instance->CheckFileDescriptor);
106
+
107
+ while (wfi->force_all_disconnect == FALSE)
108
+ {
109
+ DWORD status;
110
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
111
+ DWORD count = instance->GetEventHandles(instance, handles, ARRAYSIZE(handles));
112
+
113
+ if (count == 0)
114
+ {
115
+ WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
116
+ break;
117
+ }
118
+
119
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
120
+ if (status == WAIT_FAILED)
121
+ {
122
+ WLog_ERR(TAG, "WaitForMultipleObjects failed");
123
+ break;
124
+ }
125
+
126
+ if (instance->CheckFileDescriptor(instance) != TRUE)
127
+ {
128
+ WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
129
+ break;
130
+ }
131
+ }
132
+
133
+ WLog_INFO(TAG, "wf_server_main_loop terminating");
134
+ instance->Close(instance);
135
+
136
+ return 0;
137
+ }
138
+
139
+ BOOL wfreerdp_server_start(wfServer* server)
140
+ {
141
+ freerdp_listener* instance;
142
+
143
+ server->instance = freerdp_listener_new();
144
+ server->instance->PeerAccepted = wf_peer_accepted;
145
+ instance = server->instance;
146
+
147
+ wf_settings_read_dword(HKEY_LOCAL_MACHINE, SERVER_KEY, _T("DefaultPort"), &server->port);
148
+
149
+ if (!instance->Open(instance, NULL, (UINT16)server->port))
150
+ return FALSE;
151
+
152
+ if (!(server->thread = CreateThread(NULL, 0, wf_server_main_loop, (void*)instance, 0, NULL)))
153
+ return FALSE;
154
+
155
+ return TRUE;
156
+ }
157
+
158
+ BOOL wfreerdp_server_stop(wfServer* server)
159
+ {
160
+ wfInfo* wfi;
161
+
162
+ wfi = wf_info_get_instance();
163
+ if (!wfi)
164
+ return FALSE;
165
+ WLog_INFO(TAG, "Stopping server");
166
+ wfi->force_all_disconnect = TRUE;
167
+ server->instance->Close(server->instance);
168
+ return TRUE;
169
+ }
170
+
171
+ wfServer* wfreerdp_server_new()
172
+ {
173
+ WSADATA wsaData;
174
+ wfServer* server;
175
+
176
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
177
+ return NULL;
178
+
179
+ server = (wfServer*)calloc(1, sizeof(wfServer));
180
+
181
+ if (server)
182
+ {
183
+ server->port = 3389;
184
+ }
185
+
186
+ WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
187
+
188
+ cbEvent = NULL;
189
+
190
+ return server;
191
+ }
192
+
193
+ void wfreerdp_server_free(wfServer* server)
194
+ {
195
+ free(server);
196
+
197
+ WSACleanup();
198
+ }
199
+
200
+ BOOL wfreerdp_server_is_running(wfServer* server)
201
+ {
202
+ DWORD tStatus;
203
+ BOOL bRet;
204
+
205
+ bRet = GetExitCodeThread(server->thread, &tStatus);
206
+ if (bRet == 0)
207
+ {
208
+ WLog_ERR(TAG, "Error in call to GetExitCodeThread");
209
+ return FALSE;
210
+ }
211
+
212
+ if (tStatus == STILL_ACTIVE)
213
+ return TRUE;
214
+ return FALSE;
215
+ }
216
+
217
+ UINT32 wfreerdp_server_num_peers()
218
+ {
219
+ wfInfo* wfi;
220
+
221
+ wfi = wf_info_get_instance();
222
+ if (!wfi)
223
+ return -1;
224
+ return wfi->peerCount;
225
+ }
226
+
227
+ UINT32 wfreerdp_server_get_peer_hostname(int pId, wchar_t* dstStr)
228
+ {
229
+ wfInfo* wfi;
230
+ freerdp_peer* peer;
231
+
232
+ wfi = wf_info_get_instance();
233
+ if (!wfi)
234
+ return 0;
235
+ peer = wfi->peers[pId];
236
+
237
+ if (peer)
238
+ {
239
+ UINT32 sLen;
240
+
241
+ sLen = strnlen_s(peer->hostname, 50);
242
+ swprintf(dstStr, 50, L"%hs", peer->hostname);
243
+ return sLen;
244
+ }
245
+ else
246
+ {
247
+ WLog_WARN(TAG, "nonexistent peer id=%d", pId);
248
+ return 0;
249
+ }
250
+ }
251
+
252
+ BOOL wfreerdp_server_peer_is_local(int pId)
253
+ {
254
+ wfInfo* wfi;
255
+ freerdp_peer* peer;
256
+
257
+ wfi = wf_info_get_instance();
258
+ if (!wfi)
259
+ return FALSE;
260
+ peer = wfi->peers[pId];
261
+
262
+ if (peer)
263
+ {
264
+ return peer->local;
265
+ }
266
+ else
267
+ {
268
+ return FALSE;
269
+ }
270
+ }
271
+
272
+ BOOL wfreerdp_server_peer_is_connected(int pId)
273
+ {
274
+ wfInfo* wfi;
275
+ freerdp_peer* peer;
276
+
277
+ wfi = wf_info_get_instance();
278
+ if (!wfi)
279
+ return FALSE;
280
+ peer = wfi->peers[pId];
281
+
282
+ if (peer)
283
+ {
284
+ return peer->connected;
285
+ }
286
+ else
287
+ {
288
+ return FALSE;
289
+ }
290
+ }
291
+
292
+ BOOL wfreerdp_server_peer_is_activated(int pId)
293
+ {
294
+ wfInfo* wfi;
295
+ freerdp_peer* peer;
296
+
297
+ wfi = wf_info_get_instance();
298
+ if (!wfi)
299
+ return FALSE;
300
+ peer = wfi->peers[pId];
301
+
302
+ if (peer)
303
+ {
304
+ return peer->activated;
305
+ }
306
+ else
307
+ {
308
+ return FALSE;
309
+ }
310
+ }
311
+
312
+ BOOL wfreerdp_server_peer_is_authenticated(int pId)
313
+ {
314
+ wfInfo* wfi;
315
+ freerdp_peer* peer;
316
+
317
+ wfi = wf_info_get_instance();
318
+ if (!wfi)
319
+ return FALSE;
320
+ peer = wfi->peers[pId];
321
+
322
+ if (peer)
323
+ {
324
+ return peer->authenticated;
325
+ }
326
+ else
327
+ {
328
+ return FALSE;
329
+ }
330
+ }
331
+
332
+ void wfreerdp_server_register_callback_event(cbCallback cb)
333
+ {
334
+ cbEvent = cb;
335
+ }
336
+
337
+ void wfreerdp_server_peer_callback_event(int pId, UINT32 eType)
338
+ {
339
+ if (cbEvent)
340
+ cbEvent(pId, eType);
341
+ }
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_interface.h ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_WIN_INTERFACE_H
22
+ #define FREERDP_SERVER_WIN_INTERFACE_H
23
+
24
+ #include <winpr/windows.h>
25
+
26
+ #include <freerdp/api.h>
27
+ #include <freerdp/freerdp.h>
28
+ #include <freerdp/listener.h>
29
+
30
+ #include <freerdp/freerdp.h>
31
+ #include <freerdp/codec/rfx.h>
32
+
33
+ #include <freerdp/server/rdpsnd.h>
34
+
35
+ #if _WIN32_WINNT >= 0x0602
36
+ #define WITH_DXGI_1_2 1
37
+ #endif
38
+
39
+ #define FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_CONNECT 1
40
+ #define FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_DISCONNECT 2
41
+ #define FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_ACTIVATE 4
42
+ #define FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_AUTH 8
43
+
44
+ typedef struct wf_info wfInfo;
45
+ typedef struct wf_peer_context wfPeerContext;
46
+
47
+ struct wf_info
48
+ {
49
+ wStream* s;
50
+
51
+ // screen and monitor info
52
+ int screenID;
53
+ int virtscreen_width;
54
+ int virtscreen_height;
55
+ int servscreen_width;
56
+ int servscreen_height;
57
+ int servscreen_xoffset;
58
+ int servscreen_yoffset;
59
+
60
+ int frame_idx;
61
+ int bitsPerPixel;
62
+ HDC driverDC;
63
+ int peerCount;
64
+ int activePeerCount;
65
+ void* changeBuffer;
66
+ int framesPerSecond;
67
+ LPTSTR deviceKey;
68
+ TCHAR deviceName[32];
69
+ freerdp_peer** peers;
70
+ BOOL mirrorDriverActive;
71
+ UINT framesWaiting;
72
+
73
+ HANDLE snd_mutex;
74
+ BOOL snd_stop;
75
+ AUDIO_FORMAT* agreed_format;
76
+
77
+ RECT invalid;
78
+ HANDLE mutex;
79
+ BOOL updatePending;
80
+ HANDLE updateEvent;
81
+ HANDLE updateThread;
82
+ HANDLE updateSemaphore;
83
+ RFX_CONTEXT* rfx_context;
84
+ unsigned long lastUpdate;
85
+ unsigned long nextUpdate;
86
+ SURFACE_BITS_COMMAND cmd;
87
+
88
+ BOOL input_disabled;
89
+ BOOL force_all_disconnect;
90
+ };
91
+
92
+ struct wf_peer_context
93
+ {
94
+ rdpContext _p;
95
+
96
+ wfInfo* info;
97
+ int frame_idx;
98
+ HANDLE updateEvent;
99
+ BOOL socketClose;
100
+ HANDLE socketEvent;
101
+ HANDLE socketThread;
102
+ HANDLE socketSemaphore;
103
+
104
+ HANDLE vcm;
105
+ RdpsndServerContext* rdpsnd;
106
+ };
107
+
108
+ struct wf_server
109
+ {
110
+ DWORD port;
111
+ HANDLE thread;
112
+ freerdp_listener* instance;
113
+ };
114
+ typedef struct wf_server wfServer;
115
+
116
+ typedef void(__stdcall* cbCallback)(int, UINT32);
117
+
118
+ FREERDP_API int get_screen_info(int id, _TCHAR* name, size_t length, int* w, int* h, int* b);
119
+ FREERDP_API void set_screen_id(int id);
120
+
121
+ FREERDP_API BOOL wfreerdp_server_start(wfServer* server);
122
+ FREERDP_API BOOL wfreerdp_server_stop(wfServer* server);
123
+
124
+ FREERDP_API wfServer* wfreerdp_server_new(void);
125
+ FREERDP_API void wfreerdp_server_free(wfServer* server);
126
+
127
+ FREERDP_API BOOL wfreerdp_server_is_running(wfServer* server);
128
+
129
+ FREERDP_API UINT32 wfreerdp_server_num_peers(void);
130
+ FREERDP_API UINT32 wfreerdp_server_get_peer_hostname(int pId, wchar_t* dstStr);
131
+ FREERDP_API BOOL wfreerdp_server_peer_is_local(int pId);
132
+ FREERDP_API BOOL wfreerdp_server_peer_is_connected(int pId);
133
+ FREERDP_API BOOL wfreerdp_server_peer_is_activated(int pId);
134
+ FREERDP_API BOOL wfreerdp_server_peer_is_authenticated(int pId);
135
+
136
+ FREERDP_API void wfreerdp_server_register_callback_event(cbCallback cb);
137
+
138
+ void wfreerdp_server_peer_callback_event(int pId, UINT32 eType);
139
+
140
+ #endif /* FREERDP_SERVER_WIN_INTERFACE_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_mirage.c ADDED
@@ -0,0 +1,361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012-2013 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <winpr/tchar.h>
22
+ #include <winpr/windows.h>
23
+
24
+ #include "wf_mirage.h"
25
+
26
+ #include <freerdp/log.h>
27
+ #define TAG SERVER_TAG("Windows.mirror")
28
+
29
+ #define DEVICE_KEY_PREFIX _T("\\Registry\\Machine\\")
30
+ /*
31
+ This function will iterate over the loaded display devices until it finds
32
+ the mirror device we want to load. If found, it will then copy the registry
33
+ key corresponding to the device to the wfi and returns TRUE. Otherwise
34
+ the function returns FALSE.
35
+ */
36
+ BOOL wf_mirror_driver_find_display_device(wfInfo* wfi)
37
+ {
38
+ BOOL result;
39
+ BOOL devFound;
40
+ DWORD deviceNumber;
41
+ DISPLAY_DEVICE deviceInfo;
42
+ devFound = FALSE;
43
+ deviceNumber = 0;
44
+ deviceInfo.cb = sizeof(deviceInfo);
45
+
46
+ while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0))
47
+ {
48
+ if (_tcscmp(deviceInfo.DeviceString, _T("Mirage Driver")) == 0)
49
+ {
50
+ int deviceKeyLength;
51
+ int deviceKeyPrefixLength;
52
+ deviceKeyPrefixLength = _tcslen(DEVICE_KEY_PREFIX);
53
+
54
+ if (_tcsnicmp(deviceInfo.DeviceKey, DEVICE_KEY_PREFIX, deviceKeyPrefixLength) == 0)
55
+ {
56
+ deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength;
57
+ wfi->deviceKey = (LPTSTR)malloc((deviceKeyLength + 1) * sizeof(TCHAR));
58
+
59
+ if (!wfi->deviceKey)
60
+ return FALSE;
61
+
62
+ _tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1,
63
+ &deviceInfo.DeviceKey[deviceKeyPrefixLength], deviceKeyLength);
64
+ }
65
+
66
+ _tcsncpy_s(wfi->deviceName, 32, deviceInfo.DeviceName, _tcslen(deviceInfo.DeviceName));
67
+ return TRUE;
68
+ }
69
+
70
+ deviceNumber++;
71
+ }
72
+
73
+ return FALSE;
74
+ }
75
+
76
+ /**
77
+ * This function will attempt to access the the windows registry using the device
78
+ * key stored in the current wfi. It will attempt to read the value of the
79
+ * "Attach.ToDesktop" subkey and will return TRUE if the value is already set to
80
+ * val. If unable to read the subkey, this function will return FALSE. If the
81
+ * subkey is not set to val it will then attempt to set it to val and return TRUE. If
82
+ * unsuccessful or an unexpected value is encountered, the function returns
83
+ * FALSE.
84
+ */
85
+
86
+ BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode)
87
+ {
88
+ HKEY hKey;
89
+ LONG status;
90
+ DWORD dwType;
91
+ DWORD dwSize;
92
+ DWORD dwValue;
93
+ status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wfi->deviceKey, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY,
94
+ &hKey);
95
+
96
+ if (status != ERROR_SUCCESS)
97
+ {
98
+ WLog_DBG(TAG, "Error opening RegKey: status=0x%08lX", status);
99
+
100
+ if (status == ERROR_ACCESS_DENIED)
101
+ WLog_DBG(TAG, "access denied. Do you have admin privileges?");
102
+
103
+ return FALSE;
104
+ }
105
+
106
+ dwSize = sizeof(DWORD);
107
+ status = RegQueryValueEx(hKey, _T("Attach.ToDesktop"), NULL, &dwType, (BYTE*)&dwValue, &dwSize);
108
+
109
+ if (status != ERROR_SUCCESS)
110
+ {
111
+ WLog_DBG(TAG, "Error querying RegKey: status=0x%08lX", status);
112
+
113
+ if (status == ERROR_ACCESS_DENIED)
114
+ WLog_DBG(TAG, "access denied. Do you have admin privileges?");
115
+
116
+ return FALSE;
117
+ }
118
+
119
+ if (dwValue ^ mode) // only if we want to change modes
120
+ {
121
+ dwValue = mode;
122
+ dwSize = sizeof(DWORD);
123
+ status = RegSetValueEx(hKey, _T("Attach.ToDesktop"), 0, REG_DWORD, (BYTE*)&dwValue, dwSize);
124
+
125
+ if (status != ERROR_SUCCESS)
126
+ {
127
+ WLog_DBG(TAG, "Error writing registry key: %ld", status);
128
+
129
+ if (status == ERROR_ACCESS_DENIED)
130
+ WLog_DBG(TAG, "access denied. Do you have admin privileges?");
131
+
132
+ WLog_DBG(TAG, "");
133
+ return FALSE;
134
+ }
135
+ }
136
+
137
+ return TRUE;
138
+ }
139
+
140
+ void wf_mirror_driver_print_display_change_status(LONG status)
141
+ {
142
+ TCHAR disp_change[64];
143
+
144
+ switch (status)
145
+ {
146
+ case DISP_CHANGE_SUCCESSFUL:
147
+ _tcscpy(disp_change, _T("DISP_CHANGE_SUCCESSFUL"));
148
+ break;
149
+
150
+ case DISP_CHANGE_BADDUALVIEW:
151
+ _tcscpy(disp_change, _T("DISP_CHANGE_BADDUALVIEW"));
152
+ break;
153
+
154
+ case DISP_CHANGE_BADFLAGS:
155
+ _tcscpy(disp_change, _T("DISP_CHANGE_BADFLAGS"));
156
+ break;
157
+
158
+ case DISP_CHANGE_BADMODE:
159
+ _tcscpy(disp_change, _T("DISP_CHANGE_BADMODE"));
160
+ break;
161
+
162
+ case DISP_CHANGE_BADPARAM:
163
+ _tcscpy(disp_change, _T("DISP_CHANGE_BADPARAM"));
164
+ break;
165
+
166
+ case DISP_CHANGE_FAILED:
167
+ _tcscpy(disp_change, _T("DISP_CHANGE_FAILED"));
168
+ break;
169
+
170
+ case DISP_CHANGE_NOTUPDATED:
171
+ _tcscpy(disp_change, _T("DISP_CHANGE_NOTUPDATED"));
172
+ break;
173
+
174
+ case DISP_CHANGE_RESTART:
175
+ _tcscpy(disp_change, _T("DISP_CHANGE_RESTART"));
176
+ break;
177
+
178
+ default:
179
+ _tcscpy(disp_change, _T("DISP_CHANGE_UNKNOWN"));
180
+ break;
181
+ }
182
+
183
+ if (status != DISP_CHANGE_SUCCESSFUL)
184
+ WLog_ERR(TAG, "ChangeDisplaySettingsEx() failed with %s (%ld)", disp_change, status);
185
+ else
186
+ WLog_INFO(TAG, "ChangeDisplaySettingsEx() succeeded with %s (%ld)", disp_change, status);
187
+ }
188
+
189
+ /**
190
+ * This function will attempt to apply the currently configured display settings
191
+ * in the registry to the display driver. It will return TRUE if successful
192
+ * otherwise it returns FALSE.
193
+ * If mode is MIRROR_UNLOAD then the the driver will be asked to remove itself.
194
+ */
195
+
196
+ BOOL wf_mirror_driver_update(wfInfo* wfi, int mode)
197
+ {
198
+ BOOL status;
199
+ DWORD* extHdr;
200
+ WORD drvExtraSaved;
201
+ DEVMODE* deviceMode;
202
+ LONG disp_change_status;
203
+ DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE;
204
+
205
+ if ((mode != MIRROR_LOAD) && (mode != MIRROR_UNLOAD))
206
+ {
207
+ WLog_DBG(TAG, "Invalid mirror mode!");
208
+ return FALSE;
209
+ }
210
+
211
+ deviceMode = (DEVMODE*)malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
212
+
213
+ if (!deviceMode)
214
+ return FALSE;
215
+
216
+ deviceMode->dmDriverExtra = 2 * sizeof(DWORD);
217
+ extHdr = (DWORD*)((BYTE*)&deviceMode + sizeof(DEVMODE));
218
+ extHdr[0] = dmf_devmodewext_magic_sig;
219
+ extHdr[1] = 0;
220
+ drvExtraSaved = deviceMode->dmDriverExtra;
221
+ memset(deviceMode, 0, sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
222
+ deviceMode->dmSize = sizeof(DEVMODE);
223
+ deviceMode->dmDriverExtra = drvExtraSaved;
224
+
225
+ if (mode == MIRROR_LOAD)
226
+ {
227
+ wfi->virtscreen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
228
+ wfi->virtscreen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
229
+ deviceMode->dmPelsWidth = wfi->virtscreen_width;
230
+ deviceMode->dmPelsHeight = wfi->virtscreen_height;
231
+ deviceMode->dmBitsPerPel = wfi->bitsPerPixel;
232
+ deviceMode->u.s2.dmPosition.x = wfi->servscreen_xoffset;
233
+ deviceMode->u.s2.dmPosition.y = wfi->servscreen_yoffset;
234
+ }
235
+
236
+ deviceMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION;
237
+ _tcsncpy_s(deviceMode->dmDeviceName, 32, wfi->deviceName, _tcslen(wfi->deviceName));
238
+ disp_change_status =
239
+ ChangeDisplaySettingsEx(wfi->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL);
240
+ status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE;
241
+
242
+ if (!status)
243
+ wf_mirror_driver_print_display_change_status(disp_change_status);
244
+
245
+ return status;
246
+ }
247
+
248
+ BOOL wf_mirror_driver_map_memory(wfInfo* wfi)
249
+ {
250
+ int status;
251
+ wfi->driverDC = CreateDC(wfi->deviceName, NULL, NULL, NULL);
252
+
253
+ if (wfi->driverDC == NULL)
254
+ {
255
+ WLog_ERR(TAG, "Could not create device driver context!");
256
+ {
257
+ LPVOID lpMsgBuf;
258
+ DWORD dw = GetLastError();
259
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
260
+ FORMAT_MESSAGE_IGNORE_INSERTS,
261
+ NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0,
262
+ NULL);
263
+ // Display the error message and exit the process
264
+ WLog_ERR(TAG, "CreateDC failed on device [%s] with error %lu: %s", wfi->deviceName, dw,
265
+ lpMsgBuf);
266
+ LocalFree(lpMsgBuf);
267
+ }
268
+ return FALSE;
269
+ }
270
+
271
+ wfi->changeBuffer = calloc(1, sizeof(GETCHANGESBUF));
272
+
273
+ if (!wfi->changeBuffer)
274
+ return FALSE;
275
+
276
+ status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF),
277
+ (LPSTR)wfi->changeBuffer);
278
+
279
+ if (status <= 0)
280
+ {
281
+ WLog_ERR(TAG, "Failed to map shared memory from the driver! code %d", status);
282
+ return FALSE;
283
+ }
284
+
285
+ return TRUE;
286
+ }
287
+
288
+ /* Unmap the shared memory and release the DC */
289
+
290
+ BOOL wf_mirror_driver_cleanup(wfInfo* wfi)
291
+ {
292
+ int status;
293
+ status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_unmap, sizeof(GETCHANGESBUF),
294
+ (LPSTR)wfi->changeBuffer, 0, 0);
295
+
296
+ if (status <= 0)
297
+ {
298
+ WLog_ERR(TAG, "Failed to unmap shared memory from the driver! code %d", status);
299
+ }
300
+
301
+ if (wfi->driverDC != NULL)
302
+ {
303
+ status = DeleteDC(wfi->driverDC);
304
+
305
+ if (status == 0)
306
+ {
307
+ WLog_ERR(TAG, "Failed to release DC!");
308
+ }
309
+ }
310
+
311
+ free(wfi->changeBuffer);
312
+ return TRUE;
313
+ }
314
+
315
+ BOOL wf_mirror_driver_activate(wfInfo* wfi)
316
+ {
317
+ if (!wfi->mirrorDriverActive)
318
+ {
319
+ WLog_DBG(TAG, "Activating Mirror Driver");
320
+
321
+ if (wf_mirror_driver_find_display_device(wfi) == FALSE)
322
+ {
323
+ WLog_DBG(TAG, "Could not find dfmirage mirror driver! Is it installed?");
324
+ return FALSE;
325
+ }
326
+
327
+ if (wf_mirror_driver_display_device_attach(wfi, 1) == FALSE)
328
+ {
329
+ WLog_DBG(TAG, "Could not attach display device!");
330
+ return FALSE;
331
+ }
332
+
333
+ if (wf_mirror_driver_update(wfi, MIRROR_LOAD) == FALSE)
334
+ {
335
+ WLog_DBG(TAG, "could not update system with new display settings!");
336
+ return FALSE;
337
+ }
338
+
339
+ if (wf_mirror_driver_map_memory(wfi) == FALSE)
340
+ {
341
+ WLog_DBG(TAG, "Unable to map memory for mirror driver!");
342
+ return FALSE;
343
+ }
344
+
345
+ wfi->mirrorDriverActive = TRUE;
346
+ }
347
+
348
+ return TRUE;
349
+ }
350
+
351
+ void wf_mirror_driver_deactivate(wfInfo* wfi)
352
+ {
353
+ if (wfi->mirrorDriverActive)
354
+ {
355
+ WLog_DBG(TAG, "Deactivating Mirror Driver");
356
+ wf_mirror_driver_cleanup(wfi);
357
+ wf_mirror_driver_display_device_attach(wfi, 0);
358
+ wf_mirror_driver_update(wfi, MIRROR_UNLOAD);
359
+ wfi->mirrorDriverActive = FALSE;
360
+ }
361
+ }
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_mirage.h ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012-2013 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_SERVER_WIN_MIRAGE_H
22
+ #define FREERDP_SERVER_WIN_MIRAGE_H
23
+
24
+ #include "wf_interface.h"
25
+
26
+ enum
27
+ {
28
+ MIRROR_LOAD = 0,
29
+ MIRROR_UNLOAD = 1
30
+ };
31
+
32
+ enum
33
+ {
34
+ DMF_ESCAPE_BASE_1_VB = 1030,
35
+ DMF_ESCAPE_BASE_2_VB = 1026,
36
+ DMF_ESCAPE_BASE_3_VB = 24
37
+ };
38
+
39
+ #ifdef _WIN64
40
+
41
+ #define CLIENT_64BIT 0x8000
42
+
43
+ enum
44
+ {
45
+ DMF_ESCAPE_BASE_1 = CLIENT_64BIT | DMF_ESCAPE_BASE_1_VB,
46
+ DMF_ESCAPE_BASE_2 = CLIENT_64BIT | DMF_ESCAPE_BASE_2_VB,
47
+ DMF_ESCAPE_BASE_3 = CLIENT_64BIT | DMF_ESCAPE_BASE_3_VB,
48
+ };
49
+
50
+ #else
51
+
52
+ enum
53
+ {
54
+ DMF_ESCAPE_BASE_1 = DMF_ESCAPE_BASE_1_VB,
55
+ DMF_ESCAPE_BASE_2 = DMF_ESCAPE_BASE_2_VB,
56
+ DMF_ESCAPE_BASE_3 = DMF_ESCAPE_BASE_3_VB,
57
+ };
58
+
59
+ #endif
60
+
61
+ typedef enum
62
+ {
63
+ dmf_esc_qry_ver_info = DMF_ESCAPE_BASE_2 + 0,
64
+ dmf_esc_usm_pipe_map = DMF_ESCAPE_BASE_1 + 0,
65
+ dmf_esc_usm_pipe_unmap = DMF_ESCAPE_BASE_1 + 1,
66
+ dmf_esc_test = DMF_ESCAPE_BASE_1 + 20,
67
+ dmf_esc_usm_pipe_mapping_test = DMF_ESCAPE_BASE_1 + 21,
68
+ dmf_esc_pointer_shape_get = DMF_ESCAPE_BASE_3,
69
+
70
+ } dmf_escape;
71
+
72
+ #define CLIP_LIMIT 50
73
+ #define MAXCHANGES_BUF 20000
74
+
75
+ typedef enum
76
+ {
77
+ dmf_dfo_IGNORE = 0,
78
+ dmf_dfo_FROM_SCREEN = 1,
79
+ dmf_dfo_FROM_DIB = 2,
80
+ dmf_dfo_TO_SCREEN = 3,
81
+ dmf_dfo_SCREEN_SCREEN = 11,
82
+ dmf_dfo_BLIT = 12,
83
+ dmf_dfo_SOLIDFILL = 13,
84
+ dmf_dfo_BLEND = 14,
85
+ dmf_dfo_TRANS = 15,
86
+ dmf_dfo_PLG = 17,
87
+ dmf_dfo_TEXTOUT = 18,
88
+ dmf_dfo_Ptr_Shape = 19,
89
+ dmf_dfo_Ptr_Engage = 48,
90
+ dmf_dfo_Ptr_Avert = 49,
91
+ dmf_dfn_assert_on = 64,
92
+ dmf_dfn_assert_off = 65,
93
+ } dmf_UpdEvent;
94
+
95
+ #define NOCACHE 1
96
+ #define OLDCACHE 2
97
+ #define NEWCACHE 3
98
+
99
+ typedef struct
100
+ {
101
+ ULONG type;
102
+ RECT rect;
103
+ #ifndef DFMIRAGE_LEAN
104
+ RECT origrect;
105
+ POINT point;
106
+ ULONG color;
107
+ ULONG refcolor;
108
+ #endif
109
+ } CHANGES_RECORD;
110
+
111
+ typedef CHANGES_RECORD* PCHANGES_RECORD;
112
+
113
+ typedef struct
114
+ {
115
+ ULONG counter;
116
+ CHANGES_RECORD pointrect[MAXCHANGES_BUF];
117
+ } CHANGES_BUF;
118
+
119
+ #define EXT_DEVMODE_SIZE_MAX 3072
120
+ #define DMF_PIPE_SEC_SIZE_DEFAULT ALIGN64K(sizeof(CHANGES_BUF))
121
+
122
+ typedef struct
123
+ {
124
+ CHANGES_BUF* buffer;
125
+ PVOID Userbuffer;
126
+ } GETCHANGESBUF;
127
+
128
+ #define dmf_sprb_ERRORMASK 0x07FF
129
+ #define dmf_sprb_STRICTSESSION_AFF 0x1FFF
130
+
131
+ typedef enum
132
+ {
133
+ dmf_sprb_internal_error = 0x0001,
134
+ dmf_sprb_miniport_gen_error = 0x0004,
135
+ dmf_sprb_memory_alloc_failed = 0x0008,
136
+ dmf_sprb_pipe_buff_overflow = 0x0010,
137
+ dmf_sprb_pipe_buff_insufficient = 0x0020,
138
+ dmf_sprb_pipe_not_ready = 0x0040,
139
+ dmf_sprb_gdi_err = 0x0100,
140
+ dmf_sprb_owner_died = 0x0400,
141
+ dmf_sprb_tgtwnd_gone = 0x0800,
142
+ dmf_sprb_pdev_detached = 0x2000,
143
+ } dmf_session_prob_status;
144
+
145
+ #define DMF_ESC_RET_FAILF 0x80000000
146
+ #define DMF_ESC_RET_SSTMASK 0x0000FFFF
147
+ #define DMF_ESC_RET_IMMMASK 0x7FFF0000
148
+
149
+ typedef enum
150
+ {
151
+ dmf_escret_generic_ok = 0x00010000,
152
+ dmf_escret_bad_state = 0x00100000,
153
+ dmf_escret_access_denied = 0x00200000,
154
+ dmf_escret_bad_buffer_size = 0x00400000,
155
+ dmf_escret_internal_err = 0x00800000,
156
+ dmf_escret_out_of_memory = 0x02000000,
157
+ dmf_escret_already_connected = 0x04000000,
158
+ dmf_escret_oh_boy_too_late = 0x08000000,
159
+ dmf_escret_bad_window = 0x10000000,
160
+ dmf_escret_drv_ver_higher = 0x20000000,
161
+ dmf_escret_drv_ver_lower = 0x40000000,
162
+ } dmf_esc_retcode;
163
+
164
+ typedef struct
165
+ {
166
+ ULONG cbSize;
167
+ ULONG app_actual_version;
168
+ ULONG display_minreq_version;
169
+ ULONG connect_options;
170
+ } Esc_dmf_Qvi_IN;
171
+
172
+ enum
173
+ {
174
+ esc_qvi_prod_name_max = 16,
175
+ };
176
+
177
+ #define ESC_QVI_PROD_MIRAGE "MIRAGE"
178
+ #define ESC_QVI_PROD_QUASAR "QUASAR"
179
+
180
+ typedef struct
181
+ {
182
+ ULONG cbSize;
183
+ ULONG display_actual_version;
184
+ ULONG miniport_actual_version;
185
+ ULONG app_minreq_version;
186
+ ULONG display_buildno;
187
+ ULONG miniport_buildno;
188
+ char prod_name[esc_qvi_prod_name_max];
189
+ } Esc_dmf_Qvi_OUT;
190
+
191
+ typedef struct
192
+ {
193
+ ULONG cbSize;
194
+ char* pDstBmBuf;
195
+ ULONG nDstBmBufSize;
196
+ } Esc_dmf_pointer_shape_get_IN;
197
+
198
+ typedef struct
199
+ {
200
+ ULONG cbSize;
201
+ POINTL BmSize;
202
+ char* pMaskBm;
203
+ ULONG nMaskBmSize;
204
+ char* pColorBm;
205
+ ULONG nColorBmSize;
206
+ char* pColorBmPal;
207
+ ULONG nColorBmPalEntries;
208
+ } Esc_dmf_pointer_shape_get_OUT;
209
+
210
+ BOOL wf_mirror_driver_find_display_device(wfInfo* wfi);
211
+ BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode);
212
+ BOOL wf_mirror_driver_update(wfInfo* wfi, int mode);
213
+ BOOL wf_mirror_driver_map_memory(wfInfo* wfi);
214
+ BOOL wf_mirror_driver_cleanup(wfInfo* wfi);
215
+
216
+ BOOL wf_mirror_driver_activate(wfInfo* wfi);
217
+ void wf_mirror_driver_deactivate(wfInfo* wfi);
218
+
219
+ #endif /* FREERDP_SERVER_WIN_MIRAGE_H */
local-test-freerdp-full-01/afc-freerdp/server/Windows/wf_peer.c ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Client
3
+ * FreeRDP Windows Server
4
+ *
5
+ * Copyright 2012 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2012 Corey Clayton <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include <winpr/assert.h>
24
+ #include <winpr/tchar.h>
25
+ #include <winpr/stream.h>
26
+ #include <winpr/windows.h>
27
+
28
+ #include <freerdp/listener.h>
29
+ #include <freerdp/codec/rfx.h>
30
+ #include <freerdp/build-config.h>
31
+ #include <freerdp/crypto/certificate.h>
32
+
33
+ #include "wf_info.h"
34
+ #include "wf_input.h"
35
+ #include "wf_mirage.h"
36
+ #include "wf_update.h"
37
+ #include "wf_settings.h"
38
+ #include "wf_rdpsnd.h"
39
+
40
+ #include "wf_peer.h"
41
+ #include <freerdp/peer.h>
42
+
43
+ #include <freerdp/log.h>
44
+ #define TAG SERVER_TAG("windows")
45
+
46
+ #define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING
47
+
48
+ static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam);
49
+
50
+ static BOOL wf_peer_context_new(freerdp_peer* client, rdpContext* ctx)
51
+ {
52
+ wfPeerContext* context = (wfPeerContext*)ctx;
53
+ WINPR_ASSERT(context);
54
+
55
+ if (!(context->info = wf_info_get_instance()))
56
+ return FALSE;
57
+
58
+ context->vcm = WTSOpenServerA((LPSTR)client->context);
59
+
60
+ if (!context->vcm || context->vcm == INVALID_HANDLE_VALUE)
61
+ return FALSE;
62
+
63
+ if (!wf_info_peer_register(context->info, context))
64
+ {
65
+ WTSCloseServer(context->vcm);
66
+ context->vcm = NULL;
67
+ return FALSE;
68
+ }
69
+
70
+ return TRUE;
71
+ }
72
+
73
+ static void wf_peer_context_free(freerdp_peer* client, rdpContext* ctx)
74
+ {
75
+ wfPeerContext* context = (wfPeerContext*)ctx;
76
+ WINPR_ASSERT(context);
77
+
78
+ wf_info_peer_unregister(context->info, context);
79
+
80
+ if (context->rdpsnd)
81
+ {
82
+ wf_rdpsnd_lock();
83
+ context->info->snd_stop = TRUE;
84
+ rdpsnd_server_context_free(context->rdpsnd);
85
+ wf_rdpsnd_unlock();
86
+ }
87
+
88
+ WTSCloseServer(context->vcm);
89
+ }
90
+
91
+ static BOOL wf_peer_init(freerdp_peer* client)
92
+ {
93
+ client->ContextSize = sizeof(wfPeerContext);
94
+ client->ContextNew = wf_peer_context_new;
95
+ client->ContextFree = wf_peer_context_free;
96
+ return freerdp_peer_context_new(client);
97
+ }
98
+
99
+ static BOOL wf_peer_post_connect(freerdp_peer* client)
100
+ {
101
+ wfInfo* wfi;
102
+ rdpSettings* settings;
103
+ wfPeerContext* context;
104
+
105
+ WINPR_ASSERT(client);
106
+
107
+ context = (wfPeerContext*)client->context;
108
+ WINPR_ASSERT(context);
109
+
110
+ wfi = context->info;
111
+ WINPR_ASSERT(wfi);
112
+
113
+ settings = client->context->settings;
114
+ WINPR_ASSERT(settings);
115
+
116
+ if ((get_screen_info(wfi->screenID, NULL, 0, &wfi->servscreen_width, &wfi->servscreen_height,
117
+ &wfi->bitsPerPixel) == 0) ||
118
+ (wfi->servscreen_width == 0) || (wfi->servscreen_height == 0) || (wfi->bitsPerPixel == 0))
119
+ {
120
+ WLog_ERR(TAG, "postconnect: error getting screen info for screen %d", wfi->screenID);
121
+ WLog_ERR(TAG, "\t%dx%dx%d", wfi->servscreen_height, wfi->servscreen_width,
122
+ wfi->bitsPerPixel);
123
+ return FALSE;
124
+ }
125
+
126
+ if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) != wfi->servscreen_width) ||
127
+ (freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) != wfi->servscreen_height))
128
+ {
129
+ /*
130
+ WLog_DBG(TAG, "Client requested resolution %"PRIu32"x%"PRIu32", but will resize to %dx%d",
131
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
132
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), wfi->servscreen_width,
133
+ wfi->servscreen_height);
134
+ */
135
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, wfi->servscreen_width) ||
136
+ !freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, wfi->servscreen_height) ||
137
+ !freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, wfi->bitsPerPixel))
138
+ return FALSE;
139
+
140
+ WINPR_ASSERT(client->context->update);
141
+ WINPR_ASSERT(client->context->update->DesktopResize);
142
+ client->context->update->DesktopResize(client->context);
143
+ }
144
+
145
+ if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
146
+ {
147
+ wf_peer_rdpsnd_init(context); /* Audio Output */
148
+ }
149
+
150
+ return TRUE;
151
+ }
152
+
153
+ static BOOL wf_peer_activate(freerdp_peer* client)
154
+ {
155
+ wfInfo* wfi;
156
+ wfPeerContext* context = (wfPeerContext*)client->context;
157
+ wfi = context->info;
158
+ client->activated = TRUE;
159
+ wf_update_peer_activate(wfi, context);
160
+ wfreerdp_server_peer_callback_event(((rdpContext*)context)->peer->pId,
161
+ FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_ACTIVATE);
162
+ return TRUE;
163
+ }
164
+
165
+ static BOOL wf_peer_logon(freerdp_peer* client, const SEC_WINNT_AUTH_IDENTITY* identity,
166
+ BOOL automatic)
167
+ {
168
+ wfreerdp_server_peer_callback_event(((rdpContext*)client->context)->peer->pId,
169
+ FREERDP_SERVER_WIN_SRV_CALLBACK_EVENT_AUTH);
170
+ return TRUE;
171
+ }
172
+
173
+ static BOOL wf_peer_synchronize_event(rdpInput* input, UINT32 flags)
174
+ {
175
+ return TRUE;
176
+ }
177
+
178
+ BOOL wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
179
+ {
180
+ HANDLE hThread;
181
+
182
+ if (!(hThread = CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL)))
183
+ return FALSE;
184
+
185
+ (void)CloseHandle(hThread);
186
+ return TRUE;
187
+ }
188
+
189
+ static DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
190
+ {
191
+ wfPeerContext* context;
192
+ freerdp_peer* client = (freerdp_peer*)lpParam;
193
+
194
+ WINPR_ASSERT(client);
195
+ WINPR_ASSERT(client->GetEventHandles);
196
+ WINPR_ASSERT(client->CheckFileDescriptor);
197
+
198
+ context = (wfPeerContext*)client->context;
199
+ WINPR_ASSERT(context);
200
+
201
+ while (1)
202
+ {
203
+ DWORD status;
204
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
205
+ DWORD count = client->GetEventHandles(client, handles, ARRAYSIZE(handles));
206
+
207
+ if (count == 0)
208
+ {
209
+ WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
210
+ break;
211
+ }
212
+
213
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
214
+ if (status == WAIT_FAILED)
215
+ {
216
+ WLog_ERR(TAG, "WaitForMultipleObjects failed");
217
+ break;
218
+ }
219
+
220
+ (void)SetEvent(context->socketEvent);
221
+ (void)WaitForSingleObject(context->socketSemaphore, INFINITE);
222
+
223
+ if (context->socketClose)
224
+ break;
225
+ }
226
+
227
+ return 0;
228
+ }
229
+
230
+ static BOOL wf_peer_read_settings(freerdp_peer* client)
231
+ {
232
+ rdpSettings* settings;
233
+
234
+ WINPR_ASSERT(client);
235
+ WINPR_ASSERT(client->context);
236
+
237
+ settings = client->context->settings;
238
+ WINPR_ASSERT(settings);
239
+
240
+ char* CertificateFile = NULL;
241
+ if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, SERVER_KEY, _T("CertificateFile"),
242
+ &(CertificateFile)))
243
+ CertificateFile = _strdup("server.crt");
244
+
245
+ rdpCertificate* cert = freerdp_certificate_new_from_file(CertificateFile);
246
+ free(CertificateFile);
247
+ if (!cert)
248
+ return FALSE;
249
+
250
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1))
251
+ return FALSE;
252
+
253
+ char* PrivateKeyFile = NULL;
254
+ if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, SERVER_KEY, _T("PrivateKeyFile"),
255
+ &(PrivateKeyFile)))
256
+ PrivateKeyFile = _strdup("server.key");
257
+
258
+ rdpPrivateKey* key = freerdp_key_new_from_file(PrivateKeyFile);
259
+ free(PrivateKeyFile);
260
+
261
+ if (!key)
262
+ return FALSE;
263
+
264
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1))
265
+ return FALSE;
266
+
267
+ return TRUE;
268
+ }
269
+
270
+ DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
271
+ {
272
+ wfInfo* wfi;
273
+ DWORD nCount;
274
+ DWORD status;
275
+ HANDLE handles[32];
276
+ rdpSettings* settings;
277
+ wfPeerContext* context;
278
+ freerdp_peer* client = (freerdp_peer*)lpParam;
279
+
280
+ if (!wf_peer_init(client))
281
+ goto fail_peer_init;
282
+
283
+ WINPR_ASSERT(client->context);
284
+
285
+ settings = client->context->settings;
286
+ WINPR_ASSERT(settings);
287
+
288
+ if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE))
289
+ goto fail_peer_init;
290
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32))
291
+ goto fail_peer_init;
292
+ if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, FALSE))
293
+ goto fail_peer_init;
294
+ if (!freerdp_settings_set_bool(settings, FreeRDP_JpegCodec, FALSE))
295
+ goto fail_peer_init;
296
+
297
+ if (!wf_peer_read_settings(client))
298
+ goto fail_peer_init;
299
+
300
+ client->PostConnect = wf_peer_post_connect;
301
+ client->Activate = wf_peer_activate;
302
+ client->Logon = wf_peer_logon;
303
+
304
+ WINPR_ASSERT(client->context->input);
305
+ client->context->input->SynchronizeEvent = wf_peer_synchronize_event;
306
+ client->context->input->KeyboardEvent = wf_peer_keyboard_event;
307
+ client->context->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event;
308
+ client->context->input->MouseEvent = wf_peer_mouse_event;
309
+ client->context->input->ExtendedMouseEvent = wf_peer_extended_mouse_event;
310
+
311
+ WINPR_ASSERT(client->Initialize);
312
+ if (!client->Initialize(client))
313
+ goto fail_client_initialize;
314
+
315
+ context = (wfPeerContext*)client->context;
316
+
317
+ if (context->socketClose)
318
+ goto fail_socked_closed;
319
+
320
+ wfi = context->info;
321
+
322
+ if (wfi->input_disabled)
323
+ {
324
+ WLog_INFO(TAG, "client input is disabled");
325
+ client->context->input->KeyboardEvent = wf_peer_keyboard_event_dummy;
326
+ client->context->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy;
327
+ client->context->input->MouseEvent = wf_peer_mouse_event_dummy;
328
+ client->context->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy;
329
+ }
330
+
331
+ if (!(context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
332
+ goto fail_socket_event;
333
+
334
+ if (!(context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL)))
335
+ goto fail_socket_semaphore;
336
+
337
+ if (!(context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL)))
338
+ goto fail_socket_thread;
339
+
340
+ WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname);
341
+ nCount = 0;
342
+ handles[nCount++] = context->updateEvent;
343
+ handles[nCount++] = context->socketEvent;
344
+
345
+ while (1)
346
+ {
347
+ status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
348
+
349
+ if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT))
350
+ {
351
+ WLog_ERR(TAG, "WaitForMultipleObjects failed");
352
+ break;
353
+ }
354
+
355
+ if (WaitForSingleObject(context->updateEvent, 0) == 0)
356
+ {
357
+ if (client->activated)
358
+ wf_update_peer_send(wfi, context);
359
+
360
+ (void)ResetEvent(context->updateEvent);
361
+ ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
362
+ }
363
+
364
+ if (WaitForSingleObject(context->socketEvent, 0) == 0)
365
+ {
366
+ if (client->CheckFileDescriptor(client) != TRUE)
367
+ {
368
+ WLog_ERR(TAG, "Failed to check peer file descriptor");
369
+ context->socketClose = TRUE;
370
+ }
371
+
372
+ (void)ResetEvent(context->socketEvent);
373
+ ReleaseSemaphore(context->socketSemaphore, 1, NULL);
374
+
375
+ if (context->socketClose)
376
+ break;
377
+ }
378
+
379
+ // force disconnect
380
+ if (wfi->force_all_disconnect == TRUE)
381
+ {
382
+ WLog_INFO(TAG, "Forcing Disconnect -> ");
383
+ break;
384
+ }
385
+
386
+ /* FIXME: we should wait on this, instead of calling it every time */
387
+ if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
388
+ break;
389
+ }
390
+
391
+ WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname);
392
+
393
+ if (WaitForSingleObject(context->updateEvent, 0) == 0)
394
+ {
395
+ (void)ResetEvent(context->updateEvent);
396
+ ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
397
+ }
398
+
399
+ wf_update_peer_deactivate(wfi, context);
400
+ client->Disconnect(client);
401
+ fail_socket_thread:
402
+ (void)CloseHandle(context->socketSemaphore);
403
+ context->socketSemaphore = NULL;
404
+ fail_socket_semaphore:
405
+ (void)CloseHandle(context->socketEvent);
406
+ context->socketEvent = NULL;
407
+ fail_socket_event:
408
+ fail_socked_closed:
409
+ fail_client_initialize:
410
+ freerdp_peer_context_free(client);
411
+ fail_peer_init:
412
+ freerdp_peer_free(client);
413
+ return 0;
414
+ }