From 7455af1e41177541b501d848ba3f345cedc5db25 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 2 Sep 2024 18:09:29 +0200 Subject: [PATCH] Compute extrapolation time from last produced --- server/driver/history.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/driver/history.h b/server/driver/history.h index 90068d5b..5cb993b8 100644 --- a/server/driver/history.h +++ b/server/driver/history.h @@ -39,6 +39,7 @@ class history std::mutex mutex; std::list data; XrTime last_request; + XrTime last_produced; protected: history() : @@ -52,6 +53,7 @@ protected: std::lock_guard lock(mutex); bool active = produced - last_request < 1'000'000'000; + last_produced = std::max(produced, last_produced); // Discard outdated data, packets could be reordered if (not data.empty()) @@ -102,7 +104,7 @@ public: std::pair get_at(XrTime at_timestamp_ns) { std::lock_guard lock(mutex); - std::chrono::nanoseconds ex(0); + std::chrono::nanoseconds ex(std::max(0, at_timestamp_ns - last_produced)); last_request = at_timestamp_ns; @@ -139,14 +141,12 @@ public: { if (after->at_timestamp_ns > at_timestamp_ns) { - ex = std::chrono::nanoseconds(at_timestamp_ns - std::min(before->produced_timestamp, after->produced_timestamp)); float t = float(after->at_timestamp_ns - at_timestamp_ns) / (after->at_timestamp_ns - before->at_timestamp_ns); return {ex, Derived::interpolate(*before, *after, t)}; } } - ex = std::chrono::nanoseconds(at_timestamp_ns - data.back().produced_timestamp); if constexpr (extrapolate) { auto prev = data.rbegin();