Merge branch 'sync' into sneed
This commit is contained in:
+16
-22
@@ -49,6 +49,8 @@ set(XRT_FEATURE_OPENXR_INTERACTION_VIVE_FOCUS3 ON)
|
||||
set(XRT_FEATURE_OPENXR_INTERACTION_TOUCH_PRO ON)
|
||||
set(XRT_FEATURE_OPENXR_INTERACTION_TOUCH_PLUS ON)
|
||||
set(XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS ON)
|
||||
set(XRT_FEATURE_OPENXR_LAYER_DEPTH OFF)
|
||||
set(XRT_FEATURE_OPENXR_VARJO_QUAD_VIEWS OFF)
|
||||
|
||||
set(XRT_HAVE_BLUETOOTH OFF)
|
||||
set(XRT_HAVE_GST OFF)
|
||||
@@ -62,7 +64,7 @@ set(XRT_HAVE_DBUS OFF)
|
||||
set(XRT_HAVE_LIBUDEV OFF)
|
||||
set(XRT_HAVE_ONNXRUNTIME OFF)
|
||||
|
||||
set(XRT_HAVE_SYSTEMD ${WIVRN_USE_SYSTEMD})
|
||||
set(XRT_HAVE_SYSTEMD OFF)
|
||||
set(XRT_INSTALL_SYSTEMD_UNIT_FILES OFF)
|
||||
|
||||
set(BUILD_DOC OFF)
|
||||
@@ -97,6 +99,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
main.cpp
|
||||
sleep_inhibitor.cpp
|
||||
start_application.cpp
|
||||
start_systemd_unit.cpp
|
||||
ipc_server_cb.cpp
|
||||
target_instance_wivrn.cpp
|
||||
wivrn_ipc.cpp
|
||||
@@ -206,10 +209,6 @@ if (WIVRN_BUILD_SERVER)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIVRN_USE_SYSTEMD)
|
||||
target_link_libraries(wivrn-server PRIVATE PkgConfig::SYSTEMD)
|
||||
endif()
|
||||
|
||||
if(WIVRN_USE_PIPEWIRE)
|
||||
target_sources(
|
||||
wivrn-server
|
||||
@@ -233,31 +232,25 @@ if (WIVRN_BUILD_SERVER)
|
||||
target_link_libraries(wivrn-server PUBLIC wivrn-server-dbus)
|
||||
target_link_libraries(wivrn-server PUBLIC PkgConfig::libnotify)
|
||||
|
||||
if(WIVRN_USE_SYSTEMD)
|
||||
add_custom_command(OUTPUT systemd_manager.c systemd_manager.h
|
||||
COMMAND ${GDBUS_CODEGEN} ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml --interface-prefix org.freedesktop.systemd1 --generate-c-code systemd_manager --c-namespace systemd
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml )
|
||||
add_custom_command(OUTPUT systemd_unit.c systemd_unit.h
|
||||
COMMAND ${GDBUS_CODEGEN} ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Unit.xml --interface-prefix org.freedesktop.systemd1 --generate-c-code systemd_unit --c-namespace unit
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml )
|
||||
target_sources(wivrn-server-dbus PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}/systemd_manager.c ${CMAKE_CURRENT_BINARY_DIR}/systemd_manager.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/systemd_unit.c ${CMAKE_CURRENT_BINARY_DIR}/systemd_unit.h)
|
||||
target_sources(
|
||||
wivrn-server
|
||||
PRIVATE start_systemd_unit.cpp
|
||||
)
|
||||
endif()
|
||||
add_custom_command(OUTPUT systemd_manager.c systemd_manager.h
|
||||
COMMAND ${GDBUS_CODEGEN} ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml --interface-prefix org.freedesktop.systemd1 --generate-c-code systemd_manager --c-namespace systemd
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml )
|
||||
add_custom_command(OUTPUT systemd_unit.c systemd_unit.h
|
||||
COMMAND ${GDBUS_CODEGEN} ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Unit.xml --interface-prefix org.freedesktop.systemd1 --generate-c-code systemd_unit --c-namespace unit
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/org.freedesktop.systemd1.Manager.xml )
|
||||
target_sources(wivrn-server-dbus PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}/systemd_manager.c ${CMAKE_CURRENT_BINARY_DIR}/systemd_manager.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/systemd_unit.c ${CMAKE_CURRENT_BINARY_DIR}/systemd_unit.h)
|
||||
|
||||
target_link_libraries(
|
||||
wivrn-server
|
||||
PRIVATE
|
||||
aux_os
|
||||
aux_render
|
||||
aux_util
|
||||
aux_vk
|
||||
base
|
||||
comp_multi
|
||||
comp_render
|
||||
comp_util
|
||||
ipc_server
|
||||
target_helpers
|
||||
@@ -277,7 +270,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
wivrn_compile_glsl(wivrn-server
|
||||
TARGET_ENV vulkan1.3
|
||||
SHADERS
|
||||
"${_monado_src}/src/xrt/compositor/shaders/layer.comp"
|
||||
"${_monado_src}/src/xrt/auxiliary/render/shaders/layer.comp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/compositor/shaders/foveation.comp"
|
||||
)
|
||||
|
||||
@@ -326,6 +319,7 @@ if (WIVRN_BUILD_SERVER_LIBRARY)
|
||||
RELATIVE_RUNTIME_DIR ${CMAKE_INSTALL_LIBDIR}/wivrn
|
||||
LIBMONADO monado_wivrn
|
||||
OUT_FILENAME ${_filename}
|
||||
MANIFEST_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/dist/openxr_manifest.in.json"
|
||||
)
|
||||
|
||||
install(TARGETS ${RUNTIME_TARGET} monado
|
||||
|
||||
@@ -80,7 +80,7 @@ std::filesystem::path active_runtime::openvr_compat_path()
|
||||
return std::filesystem::path();
|
||||
},
|
||||
[](const std::string & path) {
|
||||
// exlicit value, use it
|
||||
// explicit value, use it
|
||||
std::optional<std::filesystem::path> flatpak_root = flatpak_key(flatpak::section::instance, "app-path");
|
||||
return flatpak_root.value_or("") / path;
|
||||
},
|
||||
|
||||
@@ -265,7 +265,7 @@ xrt_result_t compositor::mark_frame(int64_t frame_id,
|
||||
switch (point)
|
||||
{
|
||||
case XRT_COMPOSITOR_FRAME_POINT_WOKE:
|
||||
session.dump_time("wake_up", frame_id, when_ns);
|
||||
trace::instant_feedback("wake_up", when_ns, frame_id);
|
||||
return XRT_SUCCESS;
|
||||
default:
|
||||
assert(false);
|
||||
@@ -308,7 +308,7 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
||||
.alpha = layer_accum.data.env_blend_mode == XRT_BLEND_MODE_ALPHA_BLEND,
|
||||
};
|
||||
|
||||
session.dump_time("begin", frame.rendering.id, os_monotonic_get_ns());
|
||||
trace::instant_feedback("begin", frame.rendering.id, os_monotonic_get_ns());
|
||||
|
||||
cmd_pool.reset();
|
||||
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
||||
@@ -596,6 +596,8 @@ xrt_result_t compositor::get_view_config(
|
||||
};
|
||||
}
|
||||
return XRT_SUCCESS;
|
||||
case XRT_VIEW_TYPE_QUAD:
|
||||
return XRT_ERROR_UNSUPPORTED_VIEW_TYPE;
|
||||
}
|
||||
return XRT_ERROR_UNSUPPORTED_VIEW_TYPE;
|
||||
}
|
||||
@@ -713,6 +715,7 @@ compositor::compositor(wivrn_session & session) :
|
||||
log_level);
|
||||
vk::detail::resultCheck(vk::Result(res), "vk_init_from_given");
|
||||
|
||||
c_base->vk.version = vk_bundle::api_version;
|
||||
// vk_init_from_given can't enable calibrated timestamps; do it here.
|
||||
#ifdef VK_EXT_calibrated_timestamps
|
||||
c_base->vk.has_EXT_calibrated_timestamps = vk.has_device_ext(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
#include "main/comp_compositor.h"
|
||||
#include "math/m_space.h"
|
||||
#include "shaders/layer_defines.inc.glsl"
|
||||
#include "render/shaders/layer_defines.inc.glsl"
|
||||
#include "util/comp_layer_accum.h"
|
||||
#include "util/comp_render_helpers.h"
|
||||
|
||||
@@ -723,7 +723,7 @@ xrt_fov layer_squasher::do_projection_layer(
|
||||
&vd.pose,
|
||||
&vd.fov,
|
||||
&world_pose,
|
||||
&ubo.layers[cur_layer].transforms_timewarp);
|
||||
&ubo.layers[cur_layer].transforms);
|
||||
|
||||
return vd.fov;
|
||||
}
|
||||
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"file_format_version": "1.0.0",
|
||||
"runtime": {
|
||||
"name": "WiVRn",
|
||||
"library_path": "@target_path@"@extra_fields@
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Copyright 2018-2023, Collabora, Ltd.
|
||||
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
Vendored
-2
@@ -4,8 +4,6 @@ Description=OpenXR streaming server
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=@CMAKE_INSTALL_PREFIX@/bin/wivrn-server
|
||||
CapabilityBoundingSet=CAP_SYS_NICE
|
||||
AmbientCapabilities=CAP_SYS_NICE
|
||||
LockPersonality=true
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
|
||||
@@ -139,7 +139,7 @@ void app_pacer::predict(int64_t now_ns,
|
||||
// Sync phase with compositor
|
||||
last_display_time = compositor_display_time + period * ((period / 2 + last_display_time - compositor_display_time) / period);
|
||||
|
||||
if (cpu_time > period or gpu_time > period or (min_ready > last_display_time and min_ready < last_display_time + period))
|
||||
if (min_ready > last_display_time and min_ready < last_display_time + period)
|
||||
{
|
||||
// We are limited by app time, don't wait
|
||||
*out_wake_up_time = now_ns;
|
||||
|
||||
@@ -200,6 +200,12 @@ configuration::configuration()
|
||||
if (auto it = json.find("use-steamvr-lh"); it != json.end())
|
||||
use_steamvr_lh = *it;
|
||||
|
||||
if (auto it = json.find("lh-max-extrapolation"); it != json.end())
|
||||
lh_max_extrapolation = *it;
|
||||
|
||||
if (auto it = json.find("lh-stick-deadzone"); it != json.end())
|
||||
lh_stick_deadzone = *it;
|
||||
|
||||
if (auto it = json.find("bit-depth"); it != json.end())
|
||||
bit_depth = *it;
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ struct configuration
|
||||
std::vector<std::string> application;
|
||||
bool debug_gui = false;
|
||||
bool use_steamvr_lh = false;
|
||||
std::optional<int64_t> lh_max_extrapolation;
|
||||
std::optional<float> lh_stick_deadzone;
|
||||
bool hid_forwarding = false;
|
||||
bool tcp_only = false;
|
||||
int port = wivrn::default_port;
|
||||
|
||||
@@ -285,7 +285,7 @@ std::pair<XrTime, xrt_space_relation> pose_list::get_at(XrTime at_timestamp_ns)
|
||||
(*orientation.dy)[1],
|
||||
(*orientation.dy)[2],
|
||||
(*orientation.dy)[3]};
|
||||
Eigen::Quaternionf half_ω = dq * q;
|
||||
Eigen::Quaternionf half_ω = dq * q.conjugate();
|
||||
|
||||
flags(XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT);
|
||||
ret.angular_velocity = {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
@@ -39,6 +40,7 @@ namespace wivrn
|
||||
wivrn_android_face_tracker::wivrn_android_face_tracker(xrt_device * hmd,
|
||||
wivrn::wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_ANDROID_FACE_TRACKING,
|
||||
.device_type = XRT_DEVICE_TYPE_FACE_TRACKER,
|
||||
.str = "WiVRn Android Face Tracker",
|
||||
|
||||
@@ -21,15 +21,17 @@
|
||||
#include "wivrn_body_tracker.h"
|
||||
#include "driver/pose_list.h"
|
||||
#include "driver/wivrn_generic_tracker.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_session.h"
|
||||
#include "xrt_cast.h"
|
||||
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
static_assert(std::to_underlying(XR_BODY_JOINT_COUNT_FB) == std::to_underlying(XRT_BODY_JOINT_COUNT_FB));
|
||||
@@ -249,6 +251,7 @@ void body_joints_list::update_tracking(const wivrn::from_headset::bd_body & trac
|
||||
|
||||
wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx, std::function<void(xrt_device &)> device_add_callback) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_FB_BODY_TRACKING, // FIXME: replace with something more appropriate, when there is one
|
||||
.device_type = XRT_DEVICE_TYPE_BODY_TRACKER,
|
||||
.tracking_origin = hmd->tracking_origin,
|
||||
@@ -338,12 +341,13 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
for (auto & [joint, body_part]: joint_body_parts)
|
||||
{
|
||||
auto & name = body_part_pretty_names.at(body_part);
|
||||
auto [it, success] = virtual_trackers.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(joint),
|
||||
std::forward_as_tuple(name, hmd, cnx));
|
||||
[[maybe_unused]] auto [it, success] = virtual_trackers.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(joint),
|
||||
std::forward_as_tuple(name, hmd, cnx));
|
||||
assert(success);
|
||||
device_add_callback(it->second);
|
||||
}
|
||||
for (auto & [_, dev]: virtual_trackers)
|
||||
device_add_callback(dev);
|
||||
(*this)(*cnx.get_settings());
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,8 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
|
||||
|
||||
if (client_port >= 0)
|
||||
{
|
||||
stream.connect(client_address.sin6_addr, client_port);
|
||||
client_address.sin6_port = htons(client_port);
|
||||
stream.connect(client_address);
|
||||
stream.set_send_buffer_size(1024 * 1024 * 5);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -21,13 +21,16 @@
|
||||
#include "wivrn_controller.h"
|
||||
#include "configuration.h"
|
||||
#include "driver/xrt_cast.h"
|
||||
#include "math/m_api.h"
|
||||
#include "utils/method.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "math/m_api.h"
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
|
||||
#include <array>
|
||||
#include <format>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -35,8 +38,6 @@
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
@@ -593,6 +594,7 @@ wivrn_controller::wivrn_controller(xrt_device_name name,
|
||||
xrt_device * hmd,
|
||||
wivrn::wivrn_session * cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = name,
|
||||
.device_type = hand_id == 0 ? XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER : XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER,
|
||||
.hmd = nullptr,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
|
||||
@@ -36,6 +37,7 @@ namespace wivrn
|
||||
|
||||
wivrn_eye_tracker::wivrn_eye_tracker(wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_EYE_GAZE_INTERACTION,
|
||||
.device_type = XRT_DEVICE_TYPE_EYE_TRACKER,
|
||||
.str = "WiVRn Eye Tracker",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
@@ -38,6 +39,7 @@ namespace wivrn
|
||||
wivrn_fb_face2_tracker::wivrn_fb_face2_tracker(xrt_device * hmd,
|
||||
wivrn::wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_FB_FACE_TRACKING2,
|
||||
.device_type = XRT_DEVICE_TYPE_FACE_TRACKER,
|
||||
.str = "WiVRn FB v2 Face Tracker",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
|
||||
@@ -35,6 +36,7 @@ static_assert(gp_count == 18);
|
||||
|
||||
wivrn_gamepad::wivrn_gamepad(wivrn::wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_XBOX_CONTROLLER,
|
||||
.device_type = XRT_DEVICE_TYPE_GAMEPAD,
|
||||
.str = "WiVRn Gamepad",
|
||||
|
||||
@@ -19,54 +19,27 @@
|
||||
*/
|
||||
|
||||
#include "wivrn_generic_tracker.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "math/m_api.h"
|
||||
#include "math/m_eigen_interop.hpp"
|
||||
#include "math/m_space.h"
|
||||
#include "math/m_vec3.h"
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
#include <format>
|
||||
|
||||
using namespace xrt::auxiliary::math;
|
||||
#include <format>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
xrt_space_relation tracker_pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t)
|
||||
{
|
||||
xrt_space_relation result;
|
||||
xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags);
|
||||
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), const_cast<xrt_space_relation *>(&b), t, flags, &result);
|
||||
return result;
|
||||
return pose_list::interpolate(a, b, t);
|
||||
}
|
||||
|
||||
xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t)
|
||||
{
|
||||
float h = (tb - ta) / 1.e9;
|
||||
|
||||
xrt_space_relation res = t < ta ? a : b;
|
||||
|
||||
xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h;
|
||||
|
||||
float dt = (t - tb) / 1.e9;
|
||||
|
||||
float dt2_over_2 = dt * dt / 2;
|
||||
res.pose.position = res.pose.position + lin_vel * dt;
|
||||
|
||||
if (res.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT)
|
||||
{
|
||||
xrt_vec3 dtheta = res.angular_velocity * dt;
|
||||
xrt_quat dq;
|
||||
math_quat_exp(&dtheta, &dq);
|
||||
|
||||
map_quat(res.pose.orientation) = map_quat(res.pose.orientation) * map_quat(dq);
|
||||
}
|
||||
|
||||
return res;
|
||||
return pose_list::extrapolate(a, b, ta, tb, t);
|
||||
}
|
||||
|
||||
void tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const xrt_space_relation & pose, const clock_offset & offset)
|
||||
@@ -76,6 +49,7 @@ void tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timest
|
||||
|
||||
wivrn_generic_tracker::wivrn_generic_tracker(std::string name, xrt_device * hmd, wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_VIVE_TRACKER,
|
||||
.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER,
|
||||
.hmd = nullptr,
|
||||
@@ -118,7 +92,10 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
|
||||
XrTime production_timestamp;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
*res = XRT_SPACE_RELATION_ZERO;
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (name == XRT_INPUT_GENERIC_TRACKER_POSE)
|
||||
{
|
||||
|
||||
+27
-18
@@ -26,6 +26,7 @@
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "util/u_device.h"
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
|
||||
@@ -70,28 +71,27 @@ xrt_result_t wivrn_hmd::get_visibility_mask(xrt_visibility_mask_type type, uint3
|
||||
wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
const from_headset::headset_info_packet & info) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_GENERIC_HMD,
|
||||
.device_type = XRT_DEVICE_TYPE_HMD,
|
||||
.str = "WiVRn HMD",
|
||||
.serial = "WiVRn HMD",
|
||||
.hmd = &hmd_parts,
|
||||
.tracking_origin = &tracking_origin,
|
||||
.input_count = 1,
|
||||
.inputs = &pose_input,
|
||||
.supported = {
|
||||
.orientation_tracking = true,
|
||||
.position_tracking = true,
|
||||
.presence = info.user_presence,
|
||||
.battery_status = true,
|
||||
},
|
||||
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
|
||||
.update_inputs = method_pointer<&wivrn_hmd::update_inputs>,
|
||||
.get_tracked_pose = method_pointer<&wivrn_hmd::get_tracked_pose>,
|
||||
.get_presence = method_pointer<&wivrn_hmd::get_presence>,
|
||||
.get_view_poses = method_pointer<&wivrn_hmd::get_view_poses>,
|
||||
.get_visibility_mask = method_pointer<&wivrn_hmd::get_visibility_mask>,
|
||||
.get_battery_status = method_pointer<&wivrn_hmd::get_battery_status>,
|
||||
.destroy = [](xrt_device *) {},
|
||||
},
|
||||
presence(true, os_monotonic_get_ns()),
|
||||
cnx(cnx)
|
||||
{
|
||||
xrt_device_init(static_cast<xrt_device *>(this));
|
||||
@@ -103,6 +103,13 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
auto eye_height = info.render_eye_height;
|
||||
eye_height = ((eye_height + 3) / 4) * 4;
|
||||
|
||||
inputs_array.emplace_back(true, 0, XRT_INPUT_GENERIC_HEAD_POSE);
|
||||
if (info.user_presence)
|
||||
inputs_array.emplace_back(true, presence.get_unsafe().change_time, XRT_INPUT_GENERIC_HEAD_DETECT);
|
||||
|
||||
input_count = inputs_array.size();
|
||||
inputs = inputs_array.data();
|
||||
|
||||
// Setup info.
|
||||
hmd->view_count = 2;
|
||||
hmd->blend_modes[hmd->blend_mode_count++] = XRT_BLEND_MODE_OPAQUE;
|
||||
@@ -129,6 +136,18 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
hmd->distortion.fov[1] = xrt_cast(info.fov[1]);
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hmd::update_inputs()
|
||||
{
|
||||
if (not supported.presence)
|
||||
return XRT_SUCCESS;
|
||||
|
||||
auto p = presence.lock();
|
||||
xrt_input & input = inputs_array.at(1);
|
||||
input.value.boolean = p->value;
|
||||
input.timestamp = p->change_time;
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hmd::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
|
||||
{
|
||||
if (name != XRT_INPUT_GENERIC_HEAD_POSE)
|
||||
@@ -156,13 +175,6 @@ void wivrn_hmd::update_battery(const from_headset::battery & new_battery)
|
||||
*battery.lock() = new_battery;
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hmd::get_presence(bool * out_presence)
|
||||
{
|
||||
*out_presence = presence;
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation,
|
||||
int64_t at_timestamp_ns,
|
||||
xrt_view_type view_type,
|
||||
@@ -240,13 +252,10 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
|
||||
m->at(mask.view_index) = mask.data;
|
||||
}
|
||||
|
||||
bool wivrn_hmd::update_presence(bool new_presence)
|
||||
void wivrn_hmd::update_presence(bool new_presence, int64_t timestamp)
|
||||
{
|
||||
if (this->presence.exchange(new_presence) != new_presence)
|
||||
{
|
||||
U_LOG_I("user presence changed to %s", new_presence ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
auto p = presence.lock();
|
||||
p->value = new_presence;
|
||||
p->change_time = timestamp;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_tracking.h"
|
||||
|
||||
#include <inplace_vector.hpp>
|
||||
|
||||
#include "view_list.h"
|
||||
|
||||
#include <array>
|
||||
@@ -33,18 +35,21 @@ namespace wivrn
|
||||
{
|
||||
class wivrn_session;
|
||||
|
||||
struct wivrn_hmd_presence_data
|
||||
{
|
||||
bool value;
|
||||
int64_t change_time;
|
||||
};
|
||||
|
||||
class wivrn_hmd : public xrt_device
|
||||
{
|
||||
xrt_input pose_input{
|
||||
.active = true,
|
||||
.name = XRT_INPUT_GENERIC_HEAD_POSE,
|
||||
};
|
||||
beman::inplace_vector::inplace_vector<xrt_input, 2> inputs_array;
|
||||
xrt_hmd_parts hmd_parts{};
|
||||
|
||||
view_list views;
|
||||
thread_safe<from_headset::battery> battery{};
|
||||
|
||||
std::atomic<bool> presence{true};
|
||||
thread_safe<wivrn_hmd_presence_data> presence;
|
||||
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||
|
||||
wivrn::wivrn_session * cnx;
|
||||
@@ -58,8 +63,8 @@ public:
|
||||
|
||||
void set_foveated_size(uint32_t width, uint32_t height);
|
||||
|
||||
xrt_result_t update_inputs();
|
||||
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation *);
|
||||
xrt_result_t get_presence(bool * out_presence);
|
||||
xrt_result_t get_view_poses(const xrt_vec3 * default_eye_relation,
|
||||
int64_t at_timestamp_ns,
|
||||
xrt_view_type view_type,
|
||||
@@ -74,6 +79,6 @@ public:
|
||||
void update_battery(const from_headset::battery &);
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
void update_visibility_mask(const from_headset::visibility_mask_changed &);
|
||||
bool update_presence(bool);
|
||||
void update_presence(bool new_presence, int64_t timestamp);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "util/u_device_id.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
@@ -38,6 +39,7 @@ namespace wivrn
|
||||
wivrn_htc_face_tracker::wivrn_htc_face_tracker(xrt_device * hmd,
|
||||
wivrn::wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.id = u_device_id_generate(),
|
||||
.name = XRT_DEVICE_HTC_FACE_TRACKING,
|
||||
.device_type = XRT_DEVICE_TYPE_FACE_TRACKER,
|
||||
.str = "WiVRn HTC Face Tracker",
|
||||
|
||||
+102
-86
@@ -43,6 +43,7 @@
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/to_string.h"
|
||||
|
||||
#include "b_body_tracker.h"
|
||||
#include "b_hand_tracker.h"
|
||||
#include "b_system.h"
|
||||
#include "target_builder_helpers.h"
|
||||
@@ -82,6 +83,7 @@ bool is_forced_extension(const char * ext_name)
|
||||
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, b_system & system) :
|
||||
xrt_system_devices{
|
||||
.get_roles = method_pointer<&wivrn_session::get_roles>,
|
||||
.create_body_tracker = b_body_tracker_create,
|
||||
.create_hand_tracker = b_hand_tracker_create,
|
||||
.feature_inc = method_pointer<&wivrn_session::feature_inc>,
|
||||
.feature_dec = method_pointer<&wivrn_session::feature_dec>,
|
||||
@@ -133,43 +135,52 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
roles.gamepad = static_xdev_count;
|
||||
static_xdevs[static_xdev_count++] = &gamepad_device.emplace(*this);
|
||||
|
||||
auto conf = configuration();
|
||||
|
||||
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
|
||||
auto use_steamvr_lh = configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
||||
xrt_system_devices * lhdevs = NULL;
|
||||
|
||||
auto use_steamvr_lh = conf.use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
||||
|
||||
if (use_steamvr_lh)
|
||||
{
|
||||
if (conf.lh_stick_deadzone > 0.01f)
|
||||
setenv("LH_STICK_DEADZONE", std::format("{:.2}", *conf.lh_stick_deadzone).c_str(), true);
|
||||
|
||||
if (conf.lh_max_extrapolation.has_value())
|
||||
setenv("LH_MAX_EXTRAPOLATION_MS", std::format("{}", *conf.lh_max_extrapolation).c_str(), true);
|
||||
|
||||
U_LOG_W("=====================");
|
||||
U_LOG_W("Disregard lighthousedb / chaperone related error messages from the lighthouse driver. These are irrelevant in case of WiVRn.");
|
||||
U_LOG_W("If getting a SIGSEGV right after this, you are likely using an unsupported SteamVR version!");
|
||||
U_LOG_W("=====================");
|
||||
if (steamvr_lh_create_devices(nullptr, &lhdevs) == XRT_SUCCESS)
|
||||
int original_count = static_xdev_count;
|
||||
if (steamvr_lh_create_devices(nullptr, this) == XRT_SUCCESS)
|
||||
{
|
||||
for (int i = 0; i < lhdevs->static_xdev_count; i++)
|
||||
for (int i = original_count; i < static_xdev_count; i++)
|
||||
{
|
||||
auto lhdev = lhdevs->static_xdevs[i];
|
||||
auto lhdev = static_xdevs[i];
|
||||
switch (lhdev->device_type)
|
||||
{
|
||||
case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER:
|
||||
roles.left = static_xdev_count;
|
||||
roles.left = i;
|
||||
static_roles.hand_tracking.unobstructed.left = nullptr;
|
||||
static_roles.hand_tracking.conforming.left = lhdev;
|
||||
break;
|
||||
case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER:
|
||||
roles.right = static_xdev_count;
|
||||
roles.right = i;
|
||||
static_roles.hand_tracking.unobstructed.right = nullptr;
|
||||
static_roles.hand_tracking.conforming.right = lhdev;
|
||||
break;
|
||||
case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER:
|
||||
if (roles.left == left_controller_index)
|
||||
{
|
||||
roles.left = static_xdev_count;
|
||||
roles.left = i;
|
||||
static_roles.hand_tracking.unobstructed.left = nullptr;
|
||||
static_roles.hand_tracking.conforming.left = lhdev;
|
||||
}
|
||||
else if (roles.right == right_controller_index)
|
||||
{
|
||||
roles.right = static_xdev_count;
|
||||
roles.right = i;
|
||||
static_roles.hand_tracking.unobstructed.right = nullptr;
|
||||
static_roles.hand_tracking.conforming.right = lhdev;
|
||||
}
|
||||
@@ -177,7 +188,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
default:
|
||||
break;
|
||||
}
|
||||
static_xdevs[static_xdev_count++] = lhdev;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +265,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
strlcpy(xrt_system.base.properties.name, system_name.c_str(), std::size(xrt_system.base.properties.name));
|
||||
}
|
||||
|
||||
if (configuration().hid_forwarding)
|
||||
if (conf.hid_forwarding)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -316,6 +326,9 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
}
|
||||
self->system_compositor = *out_xsysc;
|
||||
|
||||
struct xrt_pose t_stage_local = XRT_POSE_IDENTITY;
|
||||
t_stage_local.position.y = 1.6;
|
||||
|
||||
t_builder_create_space_overseer_legacy(
|
||||
&self->xrt_system.broadcast,
|
||||
&self->hmd,
|
||||
@@ -326,6 +339,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
self->static_xdevs,
|
||||
self->static_xdev_count,
|
||||
false,
|
||||
&t_stage_local,
|
||||
false,
|
||||
out_xspovrs);
|
||||
self->space_overseer = *out_xspovrs;
|
||||
@@ -347,12 +361,6 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
}
|
||||
}
|
||||
|
||||
auto dump_file = std::getenv("WIVRN_DUMP_TIMINGS");
|
||||
if (dump_file)
|
||||
{
|
||||
self->feedback_csv.open(dump_file);
|
||||
}
|
||||
|
||||
*out_xsysd = self.release();
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
@@ -371,13 +379,27 @@ void wivrn_session::stop()
|
||||
worker_thread = std::jthread();
|
||||
}
|
||||
|
||||
bool wivrn_session::request_stop()
|
||||
void wivrn_session::request_stop()
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
bool b = net_thread.request_stop();
|
||||
stop_application(std::nullopt, 2l * U_TIME_1S_IN_NS);
|
||||
|
||||
int64_t end = os_monotonic_get_ns() + 3l * U_TIME_1S_IN_NS;
|
||||
while (os_monotonic_get_ns() < end)
|
||||
{
|
||||
{
|
||||
scoped_lock lock(xrt_system.sessions.mutex);
|
||||
if (xrt_system.sessions.count == 0)
|
||||
{
|
||||
U_LOG_I("No more sessions, exiting");
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
net_thread.request_stop();
|
||||
worker_thread.request_stop();
|
||||
ipc_server_stop(mnd_ipc_server);
|
||||
return b;
|
||||
}
|
||||
|
||||
void wivrn_session::pause_session()
|
||||
@@ -386,14 +408,9 @@ void wivrn_session::pause_session()
|
||||
|
||||
// notify clients about session pause
|
||||
|
||||
update_client_states(false, false);
|
||||
|
||||
if (get_info().user_presence)
|
||||
{
|
||||
(*this)(from_headset::user_presence_changed{
|
||||
.present = false,
|
||||
});
|
||||
}
|
||||
hmd.update_presence(false, os_monotonic_get_ns());
|
||||
update_client_states(false, false);
|
||||
|
||||
// pause session components
|
||||
|
||||
@@ -442,13 +459,6 @@ void wivrn_session::resume_session()
|
||||
|
||||
compositor.resume();
|
||||
|
||||
if (get_info().user_presence)
|
||||
{
|
||||
(*this)(from_headset::user_presence_changed{
|
||||
.present = true,
|
||||
});
|
||||
}
|
||||
|
||||
(*this)(from_headset::get_application_list{
|
||||
.language = get_info().language,
|
||||
.country = get_info().country,
|
||||
@@ -459,6 +469,7 @@ void wivrn_session::resume_session()
|
||||
|
||||
worker_thread = std::jthread([this](std::stop_token stop) { return run_worker(stop); });
|
||||
update_client_states(true, true);
|
||||
hmd.update_presence(false, os_monotonic_get_ns());
|
||||
}
|
||||
|
||||
clock_offset wivrn_session::get_offset()
|
||||
@@ -791,17 +802,17 @@ void wivrn_session::operator()(from_headset::feedback && feedback)
|
||||
compositor.on_feedback(feedback, o);
|
||||
|
||||
if (feedback.received_first_packet)
|
||||
dump_time("receive_begin", feedback.frame_index, o.from_headset(feedback.received_first_packet), feedback.stream_index);
|
||||
trace::instant_feedback("receive_begin", o.from_headset(feedback.received_first_packet), feedback.frame_index, feedback.stream_index);
|
||||
if (feedback.received_last_packet)
|
||||
dump_time("receive_end", feedback.frame_index, o.from_headset(feedback.received_last_packet), feedback.stream_index);
|
||||
trace::instant_feedback("receive_end", o.from_headset(feedback.received_last_packet), feedback.frame_index, feedback.stream_index);
|
||||
if (feedback.sent_to_decoder)
|
||||
dump_time("decode_begin", feedback.frame_index, o.from_headset(feedback.sent_to_decoder), feedback.stream_index);
|
||||
trace::instant_feedback("decode_begin", o.from_headset(feedback.sent_to_decoder), feedback.frame_index, feedback.stream_index);
|
||||
if (feedback.received_from_decoder)
|
||||
dump_time("decode_end", feedback.frame_index, o.from_headset(feedback.received_from_decoder), feedback.stream_index);
|
||||
trace::instant_feedback("decode_end", o.from_headset(feedback.received_from_decoder), feedback.frame_index, feedback.stream_index);
|
||||
if (feedback.blitted)
|
||||
dump_time("blit", feedback.frame_index, o.from_headset(feedback.blitted), feedback.stream_index);
|
||||
trace::instant_feedback("blit", o.from_headset(feedback.blitted), feedback.frame_index, feedback.stream_index);
|
||||
if (feedback.displayed)
|
||||
dump_time("display", feedback.frame_index, o.from_headset(feedback.displayed), feedback.stream_index);
|
||||
trace::instant_feedback("display", o.from_headset(feedback.displayed), feedback.frame_index, feedback.stream_index);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::battery && battery)
|
||||
@@ -845,14 +856,9 @@ void wivrn_session::operator()(from_headset::session_state_changed && event)
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
{
|
||||
if (hmd.update_presence(event.present))
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
.is_user_present = event.present,
|
||||
},
|
||||
});
|
||||
clock_offset o = offset_est.get_offset();
|
||||
U_LOG_I("user presence changed to %s", event.present ? "true" : "false");
|
||||
hmd.update_presence(event.present, o ? o.from_headset(event.change_time) : os_monotonic_get_ns());
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
|
||||
@@ -966,30 +972,7 @@ void wivrn_session::operator()(const from_headset::set_active_application & req)
|
||||
|
||||
void wivrn_session::operator()(const from_headset::stop_application & req)
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
scoped_lock lock(mnd_ipc_server->global_state.lock);
|
||||
for (auto & t: mnd_ipc_server->threads)
|
||||
{
|
||||
if (t.ics.client_state.id == req.id)
|
||||
{
|
||||
if (!t.ics.xs)
|
||||
{
|
||||
U_LOG_W("Unable to stop app %s: no session!", t.ics.client_state.info.application_name);
|
||||
break;
|
||||
}
|
||||
|
||||
U_LOG_I("Request exit for application %s", t.ics.client_state.info.application_name);
|
||||
xrt_result_t xret = xrt_session_request_exit(t.ics.xs);
|
||||
if (xret != XRT_SUCCESS)
|
||||
{
|
||||
U_LOG_W("Failed to request exit for application %s: %s", t.ics.client_state.info.application_name, u_str_xrt_result(xret));
|
||||
}
|
||||
|
||||
auto when = os_monotonic_get_ns() + 10l * U_TIME_1S_IN_NS;
|
||||
session_loss.lock()->emplace(req.id, when);
|
||||
break;
|
||||
}
|
||||
}
|
||||
stop_application(req.id, 10l * U_TIME_1S_IN_NS);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(audio_data && data)
|
||||
@@ -1085,10 +1068,17 @@ void wivrn_session::run_net(std::stop_token stop)
|
||||
for (auto & haptics: uinput_handler->read_rumble())
|
||||
send_stream(std::move(haptics));
|
||||
}
|
||||
|
||||
if (auto locked = net_exception.lock(); *locked)
|
||||
{
|
||||
std::exception_ptr ex;
|
||||
std::swap(ex, *locked);
|
||||
std::rethrow_exception(ex);
|
||||
}
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_W("Exception in network thread: %s, Session paused.", e.what());
|
||||
U_LOG_W("Network exception: %s, Session paused.", e.what());
|
||||
pause_session();
|
||||
|
||||
reconnect(stop);
|
||||
@@ -1159,20 +1149,14 @@ void wivrn_session::set_foveated_size(uint32_t width, uint32_t height)
|
||||
hmd.set_foveated_size(width, height);
|
||||
}
|
||||
|
||||
void wivrn_session::dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream, const char * extra)
|
||||
{
|
||||
trace::instant_feedback(event.c_str(), time, frame, stream);
|
||||
if (feedback_csv)
|
||||
{
|
||||
std::lock_guard lock(csv_mutex);
|
||||
feedback_csv << std::quoted(event) << "," << frame << "," << time << "," << (int)stream << extra << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::quit_if_no_client()
|
||||
{
|
||||
scoped_lock lock(xrt_system.sessions.mutex);
|
||||
if (xrt_system.sessions.count == 0)
|
||||
uint32_t count;
|
||||
{
|
||||
scoped_lock lock(xrt_system.sessions.mutex);
|
||||
count = xrt_system.sessions.count;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
U_LOG_I("No OpenXR client connected, exiting");
|
||||
request_stop();
|
||||
@@ -1291,6 +1275,7 @@ void wivrn_session::reconnect(std::stop_token stop)
|
||||
}
|
||||
|
||||
connection->reset(stop, std::move(*tcp), [this]() { quit_if_no_client(); });
|
||||
*net_exception.lock() = nullptr;
|
||||
|
||||
// validate if headset is compatible with the current session
|
||||
|
||||
@@ -1338,6 +1323,37 @@ void wivrn_session::reconnect(std::stop_token stop)
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::stop_application(std::optional<uint32_t> id, int64_t timeout_ns)
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
scoped_lock lock(mnd_ipc_server->global_state.lock);
|
||||
for (auto & t: mnd_ipc_server->threads)
|
||||
{
|
||||
if (t.state == IPC_THREAD_READY || t.state == IPC_THREAD_STOPPING)
|
||||
continue;
|
||||
|
||||
uint32_t client_id = t.ics.client_state.id;
|
||||
if (not id.has_value() or client_id == *id)
|
||||
{
|
||||
if (!t.ics.xs)
|
||||
{
|
||||
U_LOG_W("Unable to stop app %s: no session!", t.ics.client_state.info.application_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
U_LOG_I("Request exit for application %s", t.ics.client_state.info.application_name);
|
||||
xrt_result_t xret = xrt_session_request_exit(t.ics.xs);
|
||||
if (xret != XRT_SUCCESS)
|
||||
{
|
||||
U_LOG_W("Failed to request exit for application %s: %s", t.ics.client_state.info.application_name, u_str_xrt_result(xret));
|
||||
}
|
||||
|
||||
auto when = os_monotonic_get_ns() + timeout_ns;
|
||||
session_loss.lock()->emplace(client_id, when);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::update_client_states(bool visible, bool focused)
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "wivrn_uinput.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
#include "xrt/xrt_system.h"
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -110,9 +109,6 @@ class wivrn_session : public xrt_system_devices
|
||||
clock_offset_estimator offset_est;
|
||||
std::atomic<XrDuration> tracking_latency; // production to reception time
|
||||
|
||||
std::mutex csv_mutex;
|
||||
std::ofstream feedback_csv;
|
||||
|
||||
std::unique_ptr<audio_device> audio_handle;
|
||||
|
||||
// when sessions shall be destroyed, key is client id, value is timestamp
|
||||
@@ -121,6 +117,8 @@ class wivrn_session : public xrt_system_devices
|
||||
std::jthread net_thread;
|
||||
std::jthread worker_thread;
|
||||
|
||||
thread_safe<std::exception_ptr> net_exception;
|
||||
|
||||
wivrn_session(std::unique_ptr<wivrn_connection> connection, b_system &);
|
||||
|
||||
public:
|
||||
@@ -136,7 +134,7 @@ public:
|
||||
void start(ipc_server *);
|
||||
void stop();
|
||||
|
||||
bool request_stop();
|
||||
void request_stop();
|
||||
void quit_if_no_client();
|
||||
|
||||
clock_offset get_offset();
|
||||
@@ -204,21 +202,35 @@ public:
|
||||
template <typename T>
|
||||
void send_stream(T && packet)
|
||||
{
|
||||
connection->send_stream(std::forward<T>(packet));
|
||||
try
|
||||
{
|
||||
connection->send_stream(std::forward<T>(packet));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
*net_exception.lock() = std::current_exception();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void send_control(T && packet)
|
||||
{
|
||||
connection->send_control(std::forward<T>(packet));
|
||||
try
|
||||
{
|
||||
connection->send_control(std::forward<T>(packet));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
*net_exception.lock() = std::current_exception();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
xrt_result_t push_event(const xrt_session_event &);
|
||||
|
||||
void set_foveated_size(uint32_t width, uint32_t height);
|
||||
|
||||
void dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream = -1, const char * extra = "");
|
||||
|
||||
private:
|
||||
void run_net(std::stop_token stop);
|
||||
void run_worker(std::stop_token stop);
|
||||
@@ -227,6 +239,9 @@ private:
|
||||
void pause_session();
|
||||
void resume_session();
|
||||
|
||||
// nullopt for id stops all apps
|
||||
void stop_application(std::optional<uint32_t> id, int64_t timeout_ns);
|
||||
|
||||
void update_client_states(bool visible, bool focused);
|
||||
void poll_session_loss();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ wivrn::fd_base open_uinput_or_throw(int flags = O_WRONLY)
|
||||
int fd = ::open(p, flags | O_NONBLOCK);
|
||||
if (fd >= 0)
|
||||
return fd;
|
||||
if (errno != ENOENT) // exists but inaccessbile
|
||||
if (errno != ENOENT) // exists but inaccessible
|
||||
throw std::system_error(errno, std::generic_category(), "error while opening uinput");
|
||||
}
|
||||
throw std::runtime_error("no uinput device found");
|
||||
|
||||
@@ -223,17 +223,6 @@ public:
|
||||
if (config.codec == video_codec::raw or config.name == encoder_raw)
|
||||
return {encoder_raw, video_codec::raw};
|
||||
|
||||
#if WIVRN_USE_NVENC
|
||||
if ((nvidia and config.name.empty()) or config.name == encoder_nvenc)
|
||||
{
|
||||
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
|
||||
{
|
||||
if (check_nvenc(codec))
|
||||
return {encoder_nvenc, codec};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
if (config.name.empty() or config.name == encoder_vulkan)
|
||||
{
|
||||
@@ -245,6 +234,17 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WIVRN_USE_NVENC
|
||||
if ((nvidia and config.name.empty()) or config.name == encoder_nvenc)
|
||||
{
|
||||
for (auto codec: config.codec ? std::vector{*config.codec} : info.supported_codecs)
|
||||
{
|
||||
if (check_nvenc(codec))
|
||||
return {encoder_nvenc, codec};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WIVRN_USE_VAAPI
|
||||
if (config.name.empty() or config.name == encoder_vaapi)
|
||||
{
|
||||
|
||||
@@ -287,8 +287,6 @@ void video_encoder::encode(wivrn_session & cnx,
|
||||
shard.timing_info.reset();
|
||||
|
||||
auto data = encode(encode_slot, frame_index);
|
||||
cnx.dump_time("encode_begin", frame_index, encode_begin, stream_idx);
|
||||
cnx.dump_time("encode_end", frame_index, os_monotonic_get_ns(), stream_idx);
|
||||
if (data)
|
||||
{
|
||||
timing_info.encode_end = clock.to_headset(os_monotonic_get_ns());
|
||||
@@ -304,7 +302,6 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
|
||||
{
|
||||
// One SendData call per NAL; span the whole frame, not each call.
|
||||
wivrn::trace::cpu_begin(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData");
|
||||
cnx->dump_time("send_begin", shard.frame_idx, os_monotonic_get_ns(), stream_idx);
|
||||
timing_info.send_begin = clock.to_headset(os_monotonic_get_ns());
|
||||
}
|
||||
if (end_of_frame)
|
||||
@@ -346,10 +343,7 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
|
||||
begin = next;
|
||||
}
|
||||
if (end_of_frame)
|
||||
{
|
||||
cnx->dump_time("send_end", shard.frame_idx, os_monotonic_get_ns(), stream_idx);
|
||||
wivrn::trace::cpu_end(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -134,7 +134,7 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(
|
||||
.bit_depth_luma_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.bit_depth_chroma_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.log2_max_pic_order_cnt_lsb_minus4 = 4, // arbitrary
|
||||
.log2_min_luma_coding_block_size_minus3 = 0, // keep it 0, related values are filled in create()
|
||||
.log2_min_luma_coding_block_size_minus3 = 0, // set in create(), with the related values
|
||||
.num_short_term_ref_pic_sets = 0,
|
||||
.num_long_term_ref_pics_sps = 0,
|
||||
.pcm_sample_bit_depth_luma_minus1 = 0,
|
||||
@@ -309,12 +309,14 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h265> wivrn::video_encoder_vulkan_h2
|
||||
self->rate_control->pNext = &self->rc_h265;
|
||||
}
|
||||
|
||||
self->sps.log2_diff_max_min_luma_coding_block_size = find_msb((uint32_t)encode_h265_caps.ctbSizes) + 1; // First bit is 16x16.
|
||||
const uint32_t log2_ctb_size = find_msb((uint32_t)encode_h265_caps.ctbSizes) + 4;
|
||||
self->sps.log2_min_luma_coding_block_size_minus3 = 1;
|
||||
self->sps.log2_diff_max_min_luma_coding_block_size = log2_ctb_size - 4;
|
||||
self->sps.log2_min_luma_transform_block_size_minus2 = find_lsb((uint32_t)encode_h265_caps.transformBlockSizes);
|
||||
self->sps.log2_diff_max_min_luma_transform_block_size =
|
||||
find_msb((uint32_t)encode_h265_caps.transformBlockSizes) - find_lsb((uint32_t)encode_h265_caps.transformBlockSizes);
|
||||
|
||||
uint32_t max_transform_hierarchy = (find_msb((uint32_t)encode_h265_caps.ctbSizes) + 4) - (find_lsb((uint32_t)encode_h265_caps.transformBlockSizes) + 2);
|
||||
uint32_t max_transform_hierarchy = log2_ctb_size - (find_lsb((uint32_t)encode_h265_caps.transformBlockSizes) + 2);
|
||||
self->sps.max_transform_hierarchy_depth_inter = max_transform_hierarchy;
|
||||
self->sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy;
|
||||
|
||||
|
||||
+25
-8
@@ -1,3 +1,23 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022-2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022-2026 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// Original copyright, from very old copy-pasted parts
|
||||
// Copyright 2022, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
@@ -9,7 +29,6 @@
|
||||
#include "openxr/openxr.h"
|
||||
#include "sleep_inhibitor.h"
|
||||
#include "util/u_trace_marker.h"
|
||||
#include "utils/wivrn_trace.h"
|
||||
|
||||
#include "active_runtime.h"
|
||||
#include "avahi_publisher.h"
|
||||
@@ -19,6 +38,7 @@
|
||||
#include "ipc_server_cb.h"
|
||||
#include "protocol_version.h"
|
||||
#include "start_application.h"
|
||||
#include "start_systemd_unit.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "version.h"
|
||||
#include "wivrn_config.h"
|
||||
@@ -53,10 +73,6 @@
|
||||
#include <shared/ipc_protocol.h>
|
||||
#include <util/u_file.h>
|
||||
|
||||
#if WIVRN_USE_SYSTEMD
|
||||
#include "start_systemd_unit.h"
|
||||
#endif
|
||||
|
||||
// Insert the on load constructor to init trace marker.
|
||||
U_TRACE_TARGET_SETUP(U_TRACE_WHICH_SERVICE)
|
||||
|
||||
@@ -237,6 +253,9 @@ void start_server(configuration config)
|
||||
}
|
||||
else if (server_pid == 0)
|
||||
{
|
||||
if (do_fork)
|
||||
setsid();
|
||||
|
||||
setenv("AMD_DEBUG", "lowlatencyenc", false);
|
||||
|
||||
// https://github.com/WiVRn/WiVRn/issues/695
|
||||
@@ -300,7 +319,7 @@ void kill_server()
|
||||
wivrn_ipc_socket_main_loop->send(to_monado::stop{});
|
||||
|
||||
// Send SIGTERM after 1s if it is still running
|
||||
server_kill_watch = g_timeout_add(1000, [](void *) {
|
||||
server_kill_watch = g_timeout_add(3500, [](void *) {
|
||||
assert(server_pid > 0);
|
||||
kill(-server_pid, SIGTERM);
|
||||
return G_SOURCE_REMOVE; }, 0);
|
||||
@@ -819,13 +838,11 @@ void on_headset_info_packet(const wivrn::from_headset::headset_info_packet & inf
|
||||
|
||||
void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer user_data)
|
||||
{
|
||||
#if WIVRN_USE_SYSTEMD
|
||||
try
|
||||
{
|
||||
children = std::make_unique<systemd_units_manager>(connection, update_fsm);
|
||||
}
|
||||
catch (...)
|
||||
#endif
|
||||
{
|
||||
children = std::make_unique<forked_children>(update_fsm);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void set_calibration_source(::vk_bundle * monado_vk);
|
||||
|
||||
// Instant on the feedback track at an explicit monotonic timestamp.
|
||||
// name is copied at emit time (perfetto::DynamicString), so it need not outlive the call.
|
||||
void instant_feedback(const char * name, int64_t time_ns, uint64_t frame, uint8_t stream);
|
||||
void instant_feedback(const char * name, int64_t time_ns, uint64_t frame, uint8_t stream = -1);
|
||||
|
||||
// GPU-hardware-timestamped slice on the WiVRn encoder track.
|
||||
// begin_ns/end_ns must come from GPU query pools (gpu_timestamp_pool::collect),
|
||||
|
||||
@@ -36,15 +36,9 @@ namespace
|
||||
{
|
||||
|
||||
VkBool32 message_callback(
|
||||
#if VK_HEADER_VERSION >= 304
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
vk::DebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
const vk::DebugUtilsMessengerCallbackDataEXT * pCallbackData,
|
||||
#else
|
||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT * pCallbackData,
|
||||
#endif
|
||||
void * pUserData)
|
||||
{
|
||||
u_logging_level level = U_LOGGING_ERROR;
|
||||
@@ -150,7 +144,7 @@ wivrn::vk_bundle::vk_bundle() :
|
||||
vk::ApplicationInfo app_info{
|
||||
.pApplicationName = "WiVRn server",
|
||||
.pEngineName = "WiVRn",
|
||||
.apiVersion = VK_API_VERSION_1_3,
|
||||
.apiVersion = api_version,
|
||||
};
|
||||
{
|
||||
// Required extensions
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "vk/vk_allocator.h"
|
||||
#include <cstdint>
|
||||
#include <inplace_vector.hpp>
|
||||
#include <mutex>
|
||||
#include <pthread.h>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
@@ -63,6 +62,7 @@ uint64_t vk_handle(const T & handle)
|
||||
|
||||
struct vk_bundle
|
||||
{
|
||||
static const uint32_t api_version = VK_API_VERSION_1_3;
|
||||
// Lockable that can be redirected to a pthread_mutex_t owned by monado,
|
||||
// so that all VkQueue submitters take the same lock.
|
||||
class queue_mutex
|
||||
|
||||
Reference in New Issue
Block a user