mirror of https://github.com/FreeRDP/FreeRDP
xfreerdp-server: make use of winpr synch and thread apis
This commit is contained in:
parent
b4cac74136
commit
9383892d16
|
@ -65,13 +65,11 @@ void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int
|
|||
#endif
|
||||
}
|
||||
|
||||
void* xf_monitor_updates(void* param)
|
||||
void* xf_monitor_thread(void* param)
|
||||
{
|
||||
int fds;
|
||||
xfInfo* xfi;
|
||||
HANDLE event;
|
||||
XEvent xevent;
|
||||
fd_set rfds_set;
|
||||
int select_status;
|
||||
xfPeerContext* xfp;
|
||||
freerdp_peer* client;
|
||||
UINT32 wait_interval;
|
||||
|
@ -83,31 +81,13 @@ void* xf_monitor_updates(void* param)
|
|||
xfp = (xfPeerContext*) client->context;
|
||||
xfi = xfp->info;
|
||||
|
||||
fds = xfi->xfds;
|
||||
wait_interval = 1000000 / xfp->fps;
|
||||
ZeroMemory(&timeout, sizeof(struct timeval));
|
||||
|
||||
while (1)
|
||||
event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfi->xfds);
|
||||
|
||||
while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0)
|
||||
{
|
||||
/* check if we should terminate */
|
||||
pthread_testcancel();
|
||||
|
||||
FD_ZERO(&rfds_set);
|
||||
FD_SET(fds, &rfds_set);
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = wait_interval;
|
||||
select_status = select(fds + 1, &rfds_set, NULL, NULL, &timeout);
|
||||
|
||||
if (select_status == -1)
|
||||
{
|
||||
fprintf(stderr, "select failed\n");
|
||||
}
|
||||
else if (select_status == 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
while (XPending(xfi->display) > 0)
|
||||
{
|
||||
ZeroMemory(&xevent, sizeof(xevent));
|
||||
|
@ -122,9 +102,9 @@ void* xf_monitor_updates(void* param)
|
|||
width = notify->area.width;
|
||||
height = notify->area.height;
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
WaitForSingleObject(xfp->mutex, INFINITE);
|
||||
gdi_InvalidateRegion(xfp->hdc, x, y, width, height);
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
ReleaseMutex(xfp->mutex);
|
||||
|
||||
xf_xdamage_subtract_region(xfp, x, y, width, height);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,6 @@
|
|||
|
||||
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);
|
||||
void* xf_monitor_thread(void* param);
|
||||
|
||||
#endif /* __XF_ENCODE_H */
|
||||
|
|
|
@ -125,7 +125,7 @@ void xf_xdamage_init(xfInfo* xfi)
|
|||
|
||||
#endif
|
||||
|
||||
void xf_xshm_init(xfInfo* xfi)
|
||||
int xf_xshm_init(xfInfo* xfi)
|
||||
{
|
||||
xfi->fb_shm_info.shmid = -1;
|
||||
xfi->fb_shm_info.shmaddr = (char*) -1;
|
||||
|
@ -136,7 +136,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,
|
||||
|
@ -145,7 +145,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;
|
||||
|
@ -155,7 +155,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));
|
||||
|
@ -169,6 +169,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()
|
||||
|
@ -191,7 +193,7 @@ 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 */
|
||||
|
||||
|
@ -268,7 +270,13 @@ xfInfo* xf_info_init()
|
|||
#endif
|
||||
|
||||
if (xfi->use_xshm)
|
||||
xf_xshm_init(xfi);
|
||||
{
|
||||
if (xf_xshm_init(xfi) < 0)
|
||||
xfi->use_xshm = FALSE;
|
||||
}
|
||||
|
||||
if (xfi->use_xshm)
|
||||
printf("Using X Shared Memory Extension (XShm)\n");
|
||||
|
||||
xfi->bytesPerPixel = 4;
|
||||
|
||||
|
@ -313,7 +321,6 @@ void xf_peer_init(freerdp_peer* client)
|
|||
xfp = (xfPeerContext*) client->context;
|
||||
|
||||
xfp->fps = 16;
|
||||
xfp->thread = 0;
|
||||
xfp->activations = 0;
|
||||
|
||||
xfp->queue = MessageQueue_New();
|
||||
|
@ -321,7 +328,7 @@ void xf_peer_init(freerdp_peer* client)
|
|||
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)
|
||||
|
@ -334,7 +341,9 @@ wStream* 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);
|
||||
|
||||
xfp->monitorThread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) xf_monitor_thread, (void*) client, 0, NULL);
|
||||
}
|
||||
|
||||
void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int height)
|
||||
|
@ -443,14 +452,14 @@ BOOL xf_peer_check_fds(freerdp_peer* client)
|
|||
|
||||
region = xfp->hdc->hwnd->invalid;
|
||||
|
||||
pthread_mutex_lock(&(xfp->mutex));
|
||||
WaitForSingleObject(xfp->mutex, INFINITE);
|
||||
|
||||
if ((region->w * region->h) > 0)
|
||||
xf_peer_rfx_update(client, region->x, region->y, region->w, region->h);
|
||||
|
||||
region->null = 1;
|
||||
|
||||
pthread_mutex_unlock(&(xfp->mutex));
|
||||
ReleaseMutex(xfp->mutex);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -663,10 +672,6 @@ static void* xf_peer_main_loop(void* arg)
|
|||
|
||||
client->Disconnect(client);
|
||||
|
||||
pthread_cancel(xfp->thread);
|
||||
|
||||
pthread_join(xfp->thread, NULL);
|
||||
|
||||
freerdp_peer_context_free(client);
|
||||
freerdp_peer_free(client);
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
@ -50,11 +52,10 @@ struct xf_peer_context
|
|||
HGDI_DC hdc;
|
||||
xfInfo* info;
|
||||
int activations;
|
||||
pthread_t thread;
|
||||
BOOL activated;
|
||||
pthread_mutex_t mutex;
|
||||
HANDLE monitorThread;
|
||||
HANDLE mutex;
|
||||
RFX_CONTEXT* rfx_context;
|
||||
pthread_t frame_rate_thread;
|
||||
|
||||
wMessageQueue* queue;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue