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 3 commits into
base: master
Choose a base branch
from
Draft
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
42 changes: 21 additions & 21 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-dev01"
version = "21.0.0-dev02"
edition = "2021"
rust-version = "1.82"
authors = ["alvr-org"]
Expand Down
15 changes: 10 additions & 5 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -317,7 +315,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();
Expand Down
55 changes: 7 additions & 48 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ use alvr_common::{
glam::{Quat, 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, ReservedClientControlPacket,
StreamConfig, Tracking, ViewParams, ViewsConfig,
StreamConfig, Tracking, ViewParams,
};
use alvr_session::CodecType;
use connection::{ConnectionContext, DecoderCallback};
Expand Down Expand Up @@ -213,15 +212,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();
}
}

Expand All @@ -241,29 +233,6 @@ impl ClientCoreContext {
poll_timestamp
};

for (id, motion) in &mut device_motions {
if *id == *HEAD_ID {
*motion = predict_motion(target_timestamp, poll_timestamp, *motion);

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

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

while head_pose_queue.len() > 1024 {
head_pose_queue.pop_front();
}

// 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 + stats.tracker_prediction_offset();

*motion = predict_motion(tracker_timestamp, poll_timestamp, *motion);
}
}

// send_tracking() expects hand data in the multimodal protocol. In case multimodal protocol
// is not supported, convert back to legacy protocol.
if !self.connection_context.uses_multimodal_protocol.value() {
Expand Down Expand Up @@ -339,25 +308,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) {
Expand Down
11 changes: 3 additions & 8 deletions alvr/packets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ pub enum ServerControlPacket {
ReservedBuffer(Vec<u8>),
}

#[derive(Serialize, Deserialize, Clone)]
pub struct ViewsConfig {
// Note: the head-to-eye transform is always a translation along the x axis
pub ipd_m: f32,
pub fov: [Fov; 2],
}

#[derive(Serialize, Deserialize, Clone)]
pub struct BatteryInfo {
pub device_id: u64,
Expand Down Expand Up @@ -257,7 +250,7 @@ pub enum ClientControlPacket {
RequestIdr,
KeepAlive,
StreamReady, // This flag notifies the server the client streaming socket is ready listening
ViewsConfig(ViewsConfig),
ViewsParams([ViewParams; 2]), // Local frame of reference
Battery(BatteryInfo),
VideoErrorReport, // legacy
Buttons(Vec<ButtonEntry>),
Expand All @@ -278,6 +271,8 @@ pub struct FaceData {
#[derive(Serialize, Deserialize)]
pub struct VideoPacketHeader {
pub timestamp: Duration,
// These view params are in global reference frame
pub views_params: [ViewParams; 2],
pub is_idr: bool,
}

Expand Down
Loading
Loading