This commit is contained in:
C-o-r-E
2013-05-05 17:57:31 -04:00
209 changed files with 4893 additions and 2071 deletions

3
server/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
WaykServer
xrdp-ng

View File

@@ -35,3 +35,13 @@ else()
add_subdirectory(Windows)
endif()
if(WITH_WAYK)
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/WaykServer")
add_subdirectory(WaykServer)
endif()
endif()
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/xrdp-ng")
add_subdirectory("xrdp-ng")
endif()

View File

@@ -133,8 +133,8 @@ void mf_peer_rfx_update(freerdp_peer* client)
s = mfp->s;
stream_clear(s);
stream_set_pos(s, 0);
Stream_Clear(s);
Stream_SetPosition(s, 0);
UINT32 x = mfi->invalid.x / mfi->scale;
UINT32 y = mfi->invalid.y / mfi->scale;
@@ -160,7 +160,7 @@ void mf_peer_rfx_update(freerdp_peer* client)
cmd->codecID = 3;
cmd->width = rect.width;
cmd->height = rect.height;
cmd->bitmapDataLength = stream_get_length(s);
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = stream_get_head(s);
//send

View File

@@ -104,8 +104,8 @@ static void test_peer_init(freerdp_peer* client)
static wStream* test_peer_stream_init(testPeerContext* context)
{
stream_clear(context->s);
stream_set_pos(context->s, 0);
Stream_Clear(context->s);
Stream_SetPosition(context->s, 0);
return context->s;
}
@@ -179,7 +179,7 @@ static void test_peer_draw_background(freerdp_peer* client)
cmd->bpp = 32;
cmd->width = rect.width;
cmd->height = rect.height;
cmd->bitmapDataLength = stream_get_length(s);
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = stream_get_head(s);
update->SurfaceBits(update->context, cmd);
@@ -278,7 +278,7 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
cmd->bpp = 32;
cmd->width = context->icon_width;
cmd->height = context->icon_height;
cmd->bitmapDataLength = stream_get_length(s);
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = stream_get_head(s);
update->SurfaceBits(update->context, cmd);
}
@@ -305,7 +305,7 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
cmd->bpp = 32;
cmd->width = context->icon_width;
cmd->height = context->icon_height;
cmd->bitmapDataLength = stream_get_length(s);
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = stream_get_head(s);
update->SurfaceBits(update->context, cmd);
@@ -417,25 +417,25 @@ static void* tf_debug_channel_thread_func(void* arg)
if (WaitForSingleObject(context->stopEvent, 0) == WAIT_OBJECT_0)
break;
stream_set_pos(s, 0);
Stream_SetPosition(s, 0);
if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
stream_get_size(s), &bytes_returned) == FALSE)
Stream_Capacity(s), &bytes_returned) == FALSE)
{
if (bytes_returned == 0)
break;
stream_check_size(s, bytes_returned);
Stream_EnsureRemainingCapacity(s, bytes_returned);
if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
stream_get_size(s), &bytes_returned) == FALSE)
Stream_Capacity(s), &bytes_returned) == FALSE)
{
/* should not happen */
break;
}
}
stream_set_pos(s, bytes_returned);
Stream_SetPosition(s, bytes_returned);
printf("got %d bytes\n", bytes_returned);
}

View File

@@ -123,7 +123,7 @@ void wf_update_encode(wfInfo* wfi)
cmd = &wfi->cmd;
stream_set_pos(wfi->s, 0);
Stream_SetPosition(wfi->s, 0);
wf_info_getScreenData(wfi, &width, &height, &pDataBits, &stride);
@@ -134,7 +134,7 @@ void wf_update_encode(wfInfo* wfi)
//printf("x:%d y:%d w:%d h:%d\n", wfi->invalid.left, wfi->invalid.top, width, height);
stream_clear(wfi->s);
Stream_Clear(wfi->s);
rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1,
pDataBits, width, height, stride);
@@ -149,7 +149,7 @@ void wf_update_encode(wfInfo* wfi)
cmd->codecID = 3;
cmd->width = width;
cmd->height = height;
cmd->bitmapDataLength = stream_get_length(wfi->s);
cmd->bitmapDataLength = Stream_GetPosition(wfi->s);
cmd->bitmapData = stream_get_head(wfi->s);
}

View File

