From e6f3ae0113a086ad9ba4bcab3349f2b9a619aa50 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:32:06 +0900 Subject: [PATCH] passthru FB_face_tracking2 --- AndroidManifest.xml | 2 + client/application.cpp | 13 +++ client/application.h | 14 +++ client/scenes/stream.cpp | 1 + client/scenes/stream_tracking.cpp | 11 ++ client/xr/fb_face_tracker2.cpp | 62 +++++++++++ client/xr/fb_face_tracker2.h | 53 +++++++++ client/xr/session.cpp | 22 ++++ client/xr/session.h | 2 + client/xr/system.cpp | 18 ++++ client/xr/system.h | 1 + common/wivrn_packets.h | 13 ++- server/CMakeLists.txt | 18 ++-- server/driver/history.h | 4 +- server/driver/wivrn_fb_face2_tracker.cpp | 130 +++++++++++++++++++++++ server/driver/wivrn_fb_face2_tracker.h | 101 ++++++++++++++++++ server/driver/wivrn_session.cpp | 20 ++++ server/driver/wivrn_session.h | 3 + 18 files changed, 478 insertions(+), 10 deletions(-) create mode 100644 client/xr/fb_face_tracker2.cpp create mode 100644 client/xr/fb_face_tracker2.h create mode 100644 server/driver/wivrn_fb_face2_tracker.cpp create mode 100644 server/driver/wivrn_fb_face2_tracker.h diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b1ecee87..17d8c678 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -32,10 +32,12 @@ + + diff --git a/client/application.cpp b/client/application.cpp index 1d0fdace..2a57c845 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -741,6 +741,7 @@ void application::initialize() opt_extensions.push_back(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME); opt_extensions.push_back(XR_FB_PASSTHROUGH_EXTENSION_NAME); opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME); + opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME); for (const auto & i: interaction_profiles) { @@ -800,6 +801,13 @@ void application::initialize() eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction; } + if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) + { + XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); + spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); + fb_face_tracking2_supported = fb_face2_properties.supportsVisualFaceTracking; + } + switch (xr_system_id.passthrough_supported()) { case xr::system::passthrough_type::no_passthrough: @@ -848,6 +856,11 @@ void application::initialize() right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); } + if (fb_face_tracking2_supported) + { + fb_face_tracker2 = xr_session.create_fb_face_tracker2(); + } + vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; diff --git a/client/application.h b/client/application.h index cd7eca70..a66b0f71 100644 --- a/client/application.h +++ b/client/application.h @@ -20,6 +20,7 @@ #pragma once #include "configuration.h" +#include "xr/fb_face_tracker2.h" #include "xr/hand_tracker.h" #ifdef __ANDROID__ #include @@ -127,6 +128,9 @@ class application : public singleton xr::hand_tracker left_hand; xr::hand_tracker right_hand; + bool fb_face_tracking2_supported = false; + xr::fb_face_tracker2 fb_face_tracker2; + bool eye_gaze_supported = false; bool session_running = false; @@ -412,6 +416,11 @@ public: return instance().hand_tracking_supported; } + static bool get_fb_face_tracking2_supported() + { + return instance().fb_face_tracking2_supported; + } + static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -427,6 +436,11 @@ public: return instance().right_hand; } + static xr::fb_face_tracker2 & get_fb_face_tracker2() + { + return instance().fb_face_tracker2; + } + static const std::vector & get_xr_extensions() { return instance().xr_extensions; diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 7cb7ac54..384267cf 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -121,6 +121,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptr(1, prediction)) { from_headset::hand_tracking hands{}; + from_headset::fb_face2 fb_face2{}; packet.production_timestamp = t0; hands.production_timestamp = t0; + fb_face2.production_timestamp = t0; packet.timestamp = t0 + Δt; hands.timestamp = t0 + Δt; + fb_face2.timestamp = t0 + Δt; try { @@ -243,6 +246,14 @@ void scenes::stream::tracking() t.resume(); } + if (application::get_fb_face_tracking2_supported()) + { + application::get_fb_face_tracker2().get_weights(t0 + Δt, &fb_face2); + t.pause(); + network_session->send_stream(fb_face2); + t.resume(); + } + 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), 1'000'000, 5'000'000); diff --git a/client/xr/fb_face_tracker2.cpp b/client/xr/fb_face_tracker2.cpp new file mode 100644 index 00000000..46c6ca8d --- /dev/null +++ b/client/xr/fb_face_tracker2.cpp @@ -0,0 +1,62 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 galister + * + * 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 . + */ + +#include "fb_face_tracker2.h" +#include "wivrn_packets.h" +#include +#include + +static PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{}; + +XrResult xr::destroy_fb_face_tracker2(XrFaceTracker2FB id) +{ + return xrDestroyFaceTracker2FB(id); +} + +xr::fb_face_tracker2::fb_face_tracker2(instance & inst, XrFaceTracker2FB h) +{ + id = h; + xrGetFaceExpressionWeights2FB = inst.get_proc("xrGetFaceExpressionWeights2FB"); + xrDestroyFaceTracker2FB = inst.get_proc("xrDestroyFaceTracker2FB"); +} + +void xr::fb_face_tracker2::get_weights(XrTime time, xrt::drivers::wivrn::from_headset::fb_face2 * out_expressions) +{ + if (!id || !xrGetFaceExpressionWeights2FB) + return; + + XrFaceExpressionInfo2FB info{ + .type = XR_TYPE_FACE_EXPRESSION_INFO2_FB, + .next = nullptr, + .time = time, + }; + + 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(), + }; + + CHECK_XR(xrGetFaceExpressionWeights2FB(id, &info, &expression_weights)); + + out_expressions->is_valid = expression_weights.isValid; + out_expressions->is_eye_following_blendshapes_valid = expression_weights.isEyeFollowingBlendshapesValid; +} diff --git a/client/xr/fb_face_tracker2.h b/client/xr/fb_face_tracker2.h new file mode 100644 index 00000000..38713124 --- /dev/null +++ b/client/xr/fb_face_tracker2.h @@ -0,0 +1,53 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 galister + * + * 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 . + */ + +#pragma once + +#include "../common/wivrn_packets.h" +#include "utils/handle.h" +#include +#include +#include +#include + +#include "instance.h" + +namespace xr +{ +XrResult destroy_fb_face_tracker2(XrFaceTracker2FB); + +class fb_face_tracker2 : public utils::handle +{ + PFN_xrGetFaceExpressionWeights2FB xrGetFaceExpressionWeights2FB{}; + PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{}; + +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); +}; +} // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index 15d13bba..3af37a1f 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -94,6 +94,28 @@ xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSet }}; } +xr::fb_face_tracker2 xr::session::create_fb_face_tracker2() +{ + XrFaceTrackingDataSource2FB data_sources[1]; + data_sources[0] = XR_FACE_TRACKING_DATA_SOURCE2_VISUAL_FB; + + XrFaceTrackerCreateInfo2FB create_info{ + .type = XR_TYPE_FACE_TRACKER_CREATE_INFO2_FB, + .next = nullptr, + .faceExpressionSet = XR_FACE_EXPRESSION_SET2_DEFAULT_FB, + .requestedDataSourceCount = 1, + .requestedDataSources = data_sources, + }; + + XrFaceTracker2FB ft; + + auto xrCreateFaceTracker2FB = inst->get_proc("xrCreateFaceTracker2FB"); + assert(xrCreateFaceTracker2FB); + + CHECK_XR(xrCreateFaceTracker2FB(id, &create_info, &ft)); + return {*inst, ft}; +} + std::vector xr::session::get_swapchain_formats() const { std::vector formats; diff --git a/client/xr/session.h b/client/xr/session.h index af22da9f..1f689aa2 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -26,6 +26,7 @@ #include #include +#include "fb_face_tracker2.h" #include "hand_tracker.h" #include "space.h" @@ -46,6 +47,7 @@ public: space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}}); space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}}); hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT); + fb_face_tracker2 create_fb_face_tracker2(); std::vector get_swapchain_formats() const; diff --git a/client/xr/system.cpp b/client/xr/system.cpp index fb71ccd3..00217a4c 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -105,6 +105,24 @@ XrSystemEyeGazeInteractionPropertiesEXT xr::system::eye_gaze_interaction_propert return eye_gaze_prop; } +XrSystemFaceTrackingProperties2FB xr::system::fb_face_tracking2_properties() const +{ + if (!id) + throw std::invalid_argument("this"); + + XrSystemFaceTrackingProperties2FB face_tracking_prop{ + .type = XR_TYPE_SYSTEM_FACE_TRACKING_PROPERTIES2_FB, + }; + + XrSystemProperties prop{ + .type = XR_TYPE_SYSTEM_PROPERTIES, + .next = &face_tracking_prop, + }; + CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); + + return face_tracking_prop; +} + xr::system::passthrough_type xr::system::passthrough_supported() const { if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND)) diff --git a/client/xr/system.h b/client/xr/system.h index 7e959e75..e41c4c36 100644 --- a/client/xr/system.h +++ b/client/xr/system.h @@ -62,6 +62,7 @@ public: XrSystemProperties properties() const; XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const; XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const; + XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const; passthrough_type passthrough_supported() const; XrGraphicsRequirementsVulkan2KHR graphics_requirements() const; diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 5c8f26ae..dca9c097 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -109,6 +109,7 @@ struct headset_info_packet std::array fov; bool hand_tracking; bool eye_gaze; + bool face_tracking2_fb; }; struct handshake @@ -185,6 +186,16 @@ struct hand_tracking std::optional> joints; }; +struct fb_face2 +{ + std::array weights; + std::array confidences; + XrTime production_timestamp; + XrTime timestamp; + bool is_valid; + bool is_eye_following_blendshapes_valid; +}; + struct inputs { struct input_value @@ -225,7 +236,7 @@ struct battery bool charging; }; -using packets = std::variant; +using packets = std::variant; } // namespace from_headset namespace to_headset diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 6693b9e5..a86571a3 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -23,13 +23,16 @@ set(XRT_BUILD_DRIVER_WMR OFF) set(XRT_BUILD_DRIVER_XREAL_AIR OFF) set(XRT_BUILD_SAMPLES OFF) -set(XRT_FEATURE_COMPOSITOR_NULL OFF) -set(XRT_FEATURE_SERVICE ON) -set(XRT_FEATURE_SERVICE_SYSTEMD OFF) -set(XRT_FEATURE_SLAM OFF) -set(XRT_FEATURE_STEAMVR_PLUGIN OFF) -set(XRT_FEATURE_WINDOW_PEEK OFF) -set(XRT_FEATURE_STEAMVR_PLUGIN OFF) +set(XRT_FEATURE_COMPOSITOR_NULL OFF) +set(XRT_FEATURE_SERVICE ON) +set(XRT_FEATURE_SERVICE_SYSTEMD OFF) +set(XRT_FEATURE_SLAM OFF) +set(XRT_FEATURE_STEAMVR_PLUGIN OFF) +set(XRT_FEATURE_WINDOW_PEEK OFF) +set(XRT_FEATURE_STEAMVR_PLUGIN OFF) +set(XRT_FEATURE_WINDOW_PEEK OFF) +set(XRT_FEATURE_WINDOW_PEEK OFF) +set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON) set(XRT_HAVE_BLUETOOTH OFF) set(XRT_HAVE_GST OFF) @@ -77,6 +80,7 @@ add_executable(wivrn-server driver/wivrn_comp_target.cpp driver/wivrn_controller.cpp driver/wivrn_eye_tracker.cpp + driver/wivrn_fb_face2_tracker.cpp driver/pose_list.cpp driver/view_list.cpp driver/hand_joints_list.cpp diff --git a/server/driver/history.h b/server/driver/history.h index 6c4fb688..9f38d58e 100644 --- a/server/driver/history.h +++ b/server/driver/history.h @@ -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++; diff --git a/server/driver/wivrn_fb_face2_tracker.cpp b/server/driver/wivrn_fb_face2_tracker.cpp new file mode 100644 index 00000000..d48660d7 --- /dev/null +++ b/server/driver/wivrn_fb_face2_tracker.cpp @@ -0,0 +1,130 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas + * Copyright (C) 2024 galister + * + * 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 . + */ + +#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 +#include +#include + +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 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(xdev)->unregister(); +} + +static void wivrn_fb_face2_tracker_update_inputs(xrt_device * xdev) +{ + static_cast(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(xdev)->get_face_tracking(facial_expression_type, inout_value); +} diff --git a/server/driver/wivrn_fb_face2_tracker.h b/server/driver/wivrn_fb_face2_tracker.h new file mode 100644 index 00000000..a7974bf1 --- /dev/null +++ b/server/driver/wivrn_fb_face2_tracker.h @@ -0,0 +1,101 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas + * Copyright (C) 2024 galister + * + * 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 . + */ + +#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 +#include +#include + +struct wivrn_fb_face2_data +{ + std::array weights; + std::array 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 +{ +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 cnx; + +public: + wivrn_fb_face2_tracker(xrt_device * hmd, std::shared_ptr 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); +}; diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index c1146b9d..f40b1ddc 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -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(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(); diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 60b63c79..184d43c2 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -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 std::unique_ptr left_hand; std::unique_ptr right_hand; std::unique_ptr eye_tracker; + std::unique_ptr 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 &&);