Make gstreamer and pushnotificaitions build time dependencies
This commit is contained in:
13 files changed
+268
-155
No files matched your search
@@ -34,7 +34,11 @@ jobs:
|
||||
rustup toolchain install nightly --component clippy
|
||||
rustup override set nightly
|
||||
- name: Run clippy manually
|
||||
run: cargo +nightly clippy --workspace --all-targets --all-features
|
||||
run: |
|
||||
cargo +nightly clippy --workspace --all-targets --all-features
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=gstreamer
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=pushnoti
|
||||
|
||||
check_fmt:
|
||||
needs: pre_job
|
||||
|
||||
+27
-10
@@ -13,23 +13,23 @@ members = [
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.70"
|
||||
async-stream = "0.3.5"
|
||||
async-stream = {version = "0.3.5", optional = true}
|
||||
base64 = "0.22.0"
|
||||
byte-slice-cast = "1.2.2"
|
||||
byte-slice-cast = {version = "1.2.2", optional = true}
|
||||
bytes = "1.6.0"
|
||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||
crossbeam-channel = "0.5.8"
|
||||
dirs = "5.0.1"
|
||||
crossbeam-channel = {version = "0.5.8", optional = true}
|
||||
dirs = {version = "5.0.1", optional = true}
|
||||
env_logger = "0.11.3"
|
||||
fcm-push-listener = "2.0.3"
|
||||
fcm-push-listener = {version = "2.0.3", optional = true}
|
||||
futures = "0.3.28"
|
||||
gstreamer = "0.23.0"
|
||||
gstreamer-app = { version = "0.23.0", features = ["v1_20"] }
|
||||
gstreamer-rtsp = { version = "0.23.0", features = ["v1_20"] }
|
||||
gstreamer-rtsp-server = { version = "0.23.0", features = ["v1_20"] }
|
||||
gstreamer = {version = "0.23.0", optional = true}
|
||||
gstreamer-app = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
gstreamer-rtsp = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
gstreamer-rtsp-server = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
heck = "0.5.0"
|
||||
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||
md5 = "0.7.0"
|
||||
md5 = {version = "0.7.0", optional = true}
|
||||
neolink_core = { path = "crates/core", version = "0.6.3-rc.2" }
|
||||
once_cell = "1.19.0"
|
||||
quick-xml = { version = "0.36.1", features = ["serialize"] }
|
||||
@@ -46,3 +46,20 @@ validator = {version="0.18.1", features = ["derive"] }
|
||||
|
||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||
tikv-jemallocator = "0.5"
|
||||
|
||||
[features]
|
||||
default = ["gstreamer", "pushnoti"]
|
||||
gstreamer = [
|
||||
"dep:gstreamer",
|
||||
"dep:gstreamer-app",
|
||||
"dep:gstreamer-rtsp",
|
||||
"dep:gstreamer-rtsp-server",
|
||||
"dep:async-stream",
|
||||
"dep:byte-slice-cast",
|
||||
"dep:crossbeam-channel"
|
||||
]
|
||||
pushnoti = [
|
||||
"dep:fcm-push-listener",
|
||||
"dep:dirs",
|
||||
"dep:md5"
|
||||
]
|
||||
@@ -17,14 +17,18 @@ pub struct Opt {
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum Command {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Rtsp(super::rtsp::Opt),
|
||||
StatusLight(super::statusled::Opt),
|
||||
Reboot(super::reboot::Opt),
|
||||
Pir(super::pir::Opt),
|
||||
Ptz(super::ptz::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Talk(super::talk::Opt),
|
||||
Mqtt(super::mqtt::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
MqttRtsp(super::mqtt::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Image(super::image::Opt),
|
||||
Battery(super::battery::Opt),
|
||||
Services(super::services::Opt),
|
||||
|
||||
+17
-4
@@ -7,18 +7,25 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use futures::TryFutureExt;
|
||||
use std::sync::{Arc, Weak};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use tokio::sync::watch::channel as watch;
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::channel as watch,
|
||||
watch::Receiver as WatchReceiver,
|
||||
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::Receiver as WatchReceiver,
|
||||
},
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{MdState, NeoCamCommand, NeoCamThreadState, Permit, PushNoti, StreamInstance};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use super::PushNoti;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use super::StreamInstance;
|
||||
use super::{MdState, NeoCamCommand, NeoCamThreadState, Permit};
|
||||
use crate::{config::CameraConfig, AnyResult, Result};
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind};
|
||||
use neolink_core::bc_protocol::BcCamera;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
|
||||
/// This instance is the primary interface used throughout the app
|
||||
///
|
||||
@@ -225,6 +232,7 @@ impl NeoInstance {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) async fn stream(&self, name: StreamKind) -> Result<StreamInstance> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
self.camera_control
|
||||
@@ -233,6 +241,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn low_stream(&self) -> Result<Option<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -242,6 +251,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn high_stream(&self) -> Result<Option<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -251,6 +261,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn streams(&self) -> Result<Vec<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -260,6 +271,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) async fn uid(&self) -> Result<String> {
|
||||
let (reply_tx, reply_rx) = oneshot();
|
||||
self.camera_control
|
||||
@@ -268,6 +280,7 @@ impl NeoInstance {
|
||||
Ok(reply_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
|
||||
let uid = self.uid().await?;
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
|
||||
@@ -17,8 +17,8 @@ use super::NeoInstance;
|
||||
use crate::{AnyResult, Result};
|
||||
use neolink_core::bc_protocol::MotionStatus;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) enum MdState {
|
||||
#[allow(dead_code)]
|
||||
Start(Instant),
|
||||
Stop(Instant),
|
||||
Unknown,
|
||||
|
||||
@@ -2,8 +2,10 @@ mod camthread;
|
||||
mod instance;
|
||||
mod mdthread;
|
||||
mod neocam;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
mod pushnoti;
|
||||
mod reactor;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod streamthread;
|
||||
mod usecounter;
|
||||
|
||||
@@ -11,7 +13,9 @@ pub(crate) use camthread::*;
|
||||
pub(crate) use instance::*;
|
||||
pub(crate) use mdthread::*;
|
||||
pub(crate) use neocam::*;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) use pushnoti::*;
|
||||
pub(crate) use reactor::*;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) use streamthread::*;
|
||||
pub(crate) use usecounter::*;
|
||||
+88
-61
@@ -20,19 +20,29 @@ use tokio_stream::wrappers::ReceiverStream;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{
|
||||
MdRequest, MdState, NeoCamMdThread, NeoCamStreamThread, NeoCamThread, NeoCamThreadState,
|
||||
NeoInstance, Permit, PnRequest, PushNoti, StreamInstance, StreamRequest, UseCounter,
|
||||
MdRequest, MdState, NeoCamMdThread, NeoCamThread, NeoCamThreadState, NeoInstance, Permit,
|
||||
UseCounter,
|
||||
};
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use super::{NeoCamStreamThread, StreamInstance, StreamRequest};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use super::{PnRequest, PushNoti};
|
||||
use crate::{config::CameraConfig, AnyResult, Result};
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind};
|
||||
use neolink_core::bc_protocol::BcCamera;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) enum NeoCamCommand {
|
||||
HangUp,
|
||||
Instance(OneshotSender<Result<NeoInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Stream(StreamKind, OneshotSender<StreamInstance>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
HighStream(OneshotSender<Option<StreamInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
LowStream(OneshotSender<Option<StreamInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Streams(OneshotSender<Vec<StreamInstance>>),
|
||||
Motion(OneshotSender<WatchReceiver<MdState>>),
|
||||
Config(OneshotSender<WatchReceiver<CameraConfig>>),
|
||||
@@ -40,6 +50,7 @@ pub(crate) enum NeoCamCommand {
|
||||
Connect(OneshotSender<()>),
|
||||
State(OneshotSender<NeoCamThreadState>),
|
||||
GetPermit(OneshotSender<Permit>),
|
||||
#[cfg(feature = "pushnoti")]
|
||||
PushNoti(OneshotSender<WatchReceiver<Option<PushNoti>>>),
|
||||
GetUid(OneshotSender<String>),
|
||||
}
|
||||
@@ -55,11 +66,12 @@ pub(crate) struct NeoCam {
|
||||
impl NeoCam {
|
||||
pub(crate) async fn new(
|
||||
config: CameraConfig,
|
||||
pn_request_tx: MpscSender<PnRequest>,
|
||||
#[cfg(feature = "pushnoti")] pn_request_tx: MpscSender<PnRequest>,
|
||||
) -> Result<NeoCam> {
|
||||
let (commander_tx, commander_rx) = mpsc(100);
|
||||
let (watch_config_tx, watch_config_rx) = watch(config.clone());
|
||||
let (camera_watch_tx, camera_watch_rx) = watch(Weak::new());
|
||||
#[cfg(feature = "gstreamer")]
|
||||
let (stream_request_tx, stream_request_rx) = mpsc(100);
|
||||
let (md_request_tx, md_request_rx) = mpsc(100);
|
||||
let (state_tx, state_rx) = watch(NeoCamThreadState::Connected);
|
||||
@@ -83,10 +95,13 @@ impl NeoCam {
|
||||
// other threads
|
||||
let sender_cancel = me.cancel.clone();
|
||||
let mut commander_rx = ReceiverStream::new(commander_rx);
|
||||
#[cfg(feature = "gstreamer")]
|
||||
let strict = config.strict;
|
||||
let thread_commander_tx = commander_tx.clone();
|
||||
let thread_watch_config_rx = watch_config_rx.clone();
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
|
||||
me.set.spawn(async move {
|
||||
let thread_cancel = sender_cancel.clone();
|
||||
let res = tokio::select! {
|
||||
@@ -108,6 +123,7 @@ impl NeoCam {
|
||||
);
|
||||
let _ = result.send(instance);
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::Stream(name, sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::GetOrInsert {
|
||||
@@ -117,6 +133,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::HighStream(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::High {
|
||||
@@ -124,6 +141,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::LowStream(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::Low {
|
||||
@@ -131,6 +149,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::Streams(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::All {
|
||||
@@ -166,6 +185,7 @@ impl NeoCam {
|
||||
NeoCamCommand::GetPermit(sender) => {
|
||||
let _ = sender.send(users.create_activated().await?);
|
||||
}
|
||||
#[cfg(feature = "pushnoti")]
|
||||
NeoCamCommand::PushNoti(sender) => {
|
||||
thread_pn_request_tx.send(
|
||||
PnRequest::Get {
|
||||
@@ -212,17 +232,21 @@ impl NeoCam {
|
||||
me.set.spawn(async move { cam_thread.run().await });
|
||||
|
||||
// This thread maintains the streams
|
||||
let stream_instance = instance.subscribe().await?;
|
||||
let stream_cancel = me.cancel.clone();
|
||||
let mut stream_thread = NeoCamStreamThread::new(stream_request_rx, stream_instance).await?;
|
||||
me.set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = stream_thread.run() => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
#[cfg(feature = "gstreamer")]
|
||||
{
|
||||
let stream_instance = instance.subscribe().await?;
|
||||
let stream_cancel = me.cancel.clone();
|
||||
let mut stream_thread =
|
||||
NeoCamStreamThread::new(stream_request_rx, stream_instance).await?;
|
||||
me.set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = stream_thread.run() => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This thread monitors the motion
|
||||
let md_instance = instance.subscribe().await?;
|
||||
@@ -292,54 +316,57 @@ impl NeoCam {
|
||||
});
|
||||
|
||||
// Handles push notifications
|
||||
let pn_root_instance = instance.subscribe().await?;
|
||||
let pn_cancel = me.cancel.clone();
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
me.set.spawn(async move {
|
||||
tokio::select!{
|
||||
_ = pn_cancel.cancelled() => {
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
v = async {
|
||||
let mut config_rx = pn_root_instance.config().await?;
|
||||
loop {
|
||||
// Wait for the green light
|
||||
config_rx.wait_for(|config| config.push_notifications).await?;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let pn_root_instance = instance.subscribe().await?;
|
||||
let pn_cancel = me.cancel.clone();
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
me.set.spawn(async move {
|
||||
tokio::select!{
|
||||
_ = pn_cancel.cancelled() => {
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
v = async {
|
||||
let mut config_rx = pn_root_instance.config().await?;
|
||||
loop {
|
||||
// Wait for the green light
|
||||
config_rx.wait_for(|config| config.push_notifications).await?;
|
||||
|
||||
// Activate it
|
||||
let pn_instance = pn_root_instance.subscribe().await?;
|
||||
let (tx, rx) = oneshot();
|
||||
thread_pn_request_tx.send(PnRequest::Activate{sender: tx, instance: pn_instance}).await?;
|
||||
rx.await??;
|
||||
// Activate it
|
||||
let pn_instance = pn_root_instance.subscribe().await?;
|
||||
let (tx, rx) = oneshot();
|
||||
thread_pn_request_tx.send(PnRequest::Activate{sender: tx, instance: pn_instance}).await?;
|
||||
rx.await??;
|
||||
|
||||
let pn_permit_instance = pn_root_instance.subscribe().await?;
|
||||
let r = tokio::select! {
|
||||
// Push notification permits
|
||||
v = async {
|
||||
let mut prev_noti = None;
|
||||
let mut pn = pn_permit_instance.push_notifications().await?;
|
||||
loop{
|
||||
prev_noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.map(|noti| noti.clone())?;
|
||||
let _permit = pn_permit_instance.permit().await?;
|
||||
sleep(Duration::from_secs(30)).await; // Push notification will wake us up for 30s
|
||||
}
|
||||
} => v,
|
||||
// Continue loop on Red light
|
||||
v = config_rx.wait_for(|config| !config.push_notifications).map_ok(|_| ()) => {
|
||||
v?;
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
};
|
||||
if r.is_err() {
|
||||
break r;
|
||||
}
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
let pn_permit_instance = pn_root_instance.subscribe().await?;
|
||||
let r = tokio::select! {
|
||||
// Push notification permits
|
||||
v = async {
|
||||
let mut prev_noti = None;
|
||||
let mut pn = pn_permit_instance.push_notifications().await?;
|
||||
loop{
|
||||
prev_noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.map(|noti| noti.clone())?;
|
||||
let _permit = pn_permit_instance.permit().await?;
|
||||
sleep(Duration::from_secs(30)).await; // Push notification will wake us up for 30s
|
||||
}
|
||||
} => v,
|
||||
// Continue loop on Red light
|
||||
v = config_rx.wait_for(|config| !config.push_notifications).map_ok(|_| ()) => {
|
||||
v?;
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
};
|
||||
if r.is_err() {
|
||||
break r;
|
||||
}
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// MD permits
|
||||
let md_permit_instance = instance.subscribe().await?;
|
||||
|
||||
+36
-25
@@ -5,6 +5,8 @@ use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
sync::Arc,
|
||||
};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use tokio::time::{sleep, Duration};
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc::{channel as mpsc, Sender as MpscSender},
|
||||
@@ -12,12 +14,13 @@ use tokio::{
|
||||
watch::{channel as watch, Receiver as WatchReceiver},
|
||||
},
|
||||
task::JoinSet,
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{NeoCam, NeoInstance};
|
||||
use crate::{common::PushNotiThread, config::Config, AnyResult, Result};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use crate::common::PushNotiThread;
|
||||
use crate::{config::Config, AnyResult, Result};
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum NeoReactorCommand {
|
||||
@@ -38,7 +41,9 @@ pub(crate) struct NeoReactor {
|
||||
impl NeoReactor {
|
||||
pub(crate) async fn new(config: Config) -> Self {
|
||||
let (commad_tx, mut command_rx) = mpsc(100);
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let (push_noti, mut pn_rx) = mpsc(10);
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let pn_tx = push_noti.clone();
|
||||
let cancel = CancellationToken::new();
|
||||
let (config_tx, _) = watch(config);
|
||||
@@ -73,7 +78,10 @@ impl NeoReactor {
|
||||
Entry::Vacant(vac) => {
|
||||
let current_config: Config = (*thread_config_tx.borrow()).clone();
|
||||
if let Some(config) = current_config.cameras.iter().find(|cam| cam.name == name).cloned() {
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let cam = NeoCam::new(config, push_noti.clone()).await?;
|
||||
#[cfg(not(feature = "pushnoti"))]
|
||||
let cam = NeoCam::new(config).await?;
|
||||
Result::Ok(Some(
|
||||
vac.insert(
|
||||
cam,
|
||||
@@ -113,31 +121,34 @@ impl NeoReactor {
|
||||
});
|
||||
|
||||
// Push notification client
|
||||
let cancel1 = cancel.clone();
|
||||
let mut thread_config_rx = config_tx.subscribe();
|
||||
set.spawn(async move {
|
||||
let r = tokio::select! {
|
||||
_ = cancel1.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let cancel1 = cancel.clone();
|
||||
let mut thread_config_rx = config_tx.subscribe();
|
||||
set.spawn(async move {
|
||||
let r = tokio::select! {
|
||||
_ = cancel1.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
|
||||
let mut pn = PushNotiThread::new().await?;
|
||||
loop {
|
||||
thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled
|
||||
let r = tokio::select!{
|
||||
v = pn.run(&pn_tx, &mut pn_rx) => {v},
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Issue with push notifier: {r:?}");
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
} else {
|
||||
log::debug!("Push notifier reported normal shutdown. Restarting");
|
||||
let mut pn = PushNotiThread::new().await?;
|
||||
loop {
|
||||
thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled
|
||||
let r = tokio::select!{
|
||||
v = pn.run(&pn_tx, &mut pn_rx) => {v},
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Issue with push notifier: {r:?}");
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
} else {
|
||||
log::debug!("Push notifier reported normal shutdown. Restarting");
|
||||
}
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
};
|
||||
r
|
||||
});
|
||||
} => v,
|
||||
};
|
||||
r
|
||||
});
|
||||
}
|
||||
|
||||
Self {
|
||||
cancel,
|
||||
|
||||
@@ -63,6 +63,7 @@ impl UseCounter {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) async fn create_deactivated(&self) -> Result<Permit> {
|
||||
Ok(Permit::new(self))
|
||||
}
|
||||
@@ -87,6 +88,7 @@ pub(crate) struct Permit {
|
||||
}
|
||||
|
||||
impl Permit {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn subscribe(&self) -> Self {
|
||||
Self {
|
||||
is_active: false,
|
||||
@@ -141,6 +143,7 @@ impl Permit {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn get_counter(&self) -> WatchReceiver<u32> {
|
||||
self.value.clone()
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,5 +1,7 @@
|
||||
use crate::mqtt::Discoveries;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat, StreamKind};
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -99,6 +101,7 @@ pub(crate) enum StreamConfig {
|
||||
}
|
||||
|
||||
impl StreamConfig {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn as_stream_kinds(&self) -> Vec<StreamKind> {
|
||||
match self {
|
||||
StreamConfig::All => {
|
||||
|
||||
+17
@@ -40,14 +40,17 @@ mod battery;
|
||||
mod cmdline;
|
||||
mod common;
|
||||
mod config;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod image;
|
||||
mod mqtt;
|
||||
mod pir;
|
||||
mod ptz;
|
||||
mod reboot;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod rtsp;
|
||||
mod services;
|
||||
mod statusled;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod talk;
|
||||
mod utils;
|
||||
|
||||
@@ -83,6 +86,7 @@ async fn main() -> Result<()> {
|
||||
let neo_reactor = NeoReactor::new(config.clone()).await;
|
||||
|
||||
match opt.cmd {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
None => {
|
||||
warn!(
|
||||
"Deprecated command line option. Please use: `neolink rtsp --config={:?}`",
|
||||
@@ -90,6 +94,16 @@ async fn main() -> Result<()> {
|
||||
);
|
||||
rtsp::main(rtsp::Opt {}, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(not(feature = "gstreamer"))]
|
||||
None => {
|
||||
// When gstreamer is disabled the default command is MQTT
|
||||
warn!(
|
||||
"Deprecated command line option. Please use: `neolink mqtt --config={:?}`",
|
||||
conf_path
|
||||
);
|
||||
mqtt::main(mqtt::Opt {}, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Rtsp(opts)) => {
|
||||
rtsp::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
@@ -105,18 +119,21 @@ async fn main() -> Result<()> {
|
||||
Some(Command::Ptz(opts)) => {
|
||||
ptz::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Talk(opts)) => {
|
||||
talk::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
Some(Command::Mqtt(opts)) => {
|
||||
mqtt::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::MqttRtsp(opts)) => {
|
||||
tokio::select! {
|
||||
v = mqtt::main(opts, neo_reactor.clone()) => v,
|
||||
v = rtsp::main(rtsp::Opt {}, neo_reactor.clone()) => v,
|
||||
}?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Image(opts)) => {
|
||||
image::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
|
||||
+27
-20
@@ -298,7 +298,9 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
let camera_motion = camera.clone();
|
||||
let mqtt_motion = mqtt_instance.resubscribe().await?;
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let camera_pn = camera.clone();
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let mqtt_pn = mqtt_instance.resubscribe().await?;
|
||||
|
||||
let camera_snap = camera.clone();
|
||||
@@ -530,27 +532,32 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}, if config.enable_battery => v,
|
||||
// Handle the push notification messages
|
||||
v = async {
|
||||
let mut pn = camera_pn.push_notifications().await?;
|
||||
let mut prev_noti = None;
|
||||
loop {
|
||||
let v = async {
|
||||
let noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.with_context(|| {
|
||||
format!("{}: PushNoti Watch Dropped", camera_name)
|
||||
})?.clone();
|
||||
mqtt_pn.send_message("status/notification", ¬i.as_ref().unwrap().message, true).await.with_context(|| {
|
||||
format!("{}: Failed to publish push notification", camera_name)
|
||||
})?;
|
||||
prev_noti = noti;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
Err(Ok(e)) => Err(e.into()),
|
||||
Err(Err(e)) => Err (e),
|
||||
}?;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let mut pn = camera_pn.push_notifications().await?;
|
||||
let mut prev_noti = None;
|
||||
loop {
|
||||
let v = async {
|
||||
let noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.with_context(|| {
|
||||
format!("{}: PushNoti Watch Dropped", camera_name)
|
||||
})?.clone();
|
||||
mqtt_pn.send_message("status/notification", ¬i.as_ref().unwrap().message, true).await.with_context(|| {
|
||||
format!("{}: Failed to publish push notification", camera_name)
|
||||
})?;
|
||||
prev_noti = noti;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
Err(Ok(e)) => Err(e.into()),
|
||||
Err(Err(e)) => Err (e),
|
||||
}?;
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
#[cfg(not(feature = "pushnoti"))]
|
||||
unreachable!()
|
||||
}, if cfg!(feature = "pushnoti") => v,
|
||||
// Handle the floodlight task activation
|
||||
v = async {
|
||||
let flt_status = camera_floodlight_tasks.run_passive_task(|cam| Box::pin(async move {
|
||||
|
||||
+35
-32
@@ -143,40 +143,43 @@ pub(super) async fn stream_main(
|
||||
});
|
||||
|
||||
// Push notfications
|
||||
let mut pn = camera.push_notifications().await?;
|
||||
let mut curr_pn = None;
|
||||
let thread_name = name.clone();
|
||||
let thread_pause_affector_tx = pause_affector_tx.clone();
|
||||
let cancel = this_loop_cancel.clone();
|
||||
set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
loop {
|
||||
curr_pn = pn
|
||||
.wait_for(|pn| pn != &curr_pn && pn.is_some())
|
||||
.await?
|
||||
.clone();
|
||||
log::info!("{}: Enabling Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = true;
|
||||
});
|
||||
tokio::select! {
|
||||
v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => {
|
||||
v?;
|
||||
// If another PN during wait then go back to wait more
|
||||
continue;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let mut pn = camera.push_notifications().await?;
|
||||
let mut curr_pn = None;
|
||||
let thread_name = name.clone();
|
||||
let thread_pause_affector_tx = pause_affector_tx.clone();
|
||||
let cancel = this_loop_cancel.clone();
|
||||
set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
loop {
|
||||
curr_pn = pn
|
||||
.wait_for(|pn| pn != &curr_pn && pn.is_some())
|
||||
.await?
|
||||
.clone();
|
||||
log::info!("{}: Enabling Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = true;
|
||||
});
|
||||
tokio::select! {
|
||||
v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => {
|
||||
v?;
|
||||
// If another PN during wait then go back to wait more
|
||||
continue;
|
||||
}
|
||||
_ = sleep(Duration::from_secs(30)) => {}
|
||||
}
|
||||
_ = sleep(Duration::from_secs(30)) => {}
|
||||
log::info!("{}: Pausing Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = false;
|
||||
});
|
||||
}
|
||||
log::info!("{}: Pausing Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = false;
|
||||
});
|
||||
}
|
||||
} => v,
|
||||
}
|
||||
});
|
||||
} => v,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if curr_pause.on_motion || curr_pause.on_disconnect {
|
||||
|
||||
Reference in new issue
Block a user