From b31c6fb33b8f4b18c2bafd0e444e72da8a2f768c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 2 Apr 2021 15:45:22 -0300 Subject: [PATCH] stream: video_stream_udp: Check for stream position to restart stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/stream/video_stream_udp.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/stream/video_stream_udp.rs b/src/stream/video_stream_udp.rs index 8558222f..1aad3fd5 100644 --- a/src/stream/video_stream_udp.rs +++ b/src/stream/video_stream_udp.rs @@ -160,6 +160,7 @@ fn run_video_stream_udp( ); // Check if we need to break external loop + let mut previous_position: Option = None; 'innerLoop: loop { if state.lock().unwrap().kill { break 'externalLoop; @@ -168,6 +169,32 @@ fn run_video_stream_udp( break 'innerLoop; } + // Restart pipeline if pipeline position do not change, + // occur if usb connection is lost and gstreamer do not detect it + match pipeline + .as_ref() + .unwrap() + .query_position::() + { + Some(position) => { + previous_position = match previous_position { + Some(current_previous_position) => { + if current_previous_position.nanoseconds() != Some(0) + && current_previous_position.nanoseconds() == position.nanoseconds() + { + let _ = channel + .send(format!("Position did not change, restarting pipeline")); + break 'innerLoop; + } + + Some(position) + } + None => Some(position), + } + } + None => {} + } + for msg in bus.timed_pop(gstreamer::ClockTime::from_mseconds(100)) { use gstreamer::MessageView;