Deps and logs
Use quick_xml instead of yaserde Use thiserror instead of err_derive Update deps to latest (except fcm), fcm will need to wait for reolink to update their fcm apis first in their app
This commit is contained in:
35 files changed
+1419
-1735
No files matched your search
+5
-4
@@ -35,10 +35,11 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
|
||||
let ser = String::from_utf8(
|
||||
yaserde::ser::serialize_with_writer(&state, vec![], &Default::default())
|
||||
.expect("Should Ser the struct"),
|
||||
)
|
||||
let ser = String::from_utf8({
|
||||
let mut buf = bytes::BytesMut::new();
|
||||
quick_xml::se::to_writer(&mut buf, &state).expect("Should Ser the struct");
|
||||
buf.to_vec()
|
||||
})
|
||||
.expect("Should be UTF8");
|
||||
println!("{}", ser);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::{AnyResult, Result};
|
||||
use neolink_core::bc_protocol::MotionStatus;
|
||||
|
||||
pub(crate) enum MdState {
|
||||
#[allow(dead_code)]
|
||||
Start(Instant),
|
||||
Stop(Instant),
|
||||
Unknown,
|
||||
|
||||
@@ -67,6 +67,11 @@ impl PushNotiThread {
|
||||
let sender_id = "743639030586"; // andriod
|
||||
// let sender_id = "696841269229"; // ios
|
||||
|
||||
// let firebase_app_id = "1:743639030586:android:86f60a4fb7143876";
|
||||
// let firebase_project_id = "reolink-login";
|
||||
// let firebase_api_key = "AIzaSyBEUIuWHnnOEwFahxWgQB4Yt4NsgOmkPyE";
|
||||
// let vapid_key = "????";
|
||||
|
||||
let token_path = dirs::config_dir().map(|mut d| {
|
||||
d.push("./neolink_token.toml");
|
||||
d
|
||||
|
||||
+12
-12
@@ -1,19 +1,19 @@
|
||||
use crate::mqtt::Discoveries;
|
||||
use lazy_static::lazy_static;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat, StreamKind};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::clone::Clone;
|
||||
use std::collections::HashSet;
|
||||
use validator::{Validate, ValidationError};
|
||||
use validator::ValidationError;
|
||||
use validator_derive::Validate;
|
||||
|
||||
lazy_static! {
|
||||
static ref RE_TLS_CLIENT_AUTH: Regex = Regex::new(r"^(none|request|require)$").unwrap();
|
||||
static ref RE_PAUSE_MODE: Regex = Regex::new(r"^(black|still|test|none)$").unwrap();
|
||||
static ref RE_MAXENC_SRC: Regex =
|
||||
Regex::new(r"^([nN]one|[Aa][Ee][Ss]|[Bb][Cc][Ee][Nn][Cc][Rr][Yy][Pp][Tt])$").unwrap();
|
||||
}
|
||||
static RE_TLS_CLIENT_AUTH: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^(none|request|require)$").unwrap());
|
||||
static RE_PAUSE_MODE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(black|still|test|none)$").unwrap());
|
||||
static RE_MAXENC_SRC: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"^([nN]one|[Aa][Ee][Ss]|[Bb][Cc][Ee][Nn][Cc][Rr][Yy][Pp][Tt])$").unwrap()
|
||||
});
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq)]
|
||||
pub(crate) struct Config {
|
||||
@@ -37,7 +37,7 @@ pub(crate) struct Config {
|
||||
pub(crate) mqtt: Option<MqttServerConfig>,
|
||||
|
||||
#[validate(regex(
|
||||
path = "RE_TLS_CLIENT_AUTH",
|
||||
path = *RE_TLS_CLIENT_AUTH,
|
||||
message = "Incorrect tls auth",
|
||||
code = "tls_client_auth"
|
||||
))]
|
||||
@@ -159,7 +159,7 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[serde(default = "default_maxenc")]
|
||||
#[validate(regex(
|
||||
path = "RE_MAXENC_SRC",
|
||||
path = *RE_MAXENC_SRC,
|
||||
message = "Invalid maximum encryption method",
|
||||
code = "max_encryption"
|
||||
))]
|
||||
@@ -212,7 +212,7 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct UserConfig {
|
||||
#[validate(custom = "validate_username")]
|
||||
#[validate(custom(function = "validate_username"))]
|
||||
#[serde(alias = "username")]
|
||||
pub(crate) name: String,
|
||||
|
||||
@@ -329,7 +329,7 @@ pub(crate) struct PauseConfig {
|
||||
|
||||
#[serde(default = "default_pause_mode")]
|
||||
#[validate(regex(
|
||||
path = "RE_PAUSE_MODE",
|
||||
path = *RE_PAUSE_MODE,
|
||||
message = "Incorrect pause mode",
|
||||
code = "mode"
|
||||
))]
|
||||
|
||||
+11
-11
@@ -1,16 +1,16 @@
|
||||
use err_derive::Error;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum Error {
|
||||
#[error(display = "RTSP Error")]
|
||||
Rtsp(#[error(source)] super::rtsp::Error),
|
||||
#[error(display = "Status LED Error")]
|
||||
StatusLight(#[error(source)] super::statusled::Error),
|
||||
#[error(display = "Reboot Error")]
|
||||
Reboot(#[error(source)] super::reboot::Error),
|
||||
#[error(display = "Talk Error")]
|
||||
Talk(#[error(source)] super::talk::Error),
|
||||
#[error(display = "Talk Error")]
|
||||
Mqtt(#[error(source)] super::mqtt::Error),
|
||||
#[error("RTSP Error")]
|
||||
Rtsp(#[from] super::rtsp::Error),
|
||||
#[error("Status LED Error")]
|
||||
StatusLight(#[from] super::statusled::Error),
|
||||
#[error("Reboot Error")]
|
||||
Reboot(#[from] super::reboot::Error),
|
||||
#[error("Talk Error")]
|
||||
Talk(#[from] super::talk::Error),
|
||||
#[error("Talk Error")]
|
||||
Mqtt(#[from] super::mqtt::Error),
|
||||
}
|
||||
+4
-2
@@ -1,7 +1,9 @@
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use gstreamer::{parse_launch, prelude::*, ClockTime, MessageView, Pipeline, State};
|
||||
use gstreamer::{
|
||||
parse::launch_full, prelude::*, ClockTime, MessageView, ParseFlags, Pipeline, State,
|
||||
};
|
||||
use gstreamer_app::AppSrc;
|
||||
use tokio::{
|
||||
sync::{
|
||||
@@ -203,7 +205,7 @@ fn create_pipeline(format: VidFormat, file_path: &Path) -> Result<Pipeline> {
|
||||
// Parse the pipeline we want to probe from a static in-line string.
|
||||
// Here we give our audiotestsrc a name, so we can retrieve that element
|
||||
// from the resulting pipeline.
|
||||
let pipeline = parse_launch(&launch_str)
|
||||
let pipeline = launch_full(&launch_str, None, ParseFlags::empty())
|
||||
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
||||
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
||||
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
||||
|
||||
-16
@@ -53,21 +53,9 @@ mod utils;
|
||||
use cmdline::{Command, Opt};
|
||||
use common::NeoReactor;
|
||||
use config::Config;
|
||||
use console_subscriber as _;
|
||||
|
||||
pub(crate) type AnyResult<T> = Result<T, anyhow::Error>;
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
fn tokio_console_enable() {
|
||||
info!("Tokio Console Enabled");
|
||||
console_subscriber::init();
|
||||
}
|
||||
|
||||
#[cfg(not(tokio_unstable))]
|
||||
fn tokio_console_enable() {
|
||||
debug!("Tokio Console Disabled");
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
@@ -91,10 +79,6 @@ async fn main() -> Result<()> {
|
||||
.validate()
|
||||
.with_context(|| format!("Failed to validate the {:?} config file", conf_path))?;
|
||||
|
||||
if config.tokio_console {
|
||||
tokio_console_enable();
|
||||
}
|
||||
|
||||
let neo_reactor = NeoReactor::new(config.clone()).await;
|
||||
|
||||
match opt.cmd {
|
||||
|
||||
+15
-9
@@ -1156,9 +1156,11 @@ async fn handle_mqtt_message(
|
||||
"FAIL"
|
||||
}
|
||||
Ok(xml) => {
|
||||
let bytes_res =
|
||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
||||
match bytes_res {
|
||||
let ser_xml = {
|
||||
let mut buf = bytes::BytesMut::new();
|
||||
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||
};
|
||||
match ser_xml {
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(str) => {
|
||||
mqtt.send_message("status/battery", &str, false)
|
||||
@@ -1200,9 +1202,11 @@ async fn handle_mqtt_message(
|
||||
"FAIL"
|
||||
}
|
||||
Ok(xml) => {
|
||||
let bytes_res =
|
||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
||||
match bytes_res {
|
||||
let ser_xml = {
|
||||
let mut buf = bytes::BytesMut::new();
|
||||
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||
};
|
||||
match ser_xml {
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(str) => {
|
||||
mqtt.send_message("status/pir", &str, false)
|
||||
@@ -1245,9 +1249,11 @@ async fn handle_mqtt_message(
|
||||
"FAIL"
|
||||
}
|
||||
Ok(xml) => {
|
||||
let bytes_res =
|
||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
||||
match bytes_res {
|
||||
let ser_xml = {
|
||||
let mut buf = bytes::BytesMut::new();
|
||||
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||
};
|
||||
match ser_xml {
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(str) => {
|
||||
mqtt.send_message("status/ptz", &str, false)
|
||||
|
||||
+4
-4
@@ -6,8 +6,8 @@ use anyhow::{anyhow, Context, Result};
|
||||
use futures::future::FutureExt;
|
||||
use log::*;
|
||||
use rumqttc::{
|
||||
AsyncClient, ConnectReturnCode, Event, Incoming, Key, LastWill, MqttOptions, QoS,
|
||||
TlsConfiguration, Transport,
|
||||
AsyncClient, ConnectReturnCode, Event, Incoming, LastWill, MqttOptions, QoS, TlsConfiguration,
|
||||
Transport,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use tokio::task::JoinSet;
|
||||
@@ -140,7 +140,7 @@ impl<'a> MqttBackend<'a> {
|
||||
if let (Ok(cert_buf), Ok(key_buf)) =
|
||||
(std::fs::read(cert_path), std::fs::read(key_path))
|
||||
{
|
||||
Some((cert_buf, Key::RSA(key_buf)))
|
||||
Some((cert_buf, key_buf))
|
||||
} else {
|
||||
error!("Failed to set client tls");
|
||||
None
|
||||
@@ -534,7 +534,7 @@ impl LastWillMqtt {
|
||||
if let (Ok(cert_buf), Ok(key_buf)) =
|
||||
(std::fs::read(cert_path), std::fs::read(key_path))
|
||||
{
|
||||
Some((cert_buf, Key::RSA(key_buf)))
|
||||
Some((cert_buf, key_buf))
|
||||
} else {
|
||||
error!("Failed to set client tls");
|
||||
None
|
||||
|
||||
+5
-2
@@ -47,8 +47,11 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
let pir_ser = String::from_utf8(
|
||||
yaserde::ser::serialize_with_writer(&pir_state, vec![], &Default::default())
|
||||
.expect("Should Ser the struct"),
|
||||
{
|
||||
let mut buf = bytes::BytesMut::new();
|
||||
quick_xml::se::to_writer(&mut buf, &pir_state).map(|_| buf.to_vec())
|
||||
}
|
||||
.expect("Should Ser the struct"),
|
||||
)
|
||||
.expect("Should be UTF8");
|
||||
println!("{}", pir_ser);
|
||||
|
||||
+20
-8
@@ -1,7 +1,6 @@
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use gstreamer::{prelude::*, Bin, Caps, Element, ElementFactory, GhostPad};
|
||||
use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType};
|
||||
use log::*;
|
||||
use tokio::sync::mpsc::{channel as mpsc, Receiver as MpscReceiver};
|
||||
|
||||
use crate::{
|
||||
@@ -342,7 +341,6 @@ fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) ->
|
||||
Element::link_many([&source, &queue, &decoder])?;
|
||||
Element::link_many([&encoder, &payload])?;
|
||||
decoder.connect_pad_added(move |_element, pad| {
|
||||
debug!("Linking encoder to decoder: {:?}", pad.caps());
|
||||
let sink_pad = encoder
|
||||
.static_pad("sink")
|
||||
.expect("Encoder is missing its pad");
|
||||
@@ -388,7 +386,8 @@ fn make_element(kind: &str, name: &str) -> AnyResult<Element> {
|
||||
})
|
||||
}
|
||||
|
||||
fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||
#[allow(dead_code)]
|
||||
fn make_dbl_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||
let queue = make_element("queue", &format!("queue1_{}", name))?;
|
||||
queue.set_property("max-size-bytes", buffer_size);
|
||||
queue.set_property("max-size-buffers", 0u32);
|
||||
@@ -403,11 +402,11 @@ fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||
queue2.set_property("max-size-bytes", buffer_size * 2u32 / 3u32);
|
||||
queue.set_property("max-size-buffers", 0u32);
|
||||
queue.set_property("max-size-time", 0u64);
|
||||
// queue2.set_property(
|
||||
// "max-size-time",
|
||||
// std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||
// .unwrap_or(0),
|
||||
// );
|
||||
queue2.set_property(
|
||||
"max-size-time",
|
||||
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||
.unwrap_or(0),
|
||||
);
|
||||
queue2.set_property("use-buffering", false);
|
||||
|
||||
let bin = gstreamer::Bin::builder().name(name).build();
|
||||
@@ -434,6 +433,19 @@ fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||
Ok(bin)
|
||||
}
|
||||
|
||||
fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||
let queue = make_element("queue", &format!("queue1_{}", name))?;
|
||||
queue.set_property("max-size-bytes", buffer_size);
|
||||
queue.set_property("max-size-buffers", 0u32);
|
||||
queue.set_property("max-size-time", 0u64);
|
||||
queue.set_property(
|
||||
"max-size-time",
|
||||
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||
.unwrap_or(0),
|
||||
);
|
||||
Ok(queue)
|
||||
}
|
||||
|
||||
fn buffer_size(bitrate: u32) -> u32 {
|
||||
std::cmp::max(bitrate * 15u32 / 8u32, 4u32 * 1024u32 * 1024u32)
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
use super::AnyResult;
|
||||
use gstreamer::glib::object_subclass;
|
||||
use gstreamer::glib::subclass::types::ObjectSubclass;
|
||||
use gstreamer::Element;
|
||||
use gstreamer::{
|
||||
glib::{self, Object},
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::AnyResult;
|
||||
use crate::config::*;
|
||||
|
||||
use anyhow::Context;
|
||||
use gstreamer::glib::{self, object_subclass, subclass::types::ObjectSubclass, MainLoop, Object};
|
||||
use gstreamer::glib::{self, object_subclass, MainLoop, Object};
|
||||
use gstreamer_rtsp::RTSPAuthMethod;
|
||||
use gstreamer_rtsp_server::{
|
||||
gio::{TlsAuthenticationMode, TlsCertificate},
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@ use crate::AnyResult;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||
use gstreamer::{
|
||||
element_error, parse_launch, prelude::*, Caps, ClockTime, FlowError, FlowSuccess, MessageView,
|
||||
Pipeline, ResourceError, State,
|
||||
element_error, parse::launch_full, prelude::*, Caps, ClockTime, FlowError, FlowSuccess,
|
||||
MessageView, ParseFlags, Pipeline, ResourceError, State,
|
||||
};
|
||||
use gstreamer_app::{AppSink, AppSinkCallbacks};
|
||||
use tokio::task::JoinSet;
|
||||
@@ -159,7 +159,7 @@ fn create_pipeline(
|
||||
// Parse the pipeline we want to probe from a static in-line string.
|
||||
// Here we give our audiotestsrc a name, so we can retrieve that element
|
||||
// from the resulting pipeline.
|
||||
let pipeline = parse_launch(&launch_str)
|
||||
let pipeline = launch_full(&launch_str, None, ParseFlags::empty())
|
||||
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
||||
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
||||
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
||||
|
||||
@@ -22,7 +22,9 @@ where
|
||||
|
||||
pub(crate) enum AddressOrUid {
|
||||
Address(String),
|
||||
#[allow(dead_code)]
|
||||
Uid(String, DiscoveryMethods),
|
||||
#[allow(dead_code)]
|
||||
AddressWithUid(String, String, DiscoveryMethods),
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user