GUACAMOLE-172: Ignore insane timestamps when calculating lag.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/6131ad03 Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/6131ad03 Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/6131ad03 Branch: refs/heads/master Commit: 6131ad03413aadf6667762f20dd28351f80c382a Parents: 234f987 Author: Michael Jumper <[email protected]> Authored: Sun Jan 15 13:59:15 2017 -0800 Committer: Michael Jumper <[email protected]> Committed: Tue Jan 24 00:18:10 2017 -0800 ---------------------------------------------------------------------- src/libguac/user-handlers.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/6131ad03/src/libguac/user-handlers.c ---------------------------------------------------------------------- diff --git a/src/libguac/user-handlers.c b/src/libguac/user-handlers.c index 40ccb89..4f1f59b 100644 --- a/src/libguac/user-handlers.c +++ b/src/libguac/user-handlers.c @@ -95,28 +95,34 @@ 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);