@@ -16,17 +16,40 @@
# limitations under the License.
set(MODULE_NAME "xfreerdp-server")
set(MODULE_PREFIX "FREERDP_SERVER_X11")
set(MODULE_PREFIX "FREERDP_SERVER_X11_CONTROL")
include_directories(${X11_INCLUDE_DIRS})
include_directories("../../winpr/tools/makecert")
set(${MODULE_PREFIX}_SRCS
xf_peer.c
xf_peer.h
xf_input.c
xf_input.h
xf_encode.c
xfreerdp.c)
xf_encode.h
xf_update.c
xf_update.h
xf_cursor.c
xf_cursor.h
xf_monitors.c
xf_monitors.h
xf_interface.c
xf_interface.h
xfreerdp.h)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
if(WITH_SERVER_INTERFACE)
if(SERVER_INTERFACE_SHARED)
add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS})
else()
add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
endif()
set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION} PREFIX "lib")
else()
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} cli/xfreerdp.c)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "xfreerdp-server")
endif()
set(XEXT_FEATURE_TYPE "RECOMMENDED")
set(XEXT_FEATURE_PURPOSE "X11 extension")
@@ -36,14 +59,26 @@ set(XSHM_FEATURE_TYPE "RECOMMENDED")
set(XSHM_FEATURE_PURPOSE "X11 shared memory")
set(XSHM_FEATURE_DESCRIPTION "X11 shared memory extension")
set(XINERAMA_FEATURE_TYPE "RECOMMENDED")
set(XINERAMA_FEATURE_PURPOSE "multi-monitor")
set(XINERAMA_FEATURE_DESCRIPTION "X11 multi-monitor extension")
set(XTEST_FEATURE_TYPE "RECOMMENDED")
set(XTEST_FEATURE_PURPOSE "X11 input event injection")
set(XTEST_FEATURE_DESCRIPTION "X11 input event injection extension")
set(XCURSOR_FEATURE_TYPE "RECOMMENDED")
set(XCURSOR_FEATURE_PURPOSE "cursor")
set(XCURSOR_FEATURE_DESCRIPTION "X11 cursor extension")
set(XFIXES_FEATURE_TYPE "RECOMMENDED")
set(XFIXES_FEATURE_PURPOSE "X11 region")
set(XFIXES_FEATURE_DESCRIPTION "X11 region fix extension")
set(XRANDR_FEATURE_TYPE "RECOMMENDED")
set(XRANDR_FEATURE_PURPOSE "X11 resize, rotate and reflect")
set(XRANDR_FEATURE_DESCRIPTION "X11 resize, rotate and reflect extension")
set(XDAMAGE_FEATURE_TYPE "RECOMMENDED")
set(XDAMAGE_FEATURE_PURPOSE "X11 region damage")
set(XDAMAGE_FEATURE_DESCRIPTION "X11 region damage extension")
@@ -52,7 +87,10 @@ find_feature(Xext ${XEXT_FEATURE_TYPE} ${XEXT_FEATURE_PURPOSE} ${XEXT_FEATURE_DE
find_feature(XShm ${XSHM_FEATURE_TYPE} ${XSHM_FEATURE_PURPOSE} ${XSHM_FEATURE_DESCRIPTION})
find_feature(XTest ${XTEST_FEATURE_TYPE} ${XTEST_FEATURE_PURPOSE} ${XTEST_FEATURE_DESCRIPTION})
find_feature(Xfixes ${XFIXES_FEATURE_TYPE} ${XFIXES_FEATURE_PURPOSE} ${XFIXES_FEATURE_DESCRIPTION})
find_feature(XRandR ${XRANDR_FEATURE_TYPE} ${XRANDR_FEATURE_PURPOSE} ${XRANDR_FEATURE_DESCRIPTION})
find_feature(Xdamage ${XDAMAGE_FEATURE_TYPE} ${XDAMAGE_FEATURE_PURPOSE} ${XDAMAGE_FEATURE_DESCRIPTION})
find_feature(Xcursor ${XCURSOR_FEATURE_TYPE} ${XCURSOR_FEATURE_PURPOSE} ${XCURSOR_FEATURE_DESCRIPTION})
find_feature(Xinerama ${XINERAMA_FEATURE_TYPE} ${XINERAMA_FEATURE_PURPOSE} ${XINERAMA_FEATURE_DESCRIPTION})
if(WITH_XSHM)
add_definitions(-DWITH_XSHM)
@@ -65,6 +103,18 @@ if(WITH_XEXT)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XEXT_LIBRARIES})
endif()
if(WITH_XINERAMA)
add_definitions(-DWITH_XINERAMA)
include_directories(${XINERAMA_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XINERAMA_LIBRARIES})
endif()
if(WITH_XCURSOR)
add_definitions(-DWITH_XCURSOR)
include_directories(${XCURSOR_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XCURSOR_LIBRARIES})
endif()
if(WITH_XDAMAGE)
add_definitions(-DWITH_XDAMAGE)
include_directories(${XDAMAGE_INCLUDE_DIRS})
@@ -84,6 +134,12 @@ if(WITH_XTEST)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XTEST_LIBRARIES})
endif()
if(WITH_XRANDR)
add_definitions(-DWITH_XRANDR)
include_directories(${XRANDR_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XRANDR_LIBRARIES})
endif()
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${X11_LIBRARIES})
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
@@ -94,10 +150,18 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr
MODULES winpr-sspi)
MODULES winpr-sspi winpr-crt winpr-utils winpr-input winpr-sysinfo)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr-makecert-tool)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
if(WITH_SERVER_INTERFACE)
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
add_subdirectory(cli)
else()
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/X11")

View File

@@ -0,0 +1,36 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP X11 cmake build script
#
# 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.
set(MODULE_NAME "xfreerdp-server-cli")
set(MODULE_PREFIX "FREERDP_SERVER_X11")
include_directories(..)
set(${MODULE_PREFIX}_SRCS
xfreerdp.c)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "xfreerdp-server" RUNTIME_OUTPUT_DIRECTORY "..")
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} xfreerdp-server)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/X11")

