Compare commits

...
Author SHA1 Message Date
QuantumEntangledAndy 384a0271bd v0.5.12 2023-05-19 22:58:45 +07:00
Andrew King 134ef9df0f Merge pull request #86 from QuantumEntangledAndy/feature/cellular
Feature/cellular
2023-05-19 22:55:02 +07:00
QuantumEntangledAndy 9133f20e64 Seeking withoffset again 2023-05-19 10:37:40 +07:00
QuantumEntangledAndy 2b0a0edf77 Add the cellular discovery option 2023-05-19 10:30:38 +07:00
QuantumEntangledAndy 5e22a019e5 Rework discovery to allow cellular 2023-05-19 10:19:38 +07:00
QuantumEntangledAndy 2a8c713ee0 Readme updates 2023-05-19 09:34:49 +07:00
Andrew King 4a95740f96 Merge pull request #83 from PrplHaz4/patch-1 2023-05-18 20:12:48 +07:00
PrplHaz4 5eee60ee17 change log level from trace to debug 2023-05-18 08:37:23 -04:00
PrplHaz4 8f1c86a8c8 Add docker run instructions to README
Add docker run instructions to README, use host networking to avoid explicitly mapping a bunch of ports, and trace logging to document for any users that need to troubleshoot.
2023-05-15 08:32:28 -04:00
12 changed files with 115 additions and 52 deletions

No files matched your search

