Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7a244a1ab | ||
|
|
b978809a59 | ||
|
|
6b35db8fbe | ||
|
|
c3f3ecdb83 | ||
|
|
f99df6e5e7 | ||
|
|
e09d9d30dc | ||
|
|
c2f0b5b2d9 | ||
|
|
472eda9f06 | ||
|
|
c831d07573 | ||
|
|
90b51b7e46 | ||
|
|
cdc8a9cb8e | ||
|
|
790eb655a3 | ||
|
|
99584ce813 | ||
|
|
c2a5798905 | ||
|
|
951a822973 | ||
|
|
f5ac615b3c | ||
|
|
3b677f9156 | ||
|
|
9473a8ad5d | ||
|
|
56ef79ff45 | ||
|
|
d61e48ce79 | ||
|
|
86f15f9eb1 | ||
|
|
84e10530a5 | ||
|
|
2f74a720f5 | ||
|
|
511e50fe52 | ||
|
|
78da59fc71 | ||
|
|
36f70c3222 | ||
|
|
279c1c5bf1 | ||
|
|
f5ba6e244f | ||
|
|
6a980b47ae | ||
|
|
3a783bf50c | ||
|
|
9dabb43a9c |
No files matched your search
@@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
# Map a step output to a job output
|
||||
outputs:
|
||||
should_skip: ${{ steps.skip_check.outputs.should_skip }}
|
||||
should_skip: ${{ steps.skip_check.outputs.should_skip }} && ! (startsWith(github.ref, 'refs/tags/') && github.event_name == 'push')
|
||||
steps:
|
||||
- id: skip_check
|
||||
uses: fkirc/skip-duplicate-actions@v5
|
||||
|
||||
@@ -24,11 +24,11 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: apt install gstreamer
|
||||
- name: apt install gstreamer and deps
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y aptitude
|
||||
sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev
|
||||
sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev protobuf-compiler
|
||||
- name: Install nightly rust
|
||||
run: |
|
||||
rustup toolchain install nightly --component clippy
|
||||
|
||||
@@ -20,3 +20,6 @@
|
||||
._.DS_Store
|
||||
**/.DS_Store
|
||||
**/._.DS_Store
|
||||
|
||||
# The token file for the FCM tests
|
||||
token.toml
|
||||
@@ -0,0 +1,2 @@
|
||||
MD013:
|
||||
code_blocks: false
|
||||
@@ -16,4 +16,5 @@ repos:
|
||||
hooks:
|
||||
- id: markdownlint-fix
|
||||
files: README.md
|
||||
args: [--disable, MD041, --]
|
||||
|
||||
Generated
+561
-23
@@ -32,13 +32,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.3.0"
|
||||
@@ -90,9 +99,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.70"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
|
||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||
|
||||
[[package]]
|
||||
name = "assert_matches"
|
||||
@@ -208,6 +217,15 @@ version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.0"
|
||||
@@ -268,6 +286,19 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.4.4"
|
||||
@@ -280,9 +311,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.2.2"
|
||||
version = "4.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b802d85aaf3a1cdb02b224ba472ebdea62014fccfcb269b95a4d76443b5ee5a"
|
||||
checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -291,9 +322,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.2.2"
|
||||
version = "4.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14a1a858f532119338887a4b8e1af9c60de8249cd7bafd68036a489e261e37b6"
|
||||
checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -457,6 +488,41 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "delegate"
|
||||
version = "0.9.0"
|
||||
@@ -468,12 +534,50 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ece"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dd5463ffecc0677adcd786c4481f73b215714d4757edf2eb37a573c03d00459"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"byteorder",
|
||||
"hex",
|
||||
"hkdf",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"openssl",
|
||||
"serde",
|
||||
"sha2",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.0"
|
||||
@@ -531,6 +635,32 @@ dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fcm-push-listener"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51e1e9327cb6abc9da64951727a3cf534ae7101e529382dac7f5d350bccdba42"
|
||||
dependencies = [
|
||||
"base64 0.21.0",
|
||||
"ece",
|
||||
"log",
|
||||
"prost",
|
||||
"prost-build",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_with",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"uuid",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.26"
|
||||
@@ -560,6 +690,21 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
@@ -1070,12 +1215,36 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hex-string"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "848ec2dd093df965a34b434580d94852197fc83feac5b2c1962399bbf2cb4f0b"
|
||||
|
||||
[[package]]
|
||||
name = "hkdf"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437"
|
||||
dependencies = [
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.9"
|
||||
@@ -1152,6 +1321,48 @@ dependencies = [
|
||||
"tokio-io-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hyper",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
@@ -1187,6 +1398,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1224,6 +1436,12 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.7"
|
||||
@@ -1236,6 +1454,12 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_sorted"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "357376465c37db3372ef6a00585d336ed3d0f11d4345eef77ebcb05865392b21"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
@@ -1381,6 +1605,12 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
|
||||
|
||||
[[package]]
|
||||
name = "multimap"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
|
||||
|
||||
[[package]]
|
||||
name = "nanorand"
|
||||
version = "0.7.0"
|
||||
@@ -1390,6 +1620,24 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "neli"
|
||||
version = "0.5.3"
|
||||
@@ -1402,7 +1650,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "neolink"
|
||||
version = "0.5.10"
|
||||
version = "0.5.11"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byte-slice-cast",
|
||||
@@ -1415,6 +1663,8 @@ dependencies = [
|
||||
"gstreamer-app",
|
||||
"gstreamer-rtsp",
|
||||
"gstreamer-rtsp-server",
|
||||
"is_sorted",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"neolink_core",
|
||||
@@ -1432,7 +1682,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "neolink_core"
|
||||
version = "0.5.10"
|
||||
version = "0.5.11"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"assert_matches",
|
||||
@@ -1542,12 +1792,50 @@ version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-operations"
|
||||
version = "0.5.0"
|
||||
@@ -1592,6 +1880,16 @@ version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.12"
|
||||
@@ -1648,6 +1946,16 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.1.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
@@ -1701,6 +2009,28 @@ dependencies = [
|
||||
"prost-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-build"
|
||||
version = "0.11.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"heck",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"multimap",
|
||||
"petgraph",
|
||||
"prettyplease",
|
||||
"prost",
|
||||
"prost-types",
|
||||
"regex",
|
||||
"syn 1.0.109",
|
||||
"tempfile",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-derive"
|
||||
version = "0.11.9"
|
||||
@@ -1723,6 +2053,25 @@ dependencies = [
|
||||
"prost",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pushnoti"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"fcm-push-listener",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"neolink_core",
|
||||
"regex",
|
||||
"serde",
|
||||
"tokio",
|
||||
"toml",
|
||||
"validator",
|
||||
"validator_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
@@ -1782,13 +2131,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.3"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
|
||||
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
"regex-syntax 0.7.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1797,7 +2146,7 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
"regex-syntax 0.6.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1806,6 +2155,12 @@ version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
|
||||
|
||||
[[package]]
|
||||
name = "requestty"
|
||||
version = "0.5.0"
|
||||
@@ -1832,6 +2187,43 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55"
|
||||
dependencies = [
|
||||
"base64 0.21.0",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
"hyper",
|
||||
"hyper-tls",
|
||||
"ipnet",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
@@ -1974,18 +2366,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.160"
|
||||
version = "1.0.163"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
|
||||
checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.160"
|
||||
version = "1.0.163"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
||||
checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2012,6 +2404,57 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with"
|
||||
version = "2.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"chrono",
|
||||
"hex",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with_macros",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with_macros"
|
||||
version = "2.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
@@ -2109,6 +2552,12 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@@ -2231,6 +2680,7 @@ version = "0.3.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"libc",
|
||||
"num_threads",
|
||||
"serde",
|
||||
@@ -2270,9 +2720,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.27.0"
|
||||
version = "1.28.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001"
|
||||
checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
@@ -2285,7 +2735,7 @@ dependencies = [
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"tracing",
|
||||
"windows-sys 0.45.0",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2300,15 +2750,25 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.23.4"
|
||||
@@ -2590,6 +3050,28 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"rand",
|
||||
"uuid-macro-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid-macro-internal"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f67b459f42af2e6e1ee213cb9da4dbd022d3320788c3fb3e1b893093f1e45da"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "validator"
|
||||
version = "0.16.0"
|
||||
@@ -2637,6 +3119,12 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
@@ -2690,6 +3178,18 @@ dependencies = [
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
@@ -2739,6 +3239,26 @@ dependencies = [
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.22.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
|
||||
dependencies = [
|
||||
"either",
|
||||
"libc",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
@@ -2776,6 +3296,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.42.0"
|
||||
@@ -2932,6 +3461,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
|
||||
dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winsplit"
|
||||
version = "0.1.0"
|
||||
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "neolink"
|
||||
description = "A standards-compliant bridge to Reolink IP cameras"
|
||||
version = "0.5.10"
|
||||
version = "0.5.11"
|
||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "AGPL-3.0-or-later"
|
||||
@@ -23,9 +23,11 @@ gstreamer = "0.20.3"
|
||||
gstreamer-app = "0.20.0"
|
||||
gstreamer-rtsp = "0.20.0"
|
||||
gstreamer-rtsp-server = { version = "0.20.3", features = ["v1_16"] }
|
||||
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.10" }
|
||||
neolink_core = { path = "crates/core", version = "0.5.11" }
|
||||
regex = "1.7.3"
|
||||
rumqttc = "0.20.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "neolink_core"
|
||||
description = "Core services and structure for Reolink IP cameras"
|
||||
version = "0.5.10"
|
||||
version = "0.5.11"
|
||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
@@ -35,6 +35,8 @@ pub const MSG_ID_GET_GENERAL: u32 = 104;
|
||||
pub const MSG_ID_ABILITY_INFO: u32 = 151;
|
||||
/// Setting general system info (clock mostly) messages have this ID
|
||||
pub const MSG_ID_SET_GENERAL: u32 = 105;
|
||||
/// Used to pass the token and client ID for push notifications
|
||||
pub const MSG_ID_PUSH_INFO: u32 = 124;
|
||||
/// Will send the talk config for talk back data to follow this msg
|
||||
pub const MSG_ID_TALKCONFIG: u32 = 201;
|
||||
/// Used to send talk back binary data
|
||||
|
||||
@@ -85,6 +85,9 @@ pub struct BcXml {
|
||||
/// Recieved on request for a users persmissions/capabilitoes
|
||||
#[yaserde(rename = "AbilityInfo")]
|
||||
pub ability_info: Option<AbilityInfo>,
|
||||
/// Recieved on request for a users persmissions/capabilitoes
|
||||
#[yaserde(rename = "PushInfo")]
|
||||
pub push_info: Option<PushInfo>,
|
||||
}
|
||||
|
||||
impl BcXml {
|
||||
@@ -614,6 +617,19 @@ pub struct AbilityInfoSubModule {
|
||||
pub ability_value: String,
|
||||
}
|
||||
|
||||
/// PushInfo XML
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct PushInfo {
|
||||
/// The token from FCM registration
|
||||
pub token: String,
|
||||
/// The phone type, known values: `reo_iphone`
|
||||
#[yaserde(rename = "phoneType")]
|
||||
pub phone_type: String,
|
||||
/// A client ID, seems to be an all CAPS MD5 hash of something
|
||||
#[yaserde(rename = "clientID")]
|
||||
pub client_id: String,
|
||||
}
|
||||
|
||||
/// Convience function to return the xml version used throughout the library
|
||||
pub fn xml_ver() -> String {
|
||||
"1.1".to_string()
|
||||
|
||||
@@ -24,6 +24,7 @@ mod motion;
|
||||
mod ping;
|
||||
mod pirstate;
|
||||
mod ptz;
|
||||
mod pushinfo;
|
||||
mod reboot;
|
||||
mod resolution;
|
||||
mod stream;
|
||||
@@ -39,6 +40,7 @@ pub use login::MaxEncryption;
|
||||
pub use motion::{MotionData, MotionStatus};
|
||||
pub use pirstate::PirState;
|
||||
pub use ptz::Direction;
|
||||
pub use pushinfo::PhoneType;
|
||||
pub use resolution::*;
|
||||
use std::sync::Arc;
|
||||
pub use stream::{StreamData, StreamKind};
|
||||
|
||||
@@ -58,7 +58,7 @@ struct UidLookupResults {
|
||||
|
||||
pub(crate) struct Discovery {}
|
||||
|
||||
const MTU: u32 = 1030;
|
||||
const MTU: u32 = 1350;
|
||||
lazy_static! {
|
||||
static ref P2P_RELAY_HOSTNAMES: [&'static str; 10] = [
|
||||
"p2p.reolink.com",
|
||||
@@ -445,6 +445,8 @@ impl Discoverer {
|
||||
},
|
||||
};
|
||||
|
||||
trace!("Registering: {:?}", msg.payload.c2r_c);
|
||||
|
||||
// Send and await acceptance
|
||||
let (sid, dev, dmap, relay) = self
|
||||
.retry_send(msg, lookup.reg, |bc, _| match bc {
|
||||
|
||||
@@ -28,7 +28,7 @@ use tokio_util::{
|
||||
udp::UdpFramed,
|
||||
};
|
||||
|
||||
const MTU: usize = 1030;
|
||||
const MTU: usize = 1350;
|
||||
const UDPDATA_HEADER_SIZE: usize = 20;
|
||||
|
||||
pub(crate) struct UdpSource {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
use super::{BcCamera, Error, Result};
|
||||
use crate::bc::{model::*, xml::*};
|
||||
|
||||
/// Specifies the phone type for the push notification
|
||||
pub enum PhoneType {
|
||||
/// Specify that this is an ios push notfication
|
||||
///
|
||||
/// In this case the token must be the APNS
|
||||
Ios,
|
||||
/// Specify that this is an andriod push notfication
|
||||
///
|
||||
/// In this case the token must firebase cloud messaging token
|
||||
Android,
|
||||
}
|
||||
|
||||
impl BcCamera {
|
||||
/// Convenience method for andriod of `[send_pushinfo]`
|
||||
pub async fn send_pushinfo_android(&self, token: &str, client_id: &str) -> Result<()> {
|
||||
self.send_pushinfo(token, client_id, PhoneType::Android)
|
||||
.await
|
||||
}
|
||||
/// Convenience method for andriod of `[send_pushinfo]`
|
||||
pub async fn send_pushinfo_ios(&self, token: &str, client_id: &str) -> Result<()> {
|
||||
self.send_pushinfo(token, client_id, PhoneType::Ios).await
|
||||
}
|
||||
/// Send the push info to regsiter for push notfications
|
||||
pub async fn send_pushinfo(
|
||||
&self,
|
||||
token: &str,
|
||||
client_id: &str,
|
||||
phone_type: PhoneType,
|
||||
) -> Result<()> {
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub = connection.subscribe(msg_num).await?;
|
||||
|
||||
let phone_type_str = match phone_type {
|
||||
PhoneType::Ios => "reo_iphone",
|
||||
PhoneType::Android => "reo_fcm",
|
||||
};
|
||||
|
||||
let msg = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_PUSH_INFO,
|
||||
channel_id: self.channel_id,
|
||||
msg_num,
|
||||
response_code: 0,
|
||||
stream_type: 0,
|
||||
class: 0x6414,
|
||||
},
|
||||
body: BcBody::ModernMsg(ModernMsg {
|
||||
extension: None,
|
||||
payload: Some(BcPayloads::BcXml(BcXml {
|
||||
push_info: Some(PushInfo {
|
||||
token: token.to_owned(),
|
||||
phone_type: phone_type_str.to_owned(),
|
||||
client_id: client_id.to_owned(),
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
}),
|
||||
};
|
||||
|
||||
sub.send(msg).await?;
|
||||
let msg = sub.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavaliable);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,28 @@ impl BcCamera {
|
||||
sub_video.send(stop_video).await?;
|
||||
// debug!("Stream: Sent Stop");
|
||||
|
||||
tokio::select! {
|
||||
v = async {
|
||||
loop {
|
||||
let msg = sub_video.recv().await?;
|
||||
if let BcMeta {
|
||||
response_code: 200,
|
||||
msg_id: MSG_ID_VIDEO_STOP,
|
||||
..
|
||||
} = msg.meta {
|
||||
return Ok(());
|
||||
}
|
||||
else if let BcMeta {
|
||||
msg_id: MSG_ID_VIDEO_STOP,
|
||||
..
|
||||
} = msg.meta {
|
||||
return Err(Error::CameraServiceUnavaliable);
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
_ = tokio::time::sleep(tokio::time::Duration::from_secs(2)) => {Ok(())},
|
||||
}?;
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "pushnoti"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.71"
|
||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||
env_logger = "0.10.0"
|
||||
fcm-push-listener = "2.0.1"
|
||||
lazy_static = "1.4.0"
|
||||
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||
neolink_core = { path = "../core", version = "0.5" }
|
||||
regex = "1.8.1"
|
||||
serde = "1.0.163"
|
||||
tokio = { version = "1.28.1", features = ["full"] }
|
||||
toml = "0.7.3"
|
||||
validator = "0.16.0"
|
||||
validator_derive = "0.16.0"
|
||||
@@ -0,0 +1,273 @@
|
||||
# Reolink Push Notifications
|
||||
|
||||
This is the test crate to experiment with RE-ing the push notifications for a
|
||||
camera
|
||||
|
||||
The goal here is to connect to Google's firebase cloud messaging system (FCM)
|
||||
and recieve push notificaions for motion updates. This way we can get motion
|
||||
notifications without being logged in to the camera and this will let us
|
||||
disconnect from battery cameras and save power.
|
||||
|
||||
The following is the reolink data for google extracted from ios.
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>AD_UNIT_ID_FOR_BANNER_TEST</key>
|
||||
<string>ca-app-pub-3940256099942544/2934735716</string>
|
||||
<key>AD_UNIT_ID_FOR_INTERSTITIAL_TEST</key>
|
||||
<string>ca-app-pub-3940256099942544/4411468910</string>
|
||||
<key>API_KEY</key>
|
||||
<string>AIzaSyAV5l5DbbAkYB5X61wgn81Lb2f7s1h-ANE</string>
|
||||
<key>BUNDLE_ID</key>
|
||||
<string>com.reo.link</string>
|
||||
<key>CLIENT_ID</key>
|
||||
<string>696841269229-mfqfluqdkb0s2raassbsul48h09l2eiv.apps.googleusercontent.com</string>
|
||||
<key>DATABASE_URL</key>
|
||||
<string>https://reolink-for-ios.firebaseio.com</string>
|
||||
<key>GCM_SENDER_ID</key>
|
||||
<string>696841269229</string>
|
||||
<key>GOOGLE_APP_ID</key>
|
||||
<string>1:696841269229:ios:690529b18debb2e3</string>
|
||||
<key>IS_ADS_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_ANALYTICS_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_APPINVITE_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_GCM_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_SIGNIN_ENABLED</key>
|
||||
<false/>
|
||||
<key>PLIST_VERSION</key>
|
||||
<string>1</string>
|
||||
<key>PROJECT_ID</key>
|
||||
<string>reolink-for-ios</string>
|
||||
<key>REVERSED_CLIENT_ID</key>
|
||||
<string>com.googleusercontent.apps.696841269229-mfqfluqdkb0s2raassbsul48h09l2eiv</string>
|
||||
<key>STORAGE_BUCKET</key>
|
||||
<string>reolink-for-ios.appspot.com</string>
|
||||
</dict>
|
||||
</plist>
|
||||
```
|
||||
|
||||
Key information from this is
|
||||
|
||||
```xml
|
||||
<key>GCM_SENDER_ID</key>
|
||||
<string>696841269229</string>
|
||||
```
|
||||
|
||||
Which we use to register for FCM
|
||||
|
||||
---
|
||||
|
||||
p.s. maybe some one can do something fun with the API
|
||||
key not sure what thats doing there since anyone can
|
||||
extract that.
|
||||
|
||||
```xml
|
||||
<key>API_KEY</key>
|
||||
<string>AIzaSyAV5l5DbbAkYB5X61wgn81Lb2f7s1h-ANE</string>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
On android the details are little harder for me to extract (ios here). By
|
||||
extracting the apk with apktook I found the following:
|
||||
|
||||
```xml
|
||||
<string name="gcm_defaultSenderId">743639030586</string>
|
||||
<string name="google_api_key">AIzaSyBEUIuWHnnOEwFahxWgQB4Yt4NsgOmkPyE</string>
|
||||
<string name="google_app_id">1:743639030586:android:86f60a4fb7143876</string>
|
||||
<string name="google_client_id">743639030586-ove5uqrausoqtjjkev4b1tk4vjdfpt4l.apps.googleusercontent.com</string>
|
||||
```
|
||||
|
||||
Where the key we need is `743639030586`
|
||||
|
||||
To emulate the push recievier we use the `fcm-push-listener` crate. Which
|
||||
is a rust implementation of the good
|
||||
[RE work of Matthieu Lemoine.](https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0)
|
||||
hats off to you.
|
||||
|
||||
We also need to send the PushInfo command to the camera with the token we get
|
||||
from FCM and some client ID. On IOS the token is the APNS number.
|
||||
|
||||
The client ID is an all CAPS UID of hexadecimal of 33 chars. Not sure how
|
||||
these are generated but they seem to be unique to the device, perhaps a MD5 of
|
||||
something or some generated UID on app initial login.
|
||||
|
||||
To experiment I did a data wipe on the reolink app and found it generates a new UID.
|
||||
I also found out that if you do this while you have Push Notifications turned on
|
||||
then you cannot turn them off anymore. To disable the push notifications you need
|
||||
the UID which I just wiped.... Fortunatly I saved before I wiped it so I could restore.
|
||||
p.d. If you every wipe your reolink data and need to stop the push notifications
|
||||
you can try doing manually using the API listed at the end.
|
||||
|
||||
This is the data of the `PushInfo` command that is sent to the camera:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<PushInfo version="1.1">
|
||||
<token>TOKEN_FROM_FCM_OR_APNS</token>
|
||||
<phoneType>reo_iphone</phoneType>
|
||||
<clientID>SOMEID</clientID>
|
||||
</PushInfo>
|
||||
</body>
|
||||
```
|
||||
|
||||
For ios the phonetype is `reo_iphone` which I observed live but for android
|
||||
no such luck.
|
||||
|
||||
First I just tried `reo_android` but the camera replied with an error code.
|
||||
Which at least told me that I can test other string quickly and see if it
|
||||
returns the error code.
|
||||
|
||||
Next thing to do was dumping the binaries from the apk and searching for a string
|
||||
like `reo_`
|
||||
|
||||
```bash
|
||||
grep -Ria "reo_" .
|
||||
./lib/armeabi-v7a/libavcodec.so:stereo_modeError splitting the input into NAL units.
|
||||
./lib/arm64-v8a/libavcodec.so:stereo_modeError splitting the input into NAL units.
|
||||
./smali_classes2/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.smali:.field private static final ID_STEREO_MODE:I = 0x53b8
|
||||
./smali_classes2/com/google/android/exoplayer2/C.smali:.field public static final STEREO_MODE_LEFT_RIGHT:I = 0x2
|
||||
./smali_classes2/com/google/android/exoplayer2/C.smali:.field public static final STEREO_MODE_MONO:I = 0x0
|
||||
./smali_classes2/com/google/android/exoplayer2/C.smali:.field public static final STEREO_MODE_STEREO_MESH:I = 0x3
|
||||
./smali_classes2/com/google/android/exoplayer2/C.smali:.field public static final STEREO_MODE_TOP_BOTTOM:I = 0x1
|
||||
./smali_classes2/com/android/bc/util/DeviceIdUtil$UpdatePushClientIdRequest.smali: const-string v2, "reo_fcm"
|
||||
./smali_classes2/com/android/bc/pushmanager/MyPushAdapterImpl.smali: const-string v0, "reo_fcm"
|
||||
./smali/androidx/core/text/BidiFormatter.smali:.field private static final FLAG_STEREO_RESET:I = 0x2
|
||||
./smali/com/android/bc/component/BaseWebViewFragment.smali: const-string v2, "REO_LANGUAGE="
|
||||
```
|
||||
|
||||
The interesting one was `MyPushAdapterImpl.smali: const-string v0, "reo_fcm"`
|
||||
which suggested that it is `reo_fcm` stuck that in and voilla
|
||||
no error messages from the camera.
|
||||
|
||||
Now to compile the test app with all this info
|
||||
wait patiently for a motion event and...
|
||||
|
||||
viola!
|
||||
|
||||
Reolink was kinda enough to send this to my test app:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"SRVTIME": "2023-05-19T08:07:03.566Z",
|
||||
"ALMNAME": "Motion Alert from Cam01",
|
||||
"sound": "push.wav",
|
||||
"CHNAME": "Cam0",
|
||||
"messageType": "alarm",
|
||||
"DEVNAME": "Cam01",
|
||||
"pushVersion": "v1.1",
|
||||
"UID": "REDACTED",
|
||||
"ALMTYPE": "MD",
|
||||
"ALMCHN": "1",
|
||||
"alert": "Motion Alert from Cam01",
|
||||
"title": "Camera Alert"
|
||||
},
|
||||
"from": "743639030586",
|
||||
"priority": "normal",
|
||||
"notification": { "title": "Camera Alert", "body": "Motion Alert from Cam01" },
|
||||
"fcmMessageId": "REDACTED"
|
||||
}
|
||||
```
|
||||
|
||||
There's no push notifiation for motion stop event but I can wait for this message
|
||||
then login and use normal motion detection to tell when it stops.
|
||||
|
||||
Yay.... now to just add all this to actual neolink so we can save battery.....
|
||||
|
||||
---
|
||||
|
||||
While experimenting with the ios app, in addition to observing all the
|
||||
data send to the camera, I also looked at all https calls the app was making
|
||||
(mitmproxy). This showed a set of APIs that could be useful. Including the api
|
||||
for deleting a push notification.
|
||||
|
||||
---
|
||||
|
||||
To disable a PUSH request the following is done:
|
||||
|
||||
```bash
|
||||
curl -v -X DELETE 'https://pushx.reolink.com/devices/<CAMERA_UID>/notifications/listeners/<clientID_FROM_PushInfo>' -H 'Cookie:'
|
||||
```
|
||||
|
||||
Reply is:
|
||||
|
||||
```json
|
||||
{
|
||||
"status" : {
|
||||
"detail" : "OK",
|
||||
"code" : 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Nothing seems to be sent to the camera just this to the reolink api
|
||||
|
||||
---
|
||||
|
||||
On ios application start reolink send this:
|
||||
|
||||
```bash
|
||||
curl -v -X GET 'https://pushx.reolink.com/listeners/<clientID_FROM_PushInfo>/devices' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept: */*' -H 'Accept-Language: en-GB,en;q=0.9' -H 'Cookie:'
|
||||
```
|
||||
|
||||
Which resonds with this json which contains a list of all currently
|
||||
enabled push notification camera UIDs for this client
|
||||
|
||||
```json
|
||||
{
|
||||
"status" : {
|
||||
"detail" : "OK",
|
||||
"code" : 0
|
||||
},
|
||||
"data" : [
|
||||
{
|
||||
"uid" : "<CAMERA_UID>",
|
||||
"secret" : ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You can also confirm a device has a listener with
|
||||
|
||||
```bash
|
||||
curl -v -X GET 'https://pushx.reolink.com/devices/<CAMERA_UID>/listeners/<clientID_FROM_PushInfo>/config' -H 'Cookie:'
|
||||
```
|
||||
|
||||
Which returns
|
||||
|
||||
```json
|
||||
{
|
||||
"status": {
|
||||
"code":0,
|
||||
"detail":"OK"
|
||||
},
|
||||
"data": {
|
||||
"sound": {
|
||||
"soundType":0,
|
||||
"soundName":"",
|
||||
"soundVolume":0
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
There's also a profile one that the app does when a new camera is added
|
||||
but I forgot to save the details of it.
|
||||
|
||||
It reports all the capabilities of the camera, such as it's model
|
||||
and its resolution etc. Could be useful to test if a UID is valid
|
||||
quickly
|
||||
@@ -0,0 +1,80 @@
|
||||
use lazy_static::lazy_static;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat};
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::clone::Clone;
|
||||
use validator::{Validate, ValidationError};
|
||||
use validator_derive::Validate;
|
||||
|
||||
lazy_static! {
|
||||
static ref RE_STREAM_SRC: Regex =
|
||||
Regex::new(r"^(mainStream|subStream|externStream|both|all)$").unwrap();
|
||||
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();
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
pub(crate) struct Config {
|
||||
#[validate]
|
||||
pub(crate) cameras: Vec<CameraConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
#[validate(schema(function = "validate_camera_config"))]
|
||||
pub(crate) struct CameraConfig {
|
||||
pub(crate) name: String,
|
||||
|
||||
#[serde(rename = "address")]
|
||||
pub(crate) camera_addr: Option<String>,
|
||||
|
||||
#[serde(rename = "uid")]
|
||||
pub(crate) camera_uid: Option<String>,
|
||||
|
||||
pub(crate) username: String,
|
||||
pub(crate) password: Option<String>,
|
||||
|
||||
#[validate(range(min = 0, max = 31, message = "Invalid channel", code = "channel_id"))]
|
||||
#[serde(default = "default_channel_id")]
|
||||
pub(crate) channel_id: u8,
|
||||
|
||||
#[serde(default = "default_discovery")]
|
||||
pub(crate) discovery: DiscoveryMethods,
|
||||
|
||||
#[serde(default = "default_maxenc")]
|
||||
#[validate(regex(
|
||||
path = "RE_MAXENC_SRC",
|
||||
message = "Invalid maximum encryption method",
|
||||
code = "max_encryption"
|
||||
))]
|
||||
pub(crate) max_encryption: String,
|
||||
|
||||
#[serde(default = "default_print", alias = "print")]
|
||||
pub(crate) print_format: PrintFormat,
|
||||
}
|
||||
|
||||
fn default_print() -> PrintFormat {
|
||||
PrintFormat::None
|
||||
}
|
||||
|
||||
fn default_discovery() -> DiscoveryMethods {
|
||||
DiscoveryMethods::Relay
|
||||
}
|
||||
|
||||
fn default_maxenc() -> String {
|
||||
"Aes".to_string()
|
||||
}
|
||||
|
||||
fn default_channel_id() -> u8 {
|
||||
0
|
||||
}
|
||||
|
||||
fn validate_camera_config(camera_config: &CameraConfig) -> Result<(), ValidationError> {
|
||||
match (&camera_config.camera_addr, &camera_config.camera_uid) {
|
||||
(None, None) => Err(ValidationError::new(
|
||||
"Either camera address or uid must be given",
|
||||
)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use fcm_push_listener::*;
|
||||
use log::*;
|
||||
use std::{fs, path::PathBuf};
|
||||
use validator::Validate;
|
||||
|
||||
mod config;
|
||||
mod opt;
|
||||
mod utils;
|
||||
|
||||
use config::Config;
|
||||
use opt::Opt;
|
||||
use utils::find_and_connect;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
|
||||
let opt = Opt::parse();
|
||||
|
||||
let conf_path = opt.config.context("Must supply --config file")?;
|
||||
let config: Config = toml::from_str(
|
||||
&fs::read_to_string(&conf_path)
|
||||
.with_context(|| format!("Failed to read {:?}", conf_path))?,
|
||||
)
|
||||
.with_context(|| format!("Failed to parse the {:?} config file", conf_path))?;
|
||||
|
||||
config
|
||||
.validate()
|
||||
.with_context(|| format!("Failed to validate the {:?} config file", conf_path))?;
|
||||
|
||||
let camera = find_and_connect(&config, &opt.camera).await?;
|
||||
|
||||
// 696841269229 is the reo_iphone FCM Sender_ID
|
||||
// let registration = fcm_push_listener::register("696841269229").await?;
|
||||
// 743639030586 is the reo_fcm FCM Sender_ID
|
||||
// 263684512460 is my test Sender_ID
|
||||
// let registration = fcm_push_listener::register("743639030586").await?
|
||||
// I have confirmed that I can recieve test messages with this SenderID
|
||||
// into this program
|
||||
// let registration = fcm_push_listener::register("263684512460").await?;
|
||||
|
||||
let sender_id = "743639030586"; // andriod
|
||||
|
||||
// let sender_id = "696841269229"; // ios
|
||||
|
||||
// let sender_id = "263684512460"; // test
|
||||
|
||||
let token_path = PathBuf::from("./token.toml");
|
||||
let registration = if let Ok(Ok(registration)) =
|
||||
fs::read_to_string(&token_path).map(|v| toml::from_str::<Registration>(&v))
|
||||
{
|
||||
info!("Loaded token");
|
||||
registration
|
||||
} else {
|
||||
info!("Registering new token");
|
||||
let registration = fcm_push_listener::register(sender_id).await?;
|
||||
let new_token = toml::to_string(®istration)?;
|
||||
fs::write(token_path, new_token)?;
|
||||
registration
|
||||
};
|
||||
|
||||
// Send registration.fcm_token to the server to allow it to send push messages to you.
|
||||
info!("registration.fcm_token: {}", registration.fcm_token);
|
||||
let uid = "6A5443E486511B0D828543445DC55A7D"; // MD5 Hash of "WHY_REOLINK"
|
||||
camera
|
||||
.send_pushinfo_android(®istration.fcm_token, uid)
|
||||
.await?;
|
||||
|
||||
info!("Listening");
|
||||
let mut listener = FcmPushListener::create(
|
||||
registration,
|
||||
|message: FcmMessage| {
|
||||
info!("Message JSON: {}", message.payload_json);
|
||||
info!("Persistent ID: {:?}", message.persistent_id);
|
||||
},
|
||||
vec![],
|
||||
);
|
||||
listener.connect().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use clap::{crate_authors, crate_version, Parser};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// A standards-compliant bridge to Reolink IP cameras
|
||||
///
|
||||
/// Neolink is free software released under the GNU AGPL v3.
|
||||
/// You can find its source code at https://github.com/thirtythreeforty/neolink
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "pushnoti", arg_required_else_help = true, version = crate_version!(), author = crate_authors!("\n"))]
|
||||
pub struct Opt {
|
||||
#[arg(short, long, value_parser = PathBuf::from_str)]
|
||||
pub config: Option<PathBuf>,
|
||||
/// The name of the camera. Must be a name in the config
|
||||
pub camera: String,
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
//! Contains code that is not specific to any of the subcommands
|
||||
//!
|
||||
use log::*;
|
||||
|
||||
use super::config::{CameraConfig, Config};
|
||||
use anyhow::{anyhow, Context, Error, Result};
|
||||
use neolink_core::bc_protocol::{
|
||||
BcCamera, BcCameraOpt, ConnectionProtocol, Credentials, DiscoveryMethods, MaxEncryption,
|
||||
};
|
||||
use std::{
|
||||
fmt::{Display, Error as FmtError, Formatter},
|
||||
net::{IpAddr, ToSocketAddrs},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
pub(crate) enum AddressOrUid {
|
||||
Address(String),
|
||||
Uid(String, DiscoveryMethods),
|
||||
AddressWithUid(String, String, DiscoveryMethods),
|
||||
}
|
||||
|
||||
impl Display for AddressOrUid {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
|
||||
match self {
|
||||
AddressOrUid::AddressWithUid(addr, uid, _) => {
|
||||
write!(f, "Address: {}, UID: {}", addr, uid)
|
||||
}
|
||||
AddressOrUid::Address(host) => write!(f, "Address: {}", host),
|
||||
AddressOrUid::Uid(host, _) => write!(f, "UID: {}", host),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AddressOrUid {
|
||||
// Created by translating the config fields directly
|
||||
pub(crate) fn new(
|
||||
address: &Option<String>,
|
||||
uid: &Option<String>,
|
||||
method: &DiscoveryMethods,
|
||||
) -> Result<Self, Error> {
|
||||
match (address, uid) {
|
||||
(None, None) => Err(anyhow!("Neither address or uid given")),
|
||||
(Some(host), Some(uid)) => Ok(AddressOrUid::AddressWithUid(
|
||||
host.clone(),
|
||||
uid.clone(),
|
||||
*method,
|
||||
)),
|
||||
(Some(host), None) => Ok(AddressOrUid::Address(host.clone())),
|
||||
(None, Some(host)) => Ok(AddressOrUid::Uid(host.clone(), *method)),
|
||||
}
|
||||
}
|
||||
|
||||
// Convience method to get the BcCamera with the appropiate method
|
||||
// from a camera_config
|
||||
pub(crate) async fn connect_camera(
|
||||
&self,
|
||||
camera_config: &CameraConfig,
|
||||
) -> Result<BcCamera, Error> {
|
||||
let (port, addrs) = {
|
||||
if let Some(addr_str) = camera_config.camera_addr.as_ref() {
|
||||
match addr_str.to_socket_addrs() {
|
||||
Ok(addr_iter) => {
|
||||
let mut port = None;
|
||||
let mut ipaddrs = vec![];
|
||||
for addr in addr_iter {
|
||||
port = Some(addr.port());
|
||||
ipaddrs.push(addr.ip());
|
||||
}
|
||||
Ok((port, ipaddrs))
|
||||
}
|
||||
Err(_) => match IpAddr::from_str(addr_str) {
|
||||
Ok(ip) => Ok((None, vec![ip])),
|
||||
Err(_) => Err(anyhow!("Could not parse address in config")),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Ok((None, vec![]))
|
||||
}
|
||||
}?;
|
||||
|
||||
let options = BcCameraOpt {
|
||||
name: camera_config.name.clone(),
|
||||
channel_id: camera_config.channel_id,
|
||||
addrs,
|
||||
port,
|
||||
uid: camera_config.camera_uid.clone(),
|
||||
protocol: ConnectionProtocol::TcpUdp,
|
||||
discovery: camera_config.discovery,
|
||||
aux_printing: camera_config.print_format,
|
||||
credentials: Credentials {
|
||||
username: camera_config.username.clone(),
|
||||
password: camera_config.password.clone(),
|
||||
},
|
||||
};
|
||||
|
||||
trace!("Camera Info: {:?}", options);
|
||||
|
||||
Ok(BcCamera::new(&options).await?)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn find_and_connect(config: &Config, name: &str) -> Result<BcCamera> {
|
||||
let camera_config = find_camera_by_name(config, name)?;
|
||||
connect_and_login(camera_config).await
|
||||
}
|
||||
|
||||
pub(crate) async fn connect_and_login(camera_config: &CameraConfig) -> Result<BcCamera> {
|
||||
let camera_addr = AddressOrUid::new(
|
||||
&camera_config.camera_addr,
|
||||
&camera_config.camera_uid,
|
||||
&camera_config.discovery,
|
||||
)
|
||||
.unwrap();
|
||||
info!(
|
||||
"{}: Connecting to camera at {}",
|
||||
camera_config.name, camera_addr
|
||||
);
|
||||
|
||||
let camera = camera_addr
|
||||
.connect_camera(camera_config)
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to connect to camera {} at {} on channel {}",
|
||||
camera_config.name, camera_addr, camera_config.channel_id
|
||||
)
|
||||
})?;
|
||||
|
||||
let max_encryption = match camera_config.max_encryption.to_lowercase().as_str() {
|
||||
"none" => MaxEncryption::None,
|
||||
"bcencrypt" => MaxEncryption::BcEncrypt,
|
||||
"aes" => MaxEncryption::Aes,
|
||||
_ => MaxEncryption::Aes,
|
||||
};
|
||||
info!("{}: Logging in", camera_config.name);
|
||||
camera
|
||||
.login_with_maxenc(max_encryption)
|
||||
.await
|
||||
.with_context(|| format!("Failed to login to {}", camera_config.name))?;
|
||||
|
||||
info!("{}: Connected and logged in", camera_config.name);
|
||||
|
||||
Ok(camera)
|
||||
}
|
||||
|
||||
pub(crate) fn find_camera_by_name<'a>(config: &'a Config, name: &str) -> Result<&'a CameraConfig> {
|
||||
config
|
||||
.cameras
|
||||
.iter()
|
||||
.find(|c| c.name == name)
|
||||
.ok_or_else(|| anyhow!("Camera {} not found in the config file", name))
|
||||
}
|
||||
@@ -146,11 +146,14 @@ local message_types = {
|
||||
[106]="<Dst>",
|
||||
[107]="<Dst> (write)",
|
||||
[108]="<ConfigFileInfo> (log)",
|
||||
[109]="<Snap>",
|
||||
[114]="<Uid>",
|
||||
[115]="<WifiSignal>",
|
||||
[116]="<Wifi>",
|
||||
[120]="<OnlineUserList>",
|
||||
[122]="<PerformanceInfo>",
|
||||
[123]="<ReplaySeek>",
|
||||
[124]="<PushInfo>",
|
||||
[132]="<VideoInput>", -- <InputAdvanceCfg>
|
||||
[133]="<RfAlarm>",
|
||||
[141]="<Email> (test)",
|
||||
@@ -160,6 +163,7 @@ local message_types = {
|
||||
[151]="<AbilityInfo>",
|
||||
[190]="PTZ Preset",
|
||||
[194]="<Ftp> (test)",
|
||||
[195]="<AutoUpdate>",
|
||||
[199]="<Support>",
|
||||
[208]="<LedState>",
|
||||
[209]="<LedState> (write)",
|
||||
@@ -174,9 +178,13 @@ local message_types = {
|
||||
[228]="<Crop>",
|
||||
[229]="<Crop> (write)",
|
||||
[230]="<cropSnap>",
|
||||
[232]="<AudioTask>",
|
||||
[234]="UDP Keep Alive",
|
||||
[252]="<BatteryInfoList>",
|
||||
[253]="<BatteryInfo>",
|
||||
[268]="<CloudBindInfo>",
|
||||
[282]="<CloudLoginKey>",
|
||||
[287]="<TimeCfg>",
|
||||
[272]="<findAlarmVideo>",
|
||||
[273]="<alarmVideoInfo>",
|
||||
[274]="<findAlarmVideo>",
|
||||
|
||||
@@ -1662,6 +1662,64 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 109: `<Snap>`
|
||||
|
||||
- Client:
|
||||
Usual header
|
||||
|
||||
- Meta:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<channelId>0</channelId>
|
||||
</Extension>
|
||||
```
|
||||
|
||||
- Main:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<Snap version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<logicChannel>0</logicChannel>
|
||||
<time>0</time>
|
||||
<fullFrame>0</fullFrame>
|
||||
<streamType>main</streamType>
|
||||
</Snap>
|
||||
</body>
|
||||
```
|
||||
|
||||
- Camera:
|
||||
|
||||
**Notes:** XML & Binary reply over mutliple packets:
|
||||
- Reply 1:
|
||||
- Main:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<Snap version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<fileName>01_20230518140240.jpg</fileName>
|
||||
<time>0</time>
|
||||
<pictureSize>23644</pictureSize>
|
||||
</Snap>
|
||||
</body>
|
||||
```
|
||||
|
||||
- Reply 2:
|
||||
- Meta:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<binaryData>1</binaryData>
|
||||
</Extension>
|
||||
```
|
||||
- Main:
|
||||
**Binary data containing the file may be broken over multiple packets**
|
||||
|
||||
|
||||
- 115: `<WifiSignal>`
|
||||
|
||||
- Client
|
||||
@@ -1691,6 +1749,35 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 116: `<Wifi>`
|
||||
|
||||
- Client:
|
||||
Usual header
|
||||
|
||||
- Camera:
|
||||
Payload:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<Wifi version="1.1">
|
||||
<mode>station</mode>
|
||||
<authMode>wpa2psk</authMode>
|
||||
<encryptType>aes</encryptType>
|
||||
<udidList>
|
||||
<udid>
|
||||
<name>WIFINAME</name>
|
||||
<signal>NUMBER</signal>
|
||||
<encrypt>ONE_OR_ZERO</encrypt>
|
||||
</udid>
|
||||
# Repeats for ALL wifi in range
|
||||
</udidList>
|
||||
<ssid>YOUR_CURRENT_WIFI</ssid>
|
||||
<key>YOUR_CURRENT_WIFI_PASSWORD_UNENCRYPTED</key>
|
||||
<channel>YOUR_CURRENT_WIFI_CHANNEL</channel>
|
||||
</Wifi>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 132: `<VideoInput>`
|
||||
|
||||
- Client
|
||||
@@ -1803,6 +1890,37 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 124: `<PushInfo>`
|
||||
|
||||
- Client
|
||||
- Payload:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<PushInfo version="1.1">
|
||||
<token>A_PUSH_NOTIFICATION_TOKEN</token>
|
||||
<phoneType>reo_iphone</phoneType>
|
||||
<clientID>A_PUSH_NOTIFICATION_CLIENTID</clientID>
|
||||
</PushInfo>
|
||||
</body>
|
||||
```
|
||||
|
||||
- Camera
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<PushRspInfo version="1.1">
|
||||
<registerHandle>-1</registerHandle>
|
||||
<uid>CAMERA_UID</uid>
|
||||
<uidKey>A_4_CHAR_STRING</uidKey>
|
||||
</PushRspInfo>
|
||||
</body>
|
||||
```
|
||||
|
||||
|
||||
- 133: `<RfAlarm>`
|
||||
|
||||
- Client
|
||||
@@ -2338,6 +2456,154 @@ Message have zero to two payloads.
|
||||
|--------------|--------------|----------------|-------------------|-------------------|---------------|---------------|
|
||||
| 0a bc de f0 | 00 00 00 d1 | 00 00 00 00 | 85 00 00 00 | c8 00 | 00 00 | 00 00 00 00 |
|
||||
|
||||
- 219: `<PushTask>`
|
||||
- Client
|
||||
Usual header
|
||||
|
||||
- Meta:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<channelId>0</channelId>
|
||||
</Extension>
|
||||
```
|
||||
- Camera
|
||||
Usual header
|
||||
|
||||
- Payload:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<PushTask version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<enable>1</enable>
|
||||
<ScheduleList>
|
||||
<Schedule>
|
||||
<alarmType>MD</alarmType>
|
||||
<timeBlockList>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Sunday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Monday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Tuesday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Wednesday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Thursday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Friday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Saturday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
</timeBlockList>
|
||||
</Schedule>
|
||||
</ScheduleList>
|
||||
</PushTask>
|
||||
</body>
|
||||
```
|
||||
|
||||
|
||||
- 232: `<AudioTask>`
|
||||
- Client
|
||||
Usual header
|
||||
|
||||
- Meta:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<channelId>0</channelId>
|
||||
</Extension>
|
||||
```
|
||||
- Camera
|
||||
Usual header
|
||||
|
||||
- Payload:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<AudioTask version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<enable>0</enable>
|
||||
<ScheduleList>
|
||||
<Schedule>
|
||||
<alarmType>MD</alarmType>
|
||||
<timeBlockList>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Sunday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Monday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Tuesday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Wednesday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Thursday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Friday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
<timeBlock>
|
||||
<enable>1</enable>
|
||||
<weekDay>Saturday</weekDay>
|
||||
<beginHour>0</beginHour>
|
||||
<endHour>23</endHour>
|
||||
</timeBlock>
|
||||
</timeBlockList>
|
||||
</Schedule>
|
||||
</ScheduleList>
|
||||
</AudioTask>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 264: `<audioCfg>` (write)
|
||||
|
||||
@@ -2373,6 +2639,55 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 268: `CloudBindInfo`
|
||||
- Client:
|
||||
Usual header only packet
|
||||
|
||||
- Camera
|
||||
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<CloudBindInfo version="1.1">
|
||||
<binded>1</binded>
|
||||
</CloudBindInfo>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 282: `CloudLoginKey`
|
||||
|
||||
- Client:
|
||||
Usual header only packet
|
||||
|
||||
- Camera
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<body>
|
||||
<CloudLoginKey version="1.1">
|
||||
<enable>0</enable>
|
||||
</CloudLoginKey>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 287: `<TimeCfg>`
|
||||
- Client:
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<TimeCfg version="1.1">
|
||||
<realTime>1684393362</realTime>
|
||||
</TimeCfg>
|
||||
</body>
|
||||
```
|
||||
|
||||
- Camera
|
||||
Header only 200 Ok reply
|
||||
|
||||
- 288: `<FloodlightManual>` (write)
|
||||
|
||||
- Client
|
||||
|
||||
@@ -75,6 +75,22 @@ address = "192.168.1.187:9000"
|
||||
#
|
||||
# print_format = "None"
|
||||
|
||||
# Internally neolink uses a buffer to improve delivery of frames at their actual times
|
||||
# A large buffer can work even for large interupts in the connection with the camera
|
||||
# A small buffer will reduce the latency introduced
|
||||
# buffer_size: 100
|
||||
|
||||
# Over long periods of time the camera buffer can exhaust with no means of recovery
|
||||
# to combat this a time stretching stratery is employed where the stream is slowed
|
||||
# as the buffer is exhausted and sped up when full
|
||||
# this can keep the camera and rtsp streams in sync and reduce buffer exhaustions
|
||||
#
|
||||
# HOWEVER if there is real latency issues (such as too high a bitrate)
|
||||
# then smoothing can result in a stream appearing in slow motion
|
||||
#
|
||||
# you can disable and enable this feature here
|
||||
# use_smoothing: true
|
||||
|
||||
|
||||
[[cameras]]
|
||||
name = "storage shed"
|
||||
|
||||
@@ -102,6 +102,22 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[serde(default = "default_update_time", alias = "time")]
|
||||
pub(crate) update_time: bool,
|
||||
|
||||
#[validate(range(
|
||||
min = 10,
|
||||
max = 500,
|
||||
message = "Invalid buffer size",
|
||||
code = "buffer_size"
|
||||
))]
|
||||
#[serde(default = "default_buffer_size", alias = "size", alias = "buffer")]
|
||||
pub(crate) buffer_size: usize,
|
||||
|
||||
#[serde(
|
||||
default = "default_smoothing",
|
||||
alias = "smoothing",
|
||||
alias = "stretching"
|
||||
)]
|
||||
pub(crate) use_smoothing: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
@@ -239,6 +255,14 @@ fn default_pause() -> PauseConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_smoothing() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_buffer_size() -> usize {
|
||||
100
|
||||
}
|
||||
|
||||
pub(crate) static RESERVED_NAMES: &[&str] = &["anyone", "anonymous"];
|
||||
fn validate_username(name: &str) -> Result<(), ValidationError> {
|
||||
if name.trim().is_empty() {
|
||||
|
||||
+11
-3
@@ -41,14 +41,16 @@ glib::wrapper! {
|
||||
|
||||
impl Default for NeoMediaFactory {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self::new(100, true)
|
||||
}
|
||||
}
|
||||
|
||||
impl NeoMediaFactory {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(buffer_size: usize, use_smoothing: bool) -> Self {
|
||||
let factory = Object::new::<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);
|
||||
@@ -120,6 +122,8 @@ pub(crate) enum FactoryCommand {
|
||||
BcMedia(BcMedia),
|
||||
ClearBuffer,
|
||||
JumpToLive,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
pub(crate) struct NeoMediaFactoryImpl {
|
||||
@@ -149,6 +153,7 @@ impl Default for NeoMediaFactoryImpl {
|
||||
shared.clone(),
|
||||
ReceiverStream::new(datarx),
|
||||
ReceiverStream::new(rx_clientsender),
|
||||
100,
|
||||
);
|
||||
threads.spawn(async move {
|
||||
loop {
|
||||
@@ -265,7 +270,10 @@ impl NeoMediaFactoryImpl {
|
||||
bin.remove(&element)?;
|
||||
}
|
||||
|
||||
let mut client_data = NeoMediaSender::new();
|
||||
let mut client_data = NeoMediaSender::new(
|
||||
self.shared.get_buffer_size(),
|
||||
self.shared.get_use_smoothing(),
|
||||
);
|
||||
|
||||
// Now contruct the actual ones
|
||||
match (
|
||||
|
||||
+404
-279
@@ -8,6 +8,8 @@ use futures::{
|
||||
use gstreamer::{prelude::*, ClockTime};
|
||||
use gstreamer_app::AppSrc;
|
||||
pub use gstreamer_rtsp_server::gio::{TlsAuthenticationMode, TlsCertificate};
|
||||
use is_sorted::IsSorted;
|
||||
use itertools::Itertools;
|
||||
use log::*;
|
||||
use neolink_core::bcmedia::model::*;
|
||||
use std::{
|
||||
@@ -29,48 +31,94 @@ use crate::rtsp::Spring;
|
||||
|
||||
type FrameTime = i64;
|
||||
|
||||
const BUFFER_SIZE: usize = 300;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Stamped {
|
||||
time: FrameTime,
|
||||
data: Arc<BcMedia>,
|
||||
data: Vec<Arc<BcMedia>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Debug)]
|
||||
struct NeoBuffer {
|
||||
buf: VecDeque<Stamped>,
|
||||
max_size: usize,
|
||||
}
|
||||
|
||||
impl NeoBuffer {
|
||||
fn push(&mut self, item: Stamped) {
|
||||
// Sort time
|
||||
// debug!("sorting");
|
||||
let mut sorting_vec = vec![];
|
||||
let time = item.time;
|
||||
while self
|
||||
.buf
|
||||
.back()
|
||||
.map(|back| back.time > time)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
sorting_vec.push(self.buf.pop_back().unwrap());
|
||||
fn new(max_size: usize) -> Self {
|
||||
Self {
|
||||
buf: Default::default(),
|
||||
max_size,
|
||||
}
|
||||
sorting_vec.push(item);
|
||||
}
|
||||
|
||||
for sorted_item in sorting_vec.drain(..) {
|
||||
// debug!("Pushing frame with time: {}", sorted_item.time);
|
||||
self.buf.push_back(sorted_item);
|
||||
fn push(&mut self, media: Arc<BcMedia>) {
|
||||
let frame_time = match media.as_ref() {
|
||||
BcMedia::Iframe(data) => Some(data.microseconds as FrameTime),
|
||||
BcMedia::Pframe(data) => Some(data.microseconds as FrameTime),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(frame_time) = frame_time {
|
||||
let mut sorting_vec = vec![];
|
||||
let time = frame_time;
|
||||
while self
|
||||
.buf
|
||||
.back()
|
||||
.map(|back| back.time >= time)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
sorting_vec.push(self.buf.pop_back().unwrap());
|
||||
}
|
||||
if sorting_vec
|
||||
.last()
|
||||
.map(|last| last.time == frame_time)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
sorting_vec.last_mut().unwrap().data.push(media);
|
||||
} else {
|
||||
sorting_vec.push(Stamped {
|
||||
time,
|
||||
data: vec![media],
|
||||
});
|
||||
}
|
||||
|
||||
while let Some(sorted_item) = sorting_vec.pop() {
|
||||
trace!("Pushing frame with time: {}", sorted_item.time);
|
||||
self.buf.push_back(sorted_item);
|
||||
}
|
||||
|
||||
debug_assert!(
|
||||
IsSorted::is_sorted(&mut self.buf.iter().map(|stamped| stamped.time)),
|
||||
"{:?}",
|
||||
self.buf
|
||||
.iter()
|
||||
.map(|stamped| stamped.time)
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
} else if let Some(last) = self.buf.back_mut() {
|
||||
last.data.push(media);
|
||||
}
|
||||
while self.buf.len() > BUFFER_SIZE {
|
||||
|
||||
while self.buf.len() > self.max_size {
|
||||
if self.buf.pop_front().is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prep_size(&self) -> usize {
|
||||
self.max_size * 2 / 3
|
||||
}
|
||||
|
||||
fn live_size(&self) -> usize {
|
||||
self.max_size / 3
|
||||
}
|
||||
|
||||
pub(crate) fn ready(&self) -> bool {
|
||||
self.buf.len() > BUFFER_SIZE * 2 / 3
|
||||
self.buf.len() > self.prep_size()
|
||||
}
|
||||
|
||||
pub(crate) fn ready_play(&self) -> bool {
|
||||
self.buf.len() > self.live_size()
|
||||
}
|
||||
|
||||
// fn last_iframe_time(&self) -> Option<FrameTime> {
|
||||
@@ -100,14 +148,14 @@ impl NeoBuffer {
|
||||
// .map(|i| i as FrameTime)
|
||||
// }
|
||||
|
||||
fn start_time(&self) -> Option<FrameTime> {
|
||||
let (fronts, backs) = self.buf.as_slices();
|
||||
fronts
|
||||
.iter()
|
||||
.chain(&mut backs.iter())
|
||||
.map(|frame| frame.time)
|
||||
.next()
|
||||
}
|
||||
// fn start_time(&self) -> Option<FrameTime> {
|
||||
// let (fronts, backs) = self.buf.as_slices();
|
||||
// fronts
|
||||
// .iter()
|
||||
// .chain(&mut backs.iter())
|
||||
// .map(|frame| frame.time)
|
||||
// .next()
|
||||
// }
|
||||
|
||||
fn end_time(&self) -> Option<FrameTime> {
|
||||
let (fronts, backs) = self.buf.as_slices();
|
||||
@@ -163,6 +211,7 @@ impl NeoMediaSenders {
|
||||
shared: Arc<NeoMediaShared>,
|
||||
data_source: ReceiverStream<FactoryCommand>,
|
||||
client_source: ReceiverStream<NeoMediaSender>,
|
||||
buffer_size: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
data_source,
|
||||
@@ -170,7 +219,7 @@ impl NeoMediaSenders {
|
||||
shared,
|
||||
uid: Default::default(),
|
||||
client_data: Default::default(),
|
||||
buffer: Default::default(),
|
||||
buffer: NeoBuffer::new(buffer_size),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +286,7 @@ impl NeoMediaSenders {
|
||||
}
|
||||
|
||||
async fn handle_new_data(&mut self, data: BcMedia) -> AnyResult<()> {
|
||||
// debug!("Handle new data");
|
||||
// trace!("Handle new data");
|
||||
self.update_mediatypes(&data).await;
|
||||
let time = match &data {
|
||||
BcMedia::Iframe(BcMediaIframe { microseconds, .. }) => *microseconds as FrameTime,
|
||||
@@ -245,39 +294,49 @@ impl NeoMediaSenders {
|
||||
_ => self.buffer.end_time().unwrap_or(0),
|
||||
};
|
||||
|
||||
let data = Stamped {
|
||||
time,
|
||||
data: Arc::new(data),
|
||||
};
|
||||
for client_data in self.client_data.values_mut() {
|
||||
client_data.add_data(data.clone()).await?;
|
||||
}
|
||||
let data = Arc::new(data);
|
||||
|
||||
let end_time = self.buffer.end_time();
|
||||
let frame_time = data.time;
|
||||
let frame_time = time;
|
||||
// Ocassionally the camera will make a jump in timestamps of about 15s (on sub 9s on main)
|
||||
// This could mean that it runs on some fixed sized buffer
|
||||
if let Some(end_time) = end_time {
|
||||
let delta_time = frame_time - end_time - -1;
|
||||
let delta_frame = (self.buffer.buf.back().unwrap().time
|
||||
- self.buffer.buf.front().unwrap().time)
|
||||
/ self.buffer.buf.len() as i64;
|
||||
let delta_time = frame_time - end_time - delta_frame;
|
||||
let delta_duration = Duration::from_micros(delta_time.unsigned_abs());
|
||||
if delta_duration > Duration::from_secs(1) {
|
||||
debug!(
|
||||
trace!(
|
||||
"Reschedule buffer due to jump: {:?}, Prev: {}, New: {}",
|
||||
delta_duration, end_time, frame_time
|
||||
delta_duration,
|
||||
end_time,
|
||||
frame_time
|
||||
);
|
||||
debug!("Adjusting master: {}", self.buffer.buf.len());
|
||||
trace!("Adjusting master: {}", self.buffer.buf.len());
|
||||
for frame in self.buffer.buf.iter_mut() {
|
||||
let old_frame_time = frame.time;
|
||||
frame.time = frame.time.saturating_add(delta_time);
|
||||
debug!(" - New frame time: {} -> {}", frame.time, frame_time);
|
||||
trace!(
|
||||
" - New frame time: {} -> {} (target {})",
|
||||
old_frame_time,
|
||||
frame.time,
|
||||
frame_time
|
||||
);
|
||||
}
|
||||
|
||||
for (_, client) in self.client_data.iter_mut() {
|
||||
client.buffer.buf.clear();
|
||||
client.inited = false;
|
||||
for frame in client.buffer.buf.iter_mut() {
|
||||
frame.time = frame.time.saturating_add(delta_time);
|
||||
}
|
||||
client.start_time.mod_value(delta_time as f64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for client_data in self.client_data.values_mut() {
|
||||
client_data.add_data(data.clone()).await?;
|
||||
}
|
||||
self.buffer.push(data);
|
||||
|
||||
self.shared
|
||||
@@ -296,7 +355,7 @@ impl NeoMediaSenders {
|
||||
.initialise(buffer)
|
||||
.map_ok(|_| None)
|
||||
.unwrap_or_else(move |e| {
|
||||
debug!("Could not init client: {:?}", e);
|
||||
trace!("Could not init client: {:?}", e);
|
||||
Some(key)
|
||||
})
|
||||
})
|
||||
@@ -319,7 +378,7 @@ impl NeoMediaSenders {
|
||||
.process_commands(buffer)
|
||||
.map_ok(|_| None)
|
||||
.unwrap_or_else(move |e| {
|
||||
debug!("Could not process client command: {:?}", e);
|
||||
trace!("Could not process client command: {:?}", e);
|
||||
Some(key)
|
||||
})
|
||||
})
|
||||
@@ -339,7 +398,7 @@ impl NeoMediaSenders {
|
||||
.iter_mut()
|
||||
.map(|(&key, client)| {
|
||||
client.update().map_ok(|_| None).unwrap_or_else(move |e| {
|
||||
debug!("Could not update client: {:?}", e);
|
||||
trace!("Could not update client: {:?}", e);
|
||||
Some(key)
|
||||
})
|
||||
})
|
||||
@@ -367,6 +426,7 @@ impl NeoMediaSenders {
|
||||
}
|
||||
|
||||
async fn update(&mut self) -> AnyResult<()> {
|
||||
self.buffer.max_size = self.shared.get_buffer_size();
|
||||
self.init_clients().await?;
|
||||
self.process_client_commands().await?;
|
||||
self.process_client_update().await?;
|
||||
@@ -389,6 +449,15 @@ impl NeoMediaSenders {
|
||||
Some(v) = self.data_source.next() => {
|
||||
match v {
|
||||
FactoryCommand::BcMedia(media) => {
|
||||
let frame_time = match &media {
|
||||
BcMedia::Iframe(data) => Some(Duration::from_micros(data.microseconds as u64)),
|
||||
BcMedia::Pframe(data) => Some(Duration::from_micros(data.microseconds as u64)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(frame_time) = frame_time {
|
||||
trace!("Got frame at {:?}", frame_time);
|
||||
}
|
||||
|
||||
self.handle_new_data(media).await?;
|
||||
},
|
||||
FactoryCommand::ClearBuffer => {
|
||||
@@ -399,7 +468,18 @@ impl NeoMediaSenders {
|
||||
// Set them into the non init state
|
||||
// This will make them wait for the
|
||||
// buffer to be enough then jump to live
|
||||
client.inited = false;
|
||||
let _ = client.jump_to_live().await;
|
||||
}
|
||||
},
|
||||
FactoryCommand::Pause => {
|
||||
for client in self.client_data.values_mut() {
|
||||
client.playing = false;
|
||||
}
|
||||
},
|
||||
FactoryCommand::Resume => {
|
||||
for client in self.client_data.values_mut() {
|
||||
client.playing = true;
|
||||
let _ = client.jump_to_live().await;
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -432,25 +512,29 @@ pub(super) struct NeoMediaSender {
|
||||
command_sender: Sender<NeoMediaSenderCommand>,
|
||||
inited: bool,
|
||||
playing: bool,
|
||||
refilling: bool,
|
||||
use_smoothing: bool,
|
||||
}
|
||||
|
||||
impl NeoMediaSender {
|
||||
pub(super) fn new() -> Self {
|
||||
pub(super) fn new(buffer_size: usize, use_smoothing: bool) -> Self {
|
||||
let (tx, rx) = channel(30);
|
||||
Self {
|
||||
start_time: Spring::new(0.0, 0.0, 10.0),
|
||||
live_offset: 0,
|
||||
buffer: NeoBuffer::default(),
|
||||
buffer: NeoBuffer::new(buffer_size),
|
||||
vid: None,
|
||||
aud: None,
|
||||
command_reciever: rx,
|
||||
command_sender: tx,
|
||||
inited: false,
|
||||
playing: true,
|
||||
refilling: false,
|
||||
use_smoothing,
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_data(&mut self, data: Stamped) -> AnyResult<()> {
|
||||
async fn add_data(&mut self, data: Arc<BcMedia>) -> AnyResult<()> {
|
||||
self.buffer.push(data);
|
||||
Ok(())
|
||||
}
|
||||
@@ -467,41 +551,71 @@ impl NeoMediaSender {
|
||||
self.command_sender.clone()
|
||||
}
|
||||
|
||||
fn target_live(&self) -> Option<FrameTime> {
|
||||
let target_idx = BUFFER_SIZE / 3;
|
||||
if self.buffer.buf.len() >= target_idx {
|
||||
let target_frame = self.buffer.buf.len().saturating_sub(target_idx);
|
||||
self.buffer.buf.get(target_frame).map(|frame| frame.time)
|
||||
} else {
|
||||
fn target_live_for(buffer: &NeoBuffer) -> Option<FrameTime> {
|
||||
let target_idx = buffer.live_size();
|
||||
let stamps = buffer.buf.iter().map(|item| item.time).collect::<Vec<_>>();
|
||||
|
||||
if stamps.len() >= target_idx {
|
||||
let target_frame = stamps.len().saturating_sub(target_idx);
|
||||
stamps.get(target_frame).copied()
|
||||
} else if stamps.len() > 5 {
|
||||
// Approximate it's location
|
||||
let fraction = target_idx as f64 / self.buffer.buf.len() as f64;
|
||||
if let (Some(st), Some(et)) = (self.buffer.start_time(), self.buffer.end_time()) {
|
||||
let fraction = target_idx as f64 / stamps.len() as f64;
|
||||
if let (Some(st), Some(et)) = (stamps.first(), stamps.last()) {
|
||||
Some(et - ((et - st) as f64 * fraction) as FrameTime)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
trace!("Not enough timestamps for target live: {:?}", stamps);
|
||||
if let Some(st) = stamps.first() {
|
||||
trace!("Setting to 1s behind first frame in buffer");
|
||||
Some(st - Duration::from_secs(1).as_micros() as FrameTime)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn target_live(&self) -> Option<FrameTime> {
|
||||
Self::target_live_for(&self.buffer)
|
||||
}
|
||||
|
||||
async fn jump_to_live(&mut self) -> AnyResult<()> {
|
||||
if self.inited {
|
||||
let target_time = self.target_live();
|
||||
let target_time = self.target_live();
|
||||
|
||||
if let Some(target_time) = target_time {
|
||||
if let Some(et) = self.buffer.end_time() {
|
||||
debug!(
|
||||
"Minimum Latency: {:?}",
|
||||
Duration::from_micros(et.saturating_sub(target_time).max(0) as u64)
|
||||
);
|
||||
}
|
||||
let runtime = self.get_runtime().unwrap_or(0);
|
||||
|
||||
self.start_time.reset_to((target_time - runtime) as f64);
|
||||
if let Some(target_time) = target_time {
|
||||
if let Some(et) = self.buffer.end_time() {
|
||||
trace!(
|
||||
"Buffer stamps: {:?}",
|
||||
self.buffer
|
||||
.buf
|
||||
.iter()
|
||||
.fold(Vec::<FrameTime>::new(), |mut acc, item| {
|
||||
if let Some(last) = acc.last() {
|
||||
if *last < item.time {
|
||||
acc.push(item.time);
|
||||
}
|
||||
} else {
|
||||
acc.push(item.time);
|
||||
}
|
||||
acc
|
||||
})
|
||||
);
|
||||
debug!(
|
||||
"Jumped to live: New start time: {:?}",
|
||||
Duration::from_micros(self.start_time.value_u64()),
|
||||
"Minimum Latency: {:?} ({:?} - {:?})",
|
||||
Duration::from_micros(et.saturating_sub(target_time).max(0) as u64),
|
||||
Duration::from_micros(et.max(0) as u64),
|
||||
Duration::from_micros(target_time.max(0) as u64),
|
||||
);
|
||||
}
|
||||
let runtime = self.get_runtime().unwrap_or(0);
|
||||
|
||||
self.start_time.reset_to((target_time - runtime) as f64);
|
||||
trace!(
|
||||
"Jumped to live: New start time: {:?}",
|
||||
Duration::from_micros(self.start_time.value_u64()),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -510,8 +624,10 @@ impl NeoMediaSender {
|
||||
async fn update_starttime(&mut self) -> AnyResult<()> {
|
||||
self.start_time.update().await;
|
||||
|
||||
if let (Some(runtime), Some(target_time)) = (self.get_runtime(), self.target_live()) {
|
||||
self.start_time.set_target((target_time - runtime) as f64);
|
||||
if self.use_smoothing {
|
||||
if let (Some(runtime), Some(target_time)) = (self.get_runtime(), self.target_live()) {
|
||||
self.start_time.set_target((target_time - runtime) as f64);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -519,24 +635,9 @@ impl NeoMediaSender {
|
||||
async fn seek(
|
||||
&mut self,
|
||||
_original_runtime: Option<FrameTime>,
|
||||
target_runtime: FrameTime,
|
||||
master_buffer: &NeoBuffer,
|
||||
_target_runtime: FrameTime,
|
||||
_master_buffer: &NeoBuffer,
|
||||
) -> AnyResult<()> {
|
||||
if let Some(current_runtime) = self.get_runtime() {
|
||||
self.live_offset = self
|
||||
.live_offset
|
||||
.saturating_add(target_runtime.saturating_sub(current_runtime));
|
||||
trace!("Old runtime: {}", current_runtime);
|
||||
trace!("Target runtime: {}", target_runtime);
|
||||
trace!("Offset: {}", self.live_offset);
|
||||
trace!("New runtime: {:?}", self.get_runtime());
|
||||
if let Some(new_buftime) = self.get_buftime() {
|
||||
self.buffer.buf.clear();
|
||||
for frame in master_buffer.buf.iter().filter(|f| f.time >= new_buftime) {
|
||||
self.buffer.buf.push_back(frame.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.jump_to_live().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -570,30 +671,31 @@ impl NeoMediaSender {
|
||||
|
||||
async fn initialise(&mut self, buffer: &NeoBuffer) -> AnyResult<()> {
|
||||
if !self.inited && buffer.ready() {
|
||||
// Minimum buffer
|
||||
self.inited = true;
|
||||
if let Some(target_time) = Self::target_live_for(buffer) {
|
||||
// Minimum buffer
|
||||
self.inited = true;
|
||||
self.buffer.buf.clear();
|
||||
|
||||
// Split buffer into 2/3 of preprocess
|
||||
// and one third for the future buffer
|
||||
let split_idx = buffer.buf.len() * 2 / 3;
|
||||
let rebuf = buffer.buf.iter().cloned().collect::<Vec<_>>();
|
||||
let (preprocess, buffer) = rebuf.split_at(split_idx);
|
||||
let start_ms = buffer
|
||||
.first()
|
||||
.map(|data| data.time as f64)
|
||||
.expect("Buffer should have a start time");
|
||||
self.start_time.reset_to(start_ms);
|
||||
let mut buffer_iter = buffer.buf.iter().cloned();
|
||||
let preprocess = buffer_iter
|
||||
.take_while_ref(|item| item.time < target_time)
|
||||
.collect::<Vec<_>>();
|
||||
let mut buffer = buffer_iter.collect::<Vec<_>>();
|
||||
self.start_time.reset_to(target_time as f64);
|
||||
|
||||
// Send preprocess now
|
||||
self.send_buffers(preprocess).await?;
|
||||
debug!("Preprocessed");
|
||||
// Send these later
|
||||
for frame in buffer.iter() {
|
||||
self.buffer.push(frame.clone());
|
||||
// Send preprocess now
|
||||
self.send_buffers(preprocess.as_slice()).await?;
|
||||
trace!("Preprocessed");
|
||||
// Send these later
|
||||
for frame in buffer.drain(..) {
|
||||
self.buffer.buf.push_back(frame);
|
||||
}
|
||||
trace!("Buffer filled");
|
||||
|
||||
self.jump_to_live().await?;
|
||||
} else {
|
||||
debug!("Buffer not ready to init: {}", buffer.buf.len());
|
||||
}
|
||||
debug!("Buffer filled");
|
||||
|
||||
self.jump_to_live().await?;
|
||||
} else if !self.inited {
|
||||
debug!("Buffer not ready to init: {}", buffer.buf.len());
|
||||
}
|
||||
@@ -611,6 +713,10 @@ impl NeoMediaSender {
|
||||
.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,
|
||||
@@ -638,44 +744,68 @@ impl NeoMediaSender {
|
||||
}
|
||||
|
||||
async fn update(&mut self) -> AnyResult<()> {
|
||||
self.update_starttime().await?;
|
||||
let mut buffers = vec![];
|
||||
if !self
|
||||
.vid
|
||||
.as_ref()
|
||||
.map(|x| x.pads().iter().all(|pad| pad.is_linked()))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(anyhow!("Vid src is closed"));
|
||||
if self.buffer.buf.len() >= self.buffer.max_size * 9 / 10 {
|
||||
debug!("Buffer overfull");
|
||||
self.jump_to_live().await?;
|
||||
}
|
||||
if self.buffer.buf.len() < 4 {
|
||||
error!("Buffer exhausted. Not enough data from Camera.");
|
||||
} else {
|
||||
trace!("Buffer size: {}", self.buffer.buf.len());
|
||||
}
|
||||
const LATENCY: FrameTime = Duration::from_millis(250).as_micros() as FrameTime;
|
||||
if let Some(buftime) = self.get_buftime().map(|i| i.saturating_add(LATENCY)) {
|
||||
// debug!("Update: buftime: {}", buftime);
|
||||
while self
|
||||
.buffer
|
||||
.buf
|
||||
.front()
|
||||
.map(|data| data.time <= buftime)
|
||||
if self.refilling && self.buffer.ready_play() {
|
||||
self.refilling = false;
|
||||
self.jump_to_live().await?;
|
||||
} else if self.refilling {
|
||||
trace!(
|
||||
"Refilling: {}/{} ({:.2}%)",
|
||||
self.buffer.buf.len(),
|
||||
self.buffer.live_size(),
|
||||
self.buffer.buf.len() as f32 / (self.buffer.live_size()) as f32 * 100.0
|
||||
);
|
||||
} else if !self.refilling && self.inited && self.playing {
|
||||
self.update_starttime().await?;
|
||||
// Check app src is live
|
||||
if !self
|
||||
.vid
|
||||
.as_ref()
|
||||
.map(|x| x.pads().iter().all(|pad| pad.is_linked()))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
match self.buffer.buf.pop_front() {
|
||||
Some(frame) => {
|
||||
buffers.push(frame);
|
||||
return Err(anyhow!("Vid src is closed"));
|
||||
}
|
||||
|
||||
// Check if buffers are ok
|
||||
if self.buffer.buf.len() <= self.buffer.max_size / 10 {
|
||||
warn!(
|
||||
"Buffer exhausted. Not enough data from Camera. Pausing RTSP until refilled."
|
||||
);
|
||||
info!("Try reducing your Max Bitrate using the offical app");
|
||||
self.refilling = true;
|
||||
} else {
|
||||
trace!("Buffer size: {}", self.buffer.buf.len());
|
||||
}
|
||||
|
||||
// Send buffers
|
||||
let mut buffers = vec![];
|
||||
if let Some(buftime) = self.get_buftime() {
|
||||
// debug!("Update: buftime: {}", buf time);
|
||||
while self
|
||||
.buffer
|
||||
.buf
|
||||
.front()
|
||||
.map(|data| data.time <= buftime)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
match self.buffer.buf.pop_front() {
|
||||
Some(frame) => {
|
||||
buffers.push(frame);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tokio::task::yield_now().await;
|
||||
// collect certain frames
|
||||
self.send_buffers(&buffers).await?;
|
||||
tokio::task::yield_now().await;
|
||||
// collect certain frames
|
||||
self.send_buffers(&buffers).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -684,18 +814,18 @@ impl NeoMediaSender {
|
||||
if medias.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
if self.inited && self.playing {
|
||||
tokio::task::yield_now().await;
|
||||
let mut vid_buffers: Vec<(FrameTime, Vec<u8>)> = vec![];
|
||||
let mut aud_buffers: Vec<(FrameTime, Vec<u8>)> = vec![];
|
||||
for media_sets in medias.iter() {
|
||||
tokio::task::yield_now().await;
|
||||
let mut vid_buffers: Vec<(FrameTime, Vec<u8>)> = vec![];
|
||||
let mut aud_buffers: Vec<(FrameTime, Vec<u8>)> = vec![];
|
||||
for media in medias.iter() {
|
||||
tokio::task::yield_now().await;
|
||||
let buffer = match media.data.as_ref() {
|
||||
for media in media_sets.data.iter() {
|
||||
let buffer = match media.as_ref() {
|
||||
BcMedia::Iframe(_) | BcMedia::Pframe(_) => Some(&mut vid_buffers),
|
||||
BcMedia::Aac(_) | BcMedia::Adpcm(_) => Some(&mut aud_buffers),
|
||||
_ => None,
|
||||
};
|
||||
let data = match media.data.as_ref() {
|
||||
let data = match media.as_ref() {
|
||||
BcMedia::Iframe(data) => Some(&data.data),
|
||||
BcMedia::Pframe(data) => Some(&data.data),
|
||||
BcMedia::Aac(data) => Some(&data.data),
|
||||
@@ -703,7 +833,7 @@ impl NeoMediaSender {
|
||||
_ => None,
|
||||
};
|
||||
if let (Some(data), Some(buffer)) = (data, buffer) {
|
||||
let next_time = media.time;
|
||||
let next_time = media_sets.time;
|
||||
if let Some(last) = buffer.last_mut() {
|
||||
let last_time = last.0;
|
||||
if next_time == last_time {
|
||||
@@ -716,131 +846,126 @@ impl NeoMediaSender {
|
||||
}
|
||||
}
|
||||
}
|
||||
tokio::task::yield_now().await;
|
||||
tokio::try_join!(
|
||||
async {
|
||||
if !vid_buffers.is_empty() {
|
||||
// debug!("Sending video buffers: {}", vid_buffers.len());
|
||||
if let Some(appsrc) = self.vid.clone() {
|
||||
let buffers = {
|
||||
let mut buffers =
|
||||
gstreamer::BufferList::new_sized(vid_buffers.len());
|
||||
{
|
||||
let buffers_ref = buffers.get_mut().unwrap();
|
||||
for (time, buf) in vid_buffers.drain(..) {
|
||||
tokio::task::yield_now().await;
|
||||
let runtime = self.buftime_to_runtime(time);
|
||||
let _actual_runtime = self
|
||||
.get_runtime()
|
||||
.map(|i| Duration::from_micros(i as u64));
|
||||
// debug!(
|
||||
// " - Sending vid frame at time {} ({:?} Expect: {:?})",
|
||||
// time,
|
||||
// Duration::from_micros(runtime as u64),
|
||||
// actual_runtime
|
||||
// );
|
||||
|
||||
let gst_buf = {
|
||||
let mut gst_buf =
|
||||
gstreamer::Buffer::with_size(buf.len()).unwrap();
|
||||
{
|
||||
let gst_buf_mut = gst_buf.get_mut().unwrap();
|
||||
|
||||
let time = ClockTime::from_useconds(
|
||||
runtime.try_into().unwrap(),
|
||||
);
|
||||
gst_buf_mut.set_dts(time);
|
||||
let mut gst_buf_data =
|
||||
gst_buf_mut.map_writable().unwrap();
|
||||
gst_buf_data.copy_from_slice(buf.as_slice());
|
||||
}
|
||||
gst_buf
|
||||
};
|
||||
buffers_ref.add(gst_buf);
|
||||
}
|
||||
}
|
||||
buffers
|
||||
};
|
||||
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
// debug!(" - Pushing buffer: {}", buffers.len());
|
||||
appsrc
|
||||
.push_buffer_list(buffers.copy())
|
||||
.map(|_| ())
|
||||
.map_err(|_| anyhow!("Could not push buffer to appsrc"))
|
||||
})
|
||||
.await;
|
||||
match &res {
|
||||
Err(e) => {
|
||||
debug!("Paniced on send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
debug!("Failed to send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Ok(_)) => {}
|
||||
};
|
||||
res??;
|
||||
}
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
async {
|
||||
if !aud_buffers.is_empty() {
|
||||
if let Some(appsrc) = self.aud.clone() {
|
||||
let buffers = {
|
||||
let mut buffers =
|
||||
gstreamer::BufferList::new_sized(aud_buffers.len());
|
||||
{
|
||||
let buffers_ref = buffers.get_mut().unwrap();
|
||||
for (time, buf) in aud_buffers.drain(..) {
|
||||
tokio::task::yield_now().await;
|
||||
let runtime = self.buftime_to_runtime(time);
|
||||
|
||||
let gst_buf = {
|
||||
let mut gst_buf =
|
||||
gstreamer::Buffer::with_size(buf.len()).unwrap();
|
||||
{
|
||||
let gst_buf_mut = gst_buf.get_mut().unwrap();
|
||||
|
||||
let time = ClockTime::from_useconds(
|
||||
runtime.try_into().unwrap(),
|
||||
);
|
||||
gst_buf_mut.set_dts(time);
|
||||
let mut gst_buf_data =
|
||||
gst_buf_mut.map_writable().unwrap();
|
||||
gst_buf_data.copy_from_slice(buf.as_slice());
|
||||
}
|
||||
gst_buf
|
||||
};
|
||||
buffers_ref.add(gst_buf);
|
||||
}
|
||||
}
|
||||
buffers
|
||||
};
|
||||
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
appsrc
|
||||
.push_buffer_list(buffers.copy())
|
||||
.map(|_| ())
|
||||
.map_err(|_| anyhow!("Could not push buffer to appsrc"))
|
||||
})
|
||||
.await;
|
||||
match &res {
|
||||
Err(e) => {
|
||||
debug!("Paniced on send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
debug!("Failed to send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Ok(_)) => {}
|
||||
};
|
||||
res??;
|
||||
}
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
}
|
||||
)?;
|
||||
}
|
||||
tokio::task::yield_now().await;
|
||||
tokio::try_join!(
|
||||
async {
|
||||
if !vid_buffers.is_empty() {
|
||||
// debug!("Sending video buffers: {}", vid_buffers.len());
|
||||
if let Some(appsrc) = self.vid.clone() {
|
||||
let buffers = {
|
||||
let mut buffers = gstreamer::BufferList::new_sized(vid_buffers.len());
|
||||
{
|
||||
let buffers_ref = buffers.get_mut().unwrap();
|
||||
for (time, buf) in vid_buffers.drain(..) {
|
||||
tokio::task::yield_now().await;
|
||||
let runtime = self.buftime_to_runtime(time);
|
||||
trace!(
|
||||
" - Sending vid frame at time {} ({:?} Expect: {:?})",
|
||||
time,
|
||||
Duration::from_micros(runtime as u64),
|
||||
self.get_runtime().map(|i| Duration::from_micros(i as u64))
|
||||
);
|
||||
|
||||
let gst_buf = {
|
||||
let mut gst_buf =
|
||||
gstreamer::Buffer::with_size(buf.len()).unwrap();
|
||||
{
|
||||
let gst_buf_mut = gst_buf.get_mut().unwrap();
|
||||
|
||||
let time = ClockTime::from_useconds(
|
||||
runtime.try_into().unwrap(),
|
||||
);
|
||||
gst_buf_mut.set_dts(time);
|
||||
let mut gst_buf_data =
|
||||
gst_buf_mut.map_writable().unwrap();
|
||||
gst_buf_data.copy_from_slice(buf.as_slice());
|
||||
}
|
||||
gst_buf
|
||||
};
|
||||
buffers_ref.add(gst_buf);
|
||||
}
|
||||
}
|
||||
buffers
|
||||
};
|
||||
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
// debug!(" - Pushing buffer: {}", buffers.len());
|
||||
appsrc
|
||||
.push_buffer_list(buffers.copy())
|
||||
.map(|_| ())
|
||||
.map_err(|_| anyhow!("Could not push buffer to appsrc"))
|
||||
})
|
||||
.await;
|
||||
match &res {
|
||||
Err(e) => {
|
||||
debug!("Paniced on send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
debug!("Failed to send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Ok(_)) => {}
|
||||
};
|
||||
res??;
|
||||
}
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
async {
|
||||
if !aud_buffers.is_empty() {
|
||||
if let Some(appsrc) = self.aud.clone() {
|
||||
let buffers = {
|
||||
let mut buffers = gstreamer::BufferList::new_sized(aud_buffers.len());
|
||||
{
|
||||
let buffers_ref = buffers.get_mut().unwrap();
|
||||
for (time, buf) in aud_buffers.drain(..) {
|
||||
tokio::task::yield_now().await;
|
||||
let runtime = self.buftime_to_runtime(time);
|
||||
|
||||
let gst_buf = {
|
||||
let mut gst_buf =
|
||||
gstreamer::Buffer::with_size(buf.len()).unwrap();
|
||||
{
|
||||
let gst_buf_mut = gst_buf.get_mut().unwrap();
|
||||
|
||||
let time = ClockTime::from_useconds(
|
||||
runtime.try_into().unwrap(),
|
||||
);
|
||||
gst_buf_mut.set_dts(time);
|
||||
let mut gst_buf_data =
|
||||
gst_buf_mut.map_writable().unwrap();
|
||||
gst_buf_data.copy_from_slice(buf.as_slice());
|
||||
}
|
||||
gst_buf
|
||||
};
|
||||
buffers_ref.add(gst_buf);
|
||||
}
|
||||
}
|
||||
buffers
|
||||
};
|
||||
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
appsrc
|
||||
.push_buffer_list(buffers.copy())
|
||||
.map(|_| ())
|
||||
.map_err(|_| anyhow!("Could not push buffer to appsrc"))
|
||||
})
|
||||
.await;
|
||||
match &res {
|
||||
Err(e) => {
|
||||
debug!("Paniced on send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
debug!("Failed to send buffer list: {:?}", e);
|
||||
}
|
||||
Ok(Ok(_)) => {}
|
||||
};
|
||||
res??;
|
||||
}
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
}
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+32
-4
@@ -52,8 +52,12 @@ impl NeoRtspServer {
|
||||
self.imp().get_sender(tag).await
|
||||
}
|
||||
|
||||
pub(crate) async fn create_stream<U: Into<String>>(&self, tag: U) -> AnyResult<()> {
|
||||
self.imp().create_stream(tag).await
|
||||
pub(crate) async fn create_stream<U: Into<String>>(
|
||||
&self,
|
||||
tag: U,
|
||||
config: &CameraConfig,
|
||||
) -> AnyResult<()> {
|
||||
self.imp().create_stream(tag, config).await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -302,6 +306,26 @@ impl NeoRtspServer {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
|
||||
// Pause on all senders of a tag
|
||||
pub(crate) async fn pause<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::Pause).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
|
||||
// Resume on all senders of a tag
|
||||
pub(crate) async fn resume<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::Resume).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for NeoRtspServer {}
|
||||
@@ -330,12 +354,16 @@ impl ObjectSubclass for NeoRtspServerImpl {
|
||||
}
|
||||
|
||||
impl NeoRtspServerImpl {
|
||||
pub(crate) async fn create_stream<U: Into<String>>(&self, tag: U) -> AnyResult<()> {
|
||||
pub(crate) async fn create_stream<U: Into<String>>(
|
||||
&self,
|
||||
tag: U,
|
||||
config: &CameraConfig,
|
||||
) -> AnyResult<()> {
|
||||
let key = tag.into();
|
||||
match self.medias.write().await.entry(key.clone()) {
|
||||
Entry::Occupied(_occ) => {}
|
||||
Entry::Vacant(vac) => {
|
||||
let media = NeoMediaFactory::new();
|
||||
let media = NeoMediaFactory::new(config.buffer_size, config.use_smoothing);
|
||||
let thread_media = media.clone();
|
||||
self.threads
|
||||
.write()
|
||||
|
||||
+23
-1
@@ -1,7 +1,7 @@
|
||||
//! Data shared between the various
|
||||
//! components that manage a media stream
|
||||
pub use gstreamer_rtsp_server::gio::{TlsAuthenticationMode, TlsCertificate};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
@@ -23,6 +23,8 @@ pub(super) struct NeoMediaShared {
|
||||
pub(super) aud_format: RwLock<AudFormats>,
|
||||
pub(super) number_of_clients: AtomicUsize,
|
||||
pub(super) buffer_ready: AtomicBool,
|
||||
pub(super) buffer_size: AtomicUsize,
|
||||
pub(super) use_smoothing: AtomicBool,
|
||||
}
|
||||
|
||||
impl Default for NeoMediaShared {
|
||||
@@ -32,6 +34,26 @@ impl Default for NeoMediaShared {
|
||||
aud_format: RwLock::new(AudFormats::Unknown),
|
||||
number_of_clients: AtomicUsize::new(0),
|
||||
buffer_ready: AtomicBool::new(false),
|
||||
buffer_size: AtomicUsize::new(100),
|
||||
use_smoothing: AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NeoMediaShared {
|
||||
pub(super) fn get_buffer_size(&self) -> usize {
|
||||
self.buffer_size.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(super) fn set_buffer_size(&self, new_size: usize) {
|
||||
self.buffer_size.store(new_size, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(super) fn get_use_smoothing(&self) -> bool {
|
||||
self.use_smoothing.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(super) fn set_use_smoothing(&self, new_value: bool) {
|
||||
self.use_smoothing.store(new_value, Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
@@ -279,6 +279,12 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
}.with_context(|| format!("{}: Error while streaming", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.pause(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
let paused = streaming
|
||||
.stop()
|
||||
.await
|
||||
@@ -346,5 +352,11 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
.await
|
||||
.with_context(|| format!("{}: Could not start stream", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.resume(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,12 @@ impl Spring {
|
||||
self.target
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn mod_value(&mut self, delta: f64) {
|
||||
self.target += delta;
|
||||
self.value += delta;
|
||||
}
|
||||
|
||||
pub(crate) fn reset_to(&mut self, target: f64) {
|
||||
self.target = target;
|
||||
self.value = target;
|
||||
|
||||
@@ -36,4 +36,13 @@ impl Camera<Connected> {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn join(&self) -> Result<()> {
|
||||
self.state
|
||||
.camera
|
||||
.join()
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
|
||||
}
|
||||
}
|
||||
@@ -96,4 +96,13 @@ impl Camera<LoggedIn> {
|
||||
pub(crate) fn get_camera(&self) -> &BcCamera {
|
||||
&self.state.camera
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn join(&self) -> Result<()> {
|
||||
self.state
|
||||
.camera
|
||||
.join()
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ impl Shared {
|
||||
pub(crate) async fn setup_streams(&self) -> Result<()> {
|
||||
for stream in self.streams.iter() {
|
||||
let tag = self.get_tag_for_stream(stream);
|
||||
self.rtsp.create_stream(&tag).await?;
|
||||
self.rtsp.create_stream(&tag, &self.config).await?;
|
||||
self.rtsp
|
||||
.add_permitted_roles(&tag, &self.permitted_users)
|
||||
.await?;
|
||||
|
||||
@@ -100,20 +100,26 @@ impl Camera<Streaming> {
|
||||
}
|
||||
|
||||
pub(crate) async fn join(&self) -> Result<()> {
|
||||
let mut locked_threads = self.state.set.write().await;
|
||||
while let Some(res) = locked_threads.join_next().await {
|
||||
match res {
|
||||
Err(e) => {
|
||||
locked_threads.abort_all();
|
||||
return Err(e.into());
|
||||
tokio::select! {
|
||||
v = async {
|
||||
let mut locked_threads = self.state.set.write().await;
|
||||
while let Some(res) = locked_threads.join_next().await {
|
||||
match res {
|
||||
Err(e) => {
|
||||
locked_threads.abort_all();
|
||||
return Err(e.into());
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
locked_threads.abort_all();
|
||||
return Err(e);
|
||||
}
|
||||
Ok(Ok(())) => {}
|
||||
}
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
locked_threads.abort_all();
|
||||
return Err(e);
|
||||
}
|
||||
Ok(Ok(())) => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
} => v,
|
||||
v = self.state.camera.join() => v.map_err(|e| anyhow!("Camera join error: {:?}", e)),
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user