Compare commits

...
Author SHA1 Message Date
Vindicus999 e9af61cdb9 Merge remote-tracking branch 'upstream/master' 2026-02-13 02:38:13 +00:00
Patrick Nicolas c19056498d Switch flatpak/native recommendations, add notes 2026-02-12 12:27:28 +01:00
Patrick Nicolas 6f6ccefbf3 Move foveation config out of "if post processing" 2026-02-12 10:52:05 +01:00
Vindicus999 b4cda7975f Merge remote-tracking branch 'upstream/master' 2026-02-12 02:36:36 +00:00
Patrick Nicolas 06d771b89e Fix flickering screen after disconnect
Deleting the stream object has to be delayed until all Vulkan work is
done.
2026-02-11 23:36:17 +01:00
Patrick Nicolas 50ae773fec Don't log "error: " in mic change for no error 2026-02-11 20:40:01 +01:00
Patrick Nicolas 6cf46a6b73 Initialize view flags to 0 2026-02-11 19:38:11 +01:00
Sapphire f0e3e8d4ad Re-enable microphone on reconnect 2026-02-11 18:33:11 +01:00
Patrick Nicolas 399477edf5 Skip some memory copies in vulkan encode 2026-02-11 14:34:06 +01:00
Patrick Nicolas 0ec0de4509 Update vulkan memory allocator to 3.3.0 2026-02-11 14:34:06 +01:00
Patrick Nicolas a8657f7f91 Fix manual foveation window position 2026-02-11 12:30:56 +01:00
Sapphire 87b11d6817 Don't send empty HEAD pose on failed xrLocateSpace 2026-02-11 09:08:05 +01:00
Vindicus999 9d220d34d5 Merge remote-tracking branch 'upstream/master' 2026-02-11 02:42:18 +00:00
Guillaume Meunier 6ccf6eaf26 Fix fr locale 2026-02-10 21:14:40 +01:00
Sapphire 375d06dee2 Update Monado 2026-02-10 09:07:17 +01:00
Vindicus999 54e12d7fbf Merge remote-tracking branch 'upstream/master' 2026-02-10 02:44:33 +00:00
Patrick Nicolas 6b407a2d1c re-fix eye tracked foveation on Pico 2026-02-09 15:14:48 +01:00
Patrick Nicolas a712eec83a Update xrizer 2026-02-09 09:32:45 +01:00
29 changed files with 19651 additions and 21073 deletions
+10 -6
View File
@@ -38,15 +38,19 @@ WiVRn support a wide range of VR devices:
## PC Server/Dashboard
We recommend using the flatpak package from Flathub:
[![Flathub](https://flathub.org/api/badge)](https://flathub.org/apps/io.github.wivrn.wivrn)
Alternatively, packages are available from:
We recommend using native packages if available for your distribution:
- [Arch User Repositoy](https://aur.archlinux.org/packages/wivrn-dashboard)
- [Fedora](https://packages.fedoraproject.org/pkgs/wivrn/wivrn/)
- [Gentoo Guru](https://gitweb.gentoo.org/repo/proj/guru.git/tree/media-libs/wivrn)
- [NixOS](https://search.nixos.org/packages?channel=25.11&show=wivrn)
For OpenVR and Steam compatibility, you also need a [compatibility library](#openvr-and-steam-games) such as xrizer or OpenComposite.
A flatpak is available on Flathub for all distributions:
[![Flathub](https://flathub.org/api/badge)](https://flathub.org/apps/io.github.wivrn.wivrn)
Note that due to flatpak sandboxing some features may not be available such as Lighthouse tracked devices.
## Headset Client/App
@@ -97,7 +101,7 @@ The flatpak includes [OpenComposite](https://gitlab.com/znixian/OpenOVR/) and [x
If using Wine/Proton, it will probe for OpenVR at startup, This means even for OpenXR applications, OpenComposite or xrizer is required.
When you start the server through flatpak, it automatically configures the current OpenVR to use xrizer.
When a headset connects, wivrn-server sets the OpenVR runtime to xrizer unless manually configured differently.
### Steam Flatpak
If you're using the Steam Flatpak, you'll need to grant read only access to the following paths:
+1 -1
View File
@@ -76,7 +76,7 @@ public:
std::string environment_model = "assets://ground.glb";
bool override_foveation_enable = false;
float override_foveation_pitch = 10 * M_PI / 180;
float override_foveation_pitch = -10 * M_PI / 180;
float override_foveation_distance = 3;
bool high_power_mode;
+1 -1
View File
@@ -257,7 +257,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
if (next_scene->apps.draw_gui(*imgui_ctx, _("Disconnect")) == app_launcher::Cancel)
{
next_scene.reset();
next_scene->exit();
current_tab = tab::server_list;
}
}
+1 -1
View File
@@ -769,7 +769,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
last_display_time = frame_state.predictedDisplayTime;
std::shared_lock lock(decoder_mutex);
if (not frame_state.shouldRender or (decoders[0].empty() and decoders[1].empty()))
if (not frame_state.shouldRender or (decoders[0].empty() and decoders[1].empty()) or exiting)
{
// TODO: stop/restart video stream
session.begin_frame();
+1 -1
View File
@@ -218,6 +218,7 @@ public:
return state_;
}
void exit();
bool alive() const
{
return !exiting;
@@ -236,7 +237,6 @@ private:
void setup(const to_headset::video_stream_description &);
void setup_reprojection_swapchain(uint32_t width, uint32_t height);
void exit();
vk::raii::QueryPool query_pool = nullptr;
bool query_pool_filled = false;
+46 -46
View File
@@ -525,58 +525,58 @@ void scenes::stream::gui_settings(float predicted_display_period)
}
}
ImGui::Unindent();
}
bool send_packet = false;
bool save_config = false;
ImGui::Text("%s", _S("Foveation center override"));
ImGui::Indent();
bool send_packet = false;
bool save_config = false;
ImGui::Text("%s", _S("Foveation center override"));
ImGui::Indent();
{
if (ImGui::Checkbox(_S("Enable"), &override_foveation_enable))
{
if (ImGui::Checkbox(_S("Enable"), &override_foveation_enable))
{
send_packet = true;
save_config = true;
}
imgui_ctx->vibrate_on_hover();
ImGui::BeginDisabled(!override_foveation_enable);
ImGui::Text("%s", fmt::format(_F("Height {:.1f} deg"), -override_foveation_pitch * 180 / M_PI).c_str());
ImGui::Text("%s", fmt::format(_F("Distance {:.2f} m"), override_foveation_distance).c_str());
if (ImGui::Button(_S("Default")))
{
override_foveation_distance = configuration{}.override_foveation_distance;
override_foveation_pitch = configuration{}.override_foveation_pitch;
send_packet = true;
save_config = true;
}
imgui_ctx->vibrate_on_hover();
ImGui::SameLine();
if (ImGui::Button(_S("Change")))
gui_status = gui_status::foveation_settings;
imgui_ctx->vibrate_on_hover();
ImGui::EndDisabled();
send_packet = true;
save_config = true;
}
ImGui::Unindent();
imgui_ctx->vibrate_on_hover();
if (send_packet)
ImGui::BeginDisabled(!override_foveation_enable);
ImGui::Text("%s", fmt::format(_F("Height {:.1f} deg"), -override_foveation_pitch * 180 / M_PI).c_str());
ImGui::Text("%s", fmt::format(_F("Distance {:.2f} m"), override_foveation_distance).c_str());
if (ImGui::Button(_S("Default")))
{
network_session->send_control(from_headset::override_foveation_center{
.enabled = override_foveation_enable,
.pitch = override_foveation_pitch,
.distance = override_foveation_distance,
});
override_foveation_distance = configuration{}.override_foveation_distance;
override_foveation_pitch = configuration{}.override_foveation_pitch;
send_packet = true;
save_config = true;
}
imgui_ctx->vibrate_on_hover();
if (save_config)
{
auto & config = application::get_config();
config.override_foveation_enable = override_foveation_enable;
config.override_foveation_pitch = override_foveation_pitch;
config.override_foveation_distance = override_foveation_distance;
config.save();
}
ImGui::SameLine();
if (ImGui::Button(_S("Change")))
gui_status = gui_status::foveation_settings;
imgui_ctx->vibrate_on_hover();
ImGui::EndDisabled();
}
ImGui::Unindent();
if (send_packet)
{
network_session->send_control(from_headset::override_foveation_center{
.enabled = override_foveation_enable,
.pitch = override_foveation_pitch,
.distance = override_foveation_distance,
});
}
if (save_config)
{
auto & config = application::get_config();
config.override_foveation_enable = override_foveation_enable;
config.override_foveation_pitch = override_foveation_pitch;
config.override_foveation_distance = override_foveation_distance;
config.save();
}
ImGui::PopStyleVar();
}
@@ -827,7 +827,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
case gui_status::bitrate_settings:
case gui_status::foveation_settings:
imgui_ctx->layers()[0].orientation = head_position->second;
imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0, -override_foveation_distance * sin(override_foveation_pitch), -override_foveation_distance};
imgui_ctx->layers()[0].position = head_position->first + M * glm::vec3{0, override_foveation_distance * sin(override_foveation_pitch), -override_foveation_distance};
break;
case gui_status::hidden:
+2 -1
View File
@@ -84,7 +84,7 @@ from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpa
.flags = cast_flags(location.locationFlags, velocity.velocityFlags),
};
spdlog::warn("xrLocateSpace failed for {}: {}", magic_enum::enum_name(device), xr::to_string(res));
return {};
return {.device = device};
}
class locate_spaces_functor
@@ -515,6 +515,7 @@ void scenes::stream::tracking()
.w = gaze_quat.w,
},
},
.device = item.device,
.flags = uint8_t(gaze.flags & view_pose.flags & ~(flags::linear_velocity_valid | flags::angular_velocity_valid)),
});
}
+19530 -19558
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -58,7 +58,7 @@
# Keep in sync with CMakeLists.txt monado rev
rev = lib.strings.trim (builtins.readFile ./monado-rev);
# Nix will output the correct hash when it doesn't match
hash = "sha256-ueg/GDnKP4nRVepdNE3sgK8sYckZc0aaC0CQc3tuxik=";
hash = "sha256-wGqvTI/X22apc8XCN3GCGQClHfBW5xk73mZnwWvHtyI=";
};
};
+1 -1
View File
@@ -319,7 +319,7 @@ modules:
sources:
- type: git
url: https://github.com/Supreeeme/xrizer.git
tag: 01ab72809f2bd5c6494fa77fb08e4229c886da7a
tag: be664bb93eebdd82336d00230154bacc6f8b9765
- xrizer-gen-src.json
- name: wivrn-library
+2 -2
View File
@@ -243,7 +243,7 @@ msgid ""
msgstr ""
"Les valeurs élevées concentrent la qualité là où se\n"
"porte le regard, ce qui diminue la latence, réduit la\n"
"consommation d'énergé et améliore la qualité."
"consommation d'énergie et améliore la qualité."
#: client/scenes/lobby_gui.cpp:700
msgid ""
@@ -252,7 +252,7 @@ msgid ""
msgstr ""
"Les valeurs élevées concentrent la qualité au centre\n"
"de l'image, ce qui diminue la latence, réduit la\n"
"consommation d'énergé et améliore la qualité."
"consommation d'énergie et améliore la qualité."
#: client/scenes/lobby_gui.cpp:709
msgctxt "Codec"
+1 -1
View File
@@ -1 +1 @@
9dcc3e1de2f7449d9757f5db332c867b4d794fb3
723652b545a79609f9f04cb89fcbf807d9d6451a
@@ -1,7 +1,7 @@
From 0595d01bb32c959e2e64b96d5187fdb5f0f2d929 Mon Sep 17 00:00:00 2001
From 2884795b7d352e3e45348473a17660a568260d6e Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 22 Oct 2024 15:23:19 +0200
Subject: [PATCH 01/11] c/multi: early wake of compositor
Subject: [PATCH 1/8] c/multi: early wake of compositor
---
.../compositor/multi/comp_multi_compositor.c | 14 +++++++++
@@ -1,7 +1,7 @@
From bda12c93b506dd46980ca8f7e3dee6581fbdf549 Mon Sep 17 00:00:00 2001
From 8d22720c9574146f7115f5ba7ac39f3c4e4f48ae Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 8 Oct 2024 22:13:15 +0200
Subject: [PATCH 02/11] Use extern socket fd
Subject: [PATCH 2/8] Use extern socket fd
---
src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++
@@ -1,7 +1,7 @@
From a258427c4c622f838a0360c1f4c1ead3bd3e182a Mon Sep 17 00:00:00 2001
From dc8c6b0fdd002631827528b0cd831e762cf74c31 Mon Sep 17 00:00:00 2001
From: galister <85970-galister@users.noreply.gitlab.freedesktop.org>
Date: Sat, 23 Nov 2024 02:42:12 +0900
Subject: [PATCH 03/11] change environment blend mode selection logic
Subject: [PATCH 3/8] change environment blend mode selection logic
---
src/xrt/compositor/multi/comp_multi_system.c | 26 +++++++++++++-------
@@ -1,7 +1,7 @@
From 4ebef00766669bcda9f27f57ef6e10da4e66a60e Mon Sep 17 00:00:00 2001
From f4b4c07740dcc58438340171ec473570b002b379 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Sat, 15 Mar 2025 22:19:48 +0100
Subject: [PATCH 04/11] st/oxr: forward 0 refresh rate
Subject: [PATCH 4/8] st/oxr: forward 0 refresh rate
---
src/xrt/compositor/main/comp_compositor.c | 2 +-
@@ -1,7 +1,7 @@
From fb72a558ef3ccdcd9428345efcd2d2f15e474d27 Mon Sep 17 00:00:00 2001
From 73f329eaba1e46bf62ff6579e27cd39f0d9e6730 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Wed, 11 Sep 2024 22:56:29 +0200
Subject: [PATCH 05/11] Replace distortion with foveation
Subject: [PATCH 5/8] Replace distortion with foveation
---
src/xrt/compositor/main/comp_renderer.c | 6 +-
@@ -1,7 +1,7 @@
From c63be87d014aa9b67d7a8766a952a70701a629b4 Mon Sep 17 00:00:00 2001
From 9d1294834f49fc90ea22f5d841d7c0e5c0c1045d Mon Sep 17 00:00:00 2001
From: no name <git-am@invalid>
Date: Sun, 28 Sep 2025 11:33:10 +0200
Subject: [PATCH 06/11] d/steamvr_lh: prevent crash on vive pro2/WiVRn
Subject: [PATCH 6/8] d/steamvr_lh: prevent crash on vive pro2/WiVRn
---
src/xrt/drivers/steamvr_lh/steamvr_lh.cpp | 2 +-
@@ -1,7 +1,7 @@
From ccd1bef8ef971f29bf521abd74b9ebc97cb689fb Mon Sep 17 00:00:00 2001
From b9af535cf229acdbf7f1b534e9804c1b4e3fa3e1 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Fri, 7 Nov 2025 20:41:16 -0600
Subject: [PATCH 07/11] st/oxr: push XrEventDataInteractionProfileChanged when
Subject: [PATCH 7/8] st/oxr: push XrEventDataInteractionProfileChanged when
profile changes to NULL
---
@@ -9,7 +9,7 @@ Subject: [PATCH 07/11] st/oxr: push XrEventDataInteractionProfileChanged when
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c
index 388a37d9d..8e3bd9513 100644
index df2b479eb..c4b36ba81 100644
--- a/src/xrt/state_trackers/oxr/oxr_input.c
+++ b/src/xrt/state_trackers/oxr/oxr_input.c
@@ -1881,26 +1881,21 @@ oxr_session_update_action_bindings(struct oxr_logger *log, struct oxr_session *s
@@ -1,7 +1,7 @@
From 671ac1619a8986ef95cdb2dc3ca4c9db79930585 Mon Sep 17 00:00:00 2001
From 02206ede3aae832be5024263a805cafee2264080 Mon Sep 17 00:00:00 2001
From: no name <git-am@invalid>
Date: Thu, 15 Jan 2026 12:13:06 +0100
Subject: [PATCH 11/11] Don't get pose data for fast path
Subject: [PATCH 8/8] Don't get pose data for fast path
---
src/xrt/compositor/main/comp_renderer.c | 17 +++++++++--------
@@ -1,25 +0,0 @@
From b0e8426914c2b3bec366dbeaccce7db0260fa252 Mon Sep 17 00:00:00 2001
From: rcelyte <rcelyte@battletrains.org>
Date: Mon, 8 Dec 2025 19:29:28 +0000
Subject: [PATCH 08/11] d/solarxr: Fix flatpak socket path
---
src/xrt/drivers/solarxr/solarxr_ipc_socket.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
index d50d30310..8a958ad8c 100644
--- a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
+++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
@@ -129,7 +129,7 @@ solarxr_ipc_socket_find(const enum u_logging_level log_level, const char filenam
}
// try path used by SlimeVR flatpak
- static const char flatpak_runtime_dir[] = "app/" SLIMEVR_IDENTIFIER "/";
+ static const char flatpak_runtime_dir[] = ".flatpak/" SLIMEVR_IDENTIFIER "/xdg-run/";
if (sizeof(addr.sun_path) - 1 - filename_len - runtime_dir_len >= sizeof(flatpak_runtime_dir) - 1) {
memcpy(&addr.sun_path[runtime_dir_len], flatpak_runtime_dir, sizeof(flatpak_runtime_dir) - 1);
memcpy(&addr.sun_path[runtime_dir_len + (sizeof(flatpak_runtime_dir) - 1)], filename, filename_len + 1);
--
2.53.0
@@ -1,526 +0,0 @@
From b975312f8c05fc12cefe31af791d3db3bc34ac3c Mon Sep 17 00:00:00 2001
From: rcelyte <rcelyte@battletrains.org>
Date: Fri, 14 Nov 2025 19:48:59 +0000
Subject: [PATCH 09/11] d/solarxr: Sync at fixed rate This improves tracking
latency by allowing SlimeVR to synchronize updates with its processing loop.
---
src/xrt/drivers/solarxr/protocol.h | 1 +
src/xrt/drivers/solarxr/solarxr_device.c | 429 ++++++++++++-----------
2 files changed, 223 insertions(+), 207 deletions(-)
diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h
index fbdc36081..35c1dd917 100644
--- a/src/xrt/drivers/solarxr/protocol.h
+++ b/src/xrt/drivers/solarxr/protocol.h
@@ -150,6 +150,7 @@ struct solarxr_data_feed_update
enum solarxr_data_feed_message_type
{
SOLARXR_DATA_FEED_MESSAGE_POLL_DATA_FEED = 1,
+ SOLARXR_DATA_FEED_MESSAGE_START_DATA_FEED = 2,
SOLARXR_DATA_FEED_MESSAGE_DATA_FEED_UPDATE = 3,
};
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index ec5444b2a..29c0f9716 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -24,8 +24,8 @@
DEBUG_GET_ONCE_LOG_OPTION(solarxr_log, "SOLARXR_LOG", U_LOGGING_INFO)
DEBUG_GET_ONCE_BOOL_OPTION(solarxr_raw_trackers, "SOLARXR_RAW_TRACKERS", false)
-DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_delay_ms, "SOLARXR_SYNC_DELAY_MS", 4)
-DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_timeout_ms, "SOLARXR_SYNC_TIMEOUT_MS", 50)
+DEBUG_GET_ONCE_NUM_OPTION(solarxr_startup_timeout_ms, "SOLARXR_STARTUP_TIMEOUT_MS", 4000)
+DEBUG_GET_ONCE_NUM_OPTION(solarxr_sync_period_ms, "SOLARXR_SYNC_PERIOD_MS", 1)
struct solarxr_device;
struct solarxr_generic_tracker
@@ -43,7 +43,6 @@ struct solarxr_device
struct xrt_device base;
struct os_thread thread;
struct solarxr_ipc_socket socket;
- _Atomic(timepoint_ns) next_sync;
struct os_mutex mutex;
_Atomic(timepoint_ns) timestamp;
_Atomic(uint64_t) enabled_bones;
@@ -104,183 +103,6 @@ solarxr_tracker_id_to_wchar(struct solarxr_tracker_id id)
return le32toh(out);
}
-static void
-solarxr_device_sync(struct solarxr_device *const device)
-{
- const timepoint_ns time = os_monotonic_get_ns(), next_sync = atomic_exchange(&device->next_sync, INT64_MAX);
- if (time <= next_sync) {
- atomic_store(&device->next_sync, next_sync);
- return;
- }
-
- struct
- {
- uint8_t head[sizeof(struct solarxr_ipc_message)];
- struct poll_packet
- {
- uint32_t _root;
- uint16_t _table_shared[3];
- struct
- { // table MessageBundle
- int32_t _table;
- uint32_t data_feed_msgs; // vector*
- } bundle;
- struct
- { // vector<table DataFeedMessageHeader>
- uint32_t length;
- uint32_t values[1]; // table*
- } data_feed_msgs;
- uint16_t _table_data_feed_msgs_0[4];
- struct
- { // table DataFeedMessageHeader
- int32_t _table;
- uint32_t message; // table*
- uint8_t message_type; // enum DataFeedMessage
- uint8_t _pad[3];
- } data_feed_msgs_0;
- struct
- { // table PollDataFeed
- int32_t _table;
- uint32_t config; // table*
- } message;
- uint16_t _table_config[6];
- struct
- { // table DataFeedConfig
- int32_t _table;
- uint32_t trackers_mask; // table*
- bool bone_mask;
- uint8_t _pad[3];
- } config;
- struct
- { // table DeviceDataMask
- int32_t _table;
- uint32_t tracker_data; // table*
- } data_mask;
- uint16_t _table_synthetic_trackers_mask[10];
- struct
- { // table TrackerDataMask
- int32_t _table;
- bool rotation, position, raw_angular_velocity, linear_acceleration;
- } synthetic_trackers_mask;
- } body;
- } const poll_packet =
- {
- .body =
- {
- ._root = htole32(offsetof(struct poll_packet, bundle)),
- ._table_shared =
- {
- htole16(sizeof(poll_packet.body._table_shared)),
- htole16(8),
- htole16(4),
- },
- .bundle =
- {
- ._table = htole32(offsetof(struct poll_packet, bundle) -
- offsetof(struct poll_packet, _table_shared)),
- .data_feed_msgs = htole32(offsetof(struct poll_packet, data_feed_msgs) -
- offsetof(struct poll_packet, bundle.data_feed_msgs)),
- },
- .data_feed_msgs =
- {
- .length = htole32(ARRAY_SIZE(poll_packet.body.data_feed_msgs.values)),
- .values = {htole32(offsetof(struct poll_packet, data_feed_msgs_0) -
- offsetof(struct poll_packet, data_feed_msgs.values[0]))},
- },
- ._table_data_feed_msgs_0 =
- {
- htole16(sizeof(poll_packet.body._table_data_feed_msgs_0)),
- htole16(sizeof(poll_packet.body.data_feed_msgs_0) -
- sizeof(poll_packet.body.data_feed_msgs_0._pad)),
- htole16(offsetof(struct poll_packet, data_feed_msgs_0.message_type) -
- offsetof(struct poll_packet, data_feed_msgs_0)),
- htole16(offsetof(struct poll_packet, data_feed_msgs_0.message) -
- offsetof(struct poll_packet, data_feed_msgs_0)),
- },
- .data_feed_msgs_0 =
- {
- ._table = htole32(offsetof(struct poll_packet, data_feed_msgs_0) -
- offsetof(struct poll_packet, _table_data_feed_msgs_0)),
- .message = htole32(offsetof(struct poll_packet, message) -
- offsetof(struct poll_packet, data_feed_msgs_0.message)),
- .message_type = 1, // DataFeedMessage::PollDataFeed
- },
- .message =
- {
- ._table = htole32(offsetof(struct poll_packet, message) -
- offsetof(struct poll_packet, _table_shared)),
- .config = htole32(offsetof(struct poll_packet, config) -
- offsetof(struct poll_packet, message.config)),
- },
- ._table_config =
- {
- htole16(sizeof(poll_packet.body._table_config)),
- htole16(sizeof(poll_packet.body.config) - sizeof(poll_packet.body.config._pad)),
- 0,
- htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) *
- (offsetof(struct poll_packet, config.trackers_mask) -
- offsetof(struct poll_packet, config))),
- htole16((device->use_trackers && !debug_get_bool_option_solarxr_raw_trackers()) *
- (offsetof(struct poll_packet, config.trackers_mask) -
- offsetof(struct poll_packet, config))),
- htole16(offsetof(struct poll_packet, config.bone_mask) -
- offsetof(struct poll_packet, config)),
- },
- .config =
- {
- ._table = htole32(offsetof(struct poll_packet, config) -
- offsetof(struct poll_packet, _table_config)),
- .trackers_mask = htole32((debug_get_bool_option_solarxr_raw_trackers()
- ? offsetof(struct poll_packet, data_mask)
- : offsetof(struct poll_packet, synthetic_trackers_mask)) -
- offsetof(struct poll_packet, config.trackers_mask)),
- .bone_mask = true,
- },
- .data_mask =
- {
- ._table = htole32(offsetof(struct poll_packet, data_mask) -
- offsetof(struct poll_packet, _table_shared)),
- .tracker_data = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) -
- offsetof(struct poll_packet, data_mask.tracker_data)),
- },
- ._table_synthetic_trackers_mask =
- {
- htole16(sizeof(poll_packet.body._table_synthetic_trackers_mask)),
- htole16(sizeof(poll_packet.body.synthetic_trackers_mask)),
- 0,
- 0,
- htole16(offsetof(struct poll_packet, synthetic_trackers_mask.rotation) -
- offsetof(struct poll_packet, synthetic_trackers_mask)),
- htole16(offsetof(struct poll_packet, synthetic_trackers_mask.position) -
- offsetof(struct poll_packet, synthetic_trackers_mask)),
- htole16(offsetof(struct poll_packet, synthetic_trackers_mask.raw_angular_velocity) -
- offsetof(struct poll_packet, synthetic_trackers_mask)),
- 0,
- 0,
- htole16(offsetof(struct poll_packet, synthetic_trackers_mask.linear_acceleration) -
- offsetof(struct poll_packet, synthetic_trackers_mask)),
- },
- .synthetic_trackers_mask =
- {
- ._table = htole32(offsetof(struct poll_packet, synthetic_trackers_mask) -
- offsetof(struct poll_packet, _table_synthetic_trackers_mask)),
- .rotation = true,
- .position = true,
- .raw_angular_velocity = true,
- .linear_acceleration = true,
- },
- },
- };
-
- solarxr_ipc_socket_send_raw(
- &device->socket, (const uint8_t *)&poll_packet,
- solarxr_ipc_message_inline((uint8_t *)&poll_packet,
- device->use_trackers
- ? sizeof(poll_packet)
- : sizeof(poll_packet.head) + offsetof(struct poll_packet, data_mask)));
- atomic_store(&device->next_sync, time + debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS);
-}
-
static xrt_result_t
solarxr_device_update_inputs(struct xrt_device *const xdev)
{
@@ -435,7 +257,6 @@ solarxr_device_get_body_joints(struct xrt_device *const xdev,
struct solarxr_device *const device = solarxr_device(xdev);
assert(device != NULL);
- solarxr_device_sync(device);
os_mutex_lock(&device->mutex);
@@ -530,23 +351,208 @@ solarxr_device_handle_trackers(struct solarxr_device *const device,
}
}
-static struct span
-solarxr_device_receive_blocking(struct solarxr_device *const device)
-{
- do {
- const uint32_t buffer_len = solarxr_ipc_socket_receive(&device->socket);
- if (buffer_len != 0) {
- return (struct span){buffer_len, device->socket.buffer};
- }
- } while (solarxr_ipc_socket_wait_timeout(&device->socket, -1));
- return (struct span){0};
-}
-
static void *
solarxr_network_thread(void *const ptr)
{
struct solarxr_device *const device = (struct solarxr_device *)ptr;
- for (struct span buffer; (buffer = solarxr_device_receive_blocking(device)).length != 0;) {
+
+ {
+ struct
+ {
+ uint8_t head[sizeof(struct solarxr_ipc_message)];
+ struct start_packet
+ {
+ uint32_t _root;
+ uint16_t _table_shared[3];
+ struct
+ { // table MessageBundle
+ int32_t _table;
+ uint32_t data_feed_msgs; // vector*
+ } bundle;
+ struct
+ { // vector<table DataFeedMessageHeader>
+ uint32_t length;
+ uint32_t values[1]; // table*
+ } data_feed_msgs;
+ uint16_t _table_data_feed_msgs_0[4];
+ struct
+ { // table DataFeedMessageHeader
+ int32_t _table;
+ uint32_t message; // table*
+ uint8_t message_type; // enum DataFeedMessage
+ uint8_t _pad[3];
+ } data_feed_msgs_0;
+ struct
+ { // table StartDataFeed
+ int32_t _table;
+ uint32_t configs; // vector*
+ } message;
+ struct
+ { // vector<table DataFeedConfig>
+ uint32_t length;
+ uint32_t values[1]; // table*
+ } configs;
+ uint16_t _table_configs_0[6];
+ struct
+ { // table DataFeedConfig
+ int32_t _table;
+ uint32_t trackers_mask; // table*
+ uint16_t minimum_time_since_last;
+ bool bone_mask;
+ uint8_t _pad;
+ } configs_0;
+ struct
+ { // table DeviceDataMask
+ int32_t _table;
+ uint32_t tracker_data; // table*
+ } data_mask;
+ uint16_t _table_synthetic_trackers_mask[10];
+ struct
+ { // table TrackerDataMask
+ int32_t _table;
+ bool rotation, position, raw_angular_velocity, linear_acceleration;
+ } synthetic_trackers_mask;
+ } body;
+ } const start_packet =
+ {
+ .body =
+ {
+ ._root = htole32(offsetof(struct start_packet, bundle)),
+ ._table_shared =
+ {
+ htole16(sizeof(start_packet.body._table_shared)),
+ htole16(8),
+ htole16(4),
+ },
+ .bundle =
+ {
+ ._table = htole32(offsetof(struct start_packet, bundle) -
+ offsetof(struct start_packet, _table_shared)),
+ .data_feed_msgs = htole32(offsetof(struct start_packet, data_feed_msgs) -
+ offsetof(struct start_packet, bundle.data_feed_msgs)),
+ },
+ .data_feed_msgs =
+ {
+ .length = htole32(ARRAY_SIZE(start_packet.body.data_feed_msgs.values)),
+ .values = {htole32(offsetof(struct start_packet, data_feed_msgs_0) -
+ offsetof(struct start_packet, data_feed_msgs.values[0]))},
+ },
+ ._table_data_feed_msgs_0 =
+ {
+ htole16(sizeof(start_packet.body._table_data_feed_msgs_0)),
+ htole16(sizeof(start_packet.body.data_feed_msgs_0) -
+ sizeof(start_packet.body.data_feed_msgs_0._pad)),
+ htole16(offsetof(struct start_packet, data_feed_msgs_0.message_type) -
+ offsetof(struct start_packet, data_feed_msgs_0)),
+ htole16(offsetof(struct start_packet, data_feed_msgs_0.message) -
+ offsetof(struct start_packet, data_feed_msgs_0)),
+ },
+ .data_feed_msgs_0 =
+ {
+ ._table = htole32(offsetof(struct start_packet, data_feed_msgs_0) -
+ offsetof(struct start_packet, _table_data_feed_msgs_0)),
+ .message = htole32(offsetof(struct start_packet, message) -
+ offsetof(struct start_packet, data_feed_msgs_0.message)),
+ .message_type = SOLARXR_DATA_FEED_MESSAGE_START_DATA_FEED,
+ },
+ .message =
+ {
+ ._table = htole32(offsetof(struct start_packet, message) -
+ offsetof(struct start_packet, _table_shared)),
+ .configs = htole32(offsetof(struct start_packet, configs) -
+ offsetof(struct start_packet, message.configs)),
+ },
+ .configs =
+ {
+ .length = htole32(ARRAY_SIZE(start_packet.body.configs.values)),
+ .values = {htole32(offsetof(struct start_packet, configs_0) -
+ offsetof(struct start_packet, configs.values[0]))},
+ },
+ ._table_configs_0 =
+ {
+ htole16(sizeof(start_packet.body._table_configs_0)),
+ htole16(sizeof(start_packet.body.configs_0) -
+ sizeof(start_packet.body.configs_0._pad)),
+ htole16(offsetof(struct start_packet, configs_0.minimum_time_since_last) -
+ offsetof(struct start_packet, configs_0)),
+ htole16((device->use_trackers && debug_get_bool_option_solarxr_raw_trackers()) *
+ (offsetof(struct start_packet, configs_0.trackers_mask) -
+ offsetof(struct start_packet, configs_0))),
+ htole16((device->use_trackers &&
+ !debug_get_bool_option_solarxr_raw_trackers()) *
+ (offsetof(struct start_packet, configs_0.trackers_mask) -
+ offsetof(struct start_packet, configs_0))),
+ htole16(offsetof(struct start_packet, configs_0.bone_mask) -
+ offsetof(struct start_packet, configs_0)),
+ },
+ .configs_0 =
+ {
+ ._table = htole32(offsetof(struct start_packet, configs_0) -
+ offsetof(struct start_packet, _table_configs_0)),
+ .trackers_mask =
+ htole32((debug_get_bool_option_solarxr_raw_trackers()
+ ? offsetof(struct start_packet, data_mask)
+ : offsetof(struct start_packet, synthetic_trackers_mask)) -
+ offsetof(struct start_packet, configs_0.trackers_mask)),
+ .minimum_time_since_last =
+ htole16(
+ CLAMP(debug_get_num_option_solarxr_sync_period_ms(), 0, UINT16_MAX)),
+ .bone_mask = true,
+ },
+ .data_mask =
+ {
+ ._table = htole32(offsetof(struct start_packet, data_mask) -
+ offsetof(struct start_packet, _table_shared)),
+ .tracker_data = htole32(offsetof(struct start_packet, synthetic_trackers_mask) -
+ offsetof(struct start_packet, data_mask.tracker_data)),
+ },
+ ._table_synthetic_trackers_mask =
+ {
+ htole16(sizeof(start_packet.body._table_synthetic_trackers_mask)),
+ htole16(sizeof(start_packet.body.synthetic_trackers_mask)),
+ 0,
+ 0,
+ htole16(offsetof(struct start_packet, synthetic_trackers_mask.rotation) -
+ offsetof(struct start_packet, synthetic_trackers_mask)),
+ htole16(offsetof(struct start_packet, synthetic_trackers_mask.position) -
+ offsetof(struct start_packet, synthetic_trackers_mask)),
+ htole16(offsetof(struct start_packet,
+ synthetic_trackers_mask.raw_angular_velocity) -
+ offsetof(struct start_packet, synthetic_trackers_mask)),
+ 0,
+ 0,
+ htole16(offsetof(struct start_packet,
+ synthetic_trackers_mask.linear_acceleration) -
+ offsetof(struct start_packet, synthetic_trackers_mask)),
+ },
+ .synthetic_trackers_mask =
+ {
+ ._table =
+ htole32(offsetof(struct start_packet, synthetic_trackers_mask) -
+ offsetof(struct start_packet, _table_synthetic_trackers_mask)),
+ .rotation = true,
+ .position = true,
+ .raw_angular_velocity = true,
+ .linear_acceleration = true,
+ },
+ },
+ };
+
+ // start streaming
+ solarxr_ipc_socket_send_raw(
+ &device->socket, (const uint8_t *)&start_packet,
+ solarxr_ipc_message_inline((uint8_t *)&start_packet,
+ device->use_trackers ? sizeof(start_packet)
+ : sizeof(start_packet.head) +
+ offsetof(struct start_packet, data_mask)));
+ }
+
+ while (solarxr_ipc_socket_wait_timeout(&device->socket, -1)) {
+ const struct span buffer = {solarxr_ipc_socket_receive(&device->socket), device->socket.buffer};
+
+ if (buffer.length == 0) {
+ continue;
+ }
struct solarxr_message_bundle bundle;
if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length,
@@ -617,11 +623,6 @@ solarxr_network_thread(void *const ptr)
if (bundle.data_feed_msgs.length == 0) {
continue;
}
-#if 0 // for latency testing
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(), "%.3fus", (os_monotonic_get_ns() - (atomic_load(&device->next_sync) - debug_get_num_option_solarxr_sync_timeout_ms() * U_TIME_1MS_IN_NS)) / 1000.);
-#endif
- atomic_store(&device->next_sync,
- device->timestamp + debug_get_num_option_solarxr_sync_delay_ms() * U_TIME_1MS_IN_NS);
os_mutex_lock(&device->mutex);
@@ -783,7 +784,6 @@ solarxr_generic_tracker_get_tracked_pose(struct xrt_device *const xdev,
struct solarxr_device *const parent = device->parent;
if (parent != NULL && (atomic_load(&parent->enabled_bones) & (1llu << device->role)) != 0) {
- solarxr_device_sync(parent);
assert(device->history != NULL);
m_relation_history_get(device->history, at_timestamp_ns, out_relation);
result = XRT_SUCCESS;
@@ -1101,10 +1101,28 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
}
if (use_trackers) {
- const struct span buffer = solarxr_device_receive_blocking(device);
- if (buffer.length == 0) {
- U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "solarxr_ipc_socket_receive() failed");
- goto fail;
+ struct span buffer;
+ const timepoint_ns startTime = os_monotonic_get_ns();
+ for (time_duration_ns waited = 0, timeout = CLAMP(debug_get_num_option_solarxr_startup_timeout_ms(), 0,
+ INT64_MAX / U_TIME_1MS_IN_NS) *
+ U_TIME_1MS_IN_NS;
+ true;) {
+ if (!solarxr_ipc_socket_wait_timeout(&device->socket, timeout - waited)) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
+ "solarxr_ipc_socket_wait_timeout() failed");
+ goto fail;
+ }
+
+ buffer = (struct span){solarxr_ipc_socket_receive(&device->socket), device->socket.buffer};
+ if (buffer.length != 0) {
+ break;
+ }
+
+ waited = os_monotonic_get_ns() - startTime;
+ if (waited >= timeout) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "receive timeout");
+ goto fail;
+ }
}
struct solarxr_message_bundle bundle;
@@ -1231,9 +1249,6 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
goto fail;
}
- // early sync to initialize bone lengths needed by `solarxr_device_get_body_skeleton()`
- solarxr_device_sync(device);
-
assert(1 + trackers_len <= out_xdevs_cap);
out_xdevs[0] = &device->base;
for (uint32_t i = 0; i < trackers_len; ++i) {
--
2.53.0
@@ -1,876 +0,0 @@
From c39ea86d5312a3b0da0e376161df57a590a4a856 Mon Sep 17 00:00:00 2001
From: rcelyte <rcelyte@battletrains.org>
Date: Mon, 15 Sep 2025 22:46:15 +0000
Subject: [PATCH 10/11] d/solarxr: Feed device poses to server
For now this utilizes SlimeVR's separate "SteamVR Feeder" API,
waiting on https://github.com/SlimeVR/SlimeVR-Server/issues/895.
---
src/xrt/drivers/CMakeLists.txt | 2 +
src/xrt/drivers/solarxr/feeder.c | 339 ++++++++++++++++++++
src/xrt/drivers/solarxr/feeder.h | 85 +++++
src/xrt/drivers/solarxr/protocol.h | 30 +-
src/xrt/drivers/solarxr/solarxr_device.c | 161 ++++++----
src/xrt/drivers/solarxr/solarxr_interface.h | 20 ++
6 files changed, 573 insertions(+), 64 deletions(-)
create mode 100644 src/xrt/drivers/solarxr/feeder.c
create mode 100644 src/xrt/drivers/solarxr/feeder.h
diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt
index b44617e1a..040bd76b7 100644
--- a/src/xrt/drivers/CMakeLists.txt
+++ b/src/xrt/drivers/CMakeLists.txt
@@ -543,6 +543,8 @@ endif()
if(XRT_BUILD_DRIVER_SOLARXR)
add_library(
drv_solarxr STATIC
+ solarxr/feeder.c
+ solarxr/feeder.h
solarxr/protocol.c
solarxr/protocol.h
solarxr/solarxr_device.c
diff --git a/src/xrt/drivers/solarxr/feeder.c b/src/xrt/drivers/solarxr/feeder.c
new file mode 100644
index 000000000..3c79eef8b
--- /dev/null
+++ b/src/xrt/drivers/solarxr/feeder.c
@@ -0,0 +1,339 @@
+// Copyright 2025, rcelyte
+// SPDX-License-Identifier: BSL-1.0
+/*!
+ * @file
+ * @brief SolarXR pose feeder
+ * @ingroup drv_solarxr
+ */
+
+#include "feeder.h"
+#include "solarxr_ipc_message.h"
+
+#include "util/u_hashmap.h"
+#include "xrt/xrt_device.h"
+
+#include <math.h>
+#include <pb.h>
+
+static const char manufacturer[] = "Monado";
+
+#define PROTOBUF_FLOAT(v_) ((uint8_t *)&(v_))[0], ((uint8_t *)&(v_))[1], ((uint8_t *)&(v_))[2], ((uint8_t *)&(v_))[3]
+#define PROTOBUF_INT32(v_) \
+ (uint8_t)(0x80 | (uint32_t)(v_)), (uint8_t)(0x80 | (uint32_t)(v_) >> 7), \
+ (uint8_t)(0x80 | (uint32_t)(v_) >> 14), (uint8_t)(0x80 | (uint32_t)(v_) >> 21), (uint32_t)(v_) >> 28
+
+struct feeder_device
+{
+ struct feeder_device *next_to_erase;
+ struct xrt_device *xdev;
+ enum xrt_input_name input_name;
+ uint32_t id;
+ bool destroyed;
+ uint8_t last_status;
+ bool battery_charging;
+ float battery_charge;
+};
+
+bool
+feeder_add_device(struct feeder *const feeder, struct xrt_device *const xdev)
+{
+ if (xdev == NULL || !xdev->supported.orientation_tracking) {
+ return false;
+ }
+ os_mutex_lock(&feeder->mutex);
+
+ bool result = false;
+ if (!solarxr_ipc_socket_is_connected(&feeder->socket) &&
+ !solarxr_ipc_socket_connect(&feeder->socket,
+ solarxr_ipc_socket_find(feeder->socket.log_level, "SlimeVRInput"))) {
+ goto unlock;
+ }
+
+ // find a suitable pose input to report
+ enum xrt_input_name input_name = XRT_INPUT_GENERIC_TRACKER_POSE;
+ for (size_t input = 0, input_count = xdev->input_count; input < input_count; ++input) {
+ if (XRT_GET_INPUT_TYPE(xdev->inputs[input].name) == XRT_INPUT_TYPE_POSE) {
+ input_name = xdev->inputs[input].name;
+ break;
+ }
+ }
+
+ uint8_t role = 0;
+ const char *role_name = "NONE";
+ switch (xdev->device_type) {
+ case XRT_DEVICE_TYPE_HMD: {
+ role = 19;
+ role_name = "HMD";
+ } break;
+ case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: {
+ role = 14;
+ role_name = "RIGHT_CONTROLLER";
+ } break;
+ case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: {
+ role = 13;
+ role_name = "LEFT_CONTROLLER";
+ } break;
+ case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: {
+ role = 21;
+ role_name = "GENERIC_CONTROLLER";
+ } break;
+ default:;
+ }
+
+ // serialize announcement packet
+ const uint32_t serial_len = strlen(xdev->serial), name_len = strlen(xdev->str);
+ const uint8_t message_1[] = {
+ (3 << 3) | PB_WT_STRING, PROTOBUF_INT32(0), // ProtobufMessage::tracker_added
+ (1 << 3) | PB_WT_VARINT, PROTOBUF_INT32(feeder->next_id), // TrackerAdded::tracker_id
+ (4 << 3) | PB_WT_VARINT, role, // TrackerAdded::tracker_role
+ (2 << 3) | PB_WT_STRING, PROTOBUF_INT32(serial_len),
+ };
+ static_assert(sizeof(manufacturer) - 1 < 0x80, "");
+ uint8_t message_2[] = {
+ (5 << 3) | PB_WT_STRING,
+ sizeof(manufacturer) - 1,
+ // TrackerAdded::manufacturer
+ [2 + (sizeof(manufacturer) - 1)] = (3 << 3) | PB_WT_STRING,
+ PROTOBUF_INT32(name_len),
+ };
+ memcpy(&message_2[2], manufacturer, sizeof(manufacturer) - 1);
+ uint8_t packet[sizeof(struct solarxr_ipc_message) + sizeof(message_1) + sizeof(xdev->serial) +
+ sizeof(message_2) + sizeof(xdev->str)];
+ struct solarxr_ipc_message *const message = solarxr_ipc_message_start(packet, &packet[ARRAY_SIZE(packet)]);
+ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_1, sizeof(message_1));
+ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)xdev->serial,
+ serial_len); // TrackerAdded::tracker_serial
+ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], message_2, sizeof(message_2));
+ solarxr_ipc_message_write(message, &packet[ARRAY_SIZE(packet)], (const uint8_t *)xdev->str,
+ name_len); // TrackerAdded::tracker_name
+ const uint32_t packet_len = solarxr_ipc_message_end(message, &(uint8_t *){packet});
+ if (packet_len == 0) {
+ U_LOG_IFL_E(feeder->socket.log_level, "solarxr_ipc_message_end() failed");
+ assert(false);
+ goto unlock;
+ }
+ const uint8_t tracker_added[] = {
+ PROTOBUF_INT32(packet_len - sizeof(*message) - sizeof((uint8_t[]){0, PROTOBUF_INT32(0)})),
+ };
+ memcpy(&message->body[1], tracker_added, sizeof(tracker_added));
+
+ // initialize tracked state for the device
+ struct feeder_device *const device = malloc(sizeof(*device));
+ if (device == NULL) {
+ U_LOG_IFL_E(feeder->socket.log_level, "malloc() failed");
+ goto unlock;
+ }
+ *device = (struct feeder_device){
+ .xdev = xdev,
+ .input_name = input_name,
+ .id = feeder->next_id++,
+ .last_status = UINT8_MAX,
+ };
+ u_hashmap_int_insert(feeder->devices, (uint64_t)(uintptr_t)xdev, device);
+
+ // send the announcement
+ solarxr_ipc_socket_send_raw(&feeder->socket, packet, packet_len);
+ U_LOG_IFL_D(feeder->socket.log_level, " \"%s\" [id=%" PRIu32 " serial=\"%s\" role=TrackerRole::%s]",
+ xdev->str, device->id, xdev->serial, role_name);
+ result = true;
+
+unlock:
+ os_mutex_unlock(&feeder->mutex);
+ return result;
+}
+
+static void
+feeder_device_unlink(struct feeder_device *const device,
+ struct xrt_device *const xdev,
+ const enum u_logging_level log_level)
+{
+ if (device != NULL) {
+ device->destroyed = true;
+ U_LOG_IFL_D(log_level, "device \"%.*s\" removed", (unsigned)ARRAY_SIZE(xdev->str), xdev->str);
+ }
+}
+
+void
+feeder_remove_device(struct feeder *const feeder, struct xrt_device *const xdev)
+{
+ os_mutex_lock(&feeder->mutex);
+
+ struct feeder_device *device = NULL;
+ u_hashmap_int_find(feeder->devices, (uint64_t)(uintptr_t)xdev, (void **)&device);
+ feeder_device_unlink(device, xdev, feeder->socket.log_level);
+
+ os_mutex_unlock(&feeder->mutex);
+}
+
+static void
+feeder_device_remove_cb(const uint64_t key, const void *const value, void *const userptr)
+{
+ struct feeder_device *const device = (struct feeder_device *)value;
+ if (!device->destroyed) { // xdev pointer may be dangling if destroyed
+ feeder_device_unlink(device, (struct xrt_device *)(uintptr_t)key,
+ ((struct feeder *)userptr)->socket.log_level);
+ }
+}
+
+void
+feeder_clear_devices(struct feeder *const feeder)
+{
+ os_mutex_lock(&feeder->mutex);
+ u_hashmap_int_for_each(feeder->devices, feeder_device_remove_cb, feeder);
+ os_mutex_unlock(&feeder->mutex);
+}
+
+struct send_feedback_userdata
+{
+ struct feeder_device *to_erase;
+ timepoint_ns time;
+ uint8_t *packet_end, packet[0x10000];
+};
+
+static void
+feeder_device_send_feedback_cb(const uint64_t key, const void *const value, void *const userptr)
+{
+ struct feeder_device *const device = (struct feeder_device *)value;
+ struct xrt_device *const xdev = device->destroyed ? NULL : (struct xrt_device *)(uintptr_t)key;
+ struct send_feedback_userdata *const data = (struct send_feedback_userdata *)userptr;
+ uint8_t status = 0; // Status::DISCONNECTED
+ if (xdev == NULL) {
+ device->next_to_erase = data->to_erase;
+ data->to_erase = device;
+ } else {
+ // report meaningful changes in battery level
+ bool present = false, charging = false;
+ float charge = 0;
+ if (xdev->supported.battery_status &&
+ xrt_device_get_battery_status(xdev, &present, &charging, &charge) == XRT_SUCCESS &&
+ (charging != device->battery_charging || fabsf(charge - device->battery_charge) >= 1e-05)) {
+ device->battery_charging = charging;
+ device->battery_charge = charge;
+ uint8_t message[] = {
+ (5 << 3) | PB_WT_STRING, 0, // ProtobufMessage::battery
+ (1 << 3) | PB_WT_VARINT, PROTOBUF_INT32(device->id), // Battery::tracker_id
+ (2 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(charge), // Battery::battery_level
+ (3 << 3) | PB_WT_VARINT, charging, // Battery::is_charging
+ };
+ message[1] = sizeof(message) - 2;
+ solarxr_ipc_message_write_single(&data->packet_end, &data->packet[ARRAY_SIZE(data->packet)],
+ message, sizeof(message));
+ }
+
+ // report pose
+ struct xrt_space_relation relation = {0};
+ assert(xdev->get_tracked_pose != NULL);
+ if (xrt_device_get_tracked_pose(xdev, device->input_name, data->time, &relation) == XRT_SUCCESS &&
+ (relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0) {
+ uint8_t message[30 + 15] = {
+ (1 << 3) | PB_WT_STRING, 0, // ProtobufMessage::position
+ (1 << 3) | PB_WT_VARINT, PROTOBUF_INT32(device->id), // Position::tracker_id
+ (5 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.orientation.x), // Position::qx
+ (6 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.orientation.y), // Position::qy
+ (7 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.orientation.z), // Position::qz
+ (8 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.orientation.w), // Position::qw
+ (9 << 3) | PB_WT_VARINT, 3, // Position::data_source = DataSource::FULL
+ };
+ uint32_t message_len = sizeof(message);
+ if ((relation.relation_flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) != 0) {
+ const uint8_t position[15] = {
+ (2 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.position.x), // Position::x
+ (3 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.position.y), // Position::y
+ (4 << 3) | PB_WT_32BIT, PROTOBUF_FLOAT(relation.pose.position.z), // Position::z
+ };
+ memcpy(&message[sizeof(message) - sizeof(position)], position, sizeof(position));
+ } else {
+ message_len -= 15;
+ }
+ message[1] = message_len - 2;
+ solarxr_ipc_message_write_single(&data->packet_end, &data->packet[ARRAY_SIZE(data->packet)],
+ message, message_len);
+ if ((relation.relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0) {
+ status = 1; // Status::OK
+ }
+ }
+ }
+
+ // report tracking status
+ if (status != device->last_status) {
+ device->last_status = status;
+ uint8_t message[] = {
+ (4 << 3) | PB_WT_STRING, 0, // ProtobufMessage::tracker_status
+ (1 << 3) | PB_WT_VARINT, PROTOBUF_INT32(device->id), // TrackerStatus::tracker_id
+ (2 << 3) | PB_WT_VARINT, status, // TrackerStatus::status
+ };
+ message[1] = sizeof(message) - 2;
+ solarxr_ipc_message_write_single(&data->packet_end, &data->packet[ARRAY_SIZE(data->packet)], message,
+ sizeof(message));
+ }
+}
+
+void
+feeder_send_feedback(struct feeder *const feeder)
+{
+ if (!solarxr_ipc_socket_is_connected(&feeder->socket)) {
+ return;
+ }
+
+ // check for errors on the socket
+ if (!solarxr_ipc_socket_wait_timeout(&feeder->socket, 0)) {
+ U_LOG_IFL_E(feeder->socket.log_level, "connection lost");
+ solarxr_ipc_socket_destroy(&feeder->socket);
+ return;
+ }
+
+ os_mutex_lock(&feeder->mutex);
+
+ struct send_feedback_userdata data;
+ data.to_erase = NULL;
+ data.time = os_monotonic_get_ns();
+ data.packet_end = data.packet;
+ u_hashmap_int_for_each(feeder->devices, feeder_device_send_feedback_cb, &data);
+
+ // flush queued messages to socket
+ if (data.packet_end != data.packet) {
+ solarxr_ipc_socket_send_raw(&feeder->socket, data.packet, data.packet_end - data.packet);
+ }
+
+ while (data.to_erase != NULL) {
+ struct feeder_device *const entry = data.to_erase;
+ data.to_erase = entry->next_to_erase;
+ u_hashmap_int_erase(feeder->devices, (uint64_t)(uintptr_t)entry->xdev);
+ free(entry);
+ }
+
+ os_mutex_unlock(&feeder->mutex);
+}
+
+bool
+feeder_init(struct feeder *const feeder, const enum u_logging_level log_level)
+{
+ feeder->devices = NULL;
+ solarxr_ipc_socket_init(&feeder->socket, log_level);
+ if (os_mutex_init(&feeder->mutex) != 0) {
+ return false;
+ }
+ u_hashmap_int_create(&feeder->devices);
+ return true;
+}
+
+static void
+feeder_device_free_cb(const uint64_t key, const void *const value, void *const userptr)
+{
+ (void)key;
+ (void)userptr;
+ free((void *)value);
+}
+
+void
+feeder_fini(struct feeder *const feeder)
+{
+ if (feeder->devices != NULL) {
+ feeder_clear_devices(feeder);
+ feeder_send_feedback(feeder);
+ u_hashmap_int_for_each(feeder->devices, feeder_device_free_cb, NULL);
+ u_hashmap_int_destroy(&feeder->devices);
+ }
+ os_mutex_destroy(&feeder->mutex);
+ solarxr_ipc_socket_destroy(&feeder->socket);
+}
diff --git a/src/xrt/drivers/solarxr/feeder.h b/src/xrt/drivers/solarxr/feeder.h
new file mode 100644
index 000000000..cb8de6d06
--- /dev/null
+++ b/src/xrt/drivers/solarxr/feeder.h
@@ -0,0 +1,85 @@
+// Copyright 2025, rcelyte
+// SPDX-License-Identifier: BSL-1.0
+/*!
+ * @file
+ * @brief SolarXR pose feeder
+ * @ingroup drv_solarxr
+ */
+
+#pragma once
+#include "solarxr_ipc_socket.h"
+
+#include "os/os_threading.h"
+
+/*!
+ * Object that observes a collection of @ref xrt_device objects,
+ * reporting their poses and status to a SolarXR server over IPC
+ * @ingroup drv_solarxr
+ */
+struct u_hashmap_int;
+struct feeder
+{
+ struct os_mutex mutex;
+ struct solarxr_ipc_socket socket;
+ uint32_t next_id;
+ struct u_hashmap_int *devices;
+};
+
+bool
+feeder_init(struct feeder *feeder, enum u_logging_level log_level);
+
+void
+feeder_fini(struct feeder *feeder);
+
+/*!
+ * Register a device to observe and announce it to the server
+ *
+ * Holds the mutex during most of the operation.
+ *
+ * @param feeder self
+ * @param device device to register
+ *
+ * @return true on success.
+ *
+ * @public @memberof feeder
+ */
+bool
+feeder_add_device(struct feeder *feeder, struct xrt_device *xdev); // thread safe
+
+/*!
+ * Unregister a previously added device
+ *
+ * Holds the mutex during most of the operation.
+ *
+ * @param feeder self
+ * @param device device to unregister
+ *
+ * @public @memberof feeder
+ */
+void
+feeder_remove_device(struct feeder *feeder, struct xrt_device *xdev); // thread safe
+
+/*!
+ * Unregister all observed devices
+ *
+ * Holds the mutex during most of the operation.
+ *
+ * @param feeder self
+ *
+ * @public @memberof feeder
+ */
+void
+feeder_clear_devices(struct feeder *feeder); // thread safe
+
+/*!
+ * Poll all observed xdevs and
+ *
+ * Holds the mutex during most of the operation.
+ *
+ * @param feeder self
+ * @param time Timestamp used to query device poses
+ *
+ * @public @memberof feeder
+ */
+void
+feeder_send_feedback(struct feeder *feeder); // thread safe
diff --git a/src/xrt/drivers/solarxr/protocol.h b/src/xrt/drivers/solarxr/protocol.h
index 35c1dd917..b397dff41 100644
--- a/src/xrt/drivers/solarxr/protocol.h
+++ b/src/xrt/drivers/solarxr/protocol.h
@@ -89,10 +89,12 @@ struct solarxr_tracker_id
uint8_t tracker_num;
};
+typedef FLATBUFFERS_VECTOR(char) flatbuffers_vector_char_t;
+
struct solarxr_tracker_info
{ // table solarxr_protocol.data_feed.tracker.TrackerInfo
enum solarxr_body_part body_part;
- FLATBUFFERS_VECTOR(char) display_name;
+ flatbuffers_vector_char_t display_name;
};
typedef struct
@@ -120,10 +122,12 @@ typedef struct
flatbuffers_uoffset_t offset;
} solarxr_device_data_t;
+typedef FLATBUFFERS_VECTOR(solarxr_tracker_data_t) flatbuffers_vector_solarxr_tracker_data_t;
+
struct solarxr_device_data
{ // table solarxr_protocol.data_feed.device_data.DeviceData
uint8_t id;
- FLATBUFFERS_VECTOR(solarxr_tracker_data_t) trackers; // solarxr_protocol.data_feed.tracker.TrackerData[]
+ flatbuffers_vector_solarxr_tracker_data_t trackers; // solarxr_protocol.data_feed.tracker.TrackerData[]
};
typedef struct
@@ -139,12 +143,15 @@ struct solarxr_bone
struct xrt_vec3 head_position_g;
};
+typedef FLATBUFFERS_VECTOR(solarxr_device_data_t) flatbuffers_vector_solarxr_device_data_t;
+typedef FLATBUFFERS_VECTOR(solarxr_bone_t) flatbuffers_vector_solarxr_bone_t;
+
struct solarxr_data_feed_update
-{ // table solarxr_protocol.data_feed.DataFeedUpdate
- FLATBUFFERS_VECTOR(solarxr_device_data_t) devices; // solarxr_protocol.data_feed.device_data.DeviceData[]
- FLATBUFFERS_VECTOR(solarxr_tracker_data_t)
- synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[]
- FLATBUFFERS_VECTOR(solarxr_bone_t) bones; // solarxr_protocol.data_feed.Bone[]
+{ // table solarxr_protocol.data_feed.DataFeedUpdate
+ flatbuffers_vector_solarxr_device_data_t devices; // solarxr_protocol.data_feed.device_data.DeviceData[]
+ flatbuffers_vector_solarxr_tracker_data_t
+ synthetic_trackers; // solarxr_protocol.data_feed.tracker.TrackerData[]
+ flatbuffers_vector_solarxr_bone_t bones; // solarxr_protocol.data_feed.Bone[]
};
enum solarxr_data_feed_message_type
@@ -214,11 +221,14 @@ typedef struct
flatbuffers_uoffset_t offset;
} solarxr_message_bundle_t;
+typedef FLATBUFFERS_VECTOR(solarxr_data_feed_message_header_t) flatbuffers_vector_solarxr_data_feed_message_header_t;
+typedef FLATBUFFERS_VECTOR(solarxr_rpc_message_header_t) flatbuffers_vector_solarxr_rpc_message_header_t;
+
struct solarxr_message_bundle
{ // table solarxr_protocol.MessageBundle
- FLATBUFFERS_VECTOR(solarxr_data_feed_message_header_t)
- data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[]
- FLATBUFFERS_VECTOR(solarxr_rpc_message_header_t) rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[]
+ flatbuffers_vector_solarxr_data_feed_message_header_t
+ data_feed_msgs; // solarxr_protocol.data_feed.DataFeedMessageHeader[]
+ flatbuffers_vector_solarxr_rpc_message_header_t rpc_msgs; // solarxr_protocol.rpc.RpcMessageHeader[]
};
bool
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index 29c0f9716..4a65a7494 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSL-1.0
#include "solarxr_interface.h"
+#include "feeder.h"
#include "protocol.h"
#include "solarxr_ipc_message.h"
#include "solarxr_ipc_socket.h"
@@ -41,6 +42,7 @@ struct solarxr_generic_tracker
struct solarxr_device
{
struct xrt_device base;
+ struct feeder feeder;
struct os_thread thread;
struct solarxr_ipc_socket socket;
struct os_mutex mutex;
@@ -305,7 +307,7 @@ solarxr_device_handle_trackers(struct solarxr_device *const device,
for (uint32_t i = 0; i < trackers_len; ++i) {
struct solarxr_tracker_data data;
if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, &trackers[i])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(), "read_solarxr_device_data() failed");
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "read_solarxr_device_data() failed");
continue;
}
@@ -557,7 +559,7 @@ solarxr_network_thread(void *const ptr)
struct solarxr_message_bundle bundle;
if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length,
(const solarxr_message_bundle_t *)buffer.data)) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(), "read_solarxr_message_bundle() failed");
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "read_solarxr_message_bundle() failed");
continue;
}
@@ -568,7 +570,7 @@ solarxr_network_thread(void *const ptr)
struct solarxr_rpc_message_header header;
if (!read_solarxr_rpc_message_header(&header, buffer.data, buffer.length,
&bundle.rpc_msgs.data[i])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(),
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
"read_solarxr_rpc_message_header() failed");
continue;
}
@@ -624,6 +626,8 @@ solarxr_network_thread(void *const ptr)
continue;
}
+ feeder_send_feedback(&device->feeder);
+
os_mutex_lock(&device->mutex);
FLATBUFFERS_VECTOR(solarxr_bone_t) bones = {0};
@@ -631,7 +635,7 @@ solarxr_network_thread(void *const ptr)
struct solarxr_data_feed_message_header header;
if (!read_solarxr_data_feed_message_header(&header, buffer.data, buffer.length,
&bundle.data_feed_msgs.data[0])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(),
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
"read_solarxr_data_feed_message_header() failed");
continue;
}
@@ -646,7 +650,7 @@ solarxr_network_thread(void *const ptr)
if (!read_solarxr_device_data(
&device_data, buffer.data, buffer.length,
&header.message.data_feed_update.devices.data[j])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(),
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
"read_solarxr_device_data() failed");
continue;
}
@@ -672,7 +676,7 @@ solarxr_network_thread(void *const ptr)
for (size_t i = 0; i < bones.length; ++i) {
struct solarxr_bone bone;
if (!read_solarxr_bone(&bone, buffer.data, buffer.length, &bones.data[i])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(), "read_solarxr_bone() failed");
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "read_solarxr_bone() failed");
continue;
}
@@ -760,6 +764,8 @@ solarxr_device_destroy(struct xrt_device *xdev)
os_thread_destroy(&device->thread);
}
+ feeder_fini(&device->feeder);
+
for (size_t i = 0; i < ARRAY_SIZE(device->trackers); ++i) {
m_relation_history_destroy(&device->trackers[i]);
}
@@ -826,11 +832,12 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
return 0;
}
- if (out_xdevs_cap > 1 + MAX_GENERIC_TRACKERS) {
- out_xdevs_cap = 1 + MAX_GENERIC_TRACKERS;
+ struct solarxr_device *device;
+ if (out_xdevs_cap > 1 + ARRAY_SIZE(device->trackers)) {
+ out_xdevs_cap = 1 + ARRAY_SIZE(device->trackers);
}
- struct solarxr_device *const device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0);
+ device = U_DEVICE_ALLOCATE(struct solarxr_device, U_DEVICE_ALLOC_NO_FLAGS, 2, 0);
device->base.name = XRT_DEVICE_FB_BODY_TRACKING;
device->base.device_type = XRT_DEVICE_TYPE_BODY_TRACKER;
strncpy(device->base.str, "SolarXR IPC Connection", sizeof(device->base.str) - 1);
@@ -861,10 +868,11 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
memset(device->tracker_ids, 0xff, sizeof(device->tracker_ids));
uint32_t trackers_len = 0;
- struct solarxr_generic_tracker *trackers[MAX_GENERIC_TRACKERS];
+ struct solarxr_generic_tracker *trackers[ARRAY_SIZE(device->trackers)];
// `solarxr_device_destroy()` asserts unless both have attempted initialization
- if (os_mutex_init(&device->mutex) != 0) {
+ if (((int)!feeder_init(&device->feeder, debug_get_log_option_solarxr_log()) | os_mutex_init(&device->mutex)) !=
+ 0) {
goto fail;
}
@@ -1150,54 +1158,71 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
goto fail;
}
- uint32_t tracker_descs_len = 0;
- const solarxr_tracker_data_t *tracker_descs[ARRAY_SIZE(device->trackers)];
+ uint32_t tracker_datas_len = 0;
+ struct solarxr_tracker_data tracker_datas[ARRAY_SIZE(device->trackers)];
if (debug_get_bool_option_solarxr_raw_trackers()) {
- for (uint32_t i = 0; i < header.message.data_feed_update.devices.length; ++i) {
+ const flatbuffers_vector_solarxr_device_data_t devices =
+ header.message.data_feed_update.devices;
+ for (const solarxr_device_data_t *device = devices.data, *const devices_end =
+ &device[devices.length];
+ device < devices_end; ++device) {
struct solarxr_device_data device_data;
- if (!read_solarxr_device_data(&device_data, buffer.data, buffer.length,
- &header.message.data_feed_update.devices.data[i])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(),
+ if (!read_solarxr_device_data(&device_data, buffer.data, buffer.length, device)) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
"read_solarxr_device_data() failed");
continue;
}
-
- uint32_t length = device_data.trackers.length;
- if (length >= ARRAY_SIZE(tracker_descs) - tracker_descs_len) {
- length = ARRAY_SIZE(tracker_descs) - tracker_descs_len;
- header.message.data_feed_update.devices.length = i; // early exit
- }
-
- for (uint32_t j = 0; j < length; ++j) {
- tracker_descs[tracker_descs_len++] = &device_data.trackers.data[j];
+ for (const solarxr_tracker_data_t *tracker = device_data.trackers.data,
+ *const end = &tracker[device_data.trackers.length];
+ tracker < end; ++tracker) {
+ if (tracker_datas_len >= ARRAY_SIZE(tracker_datas)) {
+ device = devices_end - 1; // break outer
+ break;
+ }
+ if (!read_solarxr_tracker_data(&tracker_datas[tracker_datas_len], buffer.data,
+ buffer.length, tracker)) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
+ "read_solarxr_tracker_data() failed");
+ continue;
+ }
+ ++tracker_datas_len;
}
}
} else {
- tracker_descs_len =
- MIN(header.message.data_feed_update.synthetic_trackers.length, ARRAY_SIZE(tracker_descs));
- for (uint32_t i = 0; i < tracker_descs_len; ++i) {
- tracker_descs[i] = &header.message.data_feed_update.synthetic_trackers.data[i];
+ const flatbuffers_vector_solarxr_tracker_data_t synthetic_trackers =
+ header.message.data_feed_update.synthetic_trackers;
+ for (const solarxr_tracker_data_t *tracker = synthetic_trackers.data,
+ *const end = &tracker[synthetic_trackers.length];
+ tracker < end; ++tracker) {
+ if (tracker_datas_len >= ARRAY_SIZE(tracker_datas)) {
+ break;
+ }
+ if (!read_solarxr_tracker_data(&tracker_datas[tracker_datas_len], buffer.data,
+ buffer.length, tracker)) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
+ "read_solarxr_tracker_data() failed");
+ continue;
+ }
+ if (tracker_datas[tracker_datas_len].tracker_id.has_device_id) {
+ continue; // filter out loopback feeder devices
+ }
+ ++tracker_datas_len;
}
}
U_LOG_IFL_I(debug_get_log_option_solarxr_log(), "Enumerated %" PRIu32 " SolarXR %s trackers",
- tracker_descs_len, debug_get_bool_option_solarxr_raw_trackers() ? "physical" : "synthetic");
+ tracker_datas_len, debug_get_bool_option_solarxr_raw_trackers() ? "physical" : "synthetic");
- if (tracker_descs_len > out_xdevs_cap - 1) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(),
+ if (tracker_datas_len > out_xdevs_cap - 1) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
"Not enough xdev slots! Omitting %" PRIu32 " trackers",
- tracker_descs_len - (out_xdevs_cap - 1));
- tracker_descs_len = out_xdevs_cap - 1;
+ tracker_datas_len - (out_xdevs_cap - 1));
+ tracker_datas_len = out_xdevs_cap - 1;
}
- for (uint32_t i = 0; i < tracker_descs_len; ++i) {
- struct solarxr_tracker_data data;
- if (!read_solarxr_tracker_data(&data, buffer.data, buffer.length, tracker_descs[i])) {
- U_LOG_IFL_W(debug_get_log_option_solarxr_log(), "read_solarxr_device_data() failed");
- continue;
- }
-
- const wchar_t id = solarxr_tracker_id_to_wchar(data.tracker_id);
+ for (const struct solarxr_tracker_data *data = tracker_datas, *const end = &data[tracker_datas_len];
+ data < end; ++data) {
+ const wchar_t id = solarxr_tracker_id_to_wchar(data->tracker_id);
struct solarxr_generic_tracker *const tracker =
U_DEVICE_ALLOCATE(struct solarxr_generic_tracker, U_DEVICE_ALLOC_NO_FLAGS, 1, 0);
@@ -1219,27 +1244,27 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
tracker->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE;
tracker->role = SOLARXR_BODY_PART_NONE;
- device->tracker_ids[i] = id;
- m_relation_history_create(&device->trackers[i]);
+ assert(trackers_len < ARRAY_SIZE(trackers));
+ device->tracker_ids[trackers_len] = id;
+ m_relation_history_create(&device->trackers[trackers_len]);
tracker->parent = device;
- tracker->index = i;
- tracker->history = device->trackers[i];
- device->tracker_refs[i] = tracker;
+ tracker->index = trackers_len;
+ tracker->history = device->trackers[trackers_len];
+ device->tracker_refs[trackers_len] = tracker;
- assert(trackers_len < ARRAY_SIZE(trackers));
trackers[trackers_len++] = tracker;
- if (!data.has_info) {
+ if (!data->has_info) {
continue;
}
- if (data.info.body_part < ARRAY_SIZE(device->bones)) {
- tracker->role = data.info.body_part;
+ if (data->info.body_part < ARRAY_SIZE(device->bones)) {
+ tracker->role = data->info.body_part;
}
- if (data.info.display_name.length != 0) {
+ if (data->info.display_name.length != 0) {
snprintf(tracker->base.str, sizeof(tracker->base.str), "SolarXR Tracker \"%.*s\"",
- (unsigned)data.info.display_name.length, data.info.display_name.data);
+ (unsigned)data->info.display_name.length, data->info.display_name.data);
}
}
}
@@ -1264,3 +1289,31 @@ fail:
solarxr_device_destroy(&device->base);
return 0;
}
+
+bool
+solarxr_device_add_feeder_device(struct xrt_device *const device, struct xrt_device *const xdev)
+{
+ struct solarxr_device *const solarxr = solarxr_device(device);
+ if (solarxr == NULL || solarxr_device(xdev) != NULL || solarxr_generic_tracker(xdev) != NULL) {
+ return false;
+ }
+ return feeder_add_device(&solarxr->feeder, xdev);
+}
+
+void
+solarxr_device_remove_feeder_device(struct xrt_device *const device, struct xrt_device *const xdev)
+{
+ struct solarxr_device *const solarxr = solarxr_device(device);
+ if (solarxr != NULL) {
+ feeder_remove_device(&solarxr->feeder, xdev);
+ }
+}
+
+void
+solarxr_device_clear_feeder_devices(struct xrt_device *const device)
+{
+ struct solarxr_device *const solarxr = solarxr_device(device);
+ if (solarxr != NULL) {
+ feeder_clear_devices(&solarxr->feeder);
+ }
+}
diff --git a/src/xrt/drivers/solarxr/solarxr_interface.h b/src/xrt/drivers/solarxr/solarxr_interface.h
index c56bb15b1..209345f79 100644
--- a/src/xrt/drivers/solarxr/solarxr_interface.h
+++ b/src/xrt/drivers/solarxr/solarxr_interface.h
@@ -23,6 +23,15 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *tracking_origin,
struct xrt_device *out_xdevs[],
uint32_t out_xdevs_cap);
+bool
+solarxr_device_add_feeder_device(struct xrt_device *solarxr, struct xrt_device *xdev);
+
+void
+solarxr_device_remove_feeder_device(struct xrt_device *solarxr, struct xrt_device *xdev);
+
+void
+solarxr_device_clear_feeder_devices(struct xrt_device *solarxr);
+
static inline struct xrt_device *
solarxr_device_create(struct xrt_tracking_origin *const tracking_origin)
{
@@ -31,6 +40,17 @@ solarxr_device_create(struct xrt_tracking_origin *const tracking_origin)
return out;
}
+static inline void
+solarxr_device_set_feeder_devices(struct xrt_device *const solarxr,
+ struct xrt_device *const xdevs[],
+ const uint32_t xdev_count)
+{
+ solarxr_device_clear_feeder_devices(solarxr);
+ for (uint32_t i = 0; i < xdev_count; ++i) {
+ solarxr_device_add_feeder_device(solarxr, xdevs[i]);
+ }
+}
+
#ifdef __cplusplus
}
--
2.53.0
+11
View File
@@ -61,6 +61,7 @@ struct pipewire_device : public audio_device
std::atomic<size_t> mic_buffer_size_bytes;
audio_data mic_current;
std::unique_ptr<pw_stream, deleter> microphone;
std::atomic<std::underlying_type_t<pw_stream_state>> mic_state{PW_STREAM_STATE_UNCONNECTED};
pw_stream_events mic_events{
.version = PW_VERSION_STREAM_EVENTS,
.state_changed = &pipewire_device::mic_state_changed,
@@ -78,6 +79,7 @@ struct pipewire_device : public audio_device
static void mic_state_changed(void * self_v, pw_stream_state old, pw_stream_state state, const char * error);
void process_mic_data(wivrn::audio_data &&) override;
void on_connect() override;
~pipewire_device()
{
@@ -342,6 +344,11 @@ void pipewire_device::mic_process(void * self_v)
void pipewire_device::mic_state_changed(void * self_v, pw_stream_state old, pw_stream_state state, const char * error)
{
auto self = (pipewire_device *)self_v;
self->mic_state = state;
if (error)
U_LOG_I("Microphone state changed from %s to %s (error: %s)", magic_enum::enum_name(old).data(), magic_enum::enum_name(state).data(), error);
else
U_LOG_I("Microphone state changed from %s to %s", magic_enum::enum_name(old).data(), magic_enum::enum_name(state).data());
switch (state)
{
case PW_STREAM_STATE_ERROR:
@@ -408,6 +415,10 @@ void pipewire_device::process_mic_data(wivrn::audio_data && sample)
if (mic_samples.write(std::move(sample)))
mic_buffer_size_bytes += size;
}
void pipewire_device::on_connect()
{
session.send_control(to_headset::feature_control{to_headset::feature_control::microphone, mic_state == PW_STREAM_STATE_STREAMING});
}
std::unique_ptr<audio_device> create_pipewire_handle(
const std::string & source_name,
+5
View File
@@ -404,6 +404,11 @@ struct pulse_device : public audio_device
mic_buffer.push(std::move(mic_data));
}
void on_connect() override
{
session.send_control(to_headset::feature_control{to_headset::feature_control::microphone, true});
}
pulse_device(
const std::string & source_name,
const std::string & source_description,
+1
View File
@@ -36,6 +36,7 @@ struct audio_device
virtual wivrn::to_headset::audio_stream_description description() const = 0;
virtual void process_mic_data(wivrn::audio_data &&) = 0;
virtual void on_connect() = 0;
static std::unique_ptr<audio_device> create(
const std::string & source_name,
+1 -1
View File
@@ -40,7 +40,7 @@ class view_list
{
pose_list head_poses{device_id::HEAD};
std::mutex mutex;
XrViewStateFlags flags;
XrViewStateFlags flags{};
std::array<xrt_pose, 2> poses;
std::array<xrt_fov, 2> fovs;
+6
View File
@@ -146,7 +146,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
get_info(),
*this);
if (audio_handle)
{
send_control(audio_handle->description());
audio_handle->on_connect();
}
}
catch (const std::exception & e)
{
@@ -1128,7 +1131,10 @@ void wivrn_session::reconnect(std::stop_token stop)
comp_target->reset_encoders();
}
if (audio_handle)
{
send_control(audio_handle->description());
audio_handle->on_connect();
}
event.state.visible = true;
event.state.focused = true;
+13 -8
View File
@@ -292,10 +292,12 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
output_buffer_size = align(output_buffer_size, video_caps.minBitstreamBufferSizeAlignment);
item.output_buffer = buffer_allocation(
vk.device,
{.pNext = &video_profile_list,
.size = output_buffer_size,
.usage = vk::BufferUsageFlagBits::eVideoEncodeDstKHR | vk::BufferUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive},
{
.pNext = &video_profile_list,
.size = output_buffer_size,
.usage = vk::BufferUsageFlagBits::eVideoEncodeDstKHR | vk::BufferUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive,
},
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
@@ -304,14 +306,17 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
if (not(item.output_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
U_LOG_D("Using staging buffer for vulkan encode output");
item.host_buffer = buffer_allocation(
vk.device,
{.size = output_buffer_size,
.usage = vk::BufferUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive},
{
.size = output_buffer_size,
.usage = vk::BufferUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
},
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
},
"vulkan encode host buffer");
}