From ba79c268b130a3676da07a457c4850d4094fe80c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 12 Dec 2023 21:29:20 +0000 Subject: [PATCH] u/space_overseer: Use broadcast event sink for reference space changes Generates xrt_session_event_reference_space_change_pending events. --- src/xrt/auxiliary/util/u_builders.c | 2 +- src/xrt/auxiliary/util/u_space_overseer.c | 31 ++++++++++++++++++++++- src/xrt/auxiliary/util/u_space_overseer.h | 4 ++- src/xrt/drivers/remote/r_hub.c | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/xrt/auxiliary/util/u_builders.c b/src/xrt/auxiliary/util/u_builders.c index 928f2af43..424415fb2 100644 --- a/src/xrt/auxiliary/util/u_builders.c +++ b/src/xrt/auxiliary/util/u_builders.c @@ -173,7 +173,7 @@ u_builder_create_space_overseer_legacy(struct xrt_session_event_sink *broadcast, * Space overseer. */ - struct u_space_overseer *uso = u_space_overseer_create(); + struct u_space_overseer *uso = u_space_overseer_create(broadcast); struct xrt_pose T_stage_local = XRT_POSE_IDENTITY; T_stage_local.position.y = 1.6; diff --git a/src/xrt/auxiliary/util/u_space_overseer.c b/src/xrt/auxiliary/util/u_space_overseer.c index d8f9026e0..aa6818a34 100644 --- a/src/xrt/auxiliary/util/u_space_overseer.c +++ b/src/xrt/auxiliary/util/u_space_overseer.c @@ -10,6 +10,7 @@ #include "xrt/xrt_space.h" #include "xrt/xrt_device.h" +#include "xrt/xrt_session.h" #include "xrt/xrt_tracking.h" #include "os/os_time.h" @@ -90,6 +91,9 @@ struct u_space_overseer //! Tracks usage of reference spaces. struct xrt_reference ref_space_use[XRT_SPACE_REFERENCE_TYPE_COUNT]; + //! Event sink to broadcast events to all sessions. + struct xrt_session_event_sink *broadcast; + /*! * Can we do a recenter of the local and local_floor spaces, protected * by the lock. @@ -544,6 +548,7 @@ static xrt_result_t recenter_local_spaces(struct xrt_space_overseer *xso) { struct u_space_overseer *uso = u_space_overseer(xso); + xrt_result_t xret; // Take the full lock from the start. pthread_rwlock_wrlock(&uso->lock); @@ -617,6 +622,29 @@ recenter_local_spaces(struct xrt_space_overseer *xso) update_offset_write_locked(ulocal, &local_offset); update_offset_write_locked(ulocal_floor, &local_floor_offset); + // Push the events. + union xrt_session_event xse = XRT_STRUCT_INIT; + + // Basics + xse.ref_change.event_type = XRT_SESSION_EVENT_REFERENCE_SPACE_CHANGE_PENDING; + xse.ref_change.pose_valid = false; + xse.ref_change.pose_in_previous_space = (struct xrt_pose)XRT_POSE_IDENTITY; + xse.ref_change.timestamp_ns = os_monotonic_get_ns(); + + // Event for local space. + xse.ref_change.ref_type = XRT_SPACE_REFERENCE_TYPE_LOCAL; + xret = xrt_session_event_sink_push(uso->broadcast, &xse); + if (xret != XRT_SUCCESS) { + U_LOG_E("Failed to push event for LOCAL!"); + } + + // Event for local floor space. + xse.ref_change.ref_type = XRT_SPACE_REFERENCE_TYPE_LOCAL_FLOOR; + xret = xrt_session_event_sink_push(uso->broadcast, &xse); + if (xret != XRT_SUCCESS) { + U_LOG_E("Failed to push event LOCAL_FLOOR!"); + } + pthread_rwlock_unlock(&uso->lock); return XRT_SUCCESS; @@ -656,7 +684,7 @@ destroy(struct xrt_space_overseer *xso) */ struct u_space_overseer * -u_space_overseer_create(void) +u_space_overseer_create(struct xrt_session_event_sink *broadcast) { struct u_space_overseer *uso = U_TYPED_CALLOC(struct u_space_overseer); uso->base.create_offset_space = create_offset_space; @@ -667,6 +695,7 @@ u_space_overseer_create(void) uso->base.ref_space_dec = ref_space_dec; uso->base.recenter_local_spaces = recenter_local_spaces; uso->base.destroy = destroy; + uso->broadcast = broadcast; XRT_MAYBE_UNUSED int ret = 0; diff --git a/src/xrt/auxiliary/util/u_space_overseer.h b/src/xrt/auxiliary/util/u_space_overseer.h index 799a8dc61..089c7d551 100644 --- a/src/xrt/auxiliary/util/u_space_overseer.h +++ b/src/xrt/auxiliary/util/u_space_overseer.h @@ -17,6 +17,7 @@ extern "C" { struct u_space_overseer; +struct xrt_session_event_sink; /* @@ -28,10 +29,11 @@ struct u_space_overseer; /*! * Create a default implementation of a space overseer. * + * @param[in] broadcast Event sink that broadcasts events to all sessions. * @ingroup aux_util */ struct u_space_overseer * -u_space_overseer_create(void); +u_space_overseer_create(struct xrt_session_event_sink *broadcast); /*! * Sets up the space overseer and all semantic spaces in a way that works with diff --git a/src/xrt/drivers/remote/r_hub.c b/src/xrt/drivers/remote/r_hub.c index c131382d7..698b86216 100644 --- a/src/xrt/drivers/remote/r_hub.c +++ b/src/xrt/drivers/remote/r_hub.c @@ -477,7 +477,7 @@ r_create_devices(uint16_t port, * Space overseer. */ - struct u_space_overseer *uso = u_space_overseer_create(); + struct u_space_overseer *uso = u_space_overseer_create(broadcast); struct xrt_space_overseer *xso = (struct xrt_space_overseer *)uso; assert(uso != NULL);