Files
WiVRn/common/wivrn_packets.h

1001 lines
25 KiB
C++

/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <[email protected]>
* Copyright (C) 2022 Patrick Nicolas <[email protected]>
*
* 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 <array>
#include <chrono>
#include <cstdint>
#include <magic_enum.hpp>
#include <netinet/in.h>
#include <openssl/aes.h>
#include <optional>
#include <span>
#include <string>
#include <type_traits>
#include <variant>
#include <vector>
#include <openxr/openxr.h>
#include "packed_quaternion.h"
#include "smp.h"
#include "wivrn_serialization_types.h"
namespace wivrn
{
static constexpr int protocol_revision = 1;
enum class device_id : uint8_t
{
HEAD, // /user/head
LEFT_CONTROLLER_HAPTIC, // /user/hand/left/output/haptic
RIGHT_CONTROLLER_HAPTIC, // /user/hand/right/output/haptic
LEFT_TRIGGER_HAPTIC, // /user/hand/left/output/haptic_trigger
RIGHT_TRIGGER_HAPTIC, // /user/hand/right/output/haptic_trigger
LEFT_THUMB_HAPTIC, // /user/hand/left/output/haptic_thumb
RIGHT_THUMB_HAPTIC, // /user/hand/right/output/haptic_thumb
GAMEPAD_HAPTIC_LEFT, // /user/gamepad/output/haptic_left
GAMEPAD_HAPTIC_RIGHT, // /user/gamepad/output/haptic_right
GAMEPAD_HAPTIC_LEFT_TRIGGER, // /user/gamepad/output/haptic_left_trigger
GAMEPAD_HAPTIC_RIGHT_TRIGGER, // /user/gamepad/output/haptic_right_trigger
LEFT_GRIP, // /user/hand/left/input/grip/pose
LEFT_AIM, // /user/hand/left/input/aim/pose
LEFT_PALM, // /user/hand/left/palm_ext/pose
RIGHT_GRIP, // /user/hand/right/input/grip/pose
RIGHT_AIM, // /user/hand/right/input/aim/pose
RIGHT_PALM, // /user/hand/right/palm_ext/pose
DPAD_UP_CLICK, // /user/hand/left/input/dpad_up/click
DPAD_UP_TOUCH, // /user/hand/left/input/dpad_up/touch
DPAD_LEFT_CLICK, // /user/hand/left/input/dpad_left/click
DPAD_LEFT_TOUCH, // /user/hand/left/input/dpad_left/touch
LEFT_X_CLICK, // /user/hand/left/input/x/click or /user/hand/left/input/dpad_down/click
LEFT_X_TOUCH, // /user/hand/left/input/x/touch or /user/hand/left/input/dpad_down/touch
LEFT_Y_CLICK, // /user/hand/left/input/y/click or /user/hand/left/input/dpad_right/click
LEFT_Y_TOUCH, // /user/hand/left/input/y/touch or /user/hand/left/input/dpad_right/touch
LEFT_MENU_CLICK, // /user/hand/left/input/{menu,view}/click
LEFT_MENU_TOUCH, // /user/hand/left/input/{menu,view}/touch
LEFT_SYSTEM_CLICK, // /user/hand/left/input/system/click
LEFT_SYSTEM_TOUCH, // /user/hand/left/input/system/touch
LEFT_BUMPER_CLICK, // /user/hand/left/input/bumper/click
LEFT_BUMPER_TOUCH, // /user/hand/left/input/bumper/touch
LEFT_SQUEEZE_CLICK, // /user/hand/left/input/squeeze/click
LEFT_SQUEEZE_FORCE, // /user/hand/left/input/squeeze/force
LEFT_SQUEEZE_TOUCH, // /user/hand/left/input/squeeze/touch
LEFT_SQUEEZE_VALUE, // /user/hand/left/input/squeeze/value
LEFT_TRIGGER_CLICK, // /user/hand/left/input/trigger/click
LEFT_TRIGGER_VALUE, // /user/hand/left/input/trigger/value
LEFT_TRIGGER_TOUCH, // /user/hand/left/input/trigger/touch
LEFT_TRIGGER_PROXIMITY, // /user/hand/left/input/trigger/proximity
LEFT_TRIGGER_CURL, // /user/hand/left/input/trigger/curl_fb
LEFT_TRIGGER_SLIDE, // /user/hand/left/input/trigger/slide_fb
LEFT_TRIGGER_FORCE, // /user/hand/left/input/trigger/force
LEFT_THUMBSTICK_X, // /user/hand/left/input/thumbstick/x
LEFT_THUMBSTICK_Y, // /user/hand/left/input/thumbstick/y
LEFT_THUMBSTICK_CLICK, // /user/hand/left/input/thumbstick/click
LEFT_THUMBSTICK_TOUCH, // /user/hand/left/input/thumbstick/touch
LEFT_THUMBREST_TOUCH, // /user/hand/left/input/thumbrest/touch
LEFT_THUMBREST_FORCE, // /user/hand/left/input/thumbrest/force
LEFT_THUMB_PROXIMITY, // /user/hand/left/input/thumb_resting_surfaces/proximity
LEFT_TRACKPAD_X, // /user/hand/left/input/trackpad/x
LEFT_TRACKPAD_Y, // /user/hand/left/input/trackpad/y
LEFT_TRACKPAD_CLICK, // /user/hand/left/input/trackpad/click
LEFT_TRACKPAD_TOUCH, // /user/hand/left/input/trackpad/touch
LEFT_TRACKPAD_FORCE, // /user/hand/left/input/trackpad/force
LEFT_STYLUS_FORCE, // /user/hand/left/input/stylus_fb/force
LEFT_PINCH_POSE, // /user/hand/left/input/pinch_ext/pose
LEFT_PINCH_VALUE, // /user/hand/left/input/pinch_ext/value
LEFT_PINCH_READY, // /user/hand/left/input/pinch_ext/ready_ext
LEFT_POKE, // /user/hand/left/input/poke_ext/pose
LEFT_AIM_ACTIVATE_VALUE, // /user/hand/left/input/aim_activate_ext/value
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
A_CLICK, // /user/hand/right/input/a/click
A_TOUCH, // /user/hand/right/input/a/touch
B_CLICK, // /user/hand/right/input/b/click
B_TOUCH, // /user/hand/right/input/b/touch
RIGHT_X_CLICK, // /user/hand/right/input/x/click
RIGHT_X_TOUCH, // /user/hand/right/input/x/touch
RIGHT_Y_CLICK, // /user/hand/right/input/y/click
RIGHT_Y_TOUCH, // /user/hand/right/input/y/touch
RIGHT_MENU_CLICK, // /user/hand/right/input/menu/click
RIGHT_MENU_TOUCH, // /user/hand/right/input/menu/touch
RIGHT_SYSTEM_CLICK, // /user/hand/right/input/system/click
RIGHT_SYSTEM_TOUCH, // /user/hand/right/input/system/touch
RIGHT_BUMPER_CLICK, // /user/hand/right/input/bumper/click
RIGHT_BUMPER_TOUCH, // /user/hand/right/input/bumper/touch
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
RIGHT_SQUEEZE_FORCE, // /user/hand/right/input/squeeze/force
RIGHT_SQUEEZE_TOUCH, // /user/hand/right/input/squeeze/touch
RIGHT_SQUEEZE_VALUE, // /user/hand/right/input/squeeze/value
RIGHT_TRIGGER_CLICK, // /user/hand/right/input/trigger/click
RIGHT_TRIGGER_VALUE, // /user/hand/right/input/trigger/value
RIGHT_TRIGGER_TOUCH, // /user/hand/right/input/trigger/touch
RIGHT_TRIGGER_PROXIMITY, // /user/hand/right/input/trigger/proximity
RIGHT_TRIGGER_CURL, // /user/hand/right/input/trigger/curl_fb
RIGHT_TRIGGER_SLIDE, // /user/hand/right/input/trigger/slide_fb
RIGHT_TRIGGER_FORCE, // /user/hand/right/input/trigger/force
RIGHT_THUMBSTICK_X, // /user/hand/right/input/thumbstick/x
RIGHT_THUMBSTICK_Y, // /user/hand/right/input/thumbstick/y
RIGHT_THUMBSTICK_CLICK, // /user/hand/right/input/thumbstick/click
RIGHT_THUMBSTICK_TOUCH, // /user/hand/right/input/thumbstick/touch
RIGHT_THUMBREST_TOUCH, // /user/hand/right/input/thumbrest/touch
RIGHT_THUMBREST_FORCE, // /user/hand/right/input/thumbrest/force
RIGHT_THUMB_PROXIMITY, // /user/hand/right/input/thumb_resting_surfaces/proximity
RIGHT_TRACKPAD_X, // /user/hand/right/input/trackpad/x
RIGHT_TRACKPAD_Y, // /user/hand/right/input/trackpad/y
RIGHT_TRACKPAD_CLICK, // /user/hand/right/input/trackpad/click
RIGHT_TRACKPAD_TOUCH, // /user/hand/right/input/trackpad/touch
RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force
RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force
RIGHT_PINCH_POSE, // /user/hand/right/input/pinch_ext/pose
RIGHT_PINCH_VALUE, // /user/hand/right/input/pinch_ext/value
RIGHT_PINCH_READY, // /user/hand/right/input/pinch_ext/ready_ext
RIGHT_POKE, // /user/hand/right/input/poke_ext/pose
RIGHT_AIM_ACTIVATE_VALUE, // /user/hand/right/input/aim_activate_ext/value
RIGHT_AIM_ACTIVATE_READY, // /user/hand/right/input/aim_activate_ext/ready_ext
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
LEFT_CONTROLLER, // identify controller
RIGHT_CONTROLLER, // identify controller
LEFT_HAND = LEFT_CONTROLLER, // identify hand tracking
RIGHT_HAND = RIGHT_CONTROLLER, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
GAMEPAD, // identify gamepad
// Gamepad, microsoft/xbox_controller profile (/user/gamepad)
GAMEPAD_MENU_CLICK, // /user/gamepad/input/menu/click
GAMEPAD_VIEW_CLICK, // /user/gamepad/input/view/click
GAMEPAD_A_CLICK, // /user/gamepad/input/a/click
GAMEPAD_B_CLICK, // /user/gamepad/input/b/click
GAMEPAD_X_CLICK, // /user/gamepad/input/x/click
GAMEPAD_Y_CLICK, // /user/gamepad/input/y/click
GAMEPAD_DPAD_DOWN_CLICK, // /user/gamepad/input/dpad_down/click
GAMEPAD_DPAD_RIGHT_CLICK, // /user/gamepad/input/dpad_right/click
GAMEPAD_DPAD_UP_CLICK, // /user/gamepad/input/dpad_up/click
GAMEPAD_DPAD_LEFT_CLICK, // /user/gamepad/input/dpad_left/click
GAMEPAD_SHOULDER_LEFT_CLICK, // /user/gamepad/input/shoulder_left/click
GAMEPAD_SHOULDER_RIGHT_CLICK, // /user/gamepad/input/shoulder_right/click
GAMEPAD_THUMBSTICK_LEFT_CLICK, // /user/gamepad/input/thumbstick_left/click
GAMEPAD_THUMBSTICK_RIGHT_CLICK, // /user/gamepad/input/thumbstick_right/click
GAMEPAD_TRIGGER_LEFT_VALUE, // /user/gamepad/input/trigger_left/value
GAMEPAD_TRIGGER_RIGHT_VALUE, // /user/gamepad/input/trigger_right/value
GAMEPAD_THUMBSTICK_LEFT_X, // /user/gamepad/input/thumbstick_left/x
GAMEPAD_THUMBSTICK_LEFT_Y, // /user/gamepad/input/thumbstick_left/y
GAMEPAD_THUMBSTICK_RIGHT_X, // /user/gamepad/input/thumbstick_right/x
GAMEPAD_THUMBSTICK_RIGHT_Y, // /user/gamepad/input/thumbstick_right/y
};
enum class interaction_profile : uint8_t
{
none,
khr_simple_controller,
ext_hand_interaction_ext,
bytedance_pico_neo3_controller,
bytedance_pico4_controller,
bytedance_pico4s_controller,
bytedance_pico_g3_controller,
google_daydream_controller,
hp_mixed_reality_controller,
htc_vive_controller,
htc_vive_cosmos_controller,
htc_vive_focus3_controller,
htc_vive_pro,
ml_ml2_controller,
microsoft_motion_controller,
microsoft_xbox_controller,
oculus_go_controller,
oculus_touch_controller,
meta_touch_pro_controller,
meta_touch_plus_controller,
meta_touch_controller_rift_cv1,
meta_touch_controller_quest_1_rift_s,
meta_touch_controller_quest_2,
yvr_touch_controller_yvr,
samsung_odyssey_controller,
valve_index_controller,
valve_frame_controller_valve,
};
enum video_codec
{
h264,
h265,
hevc = h265,
av1,
raw,
};
struct video_codec_capability
{
video_codec codec;
bool supports_10bit;
bool operator==(const video_codec_capability &) const = default;
};
enum class stream_tab : uint8_t
{
hidden,
overlay_only,
compact,
stats,
settings,
foveation_settings,
applications,
application_launcher,
};
struct audio_data
{
XrTime timestamp;
std::span<uint8_t> payload;
data_holder data;
};
namespace from_headset
{
struct crypto_handshake
{
uint64_t protocol_version;
std::string public_key; // In PEM format
std::string name;
};
struct pin_check_1
{
crypto::smp::msg1 message;
};
struct pin_check_3
{
crypto::smp::msg3 message;
};
struct visibility_mask_changed
{
struct mask
{
std::vector<XrVector2f> vertices;
std::vector<uint32_t> indices;
};
static const int num_types = 3; // XrVisibilityMaskTypeKHR values
using masks = std::array<mask, num_types>;
masks data;
uint8_t view_index;
};
enum class face_type : uint8_t
{
none,
android,
fb2,
htc,
};
enum class body_type : uint8_t
{
none,
fb,
meta,
bd,
htc,
};
enum class body_part_mask : uint32_t
{
chest = 1 << 0,
left_elbow = 1 << 1,
right_elbow = 1 << 2,
hip = 1 << 3,
left_knee = 1 << 4,
right_knee = 1 << 5,
left_foot = 1 << 6,
right_foot = 1 << 7,
max,
};
struct settings_changed
{
float preferred_refresh_rate;
// for automatic
float minimum_refresh_rate;
uint32_t fps_divider = 1;
uint32_t bitrate_bps;
// Whether the server should mirror the gamepad to a virtual uinput device;
// gamepad inputs are always forwarded for the OpenXR path
bool mirror_gamepad = false;
// which virtual trackers should be enabled for body tracking
std::underlying_type_t<body_part_mask> enabled_body_parts;
};
struct headset_info_packet
{
uint16_t render_eye_width;
uint16_t render_eye_height;
uint16_t stream_eye_width;
uint16_t stream_eye_height;
std::vector<float> available_refresh_rates;
// runtime configurable settings
settings_changed settings;
struct audio_description
{
uint8_t num_channels;
uint32_t sample_rate;
};
std::optional<audio_description> speaker;
std::optional<audio_description> microphone;
bool battery_status; // supports XR_EXT_interaction_profile_battery_state_display, for reporting controller/gamepad battery status
bool hand_tracking;
bool eye_gaze;
bool palm_pose;
bool user_presence;
bool passthrough;
face_type face_tracking;
body_type body_tracking;
// htc body only
uint32_t num_generic_trackers;
std::vector<video_codec_capability> supported_codecs; // from preferred to least preferred
std::optional<uint8_t> bit_depth; // explicit preference
std::string system_name;
// Used for the application list
std::string language;
std::string country;
std::string variant;
};
struct handshake
{
// Sending this on TCP means connection will be TCP only
};
enum pose_flags : uint8_t
{
orientation_valid = 1 << 0,
position_valid = 1 << 1,
linear_velocity_valid = 1 << 2,
angular_velocity_valid = 1 << 3,
orientation_tracked = 1 << 4,
position_tracked = 1 << 5
};
inline uint8_t to_pose_flags(XrSpaceLocationFlags location_flags, XrSpaceVelocityFlags velocity_flags = 0)
{
uint8_t flags{};
if (location_flags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
flags |= pose_flags::orientation_valid;
if (location_flags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
flags |= pose_flags::position_valid;
if (location_flags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
flags |= pose_flags::orientation_tracked;
if (location_flags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
flags |= pose_flags::position_tracked;
if (velocity_flags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT)
flags |= pose_flags::linear_velocity_valid;
if (velocity_flags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT)
flags |= pose_flags::angular_velocity_valid;
return flags;
}
struct foveation
{
std::array<XrVector2f, 2> angles; // Per-eye x/y view angles in radians
};
struct tracking
{
enum state_flags : uint8_t
{
recentered = 1 << 0,
};
struct pose
{
XrPosef pose;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
device_id device;
uint8_t flags;
};
struct view
{
// Relative to XR_REFERENCE_SPACE_TYPE_VIEW
XrPosef pose;
XrFovf fov;
};
// /user/hand/left, /user/hand/right and /user/gamepad
std::array<interaction_profile, 3> interaction_profiles;
XrTime production_timestamp;
XrTime timestamp;
XrViewStateFlags view_flags;
uint8_t state_flags;
std::array<view, 2> views;
std::vector<pose> device_poses;
struct android_face
{
std::array<float, XR_FACE_PARAMETER_COUNT_ANDROID> parameters;
std::array<float, XR_FACE_REGION_CONFIDENCE_COUNT_ANDROID> confidences;
XrFaceTrackingStateANDROID state;
XrTime sample_time;
bool is_calibrated;
bool is_valid;
};
struct fb_face2
{
XrTime time;
std::array<float, XR_FACE_EXPRESSION2_COUNT_FB> weights;
std::array<float, XR_FACE_CONFIDENCE2_COUNT_FB> confidences;
bool is_valid;
bool is_eye_following_blendshapes_valid;
};
struct htc_face
{
XrTime eye_sample_time;
XrTime lip_sample_time;
std::array<float, XR_FACIAL_EXPRESSION_EYE_COUNT_HTC> eye;
std::array<float, XR_FACIAL_EXPRESSION_LIP_COUNT_HTC> lip;
bool eye_active;
bool lip_active;
};
std::variant<std::monostate, android_face, fb_face2, htc_face> face;
};
struct derived_pose
{
device_id source;
device_id target;
XrPosef relation;
};
struct hand_tracking
{
enum hand_id : uint8_t
{
left,
right,
// with data_source
left_controller,
right_controller,
};
struct pose
{
XrVector3f position;
packed_quaternion orientation;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
// In order to avoid packet fragmentation
// use 2 less bytes for radius
uint16_t radius; // 10th of mm
uint8_t flags;
};
XrTime production_timestamp;
XrTime timestamp;
hand_id hand;
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> joints;
};
struct meta_body
{
struct pose
{
XrVector3f position;
packed_quaternion orientation;
uint8_t flags;
};
struct packed_pose
{
struct
{
int16_t x, y, z; // 10th of mm relative to root
} position;
packed_quaternion orientation;
uint8_t flags;
};
XrTime production_timestamp;
XrTime timestamp;
float confidence;
struct fb_joints
{
pose root;
// excluding root
std::array<packed_pose, XR_BODY_JOINT_COUNT_FB - 1> joints;
};
struct meta_joints
{
pose root;
// excluding root
std::array<packed_pose, XR_FULL_BODY_JOINT_COUNT_META - 1> joints;
};
std::variant<std::monostate, fb_joints, meta_joints> joints;
};
struct meta_body_skeleton
{
struct fb_skeleton
{
std::array<XrBodySkeletonJointFB, XR_BODY_JOINT_COUNT_FB> joints;
};
struct meta_skeleton
{
std::array<XrBodySkeletonJointFB, XR_FULL_BODY_JOINT_COUNT_META> joints;
};
std::variant<fb_skeleton, meta_skeleton> skeleton;
};
struct bd_body
{
struct pose
{
XrVector3f position;
packed_quaternion orientation;
uint8_t flags;
};
bool all_tracked;
XrTime production_timestamp;
XrTime timestamp;
std::array<pose, XR_BODY_JOINT_COUNT_BD> joints;
};
struct htc_body
{
static constexpr size_t max_tracked_poses = 16;
struct pose
{
XrPosef pose;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
uint8_t flags;
};
XrTime production_timestamp;
XrTime timestamp;
std::array<pose, max_tracked_poses> poses;
};
struct inputs
{
struct input_value
{
device_id id;
float value;
XrTime last_change_time;
};
std::vector<input_value> values;
};
struct hid
{
struct button_down
{
uint8_t button;
};
struct button_up
{
uint8_t button;
};
struct mouse_move
{
float x;
float y;
};
struct mouse_scroll
{
float h;
float v;
};
struct key_down
{
uint8_t key;
};
struct key_up
{
uint8_t key;
};
using input_t = std::variant<button_down, button_up, mouse_move, mouse_scroll, key_down, key_up>;
struct input
{
input_t input_data;
};
};
struct timesync_response
{
XrTime query;
XrTime response;
};
struct feedback
{
uint64_t frame_index;
uint8_t stream_index;
// Timestamps
XrTime encode_begin;
XrTime encode_end;
XrTime send_begin;
XrTime send_end;
XrTime received_first_packet;
XrTime received_last_packet;
XrTime sent_to_decoder;
XrTime received_from_decoder;
XrTime blitted;
XrTime displayed;
uint8_t times_displayed;
};
struct battery
{
device_id device;
std::optional<float> charge;
bool charging;
};
struct refresh_rate_changed
{
float from;
float to;
};
struct session_state_changed
{
XrSessionState state;
};
struct user_presence_changed
{
bool present;
XrTime change_time;
};
struct stream_tab_changed
{
stream_tab tab;
};
struct get_application_list
{
std::string language;
std::string country;
std::string variant;
};
struct start_app
{
std::string app_id;
};
struct get_running_applications
{};
struct set_active_application
{
uint32_t id;
};
struct stop_application
{
uint32_t id;
};
// when changing this, also make sure there are handlers in wivrn_session, etc. or compilation will fail
using packets = std::variant<
crypto_handshake,
pin_check_1,
pin_check_3,
headset_info_packet,
settings_changed,
feedback,
audio_data,
handshake,
tracking,
derived_pose,
hand_tracking,
meta_body,
meta_body_skeleton,
bd_body,
htc_body,
inputs,
timesync_response,
battery,
visibility_mask_changed,
refresh_rate_changed,
session_state_changed,
user_presence_changed,
stream_tab_changed,
get_application_list,
start_app,
get_running_applications,
set_active_application,
hid::input,
stop_application,
foveation>;
} // namespace from_headset
namespace to_headset
{
struct crypto_handshake
{
enum class crypto_state : uint8_t
{
encryption_disabled,
pin_needed,
client_already_paired,
pairing_disabled,
incompatible_version,
};
std::string public_key; // In PEM format
crypto_state state;
};
struct pin_check_2
{
crypto::smp::msg2 message;
};
struct pin_check_4
{
crypto::smp::msg4 message;
};
struct handshake
{
// -1 if stream socket should not be used
int stream_port;
};
struct server_message
{
enum class kind : uint8_t
{
// in-stream toasts (not buffered)
toast,
toast_urgent,
// displayed in lobby after disconnect (buffered)
error,
};
kind kind;
std::string msg;
};
struct foveation_parameter
{
// The number of source pixels for each ratio,
// the middle one is 1:1
//
// how to read it:
// 1, 4, 5, 3, 1 means:
// the first output pixel has 3 source pixels
// the 4 that come after have 2 source pixels
// then 5 with 1 source pixel
// 3 with 2 source pixels
// 1 with 3 source pixels
std::vector<uint16_t> x;
std::vector<uint16_t> y;
};
struct audio_stream_description
{
struct device
{
uint8_t num_channels;
uint32_t sample_rate;
};
std::optional<device> speaker;
std::optional<device> microphone;
};
struct video_stream_description
{
// dimensions of the video stream per eye
// alpha is half resolution
uint16_t width;
uint16_t height;
std::array<video_codec, 3> codec; // left, right, alpha
float frame_rate;
float refresh_rate;
bool operator==(const video_stream_description &) const = default;
};
class video_stream_data_shard
{
public:
inline static const size_t max_payload_size = 1400;
// Identifier of stream:
// 0 left
// 1 right
// 2 alpha
uint8_t stream_item_idx;
// Counter increased for each frame
uint64_t frame_idx;
// Identifier of the shard within the frame
uint16_t shard_idx;
// Position information, must be present on first video shard
struct view_info_t
{
// ns in headset time referential
XrTime display_time;
std::array<XrPosef, 2> pose;
std::array<XrFovf, 2> fov;
std::array<foveation_parameter, 2> foveation;
// True when the frame contains an alpha channel
bool alpha;
};
std::optional<view_info_t> view_info;
// Information about timing, on last video shard
struct timing_info_t
{
XrTime encode_begin;
XrTime encode_end;
XrTime send_begin;
XrTime send_end;
};
std::optional<timing_info_t> timing_info;
// Actual video data, may contain multiple NAL units
std::span<uint8_t> payload;
// Container for the data, read payload instead
data_holder data;
};
struct haptics
{
device_id id;
std::chrono::nanoseconds duration;
float frequency;
float amplitude;
};
struct timesync_query
{
XrTime query;
};
struct tracking_control
{
struct sample
{
device_id device;
XrDuration prediction_ns;
};
std::vector<sample> pattern;
XrDuration motions_to_photons;
};
struct feature_control
{
enum feature
{
hid_input,
microphone,
};
feature f;
bool state;
};
struct refresh_rate_change
{
float hz;
};
struct stream_tab_change
{
stream_tab tab;
};
struct application_list
{
std::string language;
std::string country;
std::string variant;
struct application
{
std::string id;
std::string name;
};
std::vector<application> applications;
};
struct application_icon
{
std::string id;
std::vector<std::byte> image; // In PNG
};
struct running_applications
{
struct application
{
std::string name;
uint32_t id;
bool overlay;
bool active;
};
std::vector<application> applications;
};
using packets = std::variant<
crypto_handshake,
pin_check_2,
pin_check_4,
handshake,
server_message,
audio_stream_description,
video_stream_description,
audio_data,
video_stream_data_shard,
haptics,
timesync_query,
tracking_control,
feature_control,
refresh_rate_change,
stream_tab_change,
application_list,
application_icon,
running_applications>;
} // namespace to_headset
} // namespace wivrn
template <>
struct magic_enum::customize::enum_range<wivrn::from_headset::body_part_mask>
{
static constexpr int min = 0;
static constexpr int max = static_cast<int>(wivrn::from_headset::body_part_mask::max) - 1;
};