mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(video): prevent image freeze on disconnect and auto-recover video stream on reconnect
This commit is contained in:
1 parent
cf2e603594
commit
0e44febf27
3 files changed
+166
-22
No files matched your search
@@ -23,6 +23,7 @@ pub struct UsbVideoReceiver {
|
||||
pipeline: gst::Pipeline,
|
||||
latest_frame: Arc<Mutex<Option<VideoFrame>>>,
|
||||
stop_flag: Arc<AtomicBool>,
|
||||
has_error: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl UsbVideoReceiver {
|
||||
@@ -159,6 +160,9 @@ impl UsbVideoReceiver {
|
||||
);
|
||||
|
||||
let stop_flag = Arc::new(AtomicBool::new(false));
|
||||
let has_error = Arc::new(AtomicBool::new(false));
|
||||
let error_clone = Arc::clone(&has_error);
|
||||
|
||||
if let Some(bus) = pipeline.bus() {
|
||||
let stop_bus = Arc::clone(&stop_flag);
|
||||
let _ = thread::Builder::new()
|
||||
@@ -179,6 +183,11 @@ impl UsbVideoReceiver {
|
||||
err.error(),
|
||||
err.debug()
|
||||
);
|
||||
error_clone.store(true, Ordering::Release);
|
||||
}
|
||||
MessageView::Eos(..) => {
|
||||
log::warn!("[GStreamer] Fin de flux vidéo (EOS) reçu.");
|
||||
error_clone.store(true, Ordering::Release);
|
||||
}
|
||||
MessageView::Warning(warn) => {
|
||||
log::warn!(
|
||||
@@ -207,6 +216,7 @@ impl UsbVideoReceiver {
|
||||
pipeline,
|
||||
latest_frame,
|
||||
stop_flag,
|
||||
has_error,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -214,6 +224,30 @@ impl UsbVideoReceiver {
|
||||
Arc::clone(&self.latest_frame)
|
||||
}
|
||||
|
||||
pub fn is_broken(&self) -> bool {
|
||||
self.has_error.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_stream_live(&self, timeout: std::time::Duration) -> bool {
|
||||
let lock = self.latest_frame.lock();
|
||||
if let Some(ref vf) = *lock {
|
||||
vf.received_at.elapsed() < timeout
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restart(&mut self) -> Result<()> {
|
||||
log::info!("[USB Vidéo] Réarmement du pipeline GStreamer (State: NULL -> PLAYING)...");
|
||||
let _ = self.pipeline.set_state(gst::State::Null);
|
||||
std::thread::sleep(std::time::Duration::from_millis(60));
|
||||
self.latest_frame.lock().take();
|
||||
self.has_error.store(false, Ordering::Release);
|
||||
self.pipeline.set_state(gst::State::Playing)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render_standby_pattern(width: u32, height: u32, tick: u32, data: &mut [u8]) {
|
||||
let expected_len = (width * height * 4) as usize;
|
||||
if data.len() < expected_len {
|
||||
|
||||
Reference in new issue
Block a user