Skip to content

Commit

Permalink
feat(server): ✨ Define draft libalvr API
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Oct 13, 2023
1 parent 1825ae1 commit b75503d
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions alvr/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ alvr_server_io.workspace = true
alvr_session.workspace = true
alvr_sockets.workspace = true

ash = "0.37"
bincode = "1"
bytes = "1"
chrono = "0.4"
Expand Down
267 changes: 267 additions & 0 deletions alvr/server/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
use ash::vk;
use std::{
ffi::{c_char, CStr},
time::Instant,
};

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrFov {
/// Negative, radians
pub left: f32,
/// Positive, radians
pub right: f32,
/// Positive, radians
pub up: f32,
/// Negative, radians
pub down: f32,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrQuat {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
impl Default for AlvrQuat {
fn default() -> Self {
Self {
x: 0.0,
y: 0.0,
z: 0.0,
w: 1.0,
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct AlvrPose {
orientation: AlvrQuat,
position: [f32; 3],
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrSpaceRelation {
pub pose: AlvrPose,
pub linear_velocity: [f32; 3],
pub angular_velocity: [f32; 3],
pub has_velocity: bool,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrJoint {
relation: AlvrSpaceRelation,
radius: f32,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrJointSet {
values: [AlvrJoint; 26],
global_hand_relation: AlvrSpaceRelation,
is_active: bool,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub union AlvrInputValue {
pub bool_: bool,
pub float_: f32,
}

// the profile is implied
#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrInput {
pub id: u64,
pub value: AlvrInputValue,
}

#[repr(u8)]
#[derive(Clone, Copy)]
pub enum AlvrOutput {
Haptics {

Check warning on line 88 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

variant `Haptics` is never constructed

warning: variant `Haptics` is never constructed --> alvr/server/src/c_api.rs:88:5 | 87 | pub enum AlvrOutput { | ---------- variant in this enum 88 | Haptics { | ^^^^^^^ | = note: `AlvrOutput` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default
frequency: f32,
amplitude: f32,
duration_ns: u64,
},
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrBatteryValue {
pub device_id: u64,
/// range [0, 1]
pub value: f32,
}

#[repr(C)]
pub enum AlvrEvent {
Battery(AlvrBatteryValue),

Check warning on line 105 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

variants `Battery`, `Bounds`, `Restart`, and `Shutdown` are never constructed

warning: variants `Battery`, `Bounds`, `Restart`, and `Shutdown` are never constructed --> alvr/server/src/c_api.rs:105:5 | 104 | pub enum AlvrEvent { | --------- variants in this enum 105 | Battery(AlvrBatteryValue), | ^^^^^^^ 106 | Bounds([f32; 2]), | ^^^^^^ 107 | Restart, | ^^^^^^^ 108 | Shutdown, | ^^^^^^^^
Bounds([f32; 2]),
Restart,
Shutdown,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrTargetConfig {
target_width: u32,
target_height: u32,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct AlvrDeviceConfig {
device_id: u64,
interaction_profile_id: u64,
}

// Get ALVR server time. The libalvr user should provide timestamps in the provided time frame of
// reference in the following functions
#[no_mangle]
pub unsafe extern "C" fn alvr_get_time_ns() -> u64 {
Instant::now().elapsed().as_nanos() as u64
}

// The libalvr user is responsible of interpreting values and calling functions using
// device/input/output identifiers obtained using this function
#[no_mangle]
pub unsafe extern "C" fn alvr_path_to_id(path_string: *const c_char) -> u64 {
alvr_common::hash_string(CStr::from_ptr(path_string).to_str().unwrap())
}

#[no_mangle]
pub unsafe extern "C" fn alvr_initialize(out_target_config: *mut AlvrTargetConfig) {

Check warning on line 140 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_target_config`

warning: unused variable: `out_target_config` --> alvr/server/src/c_api.rs:140:42 | 140 | pub unsafe extern "C" fn alvr_initialize(out_target_config: *mut AlvrTargetConfig) { | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_target_config` | = note: `#[warn(unused_variables)]` on by default
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool {

Check warning on line 145 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_event`

warning: unused variable: `out_event` --> alvr/server/src/c_api.rs:145:42 | 145 | pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_event`
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_shutdown() {
todo!()
}

// Device API:

// Use the two-call pattern to first get the array length then the array data.
#[no_mangle]
pub unsafe extern "C" fn alvr_get_devices(out_device_configs: *mut AlvrDeviceConfig) -> u64 {

Check warning on line 158 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_device_configs`

warning: unused variable: `out_device_configs` --> alvr/server/src/c_api.rs:158:43 | 158 | pub unsafe extern "C" fn alvr_get_devices(out_device_configs: *mut AlvrDeviceConfig) -> u64 { | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_device_configs`
todo!()
}

// After this call, previous button and tracking data is discarded
#[no_mangle]
pub unsafe extern "C" fn alvr_update_inputs(device_id: u64) {

Check warning on line 164 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `device_id`

warning: unused variable: `device_id` --> alvr/server/src/c_api.rs:164:45 | 164 | pub unsafe extern "C" fn alvr_update_inputs(device_id: u64) { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_device_id`
todo!()
}

// Use the two-call pattern to first get the array length then the array data.
// Data is updated after a call to alvr_update_inputs.
#[no_mangle]
pub unsafe extern "C" fn alvr_get_inputs(
device_id: u64,

Check warning on line 172 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `device_id`

warning: unused variable: `device_id` --> alvr/server/src/c_api.rs:172:5 | 172 | device_id: u64, | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_device_id`
out_inputs_arr: *mut AlvrInput,

Check warning on line 173 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_inputs_arr`

warning: unused variable: `out_inputs_arr` --> alvr/server/src/c_api.rs:173:5 | 173 | out_inputs_arr: *mut AlvrInput, | ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_inputs_arr`
out_timestamp_ns: u64,

Check warning on line 174 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_timestamp_ns`

warning: unused variable: `out_timestamp_ns` --> alvr/server/src/c_api.rs:174:5 | 174 | out_timestamp_ns: u64, | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_timestamp_ns`
) -> u64 {
todo!()
}

// pose_id is something like /user/hand/left/input/grip/pose
#[no_mangle]
pub unsafe extern "C" fn alvr_get_tracked_pose(
pose_id: u64,

Check warning on line 182 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `pose_id`

warning: unused variable: `pose_id` --> alvr/server/src/c_api.rs:182:5 | 182 | pose_id: u64, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_pose_id`
timestamp_ns: u64,

Check warning on line 183 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `timestamp_ns`

warning: unused variable: `timestamp_ns` --> alvr/server/src/c_api.rs:183:5 | 183 | timestamp_ns: u64, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_timestamp_ns`
out_relation: *mut AlvrSpaceRelation,

Check warning on line 184 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_relation`

warning: unused variable: `out_relation` --> alvr/server/src/c_api.rs:184:5 | 184 | out_relation: *mut AlvrSpaceRelation, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_relation`
) {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_get_hand_tracking(
device_id: u64,

Check warning on line 191 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `device_id`

warning: unused variable: `device_id` --> alvr/server/src/c_api.rs:191:5 | 191 | device_id: u64, | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_device_id`
timestamp_ns: u64,

Check warning on line 192 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `timestamp_ns`

warning: unused variable: `timestamp_ns` --> alvr/server/src/c_api.rs:192:5 | 192 | timestamp_ns: u64, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_timestamp_ns`
out_joint_set: *mut AlvrJointSet,

Check warning on line 193 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_joint_set`

warning: unused variable: `out_joint_set` --> alvr/server/src/c_api.rs:193:5 | 193 | out_joint_set: *mut AlvrJointSet, | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_joint_set`
) {
todo!()
}

// Currently only haptics is supported
#[no_mangle]
pub unsafe extern "C" fn alvr_set_output(output_id: u64, value: *const AlvrOutput) {

Check warning on line 200 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `value`

warning: unused variable: `value` --> alvr/server/src/c_api.rs:200:58 | 200 | pub unsafe extern "C" fn alvr_set_output(output_id: u64, value: *const AlvrOutput) { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_value`

Check warning on line 200 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `output_id`

warning: unused variable: `output_id` --> alvr/server/src/c_api.rs:200:42 | 200 | pub unsafe extern "C" fn alvr_set_output(output_id: u64, value: *const AlvrOutput) { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_output_id`
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_view_poses(
out_head_relation: *mut AlvrSpaceRelation,

Check warning on line 206 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_head_relation`

warning: unused variable: `out_head_relation` --> alvr/server/src/c_api.rs:206:5 | 206 | out_head_relation: *mut AlvrSpaceRelation, | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_head_relation`
out_fov_arr: *mut AlvrFov, // 2 elements

Check warning on line 207 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_fov_arr`

warning: unused variable: `out_fov_arr` --> alvr/server/src/c_api.rs:207:5 | 207 | out_fov_arr: *mut AlvrFov, // 2 elements | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_fov_arr`
out_relative_pose_arr: *mut AlvrPose, // 2 elements

Check warning on line 208 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_relative_pose_arr`

warning: unused variable: `out_relative_pose_arr` --> alvr/server/src/c_api.rs:208:5 | 208 | out_relative_pose_arr: *mut AlvrPose, // 2 elements | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_relative_pose_arr`
) {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_destroy_device(device_id: u64) {

Check warning on line 214 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `device_id`

warning: unused variable: `device_id` --> alvr/server/src/c_api.rs:214:46 | 214 | pub unsafe extern "C" fn alvr_destroy_device(device_id: u64) { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_device_id`
todo!()
}

// Compositor target API:

// This should reflect the client current framerate
#[no_mangle]
pub unsafe extern "C" fn alvr_get_framerate() -> f32 {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_pre_vulkan() {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_post_vulkan() {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_create_vk_target_swapchain(
width: u32,

Check warning on line 238 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `width`

warning: unused variable: `width` --> alvr/server/src/c_api.rs:238:5 | 238 | width: u32, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_width`
height: u32,

Check warning on line 239 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `height`

warning: unused variable: `height` --> alvr/server/src/c_api.rs:239:5 | 239 | height: u32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_height`
color_format: vk::Format,

Check warning on line 240 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `color_format`

warning: unused variable: `color_format` --> alvr/server/src/c_api.rs:240:5 | 240 | color_format: vk::Format, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_color_format`
color_space: vk::ColorSpaceKHR,

Check warning on line 241 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `color_space`

warning: unused variable: `color_space` --> alvr/server/src/c_api.rs:241:5 | 241 | color_space: vk::ColorSpaceKHR, | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_color_space`
image_usage: vk::ImageUsageFlags,

Check warning on line 242 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `image_usage`

warning: unused variable: `image_usage` --> alvr/server/src/c_api.rs:242:5 | 242 | image_usage: vk::ImageUsageFlags, | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_image_usage`
present_mode: vk::PresentModeKHR,

Check warning on line 243 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `present_mode`

warning: unused variable: `present_mode` --> alvr/server/src/c_api.rs:243:5 | 243 | present_mode: vk::PresentModeKHR, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_present_mode`
image_count: u64,

Check warning on line 244 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `image_count`

warning: unused variable: `image_count` --> alvr/server/src/c_api.rs:244:5 | 244 | image_count: u64, | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_image_count`
) {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_acquire_image(out_swapchain_index: u64) -> vk::Result {

Check warning on line 250 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `out_swapchain_index`

warning: unused variable: `out_swapchain_index` --> alvr/server/src/c_api.rs:250:45 | 250 | pub unsafe extern "C" fn alvr_acquire_image(out_swapchain_index: u64) -> vk::Result { | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_swapchain_index`
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_present(
queue: vk::Queue,

Check warning on line 256 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `queue`

warning: unused variable: `queue` --> alvr/server/src/c_api.rs:256:5 | 256 | queue: vk::Queue, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_queue`
swapchain_index: u64,

Check warning on line 257 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `swapchain_index`

warning: unused variable: `swapchain_index` --> alvr/server/src/c_api.rs:257:5 | 257 | swapchain_index: u64, | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_swapchain_index`
timeline_semaphore_value: u64,

Check warning on line 258 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `timeline_semaphore_value`

warning: unused variable: `timeline_semaphore_value` --> alvr/server/src/c_api.rs:258:5 | 258 | timeline_semaphore_value: u64, | ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_timeline_semaphore_value`
timestamp_ns: u64,

Check warning on line 259 in alvr/server/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `timestamp_ns`

warning: unused variable: `timestamp_ns` --> alvr/server/src/c_api.rs:259:5 | 259 | timestamp_ns: u64, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_timestamp_ns`
) -> vk::Result {
todo!()
}

#[no_mangle]
pub unsafe extern "C" fn alvr_destroy_vk_target_swapchain() {
todo!()
}
1 change: 1 addition & 0 deletions alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod bitrate;
mod c_api;
mod connection;
mod face_tracking;
mod hand_gestures;
Expand Down

0 comments on commit b75503d

Please sign in to comment.