Compare commits
34
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aa60efbde | ||
|
|
84ef968dc3 | ||
|
|
a1b94f1dfc | ||
|
|
d8c8020d84 | ||
|
|
6e6dfc68fc | ||
|
|
5307f2fe62 | ||
|
|
a8e2a8b237 | ||
|
|
ec42db83bc | ||
|
|
ed32676299 | ||
|
|
d64d5909ee | ||
|
|
d8ad913b27 | ||
|
|
c5dab27f3c | ||
|
|
f8e132234b | ||
|
|
717e93846a | ||
|
|
c682f8cd9f | ||
|
|
8f0ca7b04c | ||
|
|
74befe1f4a | ||
|
|
6f22068c42 | ||
|
|
86737b71e0 | ||
|
|
a6660434e9 | ||
|
|
ecf6dfd215 | ||
|
|
94431458dc | ||
|
|
88f03acfbf | ||
|
|
f2f31e69ac | ||
|
|
8686233b49 | ||
|
|
11cd9235d9 | ||
|
|
fbe5430dc2 | ||
|
|
be504b5944 | ||
|
|
c9e078bd47 | ||
|
|
db08e4f361 | ||
|
|
fafe01b76a | ||
|
|
b66ca2e561 | ||
|
|
0cdb00fa83 | ||
|
|
5bfc9ed942 |
@@ -153,11 +153,13 @@ jobs:
|
||||
nix-test:
|
||||
name: Test Nix package and devshell
|
||||
runs-on: ubuntu-24.04
|
||||
if: ${{ vars.APK_ONLY == '' }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
- run: nix flake check
|
||||
- run: nix build
|
||||
|
||||
@@ -88,6 +88,8 @@
|
||||
|
||||
<!-- https://developer.oculus.com/documentation/native/android/mobile-splash/ -->
|
||||
<meta-data android:name="com.oculus.ossplash" android:value="true"/>
|
||||
<!-- https://developers.meta.com/horizon/documentation/native/android/mobile-passthrough-loading-screens -->
|
||||
<meta-data android:name="com.oculus.ossplash.background" android:value="passthrough-contextual"/>
|
||||
|
||||
<!-- The activity is the built-in NativeActivity framework class. -->
|
||||
<!-- launchMode is set to singleTask because there should never be multiple copies of the app running. -->
|
||||
|
||||
+2
-2
@@ -239,9 +239,9 @@ endif()
|
||||
|
||||
if (WIVRN_BUILD_DISSECTOR)
|
||||
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
|
||||
find_package(OpenXR 1.0.34)
|
||||
find_package(OpenXR 1.1.48)
|
||||
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
|
||||
find_package(OpenXR 1.0.34 REQUIRED)
|
||||
find_package(OpenXR 1.1.48 REQUIRED)
|
||||
endif()
|
||||
find_package(Wireshark REQUIRED)
|
||||
endif()
|
||||
|
||||
+73
-10
@@ -517,6 +517,35 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
"/user/hand/right/input/thumbrest/touch",
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/ext/hand_interaction_ext",
|
||||
.required_extensions = {"XR_EXT_hand_interaction"},
|
||||
.input_sources = {
|
||||
"/user/hand/left/input/aim/pose",
|
||||
"/user/hand/left/input/grip/pose",
|
||||
|
||||
"/user/hand/left/input/pinch_ext/pose",
|
||||
"/user/hand/left/input/pinch_ext/value",
|
||||
"/user/hand/left/input/pinch_ext/ready_ext",
|
||||
"/user/hand/left/input/poke_ext/pose",
|
||||
"/user/hand/left/input/aim_activate_ext/value",
|
||||
"/user/hand/left/input/aim_activate_ext/ready_ext",
|
||||
"/user/hand/left/input/grasp_ext/value",
|
||||
"/user/hand/left/input/grasp_ext/ready_ext",
|
||||
|
||||
"/user/hand/right/input/aim/pose",
|
||||
"/user/hand/right/input/grip/pose",
|
||||
|
||||
"/user/hand/right/input/pinch_ext/pose",
|
||||
"/user/hand/right/input/pinch_ext/value",
|
||||
"/user/hand/right/input/pinch_ext/ready_ext",
|
||||
"/user/hand/right/input/poke_ext/pose",
|
||||
"/user/hand/right/input/aim_activate_ext/value",
|
||||
"/user/hand/right/input/aim_activate_ext/ready_ext",
|
||||
"/user/hand/right/input/grasp_ext/value",
|
||||
"/user/hand/right/input/grasp_ext/ready_ext",
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
|
||||
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
|
||||
@@ -556,6 +585,9 @@ static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
||||
{"/joystick", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
{"/trackball", XR_ACTION_TYPE_VECTOR2F_INPUT},
|
||||
|
||||
// XR_EXT_hand_interaction
|
||||
{"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
|
||||
|
||||
// Output paths
|
||||
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
|
||||
@@ -949,19 +981,41 @@ void application::initialize_actions()
|
||||
continue;
|
||||
|
||||
// Patch profile to add grip_surface or palm_ext
|
||||
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
|
||||
bool add_palms = true;
|
||||
if (profile.profile_name.ends_with("ext/hand_interaction_ext"))
|
||||
{
|
||||
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
|
||||
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
|
||||
switch (guess_model())
|
||||
{
|
||||
// Quest breaks spec and does not support grip_surface for ext/hand_interaction_ext
|
||||
case model::meta_quest_3:
|
||||
case model::meta_quest_pro:
|
||||
case model::meta_quest_3s:
|
||||
case model::oculus_quest_2:
|
||||
case model::oculus_quest:
|
||||
add_palms = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
|
||||
if (add_palms)
|
||||
{
|
||||
profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
|
||||
profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
|
||||
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
|
||||
{
|
||||
spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name);
|
||||
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
|
||||
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
|
||||
}
|
||||
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
|
||||
{
|
||||
spdlog::info("Adding palm_ext/pose for interaction profile {}", profile.profile_name);
|
||||
profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
|
||||
profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamically add VIVE XR Trackers to the profile if available
|
||||
@@ -1004,12 +1058,20 @@ void application::initialize_actions()
|
||||
spaces[size_t(xr::spaces::aim_left)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/left/input/palm_ext/pose" or name == "/user/hand/left/input/grip_surface/pose")
|
||||
spaces[size_t(xr::spaces::palm_left)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/left/input/pinch_ext/pose")
|
||||
spaces[size_t(xr::spaces::pinch_left)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/left/input/poke_ext/pose")
|
||||
spaces[size_t(xr::spaces::poke_left)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/right/input/grip/pose")
|
||||
spaces[size_t(xr::spaces::grip_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/right/input/aim/pose")
|
||||
spaces[size_t(xr::spaces::aim_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/right/input/palm_ext/pose" or name == "/user/hand/right/input/grip_surface/pose")
|
||||
spaces[size_t(xr::spaces::palm_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/right/input/pinch_ext/pose")
|
||||
spaces[size_t(xr::spaces::pinch_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/hand/right/input/poke_ext/pose")
|
||||
spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
|
||||
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
|
||||
else if (name.contains("/input/entity_htc/pose") && htc_body)
|
||||
@@ -1098,6 +1160,7 @@ void application::initialize()
|
||||
opt_extensions.push_back(XR_KHR_MAINTENANCE1_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_EXT_HAND_TRACKING_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_EXT_HAND_INTERACTION_EXTENSION_NAME);
|
||||
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);
|
||||
|
||||
@@ -348,6 +348,24 @@ std::pair<glm::vec3, glm::quat> controller_offset(std::string_view profile, xr::
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (profile == "meta-quest-touch-plus")
|
||||
{
|
||||
switch (space)
|
||||
{
|
||||
case xr::spaces::grip_left:
|
||||
case xr::spaces::grip_right:
|
||||
return {{0, -0.010, -0.025}, glm::angleAxis(glm::radians(-12.f), glm::vec3{1, 0, 0})};
|
||||
|
||||
case xr::spaces::aim_left:
|
||||
return {{0, 0, 0.03}, {1, 0, 0, 0}};
|
||||
|
||||
case xr::spaces::aim_right:
|
||||
return {{0, 0, 0.03}, {1, 0, 0, 0}};
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (profile == "htc-vive-focus-3")
|
||||
switch (space)
|
||||
{
|
||||
|
||||
@@ -966,6 +966,12 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
.depthMask = true,
|
||||
.compareOp = application::get_config().passthrough_enabled ? XR_COMPARE_OP_LESS_FB : XR_COMPARE_OP_LESS_OR_EQUAL_FB,
|
||||
};
|
||||
XrCompositionLayerDepthTestFB layer_depth_test_bg{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_DEPTH_TEST_FB,
|
||||
.next = nullptr,
|
||||
.depthMask = true,
|
||||
.compareOp = XR_COMPARE_OP_ALWAYS_FB,
|
||||
};
|
||||
|
||||
// if (composition_layer_depth_test_supported or not application::get_config().passthrough_enabled)
|
||||
layers_with_z_index.emplace_back(constants::lobby::zindex_lobby, reinterpret_cast<XrCompositionLayerBaseHeader *>(&lobby_layer));
|
||||
@@ -977,7 +983,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
{
|
||||
lobby_layer.next = &layer_depth_test;
|
||||
lobby_layer.next = &layer_depth_test_bg;
|
||||
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
{
|
||||
|
||||
+70
-18
@@ -117,6 +117,21 @@ static const std::unordered_map<std::string, device_id> device_ids = {
|
||||
{"/user/hand/right/input/trackpad/force", device_id::RIGHT_TRACKPAD_FORCE},
|
||||
{"/user/hand/right/input/stylus/force", device_id::RIGHT_STYLUS_FORCE},
|
||||
{"/user/hand/right/input/stylus_fb/force", device_id::RIGHT_STYLUS_FORCE},
|
||||
|
||||
// XR_EXT_hand_interaction
|
||||
{"/user/hand/left/input/pinch_ext/value", device_id::LEFT_PINCH_VALUE},
|
||||
{"/user/hand/left/input/pinch_ext/ready_ext", device_id::LEFT_PINCH_READY},
|
||||
{"/user/hand/left/input/aim_activate_ext/value",device_id::LEFT_AIM_ACTIVATE_VALUE},
|
||||
{"/user/hand/left/input/aim_activate_ext/ready_ext",device_id::LEFT_AIM_ACTIVATE_READY},
|
||||
{"/user/hand/left/input/grasp_ext/value", device_id::LEFT_GRASP_VALUE},
|
||||
{"/user/hand/left/input/grasp_ext/ready_ext", device_id::LEFT_GRASP_READY},
|
||||
|
||||
{"/user/hand/right/input/pinch_ext/value", device_id::RIGHT_PINCH_VALUE},
|
||||
{"/user/hand/right/input/pinch_ext/ready_ext", device_id::RIGHT_PINCH_READY},
|
||||
{"/user/hand/right/input/aim_activate_ext/value",device_id::RIGHT_AIM_ACTIVATE_VALUE},
|
||||
{"/user/hand/right/input/aim_activate_ext/ready_ext",device_id::RIGHT_AIM_ACTIVATE_READY},
|
||||
{"/user/hand/right/input/grasp_ext/value", device_id::RIGHT_GRASP_VALUE},
|
||||
{"/user/hand/right/input/grasp_ext/ready_ext", device_id::RIGHT_GRASP_READY},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@@ -218,7 +233,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
info.hand_tracking = config.check_feature(feature::hand_tracking);
|
||||
info.eye_gaze = config.check_feature(feature::eye_gaze);
|
||||
info.presence = self->instance.has_extension(XR_EXT_USER_PRESENCE_EXTENSION_NAME) && self->system.user_presence_properties().supportsUserPresence;
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
@@ -269,9 +283,16 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
{
|
||||
for (uint8_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
self->network_session->send_control(from_headset::visibility_mask_changed{
|
||||
.data = get_visibility_mask(self->instance, self->session, view),
|
||||
.view_index = view});
|
||||
try
|
||||
{
|
||||
self->network_session->send_control(from_headset::visibility_mask_changed{
|
||||
.data = get_visibility_mask(self->instance, self->session, view),
|
||||
.view_index = view});
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Failed to get visibility mask: ", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +406,10 @@ void scenes::stream::on_focused()
|
||||
}
|
||||
|
||||
assert(video_stream_description);
|
||||
setup_reprojection_swapchain();
|
||||
std::unique_lock lock(decoder_mutex);
|
||||
setup_reprojection_swapchain(
|
||||
video_stream_description->defoveated_width / view_count,
|
||||
video_stream_description->defoveated_height);
|
||||
}
|
||||
|
||||
void scenes::stream::on_unfocused()
|
||||
@@ -749,8 +773,6 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
session.begin_frame();
|
||||
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
std::array<int, view_count> image_indices;
|
||||
|
||||
command_buffer.reset();
|
||||
@@ -890,15 +912,43 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
|
||||
// defoveate the image
|
||||
auto extents = reprojector->reproject(command_buffer, foveation, image_index);
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
XrExtent2Di extents[view_count];
|
||||
{
|
||||
extents[i] = {
|
||||
.width = std::min(extents[i].width, swapchain.width()),
|
||||
.height = std::min(extents[i].height, swapchain.height()),
|
||||
};
|
||||
int32_t max_width = 0;
|
||||
int32_t max_height = 0;
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i] = reprojector->defoveated_size(foveation[i]);
|
||||
max_width = std::max(max_width, extents[i].width);
|
||||
max_height = std::max(max_height, extents[i].height);
|
||||
}
|
||||
// If the defoveated image is larger than the swapchain, try to reallocate one
|
||||
if (swapchain.width() < max_width or swapchain.height() < max_height)
|
||||
{
|
||||
try
|
||||
{
|
||||
spdlog::info("Recreating swapchain, from {}x{} to {}x{}",
|
||||
swapchain.width(),
|
||||
swapchain.height(),
|
||||
max_width,
|
||||
max_height);
|
||||
setup_reprojection_swapchain(max_width, max_height);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("failed to increase swapchain size");
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i].width = std::min(extents[i].width, swapchain.width());
|
||||
extents[i].height = std::min(extents[i].height, swapchain.height());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// defoveate the image
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
reprojector->reproject(command_buffer, foveation, image_index);
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -1185,16 +1235,13 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::setup_reprojection_swapchain()
|
||||
void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint32_t swapchain_height)
|
||||
{
|
||||
std::unique_lock lock(decoder_mutex);
|
||||
device.waitIdle();
|
||||
session.set_refresh_rate(video_stream_description->fps);
|
||||
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
uint32_t swapchain_width = video_stream_description->defoveated_width / view_count;
|
||||
uint32_t swapchain_height = video_stream_description->defoveated_height;
|
||||
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
@@ -1289,6 +1336,11 @@ void scenes::stream::on_xr_event(const xr::event & event)
|
||||
.view_index = uint8_t(event.visibility_mask_changed.viewIndex),
|
||||
});
|
||||
break;
|
||||
case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED:
|
||||
network_session->send_control(from_headset::session_state_changed{
|
||||
.state = event.state_changed.state,
|
||||
});
|
||||
break;
|
||||
case XR_TYPE_EVENT_DATA_USER_PRESENCE_CHANGED_EXT:
|
||||
network_session->send_control(from_headset::user_presence_changed{
|
||||
.present = (bool)event.user_presence_changed.isUserPresent,
|
||||
|
||||
@@ -180,7 +180,7 @@ private:
|
||||
void on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &);
|
||||
|
||||
void setup(const to_headset::video_stream_description &);
|
||||
void setup_reprojection_swapchain();
|
||||
void setup_reprojection_swapchain(uint32_t width, uint32_t height);
|
||||
void exit();
|
||||
|
||||
vk::raii::QueryPool query_pool = nullptr;
|
||||
|
||||
@@ -390,15 +390,14 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
|
||||
ensure_vertices(std::max(required_vertices(foveation[0]), required_vertices(foveation[1])));
|
||||
std::vector<XrExtent2Di> out_extents(view_count, XrExtent2Di{});
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
@@ -409,13 +408,6 @@ std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
out_extents[view].width += ratio_x * n_out_x;
|
||||
}
|
||||
|
||||
glm::vec2 in(0), out(0); // pixel coordinates
|
||||
glm::vec2 in_pixel_size(1. / input_extent.width,
|
||||
1. / input_extent.height);
|
||||
@@ -425,7 +417,6 @@ std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
out_extents[view].height += ratio_y * n_out_y;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
@@ -496,5 +487,25 @@ std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer
|
||||
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
}
|
||||
return out_extents;
|
||||
}
|
||||
|
||||
static uint16_t count_pixels(const std::vector<uint16_t> & param)
|
||||
{
|
||||
uint16_t res = 0;
|
||||
const int n_ratio = (param.size() - 1) / 2;
|
||||
for (auto [i, n_out]: utils::enumerate_range(param))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio = std::abs(n_ratio - int(i)) + 1;
|
||||
res += ratio * n_out;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
XrExtent2Di stream_reprojection::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
{
|
||||
return {
|
||||
count_pixels(view.x),
|
||||
count_pixels(view.y),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,8 +70,10 @@ public:
|
||||
|
||||
stream_reprojection(const stream_reprojection &) = delete;
|
||||
|
||||
std::vector<XrExtent2Di> reproject(
|
||||
void reproject(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination);
|
||||
|
||||
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
|
||||
};
|
||||
|
||||
@@ -234,31 +234,6 @@ static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static bool enabled(const to_headset::tracking_control & control, device_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case device_id::HEAD:
|
||||
case device_id::EYE_GAZE:
|
||||
return true;
|
||||
case device_id::LEFT_AIM:
|
||||
return control.enabled[size_t(tid::left_aim)];
|
||||
case device_id::LEFT_GRIP:
|
||||
return control.enabled[size_t(tid::left_grip)];
|
||||
case device_id::LEFT_PALM:
|
||||
return control.enabled[size_t(tid::left_palm)];
|
||||
case device_id::RIGHT_AIM:
|
||||
return control.enabled[size_t(tid::right_aim)];
|
||||
case device_id::RIGHT_GRIP:
|
||||
return control.enabled[size_t(tid::right_grip)];
|
||||
case device_id::RIGHT_PALM:
|
||||
return control.enabled[size_t(tid::right_palm)];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T & from_pool(std::vector<T> & container, std::vector<T> & pool)
|
||||
{
|
||||
@@ -283,12 +258,20 @@ static xr::spaces device_to_space(device_id id)
|
||||
return xr::spaces::grip_left;
|
||||
case device_id::LEFT_PALM:
|
||||
return xr::spaces::palm_left;
|
||||
case device_id::LEFT_PINCH_POSE:
|
||||
return xr::spaces::pinch_left;
|
||||
case device_id::LEFT_POKE:
|
||||
return xr::spaces::poke_left;
|
||||
case device_id::RIGHT_AIM:
|
||||
return xr::spaces::aim_right;
|
||||
case device_id::RIGHT_GRIP:
|
||||
return xr::spaces::grip_right;
|
||||
case device_id::RIGHT_PALM:
|
||||
return xr::spaces::palm_right;
|
||||
case device_id::RIGHT_PINCH_POSE:
|
||||
return xr::spaces::pinch_right;
|
||||
case device_id::RIGHT_POKE:
|
||||
return xr::spaces::poke_right;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
@@ -306,20 +289,66 @@ void scenes::stream::tracking()
|
||||
#endif
|
||||
|
||||
std::vector<std::pair<device_id, XrSpace>> spaces;
|
||||
for (auto id: {
|
||||
device_id::HEAD,
|
||||
device_id::LEFT_AIM,
|
||||
device_id::LEFT_GRIP,
|
||||
device_id::LEFT_PALM,
|
||||
device_id::RIGHT_AIM,
|
||||
device_id::RIGHT_GRIP,
|
||||
device_id::RIGHT_PALM,
|
||||
})
|
||||
|
||||
{
|
||||
if (XrSpace space = application::space(device_to_space(id)))
|
||||
spaces.emplace_back(id, space);
|
||||
std::vector ids{
|
||||
device_id::HEAD,
|
||||
device_id::LEFT_AIM,
|
||||
device_id::LEFT_GRIP,
|
||||
device_id::LEFT_PALM,
|
||||
device_id::RIGHT_AIM,
|
||||
device_id::RIGHT_GRIP,
|
||||
device_id::RIGHT_PALM,
|
||||
};
|
||||
if (instance.has_extension("XR_EXT_hand_interaction"))
|
||||
{
|
||||
spdlog::info("Adding hand_interaction poses to device list");
|
||||
ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE});
|
||||
}
|
||||
|
||||
for (auto id: ids)
|
||||
{
|
||||
if (XrSpace space = application::space(device_to_space(id)))
|
||||
spaces.emplace_back(id, space);
|
||||
else
|
||||
spdlog::warn("Missing space for device {}", magic_enum::enum_name(id));
|
||||
}
|
||||
}
|
||||
|
||||
auto enabled = [](const to_headset::tracking_control & control, device_id id) -> bool {
|
||||
switch (id)
|
||||
{
|
||||
case device_id::HEAD:
|
||||
case device_id::EYE_GAZE:
|
||||
return true;
|
||||
case device_id::LEFT_AIM:
|
||||
return control.enabled[size_t(tid::left_aim)];
|
||||
case device_id::LEFT_GRIP:
|
||||
return control.enabled[size_t(tid::left_grip)];
|
||||
case device_id::LEFT_PALM:
|
||||
return control.enabled[size_t(tid::left_palm)];
|
||||
case device_id::LEFT_PINCH_POSE:
|
||||
case device_id::LEFT_POKE: {
|
||||
const auto tracking_id = id == device_id::LEFT_PINCH_POSE ? tid::left_pinch : tid::left_poke;
|
||||
return control.enabled[size_t(tracking_id)];
|
||||
}
|
||||
case device_id::RIGHT_AIM:
|
||||
return control.enabled[size_t(tid::right_aim)];
|
||||
case device_id::RIGHT_GRIP:
|
||||
return control.enabled[size_t(tid::right_grip)];
|
||||
case device_id::RIGHT_PALM:
|
||||
return control.enabled[size_t(tid::right_palm)];
|
||||
case device_id::RIGHT_PINCH_POSE:
|
||||
case device_id::RIGHT_POKE: {
|
||||
const auto tracking_id = id == device_id::RIGHT_PINCH_POSE ? tid::right_pinch : tid::right_poke;
|
||||
return control.enabled[size_t(tracking_id)];
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw std::runtime_error("enabled called on unhandled device " + std::string(magic_enum::enum_name(id)));
|
||||
};
|
||||
|
||||
const auto & config = application::get_config();
|
||||
|
||||
if (config.check_feature(feature::eye_gaze))
|
||||
@@ -623,6 +652,55 @@ static device_id derived_from(device_id target)
|
||||
|
||||
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &)
|
||||
{
|
||||
std::array path = {
|
||||
"/user/hand/left",
|
||||
"/user/hand/right",
|
||||
};
|
||||
#define DO_PROFILE(vendor, name) \
|
||||
if (profile == "/interaction_profiles/" #vendor "/" #name) \
|
||||
{ \
|
||||
interaction_profiles[i] = interaction_profile::vendor##_##name; \
|
||||
continue; \
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto profile = session.get_current_interaction_profile(path[i]);
|
||||
spdlog::info("interaction profile for {}: {}", path[i], profile);
|
||||
DO_PROFILE(khr, simple_controller)
|
||||
DO_PROFILE(ext, hand_interaction_ext)
|
||||
DO_PROFILE(bytedance, pico_neo3_controller)
|
||||
DO_PROFILE(bytedance, pico4_controller)
|
||||
DO_PROFILE(bytedance, pico4s_controller)
|
||||
DO_PROFILE(bytedance, pico_g3_controller)
|
||||
DO_PROFILE(google, daydream_controller)
|
||||
DO_PROFILE(hp, mixed_reality_controller)
|
||||
DO_PROFILE(htc, vive_controller)
|
||||
DO_PROFILE(htc, vive_cosmos_controller)
|
||||
DO_PROFILE(htc, vive_focus3_controller)
|
||||
DO_PROFILE(htc, vive_pro)
|
||||
DO_PROFILE(ml, ml2_controller)
|
||||
DO_PROFILE(microsoft, motion_controller)
|
||||
DO_PROFILE(microsoft, xbox_controller)
|
||||
DO_PROFILE(oculus, go_controller)
|
||||
DO_PROFILE(oculus, touch_controller)
|
||||
DO_PROFILE(meta, touch_pro_controller)
|
||||
DO_PROFILE(meta, touch_plus_controller)
|
||||
DO_PROFILE(meta, touch_controller_rift_cv1)
|
||||
DO_PROFILE(meta, touch_controller_quest_1_rift_s)
|
||||
DO_PROFILE(meta, touch_controller_quest_2)
|
||||
DO_PROFILE(samsung, odyssey_controller)
|
||||
DO_PROFILE(valve, index_controller)
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Failed to get current interaction profile: {}", e.what());
|
||||
}
|
||||
interaction_profiles[i] = interaction_profile::none;
|
||||
}
|
||||
|
||||
auto now = instance.now();
|
||||
for (device_id target: {
|
||||
device_id::LEFT_AIM,
|
||||
@@ -631,6 +709,17 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
||||
device_id::RIGHT_PALM,
|
||||
})
|
||||
{
|
||||
// don't do derived poses for hand interaction
|
||||
const bool right = target >= device_id::RIGHT_GRIP && target <= device_id::RIGHT_PALM;
|
||||
if (interaction_profiles[right].load() == interaction_profile::ext_hand_interaction_ext)
|
||||
{
|
||||
network_session->send_control(from_headset::derived_pose{
|
||||
.source = target,
|
||||
.target = target,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
auto source = derived_from(target);
|
||||
auto source_space = application::space(device_to_space(source));
|
||||
auto target_space = application::space(device_to_space(target));
|
||||
@@ -693,52 +782,4 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::array path = {
|
||||
"/user/hand/left",
|
||||
"/user/hand/right",
|
||||
};
|
||||
#define DO_PROFILE(vendor, name) \
|
||||
if (profile == "/interaction_profiles/" #vendor "/" #name) \
|
||||
{ \
|
||||
interaction_profiles[i] = interaction_profile::vendor##_##name; \
|
||||
continue; \
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto profile = session.get_current_interaction_profile(path[i]);
|
||||
spdlog::info("interaction profile for {}: {}", path[i], profile);
|
||||
DO_PROFILE(khr, simple_controller)
|
||||
DO_PROFILE(bytedance, pico_neo3_controller)
|
||||
DO_PROFILE(bytedance, pico4_controller)
|
||||
DO_PROFILE(bytedance, pico4s_controller)
|
||||
DO_PROFILE(bytedance, pico_g3_controller)
|
||||
DO_PROFILE(google, daydream_controller)
|
||||
DO_PROFILE(hp, mixed_reality_controller)
|
||||
DO_PROFILE(htc, vive_controller)
|
||||
DO_PROFILE(htc, vive_cosmos_controller)
|
||||
DO_PROFILE(htc, vive_focus3_controller)
|
||||
DO_PROFILE(htc, vive_pro)
|
||||
DO_PROFILE(ml, ml2_controller)
|
||||
DO_PROFILE(microsoft, motion_controller)
|
||||
DO_PROFILE(microsoft, xbox_controller)
|
||||
DO_PROFILE(oculus, go_controller)
|
||||
DO_PROFILE(oculus, touch_controller)
|
||||
DO_PROFILE(meta, touch_pro_controller)
|
||||
DO_PROFILE(meta, touch_plus_controller)
|
||||
DO_PROFILE(meta, touch_controller_rift_cv1)
|
||||
DO_PROFILE(meta, touch_controller_quest_1_rift_s)
|
||||
DO_PROFILE(meta, touch_controller_quest_2)
|
||||
DO_PROFILE(samsung, odyssey_controller)
|
||||
DO_PROFILE(valve, index_controller)
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Failed to get current interation profile: {}", e.what());
|
||||
}
|
||||
interaction_profiles[i] = interaction_profile::none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, con
|
||||
static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session & s)
|
||||
{
|
||||
PFN_xrCreatePassthroughFB xrCreatePassthroughFB = inst.get_proc<PFN_xrCreatePassthroughFB>("xrCreatePassthroughFB");
|
||||
xrDestroyPassthroughFB = inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB");
|
||||
|
||||
XrPassthroughFB id;
|
||||
XrPassthroughCreateInfoFB info{
|
||||
@@ -71,7 +72,6 @@ xr::passthrough_fb::passthrough_fb(instance & inst, session & s) :
|
||||
.purpose = XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB,
|
||||
})
|
||||
{
|
||||
xrDestroyPassthroughFB = inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB");
|
||||
xrPassthroughStartFB = inst.get_proc<PFN_xrPassthroughStartFB>("xrPassthroughStartFB");
|
||||
xrPassthroughPauseFB = inst.get_proc<PFN_xrPassthroughPauseFB>("xrPassthroughPauseFB");
|
||||
xrPassthroughLayerPauseFB = inst.get_proc<PFN_xrPassthroughLayerPauseFB>("xrPassthroughLayerPauseFB");
|
||||
|
||||
@@ -37,6 +37,11 @@ enum class spaces
|
||||
aim_right,
|
||||
palm_left,
|
||||
palm_right,
|
||||
// hand_interaction_ext
|
||||
pinch_left,
|
||||
pinch_right,
|
||||
poke_left,
|
||||
poke_right,
|
||||
|
||||
count
|
||||
};
|
||||
|
||||
+96
-71
@@ -45,82 +45,99 @@ static constexpr int protocol_revision = 1;
|
||||
|
||||
enum class device_id : uint8_t
|
||||
{
|
||||
HEAD, // /user/head
|
||||
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
|
||||
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
|
||||
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
|
||||
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
|
||||
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
|
||||
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
|
||||
LEFT_GRIP, // /user/hand/left/input/grip/pose
|
||||
LEFT_AIM, // /user/hand/left/input/aim/pose
|
||||
LEFT_PALM, // /user/hand/left/palm_ext/pose
|
||||
RIGHT_GRIP, // /user/hand/right/input/grip/pose
|
||||
RIGHT_AIM, // /user/hand/right/input/aim/pose
|
||||
RIGHT_PALM, // /user/hand/right/palm_ext/pose
|
||||
X_CLICK, // /user/hand/left/input/x/click
|
||||
X_TOUCH, // /user/hand/left/input/x/touch
|
||||
Y_CLICK, // /user/hand/left/input/y/click
|
||||
Y_TOUCH, // /user/hand/left/input/y/touch
|
||||
MENU_CLICK, // /user/hand/left/input/menu/click
|
||||
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
|
||||
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
|
||||
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
|
||||
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
|
||||
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
|
||||
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
|
||||
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
|
||||
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
|
||||
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
|
||||
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
|
||||
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
|
||||
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
|
||||
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
|
||||
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
|
||||
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
|
||||
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
|
||||
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
|
||||
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
|
||||
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
|
||||
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
|
||||
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
|
||||
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
|
||||
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
|
||||
A_CLICK, // /user/hand/right/input/a/click
|
||||
A_TOUCH, // /user/hand/right/input/a/touch
|
||||
B_CLICK, // /user/hand/right/input/b/click
|
||||
B_TOUCH, // /user/hand/right/input/b/touch
|
||||
SYSTEM_CLICK, // /user/hand/right/input/system/click
|
||||
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
|
||||
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
|
||||
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
|
||||
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
|
||||
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
|
||||
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
|
||||
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
|
||||
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
|
||||
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
|
||||
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
|
||||
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
|
||||
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
|
||||
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
|
||||
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
|
||||
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
|
||||
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
|
||||
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
|
||||
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
|
||||
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
|
||||
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
|
||||
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
|
||||
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
|
||||
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
|
||||
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
|
||||
HEAD, // /user/head
|
||||
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
|
||||
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
|
||||
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
|
||||
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
|
||||
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
|
||||
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
|
||||
LEFT_GRIP, // /user/hand/left/input/grip/pose
|
||||
LEFT_AIM, // /user/hand/left/input/aim/pose
|
||||
LEFT_PALM, // /user/hand/left/palm_ext/pose
|
||||
RIGHT_GRIP, // /user/hand/right/input/grip/pose
|
||||
RIGHT_AIM, // /user/hand/right/input/aim/pose
|
||||
RIGHT_PALM, // /user/hand/right/palm_ext/pose
|
||||
X_CLICK, // /user/hand/left/input/x/click
|
||||
X_TOUCH, // /user/hand/left/input/x/touch
|
||||
Y_CLICK, // /user/hand/left/input/y/click
|
||||
Y_TOUCH, // /user/hand/left/input/y/touch
|
||||
MENU_CLICK, // /user/hand/left/input/menu/click
|
||||
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
|
||||
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
|
||||
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
|
||||
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
|
||||
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
|
||||
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
|
||||
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
|
||||
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
|
||||
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
|
||||
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
|
||||
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
|
||||
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
|
||||
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
|
||||
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
|
||||
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
|
||||
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
|
||||
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
|
||||
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
|
||||
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
|
||||
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
|
||||
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
|
||||
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
|
||||
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
|
||||
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
|
||||
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
|
||||
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
|
||||
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
|
||||
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
|
||||
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
|
||||
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
|
||||
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
|
||||
A_CLICK, // /user/hand/right/input/a/click
|
||||
A_TOUCH, // /user/hand/right/input/a/touch
|
||||
B_CLICK, // /user/hand/right/input/b/click
|
||||
B_TOUCH, // /user/hand/right/input/b/touch
|
||||
SYSTEM_CLICK, // /user/hand/right/input/system/click
|
||||
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
|
||||
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
|
||||
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
|
||||
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
|
||||
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
|
||||
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
|
||||
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
|
||||
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
|
||||
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
|
||||
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
|
||||
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
|
||||
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
|
||||
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
|
||||
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
|
||||
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
|
||||
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
|
||||
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
|
||||
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
|
||||
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
|
||||
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
|
||||
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
|
||||
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
|
||||
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
|
||||
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
|
||||
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
|
||||
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
|
||||
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
|
||||
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
|
||||
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
|
||||
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
|
||||
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
|
||||
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
|
||||
};
|
||||
|
||||
enum class interaction_profile : uint8_t
|
||||
{
|
||||
none,
|
||||
khr_simple_controller,
|
||||
ext_hand_interaction_ext,
|
||||
bytedance_pico_neo3_controller,
|
||||
bytedance_pico4_controller,
|
||||
bytedance_pico4s_controller,
|
||||
@@ -216,7 +233,6 @@ struct headset_info_packet
|
||||
std::array<XrFovf, 2> fov;
|
||||
bool hand_tracking;
|
||||
bool eye_gaze;
|
||||
bool presence;
|
||||
bool palm_pose;
|
||||
bool passthrough;
|
||||
face_type face_tracking;
|
||||
@@ -410,6 +426,10 @@ struct refresh_rate_changed
|
||||
float to;
|
||||
};
|
||||
|
||||
struct session_state_changed
|
||||
{
|
||||
XrSessionState state;
|
||||
};
|
||||
struct user_presence_changed
|
||||
{
|
||||
bool present;
|
||||
@@ -433,6 +453,7 @@ using packets = std::variant<
|
||||
battery,
|
||||
visibility_mask_changed,
|
||||
refresh_rate_changed,
|
||||
session_state_changed,
|
||||
user_presence_changed>;
|
||||
} // namespace from_headset
|
||||
|
||||
@@ -596,9 +617,13 @@ struct tracking_control
|
||||
left_aim,
|
||||
left_grip,
|
||||
left_palm,
|
||||
left_pinch,
|
||||
left_poke,
|
||||
right_aim,
|
||||
right_grip,
|
||||
right_palm,
|
||||
right_pinch,
|
||||
right_poke,
|
||||
left_hand,
|
||||
right_hand,
|
||||
face,
|
||||
|
||||
+13
-2
@@ -1,6 +1,12 @@
|
||||
# Configurable items
|
||||
|
||||
Configuration is done on server side, in `$XDG_CONFIG_HOME/wivrn/config.json` or if `$XDG_CONFIG_HOME` is not set, `$HOME/.config/wivrn/config.json`.
|
||||
Configuration is done on server side.
|
||||
Files are read from
|
||||
- `/usr/share/wivrn/config.json` (where `/usr` is selected at configure time with `CMAKE_INSTALL_PREFIX`)
|
||||
- `/etc/wivrn/config.json`
|
||||
- `$XDG_CONFIG_HOME/wivrn/config.json` or if `$XDG_CONFIG_HOME` is not set, `$HOME/.config/wivrn/config.json`.
|
||||
|
||||
Files later in the list replace top-level values from previous ones.
|
||||
|
||||
All elements are optional and have default values.
|
||||
|
||||
@@ -16,7 +22,7 @@ Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the res
|
||||
"scale": 0.5
|
||||
}
|
||||
```
|
||||
The x and y resolution of the streamed video are half the size on the headsed, reduces the required bandwidth and encoding/decoding time by about 4.
|
||||
The x and y resolution of the streamed video are half the size on the headset, reduces the required bandwidth and encoding/decoding time by about 4.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -30,6 +36,11 @@ Default value: `50000000` (50Mb/s)
|
||||
|
||||
Bitrate of the video, in bit/s. Split among decoders based on size and codecs.
|
||||
|
||||
## `bit-depth`
|
||||
Default value: `8` (bits)
|
||||
|
||||
Bit depth of the video. 8-bit is supported by all encoders. 10-bit is supported by `vaapi` encoders using `h265` or `av1`.
|
||||
|
||||
## `encoders`
|
||||
A list of encoders to use.
|
||||
|
||||
|
||||
Generated
+9
-9
@@ -5,11 +5,11 @@
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1743550720,
|
||||
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
|
||||
"lastModified": 1751413152,
|
||||
"narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
|
||||
"rev": "77826244401ea9de6e3bac47c2db46005e1f30b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1747744144,
|
||||
"narHash": "sha256-W7lqHp0qZiENCDwUZ5EX/lNhxjMdNapFnbErcbnP11Q=",
|
||||
"lastModified": 1751271578,
|
||||
"narHash": "sha256-P/SQmKDu06x8yv7i0s8bvnnuJYkxVGBWLWHaU+tt4YY=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2795c506fe8fb7b03c36ccb51f75b6df0ab2553f",
|
||||
"rev": "3016b4b15d13f3089db8a41ef937b13a9e33a8df",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -36,11 +36,11 @@
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1743296961,
|
||||
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
|
||||
"lastModified": 1751159883,
|
||||
"narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
|
||||
"rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -56,7 +56,29 @@
|
||||
];
|
||||
}));
|
||||
in {
|
||||
packages.default = package;
|
||||
packages = {
|
||||
default = package;
|
||||
dissector = package.overrideAttrs (oldAttrs: {
|
||||
pname = "wivrn-dissector";
|
||||
cmakeFlags = (lib.filter (flag: !(lib.hasPrefix "-DWIVRN_BUILD" flag)) oldAttrs.cmakeFlags) ++ [
|
||||
(lib.cmakeBool "WIVRN_BUILD_CLIENT" false)
|
||||
(lib.cmakeBool "WIVRN_BUILD_SERVER" false)
|
||||
(lib.cmakeBool "WIVRN_BUILD_DASHBOARD" false)
|
||||
(lib.cmakeBool "WIVRN_BUILD_WIVRNCTL" false)
|
||||
(lib.cmakeBool "WIVRN_BUILD_DISSECTOR" true)
|
||||
];
|
||||
buildInputs = oldAttrs.buildInputs ++ [
|
||||
(pkgs.symlinkJoin {
|
||||
name = "wireshark-dev-out-combined";
|
||||
paths = [
|
||||
pkgs.wireshark.out
|
||||
pkgs.wireshark.dev
|
||||
];
|
||||
})
|
||||
];
|
||||
preFixup = null;
|
||||
});
|
||||
};
|
||||
devShells.default = package.overrideAttrs (oldAttrs: {
|
||||
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ devTools;
|
||||
});
|
||||
|
||||
@@ -93,7 +93,8 @@ modules:
|
||||
url: https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz
|
||||
sha256: 277807353a6726978996945af13e52829e3abd7a9a5b7fb2793894e18f1fcbb2
|
||||
- type: file
|
||||
url: https://libisl.sourceforge.io/isl-0.26.tar.xz
|
||||
dest-filename: isl-0.26.tar.xz
|
||||
url: https://sourceforge.net/projects/libisl/files/isl-0.26.tar.xz/download
|
||||
sha256: a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504
|
||||
- type: file
|
||||
url: https://www.multiprecision.org/downloads/mpc-1.3.1.tar.gz
|
||||
|
||||
@@ -1,40 +1,91 @@
|
||||
From 07084beafd9430561fbe5681398792282422dde6 Mon Sep 17 00:00:00 2001
|
||||
From a7fbfaf2407a805efa31b3e1a7f0565b46a9004e Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Nicolas <patricknicolas@laposte.net>
|
||||
Date: Wed, 19 Feb 2025 10:13:36 +0100
|
||||
Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile
|
||||
|
||||
---
|
||||
src/xrt/state_trackers/oxr/oxr_binding.c | 17 +++++++++++++++++
|
||||
1 file changed, 17 insertions(+)
|
||||
src/xrt/state_trackers/oxr/oxr_binding.c | 8 +++++---
|
||||
src/xrt/state_trackers/oxr/oxr_input.c | 19 +++++++++++++------
|
||||
src/xrt/state_trackers/oxr/oxr_objects.h | 2 +-
|
||||
3 files changed, 19 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/src/xrt/state_trackers/oxr/oxr_binding.c b/src/xrt/state_trackers/oxr/oxr_binding.c
|
||||
index ce4c0cca1..8ba94dc55 100644
|
||||
index ce4c0cca1..9645a507a 100644
|
||||
--- a/src/xrt/state_trackers/oxr/oxr_binding.c
|
||||
+++ b/src/xrt/state_trackers/oxr/oxr_binding.c
|
||||
@@ -488,6 +488,23 @@ oxr_find_profile_for_device(struct oxr_logger *log,
|
||||
return;
|
||||
}
|
||||
@@ -453,7 +453,7 @@ get_identifier_str_in_profile(struct oxr_logger *log,
|
||||
return str;
|
||||
}
|
||||
|
||||
+ // Have bindings for the dynamic role's profile been suggested?
|
||||
+#define FIND_PROFILE(X) \
|
||||
+ { \
|
||||
+ struct xrt_device *role_xdev = GET_XDEV_BY_ROLE(sess->sys, X); \
|
||||
+ if (role_xdev == xdev) { \
|
||||
+ enum xrt_device_name profile = GET_PROFILE_NAME_BY_ROLE(sess->sys, X); \
|
||||
+ oxr_get_profile_for_device_name(log, sess, profile, out_p); \
|
||||
+ if (*out_p != NULL) { \
|
||||
+ return; \
|
||||
+ } \
|
||||
-void
|
||||
+bool
|
||||
oxr_get_profile_for_device_name(struct oxr_logger *log,
|
||||
struct oxr_session *sess,
|
||||
enum xrt_device_name name,
|
||||
@@ -465,10 +465,12 @@ oxr_get_profile_for_device_name(struct oxr_logger *log,
|
||||
*/
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(profile_templates); i++) {
|
||||
if (name == profile_templates[i].name) {
|
||||
- interaction_profile_find_in_session(log, sess, profile_templates[i].path_cache, out_p);
|
||||
- return;
|
||||
+ if (interaction_profile_find_in_session(log, sess, profile_templates[i].path_cache, out_p)) {
|
||||
+ return true;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
+ return false;
|
||||
}
|
||||
|
||||
|
||||
diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c
|
||||
index 3d8da24a9..7bd3e7678 100644
|
||||
--- a/src/xrt/state_trackers/oxr/oxr_input.c
|
||||
+++ b/src/xrt/state_trackers/oxr/oxr_input.c
|
||||
@@ -800,18 +800,25 @@ oxr_find_profiles_from_roles(struct oxr_logger *log,
|
||||
{
|
||||
#define FIND_PROFILE(X) \
|
||||
{ \
|
||||
- struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, X); \
|
||||
- if (xdev != NULL) { \
|
||||
- oxr_find_profile_for_device(log, sess, xdev, &out_profiles->X); \
|
||||
- } else { \
|
||||
- oxr_get_profile_for_device_name(log, sess, GET_PROFILE_NAME_BY_ROLE(sess->sys, X), \
|
||||
- &out_profiles->X); \
|
||||
+ bool profile_found = false; \
|
||||
+ const enum xrt_device_name role_profile_name = GET_PROFILE_NAME_BY_ROLE(sess->sys, X); \
|
||||
+ if (role_profile_name != XRT_DEVICE_INVALID) { \
|
||||
+ profile_found = \
|
||||
+ oxr_get_profile_for_device_name(log, sess, role_profile_name, &out_profiles->X); \
|
||||
+ } \
|
||||
+ }
|
||||
+ FIND_PROFILE(left);
|
||||
+ FIND_PROFILE(right);
|
||||
+ FIND_PROFILE(gamepad);
|
||||
+#undef FIND_PROFILE
|
||||
+ \
|
||||
+ if (!profile_found) { \
|
||||
+ struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, X); \
|
||||
+ if (xdev != NULL) { \
|
||||
+ oxr_find_profile_for_device(log, sess, xdev, &out_profiles->X); \
|
||||
+ } \
|
||||
} \
|
||||
}
|
||||
OXR_FOR_EACH_VALID_SUBACTION_PATH(FIND_PROFILE)
|
||||
#undef FIND_PROFILE
|
||||
}
|
||||
|
||||
+
|
||||
// Have bindings for this device's interaction profile been suggested?
|
||||
oxr_get_profile_for_device_name(log, sess, xdev->name, out_p);
|
||||
if (*out_p != NULL) {
|
||||
/*!
|
||||
* @public @memberof oxr_action_attachment
|
||||
*/
|
||||
diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h
|
||||
index c4d2bcbe3..f9f1ac5a8 100644
|
||||
--- a/src/xrt/state_trackers/oxr/oxr_objects.h
|
||||
+++ b/src/xrt/state_trackers/oxr/oxr_objects.h
|
||||
@@ -651,7 +651,7 @@ oxr_find_profile_for_device(struct oxr_logger *log,
|
||||
struct xrt_device *xdev,
|
||||
struct oxr_interaction_profile **out_p);
|
||||
|
||||
-void
|
||||
+bool
|
||||
oxr_get_profile_for_device_name(struct oxr_logger *log,
|
||||
struct oxr_session *sess,
|
||||
enum xrt_device_name name,
|
||||
--
|
||||
2.50.0
|
||||
2.50.1
|
||||
|
||||
|
||||
@@ -37,12 +37,12 @@ set(XRT_FEATURE_RENDERDOC ${WIVRN_FEATURE_RENDERDOC})
|
||||
set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON)
|
||||
set(XRT_FEATURE_OPENXR_FACIAL_TRACKING_HTC ON)
|
||||
set(XRT_FEATURE_OPENXR_HAND_TRACKING_EXT ON)
|
||||
set(XRT_FEATURE_OPENXR_INTERACTION_EXT_HAND ON)
|
||||
set(XRT_FEATURE_OPENXR_INTERACTION_EXT_PALM_POSE ON)
|
||||
set(XRT_FEATURE_OPENXR_INTERACTION_BYTEDANCE ON)
|
||||
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_INTERACTION_EXT_HAND OFF)
|
||||
|
||||
set(XRT_HAVE_BLUETOOTH OFF)
|
||||
set(XRT_HAVE_GST OFF)
|
||||
@@ -94,6 +94,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
driver/wivrn_pacer.cpp
|
||||
driver/wivrn_comp_target.cpp
|
||||
driver/wivrn_controller.cpp
|
||||
driver/wivrn_hand_interaction.cpp
|
||||
driver/wivrn_eye_tracker.cpp
|
||||
driver/wivrn_fb_face2_tracker.cpp
|
||||
driver/wivrn_htc_face_tracker.cpp
|
||||
|
||||
@@ -76,7 +76,7 @@ std::filesystem::path active_runtime::openvr_compat_path()
|
||||
return std::filesystem::path();
|
||||
},
|
||||
},
|
||||
configuration::read_user_configuration().openvr_compat_path);
|
||||
configuration().openvr_compat_path);
|
||||
}
|
||||
|
||||
static std::filesystem::path backup_name(std::filesystem::path file)
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#define JSON_DISABLE_ENUM_SERIALIZATION 1
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
@@ -31,12 +33,24 @@
|
||||
|
||||
#include "util/u_logging.h"
|
||||
|
||||
#include "configuration.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
static std::filesystem::path config_file = xdg_config_home() / "wivrn" / "config.json";
|
||||
static std::filesystem::path known_keys_file = xdg_config_home() / "wivrn" / "known_keys.json";
|
||||
static std::filesystem::path cookie_file = xdg_config_home() / "wivrn" / "cookie";
|
||||
static auto resolve_path(std::filesystem::path path)
|
||||
{
|
||||
std::error_code ec;
|
||||
auto canonical = std::filesystem::canonical(path, ec);
|
||||
|
||||
// path doesn't exist
|
||||
if (ec)
|
||||
return path;
|
||||
|
||||
return canonical;
|
||||
}
|
||||
|
||||
static std::filesystem::path config_file;
|
||||
static std::filesystem::path known_keys_file = resolve_path(xdg_config_home() / "wivrn" / "known_keys.json");
|
||||
static std::filesystem::path cookie_file = resolve_path(xdg_config_home() / "wivrn" / "cookie");
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
@@ -63,12 +77,56 @@ NLOHMANN_JSON_SERIALIZE_ENUM(
|
||||
|
||||
void configuration::set_config_file(const std::filesystem::path & path)
|
||||
{
|
||||
config_file = path;
|
||||
config_file = resolve_path(path);
|
||||
}
|
||||
std::filesystem::path configuration::get_config_file()
|
||||
{
|
||||
if (config_file.empty())
|
||||
return resolve_path(xdg_config_home() / "wivrn" / "config.json");
|
||||
return config_file;
|
||||
}
|
||||
|
||||
const std::filesystem::path & configuration::get_config_file()
|
||||
nlohmann::json configuration::read_configuration()
|
||||
{
|
||||
return config_file;
|
||||
if (config_file.empty())
|
||||
{
|
||||
nlohmann::json merged;
|
||||
for (std::filesystem::path prefix: {
|
||||
std::filesystem::path(WIVRN_INSTALL_PREFIX "/share"),
|
||||
std::filesystem::path("/etc"),
|
||||
xdg_config_home(),
|
||||
})
|
||||
{
|
||||
auto path = resolve_path(prefix / "wivrn" / "config.json");
|
||||
if (std::filesystem::exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
for (const auto & [key, value]: nlohmann::json::parse(std::ifstream(path)).get<nlohmann::json::object_t>())
|
||||
{
|
||||
merged[key] = value;
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
U_LOG_E("Invalid configuration file %s: %s", path.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return nlohmann::json::parse(std::ifstream(config_file));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
U_LOG_E("Invalid configuration file %s: %s", config_file.c_str(), e.what());
|
||||
return nlohmann::json();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configuration::encoder parse_encoder(const nlohmann::json & item)
|
||||
@@ -94,85 +152,81 @@ configuration::encoder parse_encoder(const nlohmann::json & item)
|
||||
return e;
|
||||
}
|
||||
|
||||
configuration configuration::read_user_configuration()
|
||||
configuration::configuration()
|
||||
{
|
||||
configuration result;
|
||||
if (not std::filesystem::exists(config_file))
|
||||
return result;
|
||||
std::ifstream file(config_file);
|
||||
try
|
||||
{
|
||||
auto json = nlohmann::json::parse(file);
|
||||
auto json = read_configuration();
|
||||
|
||||
if (auto it = json.find("scale"); it != json.end())
|
||||
{
|
||||
if (it->is_number())
|
||||
result.scale = std::array<double, 2>{*it, *it};
|
||||
scale = std::array<double, 2>{*it, *it};
|
||||
else
|
||||
result.scale = *it;
|
||||
scale = *it;
|
||||
}
|
||||
|
||||
if (auto it = json.find("grip-surface"); it != json.end())
|
||||
{
|
||||
result.grip_surface = *it;
|
||||
grip_surface = *it;
|
||||
}
|
||||
|
||||
if (auto it = json.find("bitrate"); it != json.end())
|
||||
result.bitrate = *it;
|
||||
bitrate = *it;
|
||||
|
||||
if (auto it = json.find("encoders"); it != json.end())
|
||||
{
|
||||
for (const auto & encoder: *it)
|
||||
result.encoders.push_back(parse_encoder(encoder));
|
||||
encoders.push_back(parse_encoder(encoder));
|
||||
}
|
||||
|
||||
if (auto it = json.find("encoder-passthrough"); it != json.end())
|
||||
result.encoder_passthrough = parse_encoder(*it);
|
||||
encoder_passthrough = parse_encoder(*it);
|
||||
|
||||
if (auto it = json.find("application"); it != json.end())
|
||||
{
|
||||
if (it->is_string())
|
||||
result.application.push_back(*it);
|
||||
application.push_back(*it);
|
||||
else
|
||||
{
|
||||
for (const auto & i: *it)
|
||||
result.application.push_back(i);
|
||||
application.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto it = json.find("debug-gui"); it != json.end())
|
||||
result.debug_gui = *it;
|
||||
debug_gui = *it;
|
||||
|
||||
if (auto it = json.find("use-steamvr-lh"); it != json.end())
|
||||
result.use_steamvr_lh = *it;
|
||||
use_steamvr_lh = *it;
|
||||
|
||||
if (auto it = json.find("bit-depth"); it != json.end())
|
||||
bit_depth = *it;
|
||||
|
||||
if (auto it = json.find("tcp-only"); it != json.end())
|
||||
result.tcp_only = *it;
|
||||
tcp_only = *it;
|
||||
else if (auto it = json.find("tcp_only"); it != json.end())
|
||||
result.tcp_only = *it;
|
||||
tcp_only = *it;
|
||||
|
||||
if (auto it = json.find("publish-service"); it != json.end())
|
||||
{
|
||||
result.publication = *it;
|
||||
if (result.publication == service_publication(-1))
|
||||
publication = *it;
|
||||
if (publication == service_publication(-1))
|
||||
throw std::runtime_error("invalid service publication " + it->get<std::string>());
|
||||
}
|
||||
|
||||
if (auto it = json.find("openvr-compat-path"); it != json.end())
|
||||
{
|
||||
if (it->is_null())
|
||||
result.openvr_compat_path = nullptr;
|
||||
openvr_compat_path = nullptr;
|
||||
else
|
||||
result.openvr_compat_path = *it;
|
||||
openvr_compat_path = *it;
|
||||
}
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Invalid configuration file: %s", e.what());
|
||||
return {};
|
||||
U_LOG_E("Configuration file error: %s", e.what());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string server_cookie()
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
@@ -56,6 +57,7 @@ struct configuration
|
||||
std::vector<encoder> encoders;
|
||||
std::optional<encoder> encoder_passthrough;
|
||||
std::optional<int> bitrate;
|
||||
int bit_depth = 8;
|
||||
std::optional<std::array<double, 2>> scale;
|
||||
std::optional<std::array<float, 3>> grip_surface;
|
||||
std::vector<std::string> application;
|
||||
@@ -68,8 +70,10 @@ struct configuration
|
||||
std::variant<std::monostate, std::string, std::nullptr_t> openvr_compat_path;
|
||||
|
||||
static void set_config_file(const std::filesystem::path &);
|
||||
static const std::filesystem::path & get_config_file();
|
||||
static configuration read_user_configuration();
|
||||
static std::filesystem::path get_config_file();
|
||||
|
||||
static nlohmann::json read_configuration();
|
||||
configuration();
|
||||
};
|
||||
|
||||
std::string server_cookie();
|
||||
|
||||
@@ -131,5 +131,11 @@ public:
|
||||
|
||||
return {};
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
data.fill({});
|
||||
last_request = os_monotonic_get_ns();
|
||||
}
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -179,6 +179,13 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
|
||||
|
||||
auto format = vk::Format(cn->format);
|
||||
|
||||
bool is_10bit = format == vk::Format::eG10X6B10X6R10X62Plane420Unorm3Pack16;
|
||||
|
||||
std::array formats = {
|
||||
is_10bit ? vk::Format::eR10X6UnormPack16 : vk::Format::eR8Unorm,
|
||||
is_10bit ? vk::Format::eR10X6G10X6Unorm2Pack16 : vk::Format::eR8G8Unorm,
|
||||
format};
|
||||
|
||||
cn->images = U_TYPED_ARRAY_CALLOC(struct comp_target_image, cn->image_count);
|
||||
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
@@ -193,11 +200,6 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
|
||||
cn->psc.images.resize(cn->image_count);
|
||||
for (uint32_t i = 0; i < cn->image_count; i++)
|
||||
{
|
||||
std::array formats = {
|
||||
vk::Format::eR8Unorm,
|
||||
vk::Format::eR8G8Unorm,
|
||||
format,
|
||||
};
|
||||
vk::ImageFormatListCreateInfo formats_info{
|
||||
.viewFormatCount = formats.size(),
|
||||
.pViewFormats = formats.data(),
|
||||
@@ -249,7 +251,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
|
||||
.pNext = &usage,
|
||||
.image = item.image,
|
||||
.viewType = vk::ImageViewType::e2DArray,
|
||||
.format = vk::Format::eR8Unorm,
|
||||
.format = formats[0],
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
|
||||
.levelCount = 1,
|
||||
@@ -261,7 +263,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
|
||||
.pNext = &usage,
|
||||
.image = item.image,
|
||||
.viewType = vk::ImageViewType::e2DArray,
|
||||
.format = vk::Format::eR8G8Unorm,
|
||||
.format = formats[1],
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
|
||||
.levelCount = 1,
|
||||
@@ -407,8 +409,12 @@ static void comp_wivrn_create_images(struct comp_target * ct, const struct comp_
|
||||
|
||||
target_init_semaphores(cn);
|
||||
|
||||
// FIXME: select preferred format
|
||||
ct->format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
|
||||
// will fail on encoder init if bit_depth is arbitrary garbage
|
||||
if (cn->settings[0].bit_depth == 10)
|
||||
ct->format = VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16;
|
||||
else
|
||||
ct->format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
|
||||
|
||||
ct->width = create_info->extent.width;
|
||||
ct->height = create_info->extent.height;
|
||||
ct->surface_transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
@@ -88,7 +88,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
|
||||
throw std::system_error(errno, std::system_category(), "Cannot get client address");
|
||||
}
|
||||
|
||||
if (configuration::read_user_configuration().tcp_only)
|
||||
if (configuration().tcp_only)
|
||||
{
|
||||
port = -1;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace wivrn
|
||||
|
||||
enum wivrn_controller_input_index
|
||||
{
|
||||
WIVRN_CONTROLLER_INPUT_INVALID = -1,
|
||||
WIVRN_CONTROLLER_AIM_POSE,
|
||||
WIVRN_CONTROLLER_GRIP_POSE,
|
||||
WIVRN_CONTROLLER_PALM_POSE,
|
||||
@@ -237,7 +238,13 @@ static input_data map_input(device_id id)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw std::range_error("bad input id " + std::to_string((int)id));
|
||||
// If the headset supports hand_interaction_ext, upon switch
|
||||
// to/from hand tracking we may get the inputs packet before
|
||||
// the interaction profile change, so if we get a bad input
|
||||
// just return an invalid index so we can ignore it
|
||||
U_LOG_D("wivrn_controller: bad input id %s", std::string(magic_enum::enum_name(id)).c_str());
|
||||
// the type here doesn't really matter
|
||||
return {WIVRN_CONTROLLER_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
|
||||
}
|
||||
|
||||
static xrt_binding_input_pair simple_input_binding[] = {
|
||||
@@ -572,7 +579,7 @@ wivrn_controller::wivrn_controller(int hand_id,
|
||||
SET_INPUT(TOUCH, GRIP_POSE);
|
||||
SET_INPUT(GENERIC, PALM_POSE);
|
||||
|
||||
if (auto grip_surface = configuration::read_user_configuration().grip_surface)
|
||||
if (auto grip_surface = configuration().grip_surface)
|
||||
{
|
||||
std::array<float, 3> angles = grip_surface.value();
|
||||
float deg_2_rad = std::numbers::pi / 180.0;
|
||||
@@ -873,4 +880,11 @@ xrt_result_t wivrn_controller::set_output(xrt_output_name name, const xrt_output
|
||||
}
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
void wivrn_controller::reset_history()
|
||||
{
|
||||
grip.reset();
|
||||
aim.reset();
|
||||
palm.reset();
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -62,5 +62,7 @@ public:
|
||||
void set_derived_pose(const from_headset::derived_pose &);
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
|
||||
|
||||
void reset_history();
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -0,0 +1,483 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* 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_hand_interaction.h"
|
||||
#include "configuration.h"
|
||||
#include "driver/xrt_cast.h"
|
||||
#include "math/m_api.h"
|
||||
#include "utils/method.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "util/u_logging.h"
|
||||
#include <array>
|
||||
#include <magic_enum.hpp>
|
||||
#include <numbers>
|
||||
#include <optional>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
enum wivrn_hand_interaction_input_index
|
||||
{
|
||||
WIVRN_HAND_INTERACTION_INPUT_INVALID = -1,
|
||||
WIVRN_HAND_INTERACTION_AIM_POSE,
|
||||
WIVRN_HAND_INTERACTION_GRIP_POSE,
|
||||
WIVRN_HAND_INTERACTION_PALM_POSE,
|
||||
|
||||
WIVRN_HAND_INTERACTION_PINCH_POSE, // /user/hand/XXXX/input/pinch_ext/pose
|
||||
WIVRN_HAND_INTERACTION_PINCH_VALUE, // /user/hand/XXXX/input/pinch_ext/value
|
||||
WIVRN_HAND_INTERACTION_PINCH_READY, // /user/hand/XXXX/input/pinch_ext/ready_ext
|
||||
WIVRN_HAND_INTERACTION_POKE_POSE, // /user/hand/XXXX/input/poke_ext/pose
|
||||
WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, // /user/hand/XXXX/input/aim_activate_ext/value
|
||||
WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, // /user/hand/XXXX/input/aim_activate_ext/ready_ext
|
||||
WIVRN_HAND_INTERACTION_GRASP_VALUE, // /user/hand/XXXX/input/grasp_ext/value
|
||||
WIVRN_HAND_INTERACTION_GRASP_READY, // /user/hand/XXXX/input/ready_ext/value
|
||||
|
||||
WIVRN_HAND_INTERACTION_INPUT_COUNT
|
||||
};
|
||||
|
||||
enum class wivrn_input_type
|
||||
{
|
||||
BOOL,
|
||||
FLOAT,
|
||||
VEC2_X,
|
||||
VEC2_Y,
|
||||
POSE,
|
||||
};
|
||||
|
||||
struct input_data
|
||||
{
|
||||
wivrn_hand_interaction_input_index index;
|
||||
wivrn_input_type type;
|
||||
xrt_device_type device;
|
||||
};
|
||||
|
||||
static input_data map_input(device_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case device_id::LEFT_GRIP:
|
||||
return {WIVRN_HAND_INTERACTION_GRIP_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_GRIP:
|
||||
return {WIVRN_HAND_INTERACTION_GRIP_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_AIM:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_AIM:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_PALM:
|
||||
return {WIVRN_HAND_INTERACTION_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_PALM:
|
||||
return {WIVRN_HAND_INTERACTION_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
// XR_EXT_hand_interaction
|
||||
case device_id::LEFT_PINCH_POSE:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_PINCH_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_PINCH_READY:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_PINCH_POSE:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_PINCH_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_PINCH_READY:
|
||||
return {WIVRN_HAND_INTERACTION_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_POKE:
|
||||
return {WIVRN_HAND_INTERACTION_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_POKE:
|
||||
return {WIVRN_HAND_INTERACTION_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_AIM_ACTIVATE_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_AIM_ACTIVATE_READY:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_GRASP_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::LEFT_GRASP_READY:
|
||||
return {WIVRN_HAND_INTERACTION_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_AIM_ACTIVATE_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_AIM_ACTIVATE_READY:
|
||||
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_GRASP_VALUE:
|
||||
return {WIVRN_HAND_INTERACTION_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_GRASP_READY:
|
||||
return {WIVRN_HAND_INTERACTION_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// If the headset supports hand_interaction_ext, upon switch
|
||||
// to/from hand tracking we may get the inputs packet before
|
||||
// the interaction profile change, so if we get a bad input
|
||||
// just return an invalid index so we can ignore it
|
||||
U_LOG_D("wivrn_hand_interaction: bad input id %s", std::string(magic_enum::enum_name(id)).c_str());
|
||||
// the type here doesn't really matter
|
||||
return {WIVRN_HAND_INTERACTION_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
|
||||
}
|
||||
|
||||
static xrt_binding_input_pair hand_interaction_input_binding[] = {
|
||||
{XRT_INPUT_HAND_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
|
||||
{XRT_INPUT_HAND_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
|
||||
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
|
||||
{XRT_INPUT_HAND_PINCH_VALUE, XRT_INPUT_HAND_PINCH_VALUE},
|
||||
{XRT_INPUT_HAND_PINCH_READY, XRT_INPUT_HAND_PINCH_READY},
|
||||
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
|
||||
{XRT_INPUT_HAND_AIM_ACTIVATE_READY, XRT_INPUT_HAND_AIM_ACTIVATE_READY},
|
||||
{XRT_INPUT_HAND_AIM_ACTIVATE_VALUE, XRT_INPUT_HAND_AIM_ACTIVATE_VALUE},
|
||||
{XRT_INPUT_HAND_GRASP_VALUE, XRT_INPUT_HAND_GRASP_VALUE},
|
||||
{XRT_INPUT_HAND_GRASP_READY, XRT_INPUT_HAND_GRASP_READY},
|
||||
};
|
||||
|
||||
static xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
{
|
||||
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
|
||||
.inputs = hand_interaction_input_binding,
|
||||
.input_count = std::size(hand_interaction_input_binding),
|
||||
.outputs = nullptr,
|
||||
.output_count = 0,
|
||||
},
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
struct xrt_space_relation_csv_header
|
||||
{};
|
||||
} // namespace
|
||||
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
|
||||
{
|
||||
for (auto [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
{
|
||||
name = name.substr(strlen("XRT_SPACE_RELATION_"));
|
||||
name = name.substr(0, name.size() - strlen("_BIT"));
|
||||
out << name << ",";
|
||||
}
|
||||
}
|
||||
out << "x,y,z,";
|
||||
out << "qw,qx,qy,qz";
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
|
||||
{
|
||||
const auto & pos = rel.pose.position;
|
||||
const auto & o = rel.pose.orientation;
|
||||
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
out << bool(rel.relation_flags & value) << ',';
|
||||
}
|
||||
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
|
||||
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::mutex tracking_dump_mutex;
|
||||
static std::ofstream & tracking_dump()
|
||||
{
|
||||
static auto res = [] {
|
||||
std::ofstream res;
|
||||
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
|
||||
{
|
||||
res.open(wivrn_dump);
|
||||
res << "device_id,"
|
||||
"now_ns,"
|
||||
"timestamp_ns,"
|
||||
"extrapolation_ns,"
|
||||
"receive/get,"
|
||||
<< xrt_space_relation_csv_header{} << std::endl;
|
||||
}
|
||||
return res;
|
||||
}();
|
||||
return res;
|
||||
}
|
||||
|
||||
wivrn_hand_interaction::wivrn_hand_interaction(int hand_id,
|
||||
xrt_device * hmd,
|
||||
wivrn::wivrn_session * cnx) :
|
||||
xrt_device{
|
||||
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
|
||||
.device_type = hand_id == 0 ? XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER : XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER,
|
||||
.hmd = nullptr,
|
||||
.tracking_origin = hmd->tracking_origin,
|
||||
.binding_profile_count = std::size(wivrn_binding_profiles),
|
||||
.binding_profiles = wivrn_binding_profiles,
|
||||
.input_count = WIVRN_HAND_INTERACTION_INPUT_COUNT,
|
||||
.supported = {
|
||||
.orientation_tracking = true,
|
||||
.position_tracking = true,
|
||||
},
|
||||
.update_inputs = method_pointer<&wivrn_hand_interaction::update_inputs>,
|
||||
.get_tracked_pose = method_pointer<&wivrn_hand_interaction::get_tracked_pose>,
|
||||
.destroy = [](xrt_device *) {},
|
||||
},
|
||||
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
|
||||
aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM),
|
||||
palm(hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM),
|
||||
pinch_ext(hand_id == 0 ? device_id::LEFT_PINCH_POSE : device_id::RIGHT_PINCH_POSE),
|
||||
poke_ext(hand_id == 0 ? device_id::LEFT_POKE : device_id::RIGHT_POKE),
|
||||
inputs_array(input_count, xrt_input{}),
|
||||
cnx(cnx)
|
||||
{
|
||||
inputs = inputs_array.data();
|
||||
|
||||
// Setup input.
|
||||
#define SET_INPUT(VENDOR, NAME) \
|
||||
do \
|
||||
{ \
|
||||
inputs[WIVRN_HAND_INTERACTION_##NAME].name = XRT_INPUT_##VENDOR##_##NAME; \
|
||||
inputs[WIVRN_HAND_INTERACTION_##NAME].active = true; \
|
||||
} while (0)
|
||||
|
||||
if (auto grip_surface = configuration().grip_surface)
|
||||
{
|
||||
std::array<float, 3> angles = grip_surface.value();
|
||||
float deg_2_rad = std::numbers::pi / 180.0;
|
||||
xrt_vec3 rotation_angles{angles[0] * deg_2_rad, angles[1] * deg_2_rad, angles[2] * deg_2_rad};
|
||||
xrt_pose offset = XRT_POSE_IDENTITY;
|
||||
math_quat_from_euler_angles(&rotation_angles, &offset.orientation);
|
||||
|
||||
palm.set_derived(&grip, offset, true);
|
||||
cnx->set_enabled(palm.device, false);
|
||||
}
|
||||
else if (not cnx->get_info().palm_pose)
|
||||
{
|
||||
palm.set_derived(&grip, XRT_POSE_IDENTITY, false);
|
||||
cnx->set_enabled(palm.device, false);
|
||||
}
|
||||
|
||||
SET_INPUT(HAND, AIM_POSE);
|
||||
SET_INPUT(HAND, GRIP_POSE);
|
||||
SET_INPUT(GENERIC, PALM_POSE);
|
||||
SET_INPUT(HAND, PINCH_POSE);
|
||||
SET_INPUT(HAND, PINCH_VALUE);
|
||||
SET_INPUT(HAND, PINCH_READY);
|
||||
SET_INPUT(HAND, POKE_POSE);
|
||||
SET_INPUT(HAND, AIM_ACTIVATE_VALUE);
|
||||
SET_INPUT(HAND, AIM_ACTIVATE_READY);
|
||||
SET_INPUT(HAND, GRASP_VALUE);
|
||||
SET_INPUT(HAND, GRASP_READY);
|
||||
|
||||
#undef SET_INPUT
|
||||
inputs_staging = inputs_array;
|
||||
|
||||
// Make sure everything is mapped
|
||||
for (const auto & item: inputs_array)
|
||||
{
|
||||
assert(item.name);
|
||||
}
|
||||
|
||||
outputs = nullptr;
|
||||
output_count = 0;
|
||||
|
||||
switch (hand_id)
|
||||
{
|
||||
case 0:
|
||||
// Print name.
|
||||
strcpy(str, "WiVRn left hand interaction");
|
||||
strcpy(serial, "WiVRn left hand interaction");
|
||||
break;
|
||||
case 1:
|
||||
// Print name.
|
||||
strcpy(str, "WiVRn right hand interaction");
|
||||
strcpy(serial, "WiVRn right hand interaction");
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid hand ID");
|
||||
}
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hand_interaction::update_inputs()
|
||||
{
|
||||
std::lock_guard _{mutex};
|
||||
inputs_array = inputs_staging;
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
void wivrn_hand_interaction::set_inputs(const from_headset::inputs & inputs, const clock_offset & clock_offset)
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
for (auto & input: inputs_staging)
|
||||
{
|
||||
switch (XRT_GET_INPUT_TYPE(input.name))
|
||||
{
|
||||
case XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE:
|
||||
case XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE:
|
||||
case XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE:
|
||||
case XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE:
|
||||
case XRT_INPUT_TYPE_BOOLEAN:
|
||||
input.active = false;
|
||||
case XRT_INPUT_TYPE_POSE:
|
||||
case XRT_INPUT_TYPE_HAND_TRACKING:
|
||||
case XRT_INPUT_TYPE_FACE_TRACKING:
|
||||
case XRT_INPUT_TYPE_BODY_TRACKING:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & input: inputs.values)
|
||||
{
|
||||
int64_t last_change_time = input.last_change_time ? clock_offset.from_headset(input.last_change_time) : 0;
|
||||
auto [index, type, device] = map_input(input.id);
|
||||
if (device != device_type)
|
||||
continue;
|
||||
assert(index > 0 and index < input_count);
|
||||
inputs_staging[index].timestamp = last_change_time;
|
||||
inputs_staging[index].active = true;
|
||||
switch (type)
|
||||
{
|
||||
case wivrn_input_type::BOOL:
|
||||
inputs_staging[index].value.boolean = (input.value != 0);
|
||||
break;
|
||||
case wivrn_input_type::FLOAT:
|
||||
inputs_staging[index].value.vec1.x = input.value;
|
||||
break;
|
||||
case wivrn_input_type::VEC2_X:
|
||||
inputs_staging[index].value.vec2.x = input.value;
|
||||
break;
|
||||
case wivrn_input_type::VEC2_Y:
|
||||
inputs_staging[index].value.vec2.y = input.value;
|
||||
break;
|
||||
case wivrn_input_type::POSE:
|
||||
// Pose should not be in the inputs array
|
||||
U_LOG_W("Unexpected input id %d", int(input.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
|
||||
{
|
||||
std::chrono::nanoseconds extrapolation_time;
|
||||
device_id device;
|
||||
switch (name)
|
||||
{
|
||||
case XRT_INPUT_HAND_AIM_POSE:
|
||||
std::tie(extrapolation_time, *res, device) = aim.get_pose_at(at_timestamp_ns);
|
||||
cnx->set_enabled(device, true);
|
||||
break;
|
||||
case XRT_INPUT_HAND_GRIP_POSE:
|
||||
std::tie(extrapolation_time, *res, device) = grip.get_pose_at(at_timestamp_ns);
|
||||
cnx->set_enabled(device, true);
|
||||
break;
|
||||
case XRT_INPUT_GENERIC_PALM_POSE:
|
||||
std::tie(extrapolation_time, *res, device) = palm.get_pose_at(at_timestamp_ns);
|
||||
cnx->set_enabled(device, true);
|
||||
break;
|
||||
case XRT_INPUT_HAND_PINCH_POSE:
|
||||
std::tie(extrapolation_time, *res, device) = pinch_ext.get_pose_at(at_timestamp_ns);
|
||||
cnx->set_enabled(device, true);
|
||||
break;
|
||||
case XRT_INPUT_HAND_POKE_POSE:
|
||||
std::tie(extrapolation_time, *res, device) = poke_ext.get_pose_at(at_timestamp_ns);
|
||||
cnx->set_enabled(device, true);
|
||||
break;
|
||||
default:
|
||||
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), name);
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
cnx->add_predict_offset(extrapolation_time);
|
||||
if (auto & out = tracking_dump())
|
||||
{
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto device = [&] {
|
||||
switch (name)
|
||||
{
|
||||
case XRT_INPUT_HAND_AIM_POSE: return aim.device;
|
||||
case XRT_INPUT_HAND_GRIP_POSE: return grip.device;
|
||||
case XRT_INPUT_GENERIC_PALM_POSE: return palm.device;
|
||||
case XRT_INPUT_HAND_PINCH_POSE: return pinch_ext.device;
|
||||
case XRT_INPUT_HAND_POKE_POSE: return poke_ext.device;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
} }();
|
||||
out << magic_enum::enum_name(device) << ','
|
||||
<< os_monotonic_get_ns() << ','
|
||||
<< at_timestamp_ns << ','
|
||||
<< extrapolation_time.count() << ','
|
||||
<< "g,"
|
||||
<< *res << std::endl;
|
||||
;
|
||||
}
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
void wivrn_hand_interaction::set_derived_pose(const from_headset::derived_pose & derived)
|
||||
{
|
||||
auto list = [this](device_id id) -> pose_list * {
|
||||
for (auto item: {&grip, &aim, &palm})
|
||||
{
|
||||
if (item->device == id)
|
||||
return item;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
auto source = list(derived.source);
|
||||
auto target = list(derived.target);
|
||||
if (source and target)
|
||||
{
|
||||
target->set_derived(source, xrt_cast(derived.relation));
|
||||
if (source != target)
|
||||
cnx->set_enabled(derived.target, false);
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_hand_interaction::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
|
||||
{
|
||||
if (not aim.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(aim.device, false);
|
||||
if (not grip.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(grip.device, false);
|
||||
if (not palm.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(palm.device, false);
|
||||
if (not pinch_ext.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(pinch_ext.device, false);
|
||||
if (not poke_ext.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(poke_ext.device, false);
|
||||
if (auto & out = tracking_dump(); out and offset)
|
||||
{
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto now = os_monotonic_get_ns();
|
||||
for (const auto & pose: tracking.device_poses)
|
||||
{
|
||||
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
|
||||
out << magic_enum::enum_name(pose.device) << ','
|
||||
<< now << ','
|
||||
<< offset.from_headset(tracking.timestamp) << ','
|
||||
<< tracking.timestamp - tracking.production_timestamp << ','
|
||||
<< "r,"
|
||||
<< pose_list::convert_pose(pose) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_hand_interaction::reset_history()
|
||||
{
|
||||
aim.reset();
|
||||
grip.reset();
|
||||
palm.reset();
|
||||
pinch_ext.reset();
|
||||
poke_ext.reset();
|
||||
}
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* 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 "xrt/xrt_device.h"
|
||||
|
||||
#include "hand_joints_list.h"
|
||||
#include "pose_list.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class wivrn_session;
|
||||
|
||||
class wivrn_hand_interaction : public xrt_device
|
||||
{
|
||||
std::mutex mutex;
|
||||
|
||||
pose_list grip;
|
||||
pose_list aim;
|
||||
pose_list palm;
|
||||
pose_list pinch_ext;
|
||||
pose_list poke_ext;
|
||||
|
||||
std::vector<xrt_input> inputs_staging;
|
||||
std::vector<xrt_input> inputs_array;
|
||||
|
||||
wivrn::wivrn_session * cnx;
|
||||
|
||||
public:
|
||||
using base = xrt_device;
|
||||
wivrn_hand_interaction(int hand_id, xrt_device * hmd, wivrn::wivrn_session * cnx);
|
||||
|
||||
xrt_result_t update_inputs();
|
||||
|
||||
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
|
||||
|
||||
void set_inputs(const from_headset::inputs &, const clock_offset &);
|
||||
|
||||
void set_derived_pose(const from_headset::derived_pose &);
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
|
||||
void reset_history();
|
||||
};
|
||||
} // namespace wivrn
|
||||
@@ -76,7 +76,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
.supported = {
|
||||
.orientation_tracking = true,
|
||||
.position_tracking = true,
|
||||
.presence = info.presence,
|
||||
.presence = true,
|
||||
.battery_status = true,
|
||||
},
|
||||
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
|
||||
@@ -89,7 +89,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
},
|
||||
cnx(cnx)
|
||||
{
|
||||
const auto config = configuration::read_user_configuration();
|
||||
const auto config = configuration();
|
||||
|
||||
auto eye_width = info.recommended_eye_width;
|
||||
eye_width = ((eye_width + 3) / 4) * 4;
|
||||
@@ -232,9 +232,28 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
|
||||
m->at(mask.view_index) = mask.data;
|
||||
}
|
||||
|
||||
void wivrn_hmd::update_presence(bool presence)
|
||||
bool wivrn_hmd::update_presence(bool new_presence, bool real)
|
||||
{
|
||||
U_LOG_I("Updating user presence to %s", presence ? "true" : "false");
|
||||
this->presence = presence;
|
||||
// if this presence change comes from headset, always honor it,
|
||||
// otherwise try to keep it in sync with the real presence,
|
||||
// while still changing presence to false when session is not
|
||||
// visible
|
||||
if (real || new_presence == this->real_presence || !new_presence)
|
||||
{
|
||||
if (real && this->real_presence != new_presence)
|
||||
{
|
||||
U_LOG_I("Updating real user presence: %s -> %s", real_presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->real_presence = new_presence;
|
||||
}
|
||||
|
||||
if (this->presence == new_presence)
|
||||
return false;
|
||||
|
||||
U_LOG_I("Updating user presence: %s -> %s", this->presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->presence = new_presence;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -47,6 +47,10 @@ class wivrn_hmd : public xrt_device
|
||||
from_headset::battery battery{};
|
||||
|
||||
std::atomic<bool> presence{true};
|
||||
// last XR_EVENT_DATA_USER_PRESENCE_CHANGED_EXT from headset
|
||||
// we must keep track of this to not go out of sync with headset when
|
||||
// a session state change also triggers presence change
|
||||
std::atomic<bool> real_presence{true};
|
||||
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||
|
||||
wivrn::wivrn_session * cnx;
|
||||
@@ -84,6 +88,7 @@ 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 &);
|
||||
void update_presence(bool presence);
|
||||
// real if this update comes from a presence changed event
|
||||
bool update_presence(bool new_presence, bool real);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
+136
-24
@@ -39,6 +39,7 @@
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/to_string.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_session.h"
|
||||
#include <algorithm>
|
||||
@@ -145,8 +146,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
connection(std::move(connection)),
|
||||
xrt_system(system),
|
||||
hmd(this, get_info()),
|
||||
left_hand(0, &hmd, this),
|
||||
right_hand(1, &hmd, this)
|
||||
left_controller(0, &hmd, this),
|
||||
left_hand_interaction(0, &hmd, this),
|
||||
right_controller(1, &hmd, this),
|
||||
right_hand_interaction(1, &hmd, this)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -171,14 +174,16 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
if (hmd.supported.face_tracking)
|
||||
static_roles.face = &hmd;
|
||||
|
||||
roles.left = xdev_count;
|
||||
static_roles.hand_tracking.left = xdevs[xdev_count++] = &left_hand;
|
||||
roles.left = left_controller_index = xdev_count++;
|
||||
static_roles.hand_tracking.left = xdevs[left_controller_index] = &left_controller;
|
||||
xdevs[left_hand_interaction_index = xdev_count++] = &left_hand_interaction;
|
||||
|
||||
roles.right = xdev_count;
|
||||
static_roles.hand_tracking.right = xdevs[xdev_count++] = &right_hand;
|
||||
roles.right = right_controller_index = xdev_count++;
|
||||
static_roles.hand_tracking.right = xdevs[right_controller_index] = &right_controller;
|
||||
xdevs[right_hand_interaction_index = xdev_count++] = &right_hand_interaction;
|
||||
|
||||
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
|
||||
auto use_steamvr_lh = configuration::read_user_configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
||||
auto use_steamvr_lh = configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH");
|
||||
xrt_system_devices * lhdevs = NULL;
|
||||
|
||||
if (use_steamvr_lh && steamvr_lh_create_devices(&lhdevs) == XRT_SUCCESS)
|
||||
@@ -313,8 +318,8 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
u_builder_create_space_overseer_legacy(
|
||||
&self->xrt_system.broadcast,
|
||||
&self->hmd,
|
||||
&self->left_hand,
|
||||
&self->right_hand,
|
||||
&self->left_controller,
|
||||
&self->right_controller,
|
||||
nullptr,
|
||||
self->xdevs,
|
||||
self->xdev_count,
|
||||
@@ -363,6 +368,8 @@ static xrt_device_name get_name(interaction_profile profile)
|
||||
return XRT_DEVICE_INVALID;
|
||||
case interaction_profile::khr_simple_controller:
|
||||
return XRT_DEVICE_SIMPLE_CONTROLLER;
|
||||
case interaction_profile::ext_hand_interaction_ext:
|
||||
return XRT_DEVICE_EXT_HAND_INTERACTION;
|
||||
case interaction_profile::bytedance_pico_neo3_controller:
|
||||
return XRT_DEVICE_PICO_NEO3_CONTROLLER;
|
||||
case interaction_profile::bytedance_pico4_controller:
|
||||
@@ -407,8 +414,8 @@ static xrt_device_name get_name(interaction_profile profile)
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::trackings && tracking)
|
||||
{
|
||||
auto left = xdevs[roles.left] == &left_hand ? get_name(tracking.interaction_profiles[0]) : XRT_DEVICE_INVALID;
|
||||
auto right = xdevs[roles.right] == &right_hand ? get_name(tracking.interaction_profiles[1]) : XRT_DEVICE_INVALID;
|
||||
auto left = (roles.left == left_controller_index || roles.left == left_hand_interaction_index) ? get_name(tracking.interaction_profiles[0]) : XRT_DEVICE_INVALID;
|
||||
auto right = (roles.right == right_controller_index || roles.right == right_hand_interaction_index) ? get_name(tracking.interaction_profiles[1]) : XRT_DEVICE_INVALID;
|
||||
if (left != roles.left_profile or right != roles.right_profile)
|
||||
{
|
||||
U_LOG_I("Updating interaction profiles: from \n"
|
||||
@@ -419,8 +426,42 @@ void wivrn_session::operator()(from_headset::trackings && tracking)
|
||||
std::string(magic_enum::enum_name(roles.right_profile)).c_str(),
|
||||
std::string(magic_enum::enum_name(right)).c_str());
|
||||
std::lock_guard lock(roles_mutex);
|
||||
|
||||
// don't change role when hand from other driver is used
|
||||
if (roles.left == left_hand_interaction_index || roles.left == left_controller_index)
|
||||
{
|
||||
if (left == XRT_DEVICE_EXT_HAND_INTERACTION)
|
||||
{
|
||||
left_hand_interaction.reset_history();
|
||||
roles.left = left_hand_interaction_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
left_controller.reset_history();
|
||||
roles.left = left_controller_index;
|
||||
set_enabled(device_id::LEFT_PINCH_POSE, false);
|
||||
set_enabled(device_id::LEFT_POKE, false);
|
||||
}
|
||||
}
|
||||
roles.left_profile = left;
|
||||
|
||||
if (roles.right == right_hand_interaction_index || roles.right == right_controller_index)
|
||||
{
|
||||
if (right == XRT_DEVICE_EXT_HAND_INTERACTION)
|
||||
{
|
||||
right_hand_interaction.reset_history();
|
||||
roles.right = right_hand_interaction_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
right_controller.reset_history();
|
||||
roles.right = right_controller_index;
|
||||
set_enabled(device_id::RIGHT_PINCH_POSE, false);
|
||||
set_enabled(device_id::RIGHT_POKE, false);
|
||||
}
|
||||
}
|
||||
roles.right_profile = right;
|
||||
|
||||
++roles.generation_id;
|
||||
}
|
||||
|
||||
@@ -439,8 +480,16 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
|
||||
auto offset = offset_est.get_offset();
|
||||
|
||||
hmd.update_tracking(tracking, offset);
|
||||
left_hand.update_tracking(tracking, offset);
|
||||
right_hand.update_tracking(tracking, offset);
|
||||
if (roles.left == left_hand_interaction_index)
|
||||
left_hand_interaction.update_tracking(tracking, offset);
|
||||
else
|
||||
left_controller.update_tracking(tracking, offset);
|
||||
|
||||
if (roles.right == right_hand_interaction_index)
|
||||
right_hand_interaction.update_tracking(tracking, offset);
|
||||
else
|
||||
right_controller.update_tracking(tracking, offset);
|
||||
|
||||
if (eye_tracker)
|
||||
eye_tracker->update_tracking(tracking, offset);
|
||||
{
|
||||
@@ -457,16 +506,19 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
|
||||
|
||||
void wivrn_session::operator()(from_headset::derived_pose && derived)
|
||||
{
|
||||
left_hand.set_derived_pose(derived);
|
||||
right_hand.set_derived_pose(derived);
|
||||
left_controller.set_derived_pose(derived);
|
||||
left_hand_interaction.set_derived_pose(derived);
|
||||
|
||||
right_controller.set_derived_pose(derived);
|
||||
right_hand_interaction.set_derived_pose(derived);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
|
||||
{
|
||||
auto offset = offset_est.get_offset();
|
||||
|
||||
left_hand.update_hand_tracking(hand_tracking, offset);
|
||||
right_hand.update_hand_tracking(hand_tracking, offset);
|
||||
left_controller.update_hand_tracking(hand_tracking, offset);
|
||||
right_controller.update_hand_tracking(hand_tracking, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
|
||||
{
|
||||
@@ -485,8 +537,15 @@ void wivrn_session::operator()(from_headset::inputs && inputs)
|
||||
{
|
||||
auto offset = get_offset();
|
||||
|
||||
left_hand.set_inputs(inputs, offset);
|
||||
right_hand.set_inputs(inputs, offset);
|
||||
if (roles.left == left_hand_interaction_index)
|
||||
left_hand_interaction.set_inputs(inputs, offset);
|
||||
else if (roles.left == left_controller_index)
|
||||
left_controller.set_inputs(inputs, offset);
|
||||
|
||||
if (roles.right == right_hand_interaction_index)
|
||||
right_hand_interaction.set_inputs(inputs, offset);
|
||||
else if (roles.right == right_controller_index)
|
||||
right_controller.set_inputs(inputs, offset);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::timesync_response && timesync)
|
||||
@@ -505,12 +564,20 @@ static auto to_tracking_control(device_id id)
|
||||
return tid::left_grip;
|
||||
case device_id::LEFT_PALM:
|
||||
return tid::left_palm;
|
||||
case device_id::LEFT_PINCH_POSE:
|
||||
return tid::left_pinch;
|
||||
case device_id::LEFT_POKE:
|
||||
return tid::left_poke;
|
||||
case device_id::RIGHT_AIM:
|
||||
return tid::right_aim;
|
||||
case device_id::RIGHT_GRIP:
|
||||
return tid::right_grip;
|
||||
case device_id::RIGHT_PALM:
|
||||
return tid::right_palm;
|
||||
case device_id::RIGHT_PINCH_POSE:
|
||||
return tid::right_pinch;
|
||||
case device_id::RIGHT_POKE:
|
||||
return tid::right_poke;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -578,17 +645,61 @@ void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)
|
||||
auto result = xrt_session_event_sink_push(&xrt_system.broadcast, &event);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
void wivrn_session::operator()(from_headset::session_state_changed && event)
|
||||
{
|
||||
hmd.update_presence(event.present);
|
||||
U_LOG_I("Session state changed: %s", xr::to_string(event.state));
|
||||
bool visible, focused;
|
||||
bool changed = false;
|
||||
switch (event.state)
|
||||
{
|
||||
case XR_SESSION_STATE_SYNCHRONIZED:
|
||||
visible = false;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(false, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_VISIBLE:
|
||||
visible = true;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_FOCUSED:
|
||||
visible = true;
|
||||
focused = true;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
xrt_session_event_user_presence_change event = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
};
|
||||
hmd.get_presence(&event.is_user_present);
|
||||
push_event({.presence_change = event});
|
||||
}
|
||||
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
.is_user_present = event.present,
|
||||
.state = {
|
||||
.type = XRT_SESSION_EVENT_STATE_CHANGE,
|
||||
.visible = visible,
|
||||
.focused = focused,
|
||||
},
|
||||
});
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
{
|
||||
if (hmd.update_presence(event.present, true))
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
.is_user_present = event.present,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
|
||||
{
|
||||
@@ -615,6 +726,7 @@ void wivrn_session::operator()(audio_data && data)
|
||||
|
||||
void wivrn_session::operator()(to_monado::disconnect &&)
|
||||
{
|
||||
connection->shutdown();
|
||||
throw std::runtime_error("Disconnecting as requested by main loop");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "driver/app_pacer.h"
|
||||
#include "wivrn_connection.h"
|
||||
#include "wivrn_controller.h"
|
||||
#include "wivrn_hand_interaction.h"
|
||||
#include "wivrn_hmd.h"
|
||||
#include "wivrn_ipc.h"
|
||||
#include "wivrn_packets.h"
|
||||
@@ -105,8 +106,14 @@ class wivrn_session : public xrt_system_devices
|
||||
};
|
||||
|
||||
wivrn_hmd hmd;
|
||||
wivrn_controller left_hand;
|
||||
wivrn_controller right_hand;
|
||||
wivrn_controller left_controller;
|
||||
int32_t left_controller_index;
|
||||
wivrn_hand_interaction left_hand_interaction;
|
||||
int32_t left_hand_interaction_index;
|
||||
wivrn_controller right_controller;
|
||||
int32_t right_controller_index;
|
||||
wivrn_hand_interaction right_hand_interaction;
|
||||
int32_t right_hand_interaction_index;
|
||||
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;
|
||||
@@ -179,6 +186,7 @@ public:
|
||||
void operator()(from_headset::feedback &&);
|
||||
void operator()(from_headset::battery &&);
|
||||
void operator()(from_headset::visibility_mask_changed &&);
|
||||
void operator()(from_headset::session_state_changed &&);
|
||||
void operator()(from_headset::user_presence_changed &&);
|
||||
void operator()(from_headset::refresh_rate_changed &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
#include "video_encoder.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include <cmath>
|
||||
#include <magic_enum.hpp>
|
||||
#include <string>
|
||||
@@ -91,8 +92,9 @@ void print_encoders(const std::vector<wivrn::encoder_settings> & encoders)
|
||||
group = encoder.group;
|
||||
U_LOG_I("Group %d", group);
|
||||
}
|
||||
|
||||
std::string codec(magic_enum::enum_name(encoder.codec));
|
||||
U_LOG_I("\t%s (%s)", encoder.encoder_name.c_str(), codec.c_str());
|
||||
U_LOG_I("\t%s (%s %d-bit)", encoder.encoder_name.c_str(), codec.c_str(), encoder.bit_depth);
|
||||
U_LOG_I("\tchannels: %s", std::string(magic_enum::enum_name(encoder.channels)).c_str());
|
||||
U_LOG_I("\tsize:%" PRIu16 "x%" PRIu16 " offset:%" PRIu16 "x%" PRIu16,
|
||||
encoder.width,
|
||||
@@ -141,7 +143,7 @@ static constexpr auto ffmpeg_version()
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs)
|
||||
static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & codecs, int bit_depth)
|
||||
{
|
||||
video_encoder_ffmpeg::mute_logs mute;
|
||||
encoder_settings s{
|
||||
@@ -154,11 +156,18 @@ static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & b
|
||||
"vaapi",
|
||||
default_bitrate,
|
||||
};
|
||||
s.bit_depth = bit_depth;
|
||||
|
||||
for (auto codec: codecs)
|
||||
{
|
||||
if constexpr (ffmpeg_version()[0] < 6)
|
||||
if (codec == wivrn::video_codec::h264)
|
||||
{
|
||||
if (codec == wivrn::video_codec::h264)
|
||||
if (bit_depth != 8)
|
||||
{
|
||||
U_LOG_D("Will not use h264: %d-bit not supported", bit_depth);
|
||||
continue;
|
||||
}
|
||||
if constexpr (ffmpeg_version()[0] < 6)
|
||||
{
|
||||
U_LOG_W("Skip h264 on ffmpeg < 6 due to poor performance");
|
||||
continue;
|
||||
@@ -181,7 +190,7 @@ static std::optional<wivrn::video_codec> filter_codecs_vaapi(wivrn_vk_bundle & b
|
||||
#endif
|
||||
|
||||
#if WIVRN_USE_NVENC
|
||||
static bool probe_nvenc(wivrn_vk_bundle & bundle)
|
||||
static bool probe_nvenc(wivrn_vk_bundle & bundle, int bit_depth)
|
||||
{
|
||||
static bool res = [&]() {
|
||||
encoder_settings s{
|
||||
@@ -195,6 +204,7 @@ static bool probe_nvenc(wivrn_vk_bundle & bundle)
|
||||
encoder_nvenc,
|
||||
default_bitrate,
|
||||
};
|
||||
s.bit_depth = bit_depth;
|
||||
try
|
||||
{
|
||||
video_encoder_nvenc test(bundle, s, 60, 0);
|
||||
@@ -209,14 +219,14 @@ static bool probe_nvenc(wivrn_vk_bundle & bundle)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, configuration::encoder & config)
|
||||
static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, configuration::encoder & config, int bit_depth)
|
||||
{
|
||||
if (config.name.empty())
|
||||
{
|
||||
if (is_nvidia(*bundle.physical_device))
|
||||
{
|
||||
#if WIVRN_USE_NVENC
|
||||
if (probe_nvenc(bundle))
|
||||
if (probe_nvenc(bundle, bit_depth))
|
||||
config.name = encoder_nvenc;
|
||||
else
|
||||
#else
|
||||
@@ -224,8 +234,13 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
|
||||
#endif
|
||||
{
|
||||
#if WIVRN_USE_X264
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
if (bit_depth != 8)
|
||||
U_LOG_E("no encoder found with %d-bit support (set 8-bit to use x264)", bit_depth);
|
||||
else
|
||||
{
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
}
|
||||
#else
|
||||
U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)");
|
||||
#endif
|
||||
@@ -236,9 +251,14 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
|
||||
#if WIVRN_USE_VAAPI
|
||||
config.name = encoder_vaapi;
|
||||
#elif WIVRN_USE_X264
|
||||
U_LOG_W("ffmpeg support not compiled, vaapi encoder not available");
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
if (bit_depth != 8)
|
||||
U_LOG_E("no encoder found with %d-bit support (set 8-bit to use x264)", bit_depth);
|
||||
else
|
||||
{
|
||||
U_LOG_W("ffmpeg support not compiled, vaapi encoder not available");
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
}
|
||||
#else
|
||||
U_LOG_E("no suitable encoder available (compile with x264 or nvenc support)");
|
||||
#endif
|
||||
@@ -248,32 +268,41 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
|
||||
#if WIVRN_USE_VAAPI
|
||||
if (config.name == encoder_vaapi and not config.codec)
|
||||
{
|
||||
config.codec = filter_codecs_vaapi(bundle, headset_codecs);
|
||||
config.codec = filter_codecs_vaapi(bundle, headset_codecs, bit_depth);
|
||||
if (not config.codec)
|
||||
{
|
||||
U_LOG_W("Failed to initialize vaapi, fallback to software encoding");
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
#if WIVRN_USE_X264
|
||||
if (bit_depth != 8)
|
||||
U_LOG_E("Failed to initialize vaapi, but can't use x264 due to %d-bit encoding (set 8-bit to use x264)", bit_depth);
|
||||
else
|
||||
{
|
||||
U_LOG_W("Failed to initialize vaapi, fallback to software encoding");
|
||||
config.name = encoder_x264;
|
||||
config.codec = h264;
|
||||
}
|
||||
#else
|
||||
U_LOG_E("Failed to initialize vaapi");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config.name == encoder_vulkan and not config.codec)
|
||||
config.codec = h264;
|
||||
config.codec = h264; // this will fail if 10-bit is enabled
|
||||
|
||||
#if WIVRN_USE_X264
|
||||
if (config.name == encoder_x264)
|
||||
config.codec = h264;
|
||||
config.codec = h264; // this will fail if 10-bit is enabled
|
||||
#endif
|
||||
|
||||
if (not config.codec)
|
||||
config.codec = h264;
|
||||
config.codec = bit_depth == 10 ? h265 : h264;
|
||||
}
|
||||
|
||||
static std::vector<configuration::encoder> get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs)
|
||||
static std::vector<configuration::encoder> get_encoder_default_settings(wivrn_vk_bundle & bundle, const std::vector<wivrn::video_codec> & headset_codecs, int bit_depth)
|
||||
{
|
||||
configuration::encoder base;
|
||||
fill_defaults(bundle, headset_codecs, base);
|
||||
fill_defaults(bundle, headset_codecs, base, bit_depth);
|
||||
|
||||
#ifdef WIVRN_SPLIT_ENCODERS
|
||||
if (base.name != encoder_x264 and base.name != encoder_nvenc)
|
||||
@@ -330,16 +359,12 @@ static uint16_t align(uint16_t value, uint16_t alignment)
|
||||
std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info)
|
||||
{
|
||||
configuration config;
|
||||
try
|
||||
{
|
||||
config = configuration::read_user_configuration();
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
U_LOG_E("Failed to read encoder configuration: %s", e.what());
|
||||
}
|
||||
|
||||
if (config.bit_depth != 8 && config.bit_depth != 10)
|
||||
throw std::runtime_error("invalid bit-depth setting. supported values: 8, 10");
|
||||
|
||||
if (config.encoders.empty())
|
||||
config.encoders = get_encoder_default_settings(bundle, info.supported_codecs);
|
||||
config.encoders = get_encoder_default_settings(bundle, info.supported_codecs, config.bit_depth);
|
||||
if (not config.encoder_passthrough)
|
||||
config.encoder_passthrough.emplace();
|
||||
|
||||
@@ -347,7 +372,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
|
||||
config.encoder_passthrough->height = 1;
|
||||
config.encoder_passthrough->offset_x = 0;
|
||||
config.encoder_passthrough->offset_y = 0;
|
||||
fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough);
|
||||
fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough, config.bit_depth);
|
||||
|
||||
uint64_t bitrate = config.bitrate.value_or(default_bitrate);
|
||||
std::array<double, 2> default_scale;
|
||||
@@ -363,7 +388,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
|
||||
|
||||
for (auto & encoder: config.encoders)
|
||||
{
|
||||
fill_defaults(bundle, info.supported_codecs, encoder);
|
||||
fill_defaults(bundle, info.supported_codecs, encoder, config.bit_depth);
|
||||
assert(encoder.codec);
|
||||
check_scale(encoder.name,
|
||||
*encoder.codec,
|
||||
@@ -402,6 +427,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
|
||||
settings.video_width = settings.width;
|
||||
settings.video_height = settings.height;
|
||||
settings.codec = *encoder.codec;
|
||||
settings.bit_depth = config.bit_depth;
|
||||
if (encoder.group)
|
||||
settings.group = *encoder.group;
|
||||
else
|
||||
@@ -432,6 +458,7 @@ std::vector<encoder_settings> get_encoder_settings(wivrn_vk_bundle & bundle, uin
|
||||
settings.video_width = settings.width;
|
||||
settings.video_height = settings.height;
|
||||
settings.codec = *encoder.codec;
|
||||
settings.bit_depth = config.bit_depth;
|
||||
if (encoder.group)
|
||||
settings.group = *encoder.group;
|
||||
else
|
||||
|
||||
@@ -39,6 +39,7 @@ struct encoder_settings : public to_headset::video_stream_description::item
|
||||
std::map<std::string, std::string> options; // additional encoder-specific configuration
|
||||
// encoders in the same group are executed in sequence
|
||||
int group = 0;
|
||||
int bit_depth;
|
||||
std::optional<std::string> device;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <filesystem>
|
||||
#include <libavutil/pixfmt.h>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
@@ -124,9 +125,23 @@ std::unordered_map<uint32_t, vk::Format> vulkan_drm_format_map = {
|
||||
{DRM_FORMAT_XBGR8888, vk::Format::eR8G8B8A8Unorm},
|
||||
};
|
||||
|
||||
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc)
|
||||
std::unordered_map<uint32_t, vk::Format> vulkan_drm_format_map_10bit = {
|
||||
{DRM_FORMAT_R8, vk::Format::eR10X6UnormPack16},
|
||||
{DRM_FORMAT_R10, vk::Format::eR10X6UnormPack16},
|
||||
{DRM_FORMAT_R16, vk::Format::eR10X6UnormPack16},
|
||||
{DRM_FORMAT_GR88, vk::Format::eR10X6G10X6Unorm2Pack16},
|
||||
{DRM_FORMAT_RG88, vk::Format::eR10X6G10X6Unorm2Pack16},
|
||||
{DRM_FORMAT_GR1616, vk::Format::eR10X6G10X6Unorm2Pack16},
|
||||
{DRM_FORMAT_RG1616, vk::Format::eR10X6G10X6Unorm2Pack16},
|
||||
};
|
||||
|
||||
/// bit_depth not checked, valid values are 8 and 10
|
||||
vk::Format drm_to_vulkan_fmt(uint32_t drm_fourcc, int bit_depth)
|
||||
{
|
||||
return vulkan_drm_format_map.at(drm_fourcc);
|
||||
if (bit_depth == 10)
|
||||
return vulkan_drm_format_map_10bit.at(drm_fourcc);
|
||||
else
|
||||
return vulkan_drm_format_map.at(drm_fourcc);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -151,9 +166,28 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
settings.video_width += settings.video_width % 2;
|
||||
settings.video_height += settings.video_height % 2;
|
||||
|
||||
auto vaapi_frame_ctx = make_hwframe_ctx(vaapi_hw_ctx.get(), AV_PIX_FMT_VAAPI, AV_PIX_FMT_NV12, settings.video_width, settings.video_height);
|
||||
AVPixelFormat sw_format;
|
||||
|
||||
assert(av_pix_fmt_count_planes(AV_PIX_FMT_NV12) == 2);
|
||||
switch (settings.codec)
|
||||
{
|
||||
case video_codec::av1:
|
||||
case video_codec::h265:
|
||||
if (settings.bit_depth == 10)
|
||||
sw_format = AV_PIX_FMT_P010;
|
||||
else if (settings.bit_depth == 8)
|
||||
sw_format = AV_PIX_FMT_NV12;
|
||||
else
|
||||
throw std::runtime_error("selected codec only supports 10-bit or 8-bit encoding");
|
||||
break;
|
||||
default:
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("selected codec only supports 8-bit encoding");
|
||||
sw_format = AV_PIX_FMT_NV12;
|
||||
break;
|
||||
}
|
||||
|
||||
auto vaapi_frame_ctx = make_hwframe_ctx(vaapi_hw_ctx.get(), AV_PIX_FMT_VAAPI, sw_format, settings.video_width, settings.video_height);
|
||||
assert(av_pix_fmt_count_planes(sw_format) == 2);
|
||||
|
||||
rect = vk::Rect2D{
|
||||
.offset = {
|
||||
@@ -199,7 +233,8 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
av_dict_set(&opts, "rc_mode", "CBR", 0);
|
||||
break;
|
||||
case video_codec::h265:
|
||||
encoder_ctx->profile = FF_PROFILE_HEVC_MAIN;
|
||||
// bit_depth is either 8 or 10 here
|
||||
encoder_ctx->profile = settings.bit_depth == 10 ? FF_PROFILE_HEVC_MAIN_10 : FF_PROFILE_HEVC_MAIN;
|
||||
break;
|
||||
case video_codec::av1:
|
||||
encoder_ctx->profile = FF_PROFILE_AV1_MAIN;
|
||||
@@ -282,7 +317,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk,
|
||||
vk::StructureChain image_create_info{
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = drm_to_vulkan_fmt(desc->layers[i].format),
|
||||
.format = drm_to_vulkan_fmt(desc->layers[i].format, settings.bit_depth),
|
||||
.extent = {
|
||||
.width = uint32_t(drm_frame->width / (i == 0 ? 1 : 2)),
|
||||
.height = uint32_t(drm_frame->height / (i == 0 ? 1 : 2)),
|
||||
|
||||
@@ -336,7 +336,7 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
|
||||
auto end = data.end();
|
||||
while (begin != end)
|
||||
{
|
||||
const size_t max_payload_size = to_headset::video_stream_data_shard::max_payload_size - serialized_size(shard.view_info);
|
||||
const size_t max_payload_size = std::max(0z, ssize_t(to_headset::video_stream_data_shard::max_payload_size) - ssize_t(serialized_size(shard.view_info)));
|
||||
auto next = std::min(end, begin + max_payload_size);
|
||||
if (next == end)
|
||||
{
|
||||
|
||||
@@ -144,6 +144,9 @@ video_encoder_nvenc::video_encoder_nvenc(
|
||||
fps(fps),
|
||||
bitrate(settings.bitrate)
|
||||
{
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("nvenc encoder only supports 8-bit encoding");
|
||||
|
||||
std::tie(cuda_fn, nvenc_fn, fn, cuda, session_handle) = init();
|
||||
assert(settings.width % 32 == 0);
|
||||
assert(settings.height % 32 == 0);
|
||||
|
||||
@@ -192,6 +192,9 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h264> wivrn::video_encoder_vulkan_h2
|
||||
vk::VideoEncodeCapabilitiesKHR,
|
||||
vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get());
|
||||
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("h264 codec only supports 8-bit encoding");
|
||||
|
||||
std::unique_ptr<video_encoder_vulkan_h264> self(new video_encoder_vulkan_h264(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
|
||||
|
||||
vk::VideoEncodeH264SessionParametersAddInfoKHR h264_add_info{};
|
||||
|
||||
@@ -93,6 +93,9 @@ video_encoder_x264::video_encoder_x264(
|
||||
uint8_t stream_idx) :
|
||||
video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, false)
|
||||
{
|
||||
if (settings.bit_depth != 8)
|
||||
throw std::runtime_error("x264 encoder only supports 8-bit encoding");
|
||||
|
||||
if (settings.codec != h264)
|
||||
{
|
||||
U_LOG_W("requested x264 encoder with codec != h264");
|
||||
|
||||
+12
-6
@@ -479,7 +479,7 @@ gboolean headset_connected_success(void *)
|
||||
|
||||
expose_known_keys_on_dbus();
|
||||
|
||||
start_server(configuration::read_user_configuration());
|
||||
start_server(configuration());
|
||||
try
|
||||
{
|
||||
start_app();
|
||||
@@ -855,9 +855,15 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
|
||||
|
||||
on_headset_info_packet({});
|
||||
|
||||
std::ifstream file(configuration::get_config_file());
|
||||
std::string config{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
|
||||
std::string config;
|
||||
try
|
||||
{
|
||||
config = configuration::read_configuration().dump();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Invalid configuration: " << e.what() << std::endl;
|
||||
}
|
||||
wivrn_server_set_json_configuration(dbus_server, config.c_str());
|
||||
|
||||
expose_known_keys_on_dbus();
|
||||
@@ -1035,11 +1041,11 @@ int main(int argc, char * argv[])
|
||||
if (*no_publish)
|
||||
publication = wivrn::service_publication::none;
|
||||
else
|
||||
publication = configuration::read_user_configuration().publication;
|
||||
publication = configuration().publication;
|
||||
|
||||
#if WIVRN_USE_SYSTEMD
|
||||
if (*app_flag)
|
||||
return exec_application(configuration::read_user_configuration());
|
||||
return exec_application(configuration());
|
||||
#endif
|
||||
try
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ pid_t wivrn::start_unit_file()
|
||||
|
||||
pid_t wivrn::fork_application()
|
||||
{
|
||||
auto config = configuration::read_user_configuration();
|
||||
configuration config;
|
||||
|
||||
if (config.application.empty())
|
||||
return 0;
|
||||
|
||||
@@ -11,7 +11,7 @@ set_target_properties(wivrn-dissector PROPERTIES
|
||||
target_link_libraries(wivrn-dissector PRIVATE epan wivrn-common)
|
||||
set_target_properties(wivrn-dissector PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
if (OPENXR_FOUND)
|
||||
if (OpenXR_FOUND)
|
||||
target_link_libraries(wivrn-dissector PRIVATE OpenXR::headers)
|
||||
else()
|
||||
FetchContent_MakeAvailable(openxr_loader)
|
||||
|
||||
Reference in New Issue
Block a user