\r
extern wfInfo * wfInfoSingleton;\r
\r
-int wf_info_lock(DWORD ms)\r
+static wfInfo* wfInfoInstance = NULL;\r
+\r
+int wf_info_lock(wfInfo* wfi, DWORD ms)\r
{\r
DWORD dRes;\r
\r
- dRes = WaitForSingleObject(wfInfoSingleton->mutex, ms);\r
+ dRes = WaitForSingleObject(wfi->mutex, ms);\r
\r
- switch(dRes)\r
+ switch (dRes)\r
{\r
- case WAIT_ABANDONED:\r
- //complain and proceed as normal\r
- printf("Got ownership of abandoned mutex... resuming...\n");\r
-\r
- case WAIT_OBJECT_0:\r
- break;\r
-\r
- case WAIT_TIMEOUT:\r
- return 1;\r
- break;\r
- case WAIT_FAILED:\r
- printf("WAIT FAILED code %#X\n", GetLastError());\r
- return -1;\r
- break;\r
+ case WAIT_ABANDONED:\r
+ printf("Got ownership of abandoned mutex... resuming...\n");\r
+ break;\r
+\r
+ case WAIT_OBJECT_0:\r
+ break;\r
+\r
+ case WAIT_TIMEOUT:\r
+ return 1;\r
+ break;\r
+\r
+ case WAIT_FAILED:\r
+ printf("WAIT FAILED code %#X\n", GetLastError());\r
+ return -1;\r
+ break;\r
}\r
- \r
+\r
return 0;\r
}\r
\r
-\r
-\r
-int wf_info_unlock()\r
+int wf_info_unlock(wfInfo* wfi)\r
{\r
- if(ReleaseMutex(wfInfoSingleton->mutex) == 0)\r
+ if (ReleaseMutex(wfi->mutex) == 0)\r
return 0;\r
+\r
return 1;\r
}\r
\r
-\r
-wfInfo* wf_info_init(wfInfo * wfi)\r
+wfInfo* wf_info_init(wfInfo* wfi)\r
{\r
if (!wfi)\r
{\r
return wfi;\r
}\r
\r
+wfInfo* wf_info_get_instance()\r
+{\r
+ if (wfInfoInstance == NULL)\r
+ wfInfoInstance = wf_info_init(NULL);\r
+\r
+ return wfInfoInstance;\r
+}\r
+\r
void wf_info_mirror_init(wfInfo* wfi, wfPeerContext* context)\r
{\r
DWORD dRes;\r
\r
dRes = WaitForSingleObject(wfi->mutex, INFINITE);\r
\r
- switch(dRes)\r
+ switch (dRes)\r
{\r
case WAIT_OBJECT_0:\r
\r
{\r
/* only the first peer needs to call this. */\r
\r
- context->wfInfo = wfi;\r
- wf_check_disp_devices(context->wfInfo);\r
- wf_disp_device_set_attatch(context->wfInfo, 1);\r
- wf_update_mirror_drv(context->wfInfo, 0);\r
- wf_map_mirror_mem(context->wfInfo);\r
+ context->info = wfi;\r
+ wf_check_disp_devices(context->info);\r
+ wf_disp_device_set_attatch(context->info, 1);\r
+ wf_update_mirror_drv(context->info, 0);\r
+ wf_map_mirror_mem(context->info);\r
\r
context->rfx_context = rfx_context_new();\r
context->rfx_context->mode = RLGR3;\r
- context->rfx_context->width = context->wfInfo->width;\r
- context->rfx_context->height = context->wfInfo->height;\r
+ context->rfx_context->width = context->info->width;\r
+ context->rfx_context->height = context->info->height;\r
\r
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);\r
context->s = stream_new(65536);\r
\r
- context->wfInfo->roflbuffer = (BYTE*)malloc( (context->wfInfo->width) * (context->wfInfo->height) * 4);\r
+ context->info->roflbuffer = (BYTE*)malloc( (context->info->width) * (context->info->height) * 4);\r
\r
printf("Start Encoder\n");\r
ReleaseMutex(wfi->encodeMutex);\r
case WAIT_OBJECT_0: \r
--wfi->subscribers;\r
/* only the last peer needs to call this */\r
- wf_mirror_cleanup(context->wfInfo);\r
- wf_disp_device_set_attatch(context->wfInfo, 0);\r
- wf_update_mirror_drv(context->wfInfo, 1);\r
+ wf_mirror_cleanup(context->info);\r
+ wf_disp_device_set_attatch(context->info, 0);\r
+ wf_update_mirror_drv(context->info, 1);\r
\r
stream_free(context->s);\r
rfx_context_free(context->rfx_context);\r
\r
- free(context->wfInfo->roflbuffer);\r
+ free(context->info->roflbuffer);\r
break; \r
\r
/**\r
\r
void wf_info_updated(wfInfo* wfi)\r
{\r
-\r
- wfi->lastUpdate = wfi->nextUpdate;\r
- \r
+ wfi->lastUpdate = wfi->nextUpdate; \r
}\r
\r
void wf_info_update_changes(wfInfo* wfi)\r
\r
buf = (GETCHANGESBUF*) wfi->changeBuffer;\r
wfi->nextUpdate = buf->buffer->counter;\r
- \r
}\r
\r
void wf_info_find_invalid_region(wfInfo* wfi)\r
\r
if (wfi->invalid_y2 >= wfi->height)\r
wfi->invalid_y2 = wfi->height - 1;\r
-\r
}\r
\r
void wf_info_clear_invalid_region(wfInfo* wfi)\r
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)\r
{\r
#ifndef WITH_WIN8\r
- wfInfoSingleton = wf_info_init(wfInfoSingleton);\r
- wf_info_mirror_init(wfInfoSingleton, context);\r
+ context->info = wf_info_get_instance();\r
+ wf_info_mirror_init(context->info, context);\r
#endif\r
}\r
\r
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)\r
{\r
#ifndef WITH_WIN8\r
- wf_info_subscriber_release(wfInfoSingleton, context);\r
+ wf_info_subscriber_release(context->info, context);\r
#endif\r
}\r
\r
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)\r
{\r
DWORD fps;\r
+ wfInfo* wfi;\r
DWORD beg, end;\r
DWORD diff, rate;\r
freerdp_peer* client;\r
+ wfPeerContext* context;\r
\r
fps = 24;\r
rate = 1000 / fps;\r
client = (freerdp_peer*) lpParam;\r
+ context = (wfPeerContext*) client->context;\r
+ wfi = context->info;\r
\r
while (1)\r
{\r
beg = GetTickCount();\r
\r
- wf_info_lock(INFINITE);\r
+ wf_info_lock(wfi, INFINITE);\r
\r
- if (wf_info_has_subscribers(wfInfoSingleton))\r
+ if (wf_info_has_subscribers(wfi))\r
{\r
+ wf_info_update_changes(wfi);\r
\r
- wf_info_update_changes(wfInfoSingleton);\r
- if (wf_info_have_updates(wfInfoSingleton))\r
- {\r
+ if (wf_info_have_updates(wfi))\r
wf_rfx_encode(client);\r
- }\r
}\r
else\r
{\r
- wf_info_unlock();\r
+ wf_info_unlock(wfi);\r
}\r
\r
- wf_info_unlock();\r
+ wf_info_unlock(wfi);\r
\r
end = GetTickCount();\r
diff = end - beg;\r
\r
\r
_tprintf(_T("monitor thread terminating...\n"));\r
- wf_info_set_thread_count(wfInfoSingleton, wf_info_get_thread_count(wfInfoSingleton) - 1);\r
+ wf_info_set_thread_count(wfi, wf_info_get_thread_count(wfi) - 1);\r
\r
return 0;\r
}\r
BYTE* dstp;\r
#endif\r
\r
- if(client->activated == FALSE)\r
+ if (client->activated == FALSE)\r
return;\r
+ \r
wfp = (wfPeerContext*) client->context;\r
+ wfi = wfp->info;\r
\r
- dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, INFINITE);\r
+ dRes = WaitForSingleObject(wfi->encodeMutex, INFINITE);\r
\r
switch (dRes)\r
{\r
-\r
case WAIT_ABANDONED:\r
-\r
- printf("\n\nwf_rfx_encode: Got ownership of abandoned mutex... resuming...\n"); \r
- //no break\r
+ printf("\n\nwf_rfx_encode: Got ownership of abandoned mutex... resuming...\n");\r
\r
case WAIT_OBJECT_0:\r
\r
- wf_info_find_invalid_region(wfInfoSingleton);\r
+ wf_info_find_invalid_region(wfi);\r
\r
if( (wfp->activated == false) ||\r
- (wf_info_has_subscribers(wfInfoSingleton) == false) ||\r
- !wf_info_have_invalid_region(wfInfoSingleton) ||\r
- (wfInfoSingleton->enc_data == true) )\r
+ (wf_info_has_subscribers(wfi) == false) ||\r
+ !wf_info_have_invalid_region(wfi) ||\r
+ (wfi->enc_data == true) )\r
{\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ ReleaseMutex(wfi->encodeMutex);\r
break;\r
}\r
\r
update = client->update;\r
cmd = &update->surface_bits_command;\r
- wfi = wfp->wfInfo;\r
buf = (GETCHANGESBUF*) wfi->changeBuffer;\r
\r
width = (wfi->invalid_x2 - wfi->invalid_x1) + 1;\r
cmd->bitmapData = stream_get_head(s);\r
\r
wfi->enc_data = true;\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ ReleaseMutex(wfi->encodeMutex);\r
break;\r
\r
case WAIT_TIMEOUT:\r
\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ ReleaseMutex(wfi->encodeMutex);\r
break;\r
\r
default:\r
\r
void wf_peer_init(freerdp_peer* client)\r
{\r
+ wfInfo* wfi;\r
+\r
client->context_size = sizeof(wfPeerContext);\r
client->ContextNew = (psPeerContextNew) wf_peer_context_new;\r
client->ContextFree = (psPeerContextFree) wf_peer_context_free;\r
+ \r
freerdp_peer_context_new(client);\r
\r
+ wfi = ((wfPeerContext*) client->context)->info;\r
+\r
#ifndef WITH_WIN8\r
- if (!wf_info_get_thread_count(wfInfoSingleton))\r
+ if (!wf_info_get_thread_count(wfi))\r
{\r
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)\r
{\r
- wf_info_set_thread_count(wfInfoSingleton, wf_info_get_thread_count(wfInfoSingleton) + 1);\r
+ wf_info_set_thread_count(wfi, wf_info_get_thread_count(wfi) + 1);\r
}\r
else\r
{\r
\r
boolean wf_peer_post_connect(freerdp_peer* client)\r
{\r
+ wfInfo* wfi;\r
wfPeerContext* context = (wfPeerContext*) client->context;\r
\r
+ wfi = context->info;\r
+\r
/**\r
* This callback is called when the entire connection sequence is done, i.e. we've received the\r
* Font List PDU from the client and sent out the Font Map PDU.\r
printf("Client requested desktop: %dx%dx%d\n",\r
client->settings->width, client->settings->height, client->settings->color_depth);\r
\r
- printf("But we will try resizing to %dx%d\n", wfInfoSingleton->width, wfInfoSingleton->height);\r
+ printf("But we will try resizing to %dx%d\n", wfi->width, wfi->height);\r
\r
- client->settings->width = wfInfoSingleton->width;\r
- client->settings->height = wfInfoSingleton->height;\r
+ client->settings->width = wfi->width;\r
+ client->settings->height = wfi->height;\r
\r
client->update->DesktopResize(client->update->context);\r
\r
\r
}\r
\r
-void wf_peer_send_changes(rdpUpdate* update)\r
+void wf_peer_send_changes(freerdp_peer* client)\r
{\r
int dRes;\r
+ wfInfo* wfi;\r
+ wfPeerContext* context = (wfPeerContext*) client->context;\r
+\r
+ wfi = context->info;\r
\r
/* are we currently encoding? */\r
- dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, 0);\r
+ dRes = WaitForSingleObject(wfi->encodeMutex, 0);\r
\r
switch(dRes)\r
{\r
case WAIT_ABANDONED:\r
\r
printf("\n\nwf_peer_send_changes: Got ownership of abandoned mutex... resuming...\n");\r
- //no break;\r
+ /* no break; */\r
\r
case WAIT_OBJECT_0:\r
\r
/* are there changes to send? */\r
\r
- if ( ((wf_info_lock(0) != 0)) ||\r
- !wf_info_have_updates(wfInfoSingleton) ||\r
- !wf_info_have_invalid_region(wfInfoSingleton) ||\r
- (wfInfoSingleton->enc_data == FALSE))\r
+ if ( ((wf_info_lock(wfi, 0) != 0)) ||\r
+ !wf_info_have_updates(wfi) ||\r
+ !wf_info_have_invalid_region(wfi) ||\r
+ (wfi->enc_data == FALSE))\r
{\r
- //we dont send\r
- wf_info_unlock();\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ /* we do not send */\r
+ wf_info_unlock(wfi);\r
+ ReleaseMutex(wfi->encodeMutex);\r
break;\r
}\r
\r
- wf_info_updated(wfInfoSingleton);\r
+ wf_info_updated(wfi);\r
\r
- update->SurfaceBits(update->context, &update->surface_bits_command);\r
+ client->update->SurfaceBits(client->update->context, &client->update->surface_bits_command);\r
\r
- wfInfoSingleton->enc_data = FALSE;\r
- wf_info_unlock();\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ wfi->enc_data = FALSE;\r
+ wf_info_unlock(wfi);\r
+ ReleaseMutex(wfi->encodeMutex);\r
break;\r
\r
case WAIT_TIMEOUT:\r