diff --git a/.github/workflows/armhf.yml b/.github/workflows/armhf.yml new file mode 100644 index 0000000..9df0098 --- /dev/null +++ b/.github/workflows/armhf.yml @@ -0,0 +1,51 @@ +name: Build ARMHF + +on: [push, pull_request] + +jobs: + armhfbuild: + name: build-armhf + runs-on: ubuntu-latest + container: node:current-buster-slim + steps: + - uses: actions/checkout@v2 + - name: Install basic tools + run: | + apt-get update + apt-get install --assume-yes --no-install-recommends sudo curl ca-certificates build-essential + - name: Add armhf as a foreign architecture + run: | + sudo dpkg --add-architecture armhf + - name: Install cross compile tools + run: | + sudo apt-get update + sudo apt-get install --assume-yes --no-install-recommends gcc-arm-linux-gnueabihf + - name: Install armhf gstreamer + run: | + sudo apt-get update + sudo apt-get install --assume-yes --no-install-recommends \ + libgstrtspserver-1.0-dev:armhf \ + libgstreamer1.0-dev:armhf \ + libgtk2.0-dev:armhf + - name: Install rustup armv7 + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + target: armv7-unknown-linux-gnueabihf + - name: Build armfh + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --all-features --target=armv7-unknown-linux-gnueabihf + env: + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc + CC_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc + CXX_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++ + PKG_CONFIG_ALLOW_CROSS: 1 + PKG_CONFIG_PATH: /usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ + PKG_CONFIG_LIBDIR: /usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ + - uses: actions/upload-artifact@v2 + with: + name: release-armhf + path: "target/armv7-unknown-linux-gnueabihf/release/neolink*" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 84ae5f8..2b1b1ee 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -12,16 +12,16 @@ jobs: shell: bash run: | unset HAS_SECRET - if [-n $SECRET]; then HAS_SECRET='true' ; fi + if [ -n $SECRET ]; then HAS_SECRET='true' ; fi echo ::set-output name=HAS_SECRET_TOKEN::${HAS_SECRET} env: SECRET: "${{ secrets.DOCKER_TOKEN }}" - name: Check out the repo uses: actions/checkout@v2 - if: ${{ steps.vars.outputs.HAS_SECRET }} + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} - name: Push to Docker Hub uses: docker/build-push-action@v1 - if: ${{ steps.vars.outputs.HAS_SECRET }} + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} with: username: thirtythreeforty password: ${{ secrets.DOCKER_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 9a3ec9b..aaa95d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "anyhow" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" + [[package]] name = "arrayvec" version = "0.5.1" @@ -41,12 +47,24 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +[[package]] +name = "base-x" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + [[package]] name = "cfg-if" version = "0.1.10" @@ -90,12 +108,12 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061" +checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" dependencies = [ + "cfg-if", "crossbeam-utils", - "maybe-uninit", ] [[package]] @@ -146,6 +164,18 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + [[package]] name = "env_logger" version = "0.7.1" @@ -173,6 +203,21 @@ dependencies = [ "synstructure", ] +[[package]] +name = "futures" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.5" @@ -180,6 +225,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -238,9 +284,13 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project", "pin-utils", "proc-macro-hack", @@ -250,11 +300,12 @@ dependencies = [ [[package]] name = "gio" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd10f9415cce39b53f8024bf39a21f84f8157afa52da53837b102e585a296a5" +checksum = "3c5492e80b45e6c56214894a9a0cbe1340ab5066eb44a2dbe151393b6d7942c0" dependencies = [ "bitflags", + "futures", "futures-channel", "futures-core", "futures-io", @@ -263,27 +314,28 @@ dependencies = [ "glib", "glib-sys", "gobject-sys", - "lazy_static", "libc", + "once_cell", + "thiserror", ] [[package]] name = "gio-sys" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fad225242b9eae7ec8a063bb86974aca56885014672375e5775dc0ea3533911" +checksum = "35993626299fbcaa73c0a19be8fdd01c950f9f3d3ac9cb4fb5532b924ab1a5d7" dependencies = [ "glib-sys", "gobject-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "glib" -version = "0.9.3" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40fb573a09841b6386ddf15fd4bc6655b4f5b106ca962f57ecaecde32a0061c0" +checksum = "a5e0533f48640d86e8e2f3cee778a9f97588d4a0bec8be065ee51ea52346d6c1" dependencies = [ "bitflags", "futures-channel", @@ -291,38 +343,55 @@ dependencies = [ "futures-executor", "futures-task", "futures-util", + "glib-macros", "glib-sys", "gobject-sys", - "lazy_static", "libc", + "once_cell", +] + +[[package]] +name = "glib-macros" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41486a26d1366a8032b160b59065a59fb528530a46a49f627e7048fb8c064039" +dependencies = [ + "anyhow", + "heck", + "itertools", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "glib-sys" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95856f3802f446c05feffa5e24859fe6a183a7cb849c8449afc35c86b1e316e2" +checksum = "b6cda4af5c2f4507b7a3535b798dca2135293f4bc3a17f399ce244ef15841c4c" dependencies = [ "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gobject-sys" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31d1a804f62034eccf370006ccaef3708a71c31d561fee88564abe71177553d9" +checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c" dependencies = [ "glib-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer" -version = "0.15.7" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce8664a114cd6ec16bece783d5eee59496919915b1f6884400ba4a953274a163" +checksum = "ce4ce1ba28d3293b8cb8c3d33f50e6da2e5cfeefa59a0d10d922ab8015791609" dependencies = [ "bitflags", "cfg-if", @@ -333,18 +402,20 @@ dependencies = [ "glib-sys", "gobject-sys", "gstreamer-sys", - "lazy_static", "libc", "muldiv", "num-rational", + "once_cell", "paste", + "pretty-hex", + "thiserror", ] [[package]] name = "gstreamer-app" -version = "0.15.6" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789784e8d42f5add1e1e965cf9f7e2d09e21dd0756bae6148f971db9a761d6a9" +checksum = "b2e9ca4df66162132a8d0083c5c5a40dea29ac619acb02395dba09e26bc1c500" dependencies = [ "bitflags", "futures-core", @@ -356,28 +427,28 @@ dependencies = [ "gstreamer-app-sys", "gstreamer-base", "gstreamer-sys", - "lazy_static", "libc", + "once_cell", ] [[package]] name = "gstreamer-app-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf869ce152c23bca5d761ab62146b47f750d0b28d4d499731857532897d48167" +checksum = "55d739f1289f37352884d716df1c571d365fe3eacb8164bc1996e8070053c949" dependencies = [ "glib-sys", "gstreamer-base-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-base" -version = "0.15.4" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42552f75cc6c260b0be180d5c955f4cd74bd170289c622404c25f1210b521c12" +checksum = "872893487ce8876f18c63730402822804c5762869f631d8e3e6b18aafc8399f0" dependencies = [ "bitflags", "glib", @@ -391,22 +462,22 @@ dependencies = [ [[package]] name = "gstreamer-base-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba384f52174b3c586593fca32642680a9e67961fea9f4cd8419f678965023bed" +checksum = "c0fd5a77d39b47568fba01274dfcb28dc32382513c697009f80b89ef63fd32fd" dependencies = [ "glib-sys", "gobject-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-net" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac25e8d5593775b3a641a39410f9b25e460177982efd853f92d173419e91585a" +checksum = "caf6b7e17559f3afd74285d3007c9268bbd47ecb692dcb27944a2f54385aba73" dependencies = [ "gio", "glib", @@ -419,23 +490,23 @@ dependencies = [ [[package]] name = "gstreamer-net-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b454eef96c2fd27f8ea701024be277227ae1fe88042ffc60e7cc5c452a2660" +checksum = "ffc58fef62ae238322f24ca6589bf39f885888ab3c345b8ce15998f9a0f1b199" dependencies = [ "gio-sys", "glib-sys", "gobject-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-rtsp" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "971814f153a41e9f170b30ebcfba08f13a57a03e1bfb4ac26a872577ee8bdef4" +checksum = "17c0154054089449fa595da343660d37a9241cdb8a8794a982c7dfc4a82629f1" dependencies = [ "bitflags", "gio", @@ -453,9 +524,9 @@ dependencies = [ [[package]] name = "gstreamer-rtsp-server" -version = "0.15.5" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79512e2f481f1fd2523a3e16b94f055a17c6c68a86da3a4b868085e5ac47ec8" +checksum = "ab8e59ac0e59b7c503359d4c617d1ca447ce2d263397b80d96f66312fb75ffc4" dependencies = [ "bitflags", "gio", @@ -472,15 +543,15 @@ dependencies = [ "gstreamer-sdp", "gstreamer-sdp-sys", "gstreamer-sys", - "lazy_static", "libc", + "once_cell", ] [[package]] name = "gstreamer-rtsp-server-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17e73413368846d1a5e475fa29dd710232d5479e02c402f3bab82bcd6b9f35df" +checksum = "d09f446a03f00fe0859ca41ca6ab0150392e261eab8151c1f0e1067356e34dce" dependencies = [ "gio-sys", "glib-sys", @@ -490,14 +561,14 @@ dependencies = [ "gstreamer-sdp-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-rtsp-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6bbda651f809e0a48500f9bde3c07d662ed688051a57501dcb5f9d7b2a5fd9" +checksum = "2e12559129061c3b4cc218ff997f42a7ba8a23f3c0db356e8f5a54e12fa7c3dd" dependencies = [ "gio-sys", "glib-sys", @@ -505,14 +576,14 @@ dependencies = [ "gstreamer-sdp-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-sdp" -version = "0.15.6" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "547b3b0eb9e01e13ab5cc066c817e2ab758f83790145f80f62d3c8e43c2966af" +checksum = "6ebbe4fbea4f2c67982c667ba57b64b01d43bc3dc1dc4a8d3512cb33a2adc7c1" dependencies = [ "glib", "glib-sys", @@ -524,27 +595,27 @@ dependencies = [ [[package]] name = "gstreamer-sdp-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e88ac4f9f20323ef3409dddcea3bbf58364ff8eea10b14da5303bfcb23347a" +checksum = "289c7f258d3387ae91c6058555922d8cf0704fc2bc870d1a03190bc81b040655" dependencies = [ "glib-sys", "gobject-sys", "gstreamer-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] name = "gstreamer-sys" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d18da01b97d0ab5896acd5151e4c155acefd0e6c03c3dd24dd133ba054053db" +checksum = "1321f34d53bb5f60ab1aaf581e29b664b8d41601714ee1bb7dbea490b5b9ff60" dependencies = [ "glib-sys", "gobject-sys", "libc", - "pkg-config", + "system-deps", ] [[package]] @@ -558,9 +629,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] @@ -614,6 +685,15 @@ dependencies = [ "unindent", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.6" @@ -641,15 +721,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.71" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if", ] @@ -701,12 +781,14 @@ dependencies = [ "crossbeam", "env_logger", "err-derive", + "gio", "glib", "gstreamer", "gstreamer-app", "gstreamer-rtsp", "gstreamer-rtsp-server", "indoc", + "itertools", "lazy_static", "log", "md5", @@ -715,6 +797,7 @@ dependencies = [ "serde", "socket2", "structopt", + "time", "toml", "validator", "validator_derive", @@ -746,9 +829,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" dependencies = [ "autocfg", "num-integer", @@ -797,18 +880,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" +checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" +checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" dependencies = [ "proc-macro2", "quote", @@ -823,15 +906,30 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" + +[[package]] +name = "pretty-hex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be91bcc43e73799dc46a6c194a55e7aae1d86cc867c860fd4a436019af21bd8c" + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] [[package]] name = "proc-macro-error" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -842,22 +940,20 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", - "syn-mid", "version_check", ] [[package]] name = "proc-macro-hack" -version = "0.5.16" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" +checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" [[package]] name = "proc-macro-nested" @@ -867,9 +963,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] @@ -891,9 +987,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "regex" @@ -913,6 +1009,15 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + [[package]] name = "rustversion" version = "1.0.3" @@ -936,6 +1041,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.114" @@ -958,15 +1078,21 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" dependencies = [ "itoa", "ryu", "serde", ] +[[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + [[package]] name = "slab" version = "0.4.2" @@ -985,12 +1111,70 @@ dependencies = [ "winapi", ] +[[package]] +name = "standback" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0437cfb83762844799a60e1e3b489d5ceb6a650fbacb86437badc1b6d87b246" +dependencies = [ + "version_check", +] + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "strsim" version = "0.8.0" @@ -1022,27 +1206,34 @@ dependencies = [ ] [[package]] -name = "syn" -version = "1.0.33" +name = "strum" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" +checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" + +[[package]] +name = "strum_macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "synstructure" version = "0.12.4" @@ -1055,6 +1246,21 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "system-deps" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b" +dependencies = [ + "heck", + "pkg-config", + "strum", + "strum_macros", + "thiserror", + "toml", + "version-compare", +] + [[package]] name = "termcolor" version = "1.1.0" @@ -1073,6 +1279,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.0.1" @@ -1082,6 +1308,44 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "time" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a51cadc5b1eec673a685ff7c33192ff7b7603d0b75446fb354939ee615acb15" +dependencies = [ + "cfg-if", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", +] + +[[package]] +name = "time-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9b6e9f095bc105e183e3cd493d72579be3181ad4004fceb01adbe9eecab2d" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + [[package]] name = "tinyvec" version = "0.3.3" @@ -1186,12 +1450,72 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version-compare" +version = "0.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" + [[package]] name = "version_check" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wasm-bindgen" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 6610062..dde0a86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,11 @@ crossbeam = "0.7" env_logger = "*" err-derive = "0.2" glib = "*" -gio = "0.8" -gstreamer = "0.15" -gstreamer-app = "0.15" -gstreamer-rtsp = "0.15" -gstreamer-rtsp-server = { version = "0.15", features = ["v1_12", "v1_14"]} +gio = "0.9" +gstreamer = "0.16" +gstreamer-app = "0.16" +gstreamer-rtsp = "0.16" +gstreamer-rtsp-server = { version = "0.16", features = ["v1_12", "v1_14"]} lazy_static = "1.4" log = { version = "0.4" } indoc = "0.3" @@ -28,6 +28,7 @@ regex = "1" serde = { version = "1.0", features = ["derive"] } socket2 = "0.3" structopt = "0.3" +time = "0.2" toml = "0.5" yaserde = "0.3.16" yaserde_derive = "0.3.16" diff --git a/README.md b/README.md index c583af5..1915358 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,7 @@ Currently it has been tested on the following cameras: - B800/D800 - B400/D400 - E1 - -It *should* support the Lumus as well, but this has not yet been tested. -Please test if you have one, and [open an issue](https://github.com/thirtythreeforty/neolink/issues/new/choose) if you encounter problems: +- Lumus Neolink does not support other cameras such as the RLC-420, since they already [provide native RTSP](https://support.reolink.com/hc/en-us/articles/360007010473-How-to-Live-View-Reolink-Cameras-via-VLC-Media-Player). diff --git a/docs/Setting Up Neolink For Use With Blue Iris.md b/docs/Setting Up Neolink For Use With Blue Iris.md index 8bbfc52..f029edd 100644 --- a/docs/Setting Up Neolink For Use With Blue Iris.md +++ b/docs/Setting Up Neolink For Use With Blue Iris.md @@ -4,6 +4,7 @@ Stock Reolink cameras do not support use with non-proprietary surveillance softw **This guide applies to the following camera models:** - B800/D800 +- B400/D400 - E1 @@ -30,17 +31,7 @@ _This is the most reliable setup since Neolink cannot autodetect when a camera's _You will have to reconnect to the camera once you have changed the IP address_ -### 3. Set the camera's time to your local network time and disable Auto Reboot -_When a camera reboots, it loses its date and time settings. If the camera's time is not set, Neolink will recursively "time out" every one second and will not stream video. Setting the time and disabling auto reboot on the camera is a workaround for [issue #14](https://github.com/thirtythreeforty/neolink/issues/14)._ -1. In the Reolink PC app, login to your camera. -2. Click "Device Settings" -> "System General" -> "Synchronize Local Time." -3. Click "Ok." - -4. Click "Device Settings" -> "Maintenance." - -5. Uncheck "Enable Auto Reboot." - -### 4. Set a Password +### 3. Set a Password _It's recommended that you set a password for each of your cameras. If you want to use the Reolink Mobile App, it makes you set a password for each camera anyway._ 1. In the Reolink PC app, login to your camera. 2. Click "Device Settings" -> "Manage User." @@ -65,13 +56,22 @@ The config file tells Neolink how to connect to your camera and serve the video stream = "both" 2. Change `cameraname` to a legible, phonetic name that describes your camera. Leave the quotes around the name. + 3. The default username is `admin`; leave this unless you've created another user. + 4. Replace `password` with the password you set on the camera. If you chose to not use a password, remove this line from the config file. Again, leave the quotes. + 5. Replace `192.168.1.10:9000` with the IP address you set for your camera. Note: The port, `:9000`, should remain at the end of your IP address. This is the proprietary "media port" that Reolink uses. + 6. The `stream` line allows you to choose which stream type to use. Neolink supports streaming two streams, the main-stream, and the sub-stream. It can stream either one, or both. If you wish to stream both streams, leave this line as is. If you wish to stream _only_ the main-stream, change `both` to `mainStream`. If you wish to stream only the sub-stream, change `both` to `subStream`. + + Note: Reolink D400/B400 Cameras **_do not support serving both streams at once_**, so you must manually choose which stream type to use. For best quality, choose the main stream. + 7. For multiple cameras, copy and paste the entire `[[cameras]]` block below the first. Each camera entry must begin with `[[cameras]]`. +Note: For **E1 Cameras**, refer to [the readme](https://github.com/thirtythreeforty/neolink/#configuration) for instructions on adding the `format =` line. This configuration will be done automatically in the future. + ### 3. Start Neolink 1. Open a command prompt in the directory that contains Neolink and your config file. 2. Run the following command (with your correct config file name): @@ -80,7 +80,7 @@ The config file tells Neolink how to connect to your camera and serve the video You should get login messages that look something like this: -![Login Messages](docs/screenshots/login_messages.JPG) +![Login Messages](screenshots/login_messages.JPG) Note: Neolink hosts all streams on localhost port 8554. Each camera has a designated path for the sub-stream and the main-stream. Neolink gets the name of the path from the name of the camera you set in the config file. So the path to the sample camera's main-stream would be `127.0.0.1:8554/cameraname/mainStream` and the path to the sample camera's sub-stream would be `127.0.0.1:8554/cameraname/subStream`. @@ -97,7 +97,7 @@ _There are a few tricks to getting Blue Iris to work properly with Neolink's RTS 3. Uncheck "Enable Motion Detector." 4. Enable "Direct to disc recording." -![New Camera Window](docs/screenshots/new_camera.JPG) +![New Camera Window](screenshots/new_camera.JPG) 5. Click "OK." @@ -120,6 +120,87 @@ _Once you click "OK" on the "New Camera" window, Blue Iris should dump you direc 7. Click "OK." -![](docs/screenshots/new_camera_config.JPG) +![](screenshots/new_camera_config.JPG) **Congrats, you have set up your first camera!** + +## Step Four: Run Everything at Startup + +_In the future, Neolink will support being a Windows Service. For now, you must manually set up Neolink to run at startup._ + +### 1. Enable Blue Iris as a Windows service + +_Blue Iris natively supports running as a Windows service._ + +1. In Blue Iris, click the "Main Menu" button, then click "Settings/Info." +2. In the "Startup" tab, under "Operating System," check "Run as a Windows Service (no UI, run again for console)." +3. Type in the username and password. +4. Once you click OK, you should see a popup window that says "Service has been installed..." + +5. Restart Blue Iris or your computer to start the Blue Iris service. + +### 2. Create a Scheduled Task that starts Neolink + +_The best way to have Neolink run at startup is create a Scheduled Task that starts the Neolink process at computer startup._ + +1. Create a simple bash file that starts Neolink. + + _For the Task Scheduler to successfully start Neolink, you must run the start commands in the same directory that contains Neolink and its config files. This is best accomplished by creating a bash file that "changes directories" to the directory that contains Neolink._ + 1. Navigate in Windows Explorer to the directory in which you placed Neolink and its config files. + + 2. Create a file with a `.cmd` file extension (e.g. `neolink.cmd`). + + _Note: You may need to create a text (`.txt`) file and run `ren neolink.txt neolink.cmd` in a command prompt to obtain the correct file extension._ + + 3. Edit the file. Copy the commands below, changing your respective directories and file names. + + `cd C:\Path\to\Neolink\Folder` + + `neolink --config config.toml` + + 4. Save the file and run it. Make sure Neolink successfully starts. + +2. Create Scheduled Task + + 1. Open the Task Scheduler + + 2. In the "Actions" pane, click "Create Basic Task." + + 3. Name and describe the task and click "Next." + + 4. Select "When the Computer Starts" in the trigger settings. Click "Next." + + 5. Select "Start a Program" in the action settings. Click "Next." + + 6. Under "Program/script:," navigate to the `.cmd` file that you created and select it. Click "Next." + + 7. Check "Open the properties dialog for this task when I click finish." Click "Finish." + + _Your Finish windows should look something like this:_ + + ![](screenshots/taskfinishwindow.JPG) + + 8. In the "Properties" window, in the "General" tab, select "Run whether or not the User is logged on." + + 9. Also check "Run with highest privileges." + + 10. In the "Settings tab," **_uncheck "Stop the task if it is running longer than:"_** + + 11. Check "Run Task as soon as possible..." + + 12. Check "If the task fails, restart every:" + + 13. For redundancy, enter `999` into the number of restart tries. + + _The Settings tab should look something like this:_ + + ![](screenshots/tasksettingstab.JPG) + + 14. In the "Conditions" tab, you may want to uncheck "Start the task only if the computer is on AC Power." + 15. You may also want to check "Start only if the following network connection is available." This may prevent Neolink from retrying to connect many times if your computer takes a long time to connect to its network. + + 16. Click "OK," and enter the Username and Password. + +### 3. Test everything. + +You have now completed all the setup steps! Restart your computer and check if all the programs start as desired. \ No newline at end of file diff --git a/docs/screenshots/taskfinishwindow.JPG b/docs/screenshots/taskfinishwindow.JPG new file mode 100644 index 0000000..1291545 Binary files /dev/null and b/docs/screenshots/taskfinishwindow.JPG differ diff --git a/docs/screenshots/tasksettingstab.JPG b/docs/screenshots/tasksettingstab.JPG new file mode 100644 index 0000000..b375dd6 Binary files /dev/null and b/docs/screenshots/tasksettingstab.JPG differ diff --git a/docs/unix_service.md b/docs/unix_service.md new file mode 100644 index 0000000..418b24a --- /dev/null +++ b/docs/unix_service.md @@ -0,0 +1,98 @@ +# Creating a Service for Neolink + +This will guide you through creating a service for neolink that +can be used on linux machines such as ubuntu and debian +buster/stetch or any other os that uses systemd. + +The general steps are: + +1. Create an unprivileged user to run neolink +2. Set up neolink somewhere the unprivileged user can run it +3. Creating the service file + +## Creating the unprivileged user + +For this I will use the username neolinker. Any unused name would be fine. + +```bash +sudo adduser --system --no-create-home --shell /bin/false neolinker +``` + +Depending on your flavour of linux `adduser` may have also created +a group of the same name. If it did not, you can create a group with: + +```bash +sudo addgroup --system neolinker +``` + +## Setting up neolink + +For this we will put neolink in `/usr/local/bin` and the config in `/usr/local/etc` but any directory readable by the `neolinker` user would be fine. + +We will also secure the config file so that only neolinker (and root) can read it. We want to do this because it contains passwords. + +```bash +sudo cp neolink /usr/local/bin/neolink +sudo cp my_config.toml /usr/local/etc/neolink_config.toml +sudo chmod 755 /usr/local/bin/neolink +sudo chown neolinker:neolinker /usr/local/etc/neolink_config.toml +sudo chmod 600 /usr/local/etc/neolink_config.toml +``` + +## Creating the service + +We will create a systemd service. This service will need to point to our files for using neolink and also instruct it to start with our unprivileged user. + +Create a file here `/etc/systemd/system/neolink.service` with the following contents (you will need admin privileges to write to this location): + +``` +[Install] +WantedBy=multi-user.target + +[Unit] +Description=Neolink service + +[Service] +Type=simple +ExecStart=/usr/local/bin/neolink --config /usr/local/etc/neolink_config.toml +Restart=on-failure +User=neolinker +Group=neolinker + +``` + +And that's it + +## Controlling the Service + +You can now control the service with the usual commands + +To start it use: + +```bash +systemctl start neolink +``` + +To stop it use: + +```bash +systemctl stop neolink +``` + +To check it's running use: + +```bash +systemctl status neolink +``` + +To make it run at startup from now on: + +```bash +systemctl enable neolink +``` + +You can check it's log file with + +```bash +journalctl -xeu neolink +``` diff --git a/docs/unix_setup.md b/docs/unix_setup.md new file mode 100644 index 0000000..40886ef --- /dev/null +++ b/docs/unix_setup.md @@ -0,0 +1,289 @@ +# Setting up Neolink on Linux + +This will go through the first steps of adding neolink onto a +linux based computer. + +There are many flavours of linux so the name of some packages +may not exactly match. You are expected to be able to find the +correct names yourselves. + +The general steps we will follow in this guide are as follows: + +1. Install dependancies + +2. Download neolink + +3. Setup the config + +4. Run neolink + +## Installing the Dependencies + +The dependencies for neolink include: + +- Gstreamer RTSP server + +- Gstreamer good plugin set + +- Gstreamer bad plugin set + +- glib 2.0 + +Glib2.0 is usually already installed on most modern unix flavours. +But the others will likely need to be installed via your package +manager. + +Here are some examples for commands of package managers + +- ubuntu, buster, stretch + + ```bash + sudo apt install \ + libgstrtspserver-1.0-0 \ + libgstreamer1.0-0 \ + libgstreamer-plugins-bad1.0-0 \ + libgstreamer-plugins-good1.0-0 \ + gstreamer1.0-plugins-good \ + gstreamer1.0-plugins-bad + ``` + +- arch, manjaro + + ```bash + sudo pacman -S \ + gstreamer \ + gst-plugins-bad \ + gst-plugins-good \ + + # You will need this from AUR, and therefore need to install + # yay first (see below if you haven't done this yet) + sudo yay -S \ + gst-rtsp-server + ``` + + If your on archlinux or manjaro and you need to install `yay` do this: + + ```bash + git clone https://aur.archlinux.org/yay.git + cd yay + makepkg -si + ``` + +## Downloading neolink + +You now need to get a copy of neolink. You can get that from this +github [under the CI assets](https://github.com/thirtythreeforty/neolink/actions?query=branch%3Amaster+workflow%3ACI). + +Currently amd64 and armv7 are officially released. + +If you are installing on a raspberry pi, you will need the armv7 build. + +You will get a zip file called `release-ubuntu-18.04.zip`, unzip it with + +```bash +unzip "release-ubuntu-18.04.zip" +``` + +This will extract two files called `neolink` and `neolink.d`. These are +the binaries we will be using. + +## Setting up the Configuration File + +Neolink uses a toml file for configuration. A sample toml can be found in the +source code called `sample_config.toml`. + +You can download it with + +```bash +curl -LJO 'https://github.com/thirtythreeforty/neolink/raw/master/sample_config.toml' +``` + +Open up the file in your favourite text editor. + +For the most basic setup you need to change only the parts in `[[ cameras ]]`. +Neolink can connect to any number of supported reolink cameras at once. Each +camera requires its own `[[ cameras ]]` block. Here is an example one: + +```toml +[[cameras]] +name = "driveway" +username = "admin" +password = "12345678" +address = "192.168.1.187:9000" +``` + +Set the `name` to any value you want, this will be the name of the rtsp stream. +In this tutorial I will assume you leave it as "driveway". + +The username and passwords are the same ones used in the official reolink app. + +The address is the ip address of the camera. You should set and use a fixed ip +for your camera. There are many ways to get a fixed ip address for your camera +including changing the settings in the reolink app. +Or by assigning a fixed DHCP address from your router. How to do either of +these things is beyond the scope of this tutorial. + +- Note for E1 and Lumus + + If your camera is an E1 or a Lumus you will need to add the `format` line + to your `[[ cameras ]]` block like this: + + ```toml + [[cameras]] + name = "driveway" + username = "admin" + password = "12345678" + address = "192.168.1.187:9000" + format = "h264" + ``` + + This will tell neolink that this camera uses the H264 format for its video. + Future version of neolink will auto detect this. + +Set up as many `[[ cameras ]]` as you want and save the file as `my_config.toml` + +## Running Neolink + +We are now ready to run neolink. Open up and terminal and navigate to the +folder where `neolink` and `my_config.toml` are. + +Run neolink with: + +``` +./neolink --config my_config.toml +``` + +You should see messages such as: + +``` +[DATE TIME INFO neolink] Neolink 0.3.0 (unknown commit) release +[DATE TIME INFO neolink] camera: Connecting to camera at xxx.xxx.xxx.xxx:9000 +[DATE TIME INFO neolink] camera: Connecting to camera at xxx.xxx.xxx.xxx:9000 +[DATE TIME INFO neolink] camera: Connected to camera, starting video stream mainStream +[DATE TIME INFO neolink] camera: Connected to camera, starting video stream subStream +``` + +Neolink should now be running :) + + +## Testing with ffprobe + +To test neolink we will use `ffprobe`. + +If you do not have `ffmpeg` installed yet do it now through your package +manager: + +```bash +sudo apt install ffmpeg +``` + +You must leave neolink running at the same time you run ffprobe. Neolink is a +translator and it cannot translate reolink -> rtsp if you close it. The easiest +way to do this is to open two terminals. One with neolink running and the other +for running ffprobe. + +In a new terminal run: + +```bash +ffprobe rtsp://127.0.0.1:8554/driveway +``` + +Where you replace `driveway` with the name of your camera. + +A successful run should report something like this at the end: + +``` +Input #0, rtsp, from 'rtsp://127.0.0.1:8554/driveway': + Metadata: + title : Session streamed with GStreamer + comment : rtsp-server + Duration: N/A, start: 0.114267, bitrate: N/A + Stream #0:0: Video: h264 (High), yuv420p(progressive), 2304x1296, 90k tbr, 90k tbn, 180k tbc +``` + +You should also test the lower resolution subStream: + +```bash +ffprobe rtsp://127.0.0.1:8554/driveway/subStream +``` + +If the mainStream fails but the subStream succeeds you may need to add +`format = "h264"` to your `[[ cameras ]]` section of your config. + +## Common Errors + +- Missing dependancies + + If when start neolink you get a message such as: + + ``` + libgstrtspserver-1.0.so.0: cannot open shared object file: No such file or directory + ``` + + You have not installed all of the dependencies repeat the `Installing the Dependencies` + section of this guide. + +- Not turned on + + If when using ffprobe to test you get: + + ``` + Connection to tcp://xxx.xxx.xxx.xxx:8554?timeout=0 failed: Connection refused + rtsp://xxx.xxx.xxx.xxx:8554/driveway: Connection refused ``` + ``` + + You have probably closed neolink. You should leave it running in an open + terminal window whenever you want to use it. If you want to run it in the + background, consider following the unix_service guide in the `docs/` folder + of the source code. + +- More advanced debugging required + + For other errors you will need to enable more debugging messages before + running neolink for better diagnoses. To do this stop neolink and restart it + with this command. + + ```bash + GST_DEBUG=3 ./neolink --config my_config.toml + ``` + + This will print out a lot more information to the terminal. Try to connect + to it with ffprobe and read the error messages it generates. + + - Advanced debugging: Missing plugins + + If while running advanced debugging you get a message like this: + + ``` + GST_ELEMENT_FACTORY gstelementfactory.c:456:gst_element_factory_make: no such element factory "h265parse"! + ``` + + This means that you are missing the gstreamer plugins. You must have both + the good and the bad set of plugins. Please repeat the + `Installing the Dependencies` section of this guide. + + - Advanced debugging: Incorrect video format + + If while running advanced debugging you get a message like this: + + ``` + h265parse gsth265parse.c:1110:gst_h265_parse_handle_frame: broken/invalid nal Type: 48 Invalid, Size: 1073 will be dropped + ``` + + You have not set the format to `h264` in the `[[ cameras ]]` config while + using an E1 or Lumus camera. + + Change the `[[ cameras ]]` config to include `format = "h264"` and restart + neolink + + (If you are using another camera and you need to use h264 please let us + know via an issue so we can update this guide) + +- Something else + + If you still have problems open an issue on github and attach the + neolink log. You can save the log to file with the following command: + + ```bash + GST_DEBUG=3 ./neolink --config my_config.toml 2>&1 > neolink.log + ``` diff --git a/src/bc/model.rs b/src/bc/model.rs index 0848247..6f4ddcc 100644 --- a/src/bc/model.rs +++ b/src/bc/model.rs @@ -9,6 +9,8 @@ pub(super) const MAGIC_HEADER: u32 = 0xabcdef0; pub const MSG_ID_LOGIN: u32 = 1; pub const MSG_ID_VIDEO: u32 = 3; pub const MSG_ID_PING: u32 = 93; +pub const MSG_ID_GET_GENERAL: u32 = 104; +pub const MSG_ID_SET_GENERAL: u32 = 105; pub const CHUNK_SIZE: usize = 40000; diff --git a/src/bc/xml.rs b/src/bc/xml.rs index d1fc015..727ae68 100644 --- a/src/bc/xml.rs +++ b/src/bc/xml.rs @@ -37,6 +37,10 @@ pub struct BcXml { pub device_info: Option, #[yaserde(rename = "Preview")] pub preview: Option, + #[yaserde(rename = "SystemGeneral")] + pub system_general: Option, + #[yaserde(rename = "Norm")] + pub norm: Option, } impl AllTopXmls { @@ -125,6 +129,37 @@ pub struct Extension { pub binary_data: u32, } +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct SystemGeneral { + #[yaserde(attribute)] + pub version: String, + + #[yaserde(rename = "timeZone")] + pub time_zone: Option, + pub year: Option, + pub month: Option, + pub day: Option, + pub hour: Option, + pub minute: Option, + pub second: Option, + + #[yaserde(rename = "osdFormat")] + pub osd_format: Option, + #[yaserde(rename = "timeFormat")] + pub time_format: Option, + + pub language: Option, + #[yaserde(rename = "deviceName")] + pub device_name: Option, +} + +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct Norm { + #[yaserde(attribute)] + pub version: String, + norm: String, +} + pub fn xml_ver() -> String { "1.1".to_string() } diff --git a/src/bc_protocol.rs b/src/bc_protocol.rs index 40b13ea..30dbdf6 100644 --- a/src/bc_protocol.rs +++ b/src/bc_protocol.rs @@ -11,18 +11,20 @@ use std::time::Duration; use Md5Trunc::*; mod connection; +mod time; pub struct BcCamera { address: SocketAddr, connection: Option, logged_in: bool, - rx_timeout: Duration, } use crate::Never; type Result = std::result::Result; +const RX_TIMEOUT: Duration = Duration::from_secs(5); + #[derive(Debug, Error)] pub enum Error { #[error(display = "Communication error")] @@ -70,16 +72,11 @@ impl BcCamera { address, connection: None, logged_in: false, - rx_timeout: Duration::from_secs(1), }) } - pub fn set_rx_timeout(&mut self, timeout: Duration) { - self.rx_timeout = timeout; - } - pub fn connect(&mut self) -> Result<()> { - self.connection = Some(BcConnection::new(self.address, self.rx_timeout)?); + self.connection = Some(BcConnection::new(self.address, RX_TIMEOUT)?); Ok(()) } @@ -126,7 +123,7 @@ impl BcCamera { sub_login.send(legacy_login)?; - let legacy_reply = sub_login.rx.recv_timeout(self.rx_timeout)?; + let legacy_reply = sub_login.rx.recv_timeout(RX_TIMEOUT)?; let nonce; match legacy_reply.body { BcBody::ModernMsg(ModernMsg { @@ -180,7 +177,7 @@ impl BcCamera { ); sub_login.send(modern_login)?; - let modern_reply = sub_login.rx.recv_timeout(self.rx_timeout)?; + let modern_reply = sub_login.rx.recv_timeout(RX_TIMEOUT)?; let device_info; match modern_reply.body { @@ -237,7 +234,7 @@ impl BcCamera { sub_ping.send(ping)?; - sub_ping.rx.recv_timeout(self.rx_timeout)?; + sub_ping.rx.recv_timeout(RX_TIMEOUT)?; Ok(()) } @@ -275,7 +272,7 @@ impl BcCamera { BinaryDataKind::VideoDataIframe, BinaryDataKind::VideoDataPframe, ], - self.rx_timeout, + RX_TIMEOUT, )?; // We now have a complete interesting packet. Send it to gst. // Process the packet diff --git a/src/bc_protocol/time.rs b/src/bc_protocol/time.rs new file mode 100644 index 0000000..7b97c20 --- /dev/null +++ b/src/bc_protocol/time.rs @@ -0,0 +1,132 @@ +use super::{BcCamera, Error, Result, RX_TIMEOUT}; +use crate::bc::{model::*, xml::*}; +use time::{date, Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; + +impl BcCamera { + pub fn get_time(&self) -> Result> { + let connection = self + .connection + .as_ref() + .expect("Must be connected to get time"); + let sub_get_general = connection.subscribe(MSG_ID_GET_GENERAL)?; + let get = Bc { + meta: BcMeta { + msg_id: MSG_ID_GET_GENERAL, + client_idx: 0, + encrypted: true, + class: 0x6414, + }, + body: BcBody::ModernMsg(ModernMsg::default()), + }; + + sub_get_general.send(get)?; + let msg = sub_get_general.rx.recv_timeout(RX_TIMEOUT)?; + + if let BcBody::ModernMsg(ModernMsg { + xml: + Some(BcXml { + system_general: + Some(SystemGeneral { + time_zone: Some(time_zone), + year: Some(year), + month: Some(month), + day: Some(day), + hour: Some(hour), + minute: Some(minute), + second: Some(second), + .. + }), + .. + }), + .. + }) = msg.body + { + let datetime = match try_build_timestamp( + time_zone, year, month, day, hour, minute, second + ) { + Ok(dt) => dt, + Err(e) => return Err(Error::UnintelligibleReply { + reply: msg, + why: "Could not parse date", + }) + }; + + // This code was written in 2020; I'm trying to catch all the possible epochs that + // cameras might reset themselves to. My B800 resets to Jan 1, 1999, but I can't + // guarantee that Reolink won't pick some newer date. Therefore, last year ought + // to be new enough, yet still distant enough that it won't interfere with anything + const BOUNDARY: Date = date!(2019-01-01); + + // detect if no time is actually set, and return Ok(None): that is, operation + // succeeded, and there is no time set + if datetime.date() < BOUNDARY { + Ok(None) + } else { + Ok(Some(datetime)) + } + } else { + Err(Error::UnintelligibleReply { + reply: msg, + why: "Reply did not contain SystemGeneral with all time fields filled out", + }) + } + } + + pub fn set_time(&self, timestamp: OffsetDateTime) -> Result<()> { + let connection = self + .connection + .as_ref() + .expect("Must be connected to set time"); + let sub_set_general = connection.subscribe(MSG_ID_SET_GENERAL)?; + let set = Bc::new_from_xml( + BcMeta { + msg_id: MSG_ID_SET_GENERAL, + client_idx: 0, + encrypted: true, + class: 0x6414, + }, + BcXml { + system_general: Some(SystemGeneral { + version: xml_ver(), + //osd_format: Some("MDY".to_string()), + time_format: Some(0), + // Reolink uses positive seconds to indicate a negative UTC offset: + time_zone: Some(-timestamp.offset().as_seconds()), + year: Some(timestamp.year()), + month: Some(timestamp.month()), + day: Some(timestamp.day()), + hour: Some(timestamp.hour()), + minute: Some(timestamp.minute()), + second: Some(timestamp.second()), + ..Default::default() + }), + ..Default::default() + }, + ); + + sub_set_general.send(set)?; + let msg = sub_set_general.rx.recv_timeout(RX_TIMEOUT)?; + + Ok(()) + } +} + +fn try_build_timestamp( + timezone: i32, + year: i32, + month: u8, + day: u8, + hour: u8, + minute: u8, + second: u8, +) -> std::result::Result { + let date = Date::try_from_ymd(year, month, day)?; + let time = Time::try_from_hms(hour, minute, second)?; + let offset = if timezone > 0 { + UtcOffset::west_seconds(timezone as u32) + } else { + UtcOffset::east_seconds(-timezone as u32) + }; + + Ok(PrimitiveDateTime::new(date, time).assume_offset(offset)) +} diff --git a/src/config.rs b/src/config.rs index 5f06d49..dd2c370 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,7 @@ pub struct CameraConfig { pub username: String, pub password: Option, + // no longer used, but still here so we can warn users: pub timeout: Option, #[validate(regex( diff --git a/src/gst.rs b/src/gst.rs index a4d5500..cfa178d 100644 --- a/src/gst.rs +++ b/src/gst.rs @@ -169,7 +169,7 @@ impl RtspServer { // We seperate reading the file and changing to a PEM so that we get different error messages. let cert_contents = fs::read_to_string(cert_file).expect("TLS file not found"); let cert = - TlsCertificate::new_from_pem(&cert_contents).expect("Not a valid TLS certificate"); + TlsCertificate::from_pem(&cert_contents).expect("Not a valid TLS certificate"); auth.set_tls_certificate(Some(&cert)); auth.set_tls_authentication_mode(client_auth); diff --git a/src/main.rs b/src/main.rs index ae2bd20..435cc79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,8 +202,9 @@ fn camera_main( let mut connected = false; (|| { let mut camera = BcCamera::new_with_addr(camera_config.camera_addr)?; - if let Some(timeout) = camera_config.timeout { - camera.set_rx_timeout(timeout); + if let Some(_) = camera_config.timeout { + warn!("The undocumented `timeout` config option has been removed and is no longer needed."); + warn!("Please update your config file."); } info!( @@ -215,9 +216,34 @@ fn camera_main( camera.login(&camera_config.username, camera_config.password.as_deref())?; connected = true; + info!("{}: Connected and logged in", camera_config.name); + + let cam_time = camera.get_time()?; + if let Some(time) = cam_time { + info!( + "{}: Camera time is already set: {}", + camera_config.name, time + ); + } else { + let new_time = time::OffsetDateTime::now_local(); + warn!( + "{}: Camera has no time set, setting to {}", + camera_config.name, new_time + ); + camera.set_time(new_time)?; + let cam_time = camera.get_time()?; + if let Some(time) = cam_time { + info!( + "{}: Camera time is now set: {}", + camera_config.name, time + ); + } else { + error!("{}: Camera did not accept new time (is {} an admin?)", camera_config.name, camera_config.username); + } + } info!( - "{}: Connected to camera, starting video stream {}", + "{}: Starting video stream {}", camera_config.name, stream_name ); camera.start_video(output, stream_name)