From 3d94f30145f6d49804627f8d3f653ad0b70b8236 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 18 Jun 2020 13:46:23 -0500 Subject: [PATCH] Notify Gstreamer of end-of-stream on hangup from camera This may help resolve #13 on GitHub. --- src/gst.rs | 7 +++++++ src/main.rs | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gst.rs b/src/gst.rs index 68d3b84..1fef235 100644 --- a/src/gst.rs +++ b/src/gst.rs @@ -121,6 +121,13 @@ mod maybe_app_src { (MaybeAppSrc { rx, app_src: None }, tx) } + /// Flushes data to Gstreamer on a problem communicating with the underlying video source. + pub fn on_stream_error(&mut self) { + if let Some(src) = self.try_get_src() { + src.end_of_stream().unwrap(); + } + } + /// Attempts to retrieve the AppSrc that should be passed in by the caller of new_with_tx /// at some point after this struct has been created. At that point, we swap over to /// owning the AppSrc directly. This function handles either case and returns the AppSrc, diff --git a/src/main.rs b/src/main.rs index eacb61b..61f15e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use env_logger::Env; use err_derive::Error; use log::*; use neolink::bc_protocol::BcCamera; -use neolink::gst::RtspServer; +use neolink::gst::{MaybeAppSrc, RtspServer}; use neolink::Never; use std::fs; use std::io::Write; @@ -43,7 +43,7 @@ fn main() -> Result<(), Error> { for camera in config.cameras { s.spawn(move |_| { // TODO handle these errors - let mut output = rtsp.add_stream(&camera.name).unwrap(); // TODO + let mut output = rtsp.add_stream(&camera.name).unwrap(); camera_loop(&camera, &mut output) }); } @@ -55,13 +55,14 @@ fn main() -> Result<(), Error> { Ok(()) } -fn camera_loop(camera_config: &CameraConfig, output: &mut dyn Write) -> Result { +fn camera_loop(camera_config: &CameraConfig, output: &mut MaybeAppSrc) -> Result { let min_backoff = Duration::from_secs(1); let max_backoff = Duration::from_secs(15); let mut current_backoff = min_backoff; loop { let cam_err = camera_main(camera_config, output).unwrap_err(); + output.on_stream_error(); // Authentication failures are permanent; we retry everything else if cam_err.connected { current_backoff = min_backoff;