Merge branch 'master' of https://github.com/QuantumEntangledAndy/neolink into fix/ptz-stop
This commit is contained in:
25 files changed
+2305
-746
No files matched your search
+4
-1
@@ -1,5 +1,5 @@
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
rustflags = ["-C", "target-feature=+crt-static"]
|
||||
rustflags = ["-C", "target-feature=+crt-static", "--cfg", "tokio_unstable"]
|
||||
|
||||
# TODO not good as a default
|
||||
[target.armv7-unknown-linux-gnueabihf]
|
||||
@@ -10,3 +10,6 @@ linker = "aarch64-linux-gnu-gcc"
|
||||
|
||||
[target.i686-unknown-linux-gnu]
|
||||
linker = "i686-linux-gnu-gcc"
|
||||
|
||||
[build]
|
||||
rustflags = ["--cfg", "tokio_unstable"]
|
||||
+53
-25
@@ -3,7 +3,23 @@ name: CI
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
pre_job:
|
||||
# continue-on-error: true # Uncomment once integration is finished
|
||||
runs-on: ubuntu-latest
|
||||
# Map a step output to a job output
|
||||
outputs:
|
||||
should_skip: ${{ steps.skip_check.outputs.should_skip }}
|
||||
steps:
|
||||
- id: skip_check
|
||||
uses: fkirc/skip-duplicate-actions@v5
|
||||
with:
|
||||
# All of these options are optional, so you can remove them if you are happy with the defaults
|
||||
concurrent_skipping: 'same_content_newer'
|
||||
skip_after_successful_duplicate: 'false'
|
||||
|
||||
native:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: native
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
@@ -62,13 +78,15 @@ jobs:
|
||||
echo "PATH=${PATH}"
|
||||
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
|
||||
# pkg-config --variable pc_path pkg-config
|
||||
cargo build --release --all-features
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: release-${{ matrix.os }}
|
||||
path: "target/release/neolink*"
|
||||
cross:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: cross
|
||||
runs-on: ubuntu-latest
|
||||
container: "node:current-bullseye-slim"
|
||||
@@ -126,7 +144,7 @@ jobs:
|
||||
TARGET: ${{ matrix.target }}
|
||||
- name: Build
|
||||
run: |
|
||||
cargo build --release --all-features --target=${TARGET}
|
||||
cargo build --verbose --release --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
|
||||
@@ -134,16 +152,15 @@ jobs:
|
||||
TARGET: ${{ matrix.target }}
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: release-${{ matrix.arch }}-buster
|
||||
name: release-${{ matrix.arch }}-bullseye
|
||||
path: "target/${{ matrix.target }}/release/neolink*"
|
||||
|
||||
push_to_registry:
|
||||
name: Build Docker image
|
||||
if: github.event_name == 'push'
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- "cross"
|
||||
- "native"
|
||||
steps:
|
||||
- name: Check token is set
|
||||
id: vars
|
||||
@@ -185,18 +202,29 @@ jobs:
|
||||
id: tags
|
||||
shell: bash
|
||||
run: |
|
||||
tags=""
|
||||
if [[ "${GITHUB_REF}" =~ ^'refs/tags/'(.*) ]]; then
|
||||
gittag="$(echo "${BASH_REMATCH[1]}" | sed -E 's|[/]|-|g')"
|
||||
tags="${REPO_NAME}:${gittag}"
|
||||
elif [[ "${GITHUB_REF}" =~ ^'refs/heads/'(.*) ]]; then
|
||||
branch="$(echo "${BASH_REMATCH[1]}" | sed -E 's|[/]|-|g')"
|
||||
tags="${REPO_NAME}:${branch}"
|
||||
tags=( )
|
||||
gittag="$(git tag --points-at HEAD)"
|
||||
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
|
||||
if [[ -n "${gittag}" ]]; then
|
||||
tags=( "${tags[@]}" "${REPO_NAME}:${gittag}" )
|
||||
fi
|
||||
if [[ -n "${branch}" ]]; then
|
||||
branch="$(echo "${branch}" | sed -E 's|[/]|-|g')"
|
||||
tags=( "${tags[@]}" "${REPO_NAME}:${branch}" )
|
||||
if [ "${branch}" == "master" ]; then
|
||||
tags="${tags},${REPO_NAME}:latest"
|
||||
tags=( "${tags[@]}" "${tags},${REPO_NAME}:latest" )
|
||||
fi
|
||||
fi
|
||||
echo "TAGS=${tags}" >> "${GITHUB_OUTPUT}"
|
||||
function join_by {
|
||||
local d=${1-} f=${2-}
|
||||
if shift 2; then
|
||||
printf %s "$f" "${@/#/$d}"
|
||||
fi
|
||||
}
|
||||
tagstr="$(join_by "," "${tags[@]}")"
|
||||
echo "TAGS=${tagstr}"
|
||||
echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}"
|
||||
env:
|
||||
REPO_NAME: ${{ steps.string_repo.outputs.lowercase }}
|
||||
- name: Install latest rust
|
||||
@@ -218,22 +246,22 @@ jobs:
|
||||
- name: Download Linux x86_64
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-amd64-buster
|
||||
name: release-amd64-bullseye
|
||||
path: linux/amd64
|
||||
- name: Download Linux armv7
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-armhf-buster
|
||||
name: release-armhf-bullseye
|
||||
path: linux/arm/v7
|
||||
- name: Download Linux arm64
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-arm64-buster
|
||||
name: release-arm64-bullseye
|
||||
path: linux/arm64
|
||||
- name: Download Linux i386
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-i386-buster
|
||||
name: release-i386-bullseye
|
||||
path: linux/386
|
||||
- name: Push to Docker Hub
|
||||
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
|
||||
@@ -287,22 +315,22 @@ jobs:
|
||||
- name: Download Linux x86_64
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-amd64-buster
|
||||
path: neolink_linux_x86_64_buster
|
||||
name: release-amd64-bullseye
|
||||
path: neolink_linux_x86_64_bullseye
|
||||
- name: Download Linux armhf
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-armhf-buster
|
||||
name: release-armhf-bbullseye
|
||||
path: neolink_linux_armhf
|
||||
- name: Download Linux arm64
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-arm64-buster
|
||||
name: release-arm64-bullseye
|
||||
path: neolink_linux_arm64
|
||||
- name: Download Linux i386
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-i386-buster
|
||||
name: release-i386-bullseye
|
||||
path: neolink_linux_i386
|
||||
- name: Prepare Releases
|
||||
run: |
|
||||
@@ -310,7 +338,7 @@ jobs:
|
||||
neolink_windows
|
||||
neolink_macos
|
||||
neolink_linux_x86_64_ubuntu
|
||||
neolink_linux_x86_64_buster
|
||||
neolink_linux_x86_64_bullseye
|
||||
neolink_linux_armhf
|
||||
neolink_linux_arm64
|
||||
neolink_linux_i386
|
||||
@@ -327,7 +355,7 @@ jobs:
|
||||
neolink_windows.zip
|
||||
neolink_macos.zip
|
||||
neolink_linux_x86_64_ubuntu.zip
|
||||
neolink_linux_x86_64_buster.zip
|
||||
neolink_linux_x86_64_bullseye.zip
|
||||
neolink_linux_armhf.zip
|
||||
neolink_linux_arm64.zip
|
||||
neolink_linux_i386.zip
|
||||
|
||||
@@ -3,7 +3,23 @@ name: DockerHub
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
pre_job:
|
||||
# continue-on-error: true # Uncomment once integration is finished
|
||||
runs-on: ubuntu-latest
|
||||
# Map a step output to a job output
|
||||
outputs:
|
||||
should_skip: ${{ steps.skip_check.outputs.should_skip }}
|
||||
steps:
|
||||
- id: skip_check
|
||||
uses: fkirc/skip-duplicate-actions@v5
|
||||
with:
|
||||
# All of these options are optional, so you can remove them if you are happy with the defaults
|
||||
concurrent_skipping: 'same_content_newer'
|
||||
skip_after_successful_duplicate: 'false'
|
||||
|
||||
native:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: native
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
@@ -3,7 +3,23 @@ name: Style
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
pre_job:
|
||||
# continue-on-error: true # Uncomment once integration is finished
|
||||
runs-on: ubuntu-latest
|
||||
# Map a step output to a job output
|
||||
outputs:
|
||||
should_skip: ${{ steps.skip_check.outputs.should_skip }}
|
||||
steps:
|
||||
- id: skip_check
|
||||
uses: fkirc/skip-duplicate-actions@v5
|
||||
with:
|
||||
# All of these options are optional, so you can remove them if you are happy with the defaults
|
||||
concurrent_skipping: 'same_content_newer'
|
||||
skip_after_successful_duplicate: 'false'
|
||||
|
||||
check_clippy:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: Clippy
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
@@ -21,6 +37,8 @@ jobs:
|
||||
run: cargo +nightly clippy --workspace --all-targets --all-features
|
||||
|
||||
check_fmt:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: Rust-fmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -34,6 +52,8 @@ jobs:
|
||||
cargo +nightly fmt --all -- --check
|
||||
|
||||
check_lua:
|
||||
needs: pre_job
|
||||
if: needs.pre_job.outputs.should_skip != 'true'
|
||||
name: Luacheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
Generated
+494
-3
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.8.2"
|
||||
@@ -94,6 +100,39 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
|
||||
|
||||
[[package]]
|
||||
name = "async-stream"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51"
|
||||
dependencies = [
|
||||
"async-stream-impl",
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-stream-impl"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic_refcell"
|
||||
version = "0.1.9"
|
||||
@@ -106,6 +145,57 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "axum"
|
||||
version = "0.6.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum-core",
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"hyper",
|
||||
"itoa",
|
||||
"matchit",
|
||||
"memchr",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"sync_wrapper",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"mime",
|
||||
"rustversion",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.0"
|
||||
@@ -237,6 +327,42 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "console-api"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e57ff02e8ad8e06ab9731d5dc72dc23bef9200778eae1a89d555d8c42e5d4a86"
|
||||
dependencies = [
|
||||
"prost",
|
||||
"prost-types",
|
||||
"tonic",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console-subscriber"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a3a81dfaf6b66bce5d159eddae701e3a002f194d378cbf7be5f053c281d9be"
|
||||
dependencies = [
|
||||
"console-api",
|
||||
"crossbeam-channel",
|
||||
"crossbeam-utils",
|
||||
"futures",
|
||||
"hdrhistogram",
|
||||
"humantime",
|
||||
"prost-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thread_local",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tonic",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cookie-factory"
|
||||
version = "0.3.2"
|
||||
@@ -342,6 +468,12 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.0"
|
||||
@@ -399,6 +531,16 @@ dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flume"
|
||||
version = "0.10.14"
|
||||
@@ -412,6 +554,12 @@ dependencies = [
|
||||
"spin 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
@@ -860,6 +1008,25 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17f8a914c2987b688368b5138aa05321db91f4090cf26118185672ad588bce21"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"http",
|
||||
"indexmap",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
@@ -869,6 +1036,19 @@ dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hdrhistogram"
|
||||
version = "7.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"byteorder",
|
||||
"flate2",
|
||||
"nom",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
@@ -896,12 +1076,82 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "848ec2dd093df965a34b434580d94852197fc83feac5b2c1962399bbf2cb4f0b"
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httparse"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
|
||||
|
||||
[[package]]
|
||||
name = "httpdate"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.14.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-timeout"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1"
|
||||
dependencies = [
|
||||
"hyper",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
"tokio-io-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
@@ -986,6 +1236,15 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
@@ -1050,12 +1309,27 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
||||
|
||||
[[package]]
|
||||
name = "matchit"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
@@ -1068,12 +1342,27 @@ version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.6"
|
||||
@@ -1113,11 +1402,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "neolink"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byte-slice-cast",
|
||||
"clap",
|
||||
"console-subscriber",
|
||||
"crossbeam-channel",
|
||||
"env_logger",
|
||||
"futures",
|
||||
@@ -1142,7 +1432,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "neolink_core"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"assert_matches",
|
||||
@@ -1401,6 +1691,38 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost"
|
||||
version = "0.11.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-derive"
|
||||
version = "0.11.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost-types"
|
||||
version = "0.11.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13"
|
||||
dependencies = [
|
||||
"prost",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
@@ -1469,6 +1791,15 @@ dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
@@ -1578,7 +1909,7 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.21.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1681,6 +2012,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shell-words"
|
||||
version = "1.1.0"
|
||||
@@ -1791,6 +2131,12 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sync_wrapper"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.12.6"
|
||||
@@ -1869,6 +2215,16 @@ dependencies = [
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.20"
|
||||
@@ -1928,9 +2284,20 @@ dependencies = [
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"tracing",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-io-timeout"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.0.0"
|
||||
@@ -2017,6 +2384,70 @@ dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tonic"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"async-trait",
|
||||
"axum",
|
||||
"base64 0.13.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
"hyper",
|
||||
"hyper-timeout",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"prost",
|
||||
"prost-derive",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"tracing-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"indexmap",
|
||||
"pin-project",
|
||||
"pin-project-lite",
|
||||
"rand",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0"
|
||||
|
||||
[[package]]
|
||||
name = "tower-service"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
@@ -2025,9 +2456,21 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
@@ -2035,8 +2478,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-futures"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
|
||||
dependencies = [
|
||||
"pin-project",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
@@ -2156,6 +2631,12 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
@@ -2168,6 +2649,16 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
||||
+6
-5
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "neolink"
|
||||
description = "A standards-compliant bridge to Reolink IP cameras"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "AGPL-3.0-or-later"
|
||||
@@ -15,21 +15,22 @@ members = [
|
||||
anyhow = "1.0.70"
|
||||
byte-slice-cast = "1.2.2"
|
||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||
console-subscriber = "0.1.8"
|
||||
crossbeam-channel = "0.5.8"
|
||||
env_logger = "*"
|
||||
env_logger = "0.10.0"
|
||||
futures = "0.3.28"
|
||||
gstreamer = "0.20.3"
|
||||
gstreamer-app = "0.20.0"
|
||||
gstreamer-rtsp = "0.20.0"
|
||||
gstreamer-rtsp-server = { version = "0.20.3", features = ["v1_16"] }
|
||||
lazy_static = "1.4.0"
|
||||
log = { version = "0.4.17" }
|
||||
neolink_core = { path = "crates/core", version = "0.5.8" }
|
||||
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||
neolink_core = { path = "crates/core", version = "0.5.9" }
|
||||
regex = "1.7.3"
|
||||
rumqttc = "0.20.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
time = "0.3.20"
|
||||
tokio = { version = "1.27.0", features = ["rt", "macros", "io-util"] }
|
||||
tokio = { version = "1.27.0", features = ["rt-multi-thread", "macros", "io-util", "tracing"] }
|
||||
tokio-stream = "0.1.12"
|
||||
toml = "0.7.3"
|
||||
validator = "0.16.0"
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
# Miroslav Šedivý
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
FROM docker.io/rust:slim-buster AS build
|
||||
FROM docker.io/rust:slim-bullseye AS build
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
@@ -34,7 +34,7 @@ RUN echo "TARGETPLATFORM: ${TARGETPLATFORM}"; \
|
||||
fi
|
||||
|
||||
# Create the release container. Match the base OS used to build
|
||||
FROM debian:buster-slim
|
||||
FROM debian:bullseye-slim
|
||||
ARG TARGETPLATFORM
|
||||
ARG REPO
|
||||
ARG VERSION
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "neolink_core"
|
||||
description = "Core services and structure for Reolink IP cameras"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "AGPL-3.0-or-later"
|
||||
@@ -28,7 +28,7 @@ serde = { version = "1.0.106", features = ["derive"] }
|
||||
time = { version = "0.3.20" , 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"] }
|
||||
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
||||
yaserde = "0.8.0"
|
||||
yaserde_derive = "0.8.0"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::bc::model::*;
|
||||
use crate::bc::xml::*;
|
||||
use crate::{Credentials, Error, Result};
|
||||
use bytes::BytesMut;
|
||||
use std::io;
|
||||
use nom::AsBytes;
|
||||
use tokio_util::codec::{Decoder, Encoder};
|
||||
|
||||
pub(crate) struct BcCodex {
|
||||
@@ -54,14 +54,25 @@ impl Decoder for BcCodex {
|
||||
if buf.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("bytes remaining on BC stream: {:X?}", buf),
|
||||
)
|
||||
.into())
|
||||
log::debug!(
|
||||
"bytes remaining on BC stream: {:X?}",
|
||||
buf.as_bytes().chunks(25).next()
|
||||
);
|
||||
// Right after this we seem to get an issue with the camera dropping us
|
||||
// Needs probing
|
||||
// F0, DE, BC, A, 3, 0, 0, 0, 88, 6, 0, 0, 0, 1, 4, 0, C8, 0, 0, 0, 0, 0, 0, 0, 30, 31, 64, 63, 48,
|
||||
// 32, 36, 34, 6A, 6, 0, 0, 0, 0, 0, 0, D8, F5, C7, 86, 56, 0, 0, 0, 0, 0, 0, 1, 21, 9A, FC, 22, 7F, 6, AE, F6, 15, FF, E5, 71, 4, 2F, 24, 61, 15, 96, F0, BF, 83, DE, 10, BE, B4, 2E, 3
|
||||
// 9, 76, 56, 92, 7E, 48, 79, 20, 9A, DC, 1B, BB, AC, 22, 60, 5C, 72, B5, 3D, 8, E0, 34, 43, 3F, 2E, A7, 81, A8, 11, 75, 7F, 58, 3E, 8, 54, 91, 43, 21, EC, 6B, D6, 1A, D5, CB, D5, 6C,
|
||||
// 8C, 2E, 6E, A3, 51, C3, A4, F0, CF, 2B, 61, 81, D0, 1C, A1, 76, EE, BF, 7A, D5, D8, D1, C4, D, B0, 45, EE, 3E, 93, 9A, CE, 5F, AB, 75, 55, AC, 9D, 66, DE, 23, 6D, 5F, 25, 57, DA, F5
|
||||
//, E, 7F, 8D, 30, A7, 66, C4, 60, 76, 41, D0, 6A, 23, E, A9, C5, 51, EE, F6, DD, 19, E7, A8, 96, 9F, 2B, AF, 31, 90, 9D, FC, BE
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
// match self.decode(buf)? {
|
||||
// Some(frame) => Ok(Some(frame)),
|
||||
// None => Ok(None),
|
||||
// }
|
||||
}
|
||||
|
||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
||||
|
||||
@@ -5,10 +5,10 @@ use futures::stream::{Stream, StreamExt};
|
||||
use log::*;
|
||||
use std::collections::btree_map::Entry;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::{channel, Sender};
|
||||
use tokio::task::yield_now;
|
||||
use tokio_stream::wrappers::ReceiverStream;
|
||||
use tokio_util::sync::PollSender;
|
||||
|
||||
use tokio::{sync::RwLock, task::JoinSet};
|
||||
|
||||
@@ -16,9 +16,9 @@ type MsgHandler = Box<dyn Fn(&Bc) -> Option<Bc> + Send + Sync>;
|
||||
#[derive(Default)]
|
||||
struct Subscriber {
|
||||
/// Subscribers based on their Num
|
||||
num: RwLock<BTreeMap<u16, Sender<Result<Bc>>>>,
|
||||
num: BTreeMap<u16, Sender<Result<Bc>>>,
|
||||
/// Subscribers based on their ID
|
||||
id: RwLock<BTreeMap<u32, MsgHandler>>,
|
||||
id: BTreeMap<u32, MsgHandler>,
|
||||
}
|
||||
|
||||
pub(crate) type BcConnSink = Box<dyn Sink<Bc, Error = Error> + Send + Sync + Unpin>;
|
||||
@@ -31,35 +31,48 @@ pub(crate) type BcConnSource = Box<dyn Stream<Item = Result<Bc>> + Send + Sync +
|
||||
/// There can be only one subscriber per kind of message at a time.
|
||||
pub struct BcConnection {
|
||||
sink: Sender<Result<Bc>>,
|
||||
subscribers: Arc<Subscriber>,
|
||||
#[allow(dead_code)] // Not dead we just need to hold a reference to keep it alive
|
||||
poll_commander: Sender<PollCommand>,
|
||||
rx_thread: RwLock<JoinSet<Result<()>>>,
|
||||
}
|
||||
|
||||
impl BcConnection {
|
||||
pub async fn new(mut sink: BcConnSink, mut source: BcConnSource) -> Result<BcConnection> {
|
||||
let subscribers: Arc<Subscriber> = Default::default();
|
||||
let subs = subscribers.clone();
|
||||
pub async fn new(mut sink: BcConnSink, source: BcConnSource) -> Result<BcConnection> {
|
||||
let (sinker, sinker_rx) = channel::<Result<Bc>>(100);
|
||||
let mut rx_thread = JoinSet::new();
|
||||
let sink_thread = sinker.clone();
|
||||
|
||||
let (poll_commander, poll_commanded) = channel(200);
|
||||
let mut poller = Poller {
|
||||
subscribers: Default::default(),
|
||||
sink: sinker.clone(),
|
||||
reciever: ReceiverStream::new(poll_commanded),
|
||||
};
|
||||
|
||||
let mut rx_thread = JoinSet::<Result<()>>::new();
|
||||
let thread_poll_commander = poll_commander.clone();
|
||||
let handle = tokio::task::spawn_blocking(move || {
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap();
|
||||
runtime.block_on(
|
||||
PollSender::new(thread_poll_commander)
|
||||
.send_all(&mut source.map(|bc| Ok(PollCommand::Bc(Box::new(bc))))),
|
||||
)
|
||||
});
|
||||
rx_thread.spawn(async move {
|
||||
loop {
|
||||
yield_now().await; // Give other tasks a chance to run before pulling next packet
|
||||
let packet = source.next().await;
|
||||
let bc = match packet {
|
||||
Some(res) => res,
|
||||
None => continue,
|
||||
};
|
||||
Self::poll(bc, &subs, &sink_thread).await?
|
||||
}
|
||||
handle.await??;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
rx_thread.spawn(async move { sink.send_all(&mut ReceiverStream::new(sinker_rx)).await });
|
||||
|
||||
rx_thread.spawn(async move {
|
||||
loop {
|
||||
poller.run().await?;
|
||||
}
|
||||
});
|
||||
|
||||
Ok(BcConnection {
|
||||
sink: sinker,
|
||||
subscribers,
|
||||
poll_commander,
|
||||
rx_thread: RwLock::new(rx_thread),
|
||||
})
|
||||
}
|
||||
@@ -71,18 +84,9 @@ impl BcConnection {
|
||||
|
||||
pub async fn subscribe(&self, msg_num: u16) -> Result<BcSubscription> {
|
||||
let (tx, rx) = channel(100);
|
||||
match self.subscribers.num.write().await.entry(msg_num) {
|
||||
Entry::Vacant(vac_entry) => {
|
||||
vac_entry.insert(tx);
|
||||
}
|
||||
Entry::Occupied(mut occ_entry) => {
|
||||
if occ_entry.get().is_closed() {
|
||||
occ_entry.insert(tx);
|
||||
} else {
|
||||
return Err(Error::SimultaneousSubscription { msg_num });
|
||||
}
|
||||
}
|
||||
};
|
||||
self.poll_commander
|
||||
.send(PollCommand::AddSubscriber(msg_num, tx))
|
||||
.await?;
|
||||
Ok(BcSubscription::new(rx, msg_num as u32, self))
|
||||
}
|
||||
|
||||
@@ -93,90 +97,18 @@ impl BcConnection {
|
||||
where
|
||||
T: Fn(&Bc) -> Option<Bc> + Send + Sync + 'static,
|
||||
{
|
||||
match self.subscribers.id.write().await.entry(msg_id) {
|
||||
Entry::Vacant(vac_entry) => {
|
||||
vac_entry.insert(Box::new(handler));
|
||||
}
|
||||
Entry::Occupied(_) => {
|
||||
return Err(Error::SimultaneousSubscriptionId { msg_id });
|
||||
}
|
||||
};
|
||||
self.poll_commander
|
||||
.send(PollCommand::AddHandler(msg_id, Box::new(handler)))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stop a message handler created using [`handle_msg`]
|
||||
#[allow(dead_code)] // Currently unused but added for future use
|
||||
pub async fn unhandle_msg(&self, msg_id: u32) -> Result<()> {
|
||||
self.subscribers.id.write().await.remove(&msg_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn poll(
|
||||
response: Result<Bc>,
|
||||
subscribers: &Subscriber,
|
||||
sink: &Sender<Result<Bc>>,
|
||||
) -> Result<()> {
|
||||
match response {
|
||||
Ok(response) => {
|
||||
let msg_num = response.meta.msg_num;
|
||||
let msg_id = response.meta.msg_id;
|
||||
|
||||
let mut remove_it_num = false;
|
||||
match (
|
||||
subscribers.id.read().await.get(&msg_id),
|
||||
subscribers.num.read().await.get(&msg_num),
|
||||
) {
|
||||
(Some(occ), _) => {
|
||||
if let Some(reply) = occ(&response) {
|
||||
assert!(reply.meta.msg_num == response.meta.msg_num);
|
||||
sink.send(Ok(reply)).await?;
|
||||
}
|
||||
}
|
||||
(None, Some(occ)) => {
|
||||
if occ.capacity() == 0 {
|
||||
warn!("Reaching limit of channel");
|
||||
warn!(
|
||||
"Remaining: {} of {} message space for {} (ID: {})",
|
||||
occ.capacity(),
|
||||
occ.max_capacity(),
|
||||
&msg_num,
|
||||
&msg_id
|
||||
);
|
||||
} else {
|
||||
trace!(
|
||||
"Remaining: {} of {} message space for {} (ID: {})",
|
||||
occ.capacity(),
|
||||
occ.max_capacity(),
|
||||
&msg_num,
|
||||
&msg_id
|
||||
);
|
||||
}
|
||||
if occ.send(Ok(response)).await.is_err() {
|
||||
remove_it_num = true;
|
||||
}
|
||||
}
|
||||
(None, None) => {
|
||||
debug!(
|
||||
"Ignoring uninteresting message id {} (number: {})",
|
||||
msg_id, msg_num
|
||||
);
|
||||
trace!("Contents: {:?}", response);
|
||||
}
|
||||
}
|
||||
if remove_it_num {
|
||||
subscribers.num.write().await.remove(&msg_num);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
for sub in subscribers.num.read().await.values() {
|
||||
let _ = sub.send(Err(e.clone())).await;
|
||||
}
|
||||
subscribers.num.write().await.clear();
|
||||
subscribers.id.write().await.clear();
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
self.poll_commander
|
||||
.send(PollCommand::RemoveHandler(msg_id))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -198,3 +130,116 @@ impl BcConnection {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
enum PollCommand {
|
||||
Bc(Box<Result<Bc>>),
|
||||
AddHandler(u32, MsgHandler),
|
||||
RemoveHandler(u32),
|
||||
AddSubscriber(u16, Sender<Result<Bc>>),
|
||||
}
|
||||
|
||||
struct Poller {
|
||||
subscribers: Subscriber,
|
||||
sink: Sender<Result<Bc>>,
|
||||
reciever: ReceiverStream<PollCommand>,
|
||||
}
|
||||
|
||||
impl Poller {
|
||||
async fn run(&mut self) -> Result<()> {
|
||||
while let Some(command) = self.reciever.next().await {
|
||||
yield_now().await;
|
||||
match command {
|
||||
PollCommand::Bc(boxed_response) => match *boxed_response {
|
||||
Ok(response) => {
|
||||
let msg_num = response.meta.msg_num;
|
||||
let msg_id = response.meta.msg_id;
|
||||
|
||||
let mut remove_it_num = false;
|
||||
match (
|
||||
self.subscribers.id.get(&msg_id),
|
||||
self.subscribers.num.get(&msg_num),
|
||||
) {
|
||||
(Some(occ), _) => {
|
||||
if let Some(reply) = occ(&response) {
|
||||
assert!(reply.meta.msg_num == response.meta.msg_num);
|
||||
self.sink.send(Ok(reply)).await?;
|
||||
}
|
||||
}
|
||||
(None, Some(occ)) => {
|
||||
if occ.capacity() == 0 {
|
||||
warn!("Reaching limit of channel");
|
||||
warn!(
|
||||
"Remaining: {} of {} message space for {} (ID: {})",
|
||||
occ.capacity(),
|
||||
occ.max_capacity(),
|
||||
&msg_num,
|
||||
&msg_id
|
||||
);
|
||||
} else {
|
||||
trace!(
|
||||
"Remaining: {} of {} message space for {} (ID: {})",
|
||||
occ.capacity(),
|
||||
occ.max_capacity(),
|
||||
&msg_num,
|
||||
&msg_id
|
||||
);
|
||||
}
|
||||
if occ.send(Ok(response)).await.is_err() {
|
||||
remove_it_num = true;
|
||||
}
|
||||
}
|
||||
(None, None) => {
|
||||
debug!(
|
||||
"Ignoring uninteresting message id {} (number: {})",
|
||||
msg_id, msg_num
|
||||
);
|
||||
trace!("Contents: {:?}", response);
|
||||
}
|
||||
}
|
||||
if remove_it_num {
|
||||
self.subscribers.num.remove(&msg_num);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
for sub in self.subscribers.num.values() {
|
||||
let _ = sub.send(Err(e.clone())).await;
|
||||
}
|
||||
self.subscribers.num.clear();
|
||||
self.subscribers.id.clear();
|
||||
return Err(e);
|
||||
}
|
||||
},
|
||||
PollCommand::AddHandler(msg_id, handler) => {
|
||||
match self.subscribers.id.entry(msg_id) {
|
||||
Entry::Vacant(vac_entry) => {
|
||||
vac_entry.insert(handler);
|
||||
}
|
||||
Entry::Occupied(_) => {
|
||||
return Err(Error::SimultaneousSubscriptionId { msg_id });
|
||||
}
|
||||
};
|
||||
}
|
||||
PollCommand::RemoveHandler(msg_id) => {
|
||||
self.subscribers.id.remove(&msg_id);
|
||||
}
|
||||
PollCommand::AddSubscriber(msg_num, tx) => {
|
||||
match self.subscribers.num.entry(msg_num) {
|
||||
Entry::Vacant(vac_entry) => {
|
||||
vac_entry.insert(tx);
|
||||
}
|
||||
Entry::Occupied(mut occ_entry) => {
|
||||
if occ_entry.get().is_closed() {
|
||||
occ_entry.insert(tx);
|
||||
} else {
|
||||
let _ = tx
|
||||
.send(Err(Error::SimultaneousSubscription { msg_num }))
|
||||
.await;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -189,11 +189,16 @@ impl Discoverer {
|
||||
F: Fn(UdpDiscovery, SocketAddr) -> Option<T>,
|
||||
{
|
||||
let mut reply = ReceiverStream::new(self.subscribe(0).await?);
|
||||
loop {
|
||||
let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavaliable)??;
|
||||
if let Some(result) = map(reply, addr) {
|
||||
return Ok(result);
|
||||
}
|
||||
tokio::select! {
|
||||
v = async {
|
||||
loop {
|
||||
let (reply, addr) = reply.next().await.ok_or(Error::ConnectionUnavaliable)??;
|
||||
if let Some(result) = map(reply, addr) {
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
} => v,
|
||||
_ = tokio::time::sleep(*MAXIMUM_WAIT) => Err::<T, Error>(Error::DiscoveryTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +222,7 @@ impl Discoverer {
|
||||
where
|
||||
F: Fn(UdpDiscovery, SocketAddr) -> Option<T>,
|
||||
{
|
||||
trace!("Retrying send");
|
||||
disc.tid = 0; // Must be random to avoid simulatenous subscription errors
|
||||
let mut set = FuturesUnordered::new();
|
||||
for dest in dests.iter() {
|
||||
@@ -225,6 +231,7 @@ impl Discoverer {
|
||||
|
||||
// Get what ever completes first
|
||||
while let Some(result) = set.next().await {
|
||||
trace!("Result: {}", result.is_ok());
|
||||
if let Ok(ret) = result {
|
||||
return Ok(ret);
|
||||
}
|
||||
@@ -356,15 +363,20 @@ impl Discoverer {
|
||||
/// On success it returns the M2cQr that the p2p relay
|
||||
/// server has about the UID
|
||||
async fn uid_loopup(&self, uid: &str) -> Result<UidLookupResults> {
|
||||
let mut addrs = vec![];
|
||||
for p2p_relay in P2P_RELAY_HOSTNAMES.iter() {
|
||||
addrs.append(
|
||||
&mut format!("{}:9999", p2p_relay)
|
||||
.to_socket_addrs()
|
||||
.map(|i| i.collect::<Vec<SocketAddr>>())
|
||||
.unwrap_or_else(|_| vec![]),
|
||||
);
|
||||
}
|
||||
let task = tokio::task::spawn_blocking(move || {
|
||||
let mut addrs = vec![];
|
||||
for p2p_relay in P2P_RELAY_HOSTNAMES.iter() {
|
||||
addrs.append(
|
||||
&mut format!("{}:9999", p2p_relay)
|
||||
.to_socket_addrs()
|
||||
.map(|i| i.collect::<Vec<SocketAddr>>())
|
||||
.unwrap_or_else(|_| vec![]),
|
||||
);
|
||||
}
|
||||
addrs
|
||||
});
|
||||
let addrs = timeout(*MAXIMUM_WAIT, task).await??;
|
||||
trace!("Uid lookup to: {:?}", addrs);
|
||||
let msg = UdpDiscovery {
|
||||
tid: 0,
|
||||
payload: UdpXml {
|
||||
@@ -375,6 +387,7 @@ impl Discoverer {
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
trace!("Sending look up {:?}", msg);
|
||||
let (packet, _) = self
|
||||
.retry_send_multi(msg, addrs.as_slice(), |bc, addr| match bc {
|
||||
UdpDiscovery {
|
||||
@@ -388,7 +401,7 @@ impl Discoverer {
|
||||
_ => None,
|
||||
})
|
||||
.await?;
|
||||
|
||||
trace!("Look up complete");
|
||||
Ok(UidLookupResults {
|
||||
reg: SocketAddr::new(packet.reg.ip.parse()?, packet.reg.port),
|
||||
relay: SocketAddr::new(packet.relay.ip.parse()?, packet.relay.port),
|
||||
@@ -1004,20 +1017,25 @@ impl Discovery {
|
||||
// directly
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn remote(uid: &str) -> Result<DiscoveryResult> {
|
||||
trace!("Start remote");
|
||||
let mut discoverer = Discoverer::new().await?;
|
||||
|
||||
let client_id = generate_cid();
|
||||
trace!("client_id: {}", client_id);
|
||||
|
||||
let lookup = discoverer.uid_loopup(uid).await?;
|
||||
trace!("lookup: {:?}", lookup);
|
||||
let reg_addr = lookup.reg;
|
||||
let relay_addr = lookup.relay;
|
||||
|
||||
let reg_result = discoverer.register_address(uid, client_id, &lookup).await?;
|
||||
trace!("reg_result: {:?}", reg_result);
|
||||
|
||||
let connect_result = tokio::select! {
|
||||
v = discoverer.client_initiated_dev(®_result) => {v},
|
||||
v = discoverer.device_initiated_dev(®_result) => {v},
|
||||
}?;
|
||||
trace!("connect_result: {:?}", connect_result);
|
||||
|
||||
let (socket, keep_alive_tasks) = discoverer.into_socket().await;
|
||||
Ok(DiscoveryResult {
|
||||
|
||||
@@ -198,6 +198,7 @@ impl Sink<(BcUdp, SocketAddr)> for BcUdpSource {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum State {
|
||||
Normal, // Normal recieve
|
||||
Flushing, // Used to send ack packets and things in the buffer
|
||||
@@ -298,15 +299,15 @@ impl Stream for UdpPayloadSource {
|
||||
let mut this = self.get_mut();
|
||||
match this.state {
|
||||
State::Normal => {
|
||||
this.state = State::YieldNow;
|
||||
// this.state = State::YieldNow;
|
||||
// Handle resend events
|
||||
this.maintanence(cx);
|
||||
// Data ready to go
|
||||
if let Some(payload) = this.recieved.remove(&this.packets_want) {
|
||||
this.packets_want += 1;
|
||||
// error!("packets_want: {}", this.packets_want);
|
||||
return Poll::Ready(Some(Ok(payload)));
|
||||
}
|
||||
// Handle resend events
|
||||
this.maintanence(cx);
|
||||
// Normal behaviors
|
||||
match this.inner.poll_next_unpin(cx) {
|
||||
Poll::Ready(Some(Ok((
|
||||
|
||||
@@ -208,6 +208,12 @@ impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<tokio_util::sync::PollSendError<T>> for Error {
|
||||
fn from(_: tokio_util::sync::PollSendError<T>) -> Self {
|
||||
Error::TokioBcSendError
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cookie_factory::GenError> for Error {
|
||||
fn from(k: cookie_factory::GenError) -> Self {
|
||||
Error::GenError(std::sync::Arc::new(k))
|
||||
|
||||
@@ -12,11 +12,15 @@ pub struct BcMediaCodex {
|
||||
/// If true we will not search for the start of the next packet
|
||||
/// in the event that the stream appears to be corrupted
|
||||
strict: bool,
|
||||
amount_skipped: usize,
|
||||
}
|
||||
|
||||
impl BcMediaCodex {
|
||||
pub(crate) fn new(strict: bool) -> Self {
|
||||
Self { strict }
|
||||
Self {
|
||||
strict,
|
||||
amount_skipped: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,18 +50,19 @@ impl Decoder for BcMediaCodex {
|
||||
}
|
||||
|
||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
||||
let mut amount_skipped: usize = 0;
|
||||
loop {
|
||||
match { BcMedia::deserialize(src) } {
|
||||
Ok(bc) => {
|
||||
if amount_skipped > 0 {
|
||||
debug!("Amount skipped to restore stream: {}", amount_skipped);
|
||||
if self.amount_skipped > 0 {
|
||||
debug!("Amount skipped to restore stream: {}", self.amount_skipped);
|
||||
self.amount_skipped = 0;
|
||||
}
|
||||
return Ok(Some(bc));
|
||||
}
|
||||
Err(Error::NomIncomplete(_)) => {
|
||||
if amount_skipped > 0 {
|
||||
debug!("Amount skipped to restore stream: {}", amount_skipped);
|
||||
if self.amount_skipped > 0 {
|
||||
debug!("Amount skipped to restore stream: {}", self.amount_skipped);
|
||||
self.amount_skipped = 0;
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -67,12 +72,12 @@ impl Decoder for BcMediaCodex {
|
||||
} else if src.is_empty() {
|
||||
return Ok(None);
|
||||
} else {
|
||||
if amount_skipped == 0 {
|
||||
if self.amount_skipped == 0 {
|
||||
debug!("Error in stream attempting to restore");
|
||||
trace!(" Stream Error: {:?}", e);
|
||||
}
|
||||
// Drop the whole packet and wait for a packet that starts with magic
|
||||
amount_skipped += src.len();
|
||||
self.amount_skipped += src.len();
|
||||
src.clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ pub(crate) struct Config {
|
||||
#[serde(default = "default_bind_port")]
|
||||
pub(crate) bind_port: u16,
|
||||
|
||||
#[serde(default = "default_tokio_console")]
|
||||
pub(crate) tokio_console: bool,
|
||||
|
||||
#[serde(default = "default_certificate")]
|
||||
pub(crate) certificate: Option<String>,
|
||||
|
||||
@@ -96,6 +99,9 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[serde(default = "default_print", alias = "print")]
|
||||
pub(crate) print_format: PrintFormat,
|
||||
|
||||
#[serde(default = "default_update_time", alias = "time")]
|
||||
pub(crate) update_time: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
@@ -192,10 +198,18 @@ fn default_tls_client_auth() -> String {
|
||||
"none".to_string()
|
||||
}
|
||||
|
||||
fn default_tokio_console() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn default_channel_id() -> u8 {
|
||||
0
|
||||
}
|
||||
|
||||
fn default_update_time() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn default_motion_timeout() -> f64 {
|
||||
1.
|
||||
}
|
||||
|
||||
+16
@@ -42,6 +42,18 @@ mod utils;
|
||||
|
||||
use cmdline::{Command, Opt};
|
||||
use config::Config;
|
||||
use console_subscriber as _;
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
fn tokio_console_enable() {
|
||||
info!("Tokio Console Enabled");
|
||||
console_subscriber::init();
|
||||
}
|
||||
|
||||
#[cfg(not(tokio_unstable))]
|
||||
fn tokio_console_enable() {
|
||||
debug!("Tokio Console Disabled");
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
@@ -66,6 +78,10 @@ async fn main() -> Result<()> {
|
||||
.validate()
|
||||
.with_context(|| format!("Failed to validate the {:?} config file", conf_path))?;
|
||||
|
||||
if config.tokio_console {
|
||||
tokio_console_enable();
|
||||
}
|
||||
|
||||
match opt.cmd {
|
||||
None => {
|
||||
warn!(
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ mod sender;
|
||||
mod server;
|
||||
mod shared;
|
||||
|
||||
use factory::*;
|
||||
pub(crate) use factory::*;
|
||||
|
||||
pub(crate) use self::server::NeoRtspServer;
|
||||
|
||||
|
||||
+273
-166
@@ -11,7 +11,7 @@ use gstreamer::{
|
||||
glib::{self, Object},
|
||||
Structure,
|
||||
};
|
||||
use gstreamer::{Bin, Caps, ClockTime, Element, ElementFactory};
|
||||
use gstreamer::{Bin, Caps, Element, ElementFactory};
|
||||
use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType};
|
||||
use gstreamer_rtsp::RTSPUrl;
|
||||
use gstreamer_rtsp_server::prelude::*;
|
||||
@@ -26,7 +26,10 @@ use std::{
|
||||
sync::{atomic::Ordering, Arc},
|
||||
};
|
||||
use tokio::{
|
||||
sync::mpsc::{channel, Sender},
|
||||
sync::{
|
||||
mpsc::{channel, Sender},
|
||||
RwLock,
|
||||
},
|
||||
task::JoinSet,
|
||||
};
|
||||
use tokio_stream::wrappers::ReceiverStream;
|
||||
@@ -53,7 +56,7 @@ impl NeoMediaFactory {
|
||||
factory
|
||||
}
|
||||
|
||||
pub(crate) fn get_sender(&self) -> Sender<BcMedia> {
|
||||
pub(crate) fn get_sender(&self) -> Sender<FactoryCommand> {
|
||||
self.imp().sender.clone()
|
||||
}
|
||||
|
||||
@@ -103,22 +106,33 @@ impl NeoMediaFactory {
|
||||
pub(crate) fn buffer_ready(&self) -> bool {
|
||||
self.imp().buffer_ready()
|
||||
}
|
||||
|
||||
pub(crate) async fn join(&self) -> AnyResult<()> {
|
||||
self.imp().join().await
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for NeoMediaFactory {}
|
||||
unsafe impl Sync for NeoMediaFactory {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum FactoryCommand {
|
||||
BcMedia(BcMedia),
|
||||
ClearBuffer,
|
||||
JumpToLive,
|
||||
}
|
||||
|
||||
pub(crate) struct NeoMediaFactoryImpl {
|
||||
sender: Sender<BcMedia>,
|
||||
clientsender: Sender<ClientPipelineData>,
|
||||
sender: Sender<FactoryCommand>,
|
||||
clientsender: Sender<NeoMediaSender>,
|
||||
shared: Arc<NeoMediaShared>,
|
||||
#[allow(dead_code)] // Not dead just need a handle to keep it alive and drop with this obj
|
||||
threads: JoinSet<AnyResult<()>>,
|
||||
threads: RwLock<JoinSet<AnyResult<()>>>,
|
||||
}
|
||||
|
||||
impl Drop for NeoMediaFactoryImpl {
|
||||
fn drop(&mut self) {
|
||||
log::info!("Dopping NeoMediaFactoryImpl");
|
||||
log::debug!("Dopping NeoMediaFactoryImpl");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,14 +145,11 @@ impl Default for NeoMediaFactoryImpl {
|
||||
|
||||
// Prepare thread that sends data into the appsrcs
|
||||
let mut threads: JoinSet<AnyResult<()>> = Default::default();
|
||||
let mut sender = NeoMediaSender {
|
||||
data_source: ReceiverStream::new(datarx),
|
||||
clientsource: ReceiverStream::new(rx_clientsender),
|
||||
shared: shared.clone(),
|
||||
uid: Default::default(),
|
||||
clientdata: Default::default(),
|
||||
waiting_for_iframe: true,
|
||||
};
|
||||
let mut sender = NeoMediaSenders::new(
|
||||
shared.clone(),
|
||||
ReceiverStream::new(datarx),
|
||||
ReceiverStream::new(rx_clientsender),
|
||||
);
|
||||
threads.spawn(async move {
|
||||
loop {
|
||||
tokio::task::yield_now().await;
|
||||
@@ -150,16 +161,16 @@ impl Default for NeoMediaFactoryImpl {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sender.waiting_for_iframe = true;
|
||||
}
|
||||
Ok(())
|
||||
unreachable!();
|
||||
// Ok(())
|
||||
});
|
||||
|
||||
Self {
|
||||
sender: datasender,
|
||||
clientsender,
|
||||
shared,
|
||||
threads,
|
||||
threads: RwLock::new(threads),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,6 +221,32 @@ fn make_element(kind: &str, name: &str) -> AnyResult<Element> {
|
||||
})
|
||||
}
|
||||
|
||||
fn make_queue(name: &str) -> AnyResult<Element> {
|
||||
let queue = make_element("queue", name)?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
queue.set_property("max-size-bytes", 0u32);
|
||||
queue.set_property("max-size-buffers", 0u32);
|
||||
queue.set_property(
|
||||
"max-size-time",
|
||||
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||
.unwrap_or(0),
|
||||
);
|
||||
Ok(queue)
|
||||
}
|
||||
|
||||
fn make_queue2(name: &str) -> AnyResult<Element> {
|
||||
let queue = make_element("queue2", name)?;
|
||||
queue.set_property("use-buffering", true);
|
||||
queue.set_property("max-size-bytes", 0u32);
|
||||
queue.set_property("max-size-buffers", 0u32);
|
||||
queue.set_property(
|
||||
"max-size-time",
|
||||
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||
.unwrap_or(0),
|
||||
);
|
||||
Ok(queue)
|
||||
}
|
||||
|
||||
impl NeoMediaFactoryImpl {
|
||||
pub(crate) fn buffer_ready(&self) -> bool {
|
||||
self.shared.buffer_ready.load(Ordering::Relaxed)
|
||||
@@ -223,131 +260,25 @@ impl NeoMediaFactoryImpl {
|
||||
let bin = media
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
let clock = bin.clock();
|
||||
// Clear the autogenerated ones
|
||||
for element in bin.iterate_elements().into_iter().flatten() {
|
||||
bin.remove(&element)?;
|
||||
}
|
||||
|
||||
let mut client_data = ClientPipelineData {
|
||||
start_time: self.shared.microseconds.load(Ordering::Relaxed),
|
||||
clock,
|
||||
..Default::default()
|
||||
};
|
||||
let mut client_data = NeoMediaSender::new();
|
||||
|
||||
// Now contruct the actual ones
|
||||
match *self.shared.vid_format.blocking_read() {
|
||||
VidFormats::H265 => {
|
||||
debug!("Building H265 Pipeline");
|
||||
let source = make_element("appsrc", "vidsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
source.set_base_time(ClockTime::from_mseconds(
|
||||
self.shared.microseconds.load(Ordering::Relaxed),
|
||||
));
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(52428800);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Stream);
|
||||
|
||||
let enough_data_start = client_data.enough_data.clone();
|
||||
let enough_data_stop = client_data.enough_data.clone();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
if enough_data_stop.load(Ordering::Relaxed) {
|
||||
log::debug!("Client is in need of data");
|
||||
}
|
||||
enough_data_stop.store(false, Ordering::Relaxed);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
if !enough_data_start.load(Ordering::Relaxed) {
|
||||
log::debug!("Client is full of of data");
|
||||
}
|
||||
enough_data_start.store(true, Ordering::Relaxed);
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
// source.set_caps(Some(
|
||||
// &Caps::builder("video/x-h265").field("parsed", false).build(),
|
||||
// ));
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
let queue = make_element("queue", "source_queue")?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
queue.set_property("max-size-bytes", 104857600u32);
|
||||
let parser = make_element("h265parse", "parser")?;
|
||||
let payload = make_element("rtph265pay", "pay0")?;
|
||||
bin.add_many(&[&source, &queue, &parser, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &parser, &payload])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.vidsrc.replace(source);
|
||||
}
|
||||
VidFormats::H264 => {
|
||||
debug!("Building H264 Pipeline");
|
||||
let source = make_element("appsrc", "vidsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
source.set_base_time(ClockTime::from_mseconds(
|
||||
self.shared.microseconds.load(Ordering::Relaxed),
|
||||
));
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(52428800);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Stream);
|
||||
|
||||
let enough_data_start = client_data.enough_data.clone();
|
||||
let enough_data_stop = client_data.enough_data.clone();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
if enough_data_stop.load(Ordering::Relaxed) {
|
||||
log::debug!("Client is in need of data");
|
||||
}
|
||||
enough_data_stop.store(false, Ordering::Relaxed);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
if !enough_data_start.load(Ordering::Relaxed) {
|
||||
log::debug!("Client is full of of data");
|
||||
}
|
||||
enough_data_start.store(true, Ordering::Relaxed);
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
// source.set_caps(Some(
|
||||
// &Caps::builder("video/x-h264").field("parsed", false).build(),
|
||||
// ));
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
let queue = make_element("queue", "source_queue")?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
|
||||
let parser = make_element("h264parse", "parser")?;
|
||||
let payload = make_element("rtph264pay", "pay0")?;
|
||||
bin.add_many(&[&source, &queue, &parser, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &parser, &payload])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.vidsrc.replace(source);
|
||||
}
|
||||
VidFormats::Unknown => {
|
||||
match (
|
||||
*self.shared.vid_format.blocking_read(),
|
||||
self.shared.buffer_ready.load(Ordering::Relaxed),
|
||||
) {
|
||||
(VidFormats::Unknown, true) | (_, false) => {
|
||||
debug!("Building Unknown Pipeline");
|
||||
let source = make_element("videotestsrc", "vidsrc")?;
|
||||
let source = make_element("videotestsrc", "testvidsrc")?;
|
||||
source.set_property_from_str("pattern", "snow");
|
||||
let queue = make_element("queue", "queue0")?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
queue.set_property("max-size-bytes", 104857600u32);
|
||||
source.set_property("num-buffers", 500i32); // Send buffers then EOS
|
||||
let queue = make_queue("queue0")?;
|
||||
let queue2 = make_queue2("queue2")?;
|
||||
let overlay = make_element("textoverlay", "overlay")?;
|
||||
overlay.set_property("text", "Stream not Ready");
|
||||
overlay.set_property_from_str("valignment", "top");
|
||||
@@ -356,7 +287,7 @@ impl NeoMediaFactoryImpl {
|
||||
let encoder = make_element("jpegenc", "encoder")?;
|
||||
let payload = make_element("rtpjpegpay", "pay0")?;
|
||||
|
||||
bin.add_many(&[&source, &queue, &overlay, &encoder, &payload])?;
|
||||
bin.add_many(&[&source, &queue, &queue2, &overlay, &encoder, &payload])?;
|
||||
source.link_filtered(
|
||||
&queue,
|
||||
&Caps::builder("video/x-raw")
|
||||
@@ -367,42 +298,198 @@ impl NeoMediaFactoryImpl {
|
||||
.build(),
|
||||
)?;
|
||||
// source.link(&queue)?;
|
||||
queue.link(&overlay)?;
|
||||
overlay.link(&encoder)?;
|
||||
encoder.link(&payload)?;
|
||||
Element::link_many(&[&queue, &queue2, &overlay, &encoder, &payload])?;
|
||||
}
|
||||
}
|
||||
|
||||
match *self.shared.aud_format.blocking_read() {
|
||||
AudFormats::Unknown => {}
|
||||
AudFormats::Aac => {
|
||||
debug!("Building Aac pipeline");
|
||||
let source = make_element("appsrc", "audsrc")?
|
||||
(VidFormats::H265, true) => {
|
||||
debug!("Building H265 Pipeline");
|
||||
let source = make_element("appsrc", "vidsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
source.set_base_time(ClockTime::from_mseconds(
|
||||
self.shared.microseconds.load(Ordering::Relaxed),
|
||||
));
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(52428800);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Stream);
|
||||
source.set_stream_type(AppStreamType::Seekable);
|
||||
|
||||
let need_command = client_data.get_commader();
|
||||
let enough_command = client_data.get_commader();
|
||||
let seek_command = client_data.get_commader();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
let _ = need_command.blocking_send(NeoMediaSenderCommand::Resume);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
let _ = enough_command.blocking_send(NeoMediaSenderCommand::Pause);
|
||||
})
|
||||
.seek_data(move |appsrc, seek_pos| {
|
||||
debug!("Send seek H265");
|
||||
let runtime = appsrc.clock().and_then(|clock| {
|
||||
clock.time().and_then(|time| {
|
||||
appsrc.base_time().map(|base_time| {
|
||||
time.saturating_sub(base_time).useconds() as i64
|
||||
})
|
||||
})
|
||||
});
|
||||
let res = seek_command
|
||||
.blocking_send(NeoMediaSenderCommand::Seek(runtime, seek_pos))
|
||||
.is_ok();
|
||||
debug!("Sent seek H265: {}", res);
|
||||
res
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
// source.set_caps(Some(
|
||||
// &Caps::builder("video/x-h265").field("parsed", false).build(),
|
||||
// ));
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
let queue = make_queue("source_queue")?;
|
||||
let queue2 = make_queue2("queue2")?;
|
||||
let parser = make_element("h265parse", "parser")?;
|
||||
// parser.set_property("config-interval", 5i32);
|
||||
let payload = make_element("rtph265pay", "pay0")?;
|
||||
bin.add_many(&[&source, &queue, &queue2, &parser, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &queue2, &parser, &payload])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.update_vid(source);
|
||||
}
|
||||
(VidFormats::H264, true) => {
|
||||
debug!("Building H264 Pipeline");
|
||||
let source = make_element("appsrc", "vidsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(50000000u64); // 50MB
|
||||
// source.set_property("max-buffers", 0u32); // v1.20
|
||||
// source.set_property("max-time", Duration::from_secs_f32(2.25).as_nanos() as u64);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Seekable);
|
||||
|
||||
let need_command = client_data.get_commader();
|
||||
let enough_command = client_data.get_commader();
|
||||
let seek_command = client_data.get_commader();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
let _ = need_command.blocking_send(NeoMediaSenderCommand::Resume);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
let _ = enough_command.blocking_send(NeoMediaSenderCommand::Pause);
|
||||
})
|
||||
.seek_data(move |appsrc, seek_pos| {
|
||||
debug!("Send seek H264: {}", seek_pos);
|
||||
let runtime = appsrc.clock().and_then(|clock| {
|
||||
clock.time().and_then(|time| {
|
||||
appsrc.base_time().map(|base_time| {
|
||||
time.saturating_sub(base_time).useconds() as i64
|
||||
})
|
||||
})
|
||||
});
|
||||
let result = seek_command
|
||||
.blocking_send(NeoMediaSenderCommand::Seek(runtime, seek_pos))
|
||||
.is_ok();
|
||||
debug!(" - Sent seek H264: {}", result);
|
||||
result
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
// source.set_caps(Some(
|
||||
// &Caps::builder("video/x-h264").field("parsed", false).build(),
|
||||
// ));
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
let queue = make_queue("source_queue")?;
|
||||
let queue2 = make_queue2("queue2")?;
|
||||
let parser = make_element("h264parse", "parser")?;
|
||||
// parser.set_property("update-timecode", true);
|
||||
let payload = make_element("rtph264pay", "pay0")?;
|
||||
// payload.set_property("config-interval", 1i32);
|
||||
// let storage = make_element("rtpstorage", "vidstorage")?;
|
||||
// storage.set_property("size-time", Duration::from_secs_f32(2.25).as_nanos() as u64);
|
||||
// let jitter = make_element("rtpjitterbuffer", "pay0")?;
|
||||
// jitter.set_property("latency", Duration::from_secs_f32(2.0).as_nanos() as u32);
|
||||
|
||||
// payload.set_property("config-interval", 5i32);
|
||||
bin.add_many(&[
|
||||
&source, &queue, &queue2, &parser,
|
||||
&payload,
|
||||
// &storage,
|
||||
// &jitter,
|
||||
])?;
|
||||
Element::link_many(&[
|
||||
&source, &queue, &queue2, &parser,
|
||||
&payload,
|
||||
// &storage,
|
||||
// &jitter,
|
||||
])?;
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.update_vid(source);
|
||||
}
|
||||
}
|
||||
|
||||
// let do_aud = false;
|
||||
// if do_aud {
|
||||
match (
|
||||
*self.shared.aud_format.blocking_read(),
|
||||
self.shared.buffer_ready.load(Ordering::Relaxed),
|
||||
) {
|
||||
(AudFormats::Unknown, true) | (_, false) => {}
|
||||
(AudFormats::Aac, true) => {
|
||||
debug!("Building Aac pipeline");
|
||||
let source = make_element("appsrc", "audsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(52428800);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Seekable);
|
||||
|
||||
let need_command = client_data.get_commader();
|
||||
let enough_command = client_data.get_commader();
|
||||
// let seek_command = client_data.get_commader();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
let _ = need_command.blocking_send(NeoMediaSenderCommand::Resume);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
let _ = enough_command.blocking_send(NeoMediaSenderCommand::Pause);
|
||||
})
|
||||
.seek_data(move |_appsrc, _seek_pos| true)
|
||||
.build(),
|
||||
);
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
|
||||
let queue = make_element("queue", "audqueue")?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
queue.set_property("max-size-bytes", 104857600u32);
|
||||
let queue = make_queue("audqueue")?;
|
||||
let queue2 = make_queue2("audqueue2")?;
|
||||
let parser = make_element("aacparse", "audparser")?;
|
||||
let decoder = make_element("decodebin", "auddecoder")?;
|
||||
let encoder = make_element("audioconvert", "audencoder")?;
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
|
||||
bin.add_many(&[&source, &queue, &parser, &decoder, &encoder, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &parser, &decoder])?;
|
||||
bin.add_many(&[
|
||||
&source, &queue, &queue2, &parser, &decoder, &encoder, &payload,
|
||||
])?;
|
||||
Element::link_many(&[&source, &queue, &queue2, &parser, &decoder])?;
|
||||
Element::link_many(&[&encoder, &payload])?;
|
||||
decoder.connect_pad_added(move |_element, pad| {
|
||||
debug!("Linking encoder to decoder: {:?}", pad.caps());
|
||||
@@ -416,9 +503,9 @@ impl NeoMediaFactoryImpl {
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.audsrc.replace(source);
|
||||
client_data.update_aud(source);
|
||||
}
|
||||
AudFormats::Adpcm(block_size) => {
|
||||
(AudFormats::Adpcm(block_size), true) => {
|
||||
debug!("Building Adpcm pipeline");
|
||||
// Original command line
|
||||
// caps=audio/x-adpcm,layout=dvi,block_align={},channels=1,rate=8000
|
||||
@@ -430,15 +517,12 @@ impl NeoMediaFactoryImpl {
|
||||
let source = make_element("appsrc", "audsrc")?
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot cast to appsrc."))?;
|
||||
source.set_base_time(ClockTime::from_mseconds(
|
||||
self.shared.microseconds.load(Ordering::Relaxed),
|
||||
));
|
||||
source.set_is_live(true);
|
||||
source.set_block(false);
|
||||
source.set_property("emit-signals", false);
|
||||
source.set_max_bytes(52428800);
|
||||
source.set_do_timestamp(false);
|
||||
source.set_stream_type(AppStreamType::Stream);
|
||||
source.set_stream_type(AppStreamType::Seekable);
|
||||
source.set_caps(Some(
|
||||
&Caps::builder("audio/x-adpcm")
|
||||
.field("layout", "div")
|
||||
@@ -447,19 +531,34 @@ impl NeoMediaFactoryImpl {
|
||||
.field("rate", 8000i32)
|
||||
.build(),
|
||||
));
|
||||
|
||||
let need_command = client_data.get_commader();
|
||||
let enough_command = client_data.get_commader();
|
||||
// let seek_command = client_data.get_commader();
|
||||
source.set_callbacks(
|
||||
AppSrcCallbacks::builder()
|
||||
.need_data(move |_appsrc, _amt| {
|
||||
let _ = need_command.blocking_send(NeoMediaSenderCommand::Resume);
|
||||
})
|
||||
.enough_data(move |_appsrc| {
|
||||
let _ = enough_command.blocking_send(NeoMediaSenderCommand::Pause);
|
||||
})
|
||||
.seek_data(move |_appsrc, _seek_pos| true)
|
||||
.build(),
|
||||
);
|
||||
|
||||
let source = source
|
||||
.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))?;
|
||||
|
||||
let queue = make_element("queue", "audqueue")?;
|
||||
queue.set_property_from_str("leaky", "downstream");
|
||||
queue.set_property("max-size-bytes", 104857600u32);
|
||||
let queue = make_queue("audqueue")?;
|
||||
let queue2 = make_queue2("audqueue2")?;
|
||||
let decoder = make_element("decodebin", "auddecoder")?;
|
||||
let encoder = make_element("audioconvert", "audencoder")?;
|
||||
let payload = make_element("rtpL16pay", "pay1")?;
|
||||
|
||||
bin.add_many(&[&source, &queue, &decoder, &encoder, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &decoder])?;
|
||||
bin.add_many(&[&source, &queue, &queue2, &decoder, &encoder, &payload])?;
|
||||
Element::link_many(&[&source, &queue, &queue2, &decoder])?;
|
||||
Element::link_many(&[&encoder, &payload])?;
|
||||
decoder.connect_pad_added(move |_element, pad| {
|
||||
debug!("Linking encoder to decoder: {:?}", pad.caps());
|
||||
@@ -473,7 +572,7 @@ impl NeoMediaFactoryImpl {
|
||||
let source = source
|
||||
.dynamic_cast::<AppSrc>()
|
||||
.map_err(|_| anyhow!("Cannot convert appsrc"))?;
|
||||
client_data.audsrc.replace(source);
|
||||
client_data.update_aud(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,4 +581,12 @@ impl NeoMediaFactoryImpl {
|
||||
bin.dynamic_cast::<Element>()
|
||||
.map_err(|_| anyhow!("Cannot cast back"))
|
||||
}
|
||||
|
||||
async fn join(&self) -> AnyResult<()> {
|
||||
let mut threads = self.threads.write().await;
|
||||
while let Some(thread) = threads.join_next().await {
|
||||
thread??;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+795
-325
File diff suppressed because it is too large.
Load diff
+175
-13
@@ -13,10 +13,9 @@ use gstreamer_rtsp_server::{
|
||||
gio::{TlsAuthenticationMode, TlsCertificate},
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
RTSPAuth, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE,
|
||||
RTSPAuth, RTSPFilterResult, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE,
|
||||
};
|
||||
use log::*;
|
||||
use neolink_core::bcmedia::model::*;
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap, HashSet},
|
||||
fs,
|
||||
@@ -24,7 +23,8 @@ use std::{
|
||||
};
|
||||
use tokio::{
|
||||
sync::{mpsc::Sender, RwLock},
|
||||
task::JoinHandle,
|
||||
task::JoinSet,
|
||||
time::{timeout, Duration},
|
||||
};
|
||||
|
||||
glib::wrapper! {
|
||||
@@ -45,7 +45,10 @@ impl NeoRtspServer {
|
||||
Ok(factory)
|
||||
}
|
||||
|
||||
pub(crate) async fn get_sender<T: Into<String>>(&self, tag: T) -> Option<Sender<BcMedia>> {
|
||||
pub(crate) async fn get_sender<T: Into<String>>(
|
||||
&self,
|
||||
tag: T,
|
||||
) -> Option<Sender<FactoryCommand>> {
|
||||
self.imp().get_sender(tag).await
|
||||
}
|
||||
|
||||
@@ -83,11 +86,7 @@ impl NeoRtspServer {
|
||||
self.imp().add_permitted_roles(tag, permitted_users).await
|
||||
}
|
||||
|
||||
pub(crate) async fn run(
|
||||
&self,
|
||||
bind_addr: &str,
|
||||
bind_port: u16,
|
||||
) -> AnyResult<(JoinHandle<AnyResult<()>>, Arc<MainLoop>)> {
|
||||
pub(crate) async fn run(&self, bind_addr: &str, bind_port: u16) -> AnyResult<()> {
|
||||
let server = self;
|
||||
server.set_address(bind_addr);
|
||||
server.set_service(&format!("{}", bind_port));
|
||||
@@ -96,10 +95,34 @@ impl NeoRtspServer {
|
||||
let main_loop = Arc::new(MainLoop::new(None, false));
|
||||
// Run the Glib main loop.
|
||||
let main_loop_thread = main_loop.clone();
|
||||
#[allow(clippy::unit_arg)]
|
||||
let handle = tokio::task::spawn_blocking(move || Ok(main_loop_thread.run()));
|
||||
let handle = tokio::task::spawn_blocking(move || {
|
||||
main_loop_thread.run();
|
||||
AnyResult::Ok(())
|
||||
});
|
||||
timeout(Duration::from_secs(5), self.imp().threads.write())
|
||||
.await
|
||||
.with_context(|| "Timeout waiting to lock Server threads")?
|
||||
.spawn(async move { handle.await? });
|
||||
timeout(Duration::from_secs(5), self.imp().main_loop.write())
|
||||
.await
|
||||
.with_context(|| "Timeout waiting to lock Server main_loop")?
|
||||
.replace(main_loop);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Ok((handle, main_loop))
|
||||
pub(crate) async fn quit(&self) -> AnyResult<()> {
|
||||
if let Some(main_loop) = self.imp().main_loop.read().await.as_ref() {
|
||||
main_loop.quit();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn join(&self) -> AnyResult<()> {
|
||||
let mut threads = self.imp().threads.write().await;
|
||||
while let Some(thread) = threads.join_next().await {
|
||||
thread??;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_up_tls(&self, config: &Config) {
|
||||
@@ -150,6 +173,135 @@ impl NeoRtspServer {
|
||||
pub(crate) async fn buffer_ready<T: Into<String>>(&self, tag: T) -> Option<bool> {
|
||||
self.imp().buffer_ready(tag).await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Clear all sessions on a given path
|
||||
pub(crate) async fn clear_session<T: Into<String>>(&self, tag: T) {
|
||||
let tag: String = tag.into();
|
||||
if let Some(media) = self.imp().medias.read().await.get(&tag) {
|
||||
self.clear_session_paths(media.paths.iter());
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_session_paths<T: AsRef<str>>(&self, paths: impl Iterator<Item = T>) {
|
||||
let paths: Vec<_> = paths.collect();
|
||||
self.client_filter(Some(&mut |_server, client| {
|
||||
let mut close_client = false;
|
||||
client.session_filter(Some(&mut |_client, session| {
|
||||
let mut clean_up = false;
|
||||
session.filter(Some(&mut |_session, session_media| {
|
||||
if paths.iter().any(|p| {
|
||||
let s = p.as_ref();
|
||||
session_media
|
||||
.matches(s)
|
||||
.map(|amt| amt == s.len() as i32)
|
||||
.unwrap_or(false)
|
||||
}) {
|
||||
info!("Removing Session Media");
|
||||
clean_up = true;
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
|
||||
if clean_up {
|
||||
close_client = true;
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
if close_client {
|
||||
client.close();
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// Clear all sessions on the rtsp server that are using the not ready stream
|
||||
pub(crate) async fn clear_session_notready<T: Into<String>>(&self, tag: T) {
|
||||
let tag: String = tag.into();
|
||||
if let Some(media) = self.imp().medias.read().await.get(&tag) {
|
||||
self.clear_session_paths_notready(media.paths.iter());
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_session_paths_notready<T: AsRef<str>>(&self, paths: impl Iterator<Item = T>) {
|
||||
let paths: Vec<_> = paths.collect();
|
||||
self.client_filter(Some(&mut |_server, client| {
|
||||
let mut close_client = false;
|
||||
client.session_filter(Some(&mut |_client, session| {
|
||||
let mut clean_up = false;
|
||||
session.filter(Some(&mut |_session, session_media| {
|
||||
if paths.iter().any(|p| {
|
||||
let s = p.as_ref();
|
||||
session_media
|
||||
.matches(s)
|
||||
.map(|amt| amt == s.len() as i32)
|
||||
.unwrap_or(false)
|
||||
}) {
|
||||
// Path is correct now check for no vidsrc
|
||||
let element = session_media
|
||||
.media()
|
||||
.expect("Media should exist")
|
||||
.element()
|
||||
.dynamic_cast::<gstreamer::Bin>()
|
||||
.expect("Media element should be a bin");
|
||||
// debug!("Searching for testvidsrc on {:?}", element.name());
|
||||
// for child in element.children().iter() {
|
||||
// debug!(" - Child: {:?}", child.name());
|
||||
// }
|
||||
if element.child_by_name("testvidsrc").is_some() {
|
||||
info!("Removing Session Media");
|
||||
clean_up = true;
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
|
||||
if clean_up {
|
||||
close_client = true;
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
if close_client {
|
||||
client.close();
|
||||
RTSPFilterResult::Remove
|
||||
} else {
|
||||
RTSPFilterResult::Keep
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Clear buffers on all senders of a tag
|
||||
#[allow(dead_code)] // Old function, was used to clear buffer on reconnect
|
||||
pub(crate) async fn clear_buffer<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::ClearBuffer).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
|
||||
// Jump to live on all senders of a tag
|
||||
pub(crate) async fn jump_to_live<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::JumpToLive).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for NeoRtspServer {}
|
||||
@@ -163,6 +315,8 @@ struct FactoryData {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct NeoRtspServerImpl {
|
||||
medias: RwLock<HashMap<String, FactoryData>>,
|
||||
threads: RwLock<JoinSet<AnyResult<()>>>,
|
||||
main_loop: RwLock<Option<Arc<MainLoop>>>,
|
||||
}
|
||||
|
||||
impl ObjectImpl for NeoRtspServerImpl {}
|
||||
@@ -182,6 +336,11 @@ impl NeoRtspServerImpl {
|
||||
Entry::Occupied(_occ) => {}
|
||||
Entry::Vacant(vac) => {
|
||||
let media = NeoMediaFactory::new();
|
||||
let thread_media = media.clone();
|
||||
self.threads
|
||||
.write()
|
||||
.await
|
||||
.spawn(async move { thread_media.join().await });
|
||||
vac.insert(FactoryData {
|
||||
factory: media,
|
||||
paths: Default::default(),
|
||||
@@ -191,7 +350,10 @@ impl NeoRtspServerImpl {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_sender<T: Into<String>>(&self, tag: T) -> Option<Sender<BcMedia>> {
|
||||
pub(crate) async fn get_sender<T: Into<String>>(
|
||||
&self,
|
||||
tag: T,
|
||||
) -> Option<Sender<FactoryCommand>> {
|
||||
let key = tag.into();
|
||||
self.medias
|
||||
.read()
|
||||
|
||||
+1
-16
@@ -1,10 +1,7 @@
|
||||
//! Data shared between the various
|
||||
//! components that manage a media stream
|
||||
use gstreamer::Clock;
|
||||
use gstreamer_app::AppSrc;
|
||||
pub use gstreamer_rtsp_server::gio::{TlsAuthenticationMode, TlsCertificate};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
@@ -24,7 +21,6 @@ pub(super) enum AudFormats {
|
||||
pub(super) struct NeoMediaShared {
|
||||
pub(super) vid_format: RwLock<VidFormats>,
|
||||
pub(super) aud_format: RwLock<AudFormats>,
|
||||
pub(super) microseconds: AtomicU64,
|
||||
pub(super) number_of_clients: AtomicUsize,
|
||||
pub(super) buffer_ready: AtomicBool,
|
||||
}
|
||||
@@ -34,19 +30,8 @@ impl Default for NeoMediaShared {
|
||||
Self {
|
||||
vid_format: RwLock::new(VidFormats::Unknown),
|
||||
aud_format: RwLock::new(AudFormats::Unknown),
|
||||
microseconds: AtomicU64::new(0),
|
||||
number_of_clients: AtomicUsize::new(0),
|
||||
buffer_ready: AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(super) struct ClientPipelineData {
|
||||
pub(super) vidsrc: Option<AppSrc>,
|
||||
pub(super) audsrc: Option<AppSrc>,
|
||||
pub(super) start_time: u64,
|
||||
pub(super) inited: bool,
|
||||
pub(super) clock: Option<Clock>,
|
||||
pub(super) enough_data: Arc<AtomicBool>,
|
||||
}
|
||||
+83
-36
@@ -61,11 +61,13 @@ use tokio_stream::StreamExt;
|
||||
|
||||
mod cmdline;
|
||||
mod gst;
|
||||
mod spring;
|
||||
mod states;
|
||||
|
||||
use super::config::Config;
|
||||
pub(crate) use cmdline::Opt;
|
||||
use gst::NeoRtspServer;
|
||||
pub(crate) use spring::*;
|
||||
use states::*;
|
||||
|
||||
/// Entry point for the rtsp subcommand
|
||||
@@ -131,14 +133,15 @@ pub(crate) async fn main(_opt: Opt, mut config: Config) -> Result<()> {
|
||||
|
||||
let bind_addr = config.bind_addr.clone();
|
||||
let bind_port = config.bind_port;
|
||||
let (handle, main_loop) = rtsp.run(&bind_addr, bind_port).await?;
|
||||
set.spawn(async move { handle.await? });
|
||||
rtsp.run(&bind_addr, bind_port).await?;
|
||||
let thread_rtsp = rtsp.clone();
|
||||
set.spawn(async move { thread_rtsp.join().await });
|
||||
|
||||
while let Some(joined) = set.join_next().await {
|
||||
match &joined {
|
||||
Err(_) | Ok(Err(_)) => {
|
||||
// Panicked or error in task
|
||||
main_loop.quit();
|
||||
rtsp.quit().await?;
|
||||
}
|
||||
Ok(Ok(_)) => {
|
||||
// All good
|
||||
@@ -178,43 +181,66 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
|
||||
let _ = loggedin.manage().await;
|
||||
|
||||
let tags = loggedin.shared.get_tags();
|
||||
let rtsp_thread = loggedin.get_rtsp();
|
||||
|
||||
// Clear all buffers present
|
||||
// Uncomment to clear buffers. This is now handlled in the buffer itself,
|
||||
// instead of clearing it restamps it whenever there is a jump in the
|
||||
// timestamps of >1s
|
||||
//
|
||||
// tags.iter()
|
||||
// .map(|tag| rtsp_thread.clear_buffer(tag))
|
||||
// .collect::<FuturesUnordered<_>>()
|
||||
// .collect::<Vec<_>>()
|
||||
// .await;
|
||||
|
||||
// Start pulling data from the camera
|
||||
let mut streaming = loggedin
|
||||
.stream()
|
||||
.await
|
||||
.with_context(|| format!("{}: Could not start stream", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
let tags = streaming.shared.get_tags();
|
||||
let rtsp_thread = streaming.get_rtsp();
|
||||
|
||||
let mut waiter = tokio::time::interval(Duration::from_micros(500));
|
||||
loop {
|
||||
waiter.tick().await;
|
||||
if tags
|
||||
.iter()
|
||||
.map(|tag| rtsp_thread.buffer_ready(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.all(|f| f.unwrap_or(false))
|
||||
.await
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if streaming.get_config().pause.on_motion || streaming.get_config().pause.on_disconnect {
|
||||
log::info!("Pause buffer prepared");
|
||||
// Wait for buffers to be prepared
|
||||
tokio::select! {
|
||||
v = async {
|
||||
let mut waiter = tokio::time::interval(Duration::from_micros(500));
|
||||
loop {
|
||||
waiter.tick().await;
|
||||
if tags
|
||||
.iter()
|
||||
.map(|tag| rtsp_thread.buffer_ready(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.all(|f| f.unwrap_or(false))
|
||||
.await
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
} => v,
|
||||
// Or for stream to error
|
||||
v = streaming.join() => {v},
|
||||
}
|
||||
.with_context(|| format!("{}: Error while waiting for buffers", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
// tokio::task::spawn(async move {
|
||||
// let mut inter = tokio::time::interval(tokio::time::Duration::from_secs_f32(0.01));
|
||||
// loop {
|
||||
// inter.tick().await;
|
||||
// log::info!(
|
||||
// "Users: {:?}, {}",
|
||||
// rtsp_thread.get_number_of_clients("Cammy01::Main").await,
|
||||
// rtsp_thread.num_path_users(&["/Cammy01/mainStream"])
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.jump_to_live(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
// Clear "stream not ready" media to try and force a reconnect
|
||||
// This shoud stop them from watching the "Stream Not Ready" thing
|
||||
debug!("Clearing not ready clients");
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.clear_session_notready(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
log::info!("{}: Buffers prepared", name);
|
||||
|
||||
loop {
|
||||
// Wait for error or reason to pause
|
||||
@@ -238,7 +264,6 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
// Wait for client to disconnect
|
||||
let mut inter = tokio::time::interval(tokio::time::Duration::from_secs_f32(0.01));
|
||||
|
||||
info!("Await Client Pause");
|
||||
loop {
|
||||
inter.tick().await;
|
||||
let total_clients = tags.iter().map(|tag| rtsp_thread.get_number_of_clients(tag)).collect::<FuturesUnordered<_>>().fold(0usize, |acc, f| acc + f.unwrap_or(0usize)).await;
|
||||
@@ -261,13 +286,29 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
// Wait for reason to restart
|
||||
tokio::select! {
|
||||
v = async {
|
||||
// Wait for motion start and client for start
|
||||
let mut motion = paused.get_camera().listen_on_motion().await?;
|
||||
let mut inter = tokio::time::interval(tokio::time::Duration::from_secs_f32(0.01));
|
||||
loop {
|
||||
motion.await_start(Duration::ZERO).await?;
|
||||
let total_clients = tags.iter().map(|tag| rtsp_thread.get_number_of_clients(tag)).collect::<FuturesUnordered<_>>().fold(0usize, |acc, f| acc + f.unwrap_or(0usize)).await;
|
||||
if total_clients > 0 {
|
||||
return Result::<()>::Ok(());
|
||||
}
|
||||
inter.tick().await;
|
||||
}
|
||||
}, if paused.get_config().pause.on_motion && paused.get_config().pause.on_disconnect => {
|
||||
info!("Motion and Client Resume");
|
||||
v.with_context(|| "Error while processing motion/client messages")
|
||||
},
|
||||
v = async {
|
||||
// Wait for motion start
|
||||
let mut motion = paused.get_camera().listen_on_motion().await?;
|
||||
motion.await_start(Duration::ZERO).await
|
||||
}, if paused.get_config().pause.on_motion => {
|
||||
}, if paused.get_config().pause.on_motion && !paused.get_config().pause.on_disconnect => {
|
||||
info!("Motion Resume");
|
||||
v.map_err(|e| anyhow!("Error while processing motion messages: {:?}", e))
|
||||
v.with_context(|| "Error while processing motion messages")
|
||||
},
|
||||
v = async {
|
||||
// Wait for client to connect
|
||||
@@ -280,7 +321,7 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
}, if paused.get_config().pause.on_disconnect => {
|
||||
}, if paused.get_config().pause.on_disconnect && !paused.get_config().pause.on_motion => {
|
||||
info!("Client Resume");
|
||||
v
|
||||
},
|
||||
@@ -294,6 +335,12 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
.with_context(|| format!("{}: Error while paused", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.jump_to_live(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
streaming = paused
|
||||
.stream()
|
||||
.await
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
//! A critically damped spring
|
||||
use tokio::time::Instant;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Spring {
|
||||
last_update: Instant,
|
||||
target: f64,
|
||||
value: f64,
|
||||
velocity: f64,
|
||||
halflife: f64,
|
||||
}
|
||||
|
||||
impl Spring {
|
||||
pub(crate) fn new(value: f64, target: f64, halflife: f64) -> Self {
|
||||
Self {
|
||||
value,
|
||||
target,
|
||||
halflife,
|
||||
last_update: Instant::now(),
|
||||
velocity: 0.0f64,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn update(&mut self) {
|
||||
let now = Instant::now();
|
||||
let dt = now - self.last_update;
|
||||
self.last_update = now;
|
||||
spring_update(
|
||||
&mut self.value,
|
||||
self.target,
|
||||
&mut self.velocity,
|
||||
self.halflife,
|
||||
dt.as_secs_f64(),
|
||||
);
|
||||
}
|
||||
|
||||
// pub(crate) fn value(&self) -> f64 {
|
||||
// self.value
|
||||
// }
|
||||
|
||||
// pub(crate) fn value_u32(&self) -> u32 {
|
||||
// self.value.max(std::u32::MIN as f64).floor().min(std::u32::MAX as f64) as u32
|
||||
// }
|
||||
pub(crate) fn value_i64(&self) -> i64 {
|
||||
self.value
|
||||
.max(std::i64::MIN as f64)
|
||||
.floor()
|
||||
.min(std::i64::MAX as f64) as i64
|
||||
}
|
||||
pub(crate) fn value_u64(&self) -> u64 {
|
||||
self.value
|
||||
.max(std::u64::MIN as f64)
|
||||
.floor()
|
||||
.min(std::u64::MAX as f64) as u64
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_target(&mut self, target: f64) {
|
||||
self.target = target;
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // Used in debug print
|
||||
pub(crate) fn get_target(&self) -> f64 {
|
||||
self.target
|
||||
}
|
||||
|
||||
pub(crate) fn reset_to(&mut self, target: f64) {
|
||||
self.target = target;
|
||||
self.value = target;
|
||||
self.velocity = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
const EPS: f64 = 1e-5;
|
||||
fn halflife_to_damping(halflife: f64) -> f64 {
|
||||
(4.0 * std::f64::consts::LN_2) / (halflife + EPS)
|
||||
}
|
||||
|
||||
// fn damping_to_halflife(damping: f32) -> f32 {
|
||||
// (4.0f32 * std::f32::consts::LN_2) / (damping + EPS)
|
||||
// }
|
||||
fn fast_negexp(x: f64) -> f64 {
|
||||
1.0 / (1.0 + x + 0.48 * x * x + 0.235 * x * x * x)
|
||||
}
|
||||
|
||||
fn spring_update(value: &mut f64, target: f64, velocity: &mut f64, halflife: f64, dt: f64) {
|
||||
if halflife.abs() < 1e-3 {
|
||||
*value = target;
|
||||
*velocity = 0.0;
|
||||
} else {
|
||||
let y = halflife_to_damping(halflife) / 2.0;
|
||||
let j0 = *value - target;
|
||||
let j1 = *velocity + j0 * y;
|
||||
let eydt = fast_negexp(y * dt);
|
||||
|
||||
*value = eydt * (j0 + j1 * dt) + target;
|
||||
*velocity = eydt * (*velocity - j1 * y * dt);
|
||||
}
|
||||
}
|
||||
@@ -32,22 +32,28 @@ impl Camera<LoggedIn> {
|
||||
|
||||
pub(crate) async fn manage(&self) -> Result<()> {
|
||||
let cam_time = self.state.camera.get_time().await?;
|
||||
let mut update = false;
|
||||
if let Some(time) = cam_time {
|
||||
info!(
|
||||
"{}: Camera time is already set: {}",
|
||||
self.shared.config.name, time
|
||||
);
|
||||
if self.shared.config.update_time {
|
||||
update = true;
|
||||
}
|
||||
} else {
|
||||
update = true;
|
||||
warn!(
|
||||
"{}: Camera has no time set, Updating",
|
||||
self.shared.config.name
|
||||
);
|
||||
}
|
||||
if update {
|
||||
use time::OffsetDateTime;
|
||||
// We'd like now_local() but it's deprecated - try to get the local time, but if no
|
||||
// time zone, fall back to UTC.
|
||||
let new_time =
|
||||
OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
|
||||
|
||||
warn!(
|
||||
"{}: Camera has no time set, setting to {}",
|
||||
self.shared.config.name, new_time
|
||||
);
|
||||
info!("{}: Setting time to {}", self.shared.config.name, new_time);
|
||||
match self.state.camera.set_time(new_time).await {
|
||||
Ok(_) => {
|
||||
let cam_time = self.state.camera.get_time().await?;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Data is streamed into a gstreamer source
|
||||
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use anyhow::{anyhow, Context, Error, Result};
|
||||
use log::*;
|
||||
use neolink_core::bcmedia::model::BcMedia;
|
||||
use tokio::time::{timeout, Duration};
|
||||
@@ -11,6 +11,7 @@ use tokio::{sync::RwLock, task::JoinSet};
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind as Stream};
|
||||
|
||||
use super::{camera::Camera, LoggedIn};
|
||||
use crate::rtsp::gst::FactoryCommand;
|
||||
|
||||
pub(crate) struct Streaming {
|
||||
pub(crate) camera: BcCamera,
|
||||
@@ -54,7 +55,9 @@ impl Camera<Streaming> {
|
||||
loop {
|
||||
tokio::task::yield_now().await;
|
||||
// debug!("Straming: Get");
|
||||
let data = timeout(Duration::from_secs(15), stream_data.get_data()).await??;
|
||||
let data = timeout(Duration::from_secs(15), stream_data.get_data())
|
||||
.await
|
||||
.with_context(|| "Timed out waiting for new Media Frame")??;
|
||||
// debug!("Straming: Got");
|
||||
match &data {
|
||||
Ok(BcMedia::InfoV1(_)) => trace!("{}: - InfoV1", &tag_thread),
|
||||
@@ -66,7 +69,12 @@ impl Camera<Streaming> {
|
||||
Err(_) => trace!(" - Error"),
|
||||
}
|
||||
// debug!("Straming: Send");
|
||||
sender.send(data?).await?;
|
||||
timeout(
|
||||
Duration::from_secs(15),
|
||||
sender.send(FactoryCommand::BcMedia(data?)),
|
||||
)
|
||||
.await
|
||||
.with_context(|| "Timed out waiting to send Media Frame")??;
|
||||
// debug!("Straming: Sent");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user