clang-format

This commit is contained in:
Guillaume Meunier
2024-03-30 17:00:34 +01:00
parent bb660cfb3f
commit 9cceaac648
122 changed files with 2904 additions and 2783 deletions
+3 -3
View File
@@ -50,13 +50,13 @@ void clock_offset_estimator::add_sample(const xrt::drivers::wivrn::from_headset:
{
sample_interval = std::chrono::seconds(1);
int64_t latency = 0;
for (const auto& s: samples)
for (const auto & s: samples)
latency += s.received - s.query;
latency /= samples.size();
// packets with too high latency are likely to be retransmitted
if (sample.received - sample.query > 3 * latency)
{
U_LOG_D("drop packet for latency %ldµs > %ldµs", (sample.received - sample.query) /1000, latency/1000);
U_LOG_D("drop packet for latency %ldµs > %ldµs", (sample.received - sample.query) / 1000, latency / 1000);
return;
}
@@ -96,7 +96,7 @@ void clock_offset_estimator::add_sample(const xrt::drivers::wivrn::from_headset:
{
#if 1
// assume symmetrical latency
double x = (s.query + s.received)* 0.5 - x0;
double x = (s.query + s.received) * 0.5 - x0;
#else
// assume latency is only on server -> headset link
double x = s.received - x0;
+8 -5
View File
@@ -36,7 +36,10 @@ struct clock_offset
int64_t b = 0;
double a = 1;
operator bool() { return b != 0;}
operator bool()
{
return b != 0;
}
XrTime from_headset(XrTime) const;
@@ -45,7 +48,7 @@ struct clock_offset
class clock_offset_estimator
{
struct sample: public xrt::drivers::wivrn::from_headset::timesync_response
struct sample : public xrt::drivers::wivrn::from_headset::timesync_response
{
XrTime received;
};
@@ -58,9 +61,9 @@ class clock_offset_estimator
std::chrono::steady_clock::time_point next_sample{};
std::atomic<std::chrono::milliseconds> sample_interval = std::chrono::milliseconds(10);
public:
void request_sample(wivrn_connection& connection);
void add_sample(const xrt::drivers::wivrn::from_headset::timesync_response& sample);
public:
void request_sample(wivrn_connection & connection);
void add_sample(const xrt::drivers::wivrn::from_headset::timesync_response & sample);
clock_offset get_offset();
};
+12 -11
View File
@@ -25,8 +25,8 @@
#endif
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>
#include <stdlib.h>
#include <random>
#include <stdlib.h>
#include "util/u_logging.h"
@@ -45,14 +45,15 @@ static std::filesystem::path get_cookie_file()
namespace xrt::drivers::wivrn
{
NLOHMANN_JSON_SERIALIZE_ENUM(video_codec, {
{video_codec(-1), ""},
{h264, "h264"},
{h264, "avc"},
{h265, "h265"},
{h265, "hevc"},
})
NLOHMANN_JSON_SERIALIZE_ENUM(
video_codec,
{
{video_codec(-1), ""},
{h264, "h264"},
{h264, "avc"},
{h265, "h265"},
{h265, "hevc"},
})
}
configuration configuration::read_user_configuration()
@@ -110,7 +111,7 @@ configuration configuration::read_user_configuration()
result.application.push_back(json["application"]);
else
{
for(const auto& i: json["application"])
for (const auto & i: json["application"])
{
result.application.push_back(i);
}
@@ -146,7 +147,7 @@ std::string server_cookie()
std::uniform_int_distribution<int> dist(0, 61);
char buffer[33];
for(int i = 0; i < 32; i++)
for (int i = 0; i < 32; i++)
{
int c = dist(engine);
+16 -17
View File
@@ -28,19 +28,18 @@ static_assert(XRT_HAND_JOINT_COUNT == XR_HAND_JOINT_COUNT_EXT);
namespace
{
xrt_hand_joint_value interpolate(const xrt_hand_joint_value & a, const xrt_hand_joint_value & b, float t)
{
return {
.relation = pose_list::interpolate(a.relation, b.relation, t),
.radius = a.radius * (1-t) + b.radius * t
};
}
xrt_hand_joint_value interpolate(const xrt_hand_joint_value & a, const xrt_hand_joint_value & b, float t)
{
return {
.relation = pose_list::interpolate(a.relation, b.relation, t),
.radius = a.radius * (1 - t) + b.radius * t};
}
} // namespace
xrt_hand_joint_set hand_joints_list::interpolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, float t)
{
xrt_hand_joint_set j = a;
for(int i = 0; i < XRT_HAND_JOINT_COUNT; i++)
for (int i = 0; i < XRT_HAND_JOINT_COUNT; i++)
{
j.values.hand_joint_set_default[i] = ::interpolate(a.values.hand_joint_set_default[i], b.values.hand_joint_set_default[i], t);
}
@@ -49,7 +48,7 @@ xrt_hand_joint_set hand_joints_list::interpolate(const xrt_hand_joint_set & a, c
xrt_hand_joint_set hand_joints_list::extrapolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, uint64_t ta, uint64_t tb, uint64_t t)
{
xrt_hand_joint_set j = t <= ta ? a : b;
xrt_hand_joint_set j = t <= ta ? a : b;
// Only extrapolate the hand pose, individual joints are too noisy
j.hand_pose = pose_list::extrapolate(a.hand_pose, b.hand_pose, ta, tb, t);
return j;
@@ -78,17 +77,17 @@ static xrt_space_relation_flags cast_flags(uint8_t in_flags)
return xrt_space_relation_flags(flags);
}
static xrt_space_relation to_relation(const from_headset::hand_tracking::pose& pose)
static xrt_space_relation to_relation(const from_headset::hand_tracking::pose & pose)
{
return {
.relation_flags = cast_flags(pose.flags),
.pose = xrt_cast(pose.pose),
.linear_velocity = xrt_cast(pose.linear_velocity),
.angular_velocity = xrt_cast(pose.angular_velocity),
.relation_flags = cast_flags(pose.flags),
.pose = xrt_cast(pose.pose),
.linear_velocity = xrt_cast(pose.linear_velocity),
.angular_velocity = xrt_cast(pose.angular_velocity),
};
}
static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>>& input_joints)
static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>> & input_joints)
{
xrt_hand_joint_set output_joints{};
@@ -101,9 +100,9 @@ static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_hea
xrt_space_relation * joint_rel = m_relation_chain_reserve(&rel_chain);
m_relation_chain_push_inverted_relation(&rel_chain, &output_joints.hand_pose);
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
{
xrt_hand_joint_value& res = output_joints.values.hand_joint_set_default[i];
xrt_hand_joint_value & res = output_joints.values.hand_joint_set_default[i];
res.radius = (*input_joints)[i].radius;
*joint_rel = to_relation((*input_joints)[i]);
+2 -2
View File
@@ -22,7 +22,6 @@
#include "history.h"
#include "xrt/xrt_defines.h"
class hand_joints_list : public history<hand_joints_list, xrt_hand_joint_set>
{
int hand_id;
@@ -31,7 +30,8 @@ public:
static xrt_hand_joint_set interpolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, float t);
static xrt_hand_joint_set extrapolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, uint64_t ta, uint64_t tb, uint64_t t);
hand_joints_list(int hand_id) : hand_id(hand_id) {}
hand_joints_list(int hand_id) :
hand_id(hand_id) {}
void update_tracking(const xrt::drivers::wivrn::from_headset::hand_tracking & tracking, const clock_offset & offset);
};
+4 -3
View File
@@ -19,12 +19,12 @@
#pragma once
#include "clock_offset.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <vector>
#include <algorithm>
#include "clock_offset.h"
template <typename Derived, typename Data, bool extrapolate = false, size_t MaxSamples = 10>
class history
@@ -97,7 +97,8 @@ public:
const auto & d1 = data.back();
return Derived::extrapolate(d0, d1, d0.at_timestamp_ns, d1.at_timestamp_ns, at_timestamp_ns);
}
else {
else
{
return data.back();
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ xrt_space_relation pose_list::extrapolate(const xrt_space_relation & a, const xr
xrt_space_relation res = t < ta ? a : b;
xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position ) / h;
xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h;
float dt = (t - tb) / 1.e9;
+1 -2
View File
@@ -19,12 +19,11 @@
#pragma once
#include "wivrn_packets.h"
#include "clock_offset.h"
#include "history.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
class pose_list : public history<pose_list, xrt_space_relation>
{
xrt::drivers::wivrn::device_id device;
-1
View File
@@ -30,7 +30,6 @@ struct tracked_views
std::array<xrt_fov, 2> fovs;
};
class view_list : public history<view_list, tracked_views, true>
{
public:
+2 -3
View File
@@ -21,7 +21,6 @@
#include "encoder/video_encoder.h"
#include "main/comp_compositor.h"
#include "math/m_space.h"
#include "encoder/video_encoder.h"
#include "xrt_cast.h"
#include <condition_variable>
#include <list>
@@ -540,12 +539,12 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
view_info.display_time = cn->cnx->get_offset().to_headset(desired_present_time_ns);
for (int eye = 0; eye < 2; ++eye)
{
const auto &slot = cn->c->base.slot;
const auto & slot = cn->c->base.slot;
view_info.fov[eye] = xrt_cast(slot.fovs[eye]);
view_info.pose[eye] = xrt_cast(slot.poses[eye]);
if (cn->c->debug.atw_off)
{
const auto &stereo = slot.layers[0].data.stereo;
const auto & stereo = slot.layers[0].data.stereo;
view_info.pose[eye] = xrt_cast(eye ? stereo.r.pose : stereo.l.pose);
}
else
+3 -3
View File
@@ -28,12 +28,12 @@
#include "utils/wivrn_vk_bundle.h"
#include "vk/allocation.h"
#include "driver/wivrn_pacer.h"
#include <condition_variable>
#include <list>
#include <memory>
#include <optional>
#include <vector>
#include "driver/wivrn_pacer.h"
#include <vulkan/vulkan_raii.hpp>
namespace xrt::drivers::wivrn
@@ -74,8 +74,8 @@ struct wivrn_comp_target : public comp_target
VkColorSpaceKHR color_space;
static std::vector<const char*> wanted_instance_extensions;
static std::vector<const char*> wanted_device_extensions;
static std::vector<const char *> wanted_instance_extensions;
static std::vector<const char *> wanted_device_extensions;
struct encoder_thread
{
+3 -4
View File
@@ -29,11 +29,11 @@ wivrn_connection::wivrn_connection(TCP && tcp) :
{
sockaddr_in6 server_address;
socklen_t len = sizeof(server_address);
if (getsockname(control.get_fd(), (sockaddr*)&server_address, &len) < 0)
if (getsockname(control.get_fd(), (sockaddr *)&server_address, &len) < 0)
{
throw std::system_error(errno, std::system_category(), "Cannot get socket port");
}
int port = ntohs(((struct sockaddr_in6*)&server_address)->sin6_port);
int port = ntohs(((struct sockaddr_in6 *)&server_address)->sin6_port);
sockaddr_in6 client_address;
len = sizeof(client_address);
@@ -78,7 +78,6 @@ wivrn_connection::wivrn_connection(TCP && tcp) :
stream.set_send_buffer_size(1024 * 1024 * 5);
break;
}
}
if (std::chrono::steady_clock::now() > timeout)
@@ -92,7 +91,7 @@ wivrn_connection::wivrn_connection(TCP && tcp) :
// Set Expedited forwarding https://datatracker.ietf.org/doc/html/rfc3246
stream.set_tos(IPTOS_DSCP_EF);
}
catch (std::exception& e)
catch (std::exception & e)
{
U_LOG_I("Failed to set IP ToS to Expedited Forwarding: %s", e.what());
}
+27 -27
View File
@@ -111,24 +111,24 @@ static const size_t left_hand_bindings_count = ARRAY_SIZE(left_hand_bindings);
static const size_t right_hand_bindings_count = ARRAY_SIZE(right_hand_bindings);
static xrt_binding_input_pair simple_input_binding[] = {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
};
static xrt_binding_output_pair simple_output_binding[] = {
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
};
static xrt_binding_profile wivrn_binding_profiles[] = {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_input_binding,
.input_count = std::size(simple_input_binding),
.outputs = simple_output_binding,
.output_count = std::size(simple_output_binding),
},
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_input_binding,
.input_count = std::size(simple_input_binding),
.outputs = simple_output_binding,
.output_count = std::size(simple_output_binding),
},
};
static void wivrn_controller_destroy(xrt_device * xdev);
@@ -139,10 +139,10 @@ static void wivrn_controller_get_tracked_pose(xrt_device * xdev,
xrt_space_relation * out_relation);
static void wivrn_controller_get_hand_tracking(xrt_device * xdev,
xrt_input_name name,
uint64_t desired_timestamp_ns,
xrt_hand_joint_set * out_value,
uint64_t *out_timestamp_ns);
xrt_input_name name,
uint64_t desired_timestamp_ns,
xrt_hand_joint_set * out_value,
uint64_t * out_timestamp_ns);
static void wivrn_controller_set_output(struct xrt_device * xdev, enum xrt_output_name name, const union xrt_output_value * value);
@@ -152,10 +152,10 @@ wivrn_controller::wivrn_controller(int hand_id,
xrt_device * hmd,
std::shared_ptr<xrt::drivers::wivrn::wivrn_session> cnx) :
xrt_device{},
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM),
joints(hand_id),
cnx(cnx)
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM),
joints(hand_id),
cnx(cnx)
{
xrt_device * base = this;
@@ -252,7 +252,7 @@ void wivrn_controller::update_inputs()
inputs_array = inputs_staging;
}
void wivrn_controller::set_inputs(const from_headset::inputs & inputs, const clock_offset& clock_offset)
void wivrn_controller::set_inputs(const from_headset::inputs & inputs, const clock_offset & clock_offset)
{
std::lock_guard lock{mutex};
for (const auto & input: inputs.values)
@@ -325,11 +325,11 @@ xrt_space_relation wivrn_controller::get_tracked_pose(xrt_input_name name, uint6
std::pair<xrt_hand_joint_set, uint64_t> wivrn_controller::get_hand_tracking(xrt_input_name name, uint64_t desired_timestamp_ns)
{
switch(name)
switch (name)
{
case XRT_INPUT_GENERIC_HAND_TRACKING_LEFT:
case XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT:
return { joints.get_at(desired_timestamp_ns), desired_timestamp_ns };
return {joints.get_at(desired_timestamp_ns), desired_timestamp_ns};
default:
U_LOG_W("Unknown input name requested");
@@ -392,10 +392,10 @@ static void wivrn_controller_get_tracked_pose(xrt_device * xdev,
}
static void wivrn_controller_get_hand_tracking(xrt_device * xdev,
xrt_input_name name,
uint64_t desired_timestamp_ns,
xrt_hand_joint_set * out_value,
uint64_t *out_timestamp_ns)
xrt_input_name name,
uint64_t desired_timestamp_ns,
xrt_hand_joint_set * out_value,
uint64_t * out_timestamp_ns)
{
std::tie(*out_value, *out_timestamp_ns) = static_cast<wivrn_controller *>(xdev)->get_hand_tracking(name, desired_timestamp_ns);
}
+1 -1
View File
@@ -21,8 +21,8 @@
#include "xrt/xrt_device.h"
#include "pose_list.h"
#include "hand_joints_list.h"
#include "pose_list.h"
#include "wivrn_session.h"
#include <memory>
+1 -1
View File
@@ -91,7 +91,7 @@ static std::tuple<float, float> solve_foveation(float λ, float c)
//
// Use eq. 2 to express a as function of b, then replace in eq. 1
// equation that needs to be null is:
auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a;};
auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a; };
auto eq = [λ, c](double a) { return atan(a * (1 - c) / λ) + atan(a * (1 + c) / λ) - 2 * a; }; // (eq. 3)
// function starts positive, reaches a maximum then decreases to -∞
+5 -3
View File
@@ -41,7 +41,8 @@ class wivrn_pacer
uint64_t last_wake_up_ns = 0;
// Client wait time for each decoder
struct stream_data{
struct stream_data
{
// Last feedback for each encoder
xrt::drivers::wivrn::from_headset::feedback last_feedback;
std::vector<uint64_t> times;
@@ -49,7 +50,8 @@ class wivrn_pacer
};
std::vector<stream_data> streams;
struct frame_history{
struct frame_history
{
uint64_t frame_id;
uint64_t present_ns;
};
@@ -69,7 +71,7 @@ public:
uint64_t & out_present_slop_ns,
uint64_t & out_predicted_display_time_ns);
void on_feedback(const xrt::drivers::wivrn::from_headset::feedback &, const clock_offset&);
void on_feedback(const xrt::drivers::wivrn::from_headset::feedback &, const clock_offset &);
void mark_timing_point(
comp_target_timing_point point,
+2 -2
View File
@@ -74,7 +74,7 @@ public:
clock_offset get_offset();
void operator()(from_headset::handshake&&) {}
void operator()(from_headset::handshake &&) {}
void operator()(from_headset::headset_info_packet &&);
void operator()(from_headset::tracking &&);
void operator()(from_headset::hand_tracking &&);
@@ -97,7 +97,7 @@ public:
std::array<to_headset::video_stream_description::foveation_parameter, 2> get_foveation_parameters();
void dump_time(const std::string & event, uint64_t frame, uint64_t time, uint8_t stream = -1, const char* extra = "");
void dump_time(const std::string & event, uint64_t frame, uint64_t time, uint8_t stream = -1, const char * extra = "");
private:
static void run(std::weak_ptr<wivrn_session>);