+3
View File
@@ -20,3 +20,6 @@
._.DS_Store
**/.DS_Store
**/._.DS_Store
# The token file for the FCM tests
token.toml
Generated
+2 -2
View File
@@ -1408,7 +1408,7 @@ dependencies = [
[[package]]
name = "neolink"
version = "0.5.11"
version = "0.5.12"
dependencies = [
"anyhow",
"byte-slice-cast",
@@ -1440,7 +1440,7 @@ dependencies = [
[[package]]
name = "neolink_core"
version = "0.5.11"
version = "0.5.12"
dependencies = [
"aes",
"assert_matches",
+2 -2
View File
@@ -1,7 +1,7 @@
[package]
name = "neolink"
description = "A standards-compliant bridge to Reolink IP cameras"
version = "0.5.11"
version = "0.5.12"
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
edition = "2018"
license = "AGPL-3.0-or-later"
@@ -27,7 +27,7 @@ is_sorted = "0.1.1"
itertools = "0.10.5"
lazy_static = "1.4.0"
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
neolink_core = { path = "crates/core", version = "0.5.11" }
neolink_core = { path = "crates/core", version = "0.5.12" }
regex = "1.7.3"
rumqttc = "0.20.0"
serde = { version = "1.0.160", features = ["derive"] }
+18 -3
View File
@@ -145,6 +145,15 @@ In the `[[cameras]]` section of the toml.
Possible values are `local`, `remote`, `map`, `relay` later values implictly
enable prior methods.
#### Cellular
Cellular cameras should select `"cellular"` which only enables `map` and
`relay` since `local` and `remote` will always fail
```toml
discovery = "cellular"
```
### MQTT
To use mqtt you will to adjust your config file as such:
@@ -240,11 +249,18 @@ passed by a script for processing.
[Docker](https://hub.docker.com/r/quantumentangledandy/neolink) builds are also
provided in multiple architectures. The latest tag tracks master while each
branch gets it's own tag.
```bash
docker pull quantumentangledandy/neolink
# Add `-e "RUST_LOG=debug"` to run with debug logs
#
# --network host is only needed if you require to connect
# via local broadcasts. If you can connect via any other
# method then normal bridge mode should work fine
# and you can ommit this option
docker run --network host --volume=$PWD/config.toml:/etc/neolink.toml quantumentangledandy/neolink
```
### Image
@@ -255,11 +271,10 @@ You can write an image from the stream to disk using:
neolink image --config=config.toml --file-path=filepath CameraName
```
Where filepath is the path to save the image to and CameraName is the name o
Where filepath is the path to save the image to and CameraName is the name of
the camera from the config to save the image from.
File is always jpeg and the extension given in filepath will be added or changed
to reflect this.
## License
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "neolink_core"
description = "Core services and structure for Reolink IP cameras"
version = "0.5.11"
version = "0.5.12"
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
edition = "2018"
license = "AGPL-3.0-or-later"
+11 -8
View File
@@ -139,14 +139,16 @@ impl BcCamera {
}
}
}
info!("{}: Trying TCP discovery", options.name);
for socket in sockets.drain(..) {
let channel_id: u8 = options.channel_id;
if let Ok(addr) = Discovery::check_tcp(socket, channel_id).await.map(|_| {
info!("{}: TCP Discovery success at {:?}", options.name, &socket);
socket
}) {
return Ok(CameraLocation::Tcp(addr));
if !sockets.is_empty() {
info!("{}: Trying TCP discovery", options.name);
for socket in sockets.drain(..) {
let channel_id: u8 = options.channel_id;
if let Ok(addr) = Discovery::check_tcp(socket, channel_id).await.map(|_| {
info!("{}: TCP Discovery success at {:?}", options.name, &socket);
socket
}) {
return Ok(CameraLocation::Tcp(addr));
}
}
}
}
@@ -176,6 +178,7 @@ impl BcCamera {
DiscoveryMethods::Remote => (true, true, false, false),
DiscoveryMethods::Map => (true, true, true, false),
DiscoveryMethods::Relay => (true, true, true, true),
DiscoveryMethods::Cellular => (false, false, true, true),
DiscoveryMethods::Debug => (false, false, false, true),
};
@@ -18,6 +18,7 @@ use local_ip_address::local_ip;
use log::*;
use rand::{seq::SliceRandom, thread_rng, Rng};
use std::collections::{btree_map::Entry, BTreeMap};
use std::convert::TryInto;
use std::net::{Ipv4Addr, SocketAddr, ToSocketAddrs};
use std::sync::Arc;
use tokio::{
@@ -35,9 +36,9 @@ use tokio_util::udp::UdpFramed;
#[derive(Debug, Clone)]
struct RegisterResult {
reg: SocketAddr,
dev: SocketAddr,
dmap: SocketAddr,
relay: SocketAddr,
dev: Option<SocketAddr>,
dmap: Option<SocketAddr>,
relay: Option<SocketAddr>,
client_id: i32,
sid: u32,
}
@@ -463,17 +464,32 @@ impl Discoverer {
}),
..
},
} if !dev.ip.is_empty() && dev.port > 0 && rsp != -1 => {
} if (dev.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false)
|| dmap.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false)
|| relay.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false))
&& rsp != -1 =>
{
Some(Ok((sid, dev, dmap, relay)))
}
UdpDiscovery {
tid: _,
payload:
UdpXml {
r2c_c_r: Some(R2cCr { dev, rsp, .. }),
r2c_c_r:
Some(R2cCr {
dev,
dmap,
relay,
rsp,
..
}),
..
},
} if !dev.ip.is_empty() && dev.port > 0 && rsp == -1 => {
} if (dev.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false)
|| dmap.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false)
|| relay.as_ref().map(|d| !d.ip.is_empty()).unwrap_or(false))
&& rsp == -1 =>
{
Some(Err(Error::RegisterError))
}
_ => None,
@@ -484,9 +500,9 @@ impl Discoverer {
reg: lookup.reg,
sid,
client_id,
dev: SocketAddr::new(dev.ip.parse()?, dev.port),
dmap: SocketAddr::new(dmap.ip.parse()?, dmap.port),
relay: SocketAddr::new(relay.ip.parse()?, relay.port),
dev: dev.and_then(|d| d.try_into().ok()),
dmap: dmap.and_then(|d| d.try_into().ok()),
relay: relay.and_then(|d| d.try_into().ok()),
})
}
@@ -521,7 +537,10 @@ impl Discoverer {
},
) if cid == register_result.client_id
&& &sid == register_sid
&& &addr == register_dmap
&& register_dmap
.as_ref()
.map(|dmap| &addr == dmap)
.unwrap_or(false)
&& &conn == "local" =>
{
Some((addr, tid, did))
@@ -635,7 +654,10 @@ impl Discoverer {
},
) if cid == register_result.client_id
&& &sid == register_sid
&& &addr == register_dmap
&& register_dmap
.as_ref()
.map(|dmap| &addr == dmap)
.unwrap_or(false)
&& &conn == "map" =>
{
Some((addr, tid, did))
@@ -724,7 +746,7 @@ impl Discoverer {
) -> Result<ConnectResult> {
let tid = generate_tid();
let dev_addr = register_result.dev;
let dev_addr = register_result.dev.ok_or(Error::NoDev)?;
let msg = UdpDiscovery {
tid,
payload: UdpXml {
@@ -789,6 +811,7 @@ impl Discoverer {
) -> Result<ConnectResult> {
let tid = generate_tid();
let relay_addr = register_result.relay.ok_or(Error::NoDev)?;
let msg = UdpDiscovery {
tid,
payload: UdpXml {
@@ -803,7 +826,7 @@ impl Discoverer {
};
let (final_addr, local_did) = self
.retry_send(msg, register_result.relay, |bc, addr| match bc {
.retry_send(msg, relay_addr, |bc, addr| match bc {
UdpDiscovery {
tid: _,
payload:
@@ -38,6 +38,10 @@ pub enum DiscoveryMethods {
/// **This also enabled `Local`, `Map` and `Remote` discovery**
#[serde(alias = "relay")]
Relay,
/// Cellular camera only support relay and map, by choosing this option
/// only those are tried
#[serde(alias = "cellular")]
Cellular,
#[doc(hidden)]
#[serde(alias = "debug")]
/// Used for debugging it is set to whatever the dev is currently testing
+11 -2
View File
@@ -91,7 +91,12 @@ impl BcCamera {
mut buffer_size: usize,
strict: bool,
) -> Result<StreamData> {
self.has_ability_rw("preview").await?;
if let Err(e) = self.has_ability_rw("preview").await {
if self.has_ability_ro("streamTable").await.is_err() {
return Err(e);
}
}
let connection = self.get_connection();
let msg_num = self.new_message_num();
@@ -256,7 +261,11 @@ impl BcCamera {
/// Stop a camera from sending more stream data.
pub async fn stop_video(&self, stream: StreamKind) -> Result<()> {
self.has_ability_rw("preview").await?;
if let Err(e) = self.has_ability_rw("preview").await {
if self.has_ability_ro("streamTable").await.is_err() {
return Err(e);
}
}
let connection = self.get_connection();
let msg_num = self.new_message_num();
let mut sub_video = connection.subscribe(msg_num).await?;
+14 -3
View File
@@ -240,6 +240,17 @@ pub struct IpPort {
pub port: u16,
}
impl std::convert::TryFrom<IpPort> for std::net::SocketAddr {
type Error = crate::Error;
fn try_from(src: IpPort) -> Result<Self, Self::Error> {
Ok(src
.ip
.parse::<std::net::IpAddr>()
.map(|ip| std::net::SocketAddr::new(ip, src.port))?)
}
}
/// C2R_C xml
///
/// This is from client to the register reolink server
@@ -290,11 +301,11 @@ pub struct R2cT {
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
pub struct R2cCr {
/// Dev camera location (actual local ip)
pub dev: IpPort,
pub dev: Option<IpPort>,
/// Dmap camera location
pub dmap: IpPort,
pub dmap: Option<IpPort>,
/// The location of the relay
pub relay: IpPort,
pub relay: Option<IpPort>,
/// The nat type. Known values `"NULL"`
pub nat: String,
/// The camera SID
+2
View File
@@ -61,6 +61,8 @@ address = "192.168.1.187:9000"
# "remote" # Register our local ip address with reolink but only permit same network connections (useful if broadcast is not possible)
# "local" # Do not contact reolink servers at all. Rely soley on local UDP broadcast based discovery
#
# "cellular" # Cellular camera only support Relay and Map to speed up connecting to them this option will skip the local/remote
#
# discovery = "relay"
# Certain types of camera emit status messages (such as battery levels)
+11 -18
View File
@@ -635,9 +635,12 @@ impl NeoMediaSender {
async fn seek(
&mut self,
_original_runtime: Option<FrameTime>,
_target_runtime: FrameTime,
target_runtime: FrameTime,
_master_buffer: &NeoBuffer,
) -> AnyResult<()> {
if let Some(runtime) = self.get_raw_runtime() {
self.live_offset = target_runtime - runtime;
}
self.jump_to_live().await?;
Ok(())
}
@@ -702,28 +705,13 @@ impl NeoMediaSender {
Ok(())
}
fn get_runtime(&self) -> Option<FrameTime> {
fn get_raw_runtime(&self) -> Option<FrameTime> {
if let Some(appsrc) = self.vid.as_ref() {
if let Some(clock) = appsrc.clock() {
if let Some(time) = clock.time() {
if let Some(base_time) = appsrc.base_time() {
let runtime = time.saturating_sub(base_time);
let res = Some(
(runtime.useconds() as FrameTime)
.saturating_add(self.live_offset)
.max(0),
);
// debug!("base_time: {:?}", base_time);
// debug!("time: {:?}", time);
// debug!("runtime: {:?}", runtime);
// debug!("Final runtime: {:?}", res);
trace!(
"Runtime: {:?}, Offset: {:?}, Offseted Runtime: {:?}",
runtime,
self.live_offset,
res
);
return res;
return Some(runtime.useconds() as FrameTime);
}
}
}
@@ -731,6 +719,11 @@ impl NeoMediaSender {
None
}
fn get_runtime(&self) -> Option<FrameTime> {
self.get_raw_runtime()
.map(|runtime| runtime.saturating_add(self.live_offset).max(0))
}
fn get_buftime(&self) -> Option<FrameTime> {
self.get_runtime().map(|time| self.runtime_to_buftime(time))
}