BIN
server/X11/cli/xfreerdp-server Executable file

Binary file not shown.

52
server/X11/cli/xfreerdp.c Normal file
View File

@@ -0,0 +1,52 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xf_interface.h"
int main(int argc, char* argv[])
{
HANDLE thread;
xfServer* server;
DWORD dwExitCode;
freerdp_server_global_init();
server = freerdp_server_new(argc, argv);
if (!server)
return 0;
freerdp_server_start(server);
thread = freerdp_server_get_thread(server);
WaitForSingleObject(thread, INFINITE);
GetExitCodeThread(thread, &dwExitCode);
freerdp_server_free(server);
freerdp_server_global_uninit();
return 0;
}

55
server/X11/xf_cursor.c Normal file
View File

@@ -0,0 +1,55 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Cursor
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef WITH_XCURSOR
#include <X11/Xcursor/Xcursor.h>
#endif
#ifdef WITH_XFIXES
#include <X11/extensions/Xfixes.h>
#endif
#include <winpr/crt.h>
#include "xf_cursor.h"
int xf_cursor_init(xfInfo* xfi)
{
int event;
int error;
if (!XFixesQueryExtension(xfi->display, &event, &error))
{
fprintf(stderr, "XFixesQueryExtension failed\n");
return -1;
}
xfi->xfixes_notify_event = event + XFixesCursorNotify;
XFixesSelectCursorInput(xfi->display, DefaultRootWindow(xfi->display), XFixesDisplayCursorNotifyMask);
return 0;
}

27
server/X11/xf_cursor.h Normal file
View File

@@ -0,0 +1,27 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Cursor
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_CURSOR_H
#define XFREERDP_SERVER_CURSOR_H
#include "xfreerdp.h"
int xf_cursor_init(xfInfo* xfi);
#endif /* XFREERDP_SERVER_CURSOR_H */

View File

@@ -22,12 +22,12 @@
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/select.h>
#include <sys/signal.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include "xf_encode.h"
@@ -65,116 +65,85 @@ void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int
#endif
}
void* xf_frame_rate_thread(void* param)
int xf_update_encode(freerdp_peer* client, int x, int y, int width, int height)
{
wStream* s;
BYTE* data;
xfInfo* xfi;
HGDI_RGN region;
RFX_RECT rect;
XImage* image;
rdpUpdate* update;
xfPeerContext* xfp;
freerdp_peer* client;
UINT32 wait_interval;
SURFACE_BITS_COMMAND* cmd;
client = (freerdp_peer*) param;
update = client->update;
xfp = (xfPeerContext*) client->context;
cmd = &update->surface_bits_command;
xfi = xfp->info;
region = xfp->hdc->hwnd->invalid;
wait_interval = 1000000 / xfp->fps;
while (1)
if (width * height <= 0)
{
/* check if we should terminate */
pthread_testcancel();
if (!region->null)
{
UINT32 xy, wh;
pthread_mutex_lock(&(xfp->mutex));
xy = (region->x << 16) | region->y;
wh = (region->w << 16) | region->h;
region->null = 1;
pthread_mutex_unlock(&(xfp->mutex));
MessageQueue_Post(xfp->queue, (void*) xfp,
MakeMessageId(PeerEvent, EncodeRegion),
(void*) (size_t) xy, (void*) (size_t) wh);
}
USleep(wait_interval);
cmd->bitmapDataLength = 0;
return -1;
}
return NULL;
}
s = xfp->s;
Stream_Clear(s);
Stream_SetPosition(s, 0);
void* xf_monitor_updates(void* param)
{
int fds;
xfInfo* xfi;
XEvent xevent;
fd_set rfds_set;
int select_status;
xfPeerContext* xfp;
freerdp_peer* client;
UINT32 wait_interval;
struct timeval timeout;
int x, y, width, height;
XDamageNotifyEvent* notify;
client = (freerdp_peer*) param;
xfp = (xfPeerContext*) client->context;
xfi = xfp->info;
fds = xfi->xfds;
wait_interval = 1000000 / xfp->fps;
ZeroMemory(&timeout, sizeof(struct timeval));
pthread_create(&(xfp->frame_rate_thread), 0, xf_frame_rate_thread, (void*) client);
while (1)
if (xfi->use_xshm)
{
/* check if we should terminate */
pthread_testcancel();
/**
* Passing an offset source rectangle to rfx_compose_message()
* leads to protocol errors, so offset the data pointer instead.
*/
FD_ZERO(&rfds_set);
FD_SET(fds, &rfds_set);
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
timeout.tv_sec = 0;
timeout.tv_usec = wait_interval;
select_status = select(fds + 1, &rfds_set, NULL, NULL, &timeout);
image = xf_snapshot(xfp, x, y, width, height);
if (select_status == -1)
{
fprintf(stderr, "select failed\n");
}
else if (select_status == 0)
{
data = (BYTE*) image->data;
data = &data[(y * image->bytes_per_line) + (x * image->bits_per_pixel / 8)];
}
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
width, height, image->bytes_per_line);
while (XPending(xfi->display) > 0)
{
ZeroMemory(&xevent, sizeof(xevent));
XNextEvent(xfi->display, &xevent);
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + width;
cmd->destBottom = y + height;
}
else
{
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
if (xevent.type == xfi->xdamage_notify_event)
{
notify = (XDamageNotifyEvent*) &xevent;
image = xf_snapshot(xfp, x, y, width, height);
x = notify->area.x;
y = notify->area.y;
width = notify->area.width;
height = notify->area.height;
data = (BYTE*) image->data;
pthread_mutex_lock(&(xfp->mutex));
gdi_InvalidateRegion(xfp->hdc, x, y, width, height);
pthread_mutex_unlock(&(xfp->mutex));
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
width, height, image->bytes_per_line);
xf_xdamage_subtract_region(xfp, x, y, width, height);
}
}
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + width;
cmd->destBottom = y + height;
XDestroyImage(image);
}
return NULL;
cmd->bpp = 32;
cmd->codecID = client->settings->RemoteFxCodecId;
cmd->width = width;
cmd->height = height;
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = Stream_Buffer(s);
return 0;
}

