From cdec5b09586c10fd25fc9f9f2132cf57c829f4ff Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 11 Apr 2023 16:12:36 +0700 Subject: [PATCH] Fmt --- crates/core/src/bc_protocol.rs | 2 +- .../src/bc_protocol/connection/discovery.rs | 4 ++-- src/rtsp/gst/factory.rs | 6 +++-- src/rtsp/gst/server.rs | 7 ++---- src/rtsp/gst/shared.rs | 2 +- src/rtsp/mod.rs | 23 +++++++++++-------- src/rtsp/states/camera.rs | 2 +- src/rtsp/states/connected.rs | 1 + src/rtsp/states/loggedin.rs | 1 + src/rtsp/states/mod.rs | 4 +--- src/rtsp/states/shared.rs | 2 +- src/rtsp/states/streaming.rs | 5 +--- 12 files changed, 30 insertions(+), 29 deletions(-) diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index 41fd5d8..b6c5af0 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -390,7 +390,7 @@ impl BcCamera { }), } } - + /// Wait for all thread to finish /// /// If an error is returned in any thread it will return the first error diff --git a/crates/core/src/bc_protocol/connection/discovery.rs b/crates/core/src/bc_protocol/connection/discovery.rs index 2af796b..ef7e696 100644 --- a/crates/core/src/bc_protocol/connection/discovery.rs +++ b/crates/core/src/bc_protocol/connection/discovery.rs @@ -805,14 +805,14 @@ impl Discoverer { _ => None, }) .await?; - + let result = ConnectResult { addr: final_addr, client_id: register_result.client_id, sid: register_result.sid, camera_id: local_did, }; - + // Confirm relay to register let msg = UdpDiscovery { tid: 0, diff --git a/src/rtsp/gst/factory.rs b/src/rtsp/gst/factory.rs index 28e92b1..3de0ab5 100644 --- a/src/rtsp/gst/factory.rs +++ b/src/rtsp/gst/factory.rs @@ -214,8 +214,10 @@ impl NeoMediaFactoryImpl { bin.remove(&element)?; } - let mut client_data: ClientPipelineData = Default::default(); - client_data.start_time = self.shared.microseconds.load(Ordering::Relaxed); + let mut client_data = ClientPipelineData { + start_time: self.shared.microseconds.load(Ordering::Relaxed), + ..Default::default() + }; // Now contruct the actual ones match *self.shared.vid_format.blocking_read() { diff --git a/src/rtsp/gst/server.rs b/src/rtsp/gst/server.rs index b144d66..35e655d 100644 --- a/src/rtsp/gst/server.rs +++ b/src/rtsp/gst/server.rs @@ -13,17 +13,14 @@ use gstreamer_rtsp_server::{ gio::{TlsAuthenticationMode, TlsCertificate}, prelude::*, subclass::prelude::*, - RTSPAuth, RTSPClient, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE, + RTSPAuth, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE, }; use log::*; use neolink_core::bcmedia::model::*; use std::{ collections::{hash_map::Entry, HashMap, HashSet}, fs, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, - }, + sync::Arc, }; use tokio::{ sync::{mpsc::Sender, RwLock}, diff --git a/src/rtsp/gst/shared.rs b/src/rtsp/gst/shared.rs index c4d5826..f626d98 100644 --- a/src/rtsp/gst/shared.rs +++ b/src/rtsp/gst/shared.rs @@ -2,7 +2,7 @@ //! components that manage a media stream use gstreamer_app::AppSrc; pub use gstreamer_rtsp_server::gio::{TlsAuthenticationMode, TlsCertificate}; -use std::sync::atomic::{AtomicU64, AtomicUsize, AtomicBool}; +use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize}; use tokio::sync::RwLock; #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index f1f36ff..07f8e9d 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -53,11 +53,11 @@ // - `"none"`: Resends the last iframe the camera. This does not reencode at all. **Most use cases should use this one as it has the least effort on the cpu and gives what you would expect** // use anyhow::{anyhow, Context, Result}; -use log::*; -use tokio_stream::StreamExt; use futures::stream::FuturesUnordered; +use log::*; use std::sync::Arc; use std::time::Duration; +use tokio_stream::StreamExt; mod cmdline; mod gst; @@ -171,14 +171,20 @@ async fn camera_main(camera: Camera) -> Result<(), CameraFailureKi .await .with_context(|| format!("{}: Could not start stream", name)) .map_err(CameraFailureKind::Retry)?; - + let tags = streaming.shared.get_tags(); let rtsp_thread = streaming.get_rtsp(); - + let mut waiter = tokio::time::interval(Duration::from_micros(500)); loop { waiter.tick().await; - if tags.iter().map(|tag| rtsp_thread.buffer_ready(tag)).collect::>().all(|f| f.unwrap_or(false)).await { + if tags + .iter() + .map(|tag| rtsp_thread.buffer_ready(tag)) + .collect::>() + .all(|f| f.unwrap_or(false)) + .await + { break; } } @@ -197,8 +203,7 @@ async fn camera_main(camera: Camera) -> Result<(), CameraFailureKi // ); // } // }); - - + loop { // Wait for error or reason to pause tokio::select! { @@ -220,7 +225,7 @@ async fn camera_main(camera: Camera) -> Result<(), CameraFailureKi v = async { // Wait for client to disconnect let mut inter = tokio::time::interval(tokio::time::Duration::from_secs_f32(0.01)); - + info!("Await Client Pause"); loop { inter.tick().await; @@ -255,7 +260,7 @@ async fn camera_main(camera: Camera) -> Result<(), CameraFailureKi v = async { // Wait for client to connect let mut inter = tokio::time::interval(tokio::time::Duration::from_secs_f32(0.01)); - + loop { inter.tick().await; let total_clients = tags.iter().map(|tag| rtsp_thread.get_number_of_clients(tag)).collect::>().fold(0usize, |acc, f| acc + f.unwrap_or(0usize)).await; diff --git a/src/rtsp/states/camera.rs b/src/rtsp/states/camera.rs index f8e8c4e..a5936a1 100644 --- a/src/rtsp/states/camera.rs +++ b/src/rtsp/states/camera.rs @@ -18,7 +18,7 @@ impl Camera { pub(crate) fn get_config(&self) -> &CameraConfig { &self.shared.config } - + pub(crate) fn get_rtsp(&self) -> Arc { self.shared.rtsp.clone() } diff --git a/src/rtsp/states/connected.rs b/src/rtsp/states/connected.rs index 20d4aca..4fb580d 100644 --- a/src/rtsp/states/connected.rs +++ b/src/rtsp/states/connected.rs @@ -12,6 +12,7 @@ pub(crate) struct Connected { } impl Camera { + #[allow(dead_code)] pub(crate) async fn disconnect(self) -> Result> { Ok(Camera { shared: self.shared, diff --git a/src/rtsp/states/loggedin.rs b/src/rtsp/states/loggedin.rs index 9e12ef1..11aa7be 100644 --- a/src/rtsp/states/loggedin.rs +++ b/src/rtsp/states/loggedin.rs @@ -15,6 +15,7 @@ pub(crate) struct LoggedIn { } impl Camera { + #[allow(dead_code)] pub(crate) async fn logout(self) -> Result> { self.state.camera.logout().await?; Ok(Camera { diff --git a/src/rtsp/states/mod.rs b/src/rtsp/states/mod.rs index cb6847e..42610c9 100644 --- a/src/rtsp/states/mod.rs +++ b/src/rtsp/states/mod.rs @@ -8,6 +8,4 @@ mod loggedin; mod shared; mod streaming; -pub(crate) use self::{ - camera::*, disconnected::*, loggedin::*, shared::*, -}; +pub(crate) use self::{camera::*, disconnected::*, loggedin::*, shared::*}; diff --git a/src/rtsp/states/shared.rs b/src/rtsp/states/shared.rs index de07a40..29062a4 100644 --- a/src/rtsp/states/shared.rs +++ b/src/rtsp/states/shared.rs @@ -2,7 +2,7 @@ //! Shared data between all states //! //! -use anyhow::{Context, Error, Result}; +use anyhow::{Context, Result}; use log::*; use std::collections::HashSet; use std::sync::Arc; diff --git a/src/rtsp/states/streaming.rs b/src/rtsp/states/streaming.rs index 74d9fbe..b98e12d 100644 --- a/src/rtsp/states/streaming.rs +++ b/src/rtsp/states/streaming.rs @@ -7,10 +7,7 @@ use log::*; use tokio::time::{timeout, Duration}; use tokio::{sync::RwLock, task::JoinSet}; -use neolink_core::{ - bc_protocol::{BcCamera, StreamKind as Stream}, - bcmedia::model::BcMedia, -}; +use neolink_core::bc_protocol::{BcCamera, StreamKind as Stream}; use super::{camera::Camera, LoggedIn};