mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(core): harden OpenXR/Vulkan lifecycle, DVR composited mode, and telemetry CRC validation
- Accept 'composited' and 'osd' in DvrMode::from_str, set filesink location via GObject property, and avoid overwriting files within the same second - Validate MAVLink v1/v2 CRC-16 and CRSF CRC-8 DVB-S2 in TelemetryReceiver, join UDP worker thread on Drop, and preserve UTF-8 char boundaries in StackStr - Ensure OpenXR swapchain image release and session.end() on error paths, reuse pre-allocated raw frame buffer in render loops, and remove forced monado.service stop - Make egui SSH/RNDIS helper scripts non-blocking and flush log file buffer only on Warn/Error
This commit is contained in:
1 parent
b8f2f00f09
commit
26279836d9
7 files changed
+568
-473
No files matched your search
+329
-367
@@ -61,8 +61,6 @@ pub struct RuntimeMonitor {
|
||||
pub preview_width: u32,
|
||||
pub preview_height: u32,
|
||||
pub preview_frame_seq: u64,
|
||||
#[allow(dead_code)]
|
||||
pub manual_override_enabled: bool,
|
||||
pub manual_pan_deg: f32,
|
||||
pub manual_tilt_deg: f32,
|
||||
pub manual_roll_deg: f32,
|
||||
@@ -90,7 +88,6 @@ impl Default for RuntimeMonitor {
|
||||
preview_width: 0,
|
||||
preview_height: 0,
|
||||
preview_frame_seq: 0,
|
||||
manual_override_enabled: false,
|
||||
manual_pan_deg: 0.0,
|
||||
manual_tilt_deg: 0.0,
|
||||
manual_roll_deg: 0.0,
|
||||
@@ -205,27 +202,6 @@ impl FpvEngineController {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_optical_params(&self, opt: LiveOpticalParams) {
|
||||
*self.optical_params.lock() = opt;
|
||||
}
|
||||
|
||||
pub fn update_dvr_config(&self, dir: String, container: DvrContainer, mode: DvrMode) {
|
||||
*self.dvr_config.lock() = DvrConfig { dir, container, mode };
|
||||
}
|
||||
|
||||
pub fn start_dvr(&self) {
|
||||
*self.dvr_toggle_cmd.lock() = Some(true);
|
||||
}
|
||||
|
||||
pub fn stop_dvr(&self) {
|
||||
*self.dvr_toggle_cmd.lock() = Some(false);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_dvr_recording(&self) -> bool {
|
||||
self.monitor.lock().dvr_recording
|
||||
}
|
||||
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.worker_handle
|
||||
.as_ref()
|
||||
@@ -233,38 +209,14 @@ impl FpvEngineController {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn request_recenter(&self) {
|
||||
self.recenter_flag.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
pub fn is_telemetry_enabled(&self) -> bool {
|
||||
self.telemetry_enabled_flag.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn set_telemetry_enabled(&self, enabled: bool) {
|
||||
let prev = self.telemetry_enabled_flag.swap(enabled, Ordering::AcqRel);
|
||||
if prev != enabled {
|
||||
log::info!(
|
||||
"[Action Utilisateur] Télémétrie & OSD basculés sur : {}",
|
||||
if enabled { "ON (Activé)" } else { "OFF (Désactivé)" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_head_tracking_enabled(&self) -> bool {
|
||||
self.head_tracking_enabled_flag.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn set_head_tracking_enabled(&self, enabled: bool) {
|
||||
let prev = self.head_tracking_enabled_flag.swap(enabled, Ordering::AcqRel);
|
||||
if prev != enabled {
|
||||
log::info!(
|
||||
"[Action Utilisateur] Suivi de Tête (RadioMaster Nomad) basculé sur : {}",
|
||||
if enabled { "ON (Activé)" } else { "OFF (Désactivé)" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&mut self) {
|
||||
self.stop_flag.store(true, Ordering::Release);
|
||||
if let Some(handle) = self.worker_handle.take() {
|
||||
@@ -272,14 +224,6 @@ impl FpvEngineController {
|
||||
let _ = handle.join();
|
||||
}
|
||||
|
||||
// Sur Linux, s'assurer que la fenêtre de simulation de Monado ne reste pas bloquée
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let _ = std::process::Command::new("systemctl")
|
||||
.args(["--user", "stop", "monado.service"])
|
||||
.output();
|
||||
}
|
||||
|
||||
let mut mon = self.monitor.lock();
|
||||
mon.usb_video_status = SubsystemStatus::Stopped;
|
||||
mon.openxr_status = SubsystemStatus::Stopped;
|
||||
@@ -825,6 +769,8 @@ fn try_run_openxr_session(
|
||||
cfg.lens_k1,
|
||||
cfg.lens_k2,
|
||||
);
|
||||
let mut raw_frame_buf: Vec<u8> =
|
||||
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
||||
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||
|
||||
let session = vk_xr
|
||||
@@ -848,364 +794,376 @@ fn try_run_openxr_session(
|
||||
let mut fps_timer = Instant::now();
|
||||
let mut last_frame_id: u64 = 0;
|
||||
|
||||
while !stop_flag.load(Ordering::Relaxed) || session_running {
|
||||
let cur_opt = optical_params.lock().clone();
|
||||
if !dome_lut.matches_params(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
cur_opt.camera_fov_deg,
|
||||
cur_opt.lens_k1,
|
||||
cur_opt.lens_k2,
|
||||
) {
|
||||
dome_lut = DomeWarpLut::new(
|
||||
let loop_res: Result<()> = (|| {
|
||||
while !stop_flag.load(Ordering::Relaxed) || session_running {
|
||||
let cur_opt = optical_params.lock().clone();
|
||||
if !dome_lut.matches_params(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
cur_opt.camera_fov_deg,
|
||||
cur_opt.lens_k1,
|
||||
cur_opt.lens_k2,
|
||||
);
|
||||
}
|
||||
|
||||
let active_proj = match cur_opt.projection_mode {
|
||||
ProjectionMode::Dome140 if enabled_extensions.khr_composition_layer_equirect2 => {
|
||||
ProjectionMode::Dome140
|
||||
) {
|
||||
dome_lut = DomeWarpLut::new(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
cur_opt.camera_fov_deg,
|
||||
cur_opt.lens_k1,
|
||||
cur_opt.lens_k2,
|
||||
);
|
||||
}
|
||||
ProjectionMode::Dome140 if enabled_extensions.khr_composition_layer_cylinder => {
|
||||
ProjectionMode::Cylinder140
|
||||
}
|
||||
ProjectionMode::Cylinder140 if enabled_extensions.khr_composition_layer_cylinder => {
|
||||
ProjectionMode::Cylinder140
|
||||
}
|
||||
_ => ProjectionMode::FlatQuad,
|
||||
};
|
||||
|
||||
handle_dvr_lifecycle(
|
||||
dvr_cmd,
|
||||
dvr_cfg,
|
||||
active_dvr,
|
||||
video_rx_opt,
|
||||
cfg,
|
||||
monitor,
|
||||
);
|
||||
|
||||
let telem_on = telem_enabled_flag.load(Ordering::Relaxed);
|
||||
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
||||
|
||||
let ht_on = ht_enabled_flag.load(Ordering::Relaxed);
|
||||
sync_head_tracker(cfg, ht_on, head_tracker_opt, monitor);
|
||||
|
||||
// Si l'arrêt de l'application est demandé et que la session tourne encore, notifier proprement le runtime
|
||||
if stop_flag.load(Ordering::Relaxed) && !exiting {
|
||||
exiting = true;
|
||||
exit_deadline = Some(Instant::now() + Duration::from_millis(1500));
|
||||
log::info!("[OpenXR] Arrêt demandé, notification du runtime (request_exit)...");
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
match s.request_exit() {
|
||||
Ok(()) => {}
|
||||
Err(xr::sys::Result::ERROR_SESSION_NOT_RUNNING) => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("[OpenXR] Erreur lors de request_exit : {}", e);
|
||||
break;
|
||||
}
|
||||
let active_proj = match cur_opt.projection_mode {
|
||||
ProjectionMode::Dome140 if enabled_extensions.khr_composition_layer_equirect2 => {
|
||||
ProjectionMode::Dome140
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ProjectionMode::Dome140 if enabled_extensions.khr_composition_layer_cylinder => {
|
||||
ProjectionMode::Cylinder140
|
||||
}
|
||||
ProjectionMode::Cylinder140 if enabled_extensions.khr_composition_layer_cylinder => {
|
||||
ProjectionMode::Cylinder140
|
||||
}
|
||||
_ => ProjectionMode::FlatQuad,
|
||||
};
|
||||
|
||||
// Si en cours de sortie et dépassement du délai de grâce
|
||||
if exiting {
|
||||
if let Some(deadline) = exit_deadline {
|
||||
if Instant::now() > deadline {
|
||||
log::warn!("[OpenXR] Timeout attente transition STOPPING, fin de session forcée.");
|
||||
if session_running {
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
let _ = s.end();
|
||||
handle_dvr_lifecycle(
|
||||
dvr_cmd,
|
||||
dvr_cfg,
|
||||
active_dvr,
|
||||
video_rx_opt,
|
||||
cfg,
|
||||
monitor,
|
||||
);
|
||||
|
||||
let telem_on = telem_enabled_flag.load(Ordering::Relaxed);
|
||||
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
||||
|
||||
let ht_on = ht_enabled_flag.load(Ordering::Relaxed);
|
||||
sync_head_tracker(cfg, ht_on, head_tracker_opt, monitor);
|
||||
|
||||
// Si l'arrêt de l'application est demandé et que la session tourne encore, notifier proprement le runtime
|
||||
if stop_flag.load(Ordering::Relaxed) && !exiting {
|
||||
exiting = true;
|
||||
exit_deadline = Some(Instant::now() + Duration::from_millis(1500));
|
||||
log::info!("[OpenXR] Arrêt demandé, notification du runtime (request_exit)...");
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
match s.request_exit() {
|
||||
Ok(()) => {}
|
||||
Err(xr::sys::Result::ERROR_SESSION_NOT_RUNNING) => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("[OpenXR] Erreur lors de request_exit : {}", e);
|
||||
break;
|
||||
}
|
||||
session_running = false;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while let Some(event) = instance.poll_event(&mut event_storage)? {
|
||||
use xr::Event::*;
|
||||
match event {
|
||||
SessionStateChanged(e) => {
|
||||
log::info!("[OpenXR] Changement d'état session : {:?}", e.state());
|
||||
match e.state() {
|
||||
xr::SessionState::READY => {
|
||||
if !exiting {
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
s.begin(xr::ViewConfigurationType::PRIMARY_STEREO)?;
|
||||
session_running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
xr::SessionState::STOPPING => {
|
||||
log::info!("[OpenXR] État STOPPING reçu, appel de session.end()...");
|
||||
// Si en cours de sortie et dépassement du délai de grâce
|
||||
if exiting {
|
||||
if let Some(deadline) = exit_deadline {
|
||||
if Instant::now() > deadline {
|
||||
log::warn!("[OpenXR] Timeout attente transition STOPPING, fin de session forcée.");
|
||||
if session_running {
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
let _ = s.end();
|
||||
}
|
||||
session_running = false;
|
||||
if exiting {
|
||||
break;
|
||||
}
|
||||
}
|
||||
xr::SessionState::EXITING | xr::SessionState::LOSS_PENDING => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ReferenceSpaceChangePending(_) => {
|
||||
first_pose = true;
|
||||
}
|
||||
InstanceLossPending(_) => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if !session_running || exiting {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
continue;
|
||||
}
|
||||
|
||||
let xr_frame_state = vk_xr
|
||||
.frame_wait
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameWaiter absent"))?
|
||||
.wait()?;
|
||||
let frame_stream = vk_xr
|
||||
.frame_stream
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameStream absent"))?;
|
||||
frame_stream.begin()?;
|
||||
|
||||
let location = view_space.locate(&local_space, xr_frame_state.predicted_display_time)?;
|
||||
let mut current_pose = HeadPoseSample::default();
|
||||
|
||||
if location
|
||||
.location_flags
|
||||
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
|
||||
{
|
||||
let q = location.pose.orientation;
|
||||
let quat = Quat::from_xyzw(q.x, q.y, q.z, q.w);
|
||||
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
if first_pose || recenter_flag.swap(false, Ordering::Relaxed) {
|
||||
ht.recenter(quat);
|
||||
first_pose = false;
|
||||
}
|
||||
if let Ok(sample) = ht.send_pose(quat) {
|
||||
current_pose = sample;
|
||||
while let Some(event) = instance.poll_event(&mut event_storage)? {
|
||||
use xr::Event::*;
|
||||
match event {
|
||||
SessionStateChanged(e) => {
|
||||
log::info!("[OpenXR] Changement d'état session : {:?}", e.state());
|
||||
match e.state() {
|
||||
xr::SessionState::READY => {
|
||||
if !exiting {
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
s.begin(xr::ViewConfigurationType::PRIMARY_STEREO)?;
|
||||
session_running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
xr::SessionState::STOPPING => {
|
||||
log::info!("[OpenXR] État STOPPING reçu, appel de session.end()...");
|
||||
if let Some(ref s) = vk_xr.session {
|
||||
let _ = s.end();
|
||||
}
|
||||
session_running = false;
|
||||
if exiting {
|
||||
break;
|
||||
}
|
||||
}
|
||||
xr::SessionState::EXITING | xr::SessionState::LOSS_PENDING => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
ReferenceSpaceChangePending(_) => {
|
||||
first_pose = true;
|
||||
}
|
||||
InstanceLossPending(_) => {
|
||||
session_running = false;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !xr_frame_state.should_render {
|
||||
vk_xr
|
||||
if !session_running || exiting {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
continue;
|
||||
}
|
||||
|
||||
let xr_frame_state = vk_xr
|
||||
.frame_wait
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameWaiter absent"))?
|
||||
.wait()?;
|
||||
let frame_stream = vk_xr
|
||||
.frame_stream
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.end(
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameStream absent"))?;
|
||||
frame_stream.begin()?;
|
||||
|
||||
let location = view_space.locate(&local_space, xr_frame_state.predicted_display_time)?;
|
||||
let mut current_pose = HeadPoseSample::default();
|
||||
|
||||
if location
|
||||
.location_flags
|
||||
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
|
||||
{
|
||||
let q = location.pose.orientation;
|
||||
let quat = Quat::from_xyzw(q.x, q.y, q.z, q.w);
|
||||
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
if first_pose || recenter_flag.swap(false, Ordering::Relaxed) {
|
||||
ht.recenter(quat);
|
||||
first_pose = false;
|
||||
}
|
||||
if let Ok(sample) = ht.send_pose(quat) {
|
||||
current_pose = sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !xr_frame_state.should_render {
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[],
|
||||
)?;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut new_raw_frame: Option<Vec<u8>> = None;
|
||||
let mut has_video_stream = false;
|
||||
let mut has_new_raw_frame = false;
|
||||
let mut has_video_stream = false;
|
||||
|
||||
if let Some(rx) = video_rx_opt {
|
||||
let lock = rx.latest_frame();
|
||||
let guard = lock.lock();
|
||||
if let Some(ref vf) = *guard {
|
||||
if vf.received_at.elapsed() < Duration::from_millis(600) {
|
||||
has_video_stream = true;
|
||||
if vf.frame_id != last_frame_id {
|
||||
last_frame_id = vf.frame_id;
|
||||
fps_counter += 1;
|
||||
new_raw_frame = Some(vf.rgba_data.clone());
|
||||
if let Some(rx) = video_rx_opt {
|
||||
let lock = rx.latest_frame();
|
||||
let guard = lock.lock();
|
||||
if let Some(ref vf) = *guard {
|
||||
if vf.received_at.elapsed() < Duration::from_millis(600) {
|
||||
has_video_stream = true;
|
||||
if vf.frame_id != last_frame_id {
|
||||
last_frame_id = vf.frame_id;
|
||||
fps_counter += 1;
|
||||
raw_frame_buf.clear();
|
||||
raw_frame_buf.extend_from_slice(&vf.rgba_data);
|
||||
has_new_raw_frame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref raw) = new_raw_frame {
|
||||
dome_lut.apply(&raw, &mut composited_rgba);
|
||||
} else if !has_video_stream {
|
||||
standby_tick = standby_tick.wrapping_add(1);
|
||||
UsbVideoReceiver::render_standby_pattern(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
standby_tick,
|
||||
&mut composited_rgba,
|
||||
);
|
||||
OsdOverlay::draw_text(
|
||||
&mut composited_rgba,
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
(cfg.video_width as i32 / 2) - 230,
|
||||
(cfg.video_height as i32 / 2) + 70,
|
||||
"SIGNAL VRX PERDU - RECHERCHE FLUX UDP 5600...",
|
||||
(cfg.video_height / 360).max(2),
|
||||
[255, 180, 40, 255],
|
||||
);
|
||||
}
|
||||
|
||||
let telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
let (dvr_rec, dvr_secs) = {
|
||||
let mon = monitor.lock();
|
||||
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
||||
};
|
||||
|
||||
if telem_on {
|
||||
OsdOverlay::render(
|
||||
&mut composited_rgba,
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
&telem_snapshot,
|
||||
current_pose.pan_deg,
|
||||
current_pose.tilt_deg,
|
||||
current_pose.roll_deg,
|
||||
cfg.max_pan_deg,
|
||||
cfg.max_tilt_deg,
|
||||
active_proj.label(),
|
||||
dvr_rec,
|
||||
dvr_secs,
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(ref dvr) = *active_dvr {
|
||||
if dvr.mode() == DvrMode::CompositedOsd && new_raw_frame.is_some() {
|
||||
dvr.push_slice(&composited_rgba);
|
||||
if has_new_raw_frame {
|
||||
dome_lut.apply(&raw_frame_buf, &mut composited_rgba);
|
||||
} else if !has_video_stream {
|
||||
standby_tick = standby_tick.wrapping_add(1);
|
||||
UsbVideoReceiver::render_standby_pattern(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
standby_tick,
|
||||
&mut composited_rgba,
|
||||
);
|
||||
OsdOverlay::draw_text(
|
||||
&mut composited_rgba,
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
(cfg.video_width as i32 / 2) - 230,
|
||||
(cfg.video_height as i32 / 2) + 70,
|
||||
"SIGNAL VRX PERDU - RECHERCHE FLUX UDP 5600...",
|
||||
(cfg.video_height / 360).max(2),
|
||||
[255, 180, 40, 255],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
vk_xr.upload_rgba_to_swapchain(&composited_rgba)?;
|
||||
let telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
if standby_tick % 2 == 0 || last_frame_id % 2 == 0 {
|
||||
sync_video_status(cfg, video_rx_opt, monitor);
|
||||
let mut mon = monitor.lock();
|
||||
if fps_timer.elapsed() >= Duration::from_secs(1) {
|
||||
if has_video_stream {
|
||||
mon.video_fps = fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
|
||||
} else {
|
||||
mon.video_fps = 0.0;
|
||||
let (dvr_rec, dvr_secs) = {
|
||||
let mon = monitor.lock();
|
||||
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
||||
};
|
||||
|
||||
if telem_on {
|
||||
OsdOverlay::render(
|
||||
&mut composited_rgba,
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
&telem_snapshot,
|
||||
current_pose.pan_deg,
|
||||
current_pose.tilt_deg,
|
||||
current_pose.roll_deg,
|
||||
cfg.max_pan_deg,
|
||||
cfg.max_tilt_deg,
|
||||
active_proj.label(),
|
||||
dvr_rec,
|
||||
dvr_secs,
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(ref dvr) = *active_dvr {
|
||||
if dvr.mode() == DvrMode::CompositedOsd && has_new_raw_frame {
|
||||
dvr.push_slice(&composited_rgba);
|
||||
}
|
||||
fps_counter = 0;
|
||||
fps_timer = Instant::now();
|
||||
}
|
||||
mon.video_frames_total = last_frame_id;
|
||||
mon.latest_head_pose = current_pose;
|
||||
mon.latest_telemetry = telem_snapshot;
|
||||
mon.preview_width = cfg.video_width;
|
||||
mon.preview_height = cfg.video_height;
|
||||
mon.preview_rgba.clone_from(&composited_rgba);
|
||||
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
|
||||
}
|
||||
|
||||
let swapchain_ref = vk_xr
|
||||
.swapchain
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Swapchain absent"))?;
|
||||
let sub_image = xr::SwapchainSubImage::new()
|
||||
.swapchain(swapchain_ref)
|
||||
.image_array_index(0)
|
||||
.image_rect(xr::Rect2Di {
|
||||
offset: xr::Offset2Di { x: 0, y: 0 },
|
||||
extent: xr::Extent2Di {
|
||||
width: cfg.video_width as i32,
|
||||
height: cfg.video_height as i32,
|
||||
},
|
||||
});
|
||||
vk_xr.upload_rgba_to_swapchain(&composited_rgba)?;
|
||||
|
||||
let horizontal_fov_rad = cur_opt.camera_fov_deg.to_radians();
|
||||
let half_vert_fov_rad = (horizontal_fov_rad / aspect) * 0.5;
|
||||
let screen_height_m = cur_opt.screen_width_m / aspect;
|
||||
|
||||
let frame_stream = vk_xr
|
||||
.frame_stream
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameStream absent"))?;
|
||||
match active_proj {
|
||||
ProjectionMode::Dome140 => {
|
||||
let equirect_layer = xr::CompositionLayerEquirect2KHR::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.radius(cur_opt.screen_distance_m)
|
||||
.central_horizontal_angle(horizontal_fov_rad)
|
||||
.upper_vertical_angle(half_vert_fov_rad)
|
||||
.lower_vertical_angle(-half_vert_fov_rad);
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&equirect_layer],
|
||||
)?;
|
||||
if standby_tick % 2 == 0 || last_frame_id % 2 == 0 {
|
||||
sync_video_status(cfg, video_rx_opt, monitor);
|
||||
let mut mon = monitor.lock();
|
||||
if fps_timer.elapsed() >= Duration::from_secs(1) {
|
||||
if has_video_stream {
|
||||
mon.video_fps = fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
|
||||
} else {
|
||||
mon.video_fps = 0.0;
|
||||
}
|
||||
fps_counter = 0;
|
||||
fps_timer = Instant::now();
|
||||
}
|
||||
if current_pose.last_send_ok {
|
||||
mon.nomad_wifi_status = SubsystemStatus::Running(format!(
|
||||
"ON - Cible {}:{} ({} paquets)",
|
||||
cfg.nomad_ip, cfg.nomad_port, current_pose.packets_sent
|
||||
));
|
||||
} else if current_pose.send_errors > 0 {
|
||||
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
||||
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
||||
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
||||
));
|
||||
}
|
||||
mon.video_frames_total = last_frame_id;
|
||||
mon.latest_head_pose = current_pose;
|
||||
mon.latest_telemetry = telem_snapshot;
|
||||
mon.preview_width = cfg.video_width;
|
||||
mon.preview_height = cfg.video_height;
|
||||
mon.preview_rgba.clone_from(&composited_rgba);
|
||||
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
|
||||
}
|
||||
ProjectionMode::Cylinder140 => {
|
||||
let cylinder_layer = xr::CompositionLayerCylinderKHR::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.radius(cur_opt.screen_distance_m)
|
||||
.central_angle(horizontal_fov_rad)
|
||||
.aspect_ratio(aspect);
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&cylinder_layer],
|
||||
)?;
|
||||
}
|
||||
ProjectionMode::FlatQuad => {
|
||||
let quad_pose = xr::Posef {
|
||||
orientation: xr::Quaternionf::IDENTITY,
|
||||
position: xr::Vector3f {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: -cur_opt.screen_distance_m,
|
||||
let swapchain_ref = vk_xr
|
||||
.swapchain
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Swapchain absent"))?;
|
||||
let sub_image = xr::SwapchainSubImage::new()
|
||||
.swapchain(swapchain_ref)
|
||||
.image_array_index(0)
|
||||
.image_rect(xr::Rect2Di {
|
||||
offset: xr::Offset2Di { x: 0, y: 0 },
|
||||
extent: xr::Extent2Di {
|
||||
width: cfg.video_width as i32,
|
||||
height: cfg.video_height as i32,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
let quad_layer = xr::CompositionLayerQuad::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(quad_pose)
|
||||
.size(xr::Extent2Df {
|
||||
width: cur_opt.screen_width_m,
|
||||
height: screen_height_m,
|
||||
});
|
||||
let horizontal_fov_rad = cur_opt.camera_fov_deg.to_radians();
|
||||
let half_vert_fov_rad = (horizontal_fov_rad / aspect) * 0.5;
|
||||
let screen_height_m = cur_opt.screen_width_m / aspect;
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&quad_layer],
|
||||
)?;
|
||||
let frame_stream = vk_xr
|
||||
.frame_stream
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("FrameStream absent"))?;
|
||||
match active_proj {
|
||||
ProjectionMode::Dome140 => {
|
||||
let equirect_layer = xr::CompositionLayerEquirect2KHR::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.radius(cur_opt.screen_distance_m)
|
||||
.central_horizontal_angle(horizontal_fov_rad)
|
||||
.upper_vertical_angle(half_vert_fov_rad)
|
||||
.lower_vertical_angle(-half_vert_fov_rad);
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&equirect_layer],
|
||||
)?;
|
||||
}
|
||||
ProjectionMode::Cylinder140 => {
|
||||
let cylinder_layer = xr::CompositionLayerCylinderKHR::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.radius(cur_opt.screen_distance_m)
|
||||
.central_angle(horizontal_fov_rad)
|
||||
.aspect_ratio(aspect);
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&cylinder_layer],
|
||||
)?;
|
||||
}
|
||||
ProjectionMode::FlatQuad => {
|
||||
let quad_pose = xr::Posef {
|
||||
orientation: xr::Quaternionf::IDENTITY,
|
||||
position: xr::Vector3f {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: -cur_opt.screen_distance_m,
|
||||
},
|
||||
};
|
||||
|
||||
let quad_layer = xr::CompositionLayerQuad::new()
|
||||
.space(&view_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(quad_pose)
|
||||
.size(xr::Extent2Df {
|
||||
width: cur_opt.screen_width_m,
|
||||
height: screen_height_m,
|
||||
});
|
||||
|
||||
frame_stream.end(
|
||||
xr_frame_state.predicted_display_time,
|
||||
xr::EnvironmentBlendMode::OPAQUE,
|
||||
&[&quad_layer],
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
|
||||
if session_running {
|
||||
log::warn!("[OpenXR] Sortie de boucle avec session encore active, appel de session.end()...");
|
||||
@@ -1219,7 +1177,7 @@ fn try_run_openxr_session(
|
||||
drop(local_space);
|
||||
drop(vk_xr);
|
||||
|
||||
Ok(())
|
||||
loop_res
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -1245,6 +1203,8 @@ fn run_desktop_fallback_loop(
|
||||
cfg.lens_k1,
|
||||
cfg.lens_k2,
|
||||
);
|
||||
let mut raw_frame_buf: Vec<u8> =
|
||||
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
||||
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||
let mut standby_tick: u32 = 0;
|
||||
let mut last_frame_id: u64 = 0;
|
||||
@@ -1313,7 +1273,7 @@ fn run_desktop_fallback_loop(
|
||||
}
|
||||
}
|
||||
|
||||
let mut new_raw_frame: Option<Vec<u8>> = None;
|
||||
let mut has_new_raw_frame = false;
|
||||
let mut has_video_stream = false;
|
||||
|
||||
if let Some(rx) = video_rx_opt {
|
||||
@@ -1325,14 +1285,16 @@ fn run_desktop_fallback_loop(
|
||||
if vf.frame_id != last_frame_id {
|
||||
last_frame_id = vf.frame_id;
|
||||
fps_counter += 1;
|
||||
new_raw_frame = Some(vf.rgba_data.clone());
|
||||
raw_frame_buf.clear();
|
||||
raw_frame_buf.extend_from_slice(&vf.rgba_data);
|
||||
has_new_raw_frame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref raw) = new_raw_frame {
|
||||
dome_lut.apply(&raw, &mut composited_rgba);
|
||||
if has_new_raw_frame {
|
||||
dome_lut.apply(&raw_frame_buf, &mut composited_rgba);
|
||||
} else if !has_video_stream {
|
||||
standby_tick = standby_tick.wrapping_add(1);
|
||||
UsbVideoReceiver::render_standby_pattern(
|
||||
@@ -1382,7 +1344,7 @@ fn run_desktop_fallback_loop(
|
||||
}
|
||||
|
||||
if let Some(ref dvr) = *active_dvr {
|
||||
if dvr.mode() == DvrMode::CompositedOsd && new_raw_frame.is_some() {
|
||||
if dvr.mode() == DvrMode::CompositedOsd && has_new_raw_frame {
|
||||
dvr.push_slice(&composited_rgba);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user