Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["alvr/*"]

[workspace.package]
version = "21.0.0-dev10"
version = "21.0.0-dev11"
edition = "2024"
rust-version = "1.88"
authors = ["alvr-org"]
Expand Down
10 changes: 9 additions & 1 deletion alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ use alvr_sockets::{
};
use std::{
collections::VecDeque,
sync::{Arc, mpsc},
sync::{
Arc,
atomic::{AtomicBool, Ordering},
mpsc,
},
thread,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -90,6 +94,7 @@ pub fn connection_lifecycle_loop(
ctx: Arc<ConnectionContext>,
lifecycle_state: Arc<RwLock<LifecycleState>>,
event_queue: Arc<Mutex<VecDeque<ClientCoreEvent>>>,
headset_is_worn: Arc<AtomicBool>,
) {
dbg_connection!("connection_lifecycle_loop: Begin");

Expand All @@ -102,6 +107,7 @@ pub fn connection_lifecycle_loop(
Arc::clone(&ctx),
Arc::clone(&lifecycle_state),
Arc::clone(&event_queue),
Arc::clone(&headset_is_worn),
) {
let message = format!("Connection error:\n{e}\nCheck the PC for more details");
set_hud_message(&event_queue, &message);
Expand All @@ -125,6 +131,7 @@ fn connection_pipeline(
ctx: Arc<ConnectionContext>,
lifecycle_state: Arc<RwLock<LifecycleState>>,
event_queue: Arc<Mutex<VecDeque<ClientCoreEvent>>>,
headset_is_worn: Arc<AtomicBool>,
) -> ConResult {
dbg_connection!("connection_pipeline: Begin");

Expand Down Expand Up @@ -165,6 +172,7 @@ fn connection_pipeline(
.send(&ClientConnectionResult::ConnectionAccepted {
client_protocol_id: alvr_common::protocol_id_u64(),
display_name: alvr_system_info::platform().to_string(),
headset_is_worn: headset_is_worn.load(Ordering::Acquire),
server_ip,
streaming_capabilities: Some(
VideoStreamingCapabilities {
Expand Down
20 changes: 19 additions & 1 deletion alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use alvr_session::CodecType;
use connection::{ConnectionContext, DecoderCallback};
use std::{
collections::{HashSet, VecDeque},
sync::Arc,
sync::{
Arc,
atomic::{AtomicBool, Ordering},
},
thread::{self, JoinHandle},
time::Duration,
};
Expand Down Expand Up @@ -77,6 +80,7 @@ pub struct ClientCoreContext {
connection_context: Arc<ConnectionContext>,
connection_thread: Arc<Mutex<Option<JoinHandle<()>>>>,
last_good_global_view_params: Mutex<[ViewParams; 2]>,
headset_is_worn: Arc<AtomicBool>,
}

impl ClientCoreContext {
Expand All @@ -99,16 +103,19 @@ impl ClientCoreContext {
let lifecycle_state = Arc::new(RwLock::new(LifecycleState::Idle));
let event_queue = Arc::new(Mutex::new(VecDeque::new()));
let connection_context = Arc::new(ConnectionContext::default());
let headset_is_worn = Arc::new(AtomicBool::new(true));
let connection_thread = thread::spawn({
let lifecycle_state = Arc::clone(&lifecycle_state);
let connection_context = Arc::clone(&connection_context);
let event_queue = Arc::clone(&event_queue);
let headset_is_worn = Arc::clone(&headset_is_worn);
move || {
connection::connection_lifecycle_loop(
capabilities,
connection_context,
lifecycle_state,
event_queue,
headset_is_worn,
)
}
});
Expand All @@ -119,6 +126,7 @@ impl ClientCoreContext {
connection_context,
connection_thread: Arc::new(Mutex::new(Some(connection_thread))),
last_good_global_view_params: Mutex::new([ViewParams::DUMMY; 2]),
headset_is_worn,
}
}

Expand Down Expand Up @@ -222,6 +230,16 @@ impl ClientCoreContext {
}
}

pub fn send_proximity_state(&self, headset_is_worn: bool) {
self.headset_is_worn
.store(headset_is_worn, Ordering::Release);
if let Some(sender) = &mut *self.connection_context.control_sender.lock() {
sender
.send(&ClientControlPacket::ProximityState(headset_is_worn))
.ok();
}
}

pub fn get_total_prediction_offset(&self) -> Duration {
dbg_client_core!("get_total_prediction_offset");

Expand Down
5 changes: 5 additions & 0 deletions alvr/client_openxr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub fn entry_point() {
exts.ext_eye_gaze_interaction = available_extensions.ext_eye_gaze_interaction;
exts.ext_hand_tracking = available_extensions.ext_hand_tracking;
exts.ext_local_floor = available_extensions.ext_local_floor;
exts.ext_user_presence = available_extensions.ext_user_presence;
exts.fb_body_tracking = available_extensions.fb_body_tracking;
exts.fb_color_space = available_extensions.fb_color_space;
exts.fb_composition_layer_settings = available_extensions.fb_composition_layer_settings;
Expand Down Expand Up @@ -378,6 +379,10 @@ pub fn entry_point() {
| xr::Event::PassthroughStateChangedFB(_) => {
// todo
}
xr::Event::UserPresenceChangedEXT(event) => {
alvr_common::info!("user present: {:?}", event.is_user_present());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be an info log, but a debug one (and also preferrably import it directly)

core_context.send_proximity_state(event.is_user_present());
}
_ => (),
}
}
Expand Down
2 changes: 2 additions & 0 deletions alvr/packets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum ClientConnectionResult {
ConnectionAccepted {
client_protocol_id: u64,
display_name: String,
headset_is_worn: bool,
server_ip: IpAddr,
streaming_capabilities: Option<VideoStreamingCapabilities>,
},
Expand Down Expand Up @@ -193,6 +194,7 @@ pub enum ClientControlPacket {
level: LogSeverity,
message: String,
},
ProximityState(bool),
Reserved(String),
ReservedBuffer(Vec<u8>),
}
Expand Down
10 changes: 7 additions & 3 deletions alvr/server_core/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct AlvrBatteryInfo {

#[repr(u8)]
pub enum AlvrEvent {
ClientConnected,
ClientConnected { headset_is_worn: bool },
ClientDisconnected,
Battery(AlvrBatteryInfo),
PlayspaceSync([f32; 2]),
Expand All @@ -71,6 +71,7 @@ pub enum AlvrEvent {
CaptureFrame,
RestartPending,
ShutdownPending,
ProximityState(bool),
}

#[repr(C)]
Expand Down Expand Up @@ -252,8 +253,8 @@ pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent, timeout_ns:
&& let Ok(event) = receiver.recv_timeout(Duration::from_nanos(timeout_ns))
{
match event {
ServerCoreEvent::ClientConnected => unsafe {
*out_event = AlvrEvent::ClientConnected;
ServerCoreEvent::ClientConnected { headset_is_worn } => unsafe {
*out_event = AlvrEvent::ClientConnected { headset_is_worn };
},
ServerCoreEvent::ClientDisconnected => unsafe {
*out_event = AlvrEvent::ClientDisconnected;
Expand Down Expand Up @@ -293,6 +294,9 @@ pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent, timeout_ns:
},
ServerCoreEvent::GameRenderLatencyFeedback(_)
| ServerCoreEvent::SetOpenvrProperty { .. } => {} // implementation not needed
ServerCoreEvent::ProximityState(headset_is_worn) => unsafe {
*out_event = AlvrEvent::ProximityState(headset_is_worn);
},
}

true
Expand Down
Loading