View File

@@ -20,13 +20,12 @@
#ifndef __XF_ENCODE_H
#define __XF_ENCODE_H
#include <pthread.h>
#include "xfreerdp.h"
#include "xf_peer.h"
XImage* xf_snapshot(xfPeerContext* xfp, int x, int y, int width, int height);
void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int height);
void* xf_monitor_updates(void* param);
int xf_update_encode(freerdp_peer* client, int x, int y, int width, int height);
#endif /* __XF_ENCODE_H */

View File

@@ -25,6 +25,9 @@
#include <freerdp/locale/keyboard.h>
#include <winpr/crt.h>
#include <winpr/input.h>
#include "xf_peer.h"
#include "xf_input.h"
@@ -37,7 +40,8 @@ void xf_input_synchronize_event(rdpInput* input, UINT32 flags)
void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
#ifdef WITH_XTEST
unsigned int keycode;
DWORD vkcode;
DWORD keycode;
BOOL extended = FALSE;
xfPeerContext* xfp = (xfPeerContext*) input->context;
xfInfo* xfi = xfp->info;
@@ -45,7 +49,11 @@ void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
if (flags & KBD_FLAGS_EXTENDED)
extended = TRUE;
keycode = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(code, extended);
if (extended)
code |= KBDEXT;
vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4);
keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_EVDEV);
if (keycode != 0)
{

View File

@@ -1,8 +1,8 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server
* FreeRDP X11 Server Interface
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2013 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.
@@ -17,10 +17,6 @@
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,10 +29,9 @@
#include "xf_peer.h"
#include "xfreerdp.h"
char* xf_pcap_file = NULL;
BOOL xf_pcap_dump_realtime = TRUE;
#include "xf_interface.h"
void xf_server_main_loop(freerdp_listener* instance)
void* xf_server_thread(void* param)
{
int i;
int fds;
@@ -44,14 +39,19 @@ void xf_server_main_loop(freerdp_listener* instance)
int rcount;
void* rfds[32];
fd_set rfds_set;
xfServer* server;
freerdp_listener* listener;
ZeroMemory(rfds, sizeof(rfds));
server = (xfServer*) param;
listener = server->listener;
while (1)
{
rcount = 0;
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
if (listener->GetFileDescriptor(listener, rfds, &rcount) != TRUE)
{
fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
break;
@@ -86,41 +86,73 @@ void xf_server_main_loop(freerdp_listener* instance)
}
}
if (instance->CheckFileDescriptor(instance) != TRUE)
if (listener->CheckFileDescriptor(listener) != TRUE)
{
fprintf(stderr, "Failed to check FreeRDP file descriptor\n");
break;
}
}
instance->Close(instance);
listener->Close(listener);
return NULL;
}
int main(int argc, char* argv[])
int freerdp_server_global_init()
{
freerdp_listener* instance;
/* ignore SIGPIPE, otherwise an SSL_write failure could crash the server */
/*
* ignore SIGPIPE, otherwise an SSL_write failure could crash the server
*/
signal(SIGPIPE, SIG_IGN);
instance = freerdp_listener_new();
instance->PeerAccepted = xf_peer_accepted;
if (argc > 1)
xf_pcap_file = argv[1];
if (argc > 2 && !strcmp(argv[2], "--fast"))
xf_pcap_dump_realtime = FALSE;
/* Open the server socket and start listening. */
if (instance->Open(instance, NULL, 3389))
{
/* Entering the server main loop. In a real server the listener can be run in its own thread. */
xf_server_main_loop(instance);
}
freerdp_listener_free(instance);
return 0;
}
int freerdp_server_global_uninit()
{
return 0;
}
int freerdp_server_start(xfServer* server)
{
if (server->listener->Open(server->listener, NULL, 3389))
{
server->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_server_thread, (void*) server, 0, NULL);
}
return 0;
}
int freerdp_server_stop(xfServer* server)
{
return 0;
}
HANDLE freerdp_server_get_thread(xfServer* server)
{
return server->thread;
}
xfServer* freerdp_server_new(int argc, char** argv)
{
xfServer* server;
server = (xfServer*) malloc(sizeof(xfServer));
if (server)
{
server->listener = freerdp_listener_new();
server->listener->PeerAccepted = xf_peer_accepted;
}
return server;
}
void freerdp_server_free(xfServer* server)
{
if (server)
{
freerdp_listener_free(server->listener);
free(server);
}
}

