Pack multiple tracking items per datagram

This commit is contained in:
Patrick Nicolas
2024-10-02 23:58:13 +02:00
parent 5f359dc6d7
commit c370d19469
9 changed files with 76 additions and 70 deletions
+3 -3
View File
@@ -611,7 +611,7 @@ static void ScrollWhenDraggingOnVoid(ImVec2 delta)
static auto face_weights()
{
using weights = decltype(xrt::drivers::wivrn::from_headset::fb_face2{}.weights);
using weights = decltype(xrt::drivers::wivrn::from_headset::tracking::fb_face2{}.weights);
using item = std::pair<const char *, std::array<float, XR_FACE_EXPRESSION2_COUNT_FB>>;
std::vector<item> res;
@@ -794,8 +794,8 @@ static auto face_weights()
static const char * get_face_icon(XrTime predicted_display_time)
{
static const auto w = face_weights();
xrt::drivers::wivrn::from_headset::fb_face2 expression;
application::get_fb_face_tracker2().get_weights(predicted_display_time, &expression);
xrt::drivers::wivrn::from_headset::tracking::fb_face2 expression;
application::get_fb_face_tracker2().get_weights(predicted_display_time, expression);
if (not expression.is_valid)
return ICON_FA_FACE_MEH;
+27 -14
View File
@@ -43,10 +43,10 @@ static from_headset::tracking::pose locate_space(device_id device, XrSpace space
xrLocateSpace(space, reference, time, &location);
from_headset::tracking::pose res{
.device = device,
.pose = location.pose,
.linear_velocity = velocity.linearVelocity,
.angular_velocity = velocity.angularVelocity,
.device = device,
.flags = 0,
};
@@ -77,7 +77,6 @@ class timer
{
xr::instance & instance;
XrTime start = instance.now();
XrDuration duration = 0;
public:
timer(xr::instance & instance) :
@@ -193,7 +192,6 @@ void scenes::stream::tracking()
XrTime t0 = instance.now();
std::vector<from_headset::tracking> tracking;
std::vector<from_headset::hand_tracking> hands;
std::vector<from_headset::fb_face2> face;
int skip_samples = 0;
while (not exiting)
@@ -202,7 +200,6 @@ void scenes::stream::tracking()
{
tracking.clear();
hands.clear();
face.clear();
XrTime now = instance.now();
if (now < t0)
@@ -271,11 +268,7 @@ void scenes::stream::tracking()
if (application::get_fb_face_tracking2_supported() and control.enabled[size_t(tid::face)])
{
auto & fb_face2 = face.emplace_back();
fb_face2.production_timestamp = t0;
fb_face2.timestamp = t0 + Δt;
application::get_fb_face_tracker2().get_weights(t0 + Δt, &fb_face2);
application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace());
}
}
catch (const std::system_error & e)
@@ -331,14 +324,34 @@ void scenes::stream::tracking()
}
#endif
std::vector<from_headset::trackings> merged_tracking(1);
size_t current_size = 0;
for (auto & item: tracking)
{
size_t size =
3 * 8 // XrTime, XrViewStateFlags
+ 1 // state_flags
+ 88 // views
+ 2 + item.device_poses.size() * 54 // size + data
+ 1 + (item.face ? 70 * 4 * 2 + 2 : 0); // face
if (size + current_size > 1400)
{
merged_tracking.emplace_back();
current_size = 0;
}
current_size += size;
merged_tracking.back().items.push_back(std::move(item));
}
std::vector<serialization_packet> packets;
packets.reserve(tracking.size() + hands.size() + face.size());
for (const auto & i: tracking)
packets.reserve(merged_tracking.size() + hands.size());
for (const auto & i: merged_tracking)
wivrn_session::stream_socket_t::serialize(packets.emplace_back(), i);
for (const auto & i: hands)
wivrn_session::stream_socket_t::serialize(packets.emplace_back(), i);
for (const auto & i: face)
wivrn_session::stream_socket_t::serialize(packets.emplace_back(), i);
{
if (i.joints)
wivrn_session::stream_socket_t::serialize(packets.emplace_back(), i);
}
network_session->send_stream(std::span(packets));
+7 -7
View File
@@ -35,7 +35,7 @@ xr::fb_face_tracker2::fb_face_tracker2(instance & inst, XrFaceTracker2FB h)
xrDestroyFaceTracker2FB = inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB");
}
void xr::fb_face_tracker2::get_weights(XrTime time, xrt::drivers::wivrn::from_headset::fb_face2 * out_expressions)
void xr::fb_face_tracker2::get_weights(XrTime time, xrt::drivers::wivrn::from_headset::tracking::fb_face2 & out_expressions)
{
if (!id || !xrGetFaceExpressionWeights2FB)
return;
@@ -49,14 +49,14 @@ void xr::fb_face_tracker2::get_weights(XrTime time, xrt::drivers::wivrn::from_he
XrFaceExpressionWeights2FB expression_weights{
.type = XR_TYPE_FACE_EXPRESSION_WEIGHTS2_FB,
.next = nullptr,
.weightCount = (uint32_t)out_expressions->weights.size(),
.weights = out_expressions->weights.data(),
.confidenceCount = (uint32_t)out_expressions->confidences.size(),
.confidences = out_expressions->confidences.data(),
.weightCount = (uint32_t)out_expressions.weights.size(),
.weights = out_expressions.weights.data(),
.confidenceCount = (uint32_t)out_expressions.confidences.size(),
.confidences = out_expressions.confidences.data(),
};
CHECK_XR(xrGetFaceExpressionWeights2FB(id, &info, &expression_weights));
out_expressions->is_valid = expression_weights.isValid;
out_expressions->is_eye_following_blendshapes_valid = expression_weights.isEyeFollowingBlendshapesValid;
out_expressions.is_valid = expression_weights.isValid;
out_expressions.is_eye_following_blendshapes_valid = expression_weights.isEyeFollowingBlendshapesValid;
}
+2 -13
View File
@@ -18,11 +18,8 @@
#pragma once
#include "../common/wivrn_packets.h"
#include "utils/handle.h"
#include <array>
#include <optional>
#include <utility>
#include "wivrn_packets.h"
#include <openxr/openxr.h>
#include "instance.h"
@@ -39,15 +36,7 @@ class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB, destroy_fb_face_
public:
fb_face_tracker2() = default;
fb_face_tracker2(instance & inst, XrFaceTracker2FB h);
fb_face_tracker2(fb_face_tracker2 &&) = default;
fb_face_tracker2 & operator=(fb_face_tracker2 &&) = default;
~fb_face_tracker2()
{
if (id != XR_NULL_HANDLE && xrDestroyFaceTracker2FB)
xrDestroyFaceTracker2FB(id);
}
void get_weights(XrTime time, struct xrt::drivers::wivrn::from_headset::fb_face2 * out_expressions);
void get_weights(XrTime time, struct xrt::drivers::wivrn::from_headset::tracking::fb_face2 & out_expressions);
};
} // namespace xr
+16 -12
View File
@@ -138,10 +138,10 @@ struct tracking
struct pose
{
device_id device;
XrPosef pose;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
device_id device;
uint8_t flags;
};
@@ -160,6 +160,20 @@ struct tracking
std::array<view, 2> views;
std::vector<pose> device_poses;
struct fb_face2
{
std::array<float, XR_FACE_EXPRESSION2_COUNT_FB> weights;
std::array<float, XR_FACE_CONFIDENCE2_COUNT_FB> confidences;
bool is_valid;
bool is_eye_following_blendshapes_valid;
};
std::optional<fb_face2> face;
};
struct trackings
{
std::vector<tracking> items;
};
struct hand_tracking
@@ -195,16 +209,6 @@ struct hand_tracking
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> joints;
};
struct fb_face2
{
std::array<float, XR_FACE_EXPRESSION2_COUNT_FB> weights;
std::array<float, XR_FACE_CONFIDENCE2_COUNT_FB> confidences;
XrTime production_timestamp;
XrTime timestamp;
bool is_valid;
bool is_eye_following_blendshapes_valid;
};
struct inputs
{
struct input_value
@@ -245,7 +249,7 @@ struct battery
bool charging;
};
using packets = std::variant<headset_info_packet, feedback, audio_data, handshake, tracking, hand_tracking, fb_face2, inputs, timesync_response, battery>;
using packets = std::variant<headset_info_packet, feedback, audio_data, handshake, tracking, trackings, hand_tracking, inputs, timesync_response, battery>;
} // namespace from_headset
namespace to_headset
+10 -8
View File
@@ -70,18 +70,20 @@ void wivrn_fb_face2_tracker::update_inputs()
// Empty
}
void wivrn_fb_face2_tracker::update_tracking(const from_headset::fb_face2 & face, const clock_offset & offset)
void wivrn_fb_face2_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
if (!face.is_valid)
if (not(tracking.face and tracking.face->is_valid))
return;
const auto & face = *tracking.face;
wivrn_fb_face2_data data;
data.is_valid = face.is_valid;
data.is_eye_following_blendshapes_valid = face.is_eye_following_blendshapes_valid;
data.weights = face.weights;
data.confidences = face.confidences;
wivrn_fb_face2_data data{
.weights = face.weights,
.confidences = face.confidences,
.is_valid = face.is_valid,
.is_eye_following_blendshapes_valid = face.is_eye_following_blendshapes_valid,
};
if (not face_list.update_tracking(face.production_timestamp, face.timestamp, data, offset))
if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset))
cnx->set_enabled(to_headset::tracking_control::id::face, false);
}
+1 -1
View File
@@ -96,6 +96,6 @@ public:
}
void update_inputs();
void update_tracking(const from_headset::fb_face2 &, const clock_offset &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value);
};
+8 -10
View File
@@ -293,7 +293,12 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
{
U_LOG_W("unexpected headset info packet, ignoring");
}
void wivrn_session::operator()(from_headset::tracking && tracking)
void wivrn_session::operator()(from_headset::trackings && tracking)
{
for (auto & item: tracking.items)
(*this)(item);
}
void wivrn_session::operator()(const from_headset::tracking & tracking)
{
if (tracking.state_flags & from_headset::tracking::state_flags::recentered)
{
@@ -339,6 +344,8 @@ void wivrn_session::operator()(from_headset::tracking && tracking)
eye_tracker->update_tracking(tracking, offset);
if (foveation)
foveation->update_tracking(tracking, offset);
if (fb_face2_tracker)
fb_face2_tracker->update_tracking(tracking, offset);
}
void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
@@ -348,15 +355,6 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
left_hand->update_hand_tracking(hand_tracking, offset);
right_hand->update_hand_tracking(hand_tracking, offset);
}
void wivrn_session::operator()(from_headset::fb_face2 && fb_face2)
{
if (not fb_face2_tracker)
return;
auto offset = offset_est.get_offset();
fb_face2_tracker->update_tracking(fb_face2, offset);
}
void wivrn_session::operator()(from_headset::inputs && inputs)
{
auto offset = get_offset();
+2 -2
View File
@@ -137,9 +137,9 @@ public:
void operator()(from_headset::handshake &&) {}
void operator()(from_headset::headset_info_packet &&);
void operator()(from_headset::tracking &&);
void operator()(from_headset::trackings &&);
void operator()(const from_headset::tracking &);
void operator()(from_headset::hand_tracking &&);
void operator()(from_headset::fb_face2 &&);
void operator()(from_headset::inputs &&);
void operator()(from_headset::timesync_response &&);
void operator()(from_headset::feedback &&);