diff --git a/crates/core/src/bcudp/ser.rs b/crates/core/src/bcudp/ser.rs index b566d8a..e055e2e 100644 --- a/crates/core/src/bcudp/ser.rs +++ b/crates/core/src/bcudp/ser.rs @@ -52,7 +52,7 @@ fn bcudp_ack<'a, W: 'a + Write>( le_u32(0), le_u32(payload.group_id), le_u32(payload.packet_id), - le_u32(0), + le_u32(0xd7160000), le_u32(binary_payload.len() as u32), slice(binary_payload), )) diff --git a/src/image/mod.rs b/src/image/mod.rs index 50cf29e..d90fac0 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -42,7 +42,7 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> { .await .context("Failed to connect to the camera, check credentials and network")?; - if (opt.use_stream) { + if opt.use_stream { let mut stream_data = camera .start_video(StreamKind::Main, 0, camera_config.strict) .await diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 197db83..072bd04 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -1,5 +1,5 @@ use crate::config::CameraConfig; -use crate::utils::AddressOrUid; +use crate::utils::{timeout, AddressOrUid}; use anyhow::{anyhow, Context, Result}; use futures::stream::StreamExt; use log::*; @@ -193,10 +193,9 @@ impl EventCamThread { "aes" => MaxEncryption::Aes, _ => MaxEncryption::Aes, }; - camera - .login_with_maxenc(max_encryption) + timeout(camera.login_with_maxenc(max_encryption)) .await - .context("Failed to login to the camera")?; + .context("Failed to login to the camera")??; info!("{}: Connected and logged in", camera_config.name); self.tx.send(Messages::Login).await?; diff --git a/src/rtsp/gst/factory.rs b/src/rtsp/gst/factory.rs index 6c4426a..21e6052 100644 --- a/src/rtsp/gst/factory.rs +++ b/src/rtsp/gst/factory.rs @@ -51,7 +51,6 @@ impl NeoMediaFactory { factory.set_shared(false); factory.imp().shared.set_buffer_size(buffer_size); factory.imp().shared.set_use_smoothing(use_smoothing); - // factory.set_do_retransmission(false); // Can't use as the method is missing on the 32bit docker gst dll factory.set_launch("videotestsrc pattern=\"snow\" ! video/x-raw,width=896,height=512,framerate=25/1 ! textoverlay name=\"inittextoverlay\" text=\"Stream not Ready\" valignment=top halignment=left font-desc=\"Sans, 32\" ! jpegenc ! rtpjpegpay name=pay0"); factory.set_suspend_mode(RTSPSuspendMode::None); factory.set_transport_mode(RTSPTransportMode::PLAY); @@ -266,9 +265,11 @@ impl NeoMediaFactoryImpl { .dynamic_cast::() .map_err(|_| anyhow!("Media source's element should be a bin"))?; // Clear the autogenerated ones + log::debug!("Clearing old elements"); for element in bin.iterate_elements().into_iter().flatten() { bin.remove(&element)?; } + log::debug!("Cleared"); let mut client_data = NeoMediaSender::new( self.shared.get_buffer_size(), diff --git a/src/rtsp/gst/sender.rs b/src/rtsp/gst/sender.rs index 58af684..a2d5838 100644 --- a/src/rtsp/gst/sender.rs +++ b/src/rtsp/gst/sender.rs @@ -444,8 +444,8 @@ pub(super) struct NeoMediaSender { start_time: Spring, live_offset: FrameTime, buffer: NeoBuffer, - vid: Option, - aud: Option, + vid: Option>, + aud: Option>, command_reciever: Receiver, command_sender: Sender, inited: bool, @@ -476,11 +476,11 @@ impl NeoMediaSender { } pub(super) fn update_vid(&mut self, source: AppSrc) { - self.vid.replace(source); + self.vid.replace(Arc::new(source)); } pub(super) fn update_aud(&mut self, source: AppSrc) { - self.aud.replace(source); + self.aud.replace(Arc::new(source)); } pub(super) fn get_commader(&self) -> Sender { diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 43f7af0..3e46350 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -174,10 +174,14 @@ async fn camera_main(camera: Camera) -> Result<(), CameraFailureKi .await .with_context(|| format!("{}: Could not login to camera", name)) .map_err(|e| { - let e_inner = e.downcast_ref::().unwrap(); + let e_inner = e.downcast_ref::(); match e_inner { - neolink_core::Error::CameraLoginFail => CameraFailureKind::Fatal(e), - _ => CameraFailureKind::Retry(e), + Some(neolink_core::Error::CameraLoginFail) => CameraFailureKind::Fatal(e), + Some(_) => CameraFailureKind::Retry(e), + None => { + // Timout error usually + CameraFailureKind::Retry(e) + } } })?; diff --git a/src/rtsp/states/connected.rs b/src/rtsp/states/connected.rs index e7e0336..e20493c 100644 --- a/src/rtsp/states/connected.rs +++ b/src/rtsp/states/connected.rs @@ -3,6 +3,7 @@ // This state has formed the TCP/UDP tunnel // but has not logged in use super::{camera::Camera, disconnected::Disconnected, loggedin::LoggedIn}; +use crate::utils::timeout; use anyhow::Result; use neolink_core::bc_protocol::{BcCamera, MaxEncryption}; @@ -28,7 +29,7 @@ impl Camera { _ => MaxEncryption::Aes, }; - self.state.camera.login_with_maxenc(max_encryption).await?; + timeout(self.state.camera.login_with_maxenc(max_encryption)).await??; Ok(Camera { shared: self.shared, state: LoggedIn { diff --git a/src/utils.rs b/src/utils.rs index 7ff6c05..91a15f2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,6 +13,13 @@ use std::{ str::FromStr, }; +pub(crate) fn timeout(future: F) -> tokio::time::Timeout +where + F: std::future::Future, +{ + tokio::time::timeout(tokio::time::Duration::from_secs(5), future) +} + pub(crate) enum AddressOrUid { Address(String), Uid(String, DiscoveryMethods), @@ -133,10 +140,9 @@ pub(crate) async fn connect_and_login(camera_config: &CameraConfig) -> Result MaxEncryption::Aes, }; info!("{}: Logging in", camera_config.name); - camera - .login_with_maxenc(max_encryption) + timeout(camera.login_with_maxenc(max_encryption)) .await - .with_context(|| format!("Failed to login to {}", camera_config.name))?; + .with_context(|| format!("Failed to login to {}", camera_config.name))??; info!("{}: Connected and logged in", camera_config.name);