54
server/X11/xf_interface.h Normal file
View File

@@ -0,0 +1,54 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server Interface
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_INTERFACE_H
#define XFREERDP_SERVER_INTERFACE_H
#include <winpr/crt.h>
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
typedef struct xf_info xfInfo;
typedef struct xf_server xfServer;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Server Interface
*/
FREERDP_API int freerdp_server_global_init();
FREERDP_API int freerdp_server_global_uninit();
FREERDP_API int freerdp_server_start(xfServer* server);
FREERDP_API int freerdp_server_stop(xfServer* server);
FREERDP_API HANDLE freerdp_server_get_thread(xfServer* server);
FREERDP_API xfServer* freerdp_server_new(int argc, char** argv);
FREERDP_API void freerdp_server_free(xfServer* server);
#ifdef __cplusplus
}
#endif
#endif /* XFREERDP_SERVER_INTERFACE_H */

68
server/X11/xf_monitors.c Normal file
View File

@@ -0,0 +1,68 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Monitors
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef WITH_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include "xf_monitors.h"
int xf_list_monitors(xfInfo* xfi)
{
#ifdef WITH_XINERAMAZ
int i, nmonitors = 0;
int ignored, ignored2;
XineramaScreenInfo* screen = NULL;
if (XineramaQueryExtension(xfi->display, &ignored, &ignored2))
{
if (XineramaIsActive(xfi->display))
{
screen = XineramaQueryScreens(xfi->display, &nmonitors);
for (i = 0; i < nmonitors; i++)
{
printf(" %s [%d] %dx%d\t+%d+%d\n",
(i == 0) ? "*" : " ", i,
screen[i].width, screen[i].height,
screen[i].x_org, screen[i].y_org);
}
XFree(screen);
}
}
#else
Screen* screen;
screen = ScreenOfDisplay(xfi->display, DefaultScreen(xfi->display));
printf(" * [0] %dx%d\t+%d+%d\n", WidthOfScreen(screen), HeightOfScreen(screen), 0, 0);
#endif
return 0;
}

28
server/X11/xf_monitors.h Normal file
View File

@@ -0,0 +1,28 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Monitors
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_MONITORS_H
#define XFREERDP_SERVER_MONITORS_H
#include "xfreerdp.h"
int xf_list_monitors(xfInfo* xfi);
#endif /* XFREERDP_SERVER_MONITORS_H */

View File

