Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking rewrite #2481

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
@@ -3,7 +3,7 @@ resolver = "2"
members = ["alvr/*"]

[workspace.package]
version = "21.0.0-dev01"
version = "21.0.0-dev02"
edition = "2021"
rust-version = "1.81"
authors = ["alvr-org"]
15 changes: 10 additions & 5 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use alvr_common::{
dbg_connection, debug, error, info,
parking_lot::{Condvar, Mutex, RwLock},
wait_rwlock, warn, AnyhowToCon, ConResult, ConnectionError, ConnectionState, LifecycleState,
Pose, RelaxedAtomic, ALVR_VERSION,
RelaxedAtomic, ALVR_VERSION,
};
use alvr_packets::{
ClientConnectionResult, ClientControlPacket, ClientStatistics, Haptics, ServerControlPacket,
@@ -65,9 +65,7 @@ pub struct ConnectionContext {
pub statistics_sender: Mutex<Option<StreamSender<ClientStatistics>>>,
pub statistics_manager: Mutex<Option<StatisticsManager>>,
pub decoder_callback: Mutex<Option<Box<DecoderCallback>>>,
pub head_pose_queue: RwLock<VecDeque<(Duration, Pose)>>,
pub last_good_head_pose: RwLock<Pose>,
pub view_params: RwLock<[ViewParams; 2]>,
pub view_params_queue: RwLock<VecDeque<(Duration, [ViewParams; 2])>>,
pub uses_multimodal_protocol: RelaxedAtomic,
pub velocities_multiplier: RwLock<f32>,
pub max_prediction: RwLock<Duration>,
@@ -322,7 +320,14 @@ fn connection_pipeline(
.map(|callback| callback(header.timestamp, nal))
.unwrap_or(false);

if !submitted {
if submitted {
let view_params_lock = &mut *ctx.view_params_queue.write();
view_params_lock.push_back((header.timestamp, header.views_params));

if view_params_lock.len() > 1024 {
view_params_lock.pop_front();
}
} else {
stream_corrupted = true;
if let Some(sender) = &mut *ctx.control_sender.lock() {
sender.send(&ClientControlPacket::RequestIdr).ok();
67 changes: 14 additions & 53 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -22,11 +22,10 @@ use alvr_common::{
glam::{UVec2, Vec2, Vec3},
parking_lot::{Mutex, RwLock},
warn, ConnectionState, DeviceMotion, LifecycleState, Pose, HAND_LEFT_ID, HAND_RIGHT_ID,
HEAD_ID,
};
use alvr_packets::{
BatteryInfo, ButtonEntry, ClientControlPacket, FaceData, RealTimeConfig,
ReservedClientControlPacket, StreamConfig, Tracking, ViewParams, ViewsConfig,
ReservedClientControlPacket, StreamConfig, Tracking, ViewParams,
};
use alvr_session::CodecType;
use connection::{ConnectionContext, DecoderCallback};
@@ -212,15 +211,8 @@ impl ClientCoreContext {
pub fn send_view_params(&self, views: [ViewParams; 2]) {
dbg_client_core!("send_view_params");

*self.connection_context.view_params.write() = views;

if let Some(sender) = &mut *self.connection_context.control_sender.lock() {
sender
.send(&ClientControlPacket::ViewsConfig(ViewsConfig {
fov: [views[0].fov, views[1].fov],
ipd_m: (views[0].pose.position - views[1].pose.position).length(),
}))
.ok();
sender.send(&ClientControlPacket::ViewsParams(views)).ok();
}
}

@@ -243,34 +235,13 @@ impl ClientCoreContext {
poll_timestamp
};

// Guarantee that sent timestamps never go backwards by sending the poll time
let reported_timestamp = poll_timestamp;

for (id, motion) in &mut device_motions {
{
let velocity_multiplier = *self.connection_context.velocities_multiplier.read();
motion.linear_velocity *= velocity_multiplier;
motion.angular_velocity *= velocity_multiplier;

if *id == *HEAD_ID {
*motion = motion.predict(poll_timestamp, target_timestamp);

let mut head_pose_queue = self.connection_context.head_pose_queue.write();

head_pose_queue.push_back((reported_timestamp, motion.pose));

while head_pose_queue.len() > 1024 {
head_pose_queue.pop_front();
if velocity_multiplier != 1.0 {
for (_, motion) in &mut device_motions {
motion.linear_velocity *= velocity_multiplier;
motion.angular_velocity *= velocity_multiplier;
}

// This is done for backward compatibiity for the v20 protocol. Will be removed with the
// tracking rewrite protocol extension.
motion.linear_velocity = Vec3::ZERO;
motion.angular_velocity = Vec3::ZERO;
} else if let Some(stats) = &*self.connection_context.statistics_manager.lock() {
let tracker_timestamp = poll_timestamp
+ Duration::min(stats.tracker_prediction_offset(), max_prediction);

*motion = motion.predict(poll_timestamp, tracker_timestamp);
}
}

@@ -303,15 +274,15 @@ impl ClientCoreContext {
if let Some(sender) = &mut *self.connection_context.tracking_sender.lock() {
sender
.send_header(&Tracking {
target_timestamp: reported_timestamp,
target_timestamp,
device_motions,
hand_skeletons,
face_data,
})
.ok();

if let Some(stats) = &mut *self.connection_context.statistics_manager.lock() {
stats.report_input_acquired(reported_timestamp);
stats.report_input_acquired(target_timestamp);
}
}
}
@@ -359,25 +330,15 @@ impl ClientCoreContext {
stats.report_compositor_start(timestamp);
}

let mut head_pose = *self.connection_context.last_good_head_pose.read();
for (ts, pose) in &*self.connection_context.head_pose_queue.read() {
let mut view_params = [ViewParams::default(); 2];
for (ts, vp) in &*self.connection_context.view_params_queue.read() {
if *ts == timestamp {
head_pose = *pose;
view_params = *vp;
break;
}
}
let view_params = self.connection_context.view_params.read();

[
ViewParams {
pose: head_pose * view_params[0].pose,
fov: view_params[0].fov,
},
ViewParams {
pose: head_pose * view_params[1].pose,
fov: view_params[1].fov,
},
]

view_params
}

pub fn report_submit(&self, timestamp: Duration, vsync_queue: Duration) {
6 changes: 5 additions & 1 deletion alvr/client_openxr/src/stream.rs
Original file line number Diff line number Diff line change
@@ -423,7 +423,11 @@ impl StreamContext {
.map(|mode| ProjectionLayerAlphaConfig {
premultiplied: matches!(
mode,
PassthroughMode::AugmentedReality { .. } | PassthroughMode::ChromaKey(_)
PassthroughMode::Blend {
premultiplied_alpha: true,
..
} | PassthroughMode::RgbChromaKey(_)
| PassthroughMode::HsvChromaKey(_)
),
}),
);
Loading
Loading