diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index b8412bb4..da1b9643 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -455,6 +455,8 @@ void scenes::stream::render(const XrFrameState & frame_state) display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod; display_time_period = frame_state.predictedDisplayPeriod; + real_display_period = last_display_time ? frame_state.predictedDisplayTime - last_display_time : frame_state.predictedDisplayPeriod; + last_display_time = frame_state.predictedDisplayTime; std::shared_lock lock(decoder_mutex); if (decoders.empty() or not frame_state.shouldRender) diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 02a3cbd1..de4ce922 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -89,6 +89,8 @@ private: std::atomic recenter_requested = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; + XrTime last_display_time = 0; + std::atomic real_display_period = 0; std::optional tracking_thread; std::shared_mutex decoder_mutex; diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index e0ef5bcb..d44a6fe0 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -186,7 +186,9 @@ void scenes::stream::tracking() XrSpace view_space = application::space(xr::spaces::view); XrSpace world_space = application::space(xr::spaces::world); - XrDuration tracking_period = min_tracking_period; + XrDuration tracking_period = min_tracking_period; // target period for 20% busy time + XrDuration current_tracking_period = tracking_period; // divider of frame period + int period_adjust = 0; XrTime t0 = instance.now(); XrTime last_hand_sample = t0; @@ -288,7 +290,7 @@ void scenes::stream::tracking() XrDuration busy_time = t.count(); // Target: polling between 1 and 5ms, with 20% busy time - tracking_period = std::clamp(std::lerp(tracking_period, busy_time * 5, 0.2), min_tracking_period, max_tracking_period); + tracking_period = std::clamp(std::lerp(tracking_period, busy_time * 5, 0.1), min_tracking_period, max_tracking_period); #ifdef __ANDROID__ if (next_battery_check < now and control.enabled[size_t(tid::battery)]) @@ -335,7 +337,18 @@ void scenes::stream::tracking() network_session->send_stream(std::move(packets)); - t0 += tracking_period; + if (period_adjust == 0) + { + if (auto p = real_display_period.load()) + { + period_adjust = (p / tracking_period); + current_tracking_period = p / period_adjust; + } + } + else + --period_adjust; + + t0 += current_tracking_period; } catch (std::exception & e) {