@@ -36,13 +36,19 @@
#include <winpr/file.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <freerdp/freerdp.h>
#include <freerdp/codec/color.h>
#include <freerdp/locale/keyboard.h>
#include "xf_input.h"
#include "xf_cursor.h"
#include "xf_encode.h"
#include "xf_update.h"
#include "xf_monitors.h"
#include "makecert.h"
#include "xf_peer.h"
@@ -50,31 +56,11 @@
void xf_xdamage_init(xfInfo* xfi)
{
Bool pixmaps;
int damage_event;
int damage_error;
int major, minor;
XGCValues values;
if (xfi->use_xshm)
{
if (XShmQueryExtension(xfi->display) != False)
{
XShmQueryVersion(xfi->display, &major, &minor, &pixmaps);
if (pixmaps != True)
{
fprintf(stderr, "XShmQueryVersion failed\n");
return;
}
}
else
{
fprintf(stderr, "XShmQueryExtension failed\n");
return;
}
}
if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0)
{
fprintf(stderr, "XDamageQueryExtension failed\n");
@@ -122,8 +108,27 @@ void xf_xdamage_init(xfInfo* xfi)
#endif
void xf_xshm_init(xfInfo* xfi)
int xf_xshm_init(xfInfo* xfi)
{
Bool pixmaps;
int major, minor;
if (XShmQueryExtension(xfi->display) != False)
{
XShmQueryVersion(xfi->display, &major, &minor, &pixmaps);
if (pixmaps != True)
{
fprintf(stderr, "XShmQueryVersion failed\n");
return -1;
}
}
else
{
fprintf(stderr, "XShmQueryExtension failed\n");
return -1;
}
xfi->fb_shm_info.shmid = -1;
xfi->fb_shm_info.shmaddr = (char*) -1;
@@ -133,7 +138,7 @@ void xf_xshm_init(xfInfo* xfi)
if (!xfi->fb_image)
{
fprintf(stderr, "XShmCreateImage failed\n");
return;
return -1;
}
xfi->fb_shm_info.shmid = shmget(IPC_PRIVATE,
@@ -142,7 +147,7 @@ void xf_xshm_init(xfInfo* xfi)
if (xfi->fb_shm_info.shmid == -1)
{
fprintf(stderr, "shmget failed\n");
return;
return -1;
}
xfi->fb_shm_info.readOnly = False;
@@ -152,7 +157,7 @@ void xf_xshm_init(xfInfo* xfi)
if (xfi->fb_shm_info.shmaddr == ((char*) -1))
{
fprintf(stderr, "shmat failed\n");
return;
return -1;
}
XShmAttach(xfi->display, &(xfi->fb_shm_info));
@@ -166,6 +171,8 @@ void xf_xshm_init(xfInfo* xfi)
xfi->fb_pixmap = XShmCreatePixmap(xfi->display,
xfi->root_window, xfi->fb_image->data, &(xfi->fb_shm_info),
xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth);
return 0;
}
xfInfo* xf_info_init()
@@ -188,7 +195,9 @@ xfInfo* xf_info_init()
* To see if your X11 server supports shared pixmaps, use:
* xdpyinfo -ext MIT-SHM | grep "shared pixmaps"
*/
xfi->use_xshm = FALSE;
xfi->use_xshm = TRUE;
setenv("DISPLAY", ":0", 1); /* Set DISPLAY variable if not already set */
if (!XInitThreads())
fprintf(stderr, "warning: XInitThreads() failure\n");
@@ -201,6 +210,8 @@ xfInfo* xf_info_init()
exit(1);
}
xf_list_monitors(xfi);
xfi->xfds = ConnectionNumber(xfi->display);
xfi->number = DefaultScreen(xfi->display);
xfi->screen = ScreenOfDisplay(xfi->display, xfi->number);
@@ -236,7 +247,7 @@ xfInfo* xf_info_init()
vis = XGetVisualInfo(xfi->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
if (vis == NULL)
if (!vis)
{
fprintf(stderr, "XGetVisualInfo failed\n");
exit(1);
@@ -258,14 +269,23 @@ xfInfo* xf_info_init()
XSelectInput(xfi->display, xfi->root_window, SubstructureNotifyMask);
if (xfi->use_xshm)
{
if (xf_xshm_init(xfi) < 0)
xfi->use_xshm = FALSE;
}
if (xfi->use_xshm)
printf("Using X Shared Memory Extension (XShm)\n");
#ifdef WITH_XDAMAGE
xf_xdamage_init(xfi);
#endif
if (xfi->use_xshm)
xf_xshm_init(xfi);
xf_cursor_init(xfi);
xfi->bytesPerPixel = 4;
xfi->activePeerCount = 0;
freerdp_keyboard_init(0);
@@ -282,14 +302,18 @@ void xf_peer_context_new(freerdp_peer* client, xfPeerContext* context)
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = stream_new(65536);
context->s = Stream_New(NULL, 65536);
Stream_Clear(context->s);
context->updateReadyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->updateSentEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
}
void xf_peer_context_free(freerdp_peer* client, xfPeerContext* context)
{
if (context)
{
stream_free(context->s);
Stream_Free(context->s, TRUE);
rfx_context_free(context->rfx_context);
}
}
@@ -307,106 +331,21 @@ void xf_peer_init(freerdp_peer* client)
xfp = (xfPeerContext*) client->context;
xfp->fps = 16;
xfp->thread = 0;
xfp->activations = 0;
xfp->queue = MessageQueue_New();
xfi = xfp->info;
xfp->hdc = gdi_CreateDC(xfi->clrconv, xfi->bpp);
pthread_mutex_init(&(xfp->mutex), NULL);
xfp->mutex = CreateMutex(NULL, FALSE, NULL);
}
wStream* xf_peer_stream_init(xfPeerContext* context)
void xf_peer_send_update(freerdp_peer* client)
{
stream_clear(context->s);
stream_set_pos(context->s, 0);
return context->s;
}
void xf_peer_live_rfx(freerdp_peer* client)
{
xfPeerContext* xfp = (xfPeerContext*) client->context;
pthread_create(&(xfp->thread), 0, xf_monitor_updates, (void*) client);
}
void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int height)
{
wStream* s;
BYTE* data;
xfInfo* xfi;
RFX_RECT rect;
XImage* image;
rdpUpdate* update;
xfPeerContext* xfp;
SURFACE_BITS_COMMAND* cmd;
update = client->update;
xfp = (xfPeerContext*) client->context;
cmd = &update->surface_bits_command;
xfi = xfp->info;
if (width * height <= 0)
return;
s = xf_peer_stream_init(xfp);
if (xfi->use_xshm)
{
/**
* Passing an offset source rectangle to rfx_compose_message()
* leads to protocol errors, so offset the data pointer instead.
*/
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
image = xf_snapshot(xfp, x, y, width, height);
data = (BYTE*) image->data;
data = &data[(y * image->bytes_per_line) + (x * image->bits_per_pixel / 8)];
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
width, height, image->bytes_per_line);
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + width;
cmd->destBottom = y + height;
}
else
{
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
image = xf_snapshot(xfp, x, y, width, height);
data = (BYTE*) image->data;
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
width, height, image->bytes_per_line);
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + width;
cmd->destBottom = y + height;
XDestroyImage(image);
}
cmd->bpp = 32;
cmd->codecID = client->settings->RemoteFxCodecId;
cmd->width = width;
cmd->height = height;
cmd->bitmapDataLength = stream_get_length(s);
cmd->bitmapData = stream_get_head(s);
update->SurfaceBits(update->context, cmd);
if (cmd->bitmapDataLength)
update->SurfaceBits(update->context, cmd);
}
BOOL xf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
@@ -415,7 +354,7 @@ BOOL xf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
HANDLE event;
xfPeerContext* xfp = (xfPeerContext*) client->context;
event = MessageQueue_Event(xfp->queue);
event = xfp->updateReadyEvent;
fds = GetEventFileDescriptor(event);
rfds[*rcount] = (void*) (long) fds;
(*rcount)++;
@@ -426,34 +365,20 @@ BOOL xf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
BOOL xf_peer_check_fds(freerdp_peer* client)
{
xfInfo* xfi;
wMessage message;
xfPeerContext* xfp;
xfp = (xfPeerContext*) client->context;
xfi = xfp->info;
if (xfp->activated == FALSE)
return TRUE;
if (MessageQueue_Peek(xfp->queue, &message, TRUE))
if (WaitForSingleObject(xfp->updateReadyEvent, 0) == WAIT_OBJECT_0)
{
if (message.id == MakeMessageId(PeerEvent, EncodeRegion))
{
UINT32 xy, wh;
UINT16 x, y, w, h;
if (!xfp->activated)
return TRUE;
xy = (UINT32) (size_t) message.wParam;
wh = (UINT32) (size_t) message.lParam;
xf_peer_send_update(client);
x = ((xy & 0xFFFF0000) >> 16);
y = (xy & 0x0000FFFF);
w = ((wh & 0xFFFF0000) >> 16);
h = (wh & 0x0000FFFF);
if (w * h > 0)
xf_peer_rfx_update(client, x, y, w, h);
}
ResetEvent(xfp->updateReadyEvent);
SetEvent(xfp->updateSentEvent);
}
return TRUE;
@@ -516,34 +441,28 @@ BOOL xf_peer_activate(freerdp_peer* client)
rfx_context_reset(xfp->rfx_context);
xfp->activated = TRUE;
xf_peer_live_rfx(client);
xfp->info->activePeerCount++;
xfp->monitorThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) xf_update_thread, (void*) client, 0, NULL);
return TRUE;
}
void* xf_peer_main_loop(void* arg)
const char* makecert_argv[4] =
{
"makecert",
"-rdp",
"-live",
"-silent"
};
int makecert_argc = (sizeof(makecert_argv) / sizeof(char*));
int xf_generate_certificate(rdpSettings* settings)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
rdpSettings* settings;
char* server_file_path;
freerdp_peer* client = (freerdp_peer*) arg;
xfPeerContext* xfp;
ZeroMemory(rfds, sizeof(rfds));
fprintf(stderr, "We've got a client %s\n", client->hostname);
xf_peer_init(client);
xfp = (xfPeerContext*) client->context;
settings = client->settings;
/* Initialize the real server settings here */
MAKECERT_CONTEXT* context;
server_file_path = GetCombinedPath(settings->ConfigPath, "server");
@@ -553,6 +472,53 @@ void* xf_peer_main_loop(void* arg)
settings->CertificateFile = GetCombinedPath(server_file_path, "server.crt");
settings->PrivateKeyFile = GetCombinedPath(server_file_path, "server.key");
if ((!PathFileExistsA(settings->CertificateFile)) ||
(!PathFileExistsA(settings->PrivateKeyFile)))
{
context = makecert_context_new();
makecert_context_process(context, makecert_argc, (char**) makecert_argv);
makecert_context_set_output_file_name(context, "server");
if (!PathFileExistsA(settings->CertificateFile))
makecert_context_output_certificate_file(context, server_file_path);
if (!PathFileExistsA(settings->PrivateKeyFile))
makecert_context_output_private_key_file(context, server_file_path);
makecert_context_free(context);
}
free(server_file_path);
return 0;
}
static void* xf_peer_main_loop(void* arg)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
rdpSettings* settings;
xfPeerContext* xfp;
struct timeval timeout;
freerdp_peer* client = (freerdp_peer*) arg;
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(&timeout, sizeof(struct timeval));
fprintf(stderr, "We've got a client %s\n", client->hostname);
xf_peer_init(client);
xfp = (xfPeerContext*) client->context;
settings = client->settings;
xf_generate_certificate(settings);
settings->RemoteFxCodec = TRUE;
settings->ColorDepth = 32;
@@ -573,6 +539,7 @@ void* xf_peer_main_loop(void* arg)
fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
break;
}
if (xf_peer_get_fds(client, rfds, &rcount) != TRUE)
{
fprintf(stderr, "Failed to get xfreerdp file descriptor\n");
@@ -595,7 +562,10 @@ void* xf_peer_main_loop(void* arg)
if (max_fds == 0)
break;
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
timeout.tv_sec = 0;
timeout.tv_usec = 100;
if (select(max_fds + 1, &rfds_set, NULL, NULL, &timeout) == -1)
{
/* these are not really errors */
if (!((errno == EAGAIN) ||
@@ -613,6 +583,7 @@ void* xf_peer_main_loop(void* arg)
fprintf(stderr, "Failed to check freerdp file descriptor\n");
break;
}
if ((xf_peer_check_fds(client)) != TRUE)
{
fprintf(stderr, "Failed to check xfreerdp file descriptor\n");
@@ -624,12 +595,6 @@ void* xf_peer_main_loop(void* arg)
client->Disconnect(client);
pthread_cancel(xfp->thread);
pthread_cancel(xfp->frame_rate_thread);
pthread_join(xfp->thread, NULL);
pthread_join(xfp->frame_rate_thread, NULL);
freerdp_peer_context_free(client);
freerdp_peer_free(client);
@@ -638,8 +603,7 @@ void* xf_peer_main_loop(void* arg)
void xf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
pthread_t th;
HANDLE thread;
pthread_create(&th, 0, xf_peer_main_loop, client);
pthread_detach(th);
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_peer_main_loop, client, 0, NULL);
}

View File

@@ -21,6 +21,8 @@
#define __XF_PEER_H
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/stream.h>
#include <winpr/collections.h>
@@ -47,16 +49,13 @@ struct xf_peer_context
int fps;
wStream* s;
HGDI_DC hdc;
xfInfo* info;
int activations;
pthread_t thread;
HANDLE mutex;
BOOL activated;
pthread_mutex_t mutex;
HANDLE monitorThread;
HANDLE updateReadyEvent;
HANDLE updateSentEvent;
RFX_CONTEXT* rfx_context;
pthread_t frame_rate_thread;
wMessageQueue* queue;
};
void xf_peer_accepted(freerdp_listener* instance, freerdp_peer* client);

99
server/X11/xf_update.c Normal file
View File

@@ -0,0 +1,99 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Graphical Updates
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/sysinfo.h>
#include "xf_peer.h"
#include "xf_encode.h"
#include "xf_update.h"
void* xf_update_thread(void* param)
{
xfInfo* xfi;
HANDLE event;
XEvent xevent;
DWORD beg, end;
DWORD diff, rate;
xfPeerContext* xfp;
freerdp_peer* client;
int x, y, width, height;
XDamageNotifyEvent* notify;
client = (freerdp_peer*) param;
xfp = (xfPeerContext*) client->context;
xfi = xfp->info;
rate = 1000 / xfp->fps;
event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfi->xfds);
while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0)
{
beg = GetTickCount();
while (XPending(xfi->display) > 0)
{
ZeroMemory(&xevent, sizeof(xevent));
XNextEvent(xfi->display, &xevent);
if (xevent.type == xfi->xdamage_notify_event)
{
notify = (XDamageNotifyEvent*) &xevent;
x = notify->area.x;
y = notify->area.y;
width = notify->area.width;
height = notify->area.height;
if (xf_update_encode(client, x, y, width, height) >= 0)
{
xf_xdamage_subtract_region(xfp, x, y, width, height);
SetEvent(xfp->updateReadyEvent);
WaitForSingleObject(xfp->updateSentEvent, INFINITE);
ResetEvent(xfp->updateSentEvent);
}
}
else if (xevent.type == xfi->xfixes_notify_event)
{
XFixesCursorImage* ci = XFixesGetCursorImage(xfi->display);
XFree(ci);
}
}
end = GetTickCount();
diff = end - beg;
if (diff < rate)
Sleep(rate - diff);
}
return NULL;
}

