xfreerdp-server: cleanup
This commit is contained in:
parent
f12e4ff89d
commit
47167b8c98
@ -38,27 +38,12 @@ XImage* xf_snapshot(xfPeerContext* xfp, int x, int y, int width, int height)
|
||||
|
||||
if (xfi->use_xshm)
|
||||
{
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
|
||||
XCopyArea(xfi->display, xfi->root_window, xfi->fb_pixmap,
|
||||
xfi->xdamage_gc, x, y, width, height, x, y);
|
||||
|
||||
XSync(xfi->display, False);
|
||||
|
||||
XCopyArea(xfi->display, xfi->root_window, xfi->fb_pixmap, xfi->xdamage_gc, x, y, width, height, x, y);
|
||||
image = xfi->fb_image;
|
||||
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
|
||||
image = XGetImage(xfi->display, xfi->root_window,
|
||||
x, y, width, height, AllPlanes, ZPixmap);
|
||||
|
||||
XSync(xfi->display, False);
|
||||
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
image = XGetImage(xfi->display, xfi->root_window, x, y, width, height, AllPlanes, ZPixmap);
|
||||
}
|
||||
|
||||
return image;
|
||||
@ -75,10 +60,8 @@ void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int
|
||||
region.height = height;
|
||||
|
||||
#ifdef WITH_XFIXES
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
XFixesSetRegion(xfi->display, xfi->xdamage_region, ®ion, 1);
|
||||
XDamageSubtract(xfi->display, xfi->xdamage, xfi->xdamage_region, None);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -132,7 +115,6 @@ void* xf_monitor_updates(void* param)
|
||||
XEvent xevent;
|
||||
fd_set rfds_set;
|
||||
int select_status;
|
||||
int pending_events;
|
||||
xfPeerContext* xfp;
|
||||
freerdp_peer* client;
|
||||
UINT32 wait_interval;
|
||||
@ -171,16 +153,10 @@ void* xf_monitor_updates(void* param)
|
||||
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
pending_events = XPending(xfi->display);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
|
||||
if (pending_events > 0)
|
||||
while (XPending(xfi->display) > 0)
|
||||
{
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
ZeroMemory(&xevent, sizeof(xevent));
|
||||
XNextEvent(xfi->display, &xevent);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
|
||||
if (xevent.type == xfi->xdamage_notify_event)
|
||||
{
|
||||
@ -191,11 +167,11 @@ void* xf_monitor_updates(void* param)
|
||||
width = notify->area.width;
|
||||
height = notify->area.height;
|
||||
|
||||
xf_xdamage_subtract_region(xfp, x, y, width, height);
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
gdi_InvalidateRegion(xfp->hdc, x, y, width, height);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
|
||||
xf_xdamage_subtract_region(xfp, x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,6 @@ void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
||||
|
||||
if (keycode != 0)
|
||||
{
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
|
||||
XTestGrabControl(xfi->display, True);
|
||||
|
||||
if (flags & KBD_FLAGS_DOWN)
|
||||
@ -59,8 +57,6 @@ void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
||||
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
|
||||
|
||||
XTestGrabControl(xfi->display, False);
|
||||
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -78,7 +74,6 @@ void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
||||
BOOL down = FALSE;
|
||||
xfInfo* xfi = xfp->info;
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
XTestGrabControl(xfi->display, True);
|
||||
|
||||
if (flags & PTR_FLAGS_WHEEL)
|
||||
@ -113,7 +108,6 @@ void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
||||
}
|
||||
|
||||
XTestGrabControl(xfi->display, False);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -123,11 +117,9 @@ void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT
|
||||
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
||||
xfInfo* xfi = xfp->info;
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
XTestGrabControl(xfi->display, True);
|
||||
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
|
||||
XTestGrabControl(xfi->display, False);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,6 @@
|
||||
#include <freerdp/utils/file.h>
|
||||
#include <freerdp/utils/thread.h>
|
||||
|
||||
extern char* xf_pcap_file;
|
||||
extern BOOL xf_pcap_dump_realtime;
|
||||
|
||||
#include "xf_input.h"
|
||||
#include "xf_encode.h"
|
||||
|
||||
@ -133,7 +130,7 @@ void xf_xshm_init(xfInfo* xfi)
|
||||
xfi->fb_image = XShmCreateImage(xfi->display, xfi->visual, xfi->depth,
|
||||
ZPixmap, NULL, &(xfi->fb_shm_info), xfi->width, xfi->height);
|
||||
|
||||
if (xfi->fb_image == NULL)
|
||||
if (!xfi->fb_image)
|
||||
{
|
||||
printf("XShmCreateImage failed\n");
|
||||
return;
|
||||
@ -198,7 +195,7 @@ xfInfo* xf_info_init()
|
||||
|
||||
xfi->display = XOpenDisplay(NULL);
|
||||
|
||||
if (xfi->display == NULL)
|
||||
if (!xfi->display)
|
||||
{
|
||||
printf("failed to open display: %s\n", XDisplayName(NULL));
|
||||
exit(1);
|
||||
@ -214,7 +211,7 @@ xfInfo* xf_info_init()
|
||||
|
||||
pfs = XListPixmapFormats(xfi->display, &pf_count);
|
||||
|
||||
if (pfs == NULL)
|
||||
if (!pfs)
|
||||
{
|
||||
printf("XListPixmapFormats failed\n");
|
||||
exit(1);
|
||||
@ -331,85 +328,9 @@ STREAM* xf_peer_stream_init(xfPeerContext* context)
|
||||
void xf_peer_live_rfx(freerdp_peer* client)
|
||||
{
|
||||
xfPeerContext* xfp = (xfPeerContext*) client->context;
|
||||
|
||||
pthread_create(&(xfp->thread), 0, xf_monitor_updates, (void*) client);
|
||||
}
|
||||
|
||||
static BOOL xf_peer_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, UINT32 new_usec)
|
||||
{
|
||||
INT32 sec, usec;
|
||||
|
||||
if (*old_sec == 0 && *old_usec == 0)
|
||||
{
|
||||
*old_sec = new_sec;
|
||||
*old_usec = new_usec;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
sec = new_sec - *old_sec;
|
||||
usec = new_usec - *old_usec;
|
||||
|
||||
if (sec < 0 || (sec == 0 && usec < 0))
|
||||
{
|
||||
printf("Invalid time stamp detected.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*old_sec = new_sec;
|
||||
*old_usec = new_usec;
|
||||
|
||||
while (usec < 0)
|
||||
{
|
||||
usec += 1000000;
|
||||
sec--;
|
||||
}
|
||||
|
||||
if (sec > 0)
|
||||
Sleep(sec * 1000);
|
||||
|
||||
if (usec > 0)
|
||||
USleep(usec);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void xf_peer_dump_rfx(freerdp_peer* client)
|
||||
{
|
||||
STREAM* s;
|
||||
UINT32 prev_seconds;
|
||||
UINT32 prev_useconds;
|
||||
rdpUpdate* update;
|
||||
rdpPcap* pcap_rfx;
|
||||
pcap_record record;
|
||||
|
||||
s = stream_new(512);
|
||||
update = client->update;
|
||||
client->update->pcap_rfx = pcap_open(xf_pcap_file, FALSE);
|
||||
pcap_rfx = client->update->pcap_rfx;
|
||||
|
||||
if (pcap_rfx == NULL)
|
||||
return;
|
||||
|
||||
prev_seconds = prev_useconds = 0;
|
||||
|
||||
while (pcap_has_next_record(pcap_rfx))
|
||||
{
|
||||
pcap_get_next_record_header(pcap_rfx, &record);
|
||||
|
||||
s->data = realloc(s->data, record.length);
|
||||
record.data = s->data;
|
||||
s->size = record.length;
|
||||
|
||||
pcap_get_next_record_content(pcap_rfx, &record);
|
||||
s->p = s->data + s->size;
|
||||
|
||||
if (xf_pcap_dump_realtime && xf_peer_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == FALSE)
|
||||
break;
|
||||
|
||||
update->SurfaceCommand(update->context, s);
|
||||
}
|
||||
}
|
||||
|
||||
void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int height)
|
||||
{
|
||||
STREAM* s;
|
||||
@ -474,8 +395,6 @@ void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int heigh
|
||||
cmd->destTop = y;
|
||||
cmd->destRight = x + width;
|
||||
cmd->destBottom = y + height;
|
||||
|
||||
XDestroyImage(image);
|
||||
}
|
||||
|
||||
cmd->bpp = 32;
|
||||
@ -595,15 +514,7 @@ BOOL xf_peer_activate(freerdp_peer* client)
|
||||
rfx_context_reset(xfp->rfx_context);
|
||||
xfp->activated = TRUE;
|
||||
|
||||
if (xf_pcap_file != NULL)
|
||||
{
|
||||
client->update->dump_rfx = TRUE;
|
||||
xf_peer_dump_rfx(client);
|
||||
}
|
||||
else
|
||||
{
|
||||
xf_peer_live_rfx(client);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ void xf_server_main_loop(freerdp_listener* instance)
|
||||
void* rfds[32];
|
||||
fd_set rfds_set;
|
||||
|
||||
memset(rfds, 0, sizeof(rfds));
|
||||
ZeroMemory(rfds, sizeof(rfds));
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user