mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat: integrate DVR, live optical tuning and ARM64 tooling into modern GPUI Control Center
- Modern GPUI (src/gui_gpui.rs): Added 1-click DVR quick action button in header with live recording time/size, DVR status badge, reactive snapshots, live optical parameter tuning in Settings, and dedicated DVR settings card (MKV/MP4, StreamCopy/Composited). - Engine & DVR (src/engine.rs, src/dvr.rs, src/video_usb.rs): Integrated DVR recorder lifecycle with GStreamer supervisor probe for zero-CPU stream copy and hardware/composited OSD recording, dynamic optical updates without pipeline restarts. - Classic GUI fallback (src/gui.rs): Added DVR quick toggle, live optical slider callbacks, and full DVR settings section in egui. - OSD & Math optimizations: Zero-alloc stack formatting in src/telemetry_osd.rs, compile-time CRC8 table in src/nomad_elrs.rs, buffered file logger in src/logger.rs. - Steam Frame ARM64 scripts: udev rule scripts/99-radxa-vrx-rndis.rules, build & deployment tools scripts/build_steamframe_arm64.sh, scripts/deploy_to_steamframe.sh.
This commit is contained in:
1 parent
d5cc72750e
commit
7bee072e21
16 files changed
+1389
-67
No files matched your search
@@ -3,4 +3,6 @@ target/
|
|||||||
*.log
|
*.log
|
||||||
steamframe_fpv.log
|
steamframe_fpv.log
|
||||||
*.bin
|
*.bin
|
||||||
|
dist/
|
||||||
|
recordings/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@@ -23,3 +23,9 @@ smallvec = "1.16"
|
|||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
xattr = { path = "patches/xattr" }
|
xattr = { path = "patches/xattr" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
lto = "thin"
|
||||||
|
codegen-units = 1
|
||||||
|
strip = "symbols"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Règle Udev pour le récepteur Eachine Sphere Link (Radxa Zero 3W / Rockchip RV1106 / RNDIS)
|
||||||
|
# Déclenche l'attribution de l'IP 192.168.1.10/24 dès que le câble USB-C est branché sur le Steam Frame ou PC
|
||||||
|
|
||||||
|
ACTION=="add", SUBSYSTEM=="net", KERNEL=="usb*|enx*", ATTRS{idVendor}=="1d6b|2207|0525", RUN+="/usr/bin/ip addr add 192.168.1.10/24 dev %k", RUN+="/usr/bin/ip link set dev %k up"
|
||||||
Executable
+46
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Script de compilation optimisée pour le casque Valve Steam Frame (ARM64 / SteamOS)
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)"
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
|
echo "=== Compilation optimisée pour Valve Steam Frame (SteamOS ARM64) ==="
|
||||||
|
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
echo "[1/3] Architecture détectée : ${ARCH}"
|
||||||
|
|
||||||
|
if [ "$ARCH" = "aarch64" ]; then
|
||||||
|
echo "[+] Exécution native sur architecture ARM64 (Steam Frame / Snapdragon 8 Gen 3)."
|
||||||
|
|
||||||
|
# Vérification des dépendances sur SteamOS / Arch Linux ARM
|
||||||
|
if command -v pacman >/dev/null 2>&1; then
|
||||||
|
echo "[+] Vérification des paquets requis via pacman..."
|
||||||
|
sudo pacman -S --needed --noconfirm \
|
||||||
|
gcc pkgconf vulkan-devel openxr \
|
||||||
|
gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-libav || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[2/3] Compilation Release native avec optimisations CPU Cortex-X4 / NEON..."
|
||||||
|
export RUSTFLAGS="-C target-cpu=native -C opt-level=3"
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
echo "[3/3] Installation locale du lanceur .desktop..."
|
||||||
|
mkdir -p ~/.local/share/applications
|
||||||
|
cp steamframe-fpv.desktop ~/.local/share/applications/
|
||||||
|
sed -i "s|/home/deck/projects/steamframe_fpv|$DIR|g" ~/.local/share/applications/steamframe-fpv.desktop
|
||||||
|
|
||||||
|
echo "=== SUCCÈS : Binaire compilé dans $DIR/target/release/steamframe-fpv ==="
|
||||||
|
else
|
||||||
|
echo "[!] Exécution sur hôte ${ARCH} (Ubuntu / PC de développement)."
|
||||||
|
echo "[2/3] Compilation Release hôte standard..."
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
echo "[3/3] Création de l'archive de déploiement pour le Steam Frame..."
|
||||||
|
mkdir -p dist
|
||||||
|
tar --exclude="target" --exclude=".git" -czf dist/steamframe-fpv-deploy.tar.gz \
|
||||||
|
Cargo.toml Cargo.lock src scripts assets README.md launch.sh steamframe-fpv.desktop
|
||||||
|
|
||||||
|
echo "=== SUCCÈS : Archive de déploiement créée dans $DIR/dist/steamframe-fpv-deploy.tar.gz ==="
|
||||||
|
echo "Pour déployer sur le casque, lancez : ./scripts/deploy_to_steamframe.sh [ip_steamframe]"
|
||||||
|
fi
|
||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Script de déploiement automatique vers le casque Valve Steam Frame (SteamOS ARM64)
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)"
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
|
TARGET_HOST="${1:-deck@192.168.1.15}"
|
||||||
|
|
||||||
|
echo "=== Déploiement de SteamFrame FPV vers le casque : ${TARGET_HOST} ==="
|
||||||
|
|
||||||
|
echo "[1/5] Vérification de la connexion SSH..."
|
||||||
|
if ! ssh -o ConnectTimeout=3 -o BatchMode=yes "${TARGET_HOST}" "echo 'Connexion SSH OK'" 2>/dev/null; then
|
||||||
|
echo "ERREUR : Impossible de joindre ${TARGET_HOST} en SSH sans mot de passe."
|
||||||
|
echo "Usage : $0 <utilisateur@ip_steam_frame>"
|
||||||
|
echo "Assurez-vous d'avoir copié votre clé SSH : ssh-copy-id ${TARGET_HOST}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[2/5] Préparation du paquet de déploiement..."
|
||||||
|
./scripts/build_steamframe_arm64.sh
|
||||||
|
|
||||||
|
echo "[3/5] Transfert des fichiers du projet sur le Steam Frame..."
|
||||||
|
ssh "${TARGET_HOST}" "mkdir -p ~/projects/steamframe_fpv"
|
||||||
|
scp dist/steamframe-fpv-deploy.tar.gz "${TARGET_HOST}:~/projects/steamframe_fpv/"
|
||||||
|
ssh "${TARGET_HOST}" "cd ~/projects/steamframe_fpv && tar -xzf steamframe-fpv-deploy.tar.gz && chmod +x scripts/*.sh launch.sh"
|
||||||
|
|
||||||
|
echo "[4/5] Installation de la règle udev USB RNDIS (auto-attribution 192.168.1.10/24)..."
|
||||||
|
scp scripts/99-radxa-vrx-rndis.rules "${TARGET_HOST}:/tmp/"
|
||||||
|
ssh "${TARGET_HOST}" "sudo cp /tmp/99-radxa-vrx-rndis.rules /etc/udev/rules.d/ && sudo udevadm control --reload-rules"
|
||||||
|
|
||||||
|
echo "[5/5] Compilation Release native ARM64 sur le casque..."
|
||||||
|
ssh "${TARGET_HOST}" "cd ~/projects/steamframe_fpv && ./scripts/build_steamframe_arm64.sh"
|
||||||
|
|
||||||
|
echo "=== DÉPLOIEMENT TERMINÉ AVEC SUCCÈS ==="
|
||||||
|
echo "Vous pouvez maintenant lancer l'application directement dans le casque ou en SSH :"
|
||||||
|
echo " ssh -X ${TARGET_HOST} 'cd ~/projects/steamframe_fpv && ./launch.sh'"
|
||||||
@@ -116,6 +116,18 @@ pub struct AppConfig {
|
|||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub headless: bool,
|
pub headless: bool,
|
||||||
|
|
||||||
|
/// Dossier d'enregistrement des vidéos DVR (ex: "recordings/")
|
||||||
|
#[arg(long, default_value = "recordings")]
|
||||||
|
pub dvr_dir: String,
|
||||||
|
|
||||||
|
/// Format de conteneur DVR : "mkv" (Matroska résistant aux coupures) ou "mp4"
|
||||||
|
#[arg(long, default_value = "mkv")]
|
||||||
|
pub dvr_format: String,
|
||||||
|
|
||||||
|
/// Mode d'enregistrement DVR : "copy" (flux H.264/H.265 direct 0% CPU) ou "composited" (avec OSD incrusté)
|
||||||
|
#[arg(long, default_value = "copy")]
|
||||||
|
pub dvr_mode: String,
|
||||||
|
|
||||||
/// Désactiver l'interface graphique de monitoring (lancer directement en ligne de commande)
|
/// Désactiver l'interface graphique de monitoring (lancer directement en ligne de commande)
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub no_gui: bool,
|
pub no_gui: bool,
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ impl ProjectionMode {
|
|||||||
pub struct DomeWarpLut {
|
pub struct DomeWarpLut {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
pub fov_deg: f32,
|
||||||
|
pub k1: f32,
|
||||||
|
pub k2: f32,
|
||||||
pub src_pixel_offsets: Vec<u32>,
|
pub src_pixel_offsets: Vec<u32>,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
@@ -71,11 +74,23 @@ impl DomeWarpLut {
|
|||||||
Self {
|
Self {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
fov_deg,
|
||||||
|
k1,
|
||||||
|
k2,
|
||||||
src_pixel_offsets,
|
src_pixel_offsets,
|
||||||
enabled,
|
enabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Vérifie rapidement si la table courante correspond déjà aux paramètres optiques demandés
|
||||||
|
pub fn matches_params(&self, width: u32, height: u32, fov_deg: f32, k1: f32, k2: f32) -> bool {
|
||||||
|
self.width == width
|
||||||
|
&& self.height == height
|
||||||
|
&& (self.fov_deg - fov_deg).abs() < 1e-4
|
||||||
|
&& (self.k1 - k1).abs() < 1e-4
|
||||||
|
&& (self.k2 - k2).abs() < 1e-4
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn apply(&self, input_rgba: &[u8], output_rgba: &mut [u8]) {
|
pub fn apply(&self, input_rgba: &[u8], output_rgba: &mut [u8]) {
|
||||||
let total_pixels = (self.width * self.height) as usize;
|
let total_pixels = (self.width * self.height) as usize;
|
||||||
|
|||||||
+333
@@ -0,0 +1,333 @@
|
|||||||
|
use anyhow::{Context, Result};
|
||||||
|
use chrono::Local;
|
||||||
|
use gstreamer as gst;
|
||||||
|
use gstreamer::prelude::*;
|
||||||
|
use gstreamer_app as gst_app;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
/// Format de conteneur d'enregistrement DVR
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum DvrContainer {
|
||||||
|
Mkv,
|
||||||
|
Mp4,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DvrContainer {
|
||||||
|
pub fn from_str(s: &str) -> Self {
|
||||||
|
if s.eq_ignore_ascii_case("mp4") {
|
||||||
|
Self::Mp4
|
||||||
|
} else {
|
||||||
|
Self::Mkv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extension(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Mkv => "mkv",
|
||||||
|
Self::Mp4 => "mp4",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn muxer_element(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Mkv => "matroskamux",
|
||||||
|
Self::Mp4 => "mp4mux fragment-duration=2000 faststart=true",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mode d'enregistrement DVR
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum DvrMode {
|
||||||
|
/// Copie directe du flux compressé H.264/H.265 (Zéro-CPU, qualité 1:1 d'origine)
|
||||||
|
StreamCopy,
|
||||||
|
/// Enregistrement de la trame compositée (avec OSD et correction optique)
|
||||||
|
CompositedOsd,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DvrMode {
|
||||||
|
pub fn from_str(s: &str) -> Self {
|
||||||
|
if s.eq_ignore_ascii_case("osd") {
|
||||||
|
Self::CompositedOsd
|
||||||
|
} else {
|
||||||
|
Self::StreamCopy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn label(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::StreamCopy => "Flux Natif (Zéro-CPU)",
|
||||||
|
Self::CompositedOsd => "Avec OSD incrusté",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enregistreur vidéo DVR asynchrone basé sur GStreamer
|
||||||
|
pub struct DvrRecorder {
|
||||||
|
pipeline: gst::Pipeline,
|
||||||
|
appsrc: gst_app::AppSrc,
|
||||||
|
file_path: PathBuf,
|
||||||
|
mode: DvrMode,
|
||||||
|
start_time: Instant,
|
||||||
|
bytes_written: Arc<AtomicU64>,
|
||||||
|
frames_recorded: Arc<AtomicU64>,
|
||||||
|
is_recording: Arc<AtomicBool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DvrRecorder {
|
||||||
|
/// Démarre un enregistrement en mode copie de flux direct H.264 / H.265 (Zéro-CPU)
|
||||||
|
pub fn start_stream_copy(
|
||||||
|
dir: &str,
|
||||||
|
container: DvrContainer,
|
||||||
|
codec: &str,
|
||||||
|
) -> Result<Arc<Self>> {
|
||||||
|
gst::init().context("Échec d'initialisation GStreamer pour le DVR")?;
|
||||||
|
|
||||||
|
fs::create_dir_all(dir)
|
||||||
|
.with_context(|| format!("Impossible de créer le répertoire DVR '{}'", dir))?;
|
||||||
|
|
||||||
|
let file_path = Self::generate_filepath(dir, container);
|
||||||
|
let path_str = file_path
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Chemin DVR invalide"))?;
|
||||||
|
|
||||||
|
let codec_lower = codec.to_lowercase();
|
||||||
|
let is_h264 = codec_lower == "h264";
|
||||||
|
let parser = if is_h264 { "h264parse" } else { "h265parse" };
|
||||||
|
let caps = if is_h264 {
|
||||||
|
"video/x-h264,stream-format=byte-stream"
|
||||||
|
} else {
|
||||||
|
"video/x-h265,stream-format=byte-stream"
|
||||||
|
};
|
||||||
|
let muxer = container.muxer_element();
|
||||||
|
|
||||||
|
let pipeline_str = format!(
|
||||||
|
"appsrc name=dvr_src is-live=true format=time do-timestamp=true caps={caps} ! \
|
||||||
|
{parser} config-interval=-1 ! \
|
||||||
|
{muxer} ! \
|
||||||
|
filesink location=\"{path_str}\" sync=false"
|
||||||
|
);
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"[DVR] Démarrage enregistrement StreamCopy ({}) -> {:?}",
|
||||||
|
codec.to_uppercase(),
|
||||||
|
file_path
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::launch(pipeline_str, file_path, DvrMode::StreamCopy)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Démarre un enregistrement en mode incrustation OSD (re-encodage rapide x264enc)
|
||||||
|
pub fn start_composited_osd(
|
||||||
|
dir: &str,
|
||||||
|
container: DvrContainer,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) -> Result<Arc<Self>> {
|
||||||
|
gst::init().context("Échec d'initialisation GStreamer pour le DVR")?;
|
||||||
|
|
||||||
|
fs::create_dir_all(dir)
|
||||||
|
.with_context(|| format!("Impossible de créer le répertoire DVR '{}'", dir))?;
|
||||||
|
|
||||||
|
let file_path = Self::generate_filepath(dir, container);
|
||||||
|
let path_str = file_path
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Chemin DVR invalide"))?;
|
||||||
|
|
||||||
|
let muxer = container.muxer_element();
|
||||||
|
|
||||||
|
let pipeline_str = format!(
|
||||||
|
"appsrc name=dvr_src is-live=true format=time do-timestamp=true \
|
||||||
|
caps=video/x-raw,format=RGBA,width={width},height={height},framerate=60/1 ! \
|
||||||
|
videoconvert ! \
|
||||||
|
x264enc tune=zerolatency speed-preset=ultrafast bitrate=8000 key-int-max=60 ! \
|
||||||
|
h264parse config-interval=-1 ! \
|
||||||
|
{muxer} ! \
|
||||||
|
filesink location=\"{path_str}\" sync=false"
|
||||||
|
);
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"[DVR] Démarrage enregistrement OSD ({width}x{height} @ 60 FPS) -> {:?}",
|
||||||
|
file_path
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::launch(pipeline_str, file_path, DvrMode::CompositedOsd)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launch(pipeline_str: String, file_path: PathBuf, mode: DvrMode) -> Result<Arc<Self>> {
|
||||||
|
let element = gst::parse::launch(&pipeline_str).map_err(|e| {
|
||||||
|
log::error!("[DVR] Erreur pipeline GStreamer : {} (Cmd: {})", e, pipeline_str);
|
||||||
|
anyhow::anyhow!("Erreur pipeline DVR : {}", e)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let pipeline = element
|
||||||
|
.dynamic_cast::<gst::Pipeline>()
|
||||||
|
.map_err(|_| anyhow::anyhow!("L'élément DVR n'est pas un Pipeline"))?;
|
||||||
|
|
||||||
|
let appsrc = pipeline
|
||||||
|
.by_name("dvr_src")
|
||||||
|
.context("Appsrc 'dvr_src' introuvable dans le pipeline DVR")?
|
||||||
|
.dynamic_cast::<gst_app::AppSrc>()
|
||||||
|
.map_err(|_| anyhow::anyhow!("Impossible de convertir dvr_src en AppSrc"))?;
|
||||||
|
|
||||||
|
pipeline
|
||||||
|
.set_state(gst::State::Playing)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Impossible de démarrer le pipeline DVR : {}", e))?;
|
||||||
|
|
||||||
|
Ok(Arc::new(Self {
|
||||||
|
pipeline,
|
||||||
|
appsrc,
|
||||||
|
file_path,
|
||||||
|
mode,
|
||||||
|
start_time: Instant::now(),
|
||||||
|
bytes_written: Arc::new(AtomicU64::new(0)),
|
||||||
|
frames_recorded: Arc::new(AtomicU64::new(0)),
|
||||||
|
is_recording: Arc::new(AtomicBool::new(true)),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Génère un nom de fichier horodaté `fpv_YYYYMMDD_HHMMSS.<ext>`
|
||||||
|
pub fn generate_filepath(dir: &str, container: DvrContainer) -> PathBuf {
|
||||||
|
let now = Local::now();
|
||||||
|
let filename = format!(
|
||||||
|
"fpv_{}.{}",
|
||||||
|
now.format("%Y%m%d_%H%M%S"),
|
||||||
|
container.extension()
|
||||||
|
);
|
||||||
|
Path::new(dir).join(filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mode(&self) -> DvrMode {
|
||||||
|
self.mode
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn file_path(&self) -> &Path {
|
||||||
|
&self.file_path
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elapsed_secs(&self) -> u64 {
|
||||||
|
self.start_time.elapsed().as_secs()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bytes_written(&self) -> u64 {
|
||||||
|
self.bytes_written.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frames_recorded(&self) -> u64 {
|
||||||
|
self.frames_recorded.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn is_recording(&self) -> bool {
|
||||||
|
self.is_recording.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pousse un buffer GStreamer existant (zéro-copie de pointeur GstBuffer)
|
||||||
|
pub fn push_buffer(&self, buffer: gst::Buffer) {
|
||||||
|
if !self.is_recording.load(Ordering::Relaxed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.bytes_written
|
||||||
|
.fetch_add(buffer.size() as u64, Ordering::Relaxed);
|
||||||
|
self.frames_recorded.fetch_add(1, Ordering::Relaxed);
|
||||||
|
let _ = self.appsrc.push_buffer(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pousse un bloc d'octets mémoire (ex: trame RGBA compositée)
|
||||||
|
pub fn push_slice(&self, slice: &[u8]) {
|
||||||
|
if !self.is_recording.load(Ordering::Relaxed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let buffer = gst::Buffer::from_slice(slice.to_vec());
|
||||||
|
self.push_buffer(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Arrête proprement l'enregistrement en envoyant un signal EOS pour finaliser les en-têtes
|
||||||
|
pub fn stop(&self) {
|
||||||
|
if !self.is_recording.swap(false, Ordering::SeqCst) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"[DVR] Finalisation de l'enregistrement {:?}...",
|
||||||
|
self.file_path
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = self.appsrc.end_of_stream();
|
||||||
|
|
||||||
|
if let Some(bus) = self.pipeline.bus() {
|
||||||
|
let deadline = Instant::now() + std::time::Duration::from_millis(1500);
|
||||||
|
while Instant::now() < deadline {
|
||||||
|
if let Some(msg) = bus.timed_pop(gst::ClockTime::from_mseconds(100)) {
|
||||||
|
use gst::MessageView;
|
||||||
|
match msg.view() {
|
||||||
|
MessageView::Eos(..) => {
|
||||||
|
log::info!("[DVR] En-têtes finalisés (EOS reçu).");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MessageView::Error(err) => {
|
||||||
|
log::error!(
|
||||||
|
"[DVR] Erreur GStreamer pendant la finalisation : {}",
|
||||||
|
err.error()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = self.pipeline.set_state(gst::State::Null);
|
||||||
|
log::info!(
|
||||||
|
"[DVR] Fichier sauvegardé : {:?} ({} trames, {:.2} Mo)",
|
||||||
|
self.file_path,
|
||||||
|
self.frames_recorded.load(Ordering::Relaxed),
|
||||||
|
self.bytes_written.load(Ordering::Relaxed) as f64 / (1024.0 * 1024.0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for DvrRecorder {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dvr_filename_generation() {
|
||||||
|
let path = DvrRecorder::generate_filepath("/tmp/test_dvr", DvrContainer::Mkv);
|
||||||
|
assert!(path.to_str().unwrap().starts_with("/tmp/test_dvr/fpv_"));
|
||||||
|
assert!(path.to_str().unwrap().ends_with(".mkv"));
|
||||||
|
|
||||||
|
let path_mp4 = DvrRecorder::generate_filepath("/tmp/test_dvr", DvrContainer::Mp4);
|
||||||
|
assert!(path_mp4.to_str().unwrap().ends_with(".mp4"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dvr_recording_mkv_and_stop() {
|
||||||
|
let dir = "/tmp/test_dvr_run";
|
||||||
|
let dvr = DvrRecorder::start_composited_osd(dir, DvrContainer::Mkv, 320, 240)
|
||||||
|
.expect("start dvr failed");
|
||||||
|
let fake_rgba = vec![0u8; 320 * 240 * 4];
|
||||||
|
for _ in 0..10 {
|
||||||
|
dvr.push_slice(&fake_rgba);
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
let path = dvr.file_path().to_path_buf();
|
||||||
|
dvr.stop();
|
||||||
|
assert!(path.exists());
|
||||||
|
let meta = std::fs::metadata(&path).expect("file metadata");
|
||||||
|
assert!(meta.len() > 0);
|
||||||
|
let _ = std::fs::remove_file(&path);
|
||||||
|
}
|
||||||
|
}
|
||||||
+327
-14
@@ -1,5 +1,6 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
||||||
|
use crate::dvr::{DvrContainer, DvrMode, DvrRecorder};
|
||||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
||||||
use crate::telemetry_osd::{OsdOverlay, TelemetryReceiver, TelemetryState};
|
use crate::telemetry_osd::{OsdOverlay, TelemetryReceiver, TelemetryState};
|
||||||
use crate::video_usb::{UsbVideoReceiver, VideoLinkState};
|
use crate::video_usb::{UsbVideoReceiver, VideoLinkState};
|
||||||
@@ -23,11 +24,35 @@ pub enum SubsystemStatus {
|
|||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LiveOpticalParams {
|
||||||
|
pub camera_fov_deg: f32,
|
||||||
|
pub lens_k1: f32,
|
||||||
|
pub lens_k2: f32,
|
||||||
|
pub screen_distance_m: f32,
|
||||||
|
pub screen_width_m: f32,
|
||||||
|
pub projection_mode: ProjectionMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct DvrConfig {
|
||||||
|
pub dir: String,
|
||||||
|
pub container: DvrContainer,
|
||||||
|
pub mode: DvrMode,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RuntimeMonitor {
|
pub struct RuntimeMonitor {
|
||||||
pub usb_video_status: SubsystemStatus,
|
pub usb_video_status: SubsystemStatus,
|
||||||
pub openxr_status: SubsystemStatus,
|
pub openxr_status: SubsystemStatus,
|
||||||
pub nomad_wifi_status: SubsystemStatus,
|
pub nomad_wifi_status: SubsystemStatus,
|
||||||
pub telemetry_status: SubsystemStatus,
|
pub telemetry_status: SubsystemStatus,
|
||||||
|
pub dvr_status: SubsystemStatus,
|
||||||
|
pub dvr_recording: bool,
|
||||||
|
pub dvr_elapsed_secs: u64,
|
||||||
|
pub dvr_file_size_bytes: u64,
|
||||||
|
pub dvr_frames_recorded: u64,
|
||||||
|
pub dvr_filename: String,
|
||||||
|
pub dvr_file_path: String,
|
||||||
pub video_fps: f32,
|
pub video_fps: f32,
|
||||||
pub video_frames_total: u64,
|
pub video_frames_total: u64,
|
||||||
pub latest_head_pose: HeadPoseSample,
|
pub latest_head_pose: HeadPoseSample,
|
||||||
@@ -50,6 +75,13 @@ impl Default for RuntimeMonitor {
|
|||||||
openxr_status: SubsystemStatus::Stopped,
|
openxr_status: SubsystemStatus::Stopped,
|
||||||
nomad_wifi_status: SubsystemStatus::Stopped,
|
nomad_wifi_status: SubsystemStatus::Stopped,
|
||||||
telemetry_status: SubsystemStatus::Disabled,
|
telemetry_status: SubsystemStatus::Disabled,
|
||||||
|
dvr_status: SubsystemStatus::Stopped,
|
||||||
|
dvr_recording: false,
|
||||||
|
dvr_elapsed_secs: 0,
|
||||||
|
dvr_file_size_bytes: 0,
|
||||||
|
dvr_frames_recorded: 0,
|
||||||
|
dvr_filename: String::new(),
|
||||||
|
dvr_file_path: String::new(),
|
||||||
video_fps: 0.0,
|
video_fps: 0.0,
|
||||||
video_frames_total: 0,
|
video_frames_total: 0,
|
||||||
latest_head_pose: HeadPoseSample::default(),
|
latest_head_pose: HeadPoseSample::default(),
|
||||||
@@ -67,13 +99,16 @@ impl Default for RuntimeMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Poignée légère et sans verrou permettant à l'interface graphique de piloter
|
/// Poignée légère et sans verrou permettant à l'interface graphique de piloter
|
||||||
/// les commandes temps réel (Tare, OSD, Head-Tracking) sans jamais bloquer sur
|
/// les commandes temps réel (Tare, OSD, Head-Tracking, DVR, Optique) sans jamais bloquer sur
|
||||||
/// le Mutex de cycle de vie du moteur (`start` / `stop`).
|
/// le Mutex de cycle de vie du moteur (`start` / `stop`).
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EngineControlHandle {
|
pub struct EngineControlHandle {
|
||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telemetry_enabled_flag: Arc<AtomicBool>,
|
telemetry_enabled_flag: Arc<AtomicBool>,
|
||||||
head_tracking_enabled_flag: Arc<AtomicBool>,
|
head_tracking_enabled_flag: Arc<AtomicBool>,
|
||||||
|
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||||
|
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EngineControlHandle {
|
impl EngineControlHandle {
|
||||||
@@ -100,10 +135,29 @@ impl EngineControlHandle {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FpvEngineController {
|
pub struct FpvEngineController {
|
||||||
pub monitor: Arc<Mutex<RuntimeMonitor>>,
|
pub monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||||
|
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||||
stop_flag: Arc<AtomicBool>,
|
stop_flag: Arc<AtomicBool>,
|
||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telemetry_enabled_flag: Arc<AtomicBool>,
|
telemetry_enabled_flag: Arc<AtomicBool>,
|
||||||
@@ -113,8 +167,25 @@ pub struct FpvEngineController {
|
|||||||
|
|
||||||
impl FpvEngineController {
|
impl FpvEngineController {
|
||||||
pub fn new(initial_telemetry_enabled: bool, initial_head_tracking_enabled: bool) -> Self {
|
pub fn new(initial_telemetry_enabled: bool, initial_head_tracking_enabled: bool) -> Self {
|
||||||
|
let opt = LiveOpticalParams {
|
||||||
|
camera_fov_deg: 140.0,
|
||||||
|
lens_k1: -0.14,
|
||||||
|
lens_k2: 0.03,
|
||||||
|
screen_distance_m: 1.6,
|
||||||
|
screen_width_m: 3.2,
|
||||||
|
projection_mode: ProjectionMode::Dome140,
|
||||||
|
};
|
||||||
|
let dvr_cfg = DvrConfig {
|
||||||
|
dir: "recordings".to_string(),
|
||||||
|
container: DvrContainer::Mkv,
|
||||||
|
mode: DvrMode::StreamCopy,
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
monitor: Arc::new(Mutex::new(RuntimeMonitor::default())),
|
monitor: Arc::new(Mutex::new(RuntimeMonitor::default())),
|
||||||
|
optical_params: Arc::new(Mutex::new(opt)),
|
||||||
|
dvr_toggle_cmd: Arc::new(Mutex::new(None)),
|
||||||
|
dvr_config: Arc::new(Mutex::new(dvr_cfg)),
|
||||||
stop_flag: Arc::new(AtomicBool::new(false)),
|
stop_flag: Arc::new(AtomicBool::new(false)),
|
||||||
recenter_flag: Arc::new(AtomicBool::new(false)),
|
recenter_flag: Arc::new(AtomicBool::new(false)),
|
||||||
telemetry_enabled_flag: Arc::new(AtomicBool::new(initial_telemetry_enabled)),
|
telemetry_enabled_flag: Arc::new(AtomicBool::new(initial_telemetry_enabled)),
|
||||||
@@ -128,9 +199,33 @@ impl FpvEngineController {
|
|||||||
recenter_flag: Arc::clone(&self.recenter_flag),
|
recenter_flag: Arc::clone(&self.recenter_flag),
|
||||||
telemetry_enabled_flag: Arc::clone(&self.telemetry_enabled_flag),
|
telemetry_enabled_flag: Arc::clone(&self.telemetry_enabled_flag),
|
||||||
head_tracking_enabled_flag: Arc::clone(&self.head_tracking_enabled_flag),
|
head_tracking_enabled_flag: Arc::clone(&self.head_tracking_enabled_flag),
|
||||||
|
optical_params: Arc::clone(&self.optical_params),
|
||||||
|
dvr_toggle_cmd: Arc::clone(&self.dvr_toggle_cmd),
|
||||||
|
dvr_config: Arc::clone(&self.dvr_config),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
pub fn is_running(&self) -> bool {
|
||||||
self.worker_handle
|
self.worker_handle
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -210,6 +305,20 @@ impl FpvEngineController {
|
|||||||
self.head_tracking_enabled_flag
|
self.head_tracking_enabled_flag
|
||||||
.store(cfg.head_tracking_enabled, Ordering::Relaxed);
|
.store(cfg.head_tracking_enabled, Ordering::Relaxed);
|
||||||
|
|
||||||
|
*self.optical_params.lock() = LiveOpticalParams {
|
||||||
|
camera_fov_deg: cfg.camera_fov_deg,
|
||||||
|
lens_k1: cfg.lens_k1,
|
||||||
|
lens_k2: cfg.lens_k2,
|
||||||
|
screen_distance_m: cfg.screen_distance_m,
|
||||||
|
screen_width_m: cfg.screen_width_m,
|
||||||
|
projection_mode: ProjectionMode::from_str(&cfg.projection_mode),
|
||||||
|
};
|
||||||
|
*self.dvr_config.lock() = DvrConfig {
|
||||||
|
dir: cfg.dvr_dir.clone(),
|
||||||
|
container: DvrContainer::from_str(&cfg.dvr_format),
|
||||||
|
mode: DvrMode::from_str(&cfg.dvr_mode),
|
||||||
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut mon = self.monitor.lock();
|
let mut mon = self.monitor.lock();
|
||||||
mon.usb_video_status = SubsystemStatus::Starting;
|
mon.usb_video_status = SubsystemStatus::Starting;
|
||||||
@@ -227,6 +336,9 @@ impl FpvEngineController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let monitor_clone = Arc::clone(&self.monitor);
|
let monitor_clone = Arc::clone(&self.monitor);
|
||||||
|
let optical_clone = Arc::clone(&self.optical_params);
|
||||||
|
let dvr_cmd_clone = Arc::clone(&self.dvr_toggle_cmd);
|
||||||
|
let dvr_cfg_clone = Arc::clone(&self.dvr_config);
|
||||||
let stop_clone = Arc::clone(&self.stop_flag);
|
let stop_clone = Arc::clone(&self.stop_flag);
|
||||||
let recenter_clone = Arc::clone(&self.recenter_flag);
|
let recenter_clone = Arc::clone(&self.recenter_flag);
|
||||||
let telem_flag_clone = Arc::clone(&self.telemetry_enabled_flag);
|
let telem_flag_clone = Arc::clone(&self.telemetry_enabled_flag);
|
||||||
@@ -238,6 +350,9 @@ impl FpvEngineController {
|
|||||||
run_engine_worker(
|
run_engine_worker(
|
||||||
cfg,
|
cfg,
|
||||||
monitor_clone,
|
monitor_clone,
|
||||||
|
optical_clone,
|
||||||
|
dvr_cmd_clone,
|
||||||
|
dvr_cfg_clone,
|
||||||
stop_clone,
|
stop_clone,
|
||||||
recenter_clone,
|
recenter_clone,
|
||||||
telem_flag_clone,
|
telem_flag_clone,
|
||||||
@@ -357,14 +472,97 @@ fn sync_video_status(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_dvr_lifecycle(
|
||||||
|
dvr_cmd: &Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_cfg: &Arc<Mutex<DvrConfig>>,
|
||||||
|
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||||
|
video_rx: Option<&UsbVideoReceiver>,
|
||||||
|
cfg: &AppConfig,
|
||||||
|
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
) {
|
||||||
|
let cmd = { dvr_cmd.lock().take() };
|
||||||
|
if let Some(start) = cmd {
|
||||||
|
if start && active_dvr.is_none() {
|
||||||
|
let (dir, container, mode) = {
|
||||||
|
let conf = dvr_cfg.lock();
|
||||||
|
(conf.dir.clone(), conf.container, conf.mode)
|
||||||
|
};
|
||||||
|
|
||||||
|
let start_res = match mode {
|
||||||
|
DvrMode::StreamCopy if cfg.usb_video_mode.eq_ignore_ascii_case("rndis") => {
|
||||||
|
DvrRecorder::start_stream_copy(&dir, container, &cfg.codec)
|
||||||
|
}
|
||||||
|
_ => DvrRecorder::start_composited_osd(
|
||||||
|
&dir,
|
||||||
|
container,
|
||||||
|
cfg.video_width,
|
||||||
|
cfg.video_height,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
match start_res {
|
||||||
|
Ok(recorder) => {
|
||||||
|
log::info!("[DVR] Enregistrement démarré : {:?}", recorder.file_path());
|
||||||
|
if let Some(rx) = video_rx {
|
||||||
|
if recorder.mode() == DvrMode::StreamCopy {
|
||||||
|
rx.set_dvr_sink(Some(Arc::clone(&recorder)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut mon = monitor.lock();
|
||||||
|
mon.dvr_recording = true;
|
||||||
|
mon.dvr_file_path = recorder.file_path().to_string_lossy().to_string();
|
||||||
|
mon.dvr_filename = recorder
|
||||||
|
.file_path()
|
||||||
|
.file_name()
|
||||||
|
.map(|n| n.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
mon.dvr_status = SubsystemStatus::Running(format!(
|
||||||
|
"REC ({:?}) -> {}",
|
||||||
|
recorder.mode(),
|
||||||
|
mon.dvr_filename
|
||||||
|
));
|
||||||
|
*active_dvr = Some(recorder);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("[DVR] Échec démarrage enregistrement : {}", e);
|
||||||
|
monitor.lock().dvr_status = SubsystemStatus::Error(format!("Erreur DVR : {}", e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !start && active_dvr.is_some() {
|
||||||
|
if let Some(recorder) = active_dvr.take() {
|
||||||
|
if let Some(rx) = video_rx {
|
||||||
|
rx.set_dvr_sink(None);
|
||||||
|
}
|
||||||
|
recorder.stop();
|
||||||
|
log::info!("[DVR] Enregistrement finalisé avec succès : {:?}", recorder.file_path());
|
||||||
|
let mut mon = monitor.lock();
|
||||||
|
mon.dvr_recording = false;
|
||||||
|
mon.dvr_status = SubsystemStatus::Stopped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref dvr) = *active_dvr {
|
||||||
|
let mut mon = monitor.lock();
|
||||||
|
mon.dvr_recording = true;
|
||||||
|
mon.dvr_elapsed_secs = dvr.elapsed_secs();
|
||||||
|
mon.dvr_file_size_bytes = dvr.bytes_written();
|
||||||
|
mon.dvr_frames_recorded = dvr.frames_recorded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn run_engine_worker(
|
fn run_engine_worker(
|
||||||
cfg: AppConfig,
|
cfg: AppConfig,
|
||||||
monitor: Arc<Mutex<RuntimeMonitor>>,
|
monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||||
|
dvr_cmd: Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_cfg: Arc<Mutex<DvrConfig>>,
|
||||||
stop_flag: Arc<AtomicBool>,
|
stop_flag: Arc<AtomicBool>,
|
||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telem_enabled_flag: Arc<AtomicBool>,
|
telem_enabled_flag: Arc<AtomicBool>,
|
||||||
ht_enabled_flag: Arc<AtomicBool>,
|
ht_enabled_flag: Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
|
let mut active_dvr: Option<Arc<DvrRecorder>> = None;
|
||||||
log::info!(
|
log::info!(
|
||||||
"[Moteur FPV] Initialisation (VRX Radxa Zero 3W + 8812EU, Canal {}, Profil {}, Mode USB={})...",
|
"[Moteur FPV] Initialisation (VRX Radxa Zero 3W + 8812EU, Canal {}, Profil {}, Mode USB={})...",
|
||||||
cfg.wifi_channel,
|
cfg.wifi_channel,
|
||||||
@@ -416,6 +614,10 @@ fn run_engine_worker(
|
|||||||
let xr_res = try_run_openxr_session(
|
let xr_res = try_run_openxr_session(
|
||||||
&cfg,
|
&cfg,
|
||||||
&monitor,
|
&monitor,
|
||||||
|
&optical_params,
|
||||||
|
&dvr_cmd,
|
||||||
|
&dvr_cfg,
|
||||||
|
&mut active_dvr,
|
||||||
&stop_flag,
|
&stop_flag,
|
||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
@@ -447,6 +649,10 @@ fn run_engine_worker(
|
|||||||
run_desktop_fallback_loop(
|
run_desktop_fallback_loop(
|
||||||
&cfg,
|
&cfg,
|
||||||
&monitor,
|
&monitor,
|
||||||
|
&optical_params,
|
||||||
|
&dvr_cmd,
|
||||||
|
&dvr_cfg,
|
||||||
|
&mut active_dvr,
|
||||||
&stop_flag,
|
&stop_flag,
|
||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
@@ -457,6 +663,13 @@ fn run_engine_worker(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(dvr) = active_dvr.take() {
|
||||||
|
if let Some(ref rx) = video_rx_opt {
|
||||||
|
rx.set_dvr_sink(None);
|
||||||
|
}
|
||||||
|
let _ = dvr.stop();
|
||||||
|
}
|
||||||
|
|
||||||
log::info!("[Moteur FPV] Tous les sous-systèmes ont été arrêtés.");
|
log::info!("[Moteur FPV] Tous les sous-systèmes ont été arrêtés.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,6 +677,10 @@ fn run_engine_worker(
|
|||||||
fn try_run_openxr_session(
|
fn try_run_openxr_session(
|
||||||
cfg: &AppConfig,
|
cfg: &AppConfig,
|
||||||
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
optical_params: &Arc<Mutex<LiveOpticalParams>>,
|
||||||
|
dvr_cmd: &Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_cfg: &Arc<Mutex<DvrConfig>>,
|
||||||
|
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||||
stop_flag: &Arc<AtomicBool>,
|
stop_flag: &Arc<AtomicBool>,
|
||||||
recenter_flag: &Arc<AtomicBool>,
|
recenter_flag: &Arc<AtomicBool>,
|
||||||
telem_enabled_flag: &Arc<AtomicBool>,
|
telem_enabled_flag: &Arc<AtomicBool>,
|
||||||
@@ -547,7 +764,7 @@ fn try_run_openxr_session(
|
|||||||
active_proj.label()
|
active_proj.label()
|
||||||
));
|
));
|
||||||
|
|
||||||
let dome_lut = DomeWarpLut::new(
|
let mut dome_lut = DomeWarpLut::new(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
cfg.camera_fov_deg,
|
cfg.camera_fov_deg,
|
||||||
@@ -566,9 +783,6 @@ fn try_run_openxr_session(
|
|||||||
.create_reference_space(xr::ReferenceSpaceType::VIEW, xr::Posef::IDENTITY)?;
|
.create_reference_space(xr::ReferenceSpaceType::VIEW, xr::Posef::IDENTITY)?;
|
||||||
|
|
||||||
let aspect = cfg.video_width as f32 / cfg.video_height as f32;
|
let aspect = cfg.video_width as f32 / cfg.video_height as f32;
|
||||||
let screen_height_m = cfg.screen_width_m / aspect;
|
|
||||||
let horizontal_fov_rad = cfg.camera_fov_deg.to_radians();
|
|
||||||
let half_vert_fov_rad = (horizontal_fov_rad / aspect) * 0.5;
|
|
||||||
|
|
||||||
let mut event_storage = xr::EventDataBuffer::new();
|
let mut event_storage = xr::EventDataBuffer::new();
|
||||||
let mut session_running = false;
|
let mut session_running = false;
|
||||||
@@ -581,6 +795,45 @@ fn try_run_openxr_session(
|
|||||||
let mut last_frame_id: u64 = 0;
|
let mut last_frame_id: u64 = 0;
|
||||||
|
|
||||||
while !stop_flag.load(Ordering::Relaxed) || session_running {
|
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(
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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);
|
let telem_on = telem_enabled_flag.load(Ordering::Relaxed);
|
||||||
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
||||||
|
|
||||||
@@ -735,7 +988,7 @@ fn try_run_openxr_session(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(raw) = new_raw_frame {
|
if let Some(ref raw) = new_raw_frame {
|
||||||
dome_lut.apply(&raw, &mut composited_rgba);
|
dome_lut.apply(&raw, &mut composited_rgba);
|
||||||
} else if !has_video_stream {
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
@@ -762,6 +1015,11 @@ fn try_run_openxr_session(
|
|||||||
.map(|t| t.state().lock().clone())
|
.map(|t| t.state().lock().clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let (dvr_rec, dvr_secs) = {
|
||||||
|
let mon = monitor.lock();
|
||||||
|
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
||||||
|
};
|
||||||
|
|
||||||
if telem_on {
|
if telem_on {
|
||||||
OsdOverlay::render(
|
OsdOverlay::render(
|
||||||
&mut composited_rgba,
|
&mut composited_rgba,
|
||||||
@@ -774,9 +1032,17 @@ fn try_run_openxr_session(
|
|||||||
cfg.max_pan_deg,
|
cfg.max_pan_deg,
|
||||||
cfg.max_tilt_deg,
|
cfg.max_tilt_deg,
|
||||||
active_proj.label(),
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vk_xr.upload_rgba_to_swapchain(&composited_rgba)?;
|
vk_xr.upload_rgba_to_swapchain(&composited_rgba)?;
|
||||||
|
|
||||||
if standby_tick % 2 == 0 || last_frame_id % 2 == 0 {
|
if standby_tick % 2 == 0 || last_frame_id % 2 == 0 {
|
||||||
@@ -815,6 +1081,10 @@ fn try_run_openxr_session(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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
|
let frame_stream = vk_xr
|
||||||
.frame_stream
|
.frame_stream
|
||||||
.as_mut()
|
.as_mut()
|
||||||
@@ -826,7 +1096,7 @@ fn try_run_openxr_session(
|
|||||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||||
.sub_image(sub_image)
|
.sub_image(sub_image)
|
||||||
.pose(xr::Posef::IDENTITY)
|
.pose(xr::Posef::IDENTITY)
|
||||||
.radius(cfg.screen_distance_m)
|
.radius(cur_opt.screen_distance_m)
|
||||||
.central_horizontal_angle(horizontal_fov_rad)
|
.central_horizontal_angle(horizontal_fov_rad)
|
||||||
.upper_vertical_angle(half_vert_fov_rad)
|
.upper_vertical_angle(half_vert_fov_rad)
|
||||||
.lower_vertical_angle(-half_vert_fov_rad);
|
.lower_vertical_angle(-half_vert_fov_rad);
|
||||||
@@ -843,7 +1113,7 @@ fn try_run_openxr_session(
|
|||||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||||
.sub_image(sub_image)
|
.sub_image(sub_image)
|
||||||
.pose(xr::Posef::IDENTITY)
|
.pose(xr::Posef::IDENTITY)
|
||||||
.radius(cfg.screen_distance_m)
|
.radius(cur_opt.screen_distance_m)
|
||||||
.central_angle(horizontal_fov_rad)
|
.central_angle(horizontal_fov_rad)
|
||||||
.aspect_ratio(aspect);
|
.aspect_ratio(aspect);
|
||||||
|
|
||||||
@@ -859,7 +1129,7 @@ fn try_run_openxr_session(
|
|||||||
position: xr::Vector3f {
|
position: xr::Vector3f {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
z: -cfg.screen_distance_m,
|
z: -cur_opt.screen_distance_m,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -869,7 +1139,7 @@ fn try_run_openxr_session(
|
|||||||
.sub_image(sub_image)
|
.sub_image(sub_image)
|
||||||
.pose(quad_pose)
|
.pose(quad_pose)
|
||||||
.size(xr::Extent2Df {
|
.size(xr::Extent2Df {
|
||||||
width: cfg.screen_width_m,
|
width: cur_opt.screen_width_m,
|
||||||
height: screen_height_m,
|
height: screen_height_m,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -901,6 +1171,10 @@ fn try_run_openxr_session(
|
|||||||
fn run_desktop_fallback_loop(
|
fn run_desktop_fallback_loop(
|
||||||
cfg: &AppConfig,
|
cfg: &AppConfig,
|
||||||
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
optical_params: &Arc<Mutex<LiveOpticalParams>>,
|
||||||
|
dvr_cmd: &Arc<Mutex<Option<bool>>>,
|
||||||
|
dvr_cfg: &Arc<Mutex<DvrConfig>>,
|
||||||
|
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||||
stop_flag: &Arc<AtomicBool>,
|
stop_flag: &Arc<AtomicBool>,
|
||||||
recenter_flag: &Arc<AtomicBool>,
|
recenter_flag: &Arc<AtomicBool>,
|
||||||
telem_enabled_flag: &Arc<AtomicBool>,
|
telem_enabled_flag: &Arc<AtomicBool>,
|
||||||
@@ -909,8 +1183,7 @@ fn run_desktop_fallback_loop(
|
|||||||
telem_rx_opt: &mut Option<TelemetryReceiver>,
|
telem_rx_opt: &mut Option<TelemetryReceiver>,
|
||||||
head_tracker_opt: &mut Option<NomadHeadTracker>,
|
head_tracker_opt: &mut Option<NomadHeadTracker>,
|
||||||
) {
|
) {
|
||||||
let proj_mode = ProjectionMode::from_str(&cfg.projection_mode);
|
let mut dome_lut = DomeWarpLut::new(
|
||||||
let dome_lut = DomeWarpLut::new(
|
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
cfg.camera_fov_deg,
|
cfg.camera_fov_deg,
|
||||||
@@ -926,6 +1199,33 @@ fn run_desktop_fallback_loop(
|
|||||||
while !stop_flag.load(Ordering::Relaxed) {
|
while !stop_flag.load(Ordering::Relaxed) {
|
||||||
let loop_start = Instant::now();
|
let loop_start = Instant::now();
|
||||||
|
|
||||||
|
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(
|
||||||
|
cfg.video_width,
|
||||||
|
cfg.video_height,
|
||||||
|
cur_opt.camera_fov_deg,
|
||||||
|
cur_opt.lens_k1,
|
||||||
|
cur_opt.lens_k2,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let active_proj = cur_opt.projection_mode;
|
||||||
|
|
||||||
|
handle_dvr_lifecycle(
|
||||||
|
dvr_cmd,
|
||||||
|
dvr_cfg,
|
||||||
|
active_dvr,
|
||||||
|
video_rx_opt,
|
||||||
|
cfg,
|
||||||
|
monitor,
|
||||||
|
);
|
||||||
|
|
||||||
let telem_on = telem_enabled_flag.load(Ordering::Relaxed);
|
let telem_on = telem_enabled_flag.load(Ordering::Relaxed);
|
||||||
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
sync_telemetry_receiver(cfg, telem_on, telem_rx_opt, monitor);
|
||||||
|
|
||||||
@@ -976,7 +1276,7 @@ fn run_desktop_fallback_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(raw) = new_raw_frame {
|
if let Some(ref raw) = new_raw_frame {
|
||||||
dome_lut.apply(&raw, &mut composited_rgba);
|
dome_lut.apply(&raw, &mut composited_rgba);
|
||||||
} else if !has_video_stream {
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
@@ -1003,6 +1303,11 @@ fn run_desktop_fallback_loop(
|
|||||||
.map(|t| t.state().lock().clone())
|
.map(|t| t.state().lock().clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let (dvr_rec, dvr_secs) = {
|
||||||
|
let mon = monitor.lock();
|
||||||
|
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
||||||
|
};
|
||||||
|
|
||||||
if telem_on {
|
if telem_on {
|
||||||
OsdOverlay::render(
|
OsdOverlay::render(
|
||||||
&mut composited_rgba,
|
&mut composited_rgba,
|
||||||
@@ -1014,10 +1319,18 @@ fn run_desktop_fallback_loop(
|
|||||||
current_pose.roll_deg,
|
current_pose.roll_deg,
|
||||||
cfg.max_pan_deg,
|
cfg.max_pan_deg,
|
||||||
cfg.max_tilt_deg,
|
cfg.max_tilt_deg,
|
||||||
proj_mode.label(),
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sync_video_status(cfg, video_rx_opt, monitor);
|
sync_video_status(cfg, video_rx_opt, monitor);
|
||||||
{
|
{
|
||||||
let mut mon = monitor.lock();
|
let mut mon = monitor.lock();
|
||||||
|
|||||||
+199
-9
@@ -1,5 +1,7 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::engine::{FpvEngineController, SubsystemStatus};
|
use crate::dome_projection::ProjectionMode;
|
||||||
|
use crate::dvr::{DvrContainer, DvrMode};
|
||||||
|
use crate::engine::{FpvEngineController, LiveOpticalParams, SubsystemStatus};
|
||||||
use crate::logger::{LogBuffer, LogFilter};
|
use crate::logger::{LogBuffer, LogFilter};
|
||||||
use crate::nomad_elrs::NomadHeadTracker;
|
use crate::nomad_elrs::NomadHeadTracker;
|
||||||
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
||||||
@@ -9,7 +11,6 @@ use std::process::Command;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
||||||
pub struct SteamFrameGuiApp {
|
pub struct SteamFrameGuiApp {
|
||||||
cfg: AppConfig,
|
cfg: AppConfig,
|
||||||
engine: FpvEngineController,
|
engine: FpvEngineController,
|
||||||
@@ -42,6 +43,25 @@ impl SteamFrameGuiApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sync_optical_params(&self) {
|
||||||
|
self.engine.update_optical_params(LiveOpticalParams {
|
||||||
|
projection_mode: ProjectionMode::from_str(&self.cfg.projection_mode),
|
||||||
|
camera_fov_deg: self.cfg.camera_fov_deg,
|
||||||
|
lens_k1: self.cfg.lens_k1,
|
||||||
|
lens_k2: self.cfg.lens_k2,
|
||||||
|
screen_distance_m: self.cfg.screen_distance_m,
|
||||||
|
screen_width_m: self.cfg.screen_width_m,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sync_dvr_config(&self) {
|
||||||
|
self.engine.update_dvr_config(
|
||||||
|
self.cfg.dvr_dir.clone(),
|
||||||
|
DvrContainer::from_str(&self.cfg.dvr_format),
|
||||||
|
DvrMode::from_str(&self.cfg.dvr_mode),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn status_badge(ui: &mut egui::Ui, title: &str, status: &SubsystemStatus) {
|
fn status_badge(ui: &mut egui::Ui, title: &str, status: &SubsystemStatus) {
|
||||||
let (color, text) = match status {
|
let (color, text) = match status {
|
||||||
SubsystemStatus::Stopped => (Color32::from_rgb(130, 130, 140), "Arrêté".to_string()),
|
SubsystemStatus::Stopped => (Color32::from_rgb(130, 130, 140), "Arrêté".to_string()),
|
||||||
@@ -200,6 +220,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
xr_status,
|
xr_status,
|
||||||
nomad_status,
|
nomad_status,
|
||||||
telem_status,
|
telem_status,
|
||||||
|
dvr_status,
|
||||||
|
dvr_recording,
|
||||||
|
dvr_secs,
|
||||||
|
dvr_bytes,
|
||||||
|
dvr_frames,
|
||||||
fps,
|
fps,
|
||||||
total_frames,
|
total_frames,
|
||||||
pose,
|
pose,
|
||||||
@@ -230,6 +255,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
mon.openxr_status.clone(),
|
mon.openxr_status.clone(),
|
||||||
mon.nomad_wifi_status.clone(),
|
mon.nomad_wifi_status.clone(),
|
||||||
mon.telemetry_status.clone(),
|
mon.telemetry_status.clone(),
|
||||||
|
mon.dvr_status.clone(),
|
||||||
|
mon.dvr_recording,
|
||||||
|
mon.dvr_elapsed_secs,
|
||||||
|
mon.dvr_file_size_bytes,
|
||||||
|
mon.dvr_frames_recorded,
|
||||||
mon.video_fps,
|
mon.video_fps,
|
||||||
mon.video_frames_total,
|
mon.video_frames_total,
|
||||||
mon.latest_head_pose,
|
mon.latest_head_pose,
|
||||||
@@ -321,6 +351,33 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
self.engine.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
self.engine.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
let dvr_btn_label = if dvr_recording {
|
||||||
|
let mb = dvr_bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
let mins = dvr_secs / 60;
|
||||||
|
let secs = dvr_secs % 60;
|
||||||
|
RichText::new(format!("⏹ Arrêter DVR ({:02}:{:02} - {:.1} Mo)", mins, secs, mb))
|
||||||
|
.color(Color32::from_rgb(255, 80, 80))
|
||||||
|
.strong()
|
||||||
|
} else {
|
||||||
|
RichText::new("🔴 Enregistrer DVR")
|
||||||
|
.color(Color32::from_rgb(255, 120, 120))
|
||||||
|
.strong()
|
||||||
|
};
|
||||||
|
|
||||||
|
if ui
|
||||||
|
.button(dvr_btn_label)
|
||||||
|
.on_hover_text("Démarrer ou arrêter l'enregistrement vidéo DVR à chaud")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
if dvr_recording {
|
||||||
|
self.engine.stop_dvr();
|
||||||
|
} else {
|
||||||
|
self.engine.start_dvr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
if ui
|
if ui
|
||||||
.button(
|
.button(
|
||||||
@@ -343,6 +400,7 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
Self::status_badge(ui, "Casque OpenXR", &xr_status);
|
Self::status_badge(ui, "Casque OpenXR", &xr_status);
|
||||||
Self::status_badge(ui, "Wi-Fi Nomad ELRS", &nomad_status);
|
Self::status_badge(ui, "Wi-Fi Nomad ELRS", &nomad_status);
|
||||||
Self::status_badge(ui, "Télémétrie OSD", &telem_status);
|
Self::status_badge(ui, "Télémétrie OSD", &telem_status);
|
||||||
|
Self::status_badge(ui, "DVR Vidéo", &dvr_status);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -805,29 +863,49 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("FOV Caméra (°) :");
|
ui.label("FOV Caméra (°) :");
|
||||||
ui.add(
|
if ui
|
||||||
|
.add(
|
||||||
egui::Slider::new(&mut self.cfg.camera_fov_deg, 70.0..=180.0)
|
egui::Slider::new(&mut self.cfg.camera_fov_deg, 70.0..=180.0)
|
||||||
.suffix("°"),
|
.suffix("°"),
|
||||||
);
|
)
|
||||||
|
.changed()
|
||||||
|
{
|
||||||
|
self.sync_optical_params();
|
||||||
|
}
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Correction Lentille k1 :");
|
ui.label("Correction Lentille k1 :");
|
||||||
ui.add(egui::Slider::new(&mut self.cfg.lens_k1, -0.50..=0.50));
|
if ui
|
||||||
|
.add(egui::Slider::new(&mut self.cfg.lens_k1, -0.50..=0.50))
|
||||||
|
.changed()
|
||||||
|
{
|
||||||
|
self.sync_optical_params();
|
||||||
|
}
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Correction Lentille k2 :");
|
ui.label("Correction Lentille k2 :");
|
||||||
ui.add(egui::Slider::new(&mut self.cfg.lens_k2, -0.25..=0.25));
|
if ui
|
||||||
|
.add(egui::Slider::new(&mut self.cfg.lens_k2, -0.25..=0.25))
|
||||||
|
.changed()
|
||||||
|
{
|
||||||
|
self.sync_optical_params();
|
||||||
|
}
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Rayon / Distance (m) :");
|
ui.label("Rayon / Distance (m) :");
|
||||||
ui.add(
|
if ui
|
||||||
|
.add(
|
||||||
egui::Slider::new(&mut self.cfg.screen_distance_m, 0.8..=4.0)
|
egui::Slider::new(&mut self.cfg.screen_distance_m, 0.8..=4.0)
|
||||||
.suffix(" m"),
|
.suffix(" m"),
|
||||||
);
|
)
|
||||||
|
.changed()
|
||||||
|
{
|
||||||
|
self.sync_optical_params();
|
||||||
|
}
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(6.0);
|
ui.add_space(4.0);
|
||||||
if ui
|
if ui
|
||||||
.button(RichText::new("✔ Appliquer les changements").strong())
|
.button(RichText::new("✔ Appliquer les changements").strong())
|
||||||
.clicked()
|
.clicked()
|
||||||
@@ -835,6 +913,118 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
self.engine.start(self.cfg.clone());
|
self.engine.start(self.cfg.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
// --- Section 4 : Enregistrement DVR Vidéo ---
|
||||||
|
egui::CollapsingHeader::new(
|
||||||
|
RichText::new("🔴 4. Enregistrement Vidéo DVR").strong(),
|
||||||
|
)
|
||||||
|
.default_open(true)
|
||||||
|
.show(ui, |ui| {
|
||||||
|
egui::Grid::new("dvr_cfg_grid")
|
||||||
|
.num_columns(2)
|
||||||
|
.spacing([8.0, 6.0])
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.label("Dossier Vidéo :");
|
||||||
|
ui.text_edit_singleline(&mut self.cfg.dvr_dir);
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Format Conteneur :");
|
||||||
|
egui::ComboBox::from_id_salt("dvr_fmt_combo")
|
||||||
|
.selected_text(self.cfg.dvr_format.to_uppercase())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
if ui
|
||||||
|
.selectable_value(
|
||||||
|
&mut self.cfg.dvr_format,
|
||||||
|
"mkv".to_string(),
|
||||||
|
"MKV (Matroska - Résistant coupure batterie)",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.sync_dvr_config();
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.selectable_value(
|
||||||
|
&mut self.cfg.dvr_format,
|
||||||
|
"mp4".to_string(),
|
||||||
|
"MP4 (Fragmenté)",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.sync_dvr_config();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Mode DVR :");
|
||||||
|
let mode_label = if self.cfg.dvr_mode == "composited" || self.cfg.dvr_mode == "osd" {
|
||||||
|
"Avec OSD incrusté (Re-encodage rapide)"
|
||||||
|
} else {
|
||||||
|
"Flux natif Zéro-CPU (StreamCopy direct)"
|
||||||
|
};
|
||||||
|
egui::ComboBox::from_id_salt("dvr_mode_combo")
|
||||||
|
.selected_text(mode_label)
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
if ui
|
||||||
|
.selectable_value(
|
||||||
|
&mut self.cfg.dvr_mode,
|
||||||
|
"copy".to_string(),
|
||||||
|
"Flux natif Zéro-CPU (StreamCopy direct)",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.sync_dvr_config();
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.selectable_value(
|
||||||
|
&mut self.cfg.dvr_mode,
|
||||||
|
"composited".to_string(),
|
||||||
|
"Avec OSD incrusté (Re-encodage rapide)",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.sync_dvr_config();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.end_row();
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
|
if dvr_recording {
|
||||||
|
let mb = dvr_bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
let mins = dvr_secs / 60;
|
||||||
|
let secs = dvr_secs % 60;
|
||||||
|
ui.colored_label(
|
||||||
|
Color32::from_rgb(255, 75, 75),
|
||||||
|
format!(
|
||||||
|
"● ENREGISTREMENT ACTIF : {:02}:{:02} ({} trames, {:.1} Mo)",
|
||||||
|
mins, secs, dvr_frames, mb
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if ui
|
||||||
|
.button(
|
||||||
|
RichText::new("⏹ Arrêter l'enregistrement DVR")
|
||||||
|
.color(Color32::from_rgb(255, 80, 80))
|
||||||
|
.strong(),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.engine.stop_dvr();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ui
|
||||||
|
.button(
|
||||||
|
RichText::new("🔴 Démarrer l'enregistrement DVR")
|
||||||
|
.color(Color32::from_rgb(255, 110, 110))
|
||||||
|
.strong(),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.engine.start_dvr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+211
-2
@@ -1,5 +1,9 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::engine::{EngineControlHandle, FpvEngineController, RuntimeMonitor, SubsystemStatus};
|
use crate::dome_projection::ProjectionMode;
|
||||||
|
use crate::dvr::{DvrContainer, DvrMode};
|
||||||
|
use crate::engine::{
|
||||||
|
EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus,
|
||||||
|
};
|
||||||
use crate::logger::{LogBuffer, LogEntry, LogFilter};
|
use crate::logger::{LogBuffer, LogEntry, LogFilter};
|
||||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
||||||
use crate::telemetry_osd::TelemetryState;
|
use crate::telemetry_osd::TelemetryState;
|
||||||
@@ -58,6 +62,12 @@ pub struct SteamFrameGpuiApp {
|
|||||||
xr_status: SubsystemStatus,
|
xr_status: SubsystemStatus,
|
||||||
nomad_status: SubsystemStatus,
|
nomad_status: SubsystemStatus,
|
||||||
telem_status: SubsystemStatus,
|
telem_status: SubsystemStatus,
|
||||||
|
dvr_status: SubsystemStatus,
|
||||||
|
dvr_recording: bool,
|
||||||
|
dvr_elapsed_secs: u64,
|
||||||
|
dvr_file_size_bytes: u64,
|
||||||
|
dvr_frames_recorded: u64,
|
||||||
|
dvr_filename: String,
|
||||||
video_fps: f32,
|
video_fps: f32,
|
||||||
video_frames_total: u64,
|
video_frames_total: u64,
|
||||||
latest_pose: HeadPoseSample,
|
latest_pose: HeadPoseSample,
|
||||||
@@ -95,6 +105,12 @@ impl SteamFrameGpuiApp {
|
|||||||
xr_status: SubsystemStatus::Starting,
|
xr_status: SubsystemStatus::Starting,
|
||||||
nomad_status: SubsystemStatus::Disabled,
|
nomad_status: SubsystemStatus::Disabled,
|
||||||
telem_status: SubsystemStatus::Disabled,
|
telem_status: SubsystemStatus::Disabled,
|
||||||
|
dvr_status: SubsystemStatus::Stopped,
|
||||||
|
dvr_recording: false,
|
||||||
|
dvr_elapsed_secs: 0,
|
||||||
|
dvr_file_size_bytes: 0,
|
||||||
|
dvr_frames_recorded: 0,
|
||||||
|
dvr_filename: String::new(),
|
||||||
video_fps: 0.0,
|
video_fps: 0.0,
|
||||||
video_frames_total: 0,
|
video_frames_total: 0,
|
||||||
latest_pose: HeadPoseSample::default(),
|
latest_pose: HeadPoseSample::default(),
|
||||||
@@ -130,6 +146,18 @@ impl SteamFrameGpuiApp {
|
|||||||
self.telem_status = mon.telemetry_status.clone();
|
self.telem_status = mon.telemetry_status.clone();
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
if self.dvr_recording != mon.dvr_recording
|
||||||
|
|| self.dvr_elapsed_secs != mon.dvr_elapsed_secs
|
||||||
|
|| self.dvr_status != mon.dvr_status
|
||||||
|
{
|
||||||
|
self.dvr_recording = mon.dvr_recording;
|
||||||
|
self.dvr_elapsed_secs = mon.dvr_elapsed_secs;
|
||||||
|
self.dvr_file_size_bytes = mon.dvr_file_size_bytes;
|
||||||
|
self.dvr_frames_recorded = mon.dvr_frames_recorded;
|
||||||
|
self.dvr_filename = mon.dvr_filename.clone();
|
||||||
|
self.dvr_status = mon.dvr_status.clone();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
if (self.video_fps - mon.video_fps).abs() > 0.1 {
|
if (self.video_fps - mon.video_fps).abs() > 0.1 {
|
||||||
self.video_fps = mon.video_fps;
|
self.video_fps = mon.video_fps;
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -353,7 +381,8 @@ impl SteamFrameGpuiApp {
|
|||||||
.child("🥽 SteamFrame FPV"),
|
.child("🥽 SteamFrame FPV"),
|
||||||
)
|
)
|
||||||
.child(self.render_status_badge("VRX", &self.usb_status))
|
.child(self.render_status_badge("VRX", &self.usb_status))
|
||||||
.child(self.render_status_badge("VR", &self.xr_status)),
|
.child(self.render_status_badge("VR", &self.xr_status))
|
||||||
|
.child(self.render_status_badge("DVR", &self.dvr_status)),
|
||||||
)
|
)
|
||||||
// CENTRE : Barre d'onglets épurée
|
// CENTRE : Barre d'onglets épurée
|
||||||
.child(
|
.child(
|
||||||
@@ -434,6 +463,36 @@ impl SteamFrameGpuiApp {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}))
|
}))
|
||||||
.child("🎯 Tare"),
|
.child("🎯 Tare"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("btn_dvr_quick")
|
||||||
|
.px_2p5()
|
||||||
|
.py_1()
|
||||||
|
.bg(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_SURFACE_ELEVATED) })
|
||||||
|
.border_1()
|
||||||
|
.border_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_BORDER_SUBTLE) })
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||||||
|
.text_color(if self.dvr_recording { rgb(0xffffff) } else { rgb(COLOR_TEXT_MAIN) })
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
if this.dvr_recording {
|
||||||
|
this.controls.stop_dvr();
|
||||||
|
} else {
|
||||||
|
this.controls.start_dvr();
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(if self.dvr_recording {
|
||||||
|
let mins = self.dvr_elapsed_secs / 60;
|
||||||
|
let secs = self.dvr_elapsed_secs % 60;
|
||||||
|
let mb = self.dvr_file_size_bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
format!("⏹ DVR ({:02}:{:02} - {:.1}Mo)", mins, secs, mb)
|
||||||
|
} else {
|
||||||
|
"🔴 DVR".to_string()
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1010,6 +1069,14 @@ impl SteamFrameGpuiApp {
|
|||||||
self.cfg.projection_mode.eq_ignore_ascii_case("dome"),
|
self.cfg.projection_mode.eq_ignore_ascii_case("dome"),
|
||||||
cx.listener(|this, _, _, cx| {
|
cx.listener(|this, _, _, cx| {
|
||||||
this.cfg.projection_mode = "dome".into();
|
this.cfg.projection_mode = "dome".into();
|
||||||
|
this.controls.update_optical_params(LiveOpticalParams {
|
||||||
|
camera_fov_deg: this.cfg.camera_fov_deg,
|
||||||
|
lens_k1: this.cfg.lens_k1,
|
||||||
|
lens_k2: this.cfg.lens_k2,
|
||||||
|
screen_distance_m: this.cfg.screen_distance_m,
|
||||||
|
screen_width_m: this.cfg.screen_width_m,
|
||||||
|
projection_mode: ProjectionMode::Dome140,
|
||||||
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
@@ -1019,6 +1086,14 @@ impl SteamFrameGpuiApp {
|
|||||||
self.cfg.projection_mode.eq_ignore_ascii_case("cylinder"),
|
self.cfg.projection_mode.eq_ignore_ascii_case("cylinder"),
|
||||||
cx.listener(|this, _, _, cx| {
|
cx.listener(|this, _, _, cx| {
|
||||||
this.cfg.projection_mode = "cylinder".into();
|
this.cfg.projection_mode = "cylinder".into();
|
||||||
|
this.controls.update_optical_params(LiveOpticalParams {
|
||||||
|
camera_fov_deg: this.cfg.camera_fov_deg,
|
||||||
|
lens_k1: this.cfg.lens_k1,
|
||||||
|
lens_k2: this.cfg.lens_k2,
|
||||||
|
screen_distance_m: this.cfg.screen_distance_m,
|
||||||
|
screen_width_m: this.cfg.screen_width_m,
|
||||||
|
projection_mode: ProjectionMode::Cylinder140,
|
||||||
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
@@ -1028,6 +1103,14 @@ impl SteamFrameGpuiApp {
|
|||||||
self.cfg.projection_mode.eq_ignore_ascii_case("flat"),
|
self.cfg.projection_mode.eq_ignore_ascii_case("flat"),
|
||||||
cx.listener(|this, _, _, cx| {
|
cx.listener(|this, _, _, cx| {
|
||||||
this.cfg.projection_mode = "flat".into();
|
this.cfg.projection_mode = "flat".into();
|
||||||
|
this.controls.update_optical_params(LiveOpticalParams {
|
||||||
|
camera_fov_deg: this.cfg.camera_fov_deg,
|
||||||
|
lens_k1: this.cfg.lens_k1,
|
||||||
|
lens_k2: this.cfg.lens_k2,
|
||||||
|
screen_distance_m: this.cfg.screen_distance_m,
|
||||||
|
screen_width_m: this.cfg.screen_width_m,
|
||||||
|
projection_mode: ProjectionMode::FlatQuad,
|
||||||
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
@@ -1093,6 +1176,132 @@ impl SteamFrameGpuiApp {
|
|||||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
.text_color(rgb(COLOR_TEXT_MAIN))
|
||||||
.child(format!("0.0.0.0:{}", self.cfg.telemetry_udp_port)),
|
.child(format!("0.0.0.0:{}", self.cfg.telemetry_udp_port)),
|
||||||
)),
|
)),
|
||||||
|
))
|
||||||
|
// 3.5 Carte Enregistreur Vidéo DVR
|
||||||
|
.child(self.render_settings_card(
|
||||||
|
"🎥 5. Enregistreur Vidéo DVR",
|
||||||
|
COLOR_RED,
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
// Format de conteneur
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"Format Conteneur",
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_dvr_mkv",
|
||||||
|
"MKV (Résistant)",
|
||||||
|
self.cfg.dvr_format.eq_ignore_ascii_case("mkv"),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.dvr_format = "mkv".into();
|
||||||
|
this.controls.update_dvr_config(
|
||||||
|
this.cfg.dvr_dir.clone(),
|
||||||
|
DvrContainer::Mkv,
|
||||||
|
DvrMode::from_str(&this.cfg.dvr_mode),
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_dvr_mp4",
|
||||||
|
"MP4 (Standard)",
|
||||||
|
self.cfg.dvr_format.eq_ignore_ascii_case("mp4"),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.dvr_format = "mp4".into();
|
||||||
|
this.controls.update_dvr_config(
|
||||||
|
this.cfg.dvr_dir.clone(),
|
||||||
|
DvrContainer::Mp4,
|
||||||
|
DvrMode::from_str(&this.cfg.dvr_mode),
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
// Mode d'enregistrement
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"Mode Enregistrement",
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_dvr_copy",
|
||||||
|
"Direct 0% CPU",
|
||||||
|
self.cfg.dvr_mode.eq_ignore_ascii_case("copy"),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.dvr_mode = "copy".into();
|
||||||
|
this.controls.update_dvr_config(
|
||||||
|
this.cfg.dvr_dir.clone(),
|
||||||
|
DvrContainer::from_str(&this.cfg.dvr_format),
|
||||||
|
DvrMode::StreamCopy,
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_dvr_osd",
|
||||||
|
"Avec OSD incrusté",
|
||||||
|
self.cfg.dvr_mode.eq_ignore_ascii_case("composited") || self.cfg.dvr_mode.eq_ignore_ascii_case("osd"),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.dvr_mode = "composited".into();
|
||||||
|
this.controls.update_dvr_config(
|
||||||
|
this.cfg.dvr_dir.clone(),
|
||||||
|
DvrContainer::from_str(&this.cfg.dvr_format),
|
||||||
|
DvrMode::CompositedOsd,
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
// Statut & Action
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"Statut DVR",
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_TEXT_MUTED) })
|
||||||
|
.child(if self.dvr_recording {
|
||||||
|
let mins = self.dvr_elapsed_secs / 60;
|
||||||
|
let secs = self.dvr_elapsed_secs % 60;
|
||||||
|
let mb = self.dvr_file_size_bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
format!("● ACTIF : {:02}:{:02} ({} frames, {:.1} Mo)", mins, secs, self.dvr_frames_recorded, mb)
|
||||||
|
} else {
|
||||||
|
"Inactif (Prêt à enregistrer)".to_string()
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.pt_1()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("btn_toggle_dvr_card")
|
||||||
|
.flex_1()
|
||||||
|
.py_1p5()
|
||||||
|
.bg(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_SURFACE_CARD) })
|
||||||
|
.border_1()
|
||||||
|
.border_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_BORDER_SUBTLE) })
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(if self.dvr_recording { rgb(0xffffff) } else { rgb(COLOR_TEXT_MAIN) })
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
if this.dvr_recording {
|
||||||
|
this.controls.stop_dvr();
|
||||||
|
} else {
|
||||||
|
this.controls.start_dvr();
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(if self.dvr_recording {
|
||||||
|
"⏹ Arrêter l'enregistrement DVR"
|
||||||
|
} else {
|
||||||
|
"🔴 Démarrer l'enregistrement DVR"
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-13
@@ -2,8 +2,8 @@ use chrono::Local;
|
|||||||
use log::{Level, LevelFilter, Log, Metadata, Record};
|
use log::{Level, LevelFilter, Log, Metadata, Record};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::Write;
|
use std::io::{BufWriter, Write};
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -43,18 +43,26 @@ impl Default for LogBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
||||||
/// et les enregistrant simultanément dans `steamframe_fpv.log`.
|
/// et les enregistrant simultanément dans un fichier persistant sans réouverture synchrone.
|
||||||
pub struct GuiLogger {
|
pub struct GuiLogger {
|
||||||
buffer: Arc<Mutex<LogBuffer>>,
|
buffer: Arc<Mutex<LogBuffer>>,
|
||||||
log_file_path: String,
|
file_writer: Mutex<Option<BufWriter<File>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiLogger {
|
impl GuiLogger {
|
||||||
pub fn init(log_file_path: &str) -> Arc<Mutex<LogBuffer>> {
|
pub fn init(log_file_path: &str) -> Arc<Mutex<LogBuffer>> {
|
||||||
let buffer = Arc::new(Mutex::new(LogBuffer::default()));
|
let buffer = Arc::new(Mutex::new(LogBuffer::default()));
|
||||||
|
|
||||||
|
let file_writer = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(log_file_path)
|
||||||
|
.ok()
|
||||||
|
.map(BufWriter::new);
|
||||||
|
|
||||||
let logger = Box::new(Self {
|
let logger = Box::new(Self {
|
||||||
buffer: Arc::clone(&buffer),
|
buffer: Arc::clone(&buffer),
|
||||||
log_file_path: log_file_path.to_string(),
|
file_writer: Mutex::new(file_writer),
|
||||||
});
|
});
|
||||||
|
|
||||||
if log::set_boxed_logger(logger).is_ok() {
|
if log::set_boxed_logger(logger).is_ok() {
|
||||||
@@ -87,7 +95,7 @@ impl Log for GuiLogger {
|
|||||||
|
|
||||||
let now = Local::now().format("%H:%M:%S%.3f").to_string();
|
let now = Local::now().format("%H:%M:%S%.3f").to_string();
|
||||||
let entry = LogEntry {
|
let entry = LogEntry {
|
||||||
timestamp: now.clone(),
|
timestamp: now,
|
||||||
level: record.level(),
|
level: record.level(),
|
||||||
target: record.target().to_string(),
|
target: record.target().to_string(),
|
||||||
message: format!("{}", record.args()),
|
message: format!("{}", record.args()),
|
||||||
@@ -99,17 +107,17 @@ impl Log for GuiLogger {
|
|||||||
entry.timestamp, entry.level, entry.target, entry.message
|
entry.timestamp, entry.level, entry.target, entry.message
|
||||||
);
|
);
|
||||||
|
|
||||||
// Écriture persistante sur disque pour diagnostic après crash éventuel
|
// Écriture persistante sur descripteur ouvert avec tampon BufWriter
|
||||||
if let Ok(mut file) = OpenOptions::new()
|
|
||||||
.create(true)
|
|
||||||
.append(true)
|
|
||||||
.open(&self.log_file_path)
|
|
||||||
{
|
{
|
||||||
|
let mut writer_lock = self.file_writer.lock();
|
||||||
|
if let Some(ref mut writer) = *writer_lock {
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
file,
|
writer,
|
||||||
"[{}] [{:<5}] ({}) {}",
|
"[{}] [{:<5}] ({}) {}",
|
||||||
entry.timestamp, entry.level, entry.target, entry.message
|
entry.timestamp, entry.level, entry.target, entry.message
|
||||||
);
|
);
|
||||||
|
let _ = writer.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajout dans le tampon de l'interface graphique
|
// Ajout dans le tampon de l'interface graphique
|
||||||
@@ -133,5 +141,10 @@ impl Log for GuiLogger {
|
|||||||
lock.revision.fetch_add(1, Ordering::Release);
|
lock.revision.fetch_add(1, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {}
|
fn flush(&self) {
|
||||||
|
let mut writer_lock = self.file_writer.lock();
|
||||||
|
if let Some(ref mut writer) = *writer_lock {
|
||||||
|
let _ = writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
mod config;
|
mod config;
|
||||||
mod dome_projection;
|
mod dome_projection;
|
||||||
|
mod dvr;
|
||||||
mod engine;
|
mod engine;
|
||||||
mod gui;
|
mod gui;
|
||||||
mod gui_gpui;
|
mod gui_gpui;
|
||||||
|
|||||||
+22
-8
@@ -228,17 +228,31 @@ impl NomadHeadTracker {
|
|||||||
frame
|
frame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn crc8_dvb_s2(data: &[u8]) -> u8 {
|
pub fn crc8_dvb_s2(data: &[u8]) -> u8 {
|
||||||
|
const TABLE: [u8; 256] = {
|
||||||
|
let mut table = [0u8; 256];
|
||||||
|
let mut i = 0;
|
||||||
|
while i < 256 {
|
||||||
|
let mut curr = i as u8;
|
||||||
|
let mut j = 0;
|
||||||
|
while j < 8 {
|
||||||
|
if (curr & 0x80) != 0 {
|
||||||
|
curr = (curr << 1) ^ 0xD5;
|
||||||
|
} else {
|
||||||
|
curr <<= 1;
|
||||||
|
}
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
table[i] = curr;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
table
|
||||||
|
};
|
||||||
|
|
||||||
let mut crc: u8 = 0;
|
let mut crc: u8 = 0;
|
||||||
for &byte in data {
|
for &byte in data {
|
||||||
crc ^= byte;
|
crc = TABLE[(crc ^ byte) as usize];
|
||||||
for _ in 0..8 {
|
|
||||||
if (crc & 0x80) != 0 {
|
|
||||||
crc = (crc << 1) ^ 0xD5;
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
crc
|
crc
|
||||||
}
|
}
|
||||||
|
|||||||
+116
-18
@@ -1,11 +1,42 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use std::fmt::Write as FmtWrite;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
/// Tampon de formatage rapide sur la pile pour éliminer toute allocation sur le tas dans l'OSD
|
||||||
|
struct StackStr<const N: usize> {
|
||||||
|
buf: [u8; N],
|
||||||
|
len: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> StackStr<N> {
|
||||||
|
#[inline]
|
||||||
|
fn new() -> Self {
|
||||||
|
Self { buf: [0u8; N], len: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn as_str(&self) -> &str {
|
||||||
|
std::str::from_utf8(&self.buf[..self.len]).unwrap_or("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> std::fmt::Write for StackStr<N> {
|
||||||
|
#[inline]
|
||||||
|
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||||
|
let bytes = s.as_bytes();
|
||||||
|
let avail = N.saturating_sub(self.len);
|
||||||
|
let to_copy = bytes.len().min(avail);
|
||||||
|
self.buf[self.len..self.len + to_copy].copy_from_slice(&bytes[..to_copy]);
|
||||||
|
self.len += to_copy;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// État télémétrique temps réel fusionnant MAVLink (OpenIPC / FC) et CRSF (ELRS Nomad)
|
/// État télémétrique temps réel fusionnant MAVLink (OpenIPC / FC) et CRSF (ELRS Nomad)
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TelemetryState {
|
pub struct TelemetryState {
|
||||||
@@ -224,6 +255,27 @@ impl Drop for TelemetryReceiver {
|
|||||||
pub struct OsdOverlay;
|
pub struct OsdOverlay;
|
||||||
|
|
||||||
impl OsdOverlay {
|
impl OsdOverlay {
|
||||||
|
fn draw_heading_ribbon(rgba: &mut [u8], width: u32, height: u32, heading_deg: f32, scale: u32) {
|
||||||
|
let cx = width as i32 / 2;
|
||||||
|
let y = 14;
|
||||||
|
let norm_hdg = heading_deg.rem_euclid(360.0);
|
||||||
|
let card_label = match norm_hdg.round() as i32 {
|
||||||
|
338..=360 | 0..=22 => "N",
|
||||||
|
23..=67 => "NE",
|
||||||
|
68..=112 => "E",
|
||||||
|
113..=157 => "SE",
|
||||||
|
158..=202 => "S",
|
||||||
|
203..=247 => "SW",
|
||||||
|
248..=292 => "W",
|
||||||
|
293..=337 => "NW",
|
||||||
|
_ => "N",
|
||||||
|
};
|
||||||
|
let mut hdg_buf = StackStr::<32>::new();
|
||||||
|
let _ = write!(hdg_buf, "{:03}° {}", norm_hdg.round() as i32, card_label);
|
||||||
|
let hx = cx - ((hdg_buf.as_str().len() as i32 * 6 * scale as i32) / 2);
|
||||||
|
Self::draw_text(rgba, width, height, hx, y, hdg_buf.as_str(), scale, [210, 230, 255, 240]);
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn render(
|
pub fn render(
|
||||||
rgba: &mut [u8],
|
rgba: &mut [u8],
|
||||||
@@ -236,36 +288,67 @@ impl OsdOverlay {
|
|||||||
max_pan_deg: f32,
|
max_pan_deg: f32,
|
||||||
max_tilt_deg: f32,
|
max_tilt_deg: f32,
|
||||||
projection_label: &str,
|
projection_label: &str,
|
||||||
|
dvr_recording: bool,
|
||||||
|
dvr_elapsed_secs: u64,
|
||||||
) {
|
) {
|
||||||
let scale = (height / 360).max(2);
|
let scale = (height / 360).max(2);
|
||||||
|
|
||||||
|
// Indicateur d'enregistrement DVR en direct
|
||||||
|
if dvr_recording {
|
||||||
|
let mins = dvr_elapsed_secs / 60;
|
||||||
|
let secs = dvr_elapsed_secs % 60;
|
||||||
|
let mut rec_buf = StackStr::<32>::new();
|
||||||
|
let _ = write!(rec_buf, "* REC {:02}:{:02}", mins, secs);
|
||||||
|
Self::draw_text(rgba, width, height, 32, 12, rec_buf.as_str(), scale, [255, 45, 45, 255]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// État de la connexion télémétrie (Attente ou Perte de signal)
|
||||||
|
if telem.packets_received == 0 {
|
||||||
|
let wait_text = "WAIT TELEM";
|
||||||
|
let wx = (width as i32 / 2) - ((wait_text.len() as i32 * 6 * scale as i32) / 2);
|
||||||
|
Self::draw_text(rgba, width, height, wx, 8, wait_text, scale, [255, 210, 50, 255]);
|
||||||
|
} else if let Some(last) = telem.last_update {
|
||||||
|
if last.elapsed() > Duration::from_millis(2500) {
|
||||||
|
let lost_text = "! TELEM LOST !";
|
||||||
|
let lx = (width as i32 / 2) - ((lost_text.len() as i32 * 6 * scale as i32) / 2);
|
||||||
|
Self::draw_text(rgba, width, height, lx, 8, lost_text, scale, [255, 60, 60, 255]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ruban de Cap / Boussole en haut
|
||||||
|
Self::draw_heading_ribbon(rgba, width, height, telem.drone_heading_deg, scale);
|
||||||
|
|
||||||
let bat_color = if telem.battery_voltage_v > 0.1 && telem.battery_voltage_v < 14.0 {
|
let bat_color = if telem.battery_voltage_v > 0.1 && telem.battery_voltage_v < 14.0 {
|
||||||
[255, 65, 65, 255]
|
[255, 65, 65, 255]
|
||||||
} else {
|
} else {
|
||||||
[90, 255, 130, 255]
|
[90, 255, 130, 255]
|
||||||
};
|
};
|
||||||
|
|
||||||
let bat_text = if telem.battery_remaining_pct >= 0 {
|
let mut bat_buf = StackStr::<48>::new();
|
||||||
format!(
|
if telem.battery_remaining_pct >= 0 {
|
||||||
|
let _ = write!(
|
||||||
|
bat_buf,
|
||||||
"BAT {:4.1}V {:4.1}A {:3}%",
|
"BAT {:4.1}V {:4.1}A {:3}%",
|
||||||
telem.battery_voltage_v, telem.battery_current_a, telem.battery_remaining_pct
|
telem.battery_voltage_v, telem.battery_current_a, telem.battery_remaining_pct
|
||||||
)
|
);
|
||||||
} else {
|
} else {
|
||||||
format!(
|
let _ = write!(
|
||||||
|
bat_buf,
|
||||||
"BAT {:4.1}V {:4.1}A",
|
"BAT {:4.1}V {:4.1}A",
|
||||||
telem.battery_voltage_v, telem.battery_current_a
|
telem.battery_voltage_v, telem.battery_current_a
|
||||||
)
|
);
|
||||||
};
|
}
|
||||||
Self::draw_text(rgba, width, height, 32, 28, &bat_text, scale, bat_color);
|
Self::draw_text(rgba, width, height, 32, 28, bat_buf.as_str(), scale, bat_color);
|
||||||
|
|
||||||
let lq_color = if telem.link_quality_pct < 70 {
|
let lq_color = if telem.link_quality_pct < 70 {
|
||||||
[255, 180, 40, 255]
|
[255, 180, 40, 255]
|
||||||
} else {
|
} else {
|
||||||
[100, 225, 255, 255]
|
[100, 225, 255, 255]
|
||||||
};
|
};
|
||||||
let link_text = format!("LQ {:3}% RSSI {:3}DBM", telem.link_quality_pct, telem.rssi_dbm);
|
let mut link_buf = StackStr::<48>::new();
|
||||||
let right_x = width.saturating_sub((link_text.len() as u32) * 6 * scale + 32) as i32;
|
let _ = write!(link_buf, "LQ {:3}% RSSI {:3}DBM", telem.link_quality_pct, telem.rssi_dbm);
|
||||||
Self::draw_text(rgba, width, height, right_x, 28, &link_text, scale, lq_color);
|
let right_x = width.saturating_sub((link_buf.as_str().len() as u32) * 6 * scale + 32) as i32;
|
||||||
|
Self::draw_text(rgba, width, height, right_x, 28, link_buf.as_str(), scale, lq_color);
|
||||||
|
|
||||||
Self::draw_gimbal_radar(
|
Self::draw_gimbal_radar(
|
||||||
rgba,
|
rgba,
|
||||||
@@ -277,18 +360,20 @@ impl OsdOverlay {
|
|||||||
max_tilt_deg,
|
max_tilt_deg,
|
||||||
scale,
|
scale,
|
||||||
);
|
);
|
||||||
let ht_text = format!(
|
let mut ht_buf = StackStr::<64>::new();
|
||||||
|
let _ = write!(
|
||||||
|
ht_buf,
|
||||||
"HT PAN {:+4.0} TILT {:+4.0} ROLL {:+4.0}",
|
"HT PAN {:+4.0} TILT {:+4.0} ROLL {:+4.0}",
|
||||||
head_pan_deg, head_tilt_deg, head_roll_deg
|
head_pan_deg, head_tilt_deg, head_roll_deg
|
||||||
);
|
);
|
||||||
let ht_x = (width as i32 / 2) - ((ht_text.len() as i32 * 6 * scale as i32) / 2);
|
let ht_x = (width as i32 / 2) - ((ht_buf.as_str().len() as i32 * 6 * scale as i32) / 2);
|
||||||
Self::draw_text(
|
Self::draw_text(
|
||||||
rgba,
|
rgba,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
ht_x,
|
ht_x,
|
||||||
28 + 46 * scale as i32 / 2,
|
28 + 46 * scale as i32 / 2,
|
||||||
&ht_text,
|
ht_buf.as_str(),
|
||||||
scale,
|
scale,
|
||||||
[230, 240, 255, 255],
|
[230, 240, 255, 255],
|
||||||
);
|
);
|
||||||
@@ -303,30 +388,33 @@ impl OsdOverlay {
|
|||||||
|
|
||||||
let bottom_y = height.saturating_sub(28 + 8 * scale) as i32;
|
let bottom_y = height.saturating_sub(28 + 8 * scale) as i32;
|
||||||
let spd_kmh = telem.groundspeed_ms * 3.6;
|
let spd_kmh = telem.groundspeed_ms * 3.6;
|
||||||
let left_bottom_text = format!("SPD {:4.1}KM/H THR {:3}%", spd_kmh, telem.throttle_pct);
|
let mut left_bottom_buf = StackStr::<48>::new();
|
||||||
|
let _ = write!(left_bottom_buf, "SPD {:4.1}KM/H THR {:3}%", spd_kmh, telem.throttle_pct);
|
||||||
Self::draw_text(
|
Self::draw_text(
|
||||||
rgba,
|
rgba,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
32,
|
32,
|
||||||
bottom_y,
|
bottom_y,
|
||||||
&left_bottom_text,
|
left_bottom_buf.as_str(),
|
||||||
scale,
|
scale,
|
||||||
[240, 240, 240, 255],
|
[240, 240, 240, 255],
|
||||||
);
|
);
|
||||||
|
|
||||||
let right_bottom_text = format!(
|
let mut right_bottom_buf = StackStr::<64>::new();
|
||||||
|
let _ = write!(
|
||||||
|
right_bottom_buf,
|
||||||
"ALT {:5.1}M VSI {:+4.1}M/S [{}]",
|
"ALT {:5.1}M VSI {:+4.1}M/S [{}]",
|
||||||
telem.altitude_m, telem.climb_ms, projection_label
|
telem.altitude_m, telem.climb_ms, projection_label
|
||||||
);
|
);
|
||||||
let rb_x = width.saturating_sub((right_bottom_text.len() as u32) * 6 * scale + 32) as i32;
|
let rb_x = width.saturating_sub((right_bottom_buf.as_str().len() as u32) * 6 * scale + 32) as i32;
|
||||||
Self::draw_text(
|
Self::draw_text(
|
||||||
rgba,
|
rgba,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
rb_x,
|
rb_x,
|
||||||
bottom_y,
|
bottom_y,
|
||||||
&right_bottom_text,
|
right_bottom_buf.as_str(),
|
||||||
scale,
|
scale,
|
||||||
[240, 240, 240, 255],
|
[240, 240, 240, 255],
|
||||||
);
|
);
|
||||||
@@ -543,6 +631,7 @@ impl OsdOverlay {
|
|||||||
'G' => [0b01110, 0b10001, 0b10000, 0b10111, 0b10001, 0b10001, 0b01110],
|
'G' => [0b01110, 0b10001, 0b10000, 0b10111, 0b10001, 0b10001, 0b01110],
|
||||||
'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
||||||
'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||||
|
'J' => [0b00001, 0b00001, 0b00001, 0b00001, 0b10001, 0b10001, 0b01110],
|
||||||
'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
||||||
'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
||||||
'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
||||||
@@ -556,7 +645,9 @@ impl OsdOverlay {
|
|||||||
'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||||
'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
||||||
'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
||||||
|
'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
|
||||||
'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||||
|
'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
|
||||||
'.' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01100, 0b01100],
|
'.' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01100, 0b01100],
|
||||||
':' => [0b00000, 0b01100, 0b01100, 0b00000, 0b01100, 0b01100, 0b00000],
|
':' => [0b00000, 0b01100, 0b01100, 0b00000, 0b01100, 0b01100, 0b00000],
|
||||||
'-' => [0b00000, 0b00000, 0b00000, 0b11111, 0b00000, 0b00000, 0b00000],
|
'-' => [0b00000, 0b00000, 0b00000, 0b11111, 0b00000, 0b00000, 0b00000],
|
||||||
@@ -565,6 +656,13 @@ impl OsdOverlay {
|
|||||||
'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
||||||
'[' => [0b01110, 0b01000, 0b01000, 0b01000, 0b01000, 0b01000, 0b01110],
|
'[' => [0b01110, 0b01000, 0b01000, 0b01000, 0b01000, 0b01000, 0b01110],
|
||||||
']' => [0b01110, 0b00010, 0b00010, 0b00010, 0b00010, 0b00010, 0b01110],
|
']' => [0b01110, 0b00010, 0b00010, 0b00010, 0b00010, 0b00010, 0b01110],
|
||||||
|
'(' => [0b00010, 0b00100, 0b01000, 0b01000, 0b01000, 0b00100, 0b00010],
|
||||||
|
')' => [0b01000, 0b00100, 0b00010, 0b00010, 0b00010, 0b00100, 0b01000],
|
||||||
|
'!' => [0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00000, 0b00100],
|
||||||
|
',' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00100, 0b01000],
|
||||||
|
'*' => [0b00000, 0b10101, 0b01110, 0b11111, 0b01110, 0b10101, 0b00000],
|
||||||
|
'°' => [0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000],
|
||||||
|
|
||||||
_ => [0b00000; 7],
|
_ => [0b00000; 7],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-3
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::dvr::DvrRecorder;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gstreamer as gst;
|
use gstreamer as gst;
|
||||||
use gstreamer::prelude::*;
|
use gstreamer::prelude::*;
|
||||||
@@ -65,6 +66,7 @@ struct PipelineParams {
|
|||||||
pub struct UsbVideoReceiver {
|
pub struct UsbVideoReceiver {
|
||||||
latest_frame: Arc<Mutex<Option<VideoFrame>>>,
|
latest_frame: Arc<Mutex<Option<VideoFrame>>>,
|
||||||
link_state: Arc<Mutex<VideoLinkState>>,
|
link_state: Arc<Mutex<VideoLinkState>>,
|
||||||
|
dvr_sink: Arc<Mutex<Option<Arc<DvrRecorder>>>>,
|
||||||
stop_flag: Arc<AtomicBool>,
|
stop_flag: Arc<AtomicBool>,
|
||||||
supervisor: Option<JoinHandle<()>>,
|
supervisor: Option<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
@@ -104,21 +106,24 @@ impl UsbVideoReceiver {
|
|||||||
|
|
||||||
let latest_frame: Arc<Mutex<Option<VideoFrame>>> = Arc::new(Mutex::new(None));
|
let latest_frame: Arc<Mutex<Option<VideoFrame>>> = Arc::new(Mutex::new(None));
|
||||||
let link_state = Arc::new(Mutex::new(VideoLinkState::Waiting));
|
let link_state = Arc::new(Mutex::new(VideoLinkState::Waiting));
|
||||||
|
let dvr_sink = Arc::new(Mutex::new(None));
|
||||||
let stop_flag = Arc::new(AtomicBool::new(false));
|
let stop_flag = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let supervisor = {
|
let supervisor = {
|
||||||
let latest_frame = Arc::clone(&latest_frame);
|
let latest_frame = Arc::clone(&latest_frame);
|
||||||
let link_state = Arc::clone(&link_state);
|
let link_state = Arc::clone(&link_state);
|
||||||
|
let dvr_sink = Arc::clone(&dvr_sink);
|
||||||
let stop_flag = Arc::clone(&stop_flag);
|
let stop_flag = Arc::clone(&stop_flag);
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
.name("gst-video-supervisor".into())
|
.name("gst-video-supervisor".into())
|
||||||
.spawn(move || supervisor_loop(params, latest_frame, link_state, stop_flag))
|
.spawn(move || supervisor_loop(params, latest_frame, link_state, dvr_sink, stop_flag))
|
||||||
.context("Impossible de créer le thread superviseur vidéo")?
|
.context("Impossible de créer le thread superviseur vidéo")?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
latest_frame,
|
latest_frame,
|
||||||
link_state,
|
link_state,
|
||||||
|
dvr_sink,
|
||||||
stop_flag,
|
stop_flag,
|
||||||
supervisor: Some(supervisor),
|
supervisor: Some(supervisor),
|
||||||
})
|
})
|
||||||
@@ -128,6 +133,11 @@ impl UsbVideoReceiver {
|
|||||||
Arc::clone(&self.latest_frame)
|
Arc::clone(&self.latest_frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_dvr_sink(&self, dvr: Option<Arc<DvrRecorder>>) {
|
||||||
|
let mut lock = self.dvr_sink.lock();
|
||||||
|
*lock = dvr;
|
||||||
|
}
|
||||||
|
|
||||||
/// État courant de la liaison vidéo (mis à jour par le superviseur).
|
/// État courant de la liaison vidéo (mis à jour par le superviseur).
|
||||||
pub fn link_state(&self) -> VideoLinkState {
|
pub fn link_state(&self) -> VideoLinkState {
|
||||||
self.link_state.lock().clone()
|
self.link_state.lock().clone()
|
||||||
@@ -194,7 +204,7 @@ fn pipeline_description(p: &PipelineParams) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let is_h264 = p.codec.eq_ignore_ascii_case("h264");
|
let is_h264 = p.codec.eq_ignore_ascii_case("h264");
|
||||||
let parser = if is_h264 { "h264parse" } else { "h265parse" };
|
let parser = if is_h264 { "h264parse name=nal_parser" } else { "h265parse name=nal_parser" };
|
||||||
let codec_name = if is_h264 { "H264" } else { "H265" };
|
let codec_name = if is_h264 { "H264" } else { "H265" };
|
||||||
let depay = if is_h264 { "rtph264depay" } else { "rtph265depay" };
|
let depay = if is_h264 { "rtph264depay" } else { "rtph265depay" };
|
||||||
let decoder = if is_h264 {
|
let decoder = if is_h264 {
|
||||||
@@ -230,6 +240,7 @@ fn build_pipeline(
|
|||||||
params: &PipelineParams,
|
params: &PipelineParams,
|
||||||
latest_frame: &Arc<Mutex<Option<VideoFrame>>>,
|
latest_frame: &Arc<Mutex<Option<VideoFrame>>>,
|
||||||
sequence: &Arc<AtomicU64>,
|
sequence: &Arc<AtomicU64>,
|
||||||
|
dvr_sink: &Arc<Mutex<Option<Arc<DvrRecorder>>>>,
|
||||||
) -> Result<gst::Pipeline> {
|
) -> Result<gst::Pipeline> {
|
||||||
let pipeline_str = pipeline_description(params);
|
let pipeline_str = pipeline_description(params);
|
||||||
|
|
||||||
@@ -246,6 +257,23 @@ fn build_pipeline(
|
|||||||
.dynamic_cast::<gst_app::AppSink>()
|
.dynamic_cast::<gst_app::AppSink>()
|
||||||
.map_err(|_| anyhow::anyhow!("Impossible de convertir fpv_sink en AppSink"))?;
|
.map_err(|_| anyhow::anyhow!("Impossible de convertir fpv_sink en AppSink"))?;
|
||||||
|
|
||||||
|
if let Some(nal_parser) = pipeline.by_name("nal_parser") {
|
||||||
|
if let Some(src_pad) = nal_parser.static_pad("src") {
|
||||||
|
let dvr_slot = Arc::clone(dvr_sink);
|
||||||
|
src_pad.add_probe(gst::PadProbeType::BUFFER, move |_pad, info| {
|
||||||
|
if let Some(gst::PadProbeData::Buffer(ref buffer)) = info.data {
|
||||||
|
let guard = dvr_slot.lock();
|
||||||
|
if let Some(ref dvr) = *guard {
|
||||||
|
if dvr.mode() == crate::dvr::DvrMode::StreamCopy {
|
||||||
|
dvr.push_buffer(buffer.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gst::PadProbeReturn::Ok
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let frame_store = Arc::clone(latest_frame);
|
let frame_store = Arc::clone(latest_frame);
|
||||||
// Compteur partagé entre les reconstructions : les identifiants de trame restent
|
// Compteur partagé entre les reconstructions : les identifiants de trame restent
|
||||||
// strictement croissants, la boucle de rendu ne rate donc jamais une nouvelle trame.
|
// strictement croissants, la boucle de rendu ne rate donc jamais une nouvelle trame.
|
||||||
@@ -313,6 +341,7 @@ fn supervisor_loop(
|
|||||||
params: PipelineParams,
|
params: PipelineParams,
|
||||||
latest_frame: Arc<Mutex<Option<VideoFrame>>>,
|
latest_frame: Arc<Mutex<Option<VideoFrame>>>,
|
||||||
link_state: Arc<Mutex<VideoLinkState>>,
|
link_state: Arc<Mutex<VideoLinkState>>,
|
||||||
|
dvr_sink: Arc<Mutex<Option<Arc<DvrRecorder>>>>,
|
||||||
stop_flag: Arc<AtomicBool>,
|
stop_flag: Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
let source_desc = if params.usb_video_mode.eq_ignore_ascii_case("uvc") {
|
let source_desc = if params.usb_video_mode.eq_ignore_ascii_case("uvc") {
|
||||||
@@ -356,7 +385,7 @@ fn supervisor_loop(
|
|||||||
thread::sleep(Duration::from_millis(100));
|
thread::sleep(Duration::from_millis(100));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match build_pipeline(¶ms, &latest_frame, &sequence) {
|
match build_pipeline(¶ms, &latest_frame, &sequence, &dvr_sink) {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
if last_build_error.take().is_some() {
|
if last_build_error.take().is_some() {
|
||||||
log::info!("[USB Vidéo] Pipeline reconstruit avec succès ({source_desc}).");
|
log::info!("[USB Vidéo] Pipeline reconstruit avec succès ({source_desc}).");
|
||||||
|
|||||||
Reference in new issue
Block a user