Compare commits
58
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7158943fc8 | ||
|
|
8f19d12b8c | ||
|
|
b0e009ba4d | ||
|
|
99146a8dce | ||
|
|
3349486750 | ||
|
|
204c92cb4e | ||
|
|
d16cd4398c | ||
|
|
56d343e69f | ||
|
|
f8bb04fb8b | ||
|
|
813eb25343 | ||
|
|
f86cefc2fd | ||
|
|
a04077e2c1 | ||
|
|
1c797dffb5 | ||
|
|
9ace435f5f | ||
|
|
684e1a9015 | ||
|
|
23bf14119f | ||
|
|
77eeea224c | ||
|
|
b37b3ee4b7 | ||
|
|
3f7a231ff6 | ||
|
|
108adb13a5 | ||
|
|
b561b643c5 | ||
|
|
afd71a7cd2 | ||
|
|
6572577859 | ||
|
|
cc8a6e7e18 | ||
|
|
2e24b1e476 | ||
|
|
82524a12b2 | ||
|
|
ae6e0fd928 | ||
|
|
ab947b895c | ||
|
|
e53b0f09d2 | ||
|
|
0f53185d01 | ||
|
|
1b6011b4eb | ||
|
|
bae36ef40a | ||
|
|
32937c1f61 | ||
|
|
308a454c74 | ||
|
|
daf20e192a | ||
|
|
8f043a3ce2 | ||
|
|
0d5fbd30f1 | ||
|
|
a6ebdfe713 | ||
|
|
186d580462 | ||
|
|
e6321f36d7 | ||
|
|
366c2a4b69 | ||
|
|
e8aca0ee10 | ||
|
|
96e994512e | ||
|
|
a8b93a4ef2 | ||
|
|
9d68338774 | ||
|
|
bd2adf8924 | ||
|
|
7e407c4456 | ||
|
|
d96f637c84 | ||
|
|
556e051edc | ||
|
|
4ef6fb59f0 | ||
|
|
4b801884ef | ||
|
|
26fa7ee161 | ||
|
|
0eddab0b2e | ||
|
|
e7268f2481 | ||
|
|
f31d948671 | ||
|
|
7a920fb09a | ||
|
|
2deac96af4 | ||
|
|
1e620d15df |
No files matched your search
+20
-18
@@ -116,11 +116,12 @@ jobs:
|
||||
echo "GSTREAMER_1_0_ROOT_MSVC_X86_64=${GSTREAMER_1_0_ROOT_MSVC_X86_64}"
|
||||
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
|
||||
# pkg-config --variable pc_path pkg-config
|
||||
cargo build --all-features
|
||||
export JEMALLOC_SYS_WITH_LG_PAGE=16
|
||||
cargo build --release --all-features
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug-${{ matrix.os }}
|
||||
path: "target/debug/neolink*"
|
||||
name: release-${{ matrix.os }}
|
||||
path: "target/release/neolink*"
|
||||
cross:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
@@ -182,16 +183,17 @@ jobs:
|
||||
TARGET: ${{ matrix.target }}
|
||||
- name: Build
|
||||
run: |
|
||||
cargo build --verbose --all-features --target=${TARGET}
|
||||
cargo build --release --verbose --all-features --target=${TARGET}
|
||||
env:
|
||||
# Retarget pkg-config as described in https://www.freedesktop.org/wiki/Software/pkg-config/CrossCompileProposal/
|
||||
PKG_CONFIG_ALLOW_CROSS: 1
|
||||
PKG_CONFIG_LIBDIR: /usr/lib/${{ matrix.pkgconfig }}/pkgconfig
|
||||
TARGET: ${{ matrix.target }}
|
||||
JEMALLOC_SYS_WITH_LG_PAGE: 16
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug-${{ matrix.arch }}-bookworm
|
||||
path: "target/${{ matrix.target }}/debug/neolink*"
|
||||
name: release-${{ matrix.arch }}-bookworm
|
||||
path: "target/${{ matrix.target }}/release/neolink*"
|
||||
|
||||
push_to_registry:
|
||||
name: Build Docker image
|
||||
@@ -299,22 +301,22 @@ jobs:
|
||||
- name: Download Linux x86_64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-amd64-bookworm
|
||||
name: release-amd64-bookworm
|
||||
path: linux/amd64
|
||||
- name: Download Linux armv7
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-armhf-bookworm
|
||||
name: release-armhf-bookworm
|
||||
path: linux/arm/v7
|
||||
- name: Download Linux arm64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-arm64-bookworm
|
||||
name: release-arm64-bookworm
|
||||
path: linux/arm64
|
||||
- name: Download Linux i386
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-i386-bookworm
|
||||
name: release-i386-bookworm
|
||||
path: linux/386
|
||||
- name: Push to Docker Hub
|
||||
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
|
||||
@@ -353,42 +355,42 @@ jobs:
|
||||
- name: Download Windows
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-windows-2022
|
||||
name: release-windows-2022
|
||||
path: neolink_windows
|
||||
- name: Download Macos
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-macos-12
|
||||
name: release-macos-12
|
||||
path: neolink_macos_intel
|
||||
- name: Download Macos arm64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-macos-14
|
||||
name: release-macos-14
|
||||
path: neolink_macos_m1
|
||||
- name: Download Linux x86_64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-ubuntu-22.04
|
||||
name: release-ubuntu-22.04
|
||||
path: neolink_linux_x86_64_ubuntu
|
||||
- name: Download Linux x86_64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-amd64-bookworm
|
||||
name: release-amd64-bookworm
|
||||
path: neolink_linux_x86_64_bookworm
|
||||
- name: Download Linux armhf
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-armhf-bookworm
|
||||
name: release-armhf-bookworm
|
||||
path: neolink_linux_armhf
|
||||
- name: Download Linux arm64
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-arm64-bookworm
|
||||
name: release-arm64-bookworm
|
||||
path: neolink_linux_arm64
|
||||
- name: Download Linux i386
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug-i386-bookworm
|
||||
name: release-i386-bookworm
|
||||
path: neolink_linux_i386
|
||||
- name: Prepare releases
|
||||
run: |
|
||||
|
||||
@@ -34,7 +34,11 @@ jobs:
|
||||
rustup toolchain install nightly --component clippy
|
||||
rustup override set nightly
|
||||
- name: Run clippy manually
|
||||
run: cargo +nightly clippy --workspace --all-targets --all-features
|
||||
run: |
|
||||
cargo +nightly clippy --workspace --all-targets --all-features || exit 1
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features || exit 1
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=gstreamer || exit 1
|
||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=pushnoti || exit 1
|
||||
|
||||
check_fmt:
|
||||
needs: pre_job
|
||||
|
||||
Generated
+88
-87
@@ -149,7 +149,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -205,9 +205,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.5.0"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
@@ -333,7 +333,7 @@ dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -462,7 +462,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim 0.10.0",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -473,7 +473,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -484,7 +484,7 @@ checksum = "4e018fccbeeb50ff26562ece792ed06659b9c2dae79ece77c4456bb10d9bf79b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -743,7 +743,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -833,9 +833,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||
|
||||
[[package]]
|
||||
name = "gio"
|
||||
version = "0.19.3"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c64947d08d7fbb03bf8ad1f25a8ac6cf4329bc772c9b7e5abe7bf9493c81194f"
|
||||
checksum = "398e3da68749fdc32783cbf7521ec3f65c9cf946db8c7774f8460af49e52c6e2"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
@@ -851,9 +851,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gio-sys"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcf8e1d9219bb294636753d307b030c1e8a032062cba74f493c431a5c8b81ce4"
|
||||
checksum = "e4feb96b31c32730ea3e1e89aecd2e4e37ecb1c473ad8f685e3430a159419f63"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
@@ -864,11 +864,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "glib"
|
||||
version = "0.19.3"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01e191cc1af1f35b9699213107068cd3fe05d9816275ac118dc785a0dd8faebf"
|
||||
checksum = "fee90a615ce05be7a32932cfb8adf2c4bbb4700e80d37713c981fb24c0c56238"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"bitflags 2.6.0",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
@@ -886,22 +886,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "glib-macros"
|
||||
version = "0.19.3"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9972bb91643d589c889654693a4f1d07697fdcb5d104b5c44fb68649ba1bf68d"
|
||||
checksum = "4da558d8177c0c8c54368818b508a4244e1286fce2858cef4e547023f0cfa5ef"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-sys"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "630f097773d7c7a0bb3258df4e8157b47dc98bbfa0e60ad9ab56174813feced4"
|
||||
checksum = "4958c26e5a01c9af00dea669a97369eccbec29a8e6d125c24ea2d85ee7467b60"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"system-deps",
|
||||
@@ -909,9 +909,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gobject-sys"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c85e2b1080b9418dd0c58b498da3a5c826030343e0ef07bde6a955d28de54979"
|
||||
checksum = "c6908864f5ffff15b56df7e90346863904f49b949337ed0456b9287af61903b8"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
@@ -920,9 +920,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer"
|
||||
version = "0.22.3"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "066f3c354c526792a3deb8b6d349eba8ffcc13bae4d0bf05d4adf4bf1b91e459"
|
||||
checksum = "21e95b1d1153239a621ec143501fdcca6c1ad3efb87d268597285f85c4136f73"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-channel",
|
||||
@@ -930,7 +930,7 @@ dependencies = [
|
||||
"futures-util",
|
||||
"glib",
|
||||
"gstreamer-sys",
|
||||
"itertools 0.12.1",
|
||||
"itertools 0.13.0",
|
||||
"libc",
|
||||
"muldiv",
|
||||
"num-integer",
|
||||
@@ -945,9 +945,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-app"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50184e88d3462a796a5924fb329839c102b22f9383c1636323fa4ef5255dea92"
|
||||
checksum = "e0c86915cc4cdfa030532301a46c725e0ce0c6c2b57a68c44ce9b34db587e552"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
@@ -960,9 +960,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-app-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6771c0939f286fb261525494a0aad29435b37e802284756bab24afe3bbca7476"
|
||||
checksum = "37066c1b93ba57aa070ebc1e0a564bc1a9adda78fb0850e624861fad46fd1448"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gstreamer-base-sys",
|
||||
@@ -973,9 +973,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-base"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "514c71195b53c7eced4842b66ca9149833e41cf6a1d949e45e2ca4a4fa929850"
|
||||
checksum = "a3faa0b3cf361bf538dcb25b5cb7f6e73bd872ed031d85f3997b42d3fbd66409"
|
||||
dependencies = [
|
||||
"atomic_refcell",
|
||||
"cfg-if",
|
||||
@@ -987,9 +987,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-base-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "286591e0f85bbda1adf9bab6f21d015acd9ca0a4d4acb61da65e3d0487e23c4e"
|
||||
checksum = "4a6643ef963c636b8022adc93aa19eac6f356bd174a187c499339fc5d64c1e05"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
@@ -1000,9 +1000,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-net"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de0f4ff263821ae2c3a2de4771510dd07faba7af9d908441a738da6eb2cfc901"
|
||||
checksum = "9021fba4d09e686c9d0d8fe4dfa2320a3eb4a89e46130f0cd290a37098be17d9"
|
||||
dependencies = [
|
||||
"gio",
|
||||
"glib",
|
||||
@@ -1012,9 +1012,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-net-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fab77482d011b99fb78ad133cd30c11b27bfc203b58da9d18d8eccecea56273"
|
||||
checksum = "5b4151d4c7ad3d3c0a2b839b2b1b00930a1b445a5f0c2f99cc26c761eab5bf53"
|
||||
dependencies = [
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
@@ -1025,9 +1025,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-rtsp"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60d55c8cffe9edc8e3156c3d2f6305e86e2e4eda303f02c00e1255739f970b1f"
|
||||
checksum = "5a2c5018f3c36992df5795532749e810d41a7c6a50123a5b02746bc8cb2cabc2"
|
||||
dependencies = [
|
||||
"glib",
|
||||
"gstreamer",
|
||||
@@ -1038,9 +1038,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-rtsp-server"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7494b38cf577bf33fe1e3c28cf80ef5ee7f1d7724c6f5e37e1fddacd35f4d382"
|
||||
checksum = "583b458406bd3053ec3336376e8f31de3387faeb30aac85a5563f194f5d3901b"
|
||||
dependencies = [
|
||||
"gio",
|
||||
"glib",
|
||||
@@ -1054,9 +1054,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-rtsp-server-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc8c571931ce0ec8a4f342ed0e5094d37192ffd7bb1a463def3d89c43a273d51"
|
||||
checksum = "6f3de411751e82c40422fbed9708c70a2f7921c90e79205c189f8a3dda489994"
|
||||
dependencies = [
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
@@ -1071,9 +1071,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-rtsp-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dc20e7083bf12ee94c880bd50410948addb2ed080a05f38982f06a43640b490"
|
||||
checksum = "4414e397f632d9cc373eeac7ab4040c72ec12b23c85a9993ec452db110d5b32c"
|
||||
dependencies = [
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
@@ -1086,9 +1086,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-sdp"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f9aa459d119aa787efc18edcc591736e1e6cd488835825d1807532456ba2dbd"
|
||||
checksum = "55409c506b35b896e8f77477f1c6a3c0323fa8faacbc233173b04be39ceaa257"
|
||||
dependencies = [
|
||||
"glib",
|
||||
"gstreamer",
|
||||
@@ -1097,9 +1097,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-sdp-sys"
|
||||
version = "0.22.0"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d80dfc4811c67ca66586b4e470f85ab25aca4ea92bd2ba2665552c1dd0e5609"
|
||||
checksum = "b5310c77cef02c0fbbc20e68d9aef20e0b03db5dc9b4c305dfdc5d72002e0f94"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gstreamer-sys",
|
||||
@@ -1109,9 +1109,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-sys"
|
||||
version = "0.22.2"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5ddf526b3bf90ea627224c804f00b8bcb0452e3b447978b4d5092f8e8ff5918"
|
||||
checksum = "d9c9005b55dd2b1784645963c1ec409f9d420a56f6348d0ae69c2eaff584bcc3"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
@@ -1407,9 +1407,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
@@ -1447,7 +1447,7 @@ version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"bitflags 2.6.0",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@@ -1481,9 +1481,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.2"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
@@ -1582,8 +1582,8 @@ dependencies = [
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"toml",
|
||||
"validator 0.17.0",
|
||||
"validator_derive 0.17.0",
|
||||
"uuid",
|
||||
"validator 0.18.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1716,7 +1716,7 @@ version = "0.10.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"bitflags 2.6.0",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
@@ -1733,7 +1733,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1889,9 +1889,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.79"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -1971,9 +1971,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.31.0"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
|
||||
checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"serde",
|
||||
@@ -2193,7 +2193,7 @@ version = "0.38.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"bitflags 2.6.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
@@ -2346,7 +2346,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2406,7 +2406,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2533,9 +2533,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.58"
|
||||
version = "2.0.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
|
||||
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2571,9 +2571,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.2.2"
|
||||
version = "7.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349"
|
||||
checksum = "6c81f13d9a334a6c242465140bd262fae382b752ff2011c4f7419919a9c97922"
|
||||
dependencies = [
|
||||
"cfg-expr",
|
||||
"heck 0.5.0",
|
||||
@@ -2637,7 +2637,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2662,9 +2662,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.34"
|
||||
version = "0.3.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
|
||||
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
@@ -2685,9 +2685,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.17"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
|
||||
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
@@ -2736,7 +2736,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2970,7 +2970,7 @@ checksum = "9881bea7cbe687e36c9ab3b778c36cd0487402e270304e8b1296d5085303c1a2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2990,9 +2990,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "validator"
|
||||
version = "0.17.0"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da339118f018cc70ebf01fafc103360528aad53717e4bf311db929cb01cb9345"
|
||||
checksum = "db79c75af171630a3148bd3e6d7c4f42b6a9a014c2945bc5ed0020cbb8d9478e"
|
||||
dependencies = [
|
||||
"idna 0.5.0",
|
||||
"once_cell",
|
||||
@@ -3001,6 +3001,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"url",
|
||||
"validator_derive 0.18.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3021,16 +3022,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "validator_derive"
|
||||
version = "0.17.0"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76e88ea23b8f5e59230bff8a2f03c0ee0054a61d5b8343a38946bcd406fe624c"
|
||||
checksum = "55591299b7007f551ed1eb79a684af7672c19c3193fb9e0a31936987bb2438ec"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"once_cell",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3097,7 +3098,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@@ -3131,7 +3132,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@@ -3412,7 +3413,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+30
-13
@@ -13,26 +13,26 @@ members = [
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.70"
|
||||
async-stream = "0.3.5"
|
||||
async-stream = {version = "0.3.5", optional = true}
|
||||
base64 = "0.22.0"
|
||||
byte-slice-cast = "1.2.2"
|
||||
byte-slice-cast = {version = "1.2.2", optional = true}
|
||||
bytes = "1.6.0"
|
||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||
crossbeam-channel = "0.5.8"
|
||||
dirs = "5.0.1"
|
||||
crossbeam-channel = {version = "0.5.8", optional = true}
|
||||
dirs = {version = "5.0.1", optional = true}
|
||||
env_logger = "0.11.3"
|
||||
fcm-push-listener = "2.0.3"
|
||||
fcm-push-listener = {version = "2.0.3", optional = true}
|
||||
futures = "0.3.28"
|
||||
gstreamer = "0.22.3"
|
||||
gstreamer-app = { version = "0.22.0", features = ["v1_20"] }
|
||||
gstreamer-rtsp = { version = "0.22.0", features = ["v1_20"] }
|
||||
gstreamer-rtsp-server = { version = "0.22.0", features = ["v1_20"] }
|
||||
gstreamer = {version = "0.23.0", optional = true}
|
||||
gstreamer-app = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
gstreamer-rtsp = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
gstreamer-rtsp-server = { version = "0.23.0", features = ["v1_20"], optional = true }
|
||||
heck = "0.5.0"
|
||||
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||
md5 = "0.7.0"
|
||||
md5 = {version = "0.7.0", optional = true}
|
||||
neolink_core = { path = "crates/core", version = "0.6.3-rc.2" }
|
||||
once_cell = "1.19.0"
|
||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||
quick-xml = { version = "0.36.1", features = ["serialize"] }
|
||||
regex = "1.7.3"
|
||||
rumqttc = "0.24.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
@@ -41,8 +41,25 @@ tokio = { version = "1.27.0", features = ["rt-multi-thread", "macros", "io-util"
|
||||
tokio-stream = "0.1.12"
|
||||
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
||||
toml = "0.8.2"
|
||||
validator = "0.17.0"
|
||||
validator_derive = "0.17.0"
|
||||
uuid = { version = "1.8.0", features = ["v4"] }
|
||||
validator = {version="0.18.1", features = ["derive"] }
|
||||
|
||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||
tikv-jemallocator = "0.5"
|
||||
|
||||
[features]
|
||||
default = ["gstreamer", "pushnoti"]
|
||||
gstreamer = [
|
||||
"dep:gstreamer",
|
||||
"dep:gstreamer-app",
|
||||
"dep:gstreamer-rtsp",
|
||||
"dep:gstreamer-rtsp-server",
|
||||
"dep:async-stream",
|
||||
"dep:byte-slice-cast",
|
||||
"dep:crossbeam-channel"
|
||||
]
|
||||
pushnoti = [
|
||||
"dep:fcm-push-listener",
|
||||
"dep:dirs",
|
||||
"dep:md5"
|
||||
]
|
||||
+5
-3
@@ -30,6 +30,7 @@ RUN echo "TARGETPLATFORM: ${TARGETPLATFORM}"; \
|
||||
else \
|
||||
echo "Building from scratch"; \
|
||||
apt-get update && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
openssl \
|
||||
@@ -58,6 +59,7 @@ LABEL maintainer="$OWNER"
|
||||
|
||||
# hadolint ignore=DL3008
|
||||
RUN apt-get update && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
openssl \
|
||||
dnsutils \
|
||||
@@ -81,11 +83,11 @@ COPY docker/entrypoint.sh /entrypoint.sh
|
||||
RUN gst-inspect-1.0; \
|
||||
chmod +x "/usr/local/bin/neolink" && \
|
||||
"/usr/local/bin/neolink" --version && \
|
||||
mkdir -m 0700 /root/.config/ && \
|
||||
|
||||
mkdir -m 0700 /root/.config/
|
||||
|
||||
ENV NEO_LINK_MODE="rtsp" NEO_LINK_PORT=8554
|
||||
|
||||
CMD /usr/local/bin/neolink ${NEO_LINK_MODE} --config /etc/neolink.toml
|
||||
CMD /usr/local/bin/neolink "${NEO_LINK_MODE}" --config /etc/neolink.toml
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
EXPOSE ${NEO_LINK_PORT}
|
||||
|
||||
@@ -36,7 +36,7 @@ features not yet in upstream master.
|
||||
- Protocol more closely follows official reolink format
|
||||
- Possibly can handle more simulatenous connections
|
||||
- More ways to connect to the camera. Including Relaying through reolink
|
||||
servers
|
||||
servers
|
||||
- Camera battery levels can be displayed in the log
|
||||
|
||||
## Installation
|
||||
@@ -67,9 +67,10 @@ sudo apt install \
|
||||
```
|
||||
|
||||
- **Windows**: You may also need to
|
||||
[install openssl](https://wiki.openssl.org/index.php/Binaries)
|
||||
[install openssl](https://wiki.openssl.org/index.php/Binaries)
|
||||
- **Macos**: You may also need to
|
||||
[install openssl](https://wiki.openssl.org/index.php/Binaries) or `brew install openssl@1.1`
|
||||
[install openssl](https://wiki.openssl.org/index.php/Binaries) or
|
||||
`brew install openssl@1.1`
|
||||
- **Ubuntu/Debian**: Install the `libssl` package
|
||||
|
||||
Make a config file see below.
|
||||
@@ -114,7 +115,7 @@ using the terminal in the same folder the neolink binary is in.
|
||||
### Discovery
|
||||
|
||||
To connect to a camera using a UID we need to find the IP address of the camera
|
||||
with that UID
|
||||
with that UID
|
||||
|
||||
The IP is discovered with four methods
|
||||
|
||||
@@ -249,7 +250,7 @@ Status Messages:
|
||||
there will be no `/status/preview` message. Only published when
|
||||
`enable_preview` is true in the config
|
||||
- `/status/floodlight_tasks` The current status of the floodlight tasks
|
||||
used updated every 2s by default
|
||||
used updated every 2s by default
|
||||
|
||||
Query Messages:
|
||||
|
||||
@@ -257,7 +258,7 @@ Query Messages:
|
||||
- `/query/pir` Request that the camera reports its pir status
|
||||
- `/query/ptz/preset` Request that the camera reports its PTZ presets
|
||||
- `/query/preview` Request that the camera post a base64 encoded jpeg
|
||||
of the stream to `/status/preview` now, ignoring the timer
|
||||
of the stream to `/status/preview` now, ignoring the timer
|
||||
|
||||
### Controlling RTSP from MQTT
|
||||
|
||||
@@ -456,8 +457,11 @@ docker pull quantumentangledandy/neolink
|
||||
# network=host, notably macos lacks this option.
|
||||
docker run --network host --volume=$PWD/config.toml:/etc/neolink.toml quantumentangledandy/neolink
|
||||
```
|
||||
#### Environmental Variables
|
||||
There are currently 2 environmental variables available as part of the container:
|
||||
|
||||
#### Environmental Variables
|
||||
|
||||
There are currently 2 environmental variables available as part of the container:
|
||||
|
||||
- `NEO_LINK_MODE`: defaults to `"rtsp"` if not set, other options are "mqtt" or "mqtt-rtsp".
|
||||
- `NEO_LINK_PORT`: defaults to `8554`, set this to your required port value.
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ lazy_static = "1.4.0"
|
||||
log = "0.4.17"
|
||||
md5 = "0.7.0"
|
||||
nom = { version = "7.1.3", features = ["alloc"] }
|
||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||
quick-xml = { version = "0.36.0", features = ["serialize"] }
|
||||
rand = "0.8.5"
|
||||
regex = "1.7.3"
|
||||
serde = { version = "1.0.106", features = ["derive"] }
|
||||
thiserror = "1.0.58"
|
||||
time = { version = "0.3.20" , features = [ "macros", "parsing", "local-offset" ]}
|
||||
time = { version = "0.3.36" , features = [ "macros", "parsing", "local-offset" ]}
|
||||
tokio = { version = "1.27.0", features = ["full"] }
|
||||
tokio-stream = { version = "0.1.12", features = ["sync", "time", "net"] }
|
||||
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
||||
|
||||
+61
-16
@@ -228,7 +228,8 @@ pub struct DeviceInfo {
|
||||
#[serde(rename = "@version")]
|
||||
pub version: Option<String>,
|
||||
/// The resolution xml block
|
||||
pub resolution: Resolution,
|
||||
/// Does not exist for floodlights
|
||||
pub resolution: Option<Resolution>,
|
||||
}
|
||||
|
||||
/// VersionInfo xml
|
||||
@@ -430,7 +431,7 @@ pub struct FloodlightStatusList {
|
||||
#[serde(rename = "@version")]
|
||||
pub version: String,
|
||||
/// List of events
|
||||
#[serde(rename = "FloodlightStatus")]
|
||||
#[serde(default, rename = "FloodlightStatus")]
|
||||
pub floodlight_status_list: Vec<FloodlightStatus>,
|
||||
}
|
||||
|
||||
@@ -479,7 +480,7 @@ pub struct RfAlarmCfg {
|
||||
#[serde(rename = "timeBlockList")]
|
||||
pub struct TimeBlockList {
|
||||
/// List of time block entries which disable/enable the PIR at a time
|
||||
#[serde(rename = "timeBlock")]
|
||||
#[serde(default, rename = "timeBlock")]
|
||||
pub time_block: Vec<TimeBlock>,
|
||||
}
|
||||
|
||||
@@ -503,6 +504,7 @@ pub struct TimeBlock {
|
||||
/// AlarmHandle Xml
|
||||
pub struct AlarmHandle {
|
||||
/// Items in the alarm handle
|
||||
#[serde(default)]
|
||||
pub item: Vec<AlarmHandleItem>,
|
||||
}
|
||||
|
||||
@@ -571,13 +573,13 @@ pub struct TalkAbility {
|
||||
#[serde(rename = "@version")]
|
||||
pub version: String,
|
||||
/// Duplexes known values `"FDX"`
|
||||
#[serde(rename = "duplexList")]
|
||||
#[serde(default, rename = "duplexList")]
|
||||
pub duplex_list: Vec<DuplexList>,
|
||||
/// audioStreamModes known values `"followVideoStream"`
|
||||
#[serde(rename = "audioStreamModeList")]
|
||||
#[serde(default, rename = "audioStreamModeList")]
|
||||
pub audio_stream_mode_list: Vec<AudioStreamModeList>,
|
||||
/// AudioConfigs contans the details of the audio to follow
|
||||
#[serde(rename = "audioConfigList")]
|
||||
#[serde(default, rename = "audioConfigList")]
|
||||
pub audio_config_list: Vec<AudioConfigList>,
|
||||
}
|
||||
|
||||
@@ -611,7 +613,7 @@ pub struct AlarmEventList {
|
||||
#[serde(rename = "@version")]
|
||||
pub version: String,
|
||||
/// List of events
|
||||
#[serde(rename = "AlarmEvent")]
|
||||
#[serde(default, rename = "AlarmEvent")]
|
||||
pub alarm_events: Vec<AlarmEvent>,
|
||||
}
|
||||
|
||||
@@ -670,6 +672,7 @@ pub struct PtzPreset {
|
||||
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
|
||||
pub struct PresetList {
|
||||
/// List of Presets
|
||||
#[serde(default)]
|
||||
pub preset: Vec<Preset>,
|
||||
}
|
||||
|
||||
@@ -693,7 +696,7 @@ pub struct BatteryList {
|
||||
#[serde(rename = "@version")]
|
||||
pub version: String,
|
||||
/// Battery info items
|
||||
#[serde(rename = "BatteryInfo")]
|
||||
#[serde(default, rename = "BatteryInfo")]
|
||||
pub battery_info: Vec<BatteryInfo>,
|
||||
}
|
||||
|
||||
@@ -768,7 +771,7 @@ pub struct AbilityInfo {
|
||||
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
|
||||
pub struct AbilityInfoToken {
|
||||
/// Submodule for this ability info token
|
||||
#[serde(rename = "subModule")]
|
||||
#[serde(default, rename = "subModule")]
|
||||
pub sub_module: Vec<AbilityInfoSubModule>,
|
||||
}
|
||||
|
||||
@@ -842,7 +845,7 @@ pub struct Snap {
|
||||
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
|
||||
pub struct StreamInfoList {
|
||||
/// The stream infos. There is usually only one of these
|
||||
#[serde(rename = "StreamInfo")]
|
||||
#[serde(default, rename = "StreamInfo")]
|
||||
pub stream_infos: Vec<StreamInfo>,
|
||||
}
|
||||
|
||||
@@ -853,7 +856,7 @@ pub struct StreamInfo {
|
||||
#[serde(rename = "channelBits")]
|
||||
pub channel_bits: u32,
|
||||
/// List of encode tabeles. These hold the actual stream data
|
||||
#[serde(rename = "encodeTable")]
|
||||
#[serde(default, rename = "encodeTable")]
|
||||
pub encode_tables: Vec<EncodeTable>,
|
||||
}
|
||||
|
||||
@@ -1250,7 +1253,7 @@ pub struct Support {
|
||||
#[serde(rename = "smartHome", skip_serializing_if = "Option::is_none")]
|
||||
pub smart_home: Option<SmartHome>,
|
||||
/// Support config for specific channels
|
||||
#[serde(rename = "item")]
|
||||
#[serde(default, rename = "item")]
|
||||
pub items: Vec<SupportItem>,
|
||||
}
|
||||
|
||||
@@ -1260,7 +1263,7 @@ pub struct SmartHome {
|
||||
/// Versionm
|
||||
pub version: u32,
|
||||
/// The smarthome items
|
||||
#[serde(rename = "item")]
|
||||
#[serde(default, rename = "item")]
|
||||
pub items: Vec<SmartHomeItem>,
|
||||
}
|
||||
|
||||
@@ -1696,18 +1699,17 @@ fn test_deviceinfo_partial_deser() {
|
||||
"#
|
||||
);
|
||||
|
||||
// Needs to ignore all the other crap that we don't care about
|
||||
let b = BcXml::try_parse(sample.as_bytes()).unwrap();
|
||||
match b {
|
||||
BcXml {
|
||||
device_info:
|
||||
Some(DeviceInfo {
|
||||
resolution:
|
||||
Resolution {
|
||||
Some(Resolution {
|
||||
width: 3840,
|
||||
height: 2160,
|
||||
..
|
||||
},
|
||||
}),
|
||||
..
|
||||
}),
|
||||
..
|
||||
@@ -1781,4 +1783,47 @@ fn test_enc3_extension() {
|
||||
} => {}
|
||||
_ => panic!(),
|
||||
}
|
||||
|
||||
let sample = indoc!(
|
||||
r#"
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<checkPos>0</checkPos>
|
||||
<checkValue>-1821213800</checkValue>
|
||||
</Extension>
|
||||
"#
|
||||
);
|
||||
let b = Extension::try_parse(sample.as_bytes()).unwrap();
|
||||
match b {
|
||||
Extension {
|
||||
check_pos: Some(0),
|
||||
check_value: Some(-1821213800),
|
||||
..
|
||||
} => {}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_floodlight_status_list() {
|
||||
let _ = env_logger::builder().is_test(true).try_init();
|
||||
let sample = indoc!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<FloodlightStatusList version="1.1" />
|
||||
</body>
|
||||
"#
|
||||
);
|
||||
let b = BcXml::try_parse(sample.as_bytes()).unwrap();
|
||||
match b {
|
||||
BcXml {
|
||||
floodlight_status_list:
|
||||
Some(FloodlightStatusList {
|
||||
version,
|
||||
floodlight_status_list,
|
||||
}),
|
||||
..
|
||||
} if version == "1.1" && floodlight_status_list.is_empty() => {}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -396,7 +396,7 @@ impl Poller {
|
||||
};
|
||||
}
|
||||
PollCommand::Disconnect => {
|
||||
return Err(Error::DroppedConnection);
|
||||
return Err(Error::ConnectionShutdown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ impl Discoverer {
|
||||
tokio::task::yield_now().await;
|
||||
match reader.next().await {
|
||||
Some(Ok((BcUdp::Discovery(bcudp), addr))) => {
|
||||
log::info!("Got discovery {:?} for {}", bcudp, addr);
|
||||
log::trace!("Got discovery {:?} for {}", bcudp, addr);
|
||||
let tid = bcudp.tid;
|
||||
let mut needs_removal = false;
|
||||
if let (Some(sender), true) =
|
||||
@@ -159,7 +159,7 @@ impl Discoverer {
|
||||
}
|
||||
Some(Ok(bcudp)) => {
|
||||
// Only discovery packets should be possible atm
|
||||
log::info!("Got non Discovery during discovery: {:?}", bcudp);
|
||||
log::debug!("Got non Discovery during discovery: {:?}", bcudp);
|
||||
}
|
||||
Some(Err(e)) => {
|
||||
log::error!("Error on discovery socket: {:?}", e);
|
||||
@@ -300,7 +300,7 @@ impl Discoverer {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::DroppedConnection)
|
||||
Err(Error::DiscoveryIgnored)
|
||||
} => {v},
|
||||
v = async {
|
||||
// Send every inter for ever or until channel is no longer viable
|
||||
@@ -362,7 +362,7 @@ impl Discoverer {
|
||||
}),
|
||||
};
|
||||
|
||||
log::info!(
|
||||
log::debug!(
|
||||
"Trying a direct connect to: {:?} with tid: {}",
|
||||
addr,
|
||||
msg.tid
|
||||
@@ -374,17 +374,17 @@ impl Discoverer {
|
||||
tid: _,
|
||||
payload: UdpXml::D2cCr(D2cCr { did, cid, .. }),
|
||||
} if cid == client_id => {
|
||||
log::info!("Got expected reply");
|
||||
log::trace!("Got expected reply");
|
||||
Some((addr, did))
|
||||
}
|
||||
n => {
|
||||
log::info!("Got unexpected reply: {:?}", n);
|
||||
log::debug!("Got unexpected reply: {:?}", n);
|
||||
None
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
|
||||
log::info!(
|
||||
log::debug!(
|
||||
"Direct connect success at {:?} client: {}, device: {}",
|
||||
addr,
|
||||
client_id,
|
||||
@@ -399,7 +399,7 @@ impl Discoverer {
|
||||
};
|
||||
self.keep_alive_device(tid, &result).await;
|
||||
|
||||
log::info!("Returning direct connect: {:?}", result);
|
||||
log::debug!("Returning direct connect: {:?}", result);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
||||
@@ -350,29 +350,29 @@ impl UdpPayloadInner {
|
||||
loop {
|
||||
break tokio::select!{
|
||||
_ = recv_timeout.as_mut() => {
|
||||
log::trace!("DroppedConnection: Timeout");
|
||||
Err(Error::DroppedConnection)
|
||||
Err(Error::BcUdpTimeout)
|
||||
}
|
||||
packet = inner.next() => {
|
||||
log::trace!("Cam->App");
|
||||
let packet = packet.ok_or(Error::DroppedConnection)??;
|
||||
let packet = packet.ok_or(Error::BcUdpDropReciver)??;
|
||||
recv_timeout.as_mut().reset(Instant::now() + Duration::from_secs(TIME_OUT));
|
||||
// let packet = socket_rx.next().await.ok_or(Error::DroppedConnection)??;
|
||||
socket_out_tx.try_send(packet).map_err(|_| Error::DroppedConnection)?;
|
||||
// let packet = socket_rx.next().await.ok_or(Error::BcUdpDropReciver)??;
|
||||
socket_out_tx.try_send(packet).map_err(|_| Error::BcUdpDropReciver)?;
|
||||
continue;
|
||||
},
|
||||
packet = socket_in_rx.next() => {
|
||||
let packet = packet.ok_or(Error::DroppedConnection)?;
|
||||
let packet = packet.ok_or(Error::BcUdpDropSender)?;
|
||||
match tokio::time::timeout(tokio::time::Duration::from_millis(250), inner.send((packet, thread_camera_addr))).await {
|
||||
Ok(written) => {
|
||||
written?;
|
||||
}
|
||||
Err(_) => {
|
||||
log::trace!("Socket Error, attempting reconnect over a new one");
|
||||
// Socket is (maybe) broken
|
||||
// Seems to happen with network reconnects like over
|
||||
// a lossy cellular network
|
||||
let stream = Arc::new(tokio::time::timeout(tokio::time::Duration::from_millis(250), connect_try_port(inner.inner.get_ref().local_addr()?.port())).await.map_err(|_| Error::DroppedConnection)??);
|
||||
inner = tokio::time::timeout(tokio::time::Duration::from_millis(250), BcUdpSource::new_from_socket(stream, inner.addr)).await.map_err(|_| Error::DroppedConnection)??;
|
||||
let stream = Arc::new(tokio::time::timeout(tokio::time::Duration::from_millis(250), connect_try_port(inner.inner.get_ref().local_addr()?.port())).await.map_err(|_| Error::BcUdpReconnectTimeout)??);
|
||||
inner = tokio::time::timeout(tokio::time::Duration::from_millis(250), BcUdpSource::new_from_socket(stream, inner.addr)).await.map_err(|_| Error::BcUdpReconnectTimeout)??;
|
||||
|
||||
// Inform the camera that we are the same client
|
||||
//
|
||||
@@ -491,10 +491,7 @@ impl UdpPayloadInner {
|
||||
log::trace!("App->Camera");
|
||||
// Incomming from application
|
||||
// Outgoing on socket
|
||||
if v.is_none() {
|
||||
log::trace!("DroppedConnection: self.thread_sink.next(): {:?}", v);
|
||||
}
|
||||
let item = v.ok_or(Error::DroppedConnection)?;
|
||||
let item = v.ok_or(Error::BcUdpDropSender)?;
|
||||
|
||||
for chunk in item.chunks(MTU - UDPDATA_HEADER_SIZE) {
|
||||
let udp_data = UdpData {
|
||||
@@ -512,10 +509,7 @@ impl UdpPayloadInner {
|
||||
log::trace!("Camera->App");
|
||||
// Incomming from socket
|
||||
// Outgoing to application
|
||||
if v.is_none() {
|
||||
log::trace!("DroppedConnection: self.socket_out.next()");
|
||||
}
|
||||
let (item, addr) = v.ok_or(Error::DroppedConnection)?;
|
||||
let (item, addr) = v.ok_or(Error::BcUdpDropReciver)?;
|
||||
if addr == camera_addr {
|
||||
match item {
|
||||
BcUdp::Discovery(UdpDiscovery{
|
||||
@@ -560,7 +554,7 @@ impl UdpPayloadInner {
|
||||
self.packets_want += 1;
|
||||
self.thread_stream.feed(Ok(payload)).await?;
|
||||
}
|
||||
log::info!("recieved: {}", self.recieved.len());
|
||||
log::trace!("recieved: {}", self.recieved.len());
|
||||
log::trace!("Flush");
|
||||
self.socket_in.flush().await?;
|
||||
self.thread_stream.flush().await?;
|
||||
@@ -618,7 +612,7 @@ impl UdpPayloadInner {
|
||||
}
|
||||
}
|
||||
self.ack_latency.feed_ack();
|
||||
log::info!("sent: {}", self.sent.len());
|
||||
log::trace!("sent: {}", self.sent.len());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,7 +651,7 @@ impl UdpPayloadSource {
|
||||
if payload_inner.thread_stream.is_closed() {
|
||||
log::trace!("payload_inner.thread_stream.is_closed");
|
||||
payload_inner.thread_sink.close();
|
||||
return Err(Error::DroppedConnection);
|
||||
return Err(Error::BcUdpPayloadDroppedInner);
|
||||
}
|
||||
log::trace!("Calling inner");
|
||||
let res = payload_inner.run().await;
|
||||
|
||||
@@ -45,8 +45,16 @@ pub enum Error {
|
||||
},
|
||||
|
||||
/// Raised when the camera responds with a status code over than OK
|
||||
#[error("Camera responded with Service Unavaliable: {0}")]
|
||||
CameraServiceUnavailable(u16),
|
||||
#[error("Camera responded with Service Unavaliable: Msg of type {id} returned code {code}")]
|
||||
CameraServiceUnavailable {
|
||||
/// The message ID
|
||||
id: u32,
|
||||
/// The return code this is usually
|
||||
/// 200 for OK
|
||||
/// 400 for not yet ready
|
||||
/// 500 for camera cannot comply or understand
|
||||
code: u16,
|
||||
},
|
||||
|
||||
/// Raised when the camera responds with a status code over than OK during login
|
||||
#[error("Camera responded with Err during login")]
|
||||
@@ -64,6 +72,38 @@ pub enum Error {
|
||||
#[error("Dropped connection (Broadcast TryRecv)")]
|
||||
BroadcastDroppedConnectionTry(#[from] tokio::sync::broadcast::error::TryRecvError),
|
||||
|
||||
/// Raised when a stream thread has finished
|
||||
#[error("End of Stream")]
|
||||
StreamFinished,
|
||||
|
||||
/// Raised when a connection requests shutdown
|
||||
#[error("Connection shuting down")]
|
||||
ConnectionShutdown,
|
||||
|
||||
/// Raised when a discovery attempt fails to get a reply
|
||||
#[error("No reply to discovery packet")]
|
||||
DiscoveryIgnored,
|
||||
|
||||
/// Raised when there is no reply to a UDP packet
|
||||
#[error("BcUDP packet timeout")]
|
||||
BcUdpTimeout,
|
||||
|
||||
/// Raised when a BcUdp incomming connection is dropped
|
||||
#[error("BcUDP reciver dropped")]
|
||||
BcUdpDropReciver,
|
||||
|
||||
/// Raised when a BcUdp outgoing connection is dropped
|
||||
#[error("BcUDP sender dropped")]
|
||||
BcUdpDropSender,
|
||||
|
||||
/// Raised when a BcUdp outgoing connection is dropped
|
||||
#[error("BcUDPPayload inner protocol was dropped")]
|
||||
BcUdpPayloadDroppedInner,
|
||||
|
||||
/// Raised when BcUdp sender fails to reconnect in time
|
||||
#[error("BcUDP reconnect timeout")]
|
||||
BcUdpReconnectTimeout,
|
||||
|
||||
/// Raised when a connection is dropped during a TryRecv event
|
||||
#[error("Send Error")]
|
||||
TokioBcSendError,
|
||||
|
||||
@@ -129,7 +129,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
@@ -181,7 +184,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -29,7 +29,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -27,7 +27,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -39,10 +39,16 @@ impl BcCamera {
|
||||
reties += 1;
|
||||
continue;
|
||||
} else {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
} else if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
} else {
|
||||
// Valid message with response_code == 200
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
@@ -101,7 +107,10 @@ impl BcCamera {
|
||||
{
|
||||
let msg = reply?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcMeta {
|
||||
|
||||
@@ -317,7 +317,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -64,7 +64,10 @@ impl BcCamera {
|
||||
sub.send(msg).await?;
|
||||
let msg = sub.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -34,7 +34,10 @@ impl BcCamera {
|
||||
{
|
||||
let msg = reply?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcMeta {
|
||||
@@ -90,10 +93,16 @@ impl BcCamera {
|
||||
reties += 1;
|
||||
continue;
|
||||
} else {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
} else if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
} else {
|
||||
// Valid message with response_code == 200
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -39,7 +39,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -41,7 +41,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
@@ -132,7 +135,10 @@ impl BcCamera {
|
||||
}
|
||||
} else {
|
||||
// anything else is an error
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
// let binary_stream = sub_get.payload_stream();
|
||||
|
||||
@@ -51,17 +51,17 @@ impl StreamData {
|
||||
if handle.is_finished() {
|
||||
self.abort_handle.cancel();
|
||||
handle.await??;
|
||||
return Err(Error::DroppedConnection);
|
||||
return Err(Error::StreamFinished);
|
||||
}
|
||||
} else {
|
||||
self.abort_handle.cancel();
|
||||
return Err(Error::DroppedConnection);
|
||||
return Err(Error::StreamFinished);
|
||||
}
|
||||
match self.rx.recv().await {
|
||||
Some(data) => Ok(data),
|
||||
None => {
|
||||
self.abort_handle.cancel();
|
||||
Err(Error::DroppedConnection)
|
||||
Err(Error::StreamFinished)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +255,10 @@ impl BcCamera {
|
||||
msg_id: MSG_ID_VIDEO_STOP,
|
||||
..
|
||||
} = msg.meta {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable{
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
@@ -336,7 +339,10 @@ impl BcCamera {
|
||||
|
||||
let reply = sub_video.recv().await?;
|
||||
if reply.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(reply.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: reply.meta.msg_id,
|
||||
code: reply.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -27,7 +27,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -26,7 +26,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -33,7 +33,10 @@ impl BcCamera {
|
||||
sub_get_general.send(get).await?;
|
||||
let msg = sub_get_general.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -25,7 +25,10 @@ impl BcCamera {
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(msg.meta.response_code));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: msg.meta.msg_id,
|
||||
code: msg.meta.response_code,
|
||||
});
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
|
||||
@@ -27,9 +27,10 @@ impl BcCamera {
|
||||
|
||||
let modern_reply = sub_version.recv().await?;
|
||||
if modern_reply.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavailable(
|
||||
modern_reply.meta.response_code,
|
||||
));
|
||||
return Err(Error::CameraServiceUnavailable {
|
||||
id: modern_reply.meta.msg_id,
|
||||
code: modern_reply.meta.response_code,
|
||||
});
|
||||
}
|
||||
let version_info;
|
||||
match modern_reply.body {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ make LUA_DIR=/usr
|
||||
The shared object library should be copied to `/usr/local/lib/lua/5.2/`
|
||||
```
|
||||
mkdir --parents /usr/local/lib/lua/5.2/
|
||||
cp luagcypt.so /usr/local/lib/lua/5.2/
|
||||
cp luagcrypt.so /usr/local/lib/lua/5.2/
|
||||
```
|
||||
Additionally, the system where the dissector is used needs these packages installing (if not already present): `libgcrypt20 libgpg-error0`
|
||||
## Install `baichuan.lua`
|
||||
|
||||
+13
-8
@@ -222,13 +222,15 @@ local header_lengths = {
|
||||
-- For other locations, use: LUA_CPATH=.../luagcrypt/?.so
|
||||
bc_protocol.prefs.key = Pref.string("Decryption key", "",
|
||||
"Passphrase used for the camera. Required to decrypt the AES packets")
|
||||
_G.nonce = ""
|
||||
_G.nonce = {}
|
||||
local function hexencode(str)
|
||||
return (str:gsub(".", function(char) return string.format("%02X", char:byte()) end))
|
||||
end
|
||||
local gcrypt = require("luagcrypt")
|
||||
local function aes_decrypt(data)
|
||||
local raw_key = (_G.nonce or "") .. "-" .. bc_protocol.prefs.key
|
||||
local function aes_decrypt(data, pinfo)
|
||||
local nonce_key = tostring(pinfo.src) .. ":" .. pinfo.src_port
|
||||
local nonce = (_G.nonce[nonce_key] or "")
|
||||
local raw_key = nonce .. "-" .. bc_protocol.prefs.key
|
||||
local iv = "0123456789abcdef"
|
||||
local hasher = gcrypt.Hash(gcrypt.MD_MD5)
|
||||
hasher:write(raw_key)
|
||||
@@ -358,9 +360,9 @@ local function process_body(header, body_buffer, bc_subtree, pinfo)
|
||||
local body_tvb = xml_buffer:tvb("Meta Payload")
|
||||
body:add(body_tvb(), "Meta Payload")
|
||||
if xml_len >= 4 then
|
||||
if aes_decrypt(xml_buffer:raw(0,5)):raw() == "<?xml" then -- AES encrypted
|
||||
if aes_decrypt(xml_buffer:raw(0,5), pinfo):raw() == "<?xml" then -- AES encrypted
|
||||
local ba = xml_buffer:bytes()
|
||||
local decrypted = aes_decrypt(ba:raw())
|
||||
local decrypted = aes_decrypt(ba:raw(), pinfo)
|
||||
body_tvb = decrypted:tvb("Decrypted XML (in Meta Payload)")
|
||||
-- Create a tree item that, when clicked, automatically shows the tab we just created
|
||||
body:add(body_tvb(), "Decrypted XML (in Meta Payload)")
|
||||
@@ -369,7 +371,10 @@ local function process_body(header, body_buffer, bc_subtree, pinfo)
|
||||
local ba = xml_buffer:bytes()
|
||||
local decrypted = xml_decrypt(ba, header.enc_offset)
|
||||
local new_noonce = string.match(decrypted:raw(), "[<]nonce[>][ \t\n]*([^ \t\n<]+)[ \t\n]*[<][/]nonce[>]")
|
||||
_G.nonce = new_noonce;
|
||||
local nonce_key = tostring(pinfo.src) .. ":" .. pinfo.src_port
|
||||
_G.nonce[nonce_key] = new_noonce;
|
||||
nonce_key = tostring(pinfo.dst) .. ":" .. pinfo.dst_port
|
||||
_G.nonce[nonce_key] = new_noonce;
|
||||
body_tvb = decrypted:tvb("Decrypted XML (in Meta Payload)")
|
||||
-- Create a tree item that, when clicked, automatically shows the tab we just created
|
||||
body:add(body_tvb(), "Decrypted XML (in Meta Payload)")
|
||||
@@ -390,9 +395,9 @@ local function process_body(header, body_buffer, bc_subtree, pinfo)
|
||||
local body_tvb = binary_buffer:tvb("Main Payload");
|
||||
body:add(body_tvb(), "Main Payload")
|
||||
if bin_len > 4 then
|
||||
if aes_decrypt(binary_buffer:raw(0,5)):raw() == "<?xml" then -- AES encrypted
|
||||
if aes_decrypt(binary_buffer:raw(0,5), pinfo):raw() == "<?xml" then -- AES encrypted
|
||||
local ba = binary_buffer:bytes()
|
||||
local decrypted = aes_decrypt(ba:raw())
|
||||
local decrypted = aes_decrypt(ba:raw(), pinfo)
|
||||
body_tvb = decrypted:tvb("Decrypted XML (in Binary Payload)")
|
||||
-- Create a tree item that, when clicked, automatically shows the tab we just created
|
||||
body:add(body_tvb(), "Decrypted XML (in Binary Payload)")
|
||||
|
||||
@@ -247,7 +247,7 @@ Message have zero to two payloads.
|
||||
- Payload
|
||||
|
||||
Body is binary. This binary represents an embedded stream which should
|
||||
is detailed in [mediapacket.md](dissector/mediapacket.md).
|
||||
is detailed in [mediapacket.md](mediapacket.md).
|
||||
|
||||
- 4: `<Preview>` (stop)
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ When receiving packet these should be used to quickly discard invalid packets.
|
||||
Each function in BC has its own message ID. For example login is 1, video data
|
||||
is 3, motion detection is 33.
|
||||
|
||||
For a more complete list please see the [messages doc](dissector/messages.md)
|
||||
For a more complete list please see the [messages doc](messages.md)
|
||||
|
||||
#### Message length
|
||||
|
||||
@@ -146,7 +146,7 @@ extension XML part of the message.
|
||||
|
||||
# Login
|
||||
|
||||
For message details see the [docs](dissector/messages.md)
|
||||
For message details see the [docs](messages.md)
|
||||
|
||||
Clients should login by
|
||||
|
||||
@@ -208,7 +208,7 @@ After which all message bodies of type id 3 are binary.
|
||||
The binary represents a stream of data that can be interrupted by packet
|
||||
boundaries. Clients should create a buffer and pop bytes for processing when
|
||||
complete media packets are received. Media packets descriptions can be found in
|
||||
the [docs](dissector/mediapacket.md)
|
||||
the [docs](mediapacket.md)
|
||||
|
||||
# Other Function
|
||||
|
||||
@@ -256,7 +256,7 @@ Which contains the plain text of the username of interest and the tokens for
|
||||
abilities you want to know about.
|
||||
|
||||
Details of expected formats should be found from the
|
||||
[docs](dissector/messages.md)
|
||||
[docs](messages.md)
|
||||
|
||||
#### AES Encryption
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ exit_func() {
|
||||
}
|
||||
trap exit_func TERM INT
|
||||
|
||||
ulimit -n 1024
|
||||
ulimit -n 65535
|
||||
|
||||
echo "Running: ${*}"
|
||||
"$@"
|
||||
@@ -17,14 +17,18 @@ pub struct Opt {
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum Command {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Rtsp(super::rtsp::Opt),
|
||||
StatusLight(super::statusled::Opt),
|
||||
Reboot(super::reboot::Opt),
|
||||
Pir(super::pir::Opt),
|
||||
Ptz(super::ptz::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Talk(super::talk::Opt),
|
||||
Mqtt(super::mqtt::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
MqttRtsp(super::mqtt::Opt),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Image(super::image::Opt),
|
||||
Battery(super::battery::Opt),
|
||||
Services(super::services::Opt),
|
||||
|
||||
+15
-5
@@ -37,10 +37,14 @@ impl NeoCamThread {
|
||||
}
|
||||
async fn run_camera(&mut self, config: &CameraConfig) -> AnyResult<()> {
|
||||
let name = config.name.clone();
|
||||
log::trace!("Attempting connection with config: {config:?}");
|
||||
let camera = Arc::new(connect_and_login(config).await?);
|
||||
log::trace!(" - Connected");
|
||||
|
||||
sleep(Duration::from_secs(2)).await; // Delay a little since some calls will error if camera is waking up
|
||||
update_camera_time(&camera, &name, config.update_time).await?;
|
||||
if let Err(e) = update_camera_time(&camera, &name, config.update_time).await {
|
||||
log::warn!("Could not set camera time, (perhaps missing on this camera of your login in not an admin): {e:?}");
|
||||
}
|
||||
sleep(Duration::from_secs(2)).await; // Delay a little since some calls will error if camera is waking up
|
||||
|
||||
self.camera_watch.send_replace(Arc::downgrade(&camera));
|
||||
@@ -60,13 +64,16 @@ impl NeoCamThread {
|
||||
let mut missed_pings = 0;
|
||||
loop {
|
||||
interval.tick().await;
|
||||
log::trace!("Sending ping");
|
||||
match timeout(Duration::from_secs(5), camera.get_linktype()).await {
|
||||
Ok(Ok(_)) => {
|
||||
log::trace!("Ping reply");
|
||||
missed_pings = 0;
|
||||
continue
|
||||
},
|
||||
Ok(Err(neolink_core::Error::UnintelligibleReply { .. })) => {
|
||||
Ok(Err(neolink_core::Error::UnintelligibleReply { reply, why })) => {
|
||||
// Camera does not support pings just wait forever
|
||||
log::trace!("Pings not supported: {reply:?}: {why}");
|
||||
futures::future::pending().await
|
||||
},
|
||||
Ok(Err(e)) => {
|
||||
@@ -74,12 +81,12 @@ impl NeoCamThread {
|
||||
},
|
||||
Err(_) => {
|
||||
// Timeout
|
||||
if missed_pings > 5 {
|
||||
if missed_pings < 5 {
|
||||
missed_pings += 1;
|
||||
continue;
|
||||
} else {
|
||||
log::debug!("Timed out waiting for camera ping reply. Assuming unsupported");
|
||||
futures::future::pending().await
|
||||
log::error!("Timed out waiting for camera ping reply");
|
||||
break Err(anyhow::anyhow!("Timed out waiting for camera ping reply"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +128,7 @@ impl NeoCamThread {
|
||||
None
|
||||
}
|
||||
Ok(_) = state.wait_for(|state| matches!(state, NeoCamThreadState::Disconnected)) => {
|
||||
log::trace!("State changed to disconnect");
|
||||
None
|
||||
}
|
||||
v = self.run_camera(&config) => {
|
||||
@@ -133,6 +141,7 @@ impl NeoCamThread {
|
||||
// If None go back and reload NOW
|
||||
//
|
||||
// This occurs if there was a config change
|
||||
log::trace!("Config change or Manual disconnect");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -150,6 +159,7 @@ impl NeoCamThread {
|
||||
match result {
|
||||
Ok(()) => {
|
||||
// Normal shutdown
|
||||
log::trace!("Normal camera shutdown");
|
||||
self.cancel.cancel();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
+22
-7
@@ -7,18 +7,25 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use futures::TryFutureExt;
|
||||
use std::sync::{Arc, Weak};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use tokio::sync::watch::channel as watch;
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::channel as watch,
|
||||
watch::Receiver as WatchReceiver,
|
||||
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::Receiver as WatchReceiver,
|
||||
},
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{MdState, NeoCamCommand, NeoCamThreadState, Permit, PushNoti, StreamInstance};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use super::PushNoti;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use super::StreamInstance;
|
||||
use super::{MdState, NeoCamCommand, NeoCamThreadState, Permit};
|
||||
use crate::{config::CameraConfig, AnyResult, Result};
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind};
|
||||
use neolink_core::bc_protocol::BcCamera;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
|
||||
/// This instance is the primary interface used throughout the app
|
||||
///
|
||||
@@ -120,15 +127,17 @@ impl NeoInstance {
|
||||
if let Some(cam) = camera.clone() {
|
||||
let cam_ref = cam.as_ref();
|
||||
let mut r = Err(anyhow!("No run"));
|
||||
for _ in 0..5 {
|
||||
for i in 0..5 {
|
||||
r = task(cam_ref).await;
|
||||
if let Err(e) = &r {
|
||||
log::trace!("- Task Result: {e:?}");
|
||||
log::debug!("- Task Error: {e:?}");
|
||||
}
|
||||
if let Err(Some(neolink_core::Error::CameraServiceUnavailable(400))) = r.as_ref().map_err(|e| e.downcast_ref::<neolink_core::Error>()) {
|
||||
if let Err(Some(e @ neolink_core::Error::CameraServiceUnavailable{code: 400, ..})) = r.as_ref().map_err(|e| e.downcast_ref::<neolink_core::Error>()) {
|
||||
// Retryable without a reconnect
|
||||
// Usually occurs when camera is starting up
|
||||
// or the connection is initialising
|
||||
log::debug!("Got a 400 code for {e:?} retry {i}/5, ");
|
||||
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
continue;
|
||||
} else {
|
||||
@@ -223,6 +232,7 @@ impl NeoInstance {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) async fn stream(&self, name: StreamKind) -> Result<StreamInstance> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
self.camera_control
|
||||
@@ -231,6 +241,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn low_stream(&self) -> Result<Option<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -240,6 +251,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn high_stream(&self) -> Result<Option<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -249,6 +261,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn streams(&self) -> Result<Vec<StreamInstance>> {
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
@@ -258,6 +271,7 @@ impl NeoInstance {
|
||||
Ok(instance_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) async fn uid(&self) -> Result<String> {
|
||||
let (reply_tx, reply_rx) = oneshot();
|
||||
self.camera_control
|
||||
@@ -266,6 +280,7 @@ impl NeoInstance {
|
||||
Ok(reply_rx.await?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
|
||||
let uid = self.uid().await?;
|
||||
let (instance_tx, instance_rx) = oneshot();
|
||||
|
||||
@@ -17,8 +17,8 @@ use super::NeoInstance;
|
||||
use crate::{AnyResult, Result};
|
||||
use neolink_core::bc_protocol::MotionStatus;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) enum MdState {
|
||||
#[allow(dead_code)]
|
||||
Start(Instant),
|
||||
Stop(Instant),
|
||||
Unknown,
|
||||
|
||||
@@ -2,8 +2,10 @@ mod camthread;
|
||||
mod instance;
|
||||
mod mdthread;
|
||||
mod neocam;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
mod pushnoti;
|
||||
mod reactor;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod streamthread;
|
||||
mod usecounter;
|
||||
|
||||
@@ -11,7 +13,9 @@ pub(crate) use camthread::*;
|
||||
pub(crate) use instance::*;
|
||||
pub(crate) use mdthread::*;
|
||||
pub(crate) use neocam::*;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
pub(crate) use pushnoti::*;
|
||||
pub(crate) use reactor::*;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) use streamthread::*;
|
||||
pub(crate) use usecounter::*;
|
||||
+88
-61
@@ -20,19 +20,29 @@ use tokio_stream::wrappers::ReceiverStream;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{
|
||||
MdRequest, MdState, NeoCamMdThread, NeoCamStreamThread, NeoCamThread, NeoCamThreadState,
|
||||
NeoInstance, Permit, PnRequest, PushNoti, StreamInstance, StreamRequest, UseCounter,
|
||||
MdRequest, MdState, NeoCamMdThread, NeoCamThread, NeoCamThreadState, NeoInstance, Permit,
|
||||
UseCounter,
|
||||
};
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use super::{NeoCamStreamThread, StreamInstance, StreamRequest};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use super::{PnRequest, PushNoti};
|
||||
use crate::{config::CameraConfig, AnyResult, Result};
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind};
|
||||
use neolink_core::bc_protocol::BcCamera;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) enum NeoCamCommand {
|
||||
HangUp,
|
||||
Instance(OneshotSender<Result<NeoInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Stream(StreamKind, OneshotSender<StreamInstance>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
HighStream(OneshotSender<Option<StreamInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
LowStream(OneshotSender<Option<StreamInstance>>),
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Streams(OneshotSender<Vec<StreamInstance>>),
|
||||
Motion(OneshotSender<WatchReceiver<MdState>>),
|
||||
Config(OneshotSender<WatchReceiver<CameraConfig>>),
|
||||
@@ -40,6 +50,7 @@ pub(crate) enum NeoCamCommand {
|
||||
Connect(OneshotSender<()>),
|
||||
State(OneshotSender<NeoCamThreadState>),
|
||||
GetPermit(OneshotSender<Permit>),
|
||||
#[cfg(feature = "pushnoti")]
|
||||
PushNoti(OneshotSender<WatchReceiver<Option<PushNoti>>>),
|
||||
GetUid(OneshotSender<String>),
|
||||
}
|
||||
@@ -55,11 +66,12 @@ pub(crate) struct NeoCam {
|
||||
impl NeoCam {
|
||||
pub(crate) async fn new(
|
||||
config: CameraConfig,
|
||||
pn_request_tx: MpscSender<PnRequest>,
|
||||
#[cfg(feature = "pushnoti")] pn_request_tx: MpscSender<PnRequest>,
|
||||
) -> Result<NeoCam> {
|
||||
let (commander_tx, commander_rx) = mpsc(100);
|
||||
let (watch_config_tx, watch_config_rx) = watch(config.clone());
|
||||
let (camera_watch_tx, camera_watch_rx) = watch(Weak::new());
|
||||
#[cfg(feature = "gstreamer")]
|
||||
let (stream_request_tx, stream_request_rx) = mpsc(100);
|
||||
let (md_request_tx, md_request_rx) = mpsc(100);
|
||||
let (state_tx, state_rx) = watch(NeoCamThreadState::Connected);
|
||||
@@ -83,10 +95,13 @@ impl NeoCam {
|
||||
// other threads
|
||||
let sender_cancel = me.cancel.clone();
|
||||
let mut commander_rx = ReceiverStream::new(commander_rx);
|
||||
#[cfg(feature = "gstreamer")]
|
||||
let strict = config.strict;
|
||||
let thread_commander_tx = commander_tx.clone();
|
||||
let thread_watch_config_rx = watch_config_rx.clone();
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
|
||||
me.set.spawn(async move {
|
||||
let thread_cancel = sender_cancel.clone();
|
||||
let res = tokio::select! {
|
||||
@@ -108,6 +123,7 @@ impl NeoCam {
|
||||
);
|
||||
let _ = result.send(instance);
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::Stream(name, sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::GetOrInsert {
|
||||
@@ -117,6 +133,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::HighStream(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::High {
|
||||
@@ -124,6 +141,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::LowStream(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::Low {
|
||||
@@ -131,6 +149,7 @@ impl NeoCam {
|
||||
}
|
||||
).await?;
|
||||
},
|
||||
#[cfg(feature = "gstreamer")]
|
||||
NeoCamCommand::Streams(sender) => {
|
||||
stream_request_tx.send(
|
||||
StreamRequest::All {
|
||||
@@ -166,6 +185,7 @@ impl NeoCam {
|
||||
NeoCamCommand::GetPermit(sender) => {
|
||||
let _ = sender.send(users.create_activated().await?);
|
||||
}
|
||||
#[cfg(feature = "pushnoti")]
|
||||
NeoCamCommand::PushNoti(sender) => {
|
||||
thread_pn_request_tx.send(
|
||||
PnRequest::Get {
|
||||
@@ -212,17 +232,21 @@ impl NeoCam {
|
||||
me.set.spawn(async move { cam_thread.run().await });
|
||||
|
||||
// This thread maintains the streams
|
||||
let stream_instance = instance.subscribe().await?;
|
||||
let stream_cancel = me.cancel.clone();
|
||||
let mut stream_thread = NeoCamStreamThread::new(stream_request_rx, stream_instance).await?;
|
||||
me.set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = stream_thread.run() => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
#[cfg(feature = "gstreamer")]
|
||||
{
|
||||
let stream_instance = instance.subscribe().await?;
|
||||
let stream_cancel = me.cancel.clone();
|
||||
let mut stream_thread =
|
||||
NeoCamStreamThread::new(stream_request_rx, stream_instance).await?;
|
||||
me.set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = stream_thread.run() => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This thread monitors the motion
|
||||
let md_instance = instance.subscribe().await?;
|
||||
@@ -292,54 +316,57 @@ impl NeoCam {
|
||||
});
|
||||
|
||||
// Handles push notifications
|
||||
let pn_root_instance = instance.subscribe().await?;
|
||||
let pn_cancel = me.cancel.clone();
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
me.set.spawn(async move {
|
||||
tokio::select!{
|
||||
_ = pn_cancel.cancelled() => {
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
v = async {
|
||||
let mut config_rx = pn_root_instance.config().await?;
|
||||
loop {
|
||||
// Wait for the green light
|
||||
config_rx.wait_for(|config| config.push_notifications).await?;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let pn_root_instance = instance.subscribe().await?;
|
||||
let pn_cancel = me.cancel.clone();
|
||||
let thread_pn_request_tx = pn_request_tx.clone();
|
||||
me.set.spawn(async move {
|
||||
tokio::select!{
|
||||
_ = pn_cancel.cancelled() => {
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
v = async {
|
||||
let mut config_rx = pn_root_instance.config().await?;
|
||||
loop {
|
||||
// Wait for the green light
|
||||
config_rx.wait_for(|config| config.push_notifications).await?;
|
||||
|
||||
// Activate it
|
||||
let pn_instance = pn_root_instance.subscribe().await?;
|
||||
let (tx, rx) = oneshot();
|
||||
thread_pn_request_tx.send(PnRequest::Activate{sender: tx, instance: pn_instance}).await?;
|
||||
rx.await??;
|
||||
// Activate it
|
||||
let pn_instance = pn_root_instance.subscribe().await?;
|
||||
let (tx, rx) = oneshot();
|
||||
thread_pn_request_tx.send(PnRequest::Activate{sender: tx, instance: pn_instance}).await?;
|
||||
rx.await??;
|
||||
|
||||
let pn_permit_instance = pn_root_instance.subscribe().await?;
|
||||
let r = tokio::select! {
|
||||
// Push notification permits
|
||||
v = async {
|
||||
let mut prev_noti = None;
|
||||
let mut pn = pn_permit_instance.push_notifications().await?;
|
||||
loop{
|
||||
prev_noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.map(|noti| noti.clone())?;
|
||||
let _permit = pn_permit_instance.permit().await?;
|
||||
sleep(Duration::from_secs(30)).await; // Push notification will wake us up for 30s
|
||||
}
|
||||
} => v,
|
||||
// Continue loop on Red light
|
||||
v = config_rx.wait_for(|config| !config.push_notifications).map_ok(|_| ()) => {
|
||||
v?;
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
};
|
||||
if r.is_err() {
|
||||
break r;
|
||||
}
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
let pn_permit_instance = pn_root_instance.subscribe().await?;
|
||||
let r = tokio::select! {
|
||||
// Push notification permits
|
||||
v = async {
|
||||
let mut prev_noti = None;
|
||||
let mut pn = pn_permit_instance.push_notifications().await?;
|
||||
loop{
|
||||
prev_noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.map(|noti| noti.clone())?;
|
||||
let _permit = pn_permit_instance.permit().await?;
|
||||
sleep(Duration::from_secs(30)).await; // Push notification will wake us up for 30s
|
||||
}
|
||||
} => v,
|
||||
// Continue loop on Red light
|
||||
v = config_rx.wait_for(|config| !config.push_notifications).map_ok(|_| ()) => {
|
||||
v?;
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
};
|
||||
if r.is_err() {
|
||||
break r;
|
||||
}
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
v
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// MD permits
|
||||
let md_permit_instance = instance.subscribe().await?;
|
||||
|
||||
+36
-10
@@ -5,6 +5,7 @@
|
||||
|
||||
use anyhow::Context;
|
||||
use fcm_push_listener::*;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::{fs, sync::Arc};
|
||||
use tokio::{
|
||||
sync::{
|
||||
@@ -21,8 +22,8 @@ use crate::AnyResult;
|
||||
|
||||
pub(crate) struct PushNotiThread {
|
||||
pn_watcher: Arc<WatchSender<Option<PushNoti>>>,
|
||||
registed_cameras: Vec<NeoInstance>,
|
||||
received_ids: Vec<String>,
|
||||
registed_cameras: HashMap<String, NeoInstance>,
|
||||
received_ids: Arc<RwLock<HashSet<String>>>,
|
||||
}
|
||||
|
||||
// The push notification
|
||||
@@ -51,8 +52,8 @@ impl PushNotiThread {
|
||||
|
||||
Ok(PushNotiThread {
|
||||
pn_watcher: Arc::new(pn_watcher),
|
||||
registed_cameras: vec![],
|
||||
received_ids: vec![],
|
||||
registed_cameras: Default::default(),
|
||||
received_ids: Arc::new(RwLock::new(Default::default())),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,6 +75,31 @@ impl PushNotiThread {
|
||||
// let vapid_key = "????";
|
||||
|
||||
let token_path = dirs::config_dir().map(|mut d| {
|
||||
fs::create_dir(&d)
|
||||
.map_or_else(
|
||||
|res| {
|
||||
if let std::io::ErrorKind::AlreadyExists = res.kind() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(res)
|
||||
}
|
||||
},
|
||||
Ok,
|
||||
)
|
||||
.expect("Unable to create directory for push notification settings: {d:?}");
|
||||
d.push("neolink");
|
||||
fs::create_dir(&d)
|
||||
.map_or_else(
|
||||
|res| {
|
||||
if let std::io::ErrorKind::AlreadyExists = res.kind() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(res)
|
||||
}
|
||||
},
|
||||
Ok,
|
||||
)
|
||||
.expect("Unable to create directory for push notification settings: {d:?}");
|
||||
d.push("./neolink_token.toml");
|
||||
d
|
||||
});
|
||||
@@ -121,7 +147,7 @@ impl PushNotiThread {
|
||||
log::debug!("Push notification Listening");
|
||||
let thread_pn_watcher = self.pn_watcher.clone();
|
||||
|
||||
for instance in self.registed_cameras.iter() {
|
||||
for (_, instance) in self.registed_cameras.iter() {
|
||||
let uid = uid.clone();
|
||||
let fcm_token = fcm_token.clone();
|
||||
let instance = instance.clone();
|
||||
@@ -145,7 +171,7 @@ impl PushNotiThread {
|
||||
});
|
||||
}
|
||||
|
||||
let received_ids = Arc::new(RwLock::new(self.received_ids.clone()));
|
||||
let received_ids = self.received_ids.clone();
|
||||
tokio::select! {
|
||||
v = async {
|
||||
loop {
|
||||
@@ -162,7 +188,7 @@ impl PushNotiThread {
|
||||
id: message.persistent_id,
|
||||
}));
|
||||
},
|
||||
received_ids.read().await.clone(),
|
||||
received_ids.read().await.iter().cloned().collect(),
|
||||
);
|
||||
let r = timeout(Duration::from_secs(60*5), listener.connect()).await;
|
||||
match &r {
|
||||
@@ -207,7 +233,7 @@ impl PushNotiThread {
|
||||
PnRequest::Activate{instance, sender} => {
|
||||
let uid = uid.clone();
|
||||
let fcm_token = fcm_token.clone();
|
||||
self.registed_cameras.push(instance.clone());
|
||||
self.registed_cameras.insert(uid.clone(), instance.clone());
|
||||
tokio::task::spawn(async move {
|
||||
let r = instance.run_task(|camera| {
|
||||
let fcm_token = fcm_token.clone();
|
||||
@@ -227,8 +253,8 @@ impl PushNotiThread {
|
||||
});
|
||||
}
|
||||
PnRequest::AddPushID{id} => {
|
||||
self.received_ids.push(id.clone());
|
||||
received_ids.write().await.push(id);
|
||||
log::trace!("Recived Push Notifcation of ID: {id}");
|
||||
received_ids.write().await.insert(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
-25
@@ -5,6 +5,8 @@ use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
sync::Arc,
|
||||
};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use tokio::time::{sleep, Duration};
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc::{channel as mpsc, Sender as MpscSender},
|
||||
@@ -12,12 +14,13 @@ use tokio::{
|
||||
watch::{channel as watch, Receiver as WatchReceiver},
|
||||
},
|
||||
task::JoinSet,
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::{NeoCam, NeoInstance};
|
||||
use crate::{common::PushNotiThread, config::Config, AnyResult, Result};
|
||||
#[cfg(feature = "pushnoti")]
|
||||
use crate::common::PushNotiThread;
|
||||
use crate::{config::Config, AnyResult, Result};
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum NeoReactorCommand {
|
||||
@@ -38,7 +41,9 @@ pub(crate) struct NeoReactor {
|
||||
impl NeoReactor {
|
||||
pub(crate) async fn new(config: Config) -> Self {
|
||||
let (commad_tx, mut command_rx) = mpsc(100);
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let (push_noti, mut pn_rx) = mpsc(10);
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let pn_tx = push_noti.clone();
|
||||
let cancel = CancellationToken::new();
|
||||
let (config_tx, _) = watch(config);
|
||||
@@ -73,7 +78,10 @@ impl NeoReactor {
|
||||
Entry::Vacant(vac) => {
|
||||
let current_config: Config = (*thread_config_tx.borrow()).clone();
|
||||
if let Some(config) = current_config.cameras.iter().find(|cam| cam.name == name).cloned() {
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let cam = NeoCam::new(config, push_noti.clone()).await?;
|
||||
#[cfg(not(feature = "pushnoti"))]
|
||||
let cam = NeoCam::new(config).await?;
|
||||
Result::Ok(Some(
|
||||
vac.insert(
|
||||
cam,
|
||||
@@ -113,31 +121,34 @@ impl NeoReactor {
|
||||
});
|
||||
|
||||
// Push notification client
|
||||
let cancel1 = cancel.clone();
|
||||
let mut thread_config_rx = config_tx.subscribe();
|
||||
set.spawn(async move {
|
||||
let r = tokio::select! {
|
||||
_ = cancel1.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let cancel1 = cancel.clone();
|
||||
let mut thread_config_rx = config_tx.subscribe();
|
||||
set.spawn(async move {
|
||||
let r = tokio::select! {
|
||||
_ = cancel1.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
|
||||
let mut pn = PushNotiThread::new().await?;
|
||||
loop {
|
||||
thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled
|
||||
let r = tokio::select!{
|
||||
v = pn.run(&pn_tx, &mut pn_rx) => {v},
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Issue with push notifier: {r:?}");
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
} else {
|
||||
log::debug!("Push notifier reported normal shutdown. Restarting");
|
||||
let mut pn = PushNotiThread::new().await?;
|
||||
loop {
|
||||
thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled
|
||||
let r = tokio::select!{
|
||||
v = pn.run(&pn_tx, &mut pn_rx) => {v},
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Issue with push notifier: {r:?}");
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
} else {
|
||||
log::debug!("Push notifier reported normal shutdown. Restarting");
|
||||
}
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
};
|
||||
r
|
||||
});
|
||||
} => v,
|
||||
};
|
||||
r
|
||||
});
|
||||
}
|
||||
|
||||
Self {
|
||||
cancel,
|
||||
|
||||
+48
-23
@@ -316,11 +316,13 @@ impl StreamInstance {
|
||||
|
||||
impl StreamData {
|
||||
async fn new(name: StreamKind, instance: NeoInstance, strict: bool) -> Result<Self> {
|
||||
const BUFFER_DURATION: Duration = Duration::from_secs(3);
|
||||
let buffer_duration =
|
||||
Duration::from_millis(instance.config().await?.borrow().buffer_duration);
|
||||
log::trace!("New StreamData::{name:?}");
|
||||
// At 30fps for 15s with audio is is about 900 frames
|
||||
const BUFFER_SIZE: usize = 30usize * BUFFER_DURATION.as_millis() as usize / 1000usize;
|
||||
let (vid, _) = broadcast::<StampedData>(BUFFER_SIZE);
|
||||
let (aud, _) = broadcast::<StampedData>(BUFFER_SIZE);
|
||||
let buffer_size: usize = 30usize * buffer_duration.as_millis() as usize / 1000usize;
|
||||
let (vid, _) = broadcast::<StampedData>(buffer_size);
|
||||
let (aud, _) = broadcast::<StampedData>(buffer_size);
|
||||
let (vid_history, _) = watch::<VecDeque<StampedData>>(VecDeque::new());
|
||||
let vid_history = Arc::new(vid_history);
|
||||
let (aud_history, _) = watch::<VecDeque<StampedData>>(VecDeque::new());
|
||||
@@ -395,6 +397,8 @@ impl StreamData {
|
||||
users: UseCounter::new().await,
|
||||
};
|
||||
|
||||
let mut self_use = me.users.create_activated().await?; // Take out our own use handle until buffer is ready
|
||||
|
||||
let cancel = me.cancel.clone();
|
||||
let vid = me.vid.clone();
|
||||
let aud = me.aud.clone();
|
||||
@@ -413,8 +417,11 @@ impl StreamData {
|
||||
// create a new one from the fps
|
||||
// this makes it easier to play the frames at a constant rate
|
||||
// even across reconnects (since reconnects restart the ts otherwise)
|
||||
let mut master_ts = Duration::ZERO;
|
||||
let mut fps_delta = Duration::from_millis(1000 / (config.borrow().fps as u64));
|
||||
// These are arc mutex to allow tthem to maintain their value across reconnects (else we get an implicit copy)
|
||||
let master_ts = Arc::new(tokio::sync::RwLock::new(Duration::ZERO));
|
||||
let fps_delta = Arc::new(tokio::sync::RwLock::new(Duration::from_millis(
|
||||
1000 / (config.borrow().fps as u64),
|
||||
)));
|
||||
|
||||
me.handle = Some(tokio::task::spawn(async move {
|
||||
let r = tokio::select! {
|
||||
@@ -453,10 +460,14 @@ impl StreamData {
|
||||
tokio::select! {
|
||||
v = thread_inuse.dropped_users() => {
|
||||
// Handles the stop and restart when no active users
|
||||
log::trace!("Stopping StreamThread Permit");
|
||||
permit.deactivate().await?;
|
||||
v?;
|
||||
log::trace!("Waiting for streamthread aquire users");
|
||||
thread_inuse.aquired_users().await?; // Wait for new users of the stream
|
||||
log::trace!("Actictating streamthread permit");
|
||||
permit.activate().await?;
|
||||
log::trace!("Stream thread should now restart");
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
_ = watchdog_eat_rx => {
|
||||
@@ -471,8 +482,11 @@ impl StreamData {
|
||||
let aud_history = aud_history.clone();
|
||||
let watchdog_tx = watchdog_tx.clone();
|
||||
let fps_table = fps_table.clone();
|
||||
let master_ts = master_ts.clone();
|
||||
let fps_delta = fps_delta.clone();
|
||||
|
||||
Box::pin(async move {
|
||||
log::trace!("Starting streamthread TASK");
|
||||
// use std::io::Write;
|
||||
// let mut file = std::fs::File::create("reference.h264")?;
|
||||
let mut recieved_iframe = false;
|
||||
@@ -498,7 +512,9 @@ impl StreamData {
|
||||
false
|
||||
}
|
||||
});
|
||||
fps_delta = Duration::from_millis(1000 / (stream_config.borrow().fps as u64));
|
||||
// seperate the borrow so we don't hold it over an await
|
||||
let new_delta = Duration::from_millis(1000 / (stream_config.borrow().fps as u64));
|
||||
*fps_delta.write().await = new_delta;
|
||||
},
|
||||
BcMedia::InfoV2(info) => {
|
||||
stream_config.send_if_modified(|state| {
|
||||
@@ -512,7 +528,9 @@ impl StreamData {
|
||||
false
|
||||
}
|
||||
});
|
||||
fps_delta = Duration::from_millis(1000 / (stream_config.borrow().fps as u64));
|
||||
// seperate the borrow so we don't hold it over an await
|
||||
let new_delta = Duration::from_millis(1000 / (stream_config.borrow().fps as u64));
|
||||
*fps_delta.write().await = new_delta;
|
||||
},
|
||||
BcMedia::Iframe(frame) => {
|
||||
stream_config.send_if_modified(|state| {
|
||||
@@ -572,56 +590,58 @@ impl StreamData {
|
||||
let d = StampedData{
|
||||
keyframe: true,
|
||||
data: Arc::new(data),
|
||||
ts: master_ts,
|
||||
ts: *master_ts.read().await,
|
||||
};
|
||||
let _ = vid_tx.send(d.clone());
|
||||
vid_history.send_modify(|history| {
|
||||
let drop_time = d.ts.saturating_sub(BUFFER_DURATION);
|
||||
let drop_time = d.ts.saturating_sub(buffer_duration);
|
||||
let dts = d.ts;
|
||||
history.push_back(d);
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE {
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > buffer_size {
|
||||
history.pop_front();
|
||||
}
|
||||
log::info!("history: {}", history.len());
|
||||
log::trace!("history: {}", history.len());
|
||||
let debug: Vec<Duration> = history.iter().map(|f| f.ts).collect();
|
||||
log::info!("history ts: {:?}", debug);
|
||||
log::trace!("history ts: {:?}", debug);
|
||||
});
|
||||
recieved_iframe = true;
|
||||
aud_keyframe = true;
|
||||
log::trace!("Sent Vid Key Frame");
|
||||
master_ts += fps_delta;
|
||||
log::trace!("Sent Vid Key Frame: {:?}", master_ts.read().await);
|
||||
*master_ts.write().await += *fps_delta.read().await;
|
||||
},
|
||||
BcMedia::Pframe(BcMediaPframe{data, ..}) if recieved_iframe => {
|
||||
let d = StampedData{
|
||||
keyframe: false,
|
||||
data: Arc::new(data),
|
||||
ts: master_ts,
|
||||
ts: *master_ts.read().await,
|
||||
};
|
||||
let _ = vid_tx.send(d.clone());
|
||||
vid_history.send_modify(|history| {
|
||||
let drop_time = d.ts.saturating_sub(BUFFER_DURATION);
|
||||
let drop_time = d.ts.saturating_sub(buffer_duration);
|
||||
let dts = d.ts;
|
||||
history.push_back(d);
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE {
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > buffer_size {
|
||||
history.pop_front();
|
||||
}
|
||||
});
|
||||
master_ts += fps_delta;
|
||||
log::trace!("Sent Vid Frame");
|
||||
*master_ts.write().await += *fps_delta.read().await;
|
||||
log::trace!("Sent Vid Frame: {:?}", master_ts.read().await);
|
||||
}
|
||||
BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) if recieved_iframe => {
|
||||
let m_ts = *master_ts.read().await;
|
||||
let d = StampedData{
|
||||
keyframe: aud_keyframe,
|
||||
data: Arc::new(data),
|
||||
ts: master_ts,
|
||||
ts: m_ts,
|
||||
};
|
||||
aud_keyframe = false;
|
||||
let _ = aud_tx.send(d.clone())?;
|
||||
let last_vid_ts: Duration = vid_history.borrow().front().map(|vi| vi.ts).unwrap_or(m_ts);
|
||||
aud_history.send_modify(|history| {
|
||||
let drop_time = d.ts.saturating_sub(BUFFER_DURATION);
|
||||
let drop_time = std::cmp::max(d.ts.saturating_sub(buffer_duration), last_vid_ts);
|
||||
let dts = d.ts;
|
||||
history.push_back(d);
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > BUFFER_SIZE {
|
||||
while history.front().is_some_and(|di| di.ts < drop_time || di.ts > dts) || history.len() > buffer_size {
|
||||
history.pop_front();
|
||||
}
|
||||
});
|
||||
@@ -651,6 +671,11 @@ impl StreamData {
|
||||
}
|
||||
},
|
||||
}?;
|
||||
|
||||
// Deactivate our use handle if the vid buffer is ready
|
||||
if vid_history.borrow().len() >= buffer_size {
|
||||
self_use.deactivate().await?;
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
};
|
||||
|
||||
@@ -63,6 +63,7 @@ impl UseCounter {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) async fn create_deactivated(&self) -> Result<Permit> {
|
||||
Ok(Permit::new(self))
|
||||
}
|
||||
@@ -87,6 +88,7 @@ pub(crate) struct Permit {
|
||||
}
|
||||
|
||||
impl Permit {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn subscribe(&self) -> Self {
|
||||
Self {
|
||||
is_active: false,
|
||||
@@ -141,6 +143,7 @@ impl Permit {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn get_counter(&self) -> WatchReceiver<u32> {
|
||||
self.value.clone()
|
||||
}
|
||||
|
||||
+24
-14
@@ -1,12 +1,14 @@
|
||||
use crate::mqtt::Discoveries;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat, StreamKind};
|
||||
#[cfg(feature = "gstreamer")]
|
||||
use neolink_core::bc_protocol::StreamKind;
|
||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::clone::Clone;
|
||||
use std::collections::HashSet;
|
||||
use validator::Validate;
|
||||
use validator::ValidationError;
|
||||
use validator_derive::Validate;
|
||||
|
||||
static RE_TLS_CLIENT_AUTH: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^(none|request|require)$").unwrap());
|
||||
@@ -17,7 +19,7 @@ static RE_MAXENC_SRC: Lazy<Regex> = Lazy::new(|| {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq)]
|
||||
pub(crate) struct Config {
|
||||
#[validate]
|
||||
#[validate(nested)]
|
||||
pub(crate) cameras: Vec<CameraConfig>,
|
||||
|
||||
#[serde(rename = "bind", default = "default_bind_addr")]
|
||||
@@ -44,7 +46,7 @@ pub(crate) struct Config {
|
||||
#[serde(default = "default_tls_client_auth")]
|
||||
pub(crate) tls_client_auth: String,
|
||||
|
||||
#[validate]
|
||||
#[validate(nested)]
|
||||
#[serde(default)]
|
||||
pub(crate) users: Vec<UserConfig>,
|
||||
}
|
||||
@@ -99,6 +101,7 @@ pub(crate) enum StreamConfig {
|
||||
}
|
||||
|
||||
impl StreamConfig {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
pub(crate) fn as_stream_kinds(&self) -> Vec<StreamKind> {
|
||||
match self {
|
||||
StreamConfig::All => {
|
||||
@@ -135,6 +138,8 @@ pub(crate) struct CameraConfig {
|
||||
pub(crate) camera_uid: Option<String>,
|
||||
|
||||
pub(crate) username: String,
|
||||
|
||||
#[serde(alias = "pass")]
|
||||
pub(crate) password: Option<String>,
|
||||
|
||||
#[serde(default = "default_stream")]
|
||||
@@ -146,11 +151,11 @@ pub(crate) struct CameraConfig {
|
||||
#[serde(default = "default_channel_id", alias = "channel")]
|
||||
pub(crate) channel_id: u8,
|
||||
|
||||
#[validate]
|
||||
#[validate(nested)]
|
||||
#[serde(default = "default_mqtt")]
|
||||
pub(crate) mqtt: MqttConfig,
|
||||
|
||||
#[validate]
|
||||
#[validate(nested)]
|
||||
#[serde(default = "default_pause")]
|
||||
pub(crate) pause: PauseConfig,
|
||||
|
||||
@@ -176,13 +181,18 @@ pub(crate) struct CameraConfig {
|
||||
pub(crate) update_time: bool,
|
||||
|
||||
#[validate(range(
|
||||
min = 0,
|
||||
max = 500,
|
||||
message = "Invalid buffer size",
|
||||
code = "buffer_size"
|
||||
min = 1,
|
||||
max = 15000,
|
||||
message = "Invalid buffer duration (it's in ms)",
|
||||
code = "buffer_duration"
|
||||
))]
|
||||
#[serde(default = "default_buffer_size", alias = "size", alias = "buffer")]
|
||||
pub(crate) buffer_size: usize,
|
||||
/// Buffer duration in ms
|
||||
#[serde(
|
||||
default = "default_buffer_duration",
|
||||
alias = "duration",
|
||||
alias = "buffer"
|
||||
)]
|
||||
pub(crate) buffer_duration: u64,
|
||||
|
||||
#[serde(default = "default_true", alias = "enable")]
|
||||
pub(crate) enabled: bool,
|
||||
@@ -488,8 +498,8 @@ fn default_pause() -> PauseConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_buffer_size() -> usize {
|
||||
25
|
||||
fn default_buffer_duration() -> u64 {
|
||||
3000
|
||||
}
|
||||
|
||||
fn default_max_discovery_retries() -> usize {
|
||||
|
||||
+18
-1
@@ -40,14 +40,17 @@ mod battery;
|
||||
mod cmdline;
|
||||
mod common;
|
||||
mod config;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod image;
|
||||
mod mqtt;
|
||||
mod pir;
|
||||
mod ptz;
|
||||
mod reboot;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod rtsp;
|
||||
mod services;
|
||||
mod statusled;
|
||||
#[cfg(feature = "gstreamer")]
|
||||
mod talk;
|
||||
mod utils;
|
||||
|
||||
@@ -83,13 +86,24 @@ async fn main() -> Result<()> {
|
||||
let neo_reactor = NeoReactor::new(config.clone()).await;
|
||||
|
||||
match opt.cmd {
|
||||
#[cfg(feature = "gstreamer")]
|
||||
None => {
|
||||
warn!(
|
||||
"Deprecated command line option. Please use: `neolink rtsp --config={:?}`",
|
||||
config
|
||||
conf_path
|
||||
);
|
||||
rtsp::main(rtsp::Opt {}, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(not(feature = "gstreamer"))]
|
||||
None => {
|
||||
// When gstreamer is disabled the default command is MQTT
|
||||
warn!(
|
||||
"Deprecated command line option. Please use: `neolink mqtt --config={:?}`",
|
||||
conf_path
|
||||
);
|
||||
mqtt::main(mqtt::Opt {}, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Rtsp(opts)) => {
|
||||
rtsp::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
@@ -105,18 +119,21 @@ async fn main() -> Result<()> {
|
||||
Some(Command::Ptz(opts)) => {
|
||||
ptz::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Talk(opts)) => {
|
||||
talk::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
Some(Command::Mqtt(opts)) => {
|
||||
mqtt::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::MqttRtsp(opts)) => {
|
||||
tokio::select! {
|
||||
v = mqtt::main(opts, neo_reactor.clone()) => v,
|
||||
v = rtsp::main(rtsp::Opt {}, neo_reactor.clone()) => v,
|
||||
}?;
|
||||
}
|
||||
#[cfg(feature = "gstreamer")]
|
||||
Some(Command::Image(opts)) => {
|
||||
image::main(opts, neo_reactor.clone()).await?;
|
||||
}
|
||||
|
||||
+29
-22
@@ -298,7 +298,9 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
let camera_motion = camera.clone();
|
||||
let mqtt_motion = mqtt_instance.resubscribe().await?;
|
||||
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let camera_pn = camera.clone();
|
||||
#[cfg(feature = "pushnoti")]
|
||||
let mqtt_pn = mqtt_instance.resubscribe().await?;
|
||||
|
||||
let camera_snap = camera.clone();
|
||||
@@ -458,7 +460,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}).await;
|
||||
let image = match image {
|
||||
Err(e) => match e.downcast::<neolink_core::Error>() {
|
||||
Ok(neolink_core::Error::CameraServiceUnavailable(_)) => {
|
||||
Ok(neolink_core::Error::CameraServiceUnavailable{..}) => {
|
||||
log::debug!("Image not supported");
|
||||
futures::future::pending().await
|
||||
},
|
||||
@@ -502,7 +504,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}).await;
|
||||
let xml = match xml {
|
||||
Err(e) => match e.downcast::<neolink_core::Error>() {
|
||||
Ok(neolink_core::Error::CameraServiceUnavailable(_)) => {
|
||||
Ok(neolink_core::Error::CameraServiceUnavailable{..}) => {
|
||||
log::debug!("Battery not supported");
|
||||
futures::future::pending().await
|
||||
},
|
||||
@@ -530,27 +532,32 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}, if config.enable_battery => v,
|
||||
// Handle the push notification messages
|
||||
v = async {
|
||||
let mut pn = camera_pn.push_notifications().await?;
|
||||
let mut prev_noti = None;
|
||||
loop {
|
||||
let v = async {
|
||||
let noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.with_context(|| {
|
||||
format!("{}: PushNoti Watch Dropped", camera_name)
|
||||
})?.clone();
|
||||
mqtt_pn.send_message("status/notification", ¬i.as_ref().unwrap().message, true).await.with_context(|| {
|
||||
format!("{}: Failed to publish push notification", camera_name)
|
||||
})?;
|
||||
prev_noti = noti;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
Err(Ok(e)) => Err(e.into()),
|
||||
Err(Err(e)) => Err (e),
|
||||
}?;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let mut pn = camera_pn.push_notifications().await?;
|
||||
let mut prev_noti = None;
|
||||
loop {
|
||||
let v = async {
|
||||
let noti = pn.wait_for(|noti| noti != &prev_noti && noti.is_some()).await.with_context(|| {
|
||||
format!("{}: PushNoti Watch Dropped", camera_name)
|
||||
})?.clone();
|
||||
mqtt_pn.send_message("status/notification", ¬i.as_ref().unwrap().message, true).await.with_context(|| {
|
||||
format!("{}: Failed to publish push notification", camera_name)
|
||||
})?;
|
||||
prev_noti = noti;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
Err(Ok(e)) => Err(e.into()),
|
||||
Err(Err(e)) => Err (e),
|
||||
}?;
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
#[cfg(not(feature = "pushnoti"))]
|
||||
unreachable!()
|
||||
}, if cfg!(feature = "pushnoti") => v,
|
||||
// Handle the floodlight task activation
|
||||
v = async {
|
||||
let flt_status = camera_floodlight_tasks.run_passive_task(|cam| Box::pin(async move {
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ use tokio::{
|
||||
};
|
||||
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) struct Mqtt {
|
||||
cancel: CancellationToken,
|
||||
@@ -125,7 +126,7 @@ impl<'a> MqttBackend<'a> {
|
||||
async fn run(&mut self) -> AnyResult<()> {
|
||||
log::trace!("Run MQTT Server");
|
||||
let mut mqttoptions = MqttOptions::new(
|
||||
"Neolink".to_string(),
|
||||
format!("Neolink{}", Uuid::new_v4()),
|
||||
&self.config.broker_addr,
|
||||
self.config.port,
|
||||
);
|
||||
@@ -519,7 +520,7 @@ impl LastWillMqtt {
|
||||
) -> AnyResult<Self> {
|
||||
log::trace!("Run MQTT Last Will");
|
||||
let mut mqttoptions = MqttOptions::new(
|
||||
format!("NeolinkLastWill_{}", topic),
|
||||
format!("NeolinkLastWill_{}_{}", topic, Uuid::new_v4()),
|
||||
&config.broker_addr,
|
||||
config.port,
|
||||
);
|
||||
|
||||
+190
-24
@@ -155,9 +155,14 @@ fn build_unknown(bin: &Element, pattern: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
struct Linked {
|
||||
appsrc: AppSrc,
|
||||
output: Element,
|
||||
}
|
||||
|
||||
fn pipe_h264(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::info!(
|
||||
log::debug!(
|
||||
"buffer_size: {buffer_size}, bitrate: {}",
|
||||
stream_config.bitrate
|
||||
);
|
||||
@@ -184,17 +189,34 @@ fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let queue = make_queue("source_queue", buffer_size)?;
|
||||
let parser = make_element("h264parse", "parser")?;
|
||||
// let stamper = make_element("h264timestamper", "stamper")?;
|
||||
let payload = make_element("rtph264pay", "pay0")?;
|
||||
bin.add_many([&source, &queue, &parser, &payload])?;
|
||||
Element::link_many([&source, &queue, &parser, &payload])?;
|
||||
|
||||
bin.add_many([&source, &queue, &parser])?;
|
||||
Element::link_many([&source, &queue, &parser])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
Ok(source)
|
||||
Ok(Linked {
|
||||
appsrc: source,
|
||||
output: parser,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let linked = pipe_h264(bin, stream_config)?;
|
||||
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
|
||||
let payload = make_element("rtph264pay", "pay0")?;
|
||||
bin.add_many([&payload])?;
|
||||
Element::link_many([&linked.output, &payload])?;
|
||||
Ok(linked.appsrc)
|
||||
}
|
||||
|
||||
fn pipe_h265(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
let bin = bin
|
||||
.clone()
|
||||
@@ -218,18 +240,36 @@ fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let queue = make_queue("source_queue", buffer_size)?;
|
||||
let parser = make_element("h265parse", "parser")?;
|
||||
// let stamper = make_element("h265timestamper", "stamper")?;
|
||||
let payload = make_element("rtph265pay", "pay0")?;
|
||||
bin.add_many([&source, &queue, &parser, &payload])?;
|
||||
Element::link_many([&source, &queue, &parser, &payload])?;
|
||||
|
||||
bin.add_many([&source, &queue, &parser])?;
|
||||
Element::link_many([&source, &queue, &parser])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
Ok(source)
|
||||
Ok(Linked {
|
||||
appsrc: source,
|
||||
output: parser,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = 512 * 6;
|
||||
fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let linked = pipe_h265(bin, stream_config)?;
|
||||
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
|
||||
let payload = make_element("rtph265pay", "pay0")?;
|
||||
bin.add_many([&payload])?;
|
||||
Element::link_many([&linked.output, &payload])?;
|
||||
Ok(linked.appsrc)
|
||||
}
|
||||
|
||||
fn pipe_aac(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {
|
||||
// Audio seems to run at about 800kbs
|
||||
let buffer_size = 512 * 1416;
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
@@ -268,9 +308,8 @@ fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
}
|
||||
|
||||
let encoder = make_element("audioconvert", "audencoder")?;
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
|
||||
bin.add_many([&source, &queue, &parser, &decoder, &encoder, &payload])?;
|
||||
bin.add_many([&source, &queue, &parser, &decoder, &encoder])?;
|
||||
if let Ok(fallback_switch) = fallback_switch.as_ref() {
|
||||
bin.add_many([&silence, fallback_switch])?;
|
||||
Element::link_many([
|
||||
@@ -280,21 +319,37 @@ fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
&decoder,
|
||||
fallback_switch,
|
||||
&encoder,
|
||||
&payload,
|
||||
])?;
|
||||
Element::link_many([&silence, fallback_switch])?;
|
||||
} else {
|
||||
Element::link_many([&source, &queue, &parser, &decoder, &encoder, &payload])?;
|
||||
Element::link_many([&source, &queue, &parser, &decoder, &encoder])?;
|
||||
}
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
Ok(source)
|
||||
Ok(Linked {
|
||||
appsrc: source,
|
||||
output: encoder,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = 512 * 6;
|
||||
fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let linked = pipe_aac(bin, stream_config)?;
|
||||
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
bin.add_many([&payload])?;
|
||||
Element::link_many([&linked.output, &payload])?;
|
||||
Ok(linked.appsrc)
|
||||
}
|
||||
|
||||
fn pipe_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result<Linked> {
|
||||
let buffer_size = 512 * 1416;
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
@@ -334,11 +389,10 @@ fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) ->
|
||||
let queue = make_queue("audqueue", buffer_size)?;
|
||||
let decoder = make_element("decodebin", "auddecoder")?;
|
||||
let encoder = make_element("audioconvert", "audencoder")?;
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
let encoder_out = encoder.clone();
|
||||
|
||||
bin.add_many([&source, &queue, &decoder, &encoder, &payload])?;
|
||||
bin.add_many([&source, &queue, &decoder, &encoder])?;
|
||||
Element::link_many([&source, &queue, &decoder])?;
|
||||
Element::link_many([&encoder, &payload])?;
|
||||
decoder.connect_pad_added(move |_element, pad| {
|
||||
let sink_pad = encoder
|
||||
.static_pad("sink")
|
||||
@@ -350,7 +404,119 @@ fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) ->
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
Ok(source)
|
||||
Ok(Linked {
|
||||
appsrc: source,
|
||||
output: encoder_out,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let linked = pipe_adpcm(bin, block_size, stream_config)?;
|
||||
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
bin.add_many([&payload])?;
|
||||
Element::link_many([&linked.output, &payload])?;
|
||||
Ok(linked.appsrc)
|
||||
}
|
||||
|
||||
fn pipe_silence(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {
|
||||
// Audio seems to run at about 800kbs
|
||||
let buffer_size = 512 * 1416;
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
log::debug!("Building Silence pipeline");
|
||||
let source = make_element("appsrc", "audsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
|
||||
source.set_is_live(false);
|
||||
source.set_block(false);
|
||||
source.set_min_latency(1000 / (stream_config.fps as i64));
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(buffer_size as u64);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Seekable);
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
|
||||
let sink_queue = make_queue("audsinkqueue", buffer_size)?;
|
||||
let sink = make_element("fakesink", "silence_sink")?;
|
||||
|
||||
let silence = make_element("audiotestsrc", "audsilence")?;
|
||||
silence.set_property_from_str("wave", "silence");
|
||||
let src_queue = make_queue("audsinkqueue", buffer_size)?;
|
||||
let encoder = make_element("audioconvert", "audencoder")?;
|
||||
|
||||
bin.add_many([&source, &sink_queue, &sink, &silence, &src_queue, &encoder])?;
|
||||
|
||||
Element::link_many([&source, &sink_queue, &sink])?;
|
||||
|
||||
Element::link_many([&silence, &src_queue, &encoder])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
Ok(Linked {
|
||||
appsrc: source,
|
||||
output: encoder,
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct AppSrcPair {
|
||||
vid: AppSrc,
|
||||
aud: Option<AppSrc>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Experimental build a stream of MPEGTS
|
||||
fn build_mpegts(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrcPair> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::debug!(
|
||||
"buffer_size: {buffer_size}, bitrate: {}",
|
||||
stream_config.bitrate
|
||||
);
|
||||
|
||||
// VID
|
||||
let vid_link = match stream_config.vid_format {
|
||||
VidFormat::H264 => pipe_h264(bin, stream_config)?,
|
||||
VidFormat::H265 => pipe_h265(bin, stream_config)?,
|
||||
VidFormat::None => unreachable!(),
|
||||
};
|
||||
|
||||
// AUD
|
||||
let aud_link = match stream_config.aud_format {
|
||||
AudFormat::Aac => pipe_aac(bin, stream_config)?,
|
||||
AudFormat::Adpcm(block) => pipe_adpcm(bin, block, stream_config)?,
|
||||
AudFormat::None => pipe_silence(bin, stream_config)?,
|
||||
};
|
||||
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
|
||||
// MUX
|
||||
let muxer = make_element("mpegtsmux", "mpeg_muxer")?;
|
||||
let rtp = make_element("rtpmp2tpay", "pay0")?;
|
||||
|
||||
bin.add_many([&muxer, &rtp])?;
|
||||
Element::link_many([&vid_link.output, &muxer, &rtp])?;
|
||||
Element::link_many([&aud_link.output, &muxer])?;
|
||||
|
||||
Ok(AppSrcPair {
|
||||
vid: vid_link.appsrc,
|
||||
aud: Some(aud_link.appsrc),
|
||||
})
|
||||
}
|
||||
|
||||
// Convenice funcion to make an element or provide a message
|
||||
|
||||
+10
-5
@@ -47,10 +47,13 @@ impl NeoRtspServer {
|
||||
// Setup auth
|
||||
let auth = factory.auth().unwrap_or_default();
|
||||
auth.set_supported_methods(RTSPAuthMethod::Basic);
|
||||
let mut un_authtoken = RTSPToken::new(&[
|
||||
//RTSP_TOKEN_MEDIA_FACTORY_ROLE: Means look inside the media factory settings and use the same permissions this user (`"anonymous"`) has
|
||||
(RTSP_TOKEN_MEDIA_FACTORY_ROLE, &"anonymous"),
|
||||
]);
|
||||
let mut un_authtoken = RTSPToken::builder()
|
||||
.field(
|
||||
//RTSP_TOKEN_MEDIA_FACTORY_ROLE: Means look inside the media factory settings and use the same permissions this user (`"anonymous"`) has
|
||||
RTSP_TOKEN_MEDIA_FACTORY_ROLE,
|
||||
"anonymous",
|
||||
)
|
||||
.build();
|
||||
auth.set_default_token(Some(&mut un_authtoken));
|
||||
factory.set_auth(Some(&auth));
|
||||
|
||||
@@ -217,7 +220,9 @@ impl NeoRtspServerImpl {
|
||||
let mut locked_users = self.users.write().await;
|
||||
let auth = self.obj().auth().unwrap();
|
||||
|
||||
let token = RTSPToken::new(&[(RTSP_TOKEN_MEDIA_FACTORY_ROLE, &username)]);
|
||||
let token = RTSPToken::builder()
|
||||
.field(RTSP_TOKEN_MEDIA_FACTORY_ROLE, username)
|
||||
.build();
|
||||
let basic = RTSPAuth::make_basic(username, password);
|
||||
|
||||
if let Some(old_basic) = locked_users.get(username) {
|
||||
|
||||
+100
-88
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
use tokio::{
|
||||
sync::{broadcast::channel as broadcast, watch::channel as watch},
|
||||
task::JoinSet,
|
||||
time::{interval, sleep, Duration},
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
use tokio_stream::{wrappers::BroadcastStream, Stream, StreamExt};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -79,7 +79,7 @@ pub(super) async fn stream_main(
|
||||
let client_count = client_counter.create_deactivated().await?;
|
||||
|
||||
// Client count affector
|
||||
if curr_pause.on_motion {
|
||||
if curr_pause.on_disconnect {
|
||||
let thread_name = name.clone();
|
||||
let client_count = client_counter.create_deactivated().await?;
|
||||
let thread_pause_affector_tx = pause_affector_tx.clone();
|
||||
@@ -143,40 +143,43 @@ pub(super) async fn stream_main(
|
||||
});
|
||||
|
||||
// Push notfications
|
||||
let mut pn = camera.push_notifications().await?;
|
||||
let mut curr_pn = None;
|
||||
let thread_name = name.clone();
|
||||
let thread_pause_affector_tx = pause_affector_tx.clone();
|
||||
let cancel = this_loop_cancel.clone();
|
||||
set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
loop {
|
||||
curr_pn = pn
|
||||
.wait_for(|pn| pn != &curr_pn && pn.is_some())
|
||||
.await?
|
||||
.clone();
|
||||
log::info!("{}: Enabling Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = true;
|
||||
});
|
||||
tokio::select! {
|
||||
v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => {
|
||||
v?;
|
||||
// If another PN during wait then go back to wait more
|
||||
continue;
|
||||
#[cfg(feature = "pushnoti")]
|
||||
{
|
||||
let mut pn = camera.push_notifications().await?;
|
||||
let mut curr_pn = None;
|
||||
let thread_name = name.clone();
|
||||
let thread_pause_affector_tx = pause_affector_tx.clone();
|
||||
let cancel = this_loop_cancel.clone();
|
||||
set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
loop {
|
||||
curr_pn = pn
|
||||
.wait_for(|pn| pn != &curr_pn && pn.is_some())
|
||||
.await?
|
||||
.clone();
|
||||
log::info!("{}: Enabling Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = true;
|
||||
});
|
||||
tokio::select! {
|
||||
v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => {
|
||||
v?;
|
||||
// If another PN during wait then go back to wait more
|
||||
continue;
|
||||
}
|
||||
_ = sleep(Duration::from_secs(30)) => {}
|
||||
}
|
||||
_ = sleep(Duration::from_secs(30)) => {}
|
||||
log::info!("{}: Pausing Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = false;
|
||||
});
|
||||
}
|
||||
log::info!("{}: Pausing Push Notification", thread_name);
|
||||
thread_pause_affector_tx.send_modify(|current| {
|
||||
current.push = false;
|
||||
});
|
||||
}
|
||||
} => v,
|
||||
}
|
||||
});
|
||||
} => v,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if curr_pause.on_motion || curr_pause.on_disconnect {
|
||||
@@ -253,6 +256,7 @@ pub(super) async fn stream_main(
|
||||
v = async {
|
||||
loop {
|
||||
cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?;
|
||||
log::trace!("cur_count: {cur_count:?}");
|
||||
}
|
||||
} => v,
|
||||
}
|
||||
@@ -412,6 +416,7 @@ async fn stream_run(
|
||||
let thread_vid = vid.clone();
|
||||
let mut thread_client_count = client_count.subscribe();
|
||||
let thread_format = stream_config.vid_format;
|
||||
let (ts_tx, ts_rx) = tokio::sync::watch::channel(Duration::ZERO);
|
||||
// let fallback_time = Duration::from_secs(3);
|
||||
let framerate =
|
||||
Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64));
|
||||
@@ -424,18 +429,19 @@ async fn stream_run(
|
||||
},
|
||||
v = send_to_appsrc(
|
||||
pad_vid(
|
||||
insert_filler(
|
||||
// insert_filler(
|
||||
frametime_stream(
|
||||
// ensure_order(
|
||||
sync_stream(
|
||||
wait_for_keyframe(
|
||||
vid_data_rx,
|
||||
),
|
||||
// ),
|
||||
ts_tx,
|
||||
),
|
||||
framerate
|
||||
),
|
||||
thread_format,
|
||||
framerate,
|
||||
),
|
||||
// thread_format,
|
||||
// framerate,
|
||||
// ),
|
||||
thread_format,
|
||||
),
|
||||
&thread_vid
|
||||
@@ -463,11 +469,12 @@ async fn stream_run(
|
||||
},
|
||||
v = send_to_appsrc(
|
||||
frametime_stream(
|
||||
// ensure_order(
|
||||
hold_stream(
|
||||
wait_for_keyframe(
|
||||
aud_data_rx
|
||||
),
|
||||
// ),
|
||||
ts_rx,
|
||||
),
|
||||
aud_framerate),
|
||||
&thread_aud) => {
|
||||
v
|
||||
@@ -527,32 +534,49 @@ fn wait_for_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
// Take a stream of stamped data and release them
|
||||
// in waves when a new key frame is found
|
||||
// this ensure that the last frame sent is always an IFrame
|
||||
// only when they are after a certain time stamp
|
||||
// This time stamp is sent via a shared watcher
|
||||
//
|
||||
// This is used to ensure that the audio does not run
|
||||
// ahead of the video too much
|
||||
fn hold_stream<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
mut stream: T,
|
||||
mut vid_ts: tokio::sync::watch::Receiver<Duration>,
|
||||
) -> impl Stream<Item = AnyResult<StampedData>> + Unpin {
|
||||
Box::pin(async_stream::stream! {
|
||||
let mut held_frames = vec![];
|
||||
while let Some(frame) = stream.next().await {
|
||||
if let Ok(frame) = frame {
|
||||
if frame.keyframe {
|
||||
// Release
|
||||
for held_frame in held_frames.drain(..) {
|
||||
yield Ok(held_frame);
|
||||
}
|
||||
if frame.ts >= *vid_ts.borrow() {
|
||||
yield Ok(frame);
|
||||
} else {
|
||||
// Hold
|
||||
held_frames.push(frame);
|
||||
// Can't seem to throw an error here as it will cause
|
||||
// a borrow checker to hold over the await
|
||||
let _ = vid_ts.wait_for(|o| *o >= frame.ts).await;
|
||||
yield Ok(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// This is the counter part to [`hold_stream`]
|
||||
///
|
||||
/// It just updates the ts in the watcher
|
||||
fn sync_stream<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
mut stream: T,
|
||||
vid_ts: tokio::sync::watch::Sender<Duration>,
|
||||
) -> impl Stream<Item = AnyResult<StampedData>> + Unpin {
|
||||
Box::pin(async_stream::stream! {
|
||||
while let Some(frame) = stream.next().await {
|
||||
if let Ok(frame) = frame {
|
||||
vid_ts.send_replace(frame.ts);
|
||||
yield Ok(frame);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Take a stream of stamped data and reorder it
|
||||
// in case they are out of order
|
||||
// this also releases frames in waves of keyframe so it should replace `hold_stream`
|
||||
@@ -589,23 +613,27 @@ fn ensure_order<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
|
||||
// Take a stream of stamped data pause until
|
||||
// it is time to display it
|
||||
#[allow(dead_code)]
|
||||
fn frametime_stream<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
mut stream: T,
|
||||
expected_frame_rate: Duration,
|
||||
) -> impl Stream<Item = AnyResult<StampedData>> + Unpin {
|
||||
Box::pin(async_stream::stream! {
|
||||
let mut waiter = interval(expected_frame_rate);
|
||||
waiter.set_missed_tick_behavior( tokio::time::MissedTickBehavior::Skip);
|
||||
let mut ts_before = Duration::MAX;
|
||||
while let Some(frame) = stream.next().await {
|
||||
if let Ok(frame) = frame {
|
||||
waiter.tick().await;
|
||||
if frame.ts < ts_before {
|
||||
ts_before = frame.ts;
|
||||
}
|
||||
let wait = std::cmp::min(frame.ts.saturating_sub(ts_before), expected_frame_rate);
|
||||
tokio::time::sleep(wait).await;
|
||||
ts_before = frame.ts;
|
||||
yield Ok(frame);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Insert filler into the video stream when no frames are comming
|
||||
/// this should help the stream not be considered dead while
|
||||
/// we wait for the reconnect
|
||||
@@ -621,6 +649,7 @@ fn insert_filler<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
v
|
||||
},
|
||||
_ = tokio::time::sleep(delay) => {
|
||||
log::trace!("Filling");
|
||||
match format {
|
||||
VidFormat::H264 => {
|
||||
Some(Ok(StampedData {
|
||||
@@ -769,9 +798,8 @@ async fn send_to_appsrc<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
let mut ts_0 = Duration::MAX;
|
||||
let mut wait_for_iframe = true;
|
||||
let mut pools: HashMap<usize, gstreamer::BufferPool> = Default::default();
|
||||
let mut keyframes_pushed = 0;
|
||||
let mut inited = false;
|
||||
// appsrc.set_state(gstreamer::State::Paused).unwrap();
|
||||
let mut paused = true;
|
||||
appsrc.set_state(gstreamer::State::Paused).unwrap();
|
||||
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<StampedData>(2000);
|
||||
|
||||
@@ -790,7 +818,11 @@ async fn send_to_appsrc<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
ts_0 = data.ts;
|
||||
}
|
||||
let rt = data.ts - ts_0;
|
||||
// log::info!("rt: {:?}", rt);
|
||||
log::trace!(
|
||||
"Sending frame with TimeStamp: {:?} on {}",
|
||||
rt,
|
||||
appsrc.name()
|
||||
);
|
||||
let buf = {
|
||||
// let mut gst_buf = pool.acquire_buffer(None).unwrap();
|
||||
let msg_size = data.data.len();
|
||||
@@ -837,36 +869,17 @@ async fn send_to_appsrc<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
}
|
||||
Err(e) => Err(anyhow!("Error in streaming: {e:?}")),
|
||||
}?;
|
||||
if !inited {
|
||||
if keyframes_pushed > 1
|
||||
|| appsrc.current_level_bytes() >= appsrc.max_bytes() * 2 / 3
|
||||
{
|
||||
// log::info!("=== Playing state on {}", appsrc.name());
|
||||
// log::info!(
|
||||
// "Buffer filled to {} of {} ({} %) in {} keyframes",
|
||||
// appsrc.current_level_bytes(),
|
||||
// appsrc.max_bytes(),
|
||||
// appsrc.current_level_bytes() * 100 / appsrc.max_bytes(),
|
||||
// keyframes_pushed
|
||||
// );
|
||||
inited = true;
|
||||
// appsrc.set_state(gstreamer::State::Playing).unwrap();
|
||||
} else if data.keyframe {
|
||||
// log::info!(
|
||||
// "Buffer filling to {} of {} ({} %) in {} keyframes on {}",
|
||||
// appsrc.current_level_bytes(),
|
||||
// appsrc.max_bytes(),
|
||||
// appsrc.current_level_bytes() * 100 / appsrc.max_bytes(),
|
||||
// keyframes_pushed,
|
||||
// appsrc.name()
|
||||
// );
|
||||
keyframes_pushed += 1;
|
||||
}
|
||||
if appsrc.current_level_bytes() >= appsrc.max_bytes() * 2 / 3 && paused {
|
||||
appsrc.set_state(gstreamer::State::Playing).unwrap();
|
||||
paused = false;
|
||||
} else if appsrc.current_level_bytes() <= appsrc.max_bytes() / 3 && !paused {
|
||||
appsrc.set_state(gstreamer::State::Paused).unwrap();
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
})();
|
||||
log::error!("r: {:?}", r);
|
||||
log::trace!("r: {:?}", r);
|
||||
r
|
||||
});
|
||||
|
||||
@@ -877,6 +890,5 @@ async fn send_to_appsrc<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
break;
|
||||
}
|
||||
}
|
||||
log::error!("Exiting send_to_appsrc");
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user