GUACAMOLE-172: Merge lag calculation improvements.

This commit is contained in:
James Muehlner 2017-01-24 23:26:29 -08:00
commit 5d5fbb4d45
3 changed files with 35 additions and 23 deletions

View File

@ -95,30 +95,35 @@ int __guac_handle_sync(guac_user* user, int argc, char** argv) {
if (timestamp > user->client->last_sent_timestamp) if (timestamp > user->client->last_sent_timestamp)
return -1; return -1;
/* Update stored timestamp */ /* Only update lag calculations if timestamp is sane */
user->last_received_timestamp = timestamp; if (timestamp >= user->last_received_timestamp) {
/* Calculate length of frame, including network and processing lag */ /* Update stored timestamp */
frame_duration = current - timestamp; user->last_received_timestamp = timestamp;
/* Update lag statistics if at least one frame has been rendered */ /* Calculate length of frame, including network and processing lag */
if (user->last_frame_duration != 0) { frame_duration = current - timestamp;
/* Approximate processing lag by summing the frame duration deltas */ /* Update lag statistics if at least one frame has been rendered */
int processing_lag = user->processing_lag + frame_duration if (user->last_frame_duration != 0) {
- user->last_frame_duration;
/* Adjust back to zero if cumulative error leads to a negative value */ /* Calculate lag using the previous frame as a baseline */
if (processing_lag < 0) int processing_lag = frame_duration - user->last_frame_duration;
processing_lag = 0;
user->processing_lag = processing_lag; /* Adjust back to zero if cumulative error leads to a negative
* value */
if (processing_lag < 0)
processing_lag = 0;
user->processing_lag = processing_lag;
}
/* Record baseline duration of frame by excluding lag */
user->last_frame_duration = frame_duration - user->processing_lag;
} }
/* Record duration of frame */
user->last_frame_duration = frame_duration;
if (user->sync_handler) if (user->sync_handler)
return user->sync_handler(user, timestamp); return user->sync_handler(user, timestamp);
return 0; return 0;

View File

@ -832,6 +832,13 @@ static int guac_rdp_handle_connection(guac_client* client) {
break; break;
} while (wait_result > 0); } while (wait_result > 0);
/* Record end of frame, excluding server-side rendering time (we
* assume server-side rendering time will be consistent between any
* two subsequent frames, and that this time should thus be
* excluded from the required wait period of the next frame). */
last_frame_end = frame_start;
} }
/* If an error occurred, fail */ /* If an error occurred, fail */
@ -839,14 +846,11 @@ static int guac_rdp_handle_connection(guac_client* client) {
guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR,
"Connection closed."); "Connection closed.");
/* End of frame */ /* Flush frame */
guac_common_display_flush(rdp_client->display); guac_common_display_flush(rdp_client->display);
guac_client_end_frame(client); guac_client_end_frame(client);
guac_socket_flush(client->socket); guac_socket_flush(client->socket);
/* Record end of frame */
last_frame_end = guac_timestamp_current();
} }
pthread_mutex_lock(&(rdp_client->rdp_lock)); pthread_mutex_lock(&(rdp_client->rdp_lock));

View File

@ -380,6 +380,12 @@ void* guac_vnc_client_thread(void* data) {
} while (wait_result > 0); } while (wait_result > 0);
/* Record end of frame, excluding server-side rendering time (we
* assume server-side rendering time will be consistent between any
* two subsequent frames, and that this time should thus be
* excluded from the required wait period of the next frame). */
last_frame_end = frame_start;
} }
/* If an error occurs, log it and fail */ /* If an error occurs, log it and fail */
@ -391,9 +397,6 @@ void* guac_vnc_client_thread(void* data) {
guac_client_end_frame(client); guac_client_end_frame(client);
guac_socket_flush(client->socket); guac_socket_flush(client->socket);
/* Record end of frame */
last_frame_end = guac_timestamp_current();
} }
/* Kill client and finish connection */ /* Kill client and finish connection */