2012-08-14 23:12:44 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* FreeRDP Windows Server
|
|
|
|
*
|
|
|
|
* Copyright 2012 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.
|
|
|
|
*/
|
2012-08-23 23:36:34 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-15 00:49:24 +04:00
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/windows.h>
|
2012-08-23 23:36:34 +04:00
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
#include <freerdp/listener.h>
|
2012-08-15 00:49:24 +04:00
|
|
|
#include <freerdp/utils/sleep.h>
|
2012-08-16 02:01:06 +04:00
|
|
|
#include <freerdp/codec/rfx.h>
|
|
|
|
#include <freerdp/utils/stream.h>
|
2012-08-14 23:12:44 +04:00
|
|
|
|
2012-09-03 07:36:01 +04:00
|
|
|
#include "wf_input.h"
|
2012-08-14 23:12:44 +04:00
|
|
|
#include "wf_mirage.h"
|
|
|
|
|
|
|
|
#include "wf_peer.h"
|
|
|
|
|
|
|
|
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
|
|
|
|
{
|
2012-08-31 01:37:12 +04:00
|
|
|
#ifndef WITH_WIN8
|
2012-09-03 01:09:36 +04:00
|
|
|
context->info = wf_info_get_instance();
|
|
|
|
wf_info_mirror_init(context->info, context);
|
2012-08-31 01:37:12 +04:00
|
|
|
#endif
|
2012-08-14 23:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
|
2012-08-23 23:36:34 +04:00
|
|
|
{
|
2012-08-31 01:37:12 +04:00
|
|
|
#ifndef WITH_WIN8
|
2012-09-03 01:09:36 +04:00
|
|
|
wf_info_subscriber_release(context->info, context);
|
2012-08-31 01:37:12 +04:00
|
|
|
#endif
|
2012-08-15 00:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
|
|
|
|
{
|
2012-08-24 01:37:28 +04:00
|
|
|
DWORD fps;
|
2012-09-03 01:09:36 +04:00
|
|
|
wfInfo* wfi;
|
2012-08-24 01:10:22 +04:00
|
|
|
DWORD beg, end;
|
|
|
|
DWORD diff, rate;
|
2012-08-16 02:01:06 +04:00
|
|
|
freerdp_peer* client;
|
2012-09-03 01:09:36 +04:00
|
|
|
wfPeerContext* context;
|
2012-08-15 23:27:03 +04:00
|
|
|
|
2012-08-29 03:28:04 +04:00
|
|
|
fps = 24;
|
2012-08-24 01:37:28 +04:00
|
|
|
rate = 1000 / fps;
|
2012-08-24 01:10:22 +04:00
|
|
|
client = (freerdp_peer*) lpParam;
|
2012-09-03 01:09:36 +04:00
|
|
|
context = (wfPeerContext*) client->context;
|
|
|
|
wfi = context->info;
|
2012-08-19 01:49:52 +04:00
|
|
|
|
2012-08-30 23:50:46 +04:00
|
|
|
while (1)
|
2012-08-15 00:49:24 +04:00
|
|
|
{
|
2012-08-24 01:10:22 +04:00
|
|
|
beg = GetTickCount();
|
2012-08-15 23:27:03 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wf_info_lock(wfi) > 0)
|
2012-08-23 23:36:34 +04:00
|
|
|
{
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wf_info_has_subscribers(wfi))
|
|
|
|
{
|
|
|
|
wf_info_update_changes(wfi);
|
2012-08-24 00:35:54 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wf_info_have_updates(wfi))
|
|
|
|
{
|
|
|
|
wf_rfx_encode(client);
|
|
|
|
}
|
|
|
|
}
|
2012-08-15 23:27:03 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wf_info_unlock(wfi);
|
|
|
|
}
|
2012-08-15 23:27:03 +04:00
|
|
|
|
2012-08-18 00:24:56 +04:00
|
|
|
end = GetTickCount();
|
2012-08-24 01:10:22 +04:00
|
|
|
diff = end - beg;
|
2012-08-24 00:35:54 +04:00
|
|
|
|
|
|
|
if (diff < rate)
|
2012-08-18 00:24:56 +04:00
|
|
|
{
|
2012-08-23 23:36:34 +04:00
|
|
|
Sleep(rate - diff);
|
2012-08-18 00:24:56 +04:00
|
|
|
}
|
2012-08-14 23:12:44 +04:00
|
|
|
}
|
2012-08-25 03:39:30 +04:00
|
|
|
|
2012-09-03 02:04:41 +04:00
|
|
|
wf_info_lock(wfi);
|
|
|
|
wfi->threadCount--;
|
|
|
|
wf_info_unlock(wfi);
|
2012-08-24 00:35:54 +04:00
|
|
|
|
2012-08-15 04:30:36 +04:00
|
|
|
return 0;
|
2012-08-14 23:12:44 +04:00
|
|
|
}
|
|
|
|
|
2012-08-18 00:24:56 +04:00
|
|
|
void wf_rfx_encode(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
wfInfo* wfi;
|
2012-08-24 01:10:22 +04:00
|
|
|
long offset;
|
2012-08-18 00:24:56 +04:00
|
|
|
RFX_RECT rect;
|
2012-08-24 01:10:22 +04:00
|
|
|
long height, width;
|
2012-08-18 00:24:56 +04:00
|
|
|
rdpUpdate* update;
|
|
|
|
wfPeerContext* wfp;
|
|
|
|
GETCHANGESBUF* buf;
|
2012-08-24 01:10:22 +04:00
|
|
|
SURFACE_BITS_COMMAND* cmd;
|
2012-08-25 03:39:30 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wfp = (wfPeerContext*) client->context;
|
|
|
|
wfi = wfp->info;
|
2012-08-30 23:50:46 +04:00
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
if (client->activated == FALSE)
|
2012-08-30 23:50:46 +04:00
|
|
|
return;
|
2012-09-03 01:09:36 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wfp->activated == FALSE)
|
|
|
|
return;
|
2012-08-20 19:45:48 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wf_info_find_invalid_region(wfi);
|
2012-08-20 21:47:44 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
update = client->update;
|
|
|
|
cmd = &update->surface_bits_command;
|
|
|
|
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
2012-08-18 22:34:24 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
width = (wfi->invalid.right - wfi->invalid.left) + 1;
|
|
|
|
height = (wfi->invalid.bottom - wfi->invalid.top) + 1;
|
2012-08-18 00:24:56 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
stream_clear(wfi->s);
|
|
|
|
stream_set_pos(wfi->s, 0);
|
|
|
|
s = wfi->s;
|
2012-08-19 21:20:10 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = (uint16) width;
|
|
|
|
rect.height = (uint16) height;
|
2012-08-20 19:45:48 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->width * 4);
|
2012-08-20 19:45:48 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
rfx_compose_message(wfi->rfx_context, s, &rect, 1,
|
|
|
|
((uint8*) (buf->Userbuffer)) + offset, width, height, wfi->width * 4);
|
2012-08-19 03:46:42 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
cmd->destLeft = wfi->invalid.left;
|
|
|
|
cmd->destTop = wfi->invalid.top;
|
|
|
|
cmd->destRight = wfi->invalid.left + width;
|
|
|
|
cmd->destBottom = wfi->invalid.top + height;
|
2012-08-21 02:19:17 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
cmd->bpp = 32;
|
|
|
|
cmd->codecID = client->settings->rfx_codec_id;
|
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
|
|
|
cmd->bitmapDataLength = stream_get_length(s);
|
|
|
|
cmd->bitmapData = stream_get_head(s);
|
2012-08-18 00:24:56 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wfi->updatePending = TRUE;
|
2012-08-16 02:01:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
void wf_peer_init(freerdp_peer* client)
|
|
|
|
{
|
2012-09-03 01:09:36 +04:00
|
|
|
wfInfo* wfi;
|
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
client->context_size = sizeof(wfPeerContext);
|
|
|
|
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
|
|
|
|
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
|
2012-09-03 01:09:36 +04:00
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
freerdp_peer_context_new(client);
|
2012-08-15 00:49:24 +04:00
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
wfi = ((wfPeerContext*) client->context)->info;
|
|
|
|
|
2012-08-31 01:37:12 +04:00
|
|
|
#ifndef WITH_WIN8
|
2012-09-03 02:04:41 +04:00
|
|
|
wf_info_lock(wfi);
|
|
|
|
|
|
|
|
if (wfi->threadCount < 1)
|
2012-08-21 02:19:17 +04:00
|
|
|
{
|
|
|
|
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
|
2012-09-02 22:39:27 +04:00
|
|
|
{
|
2012-09-03 02:04:41 +04:00
|
|
|
wfi->threadCount++;
|
|
|
|
printf("started monitor thread\n");
|
2012-09-02 22:39:27 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tprintf(_T("failed to create monitor thread\n"));
|
|
|
|
}
|
2012-08-21 02:19:17 +04:00
|
|
|
}
|
2012-09-03 02:04:41 +04:00
|
|
|
|
|
|
|
wf_info_unlock(wfi);
|
2012-08-31 01:37:12 +04:00
|
|
|
#endif
|
2012-08-14 23:12:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean wf_peer_post_connect(freerdp_peer* client)
|
|
|
|
{
|
2012-09-03 01:09:36 +04:00
|
|
|
wfInfo* wfi;
|
2012-08-14 23:12:44 +04:00
|
|
|
wfPeerContext* context = (wfPeerContext*) client->context;
|
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
wfi = context->info;
|
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
/**
|
|
|
|
* This callback is called when the entire connection sequence is done, i.e. we've received the
|
|
|
|
* Font List PDU from the client and sent out the Font Map PDU.
|
|
|
|
* The server may start sending graphics output and receiving keyboard/mouse input after this
|
|
|
|
* callback returns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
|
|
|
|
client->settings->os_major_type, client->settings->os_minor_type);
|
|
|
|
|
|
|
|
if (client->settings->autologon)
|
|
|
|
{
|
|
|
|
printf(" and wants to login automatically as %s\\%s",
|
|
|
|
client->settings->domain ? client->settings->domain : "",
|
|
|
|
client->settings->username);
|
|
|
|
|
|
|
|
/* A real server may perform OS login here if NLA is not executed previously. */
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("Client requested desktop: %dx%dx%d\n",
|
|
|
|
client->settings->width, client->settings->height, client->settings->color_depth);
|
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
printf("But we will try resizing to %dx%d\n", wfi->width, wfi->height);
|
2012-08-20 22:36:59 +04:00
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
client->settings->width = wfi->width;
|
|
|
|
client->settings->height = wfi->height;
|
2012-08-20 22:36:59 +04:00
|
|
|
|
|
|
|
client->update->DesktopResize(client->update->context);
|
|
|
|
|
2012-08-14 23:12:44 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean wf_peer_activate(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
wfPeerContext* context = (wfPeerContext*) client->context;
|
|
|
|
|
|
|
|
context->activated = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wf_peer_synchronize_event(rdpInput* input, uint32 flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2012-08-18 22:34:24 +04:00
|
|
|
|
2012-09-03 01:09:36 +04:00
|
|
|
void wf_peer_send_changes(freerdp_peer* client)
|
2012-08-18 22:34:24 +04:00
|
|
|
{
|
2012-09-03 01:09:36 +04:00
|
|
|
wfInfo* wfi;
|
|
|
|
wfPeerContext* context = (wfPeerContext*) client->context;
|
|
|
|
|
|
|
|
wfi = context->info;
|
2012-08-19 01:49:52 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wf_info_lock(wfi) > 0)
|
2012-08-19 01:49:52 +04:00
|
|
|
{
|
2012-09-03 03:54:17 +04:00
|
|
|
if (wfi->updatePending)
|
|
|
|
{
|
|
|
|
wfi->lastUpdate = wfi->nextUpdate;
|
2012-08-30 23:50:46 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
client->update->SurfaceBits(client->update->context, &client->update->surface_bits_command);
|
2012-08-19 01:49:52 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wfi->updatePending = FALSE;
|
|
|
|
}
|
2012-08-18 22:34:24 +04:00
|
|
|
|
2012-09-03 03:54:17 +04:00
|
|
|
wf_info_unlock(wfi);
|
2012-08-24 00:35:54 +04:00
|
|
|
}
|
2012-08-23 23:36:34 +04:00
|
|
|
}
|