From c19eab9691cd7c048a56171db401712ab0b7c1c8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 31 Aug 2021 10:47:35 -0700 Subject: [PATCH] GUACAMOLE-377: Revise processing lag calculations to consider cumulative processing lag. --- src/libguac/user-handlers.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/libguac/user-handlers.c b/src/libguac/user-handlers.c index c5cad9df..156b039e 100644 --- a/src/libguac/user-handlers.c +++ b/src/libguac/user-handlers.c @@ -120,31 +120,39 @@ int __guac_handle_sync(guac_user* user, int argc, char** argv) { /* Calculate length of frame, including network and processing lag */ frame_duration = current - timestamp; - /* Update lag statistics if at least one frame has been rendered */ + /* Calculate processing lag portion of length of frame */ + int frame_processing_lag = 0; if (user->last_frame_duration != 0) { /* Calculate lag using the previous frame as a baseline */ - int processing_lag = frame_duration - user->last_frame_duration; + frame_processing_lag = frame_duration - user->last_frame_duration; /* Adjust back to zero if cumulative error leads to a negative * value */ - if (processing_lag < 0) - processing_lag = 0; - - user->processing_lag = processing_lag; + if (frame_processing_lag < 0) + frame_processing_lag = 0; } - /* 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 (this is the + * network round-trip time) */ + int estimated_rtt = frame_duration - frame_processing_lag; + user->last_frame_duration = estimated_rtt; + + /* Calculate cumulative accumulated processing lag relative to server timeline */ + int processing_lag = current - user->last_received_timestamp - estimated_rtt; + if (processing_lag < 0) + processing_lag = 0; + + user->processing_lag = processing_lag; } /* Log received timestamp and calculated lag (at TRACE level only) */ guac_user_log(user, GUAC_LOG_TRACE, "User confirmation of frame %" PRIu64 "ms received " - "at %" PRIu64 "ms (processing_lag=%ims)", - timestamp, current, user->processing_lag); + "at %" PRIu64 "ms (processing_lag=%ims, estimated_rtt=%ims)", + timestamp, current, user->processing_lag, user->last_frame_duration); if (user->sync_handler) return user->sync_handler(user, timestamp);