diff --git a/server/Windows/wf_info.c b/server/Windows/wf_info.c index efc5a1329..e308e8db3 100644 --- a/server/Windows/wf_info.c +++ b/server/Windows/wf_info.c @@ -93,6 +93,9 @@ void wf_info_mirror_init(wfInfo * info, wfPeerContext* context) rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); context->s = stream_new(65536); + + printf("Start Encoder\n"); + ReleaseMutex(info->encodeMutex); } ++info->subscribers; @@ -114,6 +117,8 @@ void wf_info_mirror_init(wfInfo * info, wfPeerContext* context) //in fact i may not even care about subscribers void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context) { + DWORD dRes; + WaitForSingleObject(info->mutex, INFINITE); if (context && (info->subscribers == 1)) { @@ -125,10 +130,47 @@ void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context) stream_free(context->s); rfx_context_free(context->rfx_context); - } + + printf("Stop encoder\n"); + dRes = WaitForSingleObject(info->encodeMutex, INFINITE); + + switch (dRes) + { + // The thread got ownership of the mutex + case WAIT_OBJECT_0: + printf("Thread %d locked encodeMutex...\n", GetCurrentThreadId()); + break; + + // The thread got ownership of an abandoned mutex + // The database is in an indeterminate state + default: + printf("Something else happened!!! dRes = %d\n", dRes); + } + } else { --info->subscribers; } + ReleaseMutex(info->mutex); + + /*************** + Note: if we released the last subscriber, + block the encoder until next subscriber + ***************/ + +} + + +BOOL wf_info_has_subscribers(wfInfo* info) +{ + int subs; + + WaitForSingleObject(info->mutex, INFINITE); + subs = info->subscribers; + ReleaseMutex(info->mutex); + + if(info->subscribers > 0) + return true; + return false; } \ No newline at end of file diff --git a/server/Windows/wf_info.h b/server/Windows/wf_info.h index b149adf5a..a0ebbdcbd 100644 --- a/server/Windows/wf_info.h +++ b/server/Windows/wf_info.h @@ -57,5 +57,7 @@ wfInfo* wf_info_init(wfInfo* info); 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); + #endif \ No newline at end of file diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index b1f0cab6f..52f170239 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -58,6 +58,14 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam) { start = GetTickCount(); + + + if(wf_info_has_subscribers(wfInfoSingleton)) + { + printf("Fake Encode!\n"); + } + + /* dRes = WaitForSingleObject( wfInfoSingleton->mutex, // handle to mutex