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

fix: Avoid sending garbage to VRCFT #2669

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
18 changes: 4 additions & 14 deletions alvr/server_core/src/tracking/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alvr_common::{anyhow::Result, glam::EulerRot};
use alvr_packets::FaceData;
use alvr_session::FaceTrackingSinkConfig;
use rosc::{OscMessage, OscPacket, OscType};
use std::{f32::consts::PI, mem, net::UdpSocket};
use std::{f32::consts::PI, net::UdpSocket};

const RAD_TO_DEG: f32 = 180.0 / PI;

Expand All @@ -12,7 +12,6 @@ pub struct FaceTrackingSink {
config: FaceTrackingSinkConfig,
socket: UdpSocket,
packet_buffer: Vec<u8>,
packet_cursor: usize,
}

impl FaceTrackingSink {
Expand All @@ -29,7 +28,6 @@ impl FaceTrackingSink {
config,
socket,
packet_buffer: vec![],
packet_cursor: 0,
})
}

Expand All @@ -46,18 +44,10 @@ impl FaceTrackingSink {
}

fn append_packet_vrcft(&mut self, prefix: &[u8; 8], data: &[f32]) {
let new_buffer_len = self.packet_cursor + prefix.len() + data.len() * 4;
if self.packet_buffer.len() < new_buffer_len {
self.packet_buffer.resize(new_buffer_len, 0);
}

self.packet_buffer[self.packet_cursor..][..prefix.len()].copy_from_slice(prefix.as_slice());
self.packet_cursor += prefix.len();
self.packet_buffer.extend(prefix);

for val in data {
self.packet_buffer[self.packet_cursor..][..mem::size_of::<f32>()]
.copy_from_slice(&val.to_le_bytes());
self.packet_cursor += mem::size_of::<f32>();
self.packet_buffer.extend(val.to_le_bytes());
}
}

Expand Down Expand Up @@ -112,7 +102,7 @@ impl FaceTrackingSink {
}
}
FaceTrackingSinkConfig::VrcFaceTracking { .. } => {
self.packet_cursor = 0;
self.packet_buffer.clear();

match face_data.eye_gazes {
[Some(left_quat), Some(right_quat)] => {
Expand Down
Loading