28
server/X11/xf_update.h Normal file
View File

@@ -0,0 +1,28 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Graphical Updates
*
* Copyright 2013 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.
*/
#ifndef __XF_UPDATE_H
#define __XF_UPDATE_H
#include "xfreerdp.h"
void* xf_update_thread(void* param);
#endif /* __XF_UPDATE_H */

View File

@@ -20,8 +20,15 @@
#ifndef __XFREERDP_H
#define __XFREERDP_H
#include "xf_interface.h"
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/listener.h>
#include <freerdp/codec/color.h>
#include <X11/Xlib.h>
#ifdef WITH_XSHM
#include <X11/extensions/XShm.h>
#endif
@@ -38,8 +45,6 @@
#include <X11/extensions/Xdamage.h>
#endif
typedef struct xf_info xfInfo;
struct xf_info
{
int bpp;
@@ -56,6 +61,7 @@ struct xf_info
int bytesPerPixel;
HCLRCONV clrconv;
BOOL use_xshm;
int activePeerCount;
XImage* fb_image;
Pixmap fb_pixmap;
@@ -68,6 +74,19 @@ struct xf_info
int xdamage_notify_event;
XserverRegion xdamage_region;
#endif
#ifdef WITH_XFIXES
int xfixes_notify_event;
#endif
};
struct xf_server
{
DWORD port;
HANDLE thread;
freerdp_listener* listener;
};
void* xf_server_thread(void* param);
#endif /* __XFREERDP_H */