diff --git a/client/application.cpp b/client/application.cpp index f8ec53a8..5bf205af 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1113,6 +1113,7 @@ void application::initialize() opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME); opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME); opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME); + opt_extensions.push_back(XR_EXT_USER_PRESENCE_EXTENSION_NAME); opt_extensions.push_back(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME); opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index e89605e5..f4c85870 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -21,6 +21,7 @@ #include "xr/fb_face_tracker2.h" #include "xr/htc_body_tracker.h" #include "xr/pico_body_tracker.h" +#include #define GLM_FORCE_RADIANS #include "stream.h" @@ -217,6 +218,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrinstance.has_extension(XR_EXT_USER_PRESENCE_EXTENSION_NAME) && self->system.user_presence_properties().supportsUserPresence; if (config.check_feature(feature::face_tracking)) { @@ -1287,6 +1289,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_USER_PRESENCE_CHANGED_EXT: + network_session->send_control(from_headset::user_presence_changed{ + .present = (bool)event.user_presence_changed.isUserPresent, + }); + break; case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: on_interaction_profile_changed(event.interaction_profile_changed); break; diff --git a/client/xr/instance.h b/client/xr/instance.h index 16b5a654..e4c28f5f 100644 --- a/client/xr/instance.h +++ b/client/xr/instance.h @@ -43,6 +43,7 @@ union event XrEventDataDisplayRefreshRateChangedFB refresh_rate_changed; XrEventDataPassthroughStateChangedFB passthrough_state_changed; XrEventDataVisibilityMaskChangedKHR visibility_mask_changed; + XrEventDataUserPresenceChangedEXT user_presence_changed; }; class instance : public utils::handle { diff --git a/client/xr/system.cpp b/client/xr/system.cpp index 0c88054d..50c5acfc 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -105,6 +105,24 @@ XrSystemEyeGazeInteractionPropertiesEXT xr::system::eye_gaze_interaction_propert return eye_gaze_prop; } +XrSystemUserPresencePropertiesEXT xr::system::user_presence_properties() const +{ + if (!id) + throw std::invalid_argument("this"); + + XrSystemUserPresencePropertiesEXT presence_prop{ + .type = XR_TYPE_SYSTEM_USER_PRESENCE_PROPERTIES_EXT, + }; + + XrSystemProperties prop{ + .type = XR_TYPE_SYSTEM_PROPERTIES, + .next = &presence_prop, + }; + CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); + + return presence_prop; +} + XrSystemFaceTrackingProperties2FB xr::system::fb_face_tracking2_properties() const { if (!id) diff --git a/client/xr/system.h b/client/xr/system.h index 45e7729b..9905dca8 100644 --- a/client/xr/system.h +++ b/client/xr/system.h @@ -62,6 +62,7 @@ public: XrSystemProperties properties() const; XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const; XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const; + XrSystemUserPresencePropertiesEXT user_presence_properties() const; XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const; XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const; XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const; diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 52b9bb0d..ac829131 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -216,6 +216,7 @@ struct headset_info_packet std::array fov; bool hand_tracking; bool eye_gaze; + bool presence; bool palm_pose; bool passthrough; face_type face_tracking; @@ -409,6 +410,11 @@ struct refresh_rate_changed float to; }; +struct user_presence_changed +{ + bool present; +}; + using packets = std::variant< crypto_handshake, pin_check_1, @@ -426,7 +432,8 @@ using packets = std::variant< timesync_response, battery, visibility_mask_changed, - refresh_rate_changed>; + refresh_rate_changed, + user_presence_changed>; } // namespace from_headset namespace to_headset diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index a07a42fd..755f9470 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -76,10 +76,12 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx, .supported = { .orientation_tracking = true, .position_tracking = true, + .presence = info.presence, .battery_status = true, }, .update_inputs = [](xrt_device *) { return XRT_SUCCESS; }, .get_tracked_pose = method_pointer<&wivrn_hmd::get_tracked_pose>, + .get_presence = method_pointer<&wivrn_hmd::get_presence>, .get_view_poses = method_pointer<&wivrn_hmd::get_view_poses>, .get_visibility_mask = method_pointer<&wivrn_hmd::get_visibility_mask>, .get_battery_status = method_pointer<&wivrn_hmd::get_battery_status>, @@ -147,6 +149,13 @@ void wivrn_hmd::update_battery(const from_headset::battery & new_battery) battery = new_battery; } +xrt_result_t wivrn_hmd::get_presence(bool * out_presence) +{ + *out_presence = presence; + + return XRT_SUCCESS; +} + xrt_result_t wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, @@ -222,4 +231,10 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang auto m = visibility_mask.lock(); m->at(mask.view_index) = mask.data; } + +void wivrn_hmd::update_presence(bool presence) +{ + U_LOG_I("Updating user presence to %s", presence ? "true" : "false"); + this->presence = presence; +} } // namespace wivrn diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index c90f4f4b..275e967e 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -53,6 +53,7 @@ class wivrn_hmd : public xrt_device view_list views; from_headset::battery battery{}; + std::atomic presence{true}; thread_safe, 2>> visibility_mask; wivrn::wivrn_session * cnx; @@ -67,6 +68,7 @@ public: void set_foveated_size(uint32_t width, uint32_t height); xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation *); + xrt_result_t get_presence(bool * out_presence); xrt_result_t get_view_poses(const xrt_vec3 * default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, @@ -80,5 +82,6 @@ public: void update_battery(const from_headset::battery &); void update_tracking(const from_headset::tracking &, const clock_offset &); void update_visibility_mask(const from_headset::visibility_mask_changed &); + void update_presence(bool presence); }; } // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 5475de30..ea1e6968 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -576,6 +576,18 @@ 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) +{ + hmd.update_presence(event.present); + 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) { { diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 93ee8a93..63ea1168 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -179,6 +179,7 @@ public: void operator()(from_headset::feedback &&); void operator()(from_headset::battery &&); void operator()(from_headset::visibility_mask_changed &&); + void operator()(from_headset::user_presence_changed &&); void operator()(from_headset::refresh_rate_changed &&); void operator()(audio_data &&);