21 #include <freerdp/config.h>
25 #include <winpr/windows.h>
27 #include <freerdp/freerdp.h>
28 #include <freerdp/listener.h>
32 #include "wf_mirage.h"
34 #include "wf_update.h"
36 #include <freerdp/log.h>
37 #define TAG SERVER_TAG("windows")
39 DWORD WINAPI wf_update_thread(LPVOID lpParam)
45 wfi = (wfInfo*)lpParam;
46 fps = wfi->framesPerSecond;
53 if (wf_info_lock(wfi) > 0)
55 if (wfi->activePeerCount > 0)
57 wf_info_update_changes(wfi);
59 if (wf_info_have_updates(wfi))
61 wf_update_encode(wfi);
65 for (
int peerindex = 0; peerindex < wfi->peerCount; peerindex++)
67 for (; index < FREERDP_SERVER_WIN_INFO_MAXPEERS; index++)
69 if (wfi->peers[index] && wfi->peers[index]->activated)
74 ((wfPeerContext*)wfi->peers[index]->context)->updateEvent);
79 for (
int index = 0; index < wfi->activePeerCount; index++)
83 (void)WaitForSingleObject(wfi->updateSemaphore, 1000);
87 wf_info_clear_invalid_region(wfi);
107 void wf_update_encode(wfInfo* wfi)
111 BYTE* pDataBits = NULL;
114 wf_info_find_invalid_region(wfi);
116 Stream_SetPosition(wfi->s, 0);
117 wf_info_getScreenData(wfi, &width, &height, &pDataBits, &stride);
120 rect.width = (UINT16)width;
121 rect.height = (UINT16)height;
124 Stream_Clear(wfi->s);
126 if (!(rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1, pDataBits, width, height,
132 wfi->frame_idx = rfx_context_get_frame_idx(wfi->rfx_context);
133 cmd->destLeft = wfi->invalid.left;
134 cmd->destTop = wfi->invalid.top;
135 cmd->destRight = wfi->invalid.left + width;
136 cmd->destBottom = wfi->invalid.top + height;
138 cmd->bmp.codecID = 3;
139 cmd->bmp.width = width;
140 cmd->bmp.height = height;
141 cmd->bmp.bitmapDataLength = Stream_GetPosition(wfi->s);
142 cmd->bmp.bitmapData = Stream_Buffer(wfi->s);
145 void wf_update_peer_send(wfInfo* wfi, wfPeerContext* context)
147 freerdp_peer* client;
150 WINPR_ASSERT(context);
152 client = ((rdpContext*)context)->peer;
153 WINPR_ASSERT(client);
157 if (wfi->frame_idx == 1)
158 context->frame_idx = 0;
166 if ((context->frame_idx + 1) != wfi->frame_idx)
169 if (context->frame_idx == 0)
173 WLog_DBG(TAG,
"Unexpected Frame Index: Actual: %d Expected: %d", wfi->frame_idx,
174 context->frame_idx + 1);
177 WINPR_ASSERT(client->context);
178 WINPR_ASSERT(client->context->settings);
179 WINPR_ASSERT(client->context->update);
180 WINPR_ASSERT(client->context->update->SurfaceBits);
182 wfi->cmd.bmp.codecID =
184 client->context->update->SurfaceBits(client->context, &wfi->cmd);
185 context->frame_idx++;
188 void wf_update_encoder_reset(wfInfo* wfi)
190 if (wf_info_lock(wfi) > 0)
192 WLog_DBG(TAG,
"Resetting encoder");
194 if (wfi->rfx_context)
196 rfx_context_reset(wfi->rfx_context, wfi->servscreen_width, wfi->servscreen_height);
201 wfi->rfx_context = rfx_context_new(TRUE);
202 rfx_context_set_mode(wfi->rfx_context, RLGR3);
203 rfx_context_reset(wfi->rfx_context, wfi->servscreen_width, wfi->servscreen_height);
204 rfx_context_set_pixel_format(wfi->rfx_context, PIXEL_FORMAT_BGRA32);
205 wfi->s = Stream_New(NULL, 0xFFFF);
208 wf_info_invalidate_full_screen(wfi);
213 void wf_update_peer_activate(wfInfo* wfi, wfPeerContext* context)
215 if (wf_info_lock(wfi) > 0)
217 if (wfi->activePeerCount < 1)
219 #ifndef WITH_DXGI_1_2
220 wf_mirror_driver_activate(wfi);
222 ResumeThread(wfi->updateThread);
225 wf_update_encoder_reset(wfi);
226 wfi->activePeerCount++;
227 WLog_DBG(TAG,
"Activating Peer Updates: %d", wfi->activePeerCount);
232 void wf_update_peer_deactivate(wfInfo* wfi, wfPeerContext* context)
234 if (wf_info_lock(wfi) > 0)
236 freerdp_peer* client = ((rdpContext*)context)->peer;
238 if (client->activated)
240 if (wfi->activePeerCount <= 1)
242 wf_mirror_driver_deactivate(wfi);
245 client->activated = FALSE;
246 wfi->activePeerCount--;
247 WLog_DBG(TAG,
"Deactivating Peer Updates: %d", wfi->activePeerCount);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.