diff --git a/server/Windows/wf_info.c b/server/Windows/wf_info.c index e308e8db3..bfde742c2 100644 --- a/server/Windows/wf_info.c +++ b/server/Windows/wf_info.c @@ -173,4 +173,56 @@ BOOL wf_info_has_subscribers(wfInfo* info) if(info->subscribers > 0) return true; return false; -} \ No newline at end of file +} + + +BOOL wf_info_have_updates(wfInfo* info) +{ + BOOL ret; + ret = true; + WaitForSingleObject(info->mutex, INFINITE); + if(info->nextUpdate == info->lastUpdate) + ret = false; + ReleaseMutex(info->mutex); + + return ret; +} + + +void wf_info_updated(wfInfo* info) +{ + + WaitForSingleObject(info->mutex, INFINITE); + info->lastUpdate = info->nextUpdate; + ReleaseMutex(info->mutex); +} + + +void wf_info_update_changes(wfInfo* info) +{ + GETCHANGESBUF* buf; + + WaitForSingleObject(info->mutex, INFINITE); + buf = (GETCHANGESBUF*)info->changeBuffer; + info->nextUpdate = buf->buffer->counter; + ReleaseMutex(info->mutex); +} + + +void wf_info_find_invalid_region(wfInfo* info) +{ + int i; + GETCHANGESBUF* buf; + + WaitForSingleObject(info->mutex, INFINITE); + buf = (GETCHANGESBUF*)info->changeBuffer; + for(i = info->lastUpdate; i <= info->nextUpdate; ++i) + { + info->invalid_x1 = min(info->invalid_x1, buf->buffer->pointrect[i].rect.left); + info->invalid_x2 = max(info->invalid_x2, buf->buffer->pointrect[i].rect.right); + info->invalid_y1 = min(info->invalid_y1, buf->buffer->pointrect[i].rect.top); + info->invalid_y2 = max(info->invalid_y2, buf->buffer->pointrect[i].rect.bottom); + } + ReleaseMutex(info->mutex); +} + diff --git a/server/Windows/wf_info.h b/server/Windows/wf_info.h index a0ebbdcbd..072b96363 100644 --- a/server/Windows/wf_info.h +++ b/server/Windows/wf_info.h @@ -58,6 +58,10 @@ void wf_info_mirror_init(wfInfo* info, wfPeerContext* context); void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context); BOOL wf_info_has_subscribers(wfInfo* info); +BOOL wf_info_have_updates(wfInfo* info); +void wf_info_updated(wfInfo* info); +void wf_info_update_changes(wfInfo* info); +void wf_info_find_invalid_region(wfInfo* info); #endif \ No newline at end of file diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 52f170239..7097c9c1d 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -46,13 +46,13 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) DWORD dRes; DWORD start, end, diff; DWORD rate; - GETCHANGESBUF* buf; + freerdp_peer* client; unsigned long i; rate = 1000; client = (freerdp_peer*)lpParam; - buf = (GETCHANGESBUF*)wfInfoSingleton->changeBuffer; + //todo: make sure we dont encode after no clients while(1) { @@ -62,7 +62,12 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) if(wf_info_has_subscribers(wfInfoSingleton)) { - printf("Fake Encode!\n"); + wf_info_update_changes(wfInfoSingleton); + if(wf_info_have_updates(wfInfoSingleton)) + { + wf_info_find_invalid_region(wfInfoSingleton); + printf("Fake Encode!\n"); + } } @@ -75,7 +80,7 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) case WAIT_OBJECT_0: if(wfInfoSingleton->subscribers > 0) { - wfInfoSingleton->nextUpdate = buf->buffer->counter; + wfInfoSingleton->nextUpdate = buf->buffer->counter; ///////////////////////////// //_tprintf(_T("Count = %lu\n"), wfInfoSingleton->nextUpdate); @@ -87,7 +92,7 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) wfInfoSingleton->invalid_x2 = max(wfInfoSingleton->invalid_x2, buf->buffer->pointrect[i].rect.right); wfInfoSingleton->invalid_y1 = min(wfInfoSingleton->invalid_y1, buf->buffer->pointrect[i].rect.top); wfInfoSingleton->invalid_y2 = max(wfInfoSingleton->invalid_y2, buf->buffer->pointrect[i].rect.bottom); - } + }/////////////////////////////// wf_rfx_encode(client); } @@ -340,7 +345,24 @@ void wf_peer_synchronize_event(rdpInput* input, uint32 flags) void wf_peer_send_changes() { - //get can_send_mutex + int dRes; + + //are we currently encoding? + dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, INFINITE); + switch(dRes) + { + case WAIT_OBJECT_0: + //are there changes to send? + if(!wf_info_have_updates(wfInfoSingleton)) + return; + + wf_info_updated(wfInfoSingleton); + printf("\tSend...\n"); + + break; + + default: + printf("Something else happened!!! dRes = %d\n", dRes); + } - printf("sending\n"); }