Put not requested tracking on standby
This commit is contained in:
@@ -80,7 +80,8 @@ private:
|
||||
std::thread network_thread;
|
||||
std::mutex local_floor_mutex;
|
||||
xr::space local_floor;
|
||||
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset = 0;
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control;
|
||||
std::atomic<XrDuration> display_time_phase = 0;
|
||||
std::atomic<XrDuration> display_time_period = 0;
|
||||
std::optional<std::thread> tracking_thread;
|
||||
@@ -138,7 +139,7 @@ public:
|
||||
void operator()(to_headset::video_stream_data_shard &&);
|
||||
void operator()(to_headset::haptics &&);
|
||||
void operator()(to_headset::timesync_query &&);
|
||||
void operator()(to_headset::prediction_offset &&);
|
||||
void operator()(to_headset::tracking_control &&);
|
||||
void operator()(to_headset::audio_stream_description &&);
|
||||
void operator()(to_headset::video_stream_description &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
@@ -313,7 +313,10 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
|
||||
}
|
||||
|
||||
ImPlot::PopStyleColor(5);
|
||||
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), tracking_prediction_offset.load() / 1'000'000).c_str());
|
||||
{
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.offset).count()).c_str());
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
return imgui_ctx->end_frame();
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "jnipp.h"
|
||||
#endif
|
||||
|
||||
using tid = to_headset::tracking_control::id;
|
||||
|
||||
static from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpace reference, XrTime time)
|
||||
{
|
||||
XrSpaceVelocity velocity{
|
||||
@@ -137,6 +139,26 @@ static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static bool enabled(const to_headset::tracking_control & control, device_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case device_id::HEAD:
|
||||
return true;
|
||||
case device_id::LEFT_AIM:
|
||||
return control.enabled[size_t(tid::left_aim)];
|
||||
case device_id::LEFT_GRIP:
|
||||
return control.enabled[size_t(tid::left_grip)];
|
||||
case device_id::RIGHT_AIM:
|
||||
return control.enabled[size_t(tid::right_aim)];
|
||||
case device_id::RIGHT_GRIP:
|
||||
return control.enabled[size_t(tid::right_grip)];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void scenes::stream::tracking()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
@@ -200,7 +222,13 @@ void scenes::stream::tracking()
|
||||
t.resume();
|
||||
};
|
||||
|
||||
XrDuration prediction = std::min<XrDuration>(tracking_prediction_offset, 80'000'000);
|
||||
to_headset::tracking_control control;
|
||||
{
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
control = tracking_control;
|
||||
}
|
||||
|
||||
XrDuration prediction = std::min<XrDuration>(control.offset.count(), 80'000'000);
|
||||
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
|
||||
for (XrDuration Δt = 0; Δt <= prediction + period / 2; Δt += period, ++samples)
|
||||
{
|
||||
@@ -232,23 +260,30 @@ void scenes::stream::tracking()
|
||||
std::lock_guard lock(local_floor_mutex);
|
||||
for (auto [device, space]: spaces)
|
||||
{
|
||||
packet.device_poses.push_back(locate_space(device, space, local_floor, t0 + Δt));
|
||||
if (enabled(control, device))
|
||||
packet.device_poses.push_back(locate_space(device, space, local_floor, t0 + Δt));
|
||||
}
|
||||
|
||||
send_stream(packet);
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
|
||||
hands.joints = locate_hands(application::get_left_hand(), local_floor, hands.timestamp);
|
||||
send_stream(hands);
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
{
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
|
||||
hands.joints = locate_hands(application::get_left_hand(), local_floor, hands.timestamp);
|
||||
send_stream(hands);
|
||||
}
|
||||
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
|
||||
hands.joints = locate_hands(application::get_right_hand(), local_floor, hands.timestamp);
|
||||
send_stream(hands);
|
||||
if (control.enabled[size_t(tid::right_hand)])
|
||||
{
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
|
||||
hands.joints = locate_hands(application::get_right_hand(), local_floor, hands.timestamp);
|
||||
send_stream(hands);
|
||||
}
|
||||
}
|
||||
|
||||
if (application::get_fb_face_tracking2_supported())
|
||||
if (application::get_fb_face_tracking2_supported() and control.enabled[size_t(tid::face)])
|
||||
{
|
||||
application::get_fb_face_tracker2().get_weights(t0 + Δt, &fb_face2);
|
||||
send_stream(fb_face2);
|
||||
@@ -278,7 +313,7 @@ void scenes::stream::tracking()
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
if (next_battery_check < now)
|
||||
if (next_battery_check < now and control.enabled[size_t(tid::battery)])
|
||||
{
|
||||
timer t2(instance);
|
||||
from_headset::battery battery{};
|
||||
@@ -317,8 +352,8 @@ void scenes::stream::tracking()
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::prediction_offset && packet)
|
||||
void scenes::stream::operator()(to_headset::tracking_control && packet)
|
||||
{
|
||||
if (packet.offset.count() >= 0)
|
||||
tracking_prediction_offset = std::lerp(packet.offset.count(), tracking_prediction_offset.load(), 0.2);
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
tracking_control = packet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user