Stay in handle_messages for 30ms max (per frame).

This commit is contained in:
Michael Jumper 2013-08-20 11:32:47 -07:00
parent dfe454f484
commit 21420aaf5c
4 changed files with 38 additions and 6 deletions

View File

@ -51,6 +51,10 @@
#include "rdp_keymap.h"
#include "rdp_settings.h"
/**
* The maximum duration of a frame in milliseconds.
*/
#define GUAC_RDP_FRAME_DURATION 30
/**
* Client data that will remain accessible through the guac_client.

View File

@ -198,8 +198,12 @@ int rdp_guac_client_handle_messages(guac_client* client) {
/* Wait for messages */
int wait_result = rdp_guac_client_wait_for_messages(client, 250000);
guac_timestamp frame_start = guac_timestamp_current();
while (wait_result > 0) {
guac_timestamp frame_end;
int frame_remaining;
pthread_mutex_lock(&(guac_client_data->rdp_lock));
/* Check the libfreerdp fds */
@ -247,9 +251,18 @@ int rdp_guac_client_handle_messages(guac_client* client) {
if (guac_client_data->audio != NULL)
guac_socket_flush(guac_client_data->audio->stream->socket);
/* Wait again */
pthread_mutex_unlock(&(guac_client_data->rdp_lock));
wait_result = rdp_guac_client_wait_for_messages(client, 0);
/* Calculate time remaining in frame */
frame_end = guac_timestamp_current();
frame_remaining = frame_start + GUAC_RDP_FRAME_DURATION - frame_end;
/* Wait again if frame remaining */
if (frame_remaining > 0)
wait_result = rdp_guac_client_wait_for_messages(client,
frame_remaining*1000);
else
break;
}

View File

@ -44,6 +44,11 @@
#include <pulse/pulseaudio.h>
/**
* The maximum duration of a frame in milliseconds.
*/
#define GUAC_VNC_FRAME_DURATION 30
extern char* __GUAC_CLIENT;
typedef struct vnc_guac_client_data {

View File

@ -53,21 +53,31 @@
int vnc_guac_client_handle_messages(guac_client* client) {
int wait_result;
rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
/* Initially wait for messages */
wait_result = WaitForMessage(rfb_client, 1000000);
int wait_result = WaitForMessage(rfb_client, 1000000);
guac_timestamp frame_start = guac_timestamp_current();
while (wait_result > 0) {
guac_timestamp frame_end;
int frame_remaining;
/* Handle any message received */
if (!HandleRFBServerMessage(rfb_client)) {
guac_client_log_error(client, "Error handling VNC server message\n");
return 1;
}
/* Check for additional messages */
wait_result = WaitForMessage(rfb_client, 0);
/* Calculate time remaining in frame */
frame_end = guac_timestamp_current();
frame_remaining = frame_start + GUAC_VNC_FRAME_DURATION - frame_end;
/* Wait again if frame remaining */
if (frame_remaining > 0)
wait_result = WaitForMessage(rfb_client, frame_remaining*1000);
else
break;
}