pass through HTC_facial_tracking
This commit is contained in:
@@ -84,6 +84,7 @@ add_executable(wivrn-server
|
||||
driver/wivrn_controller.cpp
|
||||
driver/wivrn_eye_tracker.cpp
|
||||
driver/wivrn_fb_face2_tracker.cpp
|
||||
driver/wivrn_htc_face_tracker.cpp
|
||||
driver/wivrn_foveation.cpp
|
||||
driver/pose_list.cpp
|
||||
driver/view_list.cpp
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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_htc_face_tracker.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "util/u_logging.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
static void wivrn_htc_face_tracker_destroy(xrt_device * xdev);
|
||||
|
||||
static xrt_result_t wivrn_htc_face_tracker_update_inputs(xrt_device * xdev)
|
||||
{
|
||||
static_cast<wivrn_htc_face_tracker *>(xdev)->update_inputs();
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
static xrt_result_t wivrn_htc_face_tracker_get_face_tracking(struct xrt_device * xdev,
|
||||
enum xrt_input_name facial_expression_type,
|
||||
int64_t at_timestamp_ns,
|
||||
struct xrt_facial_expression_set * out_value);
|
||||
|
||||
wivrn_htc_face_tracker::wivrn_htc_face_tracker(xrt_device * hmd,
|
||||
wivrn::wivrn_session & cnx) :
|
||||
xrt_device{}, cnx(cnx)
|
||||
{
|
||||
xrt_device * base = this;
|
||||
base->tracking_origin = hmd->tracking_origin;
|
||||
base->get_face_tracking = wivrn_htc_face_tracker_get_face_tracking;
|
||||
base->update_inputs = wivrn_htc_face_tracker_update_inputs;
|
||||
base->destroy = wivrn_htc_face_tracker_destroy;
|
||||
name = XRT_DEVICE_HTC_FACE_TRACKING;
|
||||
device_type = XRT_DEVICE_TYPE_FACE_TRACKER;
|
||||
face_tracking_supported = true;
|
||||
|
||||
// Print name.
|
||||
strcpy(str, "WiVRn HTC Face Tracker");
|
||||
strcpy(serial, "WiVRn HTC Face Tracker");
|
||||
|
||||
// Setup input.
|
||||
inputs_array[0].name = XRT_INPUT_HTC_EYE_FACE_TRACKING;
|
||||
inputs_array[0].active = true;
|
||||
|
||||
inputs_array[1].name = XRT_INPUT_HTC_LIP_FACE_TRACKING;
|
||||
inputs_array[1].active = true;
|
||||
|
||||
inputs = inputs_array.data();
|
||||
input_count = inputs_array.size();
|
||||
}
|
||||
|
||||
void wivrn_htc_face_tracker::update_inputs()
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
void wivrn_htc_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
|
||||
{
|
||||
if (not(tracking.face_htc))
|
||||
return;
|
||||
const auto & face = *tracking.face_htc;
|
||||
|
||||
wivrn_htc_face_data data{
|
||||
.eye = face.eye,
|
||||
.lip = face.lip,
|
||||
.eye_active = face.eye_active,
|
||||
.lip_active = face.lip_active};
|
||||
|
||||
if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset))
|
||||
cnx.set_enabled(to_headset::tracking_control::id::face, false);
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_htc_face_tracker::get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * inout_value)
|
||||
{
|
||||
if (facial_expression_type == XRT_INPUT_HTC_EYE_FACE_TRACKING)
|
||||
{
|
||||
cnx.set_enabled(to_headset::tracking_control::id::face, true);
|
||||
auto [_, data] = face_list.get_at(at_timestamp_ns);
|
||||
|
||||
inout_value->base_expression_set_htc.is_active = data.eye_active;
|
||||
inout_value->base_expression_set_htc.sample_time_ns = at_timestamp_ns;
|
||||
|
||||
if (not data.eye_active)
|
||||
return XRT_SUCCESS;
|
||||
|
||||
memcpy(&inout_value->eye_expression_set_htc.expression_weights, data.eye.data(), sizeof(float) * data.eye.size());
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
else if (facial_expression_type == XRT_INPUT_HTC_LIP_FACE_TRACKING)
|
||||
{
|
||||
cnx.set_enabled(to_headset::tracking_control::id::face, true);
|
||||
auto [_, data] = face_list.get_at(at_timestamp_ns);
|
||||
|
||||
inout_value->base_expression_set_htc.is_active = data.lip_active;
|
||||
inout_value->base_expression_set_htc.sample_time_ns = at_timestamp_ns;
|
||||
|
||||
if (not data.lip_active)
|
||||
return XRT_SUCCESS;
|
||||
|
||||
memcpy(&inout_value->lip_expression_set_htc.expression_weights, data.lip.data(), sizeof(float) * data.lip.size());
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
return XRT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
*/
|
||||
|
||||
static void wivrn_htc_face_tracker_destroy(xrt_device * xdev)
|
||||
{
|
||||
}
|
||||
|
||||
static xrt_result_t wivrn_htc_face_tracker_get_face_tracking(struct xrt_device * xdev,
|
||||
enum xrt_input_name facial_expression_type,
|
||||
int64_t at_timestamp_ns,
|
||||
struct xrt_facial_expression_set * inout_value)
|
||||
{
|
||||
return static_cast<wivrn_htc_face_tracker *>(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value);
|
||||
}
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 "history.h"
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
struct clock_offset;
|
||||
class wivrn_session;
|
||||
|
||||
struct wivrn_htc_face_data
|
||||
{
|
||||
std::array<float, XRT_FACIAL_EXPRESSION_EYE_COUNT_HTC> eye;
|
||||
std::array<float, XRT_FACIAL_EXPRESSION_LIP_COUNT_HTC> lip;
|
||||
bool eye_active;
|
||||
bool lip_active;
|
||||
};
|
||||
|
||||
class htc_face_list : public history<htc_face_list, wivrn_htc_face_data>
|
||||
{
|
||||
public:
|
||||
static wivrn_htc_face_data interpolate(const wivrn_htc_face_data & a, const wivrn_htc_face_data & b, float t)
|
||||
{
|
||||
wivrn_htc_face_data result = b;
|
||||
|
||||
if (not a.eye_active)
|
||||
{
|
||||
result.eye = b.eye;
|
||||
result.eye_active = b.eye_active;
|
||||
}
|
||||
else if (not b.eye_active)
|
||||
{
|
||||
result.eye = a.eye;
|
||||
result.eye_active = a.eye_active;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.eye_active = true;
|
||||
for (size_t i = 0; i < result.eye.size(); i++)
|
||||
{
|
||||
result.eye[i] = std::clamp(std::lerp(a.eye[i], b.eye[i], t), 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (not a.lip_active)
|
||||
{
|
||||
result.lip = b.lip;
|
||||
result.lip_active = b.lip_active;
|
||||
}
|
||||
else if (not b.lip_active)
|
||||
{
|
||||
result.lip = a.lip;
|
||||
result.lip_active = a.lip_active;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.lip_active = true;
|
||||
for (size_t i = 0; i < result.lip.size(); i++)
|
||||
{
|
||||
result.lip[i] = std::clamp(std::lerp(a.lip[i], b.lip[i], t), 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool update_tracking(const XrTime & production_timestamp, const XrTime & timestamp, const wivrn_htc_face_data & data, const clock_offset & offset)
|
||||
{
|
||||
return this->add_sample(production_timestamp, timestamp, data, offset);
|
||||
}
|
||||
};
|
||||
|
||||
class wivrn_htc_face_tracker : public xrt_device
|
||||
{
|
||||
htc_face_list face_list;
|
||||
std::array<xrt_input, 2> inputs_array;
|
||||
|
||||
wivrn::wivrn_session & cnx;
|
||||
|
||||
public:
|
||||
wivrn_htc_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx);
|
||||
|
||||
void update_inputs();
|
||||
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);
|
||||
};
|
||||
} // namespace wivrn
|
||||
@@ -34,8 +34,10 @@
|
||||
#include "wivrn_eye_tracker.h"
|
||||
#include "wivrn_fb_face2_tracker.h"
|
||||
#include "wivrn_foveation.h"
|
||||
#include "wivrn_htc_face_tracker.h"
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "xrt/xrt_session.h"
|
||||
#include <cmath>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -197,11 +199,20 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
static_roles.eyes = eye_tracker.get();
|
||||
xdevs[xdev_count++] = eye_tracker.get();
|
||||
}
|
||||
if (get_info().face_tracking2_fb || is_forced_extension("FB_face_tracking2"))
|
||||
switch (get_info().face_tracking)
|
||||
{
|
||||
fb_face2_tracker = std::make_unique<wivrn_fb_face2_tracker>(&hmd, *this);
|
||||
static_roles.face = fb_face2_tracker.get();
|
||||
xdevs[xdev_count++] = fb_face2_tracker.get();
|
||||
case wivrn::from_headset::face_type::fb2:
|
||||
fb_face2_tracker = std::make_unique<wivrn_fb_face2_tracker>(&hmd, *this);
|
||||
static_roles.face = fb_face2_tracker.get();
|
||||
xdevs[xdev_count++] = fb_face2_tracker.get();
|
||||
break;
|
||||
case wivrn::from_headset::face_type::htc:
|
||||
htc_face_tracker = std::make_unique<wivrn_htc_face_tracker>(&hmd, *this);
|
||||
static_roles.face = htc_face_tracker.get();
|
||||
xdevs[xdev_count++] = htc_face_tracker.get();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if WIVRN_FEATURE_SOLARXR
|
||||
@@ -322,8 +333,11 @@ void wivrn_session::operator()(const 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);
|
||||
else if (htc_face_tracker)
|
||||
htc_face_tracker->update_tracking(tracking, offset);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::derived_pose && derived)
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace wivrn
|
||||
{
|
||||
class wivrn_eye_tracker;
|
||||
class wivrn_fb_face2_tracker;
|
||||
class wivrn_htc_face_tracker;
|
||||
class wivrn_foveation;
|
||||
class wivrn_foveation_renderer;
|
||||
struct audio_device;
|
||||
@@ -105,6 +106,7 @@ class wivrn_session : public xrt_system_devices
|
||||
wivrn_controller right_hand;
|
||||
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
|
||||
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
|
||||
std::unique_ptr<wivrn_htc_face_tracker> htc_face_tracker;
|
||||
std::unique_ptr<wivrn_foveation> foveation;
|
||||
wivrn_comp_target * comp_target;
|
||||
|
||||
|
||||
+1
-1
@@ -782,7 +782,7 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
|
||||
|
||||
wivrn_server_set_hand_tracking(dbus_server, info.hand_tracking);
|
||||
wivrn_server_set_eye_gaze(dbus_server, info.eye_gaze);
|
||||
wivrn_server_set_face_tracking(dbus_server, info.face_tracking2_fb);
|
||||
wivrn_server_set_face_tracking(dbus_server, info.face_tracking != wivrn::from_headset::face_type::none);
|
||||
|
||||
std::vector<const char *> codecs;
|
||||
static const std::map<video_codec, const char *> codec_names = {
|
||||
|
||||
Reference in New Issue
Block a user