Compare commits

...
21 changed files with 249 additions and 68 deletions
+7 -3
View File
@@ -279,7 +279,6 @@ jobs:
VERSION_CODE=$(( $VERSION_CODE + 1 ))
fi
CSS=images/wivrn-release.css
APPNAME=WiVRn
else
VERSION_CODE=1
@@ -287,15 +286,20 @@ jobs:
if [ ${{ github.ref_type }} = 'tag' ]
then
SUFFIX=".github"
CSS=images/wivrn-release.css
APPNAME="WiVRn"
else
SUFFIX=".github.testing"
CSS=images/wivrn-nightly.css
APPNAME="WiVRn Testing"
fi
fi
if [ ${{ github.ref_type }} = 'tag' ]
then
CSS=images/wivrn-release.css
else
CSS=images/wivrn-nightly.css
fi
echo Setting version $VERSION and version code $VERSION_CODE in manifest
echo Using stylesheet $CSS and name $APPNAME
+2 -1
View File
@@ -207,7 +207,8 @@ static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT
for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
{
poses[i] = {
.pose = (*joints)[i].first.pose,
.position = (*joints)[i].first.pose.position,
.orientation = pack((*joints)[i].first.pose.orientation),
.linear_velocity = (*joints)[i].second.linearVelocity,
.angular_velocity = (*joints)[i].second.angularVelocity,
.radius = uint16_t((*joints)[i].first.radius * 10'000),
+105
View File
@@ -0,0 +1,105 @@
/*
* WiVRn VR streaming
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <openxr/openxr.h>
struct packed_quaternion
{
uint32_t value;
static packed_quaternion from_quaternion(const XrQuaternionf & q)
{
assert(std::abs(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z - 1) < 0.01);
float abs_w = std::abs(q.w);
float abs_x = std::abs(q.x);
float abs_y = std::abs(q.y);
float abs_z = std::abs(q.z);
const float scale_factor = 511 * std::sqrt(2);
if (abs_x > std::max({abs_y, abs_z, abs_w}))
{
uint32_t q1 = q.y * std::copysign(scale_factor, q.x) + 512.5;
uint32_t q2 = q.z * std::copysign(scale_factor, q.x) + 512.5;
uint32_t q3 = q.w * std::copysign(scale_factor, q.x) + 512.5;
return {(0 << 30) | (q1 << 20) | (q2 << 10) | q3};
}
else if (abs_y > std::max({abs_x, abs_z, abs_w}))
{
uint32_t q1 = q.x * std::copysign(scale_factor, q.y) + 512.5;
uint32_t q2 = q.z * std::copysign(scale_factor, q.y) + 512.5;
uint32_t q3 = q.w * std::copysign(scale_factor, q.y) + 512.5;
return {(1 << 30) | (q1 << 20) | (q2 << 10) | q3};
}
else if (abs_z > std::max({abs_x, abs_y, abs_w}))
{
uint32_t q1 = q.x * std::copysign(scale_factor, q.z) + 512.5;
uint32_t q2 = q.y * std::copysign(scale_factor, q.z) + 512.5;
uint32_t q3 = q.w * std::copysign(scale_factor, q.z) + 512.5;
return {(2 << 30) | (q1 << 20) | (q2 << 10) | q3};
}
else
{
uint32_t q1 = q.x * std::copysign(scale_factor, q.w) + 512.5;
uint32_t q2 = q.y * std::copysign(scale_factor, q.w) + 512.5;
uint32_t q3 = q.z * std::copysign(scale_factor, q.w) + 512.5;
return {(3 << 30) | (q1 << 20) | (q2 << 10) | q3};
}
}
operator XrQuaternionf() const
{
const float scale_factor = 1. / (511 * std::sqrt(2));
float q1 = (int((value >> 20) & 0x3ff) - 512) * scale_factor;
float q2 = (int((value >> 10) & 0x3ff) - 512) * scale_factor;
float q3 = (int((value >> 0) & 0x3ff) - 512) * scale_factor;
float q0 = std::sqrt(1 - q1 * q1 - q2 * q2 - q3 * q3);
switch (value >> 30)
{
case 0:
return {q0, q1, q2, q3};
case 1:
return {q1, q0, q2, q3};
case 2:
return {q1, q2, q0, q3};
case 3:
return {q1, q2, q3, q0};
}
__builtin_unreachable();
}
};
inline packed_quaternion pack(const XrQuaternionf & q)
{
return packed_quaternion::from_quaternion(q);
}
+3 -1
View File
@@ -32,6 +32,7 @@
#include <vulkan/vulkan_core.h>
#include <openxr/openxr.h>
#include "packed_quaternion.h"
#include "smp.h"
#include "wivrn_serialization_types.h"
@@ -372,7 +373,8 @@ struct hand_tracking
};
struct pose
{
XrPosef pose;
XrVector3f position;
packed_quaternion orientation;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
// In order to avoid packet fragmentation
+15 -15
View File
@@ -308,29 +308,29 @@ wivrn::deserialization_packet wivrn::UDP::receive_raw()
static const size_t message_size = 2048;
static const size_t num_messages = 20;
if ((not buffer) or buffer.use_count() > 1)
{
#if defined(__cpp_lib_smart_ptr_for_overwrite) && __cpp_lib_smart_ptr_for_overwrite >= 202002L
buffer = std::make_shared_for_overwrite<uint8_t[]>(message_size * num_messages);
buffer = std::make_shared_for_overwrite<uint8_t[]>(message_size * num_messages);
#else
buffer.reset(new uint8_t[message_size * num_messages]);
buffer.reset(new uint8_t[message_size * num_messages]);
#endif
std::vector<iovec> iovecs;
std::vector<mmsghdr> mmsgs;
iovecs.reserve(num_messages);
mmsgs.reserve(num_messages);
}
std::array<iovec, num_messages> iovecs;
std::array<mmsghdr, num_messages> mmsgs;
for (size_t i = 0; i < num_messages; ++i)
{
iovecs.push_back({
iovecs[i] = {
.iov_base = buffer.get() + message_size * i,
.iov_len = message_size,
});
};
mmsgs.push_back(
{
.msg_hdr = {
.msg_iov = &iovecs.back(),
.msg_iovlen = 1,
},
});
mmsgs[i] = {
.msg_hdr = {
.msg_iov = &iovecs[i],
.msg_iovlen = 1,
},
};
}
int received = recvmmsg(fd, mmsgs.data(), num_messages, MSG_DONTWAIT, nullptr);
-17
View File
@@ -256,23 +256,6 @@ modules:
cleanup:
- '*'
- name: libnotify
buildsystem: meson
config-opts:
- -Dtests=false
- -Dintrospection=disabled
- -Dman=false
- -Dgtk_doc=false
- -Ddocbook_docs=disabled
sources:
- type: archive
url: https://download.gnome.org/sources/libnotify/0.8/libnotify-0.8.8.tar.xz
sha256: 23420ef619dc2cb5aebad613f4823a2fa41c07e5a1d05628d40f6ec4b35bfddd
x-checker-data:
type: gnome
name: libnotify
stable-only: true
- name: qcoro
buildsystem: cmake-ninja
config-opts:
+3 -3
View File
@@ -380,7 +380,7 @@ void pipewire_device::process_mic_data(wivrn::audio_data && sample)
mic_buffer_size_bytes += size;
}
std::shared_ptr<audio_device> create_pipewire_handle(
std::unique_ptr<audio_device> create_pipewire_handle(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
@@ -390,7 +390,7 @@ std::shared_ptr<audio_device> create_pipewire_handle(
{
try
{
return std::make_shared<pipewire_device>(
return std::make_unique<pipewire_device>(
source_name, source_description, sink_name, sink_description, info, session);
}
catch (std::exception & e)
@@ -399,4 +399,4 @@ std::shared_ptr<audio_device> create_pipewire_handle(
return nullptr;
}
}
} // namespace wivrn
} // namespace wivrn
+1 -1
View File
@@ -23,7 +23,7 @@
namespace wivrn
{
std::shared_ptr<audio_device> create_pipewire_handle(
std::unique_ptr<audio_device> create_pipewire_handle(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
+2 -2
View File
@@ -445,7 +445,7 @@ struct pulse_device : public audio_device
}
};
std::shared_ptr<audio_device> create_pulse_handle(
std::unique_ptr<audio_device> create_pulse_handle(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
@@ -455,7 +455,7 @@ std::shared_ptr<audio_device> create_pulse_handle(
{
try
{
return std::make_shared<pulse_device>(
return std::make_unique<pulse_device>(
source_name, source_description, sink_name, sink_description, info, session);
}
catch (std::exception & e)
+1 -1
View File
@@ -23,7 +23,7 @@
namespace wivrn
{
std::shared_ptr<audio_device> create_pulse_handle(
std::unique_ptr<audio_device> create_pulse_handle(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
+1 -1
View File
@@ -30,7 +30,7 @@
#include "audio_pipewire.h"
#endif
std::shared_ptr<wivrn::audio_device> wivrn::audio_device::create(
std::unique_ptr<wivrn::audio_device> wivrn::audio_device::create(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
+1 -1
View File
@@ -37,7 +37,7 @@ struct audio_device
virtual void process_mic_data(wivrn::audio_data &&) = 0;
static std::shared_ptr<audio_device> create(
static std::unique_ptr<audio_device> create(
const std::string & source_name,
const std::string & source_description,
const std::string & sink_name,
+4 -1
View File
@@ -80,7 +80,10 @@ static xrt_space_relation to_relation(const from_headset::hand_tracking::pose &
{
return {
.relation_flags = cast_flags(pose.flags),
.pose = xrt_cast(pose.pose),
.pose = xrt_cast(XrPosef{
.orientation = pose.orientation,
.position = pose.position,
}),
.linear_velocity = xrt_cast(pose.linear_velocity),
.angular_velocity = xrt_cast(pose.angular_velocity),
};
+24 -1
View File
@@ -34,7 +34,30 @@ xrt_space_relation pose_list::interpolate(const xrt_space_relation & a, const xr
{
xrt_space_relation result;
xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags);
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), const_cast<xrt_space_relation *>(&b), t, flags, &result);
if (math_quat_dot(&a.pose.orientation, &b.pose.orientation) > 0)
{
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), const_cast<xrt_space_relation *>(&b), t, flags, &result);
}
else
{
xrt_space_relation b2{
.relation_flags = b.relation_flags,
.pose = {
.orientation = {
.x = -b.pose.orientation.x,
.y = -b.pose.orientation.y,
.z = -b.pose.orientation.z,
.w = -b.pose.orientation.w,
},
.position = b.pose.position,
},
.linear_velocity = b.linear_velocity,
.angular_velocity = b.angular_velocity,
};
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), &b2, t, flags, &result);
}
return result;
}
+1 -1
View File
@@ -137,7 +137,7 @@ class wivrn_session : public xrt_system_devices
std::mutex csv_mutex;
std::ofstream feedback_csv;
std::shared_ptr<audio_device> audio_handle;
std::unique_ptr<audio_device> audio_handle;
// run-time editable settings
thread_safe<from_headset::settings_changed> settings;
+1 -1
View File
@@ -513,7 +513,7 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
[&](const wivrn::from_headset::start_app & request) {
const auto & apps = list_applications();
if (auto it = apps.find(request.app_id); it != apps.end())
children->start_application(it->second.exec);
children->start_application(it->second.exec, it->second.path);
},
[&](const from_monado::headset_connected &) {
stop_publishing();
+17 -3
View File
@@ -22,6 +22,7 @@
#include "utils/flatpak.h"
#include <cassert>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
@@ -95,15 +96,15 @@ static std::vector<std::string> unescape_string(const std::string & app_string)
return app;
}
void children_manager::start_application(const std::string & exec)
void children_manager::start_application(const std::string & exec, const std::optional<std::string> & path)
{
start_application(unescape_string(exec));
start_application(unescape_string(exec), path);
}
forked_children::forked_children(std::function<void()> state_changed_cb) :
state_changed_cb(state_changed_cb) {}
void forked_children::start_application(const std::vector<std::string> & args)
void forked_children::start_application(const std::vector<std::string> & args, const std::optional<std::string> & path)
{
if (args.empty())
return;
@@ -151,6 +152,19 @@ void forked_children::start_application(const std::vector<std::string> & args)
{
tmp.push_back("flatpak-spawn");
tmp.push_back("--host");
if (path)
tmp.push_back("--directory=" + *path);
}
else
{
try
{
std::filesystem::current_path(*path);
}
catch (std::exception & e)
{
std::cerr << "Failed to set path to " << *path << ": " << e.what() << std::endl;
}
}
tmp.insert(tmp.end(), args.begin(), args.end());
+4 -3
View File
@@ -19,6 +19,7 @@
#include <functional>
#include <glib.h>
#include <optional>
#include <string>
#include <sys/types.h>
#include <unordered_map>
@@ -32,8 +33,8 @@ class children_manager
public:
virtual ~children_manager();
virtual void start_application(const std::vector<std::string> &) = 0;
void start_application(const std::string &);
virtual void start_application(const std::vector<std::string> &, const std::optional<std::string> & path = {}) = 0;
void start_application(const std::string &, const std::optional<std::string> & path = {});
virtual bool running() const = 0;
@@ -55,7 +56,7 @@ public:
forked_children(std::function<void()> state_changed_cb);
virtual ~forked_children();
void start_application(const std::vector<std::string> &) override;
void start_application(const std::vector<std::string> &, const std::optional<std::string> & path) override;
// true if any unit started by this object is still running
bool running() const override;
+7 -1
View File
@@ -196,7 +196,7 @@ struct variant_builder
}; // namespace
void systemd_units_manager::start_application(const std::vector<std::string> & args)
void systemd_units_manager::start_application(const std::vector<std::string> & args, const std::optional<std::string> & path)
{
if (args.empty())
return;
@@ -224,6 +224,12 @@ void systemd_units_manager::start_application(const std::vector<std::string> & a
&exec_start,
1));
if (path)
g_variant_builder_add(&b,
"(sv)",
"WorkingDirectory",
g_variant_new("s", path->c_str()));
if (auto path = std::getenv("PATH"))
{
variant_builder pathv(G_VARIANT_TYPE("as"));
+1 -1
View File
@@ -54,7 +54,7 @@ public:
systemd_units_manager(GDBusConnection * connection, std::function<void()> state_changed_cb);
// create and start the transient unit
void start_application(const std::vector<std::string> &) override;
void start_application(const std::vector<std::string> &, const std::optional<std::string> & path) override;
// true if any unit started by this object is still running
bool running() const override;
+49 -10
View File
@@ -35,6 +35,10 @@
#include "wivrn_packets.h"
#if WIRESHARK_VERSION_MAJOR > 4 || (WIRESHARK_VERSION_MAJOR == 4 && WIRESHARK_VERSION_MINOR >= 4)
static inline uint32_t get_uint32(tvbuff_t * tvb, const int offset, const unsigned encoding)
{
return tvb_get_uint32(tvb, offset, encoding);
}
static inline uint16_t get_uint16(tvbuff_t * tvb, const int offset, const unsigned encoding)
{
return tvb_get_uint16(tvb, offset, encoding);
@@ -45,6 +49,10 @@ static inline uint16_t get_uint8(tvbuff_t * tvb, const int offset)
return tvb_get_uint8(tvb, offset);
}
#else
static inline uint32_t get_uint32(tvbuff_t * tvb, const int offset, const unsigned encoding)
{
return tvb_get_guint32(tvb, offset, encoding);
}
static inline uint16_t get_uint16(tvbuff_t * tvb, const int offset, const unsigned encoding)
{
return tvb_get_guint16(tvb, offset, encoding);
@@ -439,6 +447,11 @@ struct tree_traits<abbrev, std::vector<T>>
size_t count = get_uint16(tvb, start, ENC_LITTLE_ENDIAN);
start += sizeof(uint16_t);
if (count & 0x8000)
{
count = (count & 0x7fff) | (get_uint16(tvb, start, ENC_LITTLE_ENDIAN) << 15);
start += sizeof(uint16_t);
}
for (size_t i = 0; i < count; i++)
{
@@ -452,6 +465,13 @@ struct tree_traits<abbrev, std::vector<T>>
start += sizeof(uint16_t);
size_t size = sizeof(uint16_t);
if (count & 0x8000)
{
count = (count & 0x7fff) | (get_uint16(tvb, start, ENC_LITTLE_ENDIAN) << 15);
start += sizeof(uint16_t);
size += sizeof(uint16_t);
}
for (size_t i = 0; i < count; i++)
{
size += tree_traits<details::join(abbrev, details::type_name<T>()), T>::size(tvb, start);
@@ -794,19 +814,38 @@ int dissect_wivrn(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree _U_, vo
/* Clear out stuff in the info column */
col_clear(pinfo->cinfo, COL_INFO);
proto_item * ti = proto_tree_add_item(tree, proto, tvb, 0, -1, ENC_NA);
proto_tree * subtree = proto_item_add_subtree(ti, subtree_handles.at(""));
int start = 0;
int offset = 0;
if (tcp)
start += sizeof(uint16_t);
while (true)
{
proto_item * ti = proto_tree_add_item(tree, proto, tvb, 0, -1, ENC_NA);
proto_tree * subtree = proto_item_add_subtree(ti, subtree_handles.at(""));
if (pinfo->destport == wivrn::default_port)
tree_traits<"wivrn.from_headset", from_headset::packets>::dissect(subtree, tvb, start);
else
tree_traits<"wivrn.to_headset", to_headset::packets>::dissect(subtree, tvb, start);
int remaining = tvb_reported_length_remaining(tvb, offset);
return tvb_captured_length(tvb);
if (tcp)
{
if (remaining < sizeof(uint32_t))
return remaining - sizeof(uint32_t);
remaining -= sizeof(uint32_t);
uint32_t size = get_uint32(tvb, offset, ENC_LITTLE_ENDIAN);
if (remaining < size)
return remaining - size;
offset += sizeof(uint32_t);
}
if (pinfo->destport == wivrn::default_port)
tree_traits<"wivrn.from_headset", from_headset::packets>::dissect(subtree, tvb, offset);
else
tree_traits<"wivrn.to_headset", to_headset::packets>::dissect(subtree, tvb, offset);
if (not tcp)
return offset;
if (tvb_reported_length(tvb) <= offset)
return offset;
}
}
int dissect_wivrn_udp(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree _U_, void * data _U_)