* limitations under the License.\r
*/\r
\r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif\r
+\r
#include <stdlib.h>\r
+\r
#include <winpr/tchar.h>\r
#include <winpr/windows.h>\r
\r
\r
wfInfo * wf_info_init(wfInfo * info)\r
{\r
- if(!info)\r
+ if (!info)\r
{\r
- info = (wfInfo*)malloc(sizeof(wfInfo)); //free this on shutdown\r
- memset(info, 0, sizeof(wfInfo));\r
+ info = (wfInfo*) malloc(sizeof(wfInfo));\r
+ ZeroMemory(info, sizeof(wfInfo));\r
\r
- info->mutex = CreateMutex( \r
- NULL, // default security attributes\r
- FALSE, // initially not owned\r
- NULL); // unnamed mutex\r
+ info->mutex = CreateMutex(NULL, FALSE, NULL);\r
\r
if (info->mutex == NULL) \r
{\r
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());\r
}\r
\r
- info->encodeMutex = CreateMutex( \r
- NULL, // default security attributes\r
- FALSE, // initially not owned\r
- NULL); // unnamed mutex\r
+ info->encodeMutex = CreateMutex(NULL, FALSE, NULL);\r
\r
if (info->encodeMutex == NULL) \r
{\r
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());\r
}\r
\r
- info->can_send_mutex = CreateMutex( \r
- NULL, // default security attributes\r
- FALSE, // initially not owned\r
- NULL); // unnamed mutex\r
+ info->can_send_mutex = CreateMutex(NULL, FALSE, NULL);\r
\r
if (info->can_send_mutex == NULL) \r
{\r
{\r
DWORD dRes;\r
\r
-\r
- dRes = WaitForSingleObject( \r
- info->mutex, // handle to mutex\r
- INFINITE); // no time-out interval\r
+ dRes = WaitForSingleObject(info->mutex, INFINITE);\r
\r
switch(dRes)\r
{\r
case WAIT_OBJECT_0:\r
- if(info->subscribers == 0)\r
+\r
+ if (info->subscribers == 0)\r
{\r
- //only the first peer needs to call this.\r
+ /* only the first peer needs to call this. */\r
+\r
context->wfInfo = info;\r
wf_check_disp_devices(context->wfInfo);\r
wf_disp_device_set_attatch(context->wfInfo, 1);\r
}\r
++info->subscribers;\r
\r
- if (! ReleaseMutex(info->mutex)) \r
- { \r
- _tprintf(_T("Error releasing mutex\n"));\r
- } \r
+ if (!ReleaseMutex(info->mutex)) \r
+ {\r
+ _tprintf(_T("Error releasing mutex\n"));\r
+ }\r
\r
break;\r
\r
default:\r
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);\r
+ break;\r
}\r
-\r
}\r
\r
\r
-//todo: i think i can replace all the context->info here with info\r
-//in fact it may not even care about subscribers\r
+/**\r
+ * TODO: i think i can replace all the context->info here with info\r
+ * in fact it may not even care about subscribers\r
+ */\r
+\r
void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context)\r
{\r
DWORD dRes;\r
{\r
\r
dRes = WaitForSingleObject(info->encodeMutex, INFINITE);\r
- switch (dRes) \r
- {\r
- // The thread got ownership of the mutex\r
- case WAIT_OBJECT_0: \r
+\r
+ switch (dRes)\r
+ {\r
+ /* The thread got ownership of the mutex */\r
+ \r
+ case WAIT_OBJECT_0: \r
--info->subscribers;\r
- //only the last peer needs to call this\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
rfx_context_free(context->rfx_context);\r
\r
printf("Stop encoder\n");\r
- break; \r
-\r
- // The thread got ownership of an abandoned mutex\r
- // The database is in an indeterminate state\r
- default: \r
- printf("wf_info_subscriber_release: Something else happened!!! dRes = %d\n", dRes); \r
- }\r
- } \r
+ break; \r
+\r
+ /**\r
+ * The thread got ownership of an abandoned mutex\r
+ * The database is in an indeterminate state\r
+ */\r
+ default: \r
+ printf("wf_info_subscriber_release: Something else happened!!! dRes = %d\n", dRes);\r
+ break;\r
+ }\r
+ } \r
else\r
{\r
--info->subscribers;\r
\r
ReleaseMutex(info->mutex);\r
\r
- /***************\r
- Note: if we released the last subscriber,\r
- block the encoder until next subscriber\r
- ***************/\r
- \r
+ /**\r
+ * Note: if we released the last subscriber,\r
+ * block the encoder until next subscriber\r
+ */ \r
}\r
\r
-\r
BOOL wf_info_has_subscribers(wfInfo* info)\r
{\r
int subs;\r
\r
- WaitForSingleObject(info->mutex, INFINITE); \r
+ WaitForSingleObject(info->mutex, INFINITE);\r
+\r
subs = info->subscribers;\r
ReleaseMutex(info->mutex);\r
\r
- if(info->subscribers > 0)\r
- return true;\r
- return false;\r
+ if (info->subscribers > 0)\r
+ return TRUE;\r
+\r
+ return FALSE;\r
}\r
\r
\r
BOOL wf_info_have_updates(wfInfo* info)\r
{\r
- BOOL ret;\r
- ret = true;\r
+ BOOL status = TRUE;\r
+\r
WaitForSingleObject(info->mutex, INFINITE); \r
- if(info->nextUpdate == info->lastUpdate)\r
- ret = false;\r
+ \r
+ if (info->nextUpdate == info->lastUpdate)\r
+ status = FALSE;\r
+ \r
ReleaseMutex(info->mutex);\r
\r
- return ret;\r
+ return status;\r
}\r
\r
-\r
void wf_info_updated(wfInfo* info)\r
{\r
-\r
WaitForSingleObject(info->mutex, INFINITE); \r
info->lastUpdate = info->nextUpdate;\r
ReleaseMutex(info->mutex);\r
WaitForSingleObject(info->mutex, INFINITE); \r
buf = (GETCHANGESBUF*)info->changeBuffer;\r
\r
- if(info->enc_data == false)\r
+ if (info->enc_data == FALSE)\r
{\r
- info->invalid_x1 = 1920;//info->width;\r
+ info->invalid_x1 = 1920;\r
info->invalid_x2 = 0;\r
- info->invalid_y1 = 1200;// info->height;\r
+ info->invalid_y1 = 1200;\r
info->invalid_y2 = 0;\r
}\r
\r
- //printf("\tFIND = (%d, %d), (%d, %d)\n", info->invalid_x1, info->invalid_y1, info->invalid_x2, info->invalid_y2);\r
- for(i = info->lastUpdate; i != info->nextUpdate; i = (i+1) % MAXCHANGES_BUF )\r
+ for (i = info->lastUpdate; i != info->nextUpdate; i = (i+1) % MAXCHANGES_BUF )\r
{\r
- /*printf("\t(%d, %d), (%d, %d)\n", \r
- buf->buffer->pointrect[i].rect.left,\r
- buf->buffer->pointrect[i].rect.top,\r
- buf->buffer->pointrect[i].rect.right,\r
- buf->buffer->pointrect[i].rect.bottom);\r
- */\r
info->invalid_x1 = min(info->invalid_x1, buf->buffer->pointrect[i].rect.left);\r
info->invalid_x2 = max(info->invalid_x2, buf->buffer->pointrect[i].rect.right);\r
info->invalid_y1 = min(info->invalid_y1, buf->buffer->pointrect[i].rect.top);\r
info->invalid_y2 = max(info->invalid_y2, buf->buffer->pointrect[i].rect.bottom);\r
}\r
+\r
ReleaseMutex(info->mutex);\r
}\r
\r
-\r
void wf_info_clear_invalid_region(wfInfo* info)\r
{\r
- \r
WaitForSingleObject(info->mutex, INFINITE); \r
info->lastUpdate = info->nextUpdate;\r
info->invalid_x1 = info->width;\r
\r
BOOL wf_info_have_invalid_region(wfInfo* info)\r
{\r
- if((info->invalid_x1 >= info->invalid_x2) || (info->invalid_y1 >= info->invalid_y2))\r
- return false;\r
- return true;\r
+ if ((info->invalid_x1 >= info->invalid_x2) || (info->invalid_y1 >= info->invalid_y2))\r
+ return FALSE;\r
+\r
+ return TRUE;\r
}\r
\r
int wf_info_get_height(wfInfo* info)\r
{\r
- int ret;\r
+ int height;\r
\r
WaitForSingleObject(info->mutex, INFINITE); \r
- ret = info->height;\r
+ height = info->height;\r
ReleaseMutex(info->mutex);\r
\r
- return ret;\r
+ return height;\r
}\r
\r
int wf_info_get_width(wfInfo* info)\r
{\r
- int ret;\r
+ int width;\r
\r
WaitForSingleObject(info->mutex, INFINITE); \r
- ret = info->width;\r
+ width = info->width;\r
ReleaseMutex(info->mutex);\r
\r
- return ret;\r
+ return width;\r
}\r
\r
int wf_info_get_thread_count(wfInfo* info)\r
{\r
- int ret;\r
+ int count;\r
+ \r
WaitForSingleObject(info->mutex, INFINITE); \r
- ret = info->threadCnt;\r
+ count = info->threadCnt;\r
ReleaseMutex(info->mutex);\r
- return ret;\r
+ \r
+ return count;\r
}\r
\r
-\r
void wf_info_set_thread_count(wfInfo* info, int count)\r
{\r
-\r
WaitForSingleObject(info->mutex, INFINITE); \r
info->threadCnt = count;\r
ReleaseMutex(info->mutex);\r
*/\r
BOOL wf_update_mirror_drv(wfInfo* context, int unload)\r
{\r
- int currentScreenPixHeight, currentScreenPixWidth, currentScreenBPP;\r
HDC dc;\r
- LONG status;\r
+ BOOL status;\r
DWORD* extHdr;\r
+ TCHAR rMsg[64];\r
WORD drvExtraSaved;\r
DEVMODE* deviceMode;\r
+ int currentScreenBPP;\r
+ int currentScreenPixHeight;\r
+ int currentScreenPixWidth;\r
+ LONG disp_change_status;\r
DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE;\r
- TCHAR rMsg[64];\r
- BOOL rturn;\r
\r
- if(!unload)\r
+ if (!unload)\r
{\r
/*\r
- Will have to come back to this for supporting non primary displays and \r
- multimonitor setups\r
- */\r
+ * Will have to come back to this for supporting non primary displays and multimonitor setups\r
+ */\r
dc = GetDC(NULL);\r
currentScreenPixHeight = GetDeviceCaps(dc, VERTRES);\r
currentScreenPixWidth = GetDeviceCaps(dc, HORZRES);\r
\r
_tcsncpy_s(deviceMode->dmDeviceName, 32, context->deviceName, _tcslen(context->deviceName));\r
\r
- status = ChangeDisplaySettingsEx(context->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL);\r
+ disp_change_status = ChangeDisplaySettingsEx(context->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL);\r
+\r
+ status = FALSE;\r
\r
- rturn = false;\r
- switch (status)\r
+ switch (disp_change_status)\r
{\r
case DISP_CHANGE_SUCCESSFUL:\r
_tprintf(_T("ChangeDisplaySettingsEx() was successfull\n"));\r
- rturn = true;\r
+ status = true;\r
break;\r
\r
case DISP_CHANGE_BADDUALVIEW:\r
break;\r
}\r
\r
- if(!rturn)\r
- _tprintf(_T("ChangeDisplaySettingsEx() failed with %s, code %d\n"), rMsg, status);\r
+ if (!status)\r
+ _tprintf(_T("ChangeDisplaySettingsEx() failed with %s, code %d\n"), rMsg, disp_change_status);\r
\r
- return rturn;\r
+ return status;\r
}\r
\r
\r
if (context->driverDC == NULL)\r
{\r
_tprintf(_T("Could not create device driver context!\n"));\r
- return false;\r
+ return FALSE;\r
}\r
\r
context->changeBuffer = malloc(sizeof(GETCHANGESBUF));\r
b = (GETCHANGESBUF*)context->changeBuffer;\r
_tprintf(_T("ExtEscape() returned code %d\n"), status);\r
\r
- return true;\r
+ return TRUE;\r
}\r
\r
/*\r
_tprintf(_T("\n\nCleaning up...\nDisconnecting driver...\n"));\r
iResult = ExtEscape(context->driverDC, dmf_esc_usm_pipe_unmap, sizeof(context->changeBuffer), (LPSTR) context->changeBuffer, 0, 0);\r
\r
- if(iResult <= 0)\r
+ if (iResult <= 0)\r
{\r
_tprintf(_T("Failed to unmap shared memory from the driver! Code %d\n"), iResult);\r
}\r
\r
_tprintf(_T("Releasing DC\n"));\r
- if(context->driverDC != NULL)\r
+\r
+ if (context->driverDC != NULL)\r
{\r
iResult = DeleteDC(context->driverDC);\r
if(iResult == 0)\r
free(context->changeBuffer);\r
\r
return true;\r
-}
\ No newline at end of file
+}\r
\r
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)\r
{\r
- DWORD start, end, diff;\r
+ DWORD start;\r
+ DWORD end;\r
+ DWORD diff;\r
DWORD rate;\r
- \r
freerdp_peer* client;\r
\r
rate = 42;\r
client = (freerdp_peer*)lpParam;\r
\r
- //todo: make sure we dont encode after no clients\r
+ /* TODO: do not encode when no clients are connected */\r
+\r
while(1)\r
{\r
\r
start = GetTickCount();\r
\r
-\r
- if(wf_info_has_subscribers(wfInfoSingleton))\r
+ if (wf_info_has_subscribers(wfInfoSingleton))\r
{\r
wf_info_update_changes(wfInfoSingleton);\r
- if(wf_info_have_updates(wfInfoSingleton))\r
+\r
+ if (wf_info_have_updates(wfInfoSingleton))\r
{\r
- //wf_info_find_invalid_region(wfInfoSingleton);\r
- //printf("Fake Encode!\n");\r
wf_rfx_encode(client);\r
} \r
}\r
\r
end = GetTickCount();\r
diff = end - start;\r
- if(diff < rate)\r
+\r
+ if (diff < rate)\r
{\r
- //printf("sleeping for %d ms...\n", rate - diff);\r
Sleep(rate - diff);\r
}\r
\r
\r
_tprintf(_T("monitor thread terminating...\n"));\r
wf_info_set_thread_count(wfInfoSingleton, wf_info_get_thread_count(wfInfoSingleton) - 1 );\r
+\r
return 0;\r
}\r
\r
dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, INFINITE);\r
switch(dRes)\r
{\r
- case WAIT_OBJECT_0:\r
+ case WAIT_OBJECT_0:\r
\r
- wf_info_find_invalid_region(wfInfoSingleton);\r
+ wf_info_find_invalid_region(wfInfoSingleton);\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
- {\r
- ReleaseMutex(wfInfoSingleton->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
+ if( (wfp->activated == false) ||\r
+ (wf_info_has_subscribers(wfInfoSingleton) == false) ||\r
+ !wf_info_have_invalid_region(wfInfoSingleton) ||\r
+ (wfInfoSingleton->enc_data == true) )\r
+ {\r
+ ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ break;\r
+ }\r
\r
- //printf("encode %d\n", wfi->nextUpdate - wfi->lastUpdate);\r
- //printf("\tinvlaid region = (%d, %d), (%d, %d)\n", wfi->invalid_x1, wfi->invalid_y1, wfi->invalid_x2, wfi->invalid_y2);\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;\r
- height = wfi->invalid_y2 - wfi->invalid_y1;\r
+ width = wfi->invalid_x2 - wfi->invalid_x1;\r
+ height = wfi->invalid_y2 - wfi->invalid_y1;\r
\r
- stream_clear(wfp->s);\r
- stream_set_pos(wfp->s, 0);\r
- s = wfp->s;\r
+ stream_clear(wfp->s);\r
+ stream_set_pos(wfp->s, 0);\r
+ s = wfp->s;\r
\r
- rect.x = 0;\r
- rect.y = 0;\r
- rect.width = (uint16) width;\r
- rect.height = (uint16) height;\r
+ rect.x = 0;\r
+ rect.y = 0;\r
+ rect.width = (uint16) width;\r
+ rect.height = (uint16) height;\r
\r
- offset = (4 * wfi->invalid_x1) + (wfi->invalid_y1 * wfi->width * 4);\r
+ offset = (4 * wfi->invalid_x1) + (wfi->invalid_y1 * wfi->width * 4);\r
\r
- //printf("width = %d, height = %d\n", width, height);\r
- rfx_compose_message(wfp->rfx_context, s, &rect, 1,\r
- ((uint8*) (buf->Userbuffer)) + offset, width, height, wfi->width * 4);\r
+ rfx_compose_message(wfp->rfx_context, s, &rect, 1,\r
+ ((uint8*) (buf->Userbuffer)) + offset, width, height, wfi->width * 4);\r
\r
- cmd->destLeft = wfi->invalid_x1;\r
- cmd->destTop = wfi->invalid_y1;\r
- cmd->destRight = wfi->invalid_x1 + width;\r
- cmd->destBottom = wfi->invalid_y1 + height;\r
+ cmd->destLeft = wfi->invalid_x1;\r
+ cmd->destTop = wfi->invalid_y1;\r
+ cmd->destRight = wfi->invalid_x1 + width;\r
+ cmd->destBottom = wfi->invalid_y1 + height;\r
\r
+ cmd->bpp = 32;\r
+ cmd->codecID = client->settings->rfx_codec_id;\r
+ cmd->width = width;\r
+ cmd->height = height;\r
+ cmd->bitmapDataLength = stream_get_length(s);\r
+ cmd->bitmapData = stream_get_head(s);\r
\r
- cmd->bpp = 32;\r
- cmd->codecID = client->settings->rfx_codec_id;\r
- cmd->width = width;\r
- cmd->height = height;\r
- cmd->bitmapDataLength = stream_get_length(s);\r
- cmd->bitmapData = stream_get_head(s);\r
+ wfi->enc_data = true;\r
+ ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ break;\r
\r
- wfi->enc_data = true;\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
- break;\r
+ case WAIT_TIMEOUT:\r
\r
- case WAIT_TIMEOUT:\r
+ ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ break;\r
\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
- break;\r
+ case WAIT_ABANDONED:\r
\r
- case WAIT_ABANDONED:\r
+ printf("\n\nwf_rfx_encode: Got ownership of abandoned mutex... releasing...\n", dRes);\r
+ ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ break;\r
\r
- printf("\n\nwf_rfx_encode: Got ownership of abandoned mutex... releasing...\n", dRes);\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
- break;\r
- default: \r
- printf("\n\nwf_rfx_encode: Something else happened!!! dRes = %d\n", dRes);\r
+ default:\r
+ printf("\n\nwf_rfx_encode: Something else happened!!! dRes = %d\n", dRes);\r
+ break;\r
}\r
\r
}\r
\r
printf("But we will try resizing to %dx%d\n",\r
wf_info_get_width(wfInfoSingleton),\r
- wf_info_get_height(wfInfoSingleton)\r
- );\r
+ wf_info_get_height(wfInfoSingleton));\r
\r
client->settings->width = wf_info_get_width(wfInfoSingleton);\r
client->settings->height = wf_info_get_height(wfInfoSingleton);\r
{\r
int dRes;\r
\r
- //are we currently encoding?\r
+ /* are we currently encoding? */\r
dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, 0);\r
+\r
switch(dRes)\r
{\r
- case WAIT_OBJECT_0:\r
- //are there changes to send?\r
- if( !wf_info_have_updates(wfInfoSingleton) || !wf_info_have_invalid_region(wfInfoSingleton) || (wfInfoSingleton->enc_data == false) )\r
- {\r
+ case WAIT_OBJECT_0:\r
+\r
+ /* are there changes to send? */\r
+ if (!wf_info_have_updates(wfInfoSingleton) ||\r
+ !wf_info_have_invalid_region(wfInfoSingleton) ||\r
+ (wfInfoSingleton->enc_data == FALSE))\r
+ {\r
+ ReleaseMutex(wfInfoSingleton->encodeMutex);\r
+ break;\r
+ }\r
+\r
+ wf_info_updated(wfInfoSingleton);\r
+\r
+ update->SurfaceBits(update->context, &update->surface_bits_command);\r
+\r
+ wfInfoSingleton->enc_data = FALSE;\r
ReleaseMutex(wfInfoSingleton->encodeMutex);\r
break;\r
- }\r
- \r
-\r
- wf_info_updated(wfInfoSingleton);\r
- /*\r
- printf("\tSend...");\r
- printf("\t(%d, %d), (%d, %d) [%dx%d]\n",\r
- update->surface_bits_command.destLeft, update->surface_bits_command.destTop,\r
- update->surface_bits_command.destRight, update->surface_bits_command.destBottom,\r
- update->surface_bits_command.width, update->surface_bits_command.height);\r
- */\r
- update->SurfaceBits(update->context, &update->surface_bits_command);\r
- //wf_info_clear_invalid_region(wfInfoSingleton);\r
- wfInfoSingleton->enc_data = false;\r
- ReleaseMutex(wfInfoSingleton->encodeMutex);\r
- break;\r
-\r
- case WAIT_TIMEOUT:\r
- break;\r
-\r
-\r
- default: \r
- printf("wf_peer_send_changes: Something else happened!!! dRes = %d\n", dRes);\r
- }\r
\r
- \r
+ case WAIT_TIMEOUT:\r
+ break;\r
+\r
+ default:\r
+ printf("wf_peer_send_changes: Something else happened!!! dRes = %d\n", dRes);\r
+ break;\r
+ }\r
}\r