This commit is contained in:
C-o-r-E 2012-08-18 14:34:24 -04:00
parent 39c2e93562
commit c077eb4dc7
7 changed files with 271 additions and 153 deletions

View File

@ -1,33 +1,35 @@
# FreeRDP: A Remote Desktop Protocol Client
# FreeRDP Windows Server cmake build script
#
# Copyright 2011 O.S. Systems Software Ltda.
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_executable(wfreerdp-server
wf_input.c
wf_input.h
wf_mirage.c
wf_mirage.h
wf_peer.c
wf_peer.h
wfreerdp.c
wfreerdp.h)
target_link_libraries(wfreerdp-server freerdp-core)
target_link_libraries(wfreerdp-server freerdp-utils)
target_link_libraries(wfreerdp-server freerdp-codec)
target_link_libraries(wfreerdp-server freerdp-channels)
# FreeRDP: A Remote Desktop Protocol Client
# FreeRDP Windows Server cmake build script
#
# Copyright 2011 O.S. Systems Software Ltda.
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_executable(wfreerdp-server
wf_input.c
wf_input.h
wf_mirage.c
wf_mirage.h
wf_peer.c
wf_peer.h
wf_info.c
wf_info.h
wfreerdp.c
wfreerdp.h)
target_link_libraries(wfreerdp-server freerdp-core)
target_link_libraries(wfreerdp-server freerdp-utils)
target_link_libraries(wfreerdp-server freerdp-codec)
target_link_libraries(wfreerdp-server freerdp-channels)

134
server/Windows/wf_info.c Normal file
View File

@ -0,0 +1,134 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include "wf_info.h"
#include "wf_mirage.h"
wfInfo * wf_info_init(wfInfo * info)
{
if(!info)
{
info = (wfInfo*)malloc(sizeof(wfInfo)); //free this on shutdown
memset(info, 0, sizeof(wfInfo));
info->mutex = CreateMutex(
NULL, // default security attributes
FALSE, // initially not owned
NULL); // unnamed mutex
if (info->mutex == NULL)
{
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
info->encodeMutex = CreateMutex(
NULL, // default security attributes
FALSE, // initially not owned
NULL); // unnamed mutex
if (info->encodeMutex == NULL)
{
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
info->can_send_mutex = CreateMutex(
NULL, // default security attributes
FALSE, // initially not owned
NULL); // unnamed mutex
if (info->can_send_mutex == NULL)
{
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
}
return info;
}
void wf_info_mirror_init(wfInfo * info, wfPeerContext* context)
{
DWORD dRes;
dRes = WaitForSingleObject(
info->mutex, // handle to mutex
INFINITE); // no time-out interval
switch(dRes)
{
case WAIT_OBJECT_0:
if(info->subscribers == 0)
{
//only the first peer needs to call this.
context->wfInfo = info;
wf_check_disp_devices(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 1);
wf_update_mirror_drv(context->wfInfo, 0);
wf_map_mirror_mem(context->wfInfo);
context->rfx_context = rfx_context_new();
context->rfx_context->mode = RLGR3;
context->rfx_context->width = context->wfInfo->width;
context->rfx_context->height = context->wfInfo->height;
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = stream_new(65536);
}
++info->subscribers;
if (! ReleaseMutex(info->mutex))
{
_tprintf(_T("Error releasing mutex\n"));
}
break;
default:
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);
}
}
//todo: i think i can replace all the context->info here with info
//in fact i may not even care about subscribers
void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context)
{
WaitForSingleObject(info->mutex, INFINITE);
if (context && (info->subscribers == 1))
{
--info->subscribers;
//only the last peer needs to call this
wf_mirror_cleanup(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 0);
wf_update_mirror_drv(context->wfInfo, 1);
stream_free(context->s);
rfx_context_free(context->rfx_context);
}
else
{
--info->subscribers;
}
ReleaseMutex(info->mutex);
}

61
server/Windows/wf_info.h Normal file
View File

@ -0,0 +1,61 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server
*
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WF_INFO_H
#define WF_INFO_H
//#include "wfreerdp.h"
struct wf_peer_context;
typedef struct wf_peer_context wfPeerContext;
struct wf_info
{
HDC driverDC;
BOOL activated;
void* changeBuffer;
LPTSTR deviceKey;
TCHAR deviceName[32];
int subscribers;
int threadCnt;
int height;
int width;
int bitsPerPix;
HANDLE mutex, encodeMutex, can_send_mutex;
unsigned long lastUpdate;
unsigned long nextUpdate;
long invalid_x1;
long invalid_y1;
long invalid_x2;
long invalid_y2;
};
typedef struct wf_info wfInfo;
wfInfo* wf_info_init(wfInfo* info);
void wf_info_mirror_init(wfInfo* info, wfPeerContext* context);
void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context);
#endif

View File

