passthru FB_face_tracking2

This commit is contained in:
galister
2024-08-19 16:35:26 +02:00
committed by xytovl
parent 7f1289bbb0
commit e6f3ae0113
18 changed files with 478 additions and 10 deletions
+2 -2
View File
@@ -94,7 +94,7 @@ public:
if (data.front().at_timestamp_ns > at_timestamp_ns)
{
if (extrapolate)
if constexpr (extrapolate)
{
auto second = data.begin();
auto first = second++;
@@ -116,7 +116,7 @@ public:
}
ex = std::chrono::nanoseconds(at_timestamp_ns - data.back().produced_timestamp);
if (extrapolate)
if constexpr (extrapolate)
{
auto prev = data.rbegin();
auto last = prev++;
+130
View File
@@ -0,0 +1,130 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2024 galister <galister@librevr.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wivrn_fb_face2_tracker.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "util/u_logging.h"
#include "xrt/xrt_results.h"
#include <cmath>
#include <cstring>
#include <openxr/openxr.h>
static void wivrn_fb_face2_tracker_destroy(xrt_device * xdev);
static void wivrn_fb_face2_tracker_update_inputs(xrt_device * xdev);
static xrt_result_t wivrn_fb_face2_tracker_get_face_tracking(struct xrt_device * xdev,
enum xrt_input_name facial_expression_type,
struct xrt_facial_expression_set * out_value);
wivrn_fb_face2_tracker::wivrn_fb_face2_tracker(xrt_device * hmd,
std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx) :
xrt_device{}, cnx(cnx)
{
xrt_device * base = this;
base->tracking_origin = hmd->tracking_origin;
base->get_face_tracking = wivrn_fb_face2_tracker_get_face_tracking;
base->update_inputs = wivrn_fb_face2_tracker_update_inputs;
base->destroy = wivrn_fb_face2_tracker_destroy;
name = XRT_DEVICE_FB_FACE_TRACKING2;
device_type = XRT_DEVICE_TYPE_FACE_TRACKER;
face_tracking_supported = true;
// Print name.
strcpy(str, "WiVRn FB v2 Face Tracker");
strcpy(serial, "WiVRn FB v2 Face Tracker");
// Setup input.
face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL;
face_input.active = true;
inputs = &face_input;
input_count = 1;
}
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)
{
if (!face.is_valid)
return;
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;
face_list.update_tracking(face.production_timestamp, face.timestamp, data, offset);
}
xrt_result_t wivrn_fb_face2_tracker::get_face_tracking(enum xrt_input_name facial_expression_type, struct xrt_facial_expression_set * inout_value)
{
if (facial_expression_type == XRT_INPUT_FB_FACE_TRACKING2_VISUAL)
{
auto [_, data] = face_list.get_at(inout_value->face_expression_set2_fb.sample_time_ns);
inout_value->face_expression_set2_fb.is_valid = data.is_valid;
if (not data.is_valid)
return XRT_SUCCESS;
inout_value->face_expression_set2_fb.is_eye_following_blendshapes_valid = data.is_eye_following_blendshapes_valid;
memcpy(&inout_value->face_expression_set2_fb.weights, data.weights.data(), sizeof(float) * data.weights.size());
memcpy(&inout_value->face_expression_set2_fb.confidences, data.confidences.data(), sizeof(float) * data.confidences.size());
inout_value->face_expression_set2_fb.data_source = XRT_FACE_TRACKING_DATA_SOURCE2_VISUAL_FB;
return XRT_SUCCESS;
}
return XRT_ERROR_NOT_IMPLEMENTED;
}
/*
*
* Functions
*
*/
static void wivrn_fb_face2_tracker_destroy(xrt_device * xdev)
{
static_cast<wivrn_fb_face2_tracker *>(xdev)->unregister();
}
static void wivrn_fb_face2_tracker_update_inputs(xrt_device * xdev)
{
static_cast<wivrn_fb_face2_tracker *>(xdev)->update_inputs();
}
static xrt_result_t wivrn_fb_face2_tracker_get_face_tracking(struct xrt_device * xdev,
enum xrt_input_name facial_expression_type,
struct xrt_facial_expression_set * inout_value)
{
return static_cast<wivrn_fb_face2_tracker *>(xdev)->get_face_tracking(facial_expression_type, inout_value);
}
+101
View File
@@ -0,0 +1,101 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2024 galister <galister@librevr.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_tracking.h"
#include "clock_offset.h"
#include "history.h"
#include "wivrn_session.h"
#include <cmath>
#include <memory>
#include <openxr/openxr.h>
struct wivrn_fb_face2_data
{
std::array<float, XRT_FACE_EXPRESSION2_COUNT_FB> weights;
std::array<float, XRT_FACE_CONFIDENCE2_COUNT_FB> confidences;
bool is_valid;
// only changes if the user disables eye tracking from
// the Quest's system settings at runtime. at that time,
// the old sample from before opening the Quest menu
// would be too old to be considered for interpolation
bool is_eye_following_blendshapes_valid;
};
class fb_face2_list : public history<fb_face2_list, wivrn_fb_face2_data>
{
public:
static wivrn_fb_face2_data interpolate(const wivrn_fb_face2_data & a, const wivrn_fb_face2_data & b, float t)
{
if (not a.is_valid)
{
// in case neither is valid, both will be zeroed,
// so return the later one for timestamp's sake
return b;
}
else if (not b.is_valid)
{
return a;
}
wivrn_fb_face2_data result = b;
for (size_t i = 0; i < result.weights.size(); i++)
{
result.weights[i] = std::clamp(std::lerp(a.weights[i], b.weights[i], t), 0.0f, 1.0f);
}
for (size_t i = 0; i < result.confidences.size(); i++)
{
result.confidences[i] = std::clamp(std::lerp(a.confidences[i], b.confidences[i], t), 0.0f, 1.0f);
}
return result;
}
void update_tracking(const XrTime & production_timestamp, const XrTime & timestamp, const wivrn_fb_face2_data & data, const clock_offset & offset)
{
this->add_sample(production_timestamp, timestamp, data, offset);
}
};
class wivrn_fb_face2_tracker : public xrt_device
{
fb_face2_list face_list;
xrt_input face_input;
std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx;
public:
wivrn_fb_face2_tracker(xrt_device * hmd, std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx);
void unregister()
{
cnx = nullptr;
}
void update_inputs();
void update_tracking(const from_headset::fb_face2 &, const clock_offset &);
xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, struct xrt_facial_expression_set * out_value);
};
+20
View File
@@ -32,6 +32,7 @@
#include "wivrn_comp_target.h"
#include "wivrn_controller.h"
#include "wivrn_eye_tracker.h"
#include "wivrn_fb_face2_tracker.h"
#include "wivrn_hmd.h"
#include "xrt/xrt_session.h"
@@ -144,6 +145,9 @@ xrt_result_t xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wi
if (self->hmd)
usysds->base.base.static_roles.head = devices->xdevs[n++] = self->hmd.get();
if (self->hmd->face_tracking_supported)
usysds->base.base.static_roles.face = self->hmd.get();
if (self->left_hand)
{
devices->xdevs[n++] = self->left_hand.get();
@@ -160,6 +164,12 @@ xrt_result_t xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wi
usysds->base.base.static_roles.eyes = self->eye_tracker.get();
devices->xdevs[n++] = self->eye_tracker.get();
}
if (info.face_tracking2_fb)
{
self->fb_face2_tracker = std::make_unique<wivrn_fb_face2_tracker>(self->hmd.get(), self);
usysds->base.base.static_roles.face = self->fb_face2_tracker.get();
devices->xdevs[n++] = self->fb_face2_tracker.get();
}
devices->xdev_count = n;
u_system_devices_static_finalize(usysds, self->left_hand.get(), self->right_hand.get());
@@ -267,7 +277,17 @@ 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();
if (not offset)
return;
fb_face2_tracker->update_tracking(fb_face2, offset);
}
void wivrn_session::operator()(from_headset::inputs && inputs)
{
auto offset = get_offset();
+3
View File
@@ -33,6 +33,7 @@
class wivrn_hmd;
class wivrn_controller;
class wivrn_eye_tracker;
class wivrn_fb_face2_tracker;
struct audio_device;
struct u_system;
@@ -81,6 +82,7 @@ class wivrn_session : public std::enable_shared_from_this<wivrn_session>
std::unique_ptr<wivrn_controller> left_hand;
std::unique_ptr<wivrn_controller> right_hand;
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
wivrn_comp_target * comp_target;
clock_offset_estimator offset_est;
@@ -114,6 +116,7 @@ public:
void operator()(from_headset::headset_info_packet &&);
void operator()(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 &&);