Forward XR_ANDROID_face_tracking

This commit is contained in:
Sapphire
2025-12-04 11:16:31 +01:00
committed by xytovl
parent ac0a926811
commit 51d8742029
16 changed files with 403 additions and 8 deletions
+2
View File
@@ -1219,6 +1219,8 @@ void application::initialize()
XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME,
XR_EXT_USER_PRESENCE_EXTENSION_NAME,
XR_ANDROID_FACE_TRACKING_EXTENSION_NAME,
XR_BD_BODY_TRACKING_EXTENSION_NAME,
XR_FB_BODY_TRACKING_EXTENSION_NAME,
-2
View File
@@ -1231,8 +1231,6 @@ void scenes::lobby::on_focused()
},
};
face_tracker = xr::make_face_tracker(instance, system, session);
// 0.4mm / pixel
std::vector<imgui_context::viewport> vps{
{
+6 -1
View File
@@ -722,7 +722,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
ImGui::BeginDisabled(system.face_tracker_supported() == xr::face_tracker_type::none);
bool enabled = config.check_feature(feature::face_tracking);
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
{
@@ -1422,6 +1422,7 @@ static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracke
const char * result = nullptr;
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](xr::android_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
[&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
[&](auto & ft) {
ft.get_weights(predicted_display_time, expression);
@@ -1504,6 +1505,10 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
});
}
else if (system.face_tracker_supported() != xr::face_tracker_type::none and config.check_feature(feature::face_tracking))
{
face_tracker = xr::make_face_tracker(instance, system, session);
}
if (system.body_tracker_supported() != xr::body_tracker_type::none)
{
+3
View File
@@ -259,6 +259,9 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
case xr::face_tracker_type::none:
info.face_tracking = from_headset::face_type::none;
break;
case xr::face_tracker_type::android:
info.face_tracking = from_headset::face_type::android;
break;
case xr::face_tracker_type::fb:
case xr::face_tracker_type::pico:
info.face_tracking = from_headset::face_type::fb2;
+71
View File
@@ -0,0 +1,71 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "android_face_tracker.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/session.h"
#include <openxr/openxr.h>
xr::android_face_tracker::android_face_tracker(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyFaceTrackerANDROID>("xrDestroyFaceTrackerANDROID"))
{
auto xrCreateFaceTrackerANDROID = inst.get_proc<PFN_xrCreateFaceTrackerANDROID>("xrCreateFaceTrackerANDROID");
xrGetFaceCalibrationStateANDROID = inst.get_proc<PFN_xrGetFaceCalibrationStateANDROID>("xrGetFaceCalibrationStateANDROID");
xrGetFaceStateANDROID = inst.get_proc<PFN_xrGetFaceStateANDROID>("xrGetFaceStateANDROID");
assert(xrCreateFaceTrackerANDROID);
XrFaceTrackerCreateInfoANDROID create_info{
.type = XR_TYPE_FACE_TRACKER_CREATE_INFO_ANDROID,
.next = nullptr,
};
CHECK_XR(xrCreateFaceTrackerANDROID(s, &create_info, &id));
}
void xr::android_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::android_face & out_expressions)
{
if (!id || !xrGetFaceStateANDROID)
return;
XrBool32 is_calibrated;
if (XR_SUCCEEDED(xrGetFaceCalibrationStateANDROID(id, &is_calibrated)))
out_expressions.is_calibrated = is_calibrated;
else
out_expressions.is_calibrated = false;
XrFaceStateGetInfoANDROID info{
.type = XR_TYPE_FACE_STATE_GET_INFO_ANDROID,
.next = nullptr,
.time = time,
};
XrFaceStateANDROID state{
.type = XR_TYPE_FACE_STATE_ANDROID,
.next = nullptr,
.parametersCapacityInput = (uint32_t)out_expressions.parameters.size(),
.parameters = out_expressions.parameters.data(),
.regionConfidencesCapacityInput = (uint32_t)out_expressions.confidences.size(),
.regionConfidences = out_expressions.confidences.data(),
};
CHECK_XR(xrGetFaceStateANDROID(id, &info, &state));
out_expressions.state = state.faceTrackingState;
out_expressions.is_valid = state.isValid;
}
+42
View File
@@ -0,0 +1,42 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "utils/handle.h"
#include "wivrn_packets.h"
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
class android_face_tracker : public utils::handle<XrFaceTrackerANDROID>
{
PFN_xrGetFaceCalibrationStateANDROID xrGetFaceCalibrationStateANDROID{};
PFN_xrGetFaceStateANDROID xrGetFaceStateANDROID{};
public:
using packet_type = wivrn::from_headset::tracking::android_face;
android_face_tracker(instance & inst, session & s);
void get_weights(XrTime, packet_type & out_expressions);
};
} // namespace xr
+14
View File
@@ -24,6 +24,13 @@
xr::face_tracker_type xr::face_tracker_supported(xr::instance & instance, xr::system & system)
{
if (instance.has_extension(XR_ANDROID_FACE_TRACKING_EXTENSION_NAME))
{
auto properties = system.android_face_tracking_properties();
if (properties.supportsFaceTracking)
return xr::face_tracker_type::android;
}
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
@@ -57,6 +64,13 @@ xr::face_tracker_type xr::face_tracker_supported(xr::instance & instance, xr::sy
xr::face_tracker xr::make_face_tracker(xr::instance & instance, xr::system & system, xr::session & session)
{
if (instance.has_extension(XR_ANDROID_FACE_TRACKING_EXTENSION_NAME))
{
auto properties = system.android_face_tracking_properties();
if (properties.supportsFaceTracking)
return xr::face_tracker(std::in_place_type_t<xr::android_face_tracker>(), instance, session);
}
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
+2 -1
View File
@@ -18,6 +18,7 @@
#pragma once
#include "android_face_tracker.h"
#include "fb_face_tracker2.h"
#include "htc_face_tracker.h"
#include "pico_face_tracker.h"
@@ -31,7 +32,7 @@ namespace xr
class instance;
class session;
using face_tracker = std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker>;
using face_tracker = std::variant<std::monostate, xr::android_face_tracker, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker>;
face_tracker make_face_tracker(xr::instance &, xr::system &, xr::session &);
+18
View File
@@ -131,6 +131,24 @@ XrSystemUserPresencePropertiesEXT xr::system::user_presence_properties() const
return presence_prop;
}
XrSystemFaceTrackingPropertiesANDROID xr::system::android_face_tracking_properties() const
{
if (!id)
throw std::invalid_argument("this");
XrSystemFaceTrackingPropertiesANDROID face_tracking_prop{
.type = XR_TYPE_SYSTEM_FACE_TRACKING_PROPERTIES_ANDROID,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &face_tracking_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return face_tracking_prop;
}
XrSystemFaceTrackingProperties2FB xr::system::fb_face_tracking2_properties() const
{
if (!id)
+2
View File
@@ -50,6 +50,7 @@ enum class body_tracker_type
enum class face_tracker_type
{
none,
android,
fb,
htc,
pico,
@@ -83,6 +84,7 @@ public:
XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const;
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const;
XrSystemUserPresencePropertiesEXT user_presence_properties() const;
XrSystemFaceTrackingPropertiesANDROID android_face_tracking_properties() const;
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
+12 -2
View File
@@ -38,7 +38,7 @@
namespace wivrn
{
static constexpr int protocol_revision = 2;
static constexpr int protocol_revision = 0;
enum class device_id : uint8_t
{
@@ -211,6 +211,7 @@ struct visibility_mask_changed
enum face_type : uint8_t
{
none,
android,
fb2,
htc,
};
@@ -301,6 +302,15 @@ struct tracking
std::array<view, 2> views;
std::vector<pose> device_poses;
struct android_face
{
std::array<float, XR_FACE_PARAMETER_COUNT_ANDROID> parameters;
std::array<float, XR_FACE_REGION_CONFIDENCE_COUNT_ANDROID> confidences;
XrFaceTrackingStateANDROID state;
bool is_calibrated;
bool is_valid;
};
struct fb_face2
{
std::array<float, XR_FACE_EXPRESSION2_COUNT_FB> weights;
@@ -317,7 +327,7 @@ struct tracking
bool lip_active;
};
std::variant<std::monostate, fb_face2, htc_face> face;
std::variant<std::monostate, android_face, fb_face2, htc_face> face;
};
struct trackings
+2
View File
@@ -35,6 +35,7 @@ set(XRT_FEATURE_WINDOW_PEEK OFF)
set(XRT_FEATURE_OPENXR_ACTIVE_ACTION_SET_PRIORITY ON)
set(XRT_FEATURE_RENDERDOC ${WIVRN_FEATURE_RENDERDOC})
set(XRT_FEATURE_OPENXR_FACE_TRACKING_ANDROID ON)
set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON)
set(XRT_FEATURE_OPENXR_FACIAL_TRACKING_HTC ON)
set(XRT_FEATURE_OPENXR_HAND_TRACKING_EXT ON)
@@ -101,6 +102,7 @@ if (WIVRN_BUILD_SERVER)
driver/wivrn_controller.cpp
driver/wivrn_hand_interaction.cpp
driver/wivrn_eye_tracker.cpp
driver/wivrn_android_face_tracker.cpp
driver/wivrn_fb_face2_tracker.cpp
driver/wivrn_htc_face_tracker.cpp
driver/wivrn_generic_tracker.cpp
@@ -0,0 +1,118 @@
/*
* 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>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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_android_face_tracker.h"
#include "wivrn_packets.h"
#include "wivrn_session.h"
#include "os/os_time.h"
#include "util/u_logging.h"
#include "utils/method.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_results.h"
#include <cmath>
#include <cstdint>
#include <cstring>
namespace wivrn
{
wivrn_android_face_tracker::wivrn_android_face_tracker(xrt_device * hmd,
wivrn::wivrn_session & cnx) :
xrt_device{
.name = XRT_DEVICE_ANDROID_FACE_TRACKING,
.device_type = XRT_DEVICE_TYPE_FACE_TRACKER,
.str = "WiVRn Android Face Tracker",
.serial = "WiVRn Android Face Tracker",
.tracking_origin = hmd->tracking_origin,
.input_count = 1,
.inputs = &face_input,
.supported = {
.face_tracking = true,
},
.update_inputs = method_pointer<&wivrn_android_face_tracker::update_inputs>,
.get_face_tracking = method_pointer<&wivrn_android_face_tracker::get_face_tracking>,
.get_face_calibration_state_android = method_pointer<&wivrn_android_face_tracker::get_face_calibration_state_android>,
.destroy = [](xrt_device *) {},
},
face_input{
.active = true,
.name = XRT_INPUT_ANDROID_FACE_TRACKING,
},
cnx(cnx)
{
}
xrt_result_t wivrn_android_face_tracker::update_inputs()
{
return XRT_SUCCESS;
}
void wivrn_android_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
auto * face = std::get_if<from_headset::tracking::android_face>(&tracking.face);
if (not(face and face->is_valid))
return;
wivrn_android_face_data data{
.parameters = face->parameters,
.confidences = face->confidences,
.state = (xrt_face_tracking_state_android)face->state,
.is_calibrated = face->is_calibrated,
.is_valid = face->is_valid,
};
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_android_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_ANDROID_FACE_TRACKING)
{
cnx.set_enabled(to_headset::tracking_control::id::face, true);
auto [_, data] = face_list.get_at(at_timestamp_ns);
inout_value->face_expression_set_android.state = data.state;
inout_value->face_expression_set_android.is_valid = data.is_valid;
if (not data.is_valid)
return XRT_SUCCESS;
memcpy(&inout_value->face_expression_set_android.parameters, data.parameters.data(), sizeof(float) * data.parameters.size());
memcpy(&inout_value->face_expression_set_android.region_confidences, data.confidences.data(), sizeof(float) * data.confidences.size());
return XRT_SUCCESS;
}
return XRT_ERROR_NOT_IMPLEMENTED;
}
xrt_result_t wivrn_android_face_tracker::get_face_calibration_state_android(bool * out_face_is_calibrated)
{
auto [_, data] = face_list.get_at(os_monotonic_get_ns());
*out_face_is_calibrated = data.is_calibrated;
return XRT_SUCCESS;
}
} // namespace wivrn
@@ -0,0 +1,99 @@
/*
* 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>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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>
namespace wivrn
{
struct clock_offset;
class wivrn_session;
struct wivrn_android_face_data
{
std::array<float, XRT_FACE_PARAMETER_COUNT_ANDROID> parameters;
std::array<float, XRT_FACE_REGION_CONFIDENCE_COUNT_ANDROID> confidences;
xrt_face_tracking_state_android state;
bool is_calibrated;
bool is_valid;
};
class android_face_list : public history<android_face_list, wivrn_android_face_data>
{
public:
static wivrn_android_face_data interpolate(const wivrn_android_face_data & a, const wivrn_android_face_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_android_face_data result = b;
for (size_t i = 0; i < result.parameters.size(); i++)
{
result.parameters[i] = std::clamp(std::lerp(a.parameters[i], b.parameters[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;
}
bool update_tracking(const XrTime & production_timestamp, const XrTime & timestamp, const wivrn_android_face_data & data, const clock_offset & offset)
{
return this->add_sample(production_timestamp, timestamp, data, offset);
}
};
class wivrn_android_face_tracker : public xrt_device
{
android_face_list face_list;
xrt_input face_input;
wivrn::wivrn_session & cnx;
public:
using base = xrt_device;
wivrn_android_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx);
xrt_result_t 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);
xrt_result_t get_face_calibration_state_android(bool * out_face_is_calibrated);
};
} // namespace wivrn
+10 -2
View File
@@ -34,6 +34,7 @@
#include "utils/scoped_lock.h"
#include "audio/audio_setup.h"
#include "wivrn_android_face_tracker.h"
#include "wivrn_comp_target.h"
#include "wivrn_config.h"
#include "wivrn_eye_tracker.h"
@@ -228,6 +229,12 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
}
auto face = get_info().face_tracking;
if (face == from_headset::face_type::android || is_forced_extension("ANDROID_face_tracking"))
{
android_face_tracker = std::make_unique<wivrn_android_face_tracker>(&hmd, *this);
static_roles.face = android_face_tracker.get();
xdevs[xdev_count++] = android_face_tracker.get();
}
if (face == from_headset::face_type::fb2 || is_forced_extension("FB_face_tracking2"))
{
fb_face2_tracker = std::make_unique<wivrn_fb_face2_tracker>(&hmd, *this);
@@ -552,7 +559,9 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
comp_target->foveation->update_tracking(tracking, offset);
}
if (fb_face2_tracker)
if (android_face_tracker)
android_face_tracker->update_tracking(tracking, offset);
else if (fb_face2_tracker)
fb_face2_tracker->update_tracking(tracking, offset);
else if (htc_face_tracker)
htc_face_tracker->update_tracking(tracking, offset);
@@ -1106,7 +1115,6 @@ xrt_result_t wivrn_session::get_roles(xrt_system_roles * out_roles)
return XRT_SUCCESS;
}
// FIXME: use feature_inc and feature_dec to toggle trackings
xrt_result_t wivrn_session::feature_inc(xrt_device_feature_type type)
{
switch (type)
+2
View File
@@ -48,6 +48,7 @@ union xrt_session_event;
namespace wivrn
{
class wivrn_eye_tracker;
class wivrn_android_face_tracker;
class wivrn_fb_face2_tracker;
class wivrn_htc_face_tracker;
class wivrn_generic_tracker;
@@ -123,6 +124,7 @@ class wivrn_session : public xrt_system_devices
wivrn_hand_interaction right_hand_interaction;
int32_t right_hand_interaction_index;
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
std::unique_ptr<wivrn_android_face_tracker> android_face_tracker;
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
std::unique_ptr<wivrn_htc_face_tracker> htc_face_tracker;
std::vector<std::unique_ptr<wivrn_generic_tracker>> generic_trackers;