feat(server): Define draft libalvr API

This commit is contained in:
Riccardo Zaglia 2023-10-14 00:22:28 +08:00
parent 1825ae1b58
commit b75503d7a3
4 changed files with 270 additions and 0 deletions

1
Cargo.lock generated
View File

@ -348,6 +348,7 @@ dependencies = [
"alvr_server_io",
"alvr_session",
"alvr_sockets",
"ash",
"bincode",
"bindgen 0.66.1",
"bytes",

View File

@ -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"

267
alvr/server/src/c_api.rs Normal file
View File

@ -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 {
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),
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) {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool {
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 {
todo!()
}
// After this call, previous button and tracking data is discarded
#[no_mangle]
pub unsafe extern "C" fn alvr_update_inputs(device_id: u64) {
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,
out_inputs_arr: *mut AlvrInput,
out_timestamp_ns: u64,
) -> 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,
timestamp_ns: u64,
out_relation: *mut AlvrSpaceRelation,
) {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_get_hand_tracking(
device_id: u64,
timestamp_ns: u64,
out_joint_set: *mut AlvrJointSet,
) {
todo!()
}
// Currently only haptics is supported
#[no_mangle]
pub unsafe extern "C" fn alvr_set_output(output_id: u64, value: *const AlvrOutput) {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_view_poses(
out_head_relation: *mut AlvrSpaceRelation,
out_fov_arr: *mut AlvrFov, // 2 elements
out_relative_pose_arr: *mut AlvrPose, // 2 elements
) {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_destroy_device(device_id: u64) {
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,
height: u32,
color_format: vk::Format,
color_space: vk::ColorSpaceKHR,
image_usage: vk::ImageUsageFlags,
present_mode: vk::PresentModeKHR,
image_count: u64,
) {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_acquire_image(out_swapchain_index: u64) -> vk::Result {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_present(
queue: vk::Queue,
swapchain_index: u64,
timeline_semaphore_value: u64,
timestamp_ns: u64,
) -> vk::Result {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn alvr_destroy_vk_target_swapchain() {
todo!()
}

View File

@ -1,4 +1,5 @@
mod bitrate;
mod c_api;
mod connection;
mod face_tracking;
mod hand_gestures;