@ -31,108 +31,34 @@
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
DWORD dRes;
if(!wfInfoSingleton)
{
wfInfoSingleton = (wfInfo*)malloc(sizeof(wfInfo)); //free this on shutdown
memset(wfInfoSingleton, 0, sizeof(wfInfo));
wfInfoSingleton->mutex = CreateMutex(
NULL, // default security attributes
FALSE, // initially not owned
NULL); // unnamed mutex
if (wfInfoSingleton->mutex == NULL)
{
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
wfInfoSingleton->encodeMutex = CreateMutex(
NULL, // default security attributes
FALSE, // initially not owned
NULL); // unnamed mutex
if (wfInfoSingleton->encodeMutex == NULL)
{
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
}
dRes = WaitForSingleObject(
wfInfoSingleton->mutex, // handle to mutex
INFINITE); // no time-out interval
switch(dRes)
{
case WAIT_OBJECT_0:
if(wfInfoSingleton->subscribers == 0)
{
//only the first peer needs to call this.
context->wfInfo = wfInfoSingleton;
wf_check_disp_devices(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 1);
wf_update_mirror_drv(context->wfInfo, 0);
wf_map_mirror_mem(context->wfInfo);
context->rfx_context = rfx_context_new();
context->rfx_context->mode = RLGR3;
context->rfx_context->width = context->wfInfo->width;
context->rfx_context->height = context->wfInfo->height;
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = stream_new(65536);
}
++wfInfoSingleton->subscribers;
if (! ReleaseMutex(wfInfoSingleton->mutex))
{
_tprintf(_T("Error releasing mutex\n"));
}
break;
default:
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);
}
DWORD dRes;
wfInfoSingleton = wf_info_init(wfInfoSingleton);
wf_info_mirror_init(wfInfoSingleton, context);
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
if (context && (wfInfoSingleton->subscribers == 1))
{
--wfInfoSingleton->subscribers;
//only the last peer needs to call this
wf_mirror_cleanup(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 0);
wf_update_mirror_drv(context->wfInfo, 1);
stream_free(context->s);
rfx_context_free(context->rfx_context);
}
else
{
--wfInfoSingleton->subscribers;
}
{
wf_info_subscriber_release(wfInfoSingleton, context);
}
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
{
DWORD dRes;
DWORD start, end, diff;
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)
{
start = GetTickCount();
start = GetTickCount();
/*
dRes = WaitForSingleObject(
wfInfoSingleton->mutex, // handle to mutex
INFINITE); // no time-out interval
@ -168,12 +94,14 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
default:
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);
}
*/
end = GetTickCount();
diff = end - start;
if(diff < 42)
diff = end - start;
if(diff < rate)
{
Sleep(42 - diff);
printf("sleeping for %d ms...\n", rate - diff);
Sleep(rate - diff);
}
@ -271,9 +199,11 @@ void wf_rfx_encode(freerdp_peer* client)
/*
printf("encode %d\n", wfi->nextUpdate - wfi->lastUpdate);
printf("\tinvlaid region = (%d, %d), (%d, %d)\n", wfi->invalid_x1, wfi->invalid_y1, wfi->invalid_x2, wfi->invalid_y2);
wfi->lastUpdate = wfi->nextUpdate;
printf("\tinvlaid region = (%d, %d), (%d, %d)\n", wfi->invalid_x1, wfi->invalid_y1, wfi->invalid_x2, wfi->invalid_y2);
*/
wfi->lastUpdate = wfi->nextUpdate;
if ( (wfi->invalid_x1 >= wfi->invalid_x2) ||
(wfi->invalid_y1 >= wfi->invalid_y2) )
return;
@ -320,6 +250,10 @@ void wf_peer_init(freerdp_peer* client)
_tprintf(_T("Trying to create a monitor thread...\n"));
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
_tprintf(_T("Created!\n"));
/*
if(wfInfoSingleton)
{
dRes = WaitForSingleObject(
@ -346,9 +280,9 @@ void wf_peer_init(freerdp_peer* client)
default:
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);
}
}
*/
}
@ -395,3 +329,10 @@ void wf_peer_synchronize_event(rdpInput* input, uint32 flags)
{
}
void wf_peer_send_changes()
{
//get can_send_mutex
printf("sending\n");
}

View File

@ -21,6 +21,7 @@
#define WF_PEER_H
#include "wfreerdp.h"
#include "wf_info.h"
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context);
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context);
@ -35,6 +36,8 @@ boolean wf_peer_activate(freerdp_peer* client);
void wf_peer_synchronize_event(rdpInput* input, uint32 flags);
void wf_peer_send_changes();
wfInfo * wfInfoSingleton;
#endif /* WF_PEER_H */

View File

@ -42,6 +42,8 @@ int g_thread_count = 0;
//extern wfInfo * wfInfoSingleton;
BOOL derp = false;
static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{
int dRes;
@ -88,6 +90,7 @@ static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
break;
}
/*
if(wfInfoSingleton)
{
//wf_peer_rfx_update(client, 0, 0, wfInfoSingleton->width, wfInfoSingleton->height);
@ -128,6 +131,7 @@ static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
_tprintf(_T("Error waiting for mutex: %d\n"), dRes);
}
}
*/
}
printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname);

View File

@ -22,34 +22,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/codec/rfx.h>
struct wf_info
{
HDC driverDC;
boolean activated;
void* changeBuffer;
LPTSTR deviceKey;
TCHAR deviceName[32];
int subscribers;
int threadCnt;
int height;
int width;
int bitsPerPix;
HANDLE mutex, encodeMutex;
unsigned long lastUpdate;
unsigned long nextUpdate;
long invalid_x1;
long invalid_y1;
long invalid_x2;
long invalid_y2;
};
typedef struct wf_info wfInfo;
#include "wf_info.h"
struct wf_peer_context
{