From 6131ad03413aadf6667762f20dd28351f80c382a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 15 Jan 2017 13:59:15 -0800 Subject: [PATCH] GUACAMOLE-172: Ignore insane timestamps when calculating lag. --- src/libguac/user-handlers.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/libguac/user-handlers.c b/src/libguac/user-handlers.c index 40ccb893..4f1f59b0 100644 --- a/src/libguac/user-handlers.c +++ b/src/libguac/user-handlers.c @@ -95,29 +95,35 @@ int __guac_handle_sync(guac_user* user, int argc, char** argv) { if (timestamp > user->client->last_sent_timestamp) return -1; - /* Update stored timestamp */ - user->last_received_timestamp = timestamp; + /* Only update lag calculations if timestamp is sane */ + if (timestamp >= user->last_received_timestamp) { - /* Calculate length of frame, including network and processing lag */ - frame_duration = current - timestamp; + /* Update stored timestamp */ + user->last_received_timestamp = timestamp; - /* Update lag statistics if at least one frame has been rendered */ - if (user->last_frame_duration != 0) { + /* Calculate length of frame, including network and processing lag */ + frame_duration = current - timestamp; - /* Calculate lag using the previous frame as a baseline */ - int processing_lag = frame_duration - user->last_frame_duration; + /* Update lag statistics if at least one frame has been rendered */ + if (user->last_frame_duration != 0) { - /* Adjust back to zero if cumulative error leads to a negative value */ - if (processing_lag < 0) - processing_lag = 0; + /* Calculate lag using the previous frame as a baseline */ + int processing_lag = frame_duration - user->last_frame_duration; - 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 baseline duration of frame by excluding lag */ - user->last_frame_duration = frame_duration - user->processing_lag; - if (user->sync_handler) return user->sync_handler(user, timestamp); return 0;