From 0423d83311eb6ef00615407c0f282db6b833c572 Mon Sep 17 00:00:00 2001 From: Breadway Date: Wed, 22 Jul 2026 12:03:32 +0800 Subject: [PATCH] init commit --- .gitignore | 3 + Cargo.lock | 1437 ++++++++++++++++++++++++++++++ Cargo.toml | 30 + LICENSE | 21 + README.md | 17 + models/fetch.sh | 10 + packaging/systemd/crustd.service | 19 + src/bread.rs | 69 ++ src/camera.rs | 149 ++++ src/config.rs | 179 ++++ src/idle.rs | 126 +++ src/lid.rs | 28 + src/main.rs | 259 ++++++ src/motion.rs | 49 + src/presence.rs | 75 ++ src/vision.rs | 110 +++ 16 files changed, 2581 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100755 models/fetch.sh create mode 100644 packaging/systemd/crustd.service create mode 100644 src/bread.rs create mode 100644 src/camera.rs create mode 100644 src/config.rs create mode 100644 src/idle.rs create mode 100644 src/lid.rs create mode 100644 src/main.rs create mode 100644 src/motion.rs create mode 100644 src/presence.rs create mode 100644 src/vision.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..45f6f1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/models/*.onnx +*.onnx diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..630d11d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1437 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex 1.3.0", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" + +[[package]] +name = "cc" +version = "1.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96" +dependencies = [ + "find-msvc-tools", + "shlex 2.0.1", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crustd" +version = "0.1.0" +dependencies = [ + "anyhow", + "directories", + "ort", + "serde", + "serde_json", + "tokio", + "toml", + "tracing", + "tracing-subscriber", + "v4l", + "wayland-client", + "wayland-protocols", +] + +[[package]] +name = "der" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b" +dependencies = [ + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hmac-sha256" +version = "1.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec9d92d097f4749b64e8cc33d924d9f40a2d4eb91402b458014b781f5733d60f" + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "http" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "libredox" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652" +dependencies = [ + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "lzma-rust2" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e20f57f9918e5bd7bc58c22cdd70a6afc7375d4dd9683af5f2b34bd3d2bba619" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08" +dependencies = [ + "autocfg", + "rawpointer", +] + +[[package]] +name = "memchr" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "native-tls" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ndarray" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d" +dependencies = [ + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "portable-atomic", + "portable-atomic-util", + "rawpointer", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "openssl" +version = "0.10.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45" +dependencies = [ + "bitflags 2.13.0", + "cfg-if", + "foreign-types", + "libc", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "ort" +version = "2.0.0-rc.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7de3af33d24a745ffb8fab904b13478438d1cd52868e6f17735ef6e1f8bf133" +dependencies = [ + "ndarray", + "ort-sys", + "smallvec", + "tracing", + "ureq", +] + +[[package]] +name = "ort-sys" +version = "2.0.0-rc.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7b497d21a8b6fbb4b5a544f8fadb77e801a09ae0add9e411d31c6f89e3c1e90" +dependencies = [ + "hmac-sha256", + "lzma-rust2", + "ureq", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pem-rfc7468" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.39.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdcc8dd4e2f670d309a5f0e83fe36dfdc05af317008fea29144da1a2ac858e5e" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.13.0", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags 2.13.0", + "errno", + "libc", + "linux-raw-sys 0.12.1", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046" +dependencies = [ + "zeroize", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.13.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "socks" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b" +dependencies = [ + "byteorder", + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "2.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix 1.1.4", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "ureq" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea7109cdcd5864d4eeb1b58a1648dc9bf520360d7af16ec26d0a9354bafcfc0" +dependencies = [ + "base64", + "der", + "log", + "native-tls", + "percent-encoding", + "rustls-pki-types", + "socks", + "ureq-proto", + "utf8-zero", + "webpki-root-certs", +] + +[[package]] +name = "ureq-proto" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e994ba84b0bd1b1b0cf92878b7ef898a5c1760108fe7b6010327e274917a808c" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "utf8-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + +[[package]] +name = "v4l" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8fbfea44a46799d62c55323f3c55d06df722fbe577851d848d328a1041c3403" +dependencies = [ + "bitflags 1.3.2", + "libc", + "v4l2-sys-mit", +] + +[[package]] +name = "v4l2-sys-mit" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6779878362b9bacadc7893eac76abe69612e8837ef746573c4a5239daf11990b" +dependencies = [ + "bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wayland-backend" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2857dd20b54e916ec7253b3d6b4d5c4d7d4ca2c33c2e11c6c76a99bd8744755d" +dependencies = [ + "cc", + "downcast-rs", + "rustix 1.1.4", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c7c96bb74690c3189b5c9cb4ca1627062bb23693a4fad9d8c3de958260144" +dependencies = [ + "bitflags 2.13.0", + "rustix 1.1.4", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6" +dependencies = [ + "bitflags 2.13.0", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c324a910fd86ebdc364a3e61ec1f11737d3b1d6c273c0239ee8ff4bc0d24b4a" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.44", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +dependencies = [ + "memchr", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f733916 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "crustd" +version = "0.1.0" +edition = "2021" +description = "Tiered, power-efficient presence detection daemon for Bread" +license = "MIT" + +[[bin]] +name = "crustd" +path = "src/main.rs" + +[dependencies] +tokio = { version = "1", features = ["rt-multi-thread", "net", "time", "macros", "signal", "sync", "io-util"] } +v4l = "0.14" +ort = { version = "2.0.0-rc.12", default-features = false, features = ["std", "download-binaries", "tls-native", "copy-dylibs"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +anyhow = "1" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +directories = "5" +wayland-client = "0.31" +wayland-protocols = { version = "0.32", features = ["client", "staging"] } + +[profile.release] +opt-level = 2 +lto = true +codegen-units = 1 +strip = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cb2aee2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Breadway Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..602d6e3 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# crustd + +Tiered, power-efficient presence detection daemon for [Bread](https://github.com/Breadway/bread). + +## Building + +```bash +cargo build --release +``` + +## Running + +```bash +./target/release/crustd +``` + +See `packaging/` for distribution packaging. diff --git a/models/fetch.sh b/models/fetch.sh new file mode 100755 index 0000000..2e0eaee --- /dev/null +++ b/models/fetch.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Downloads the tier-1 presence face detector (UltraFace-RFB-320, ~1.2MB, MIT-licensed) +# from the upstream Ultra-Light-Fast-Generic-Face-Detector-1MB repo. +set -euo pipefail +cd "$(dirname "$0")" +curl -fsSL -o ultraface-rfb-320.onnx \ + "https://raw.githubusercontent.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/master/models/onnx/version-RFB-320.onnx" +mkdir -p ~/.local/share/crustd/models +cp ultraface-rfb-320.onnx ~/.local/share/crustd/models/ultraface-rfb-320.onnx +echo "installed to ~/.local/share/crustd/models/ultraface-rfb-320.onnx" diff --git a/packaging/systemd/crustd.service b/packaging/systemd/crustd.service new file mode 100644 index 0000000..1c2292e --- /dev/null +++ b/packaging/systemd/crustd.service @@ -0,0 +1,19 @@ +[Unit] +Description=crustd - tiered presence detection for Bread +After=graphical-session.target + +[Service] +Type=simple +ExecStart=%h/.local/bin/crustd +Restart=on-failure +RestartSec=5 + +# Power/hardening: no network, no writes outside its own state dir, camera access only. +PrivateTmp=true +ProtectSystem=strict +ReadWritePaths=%h/.local/share/crustd %h/.config/crustd +NoNewPrivileges=true +SupplementaryGroups=video render + +[Install] +WantedBy=default.target diff --git a/src/bread.rs b/src/bread.rs new file mode 100644 index 0000000..28aea4c --- /dev/null +++ b/src/bread.rs @@ -0,0 +1,69 @@ +use std::path::PathBuf; + +use anyhow::{Context, Result}; +use serde_json::json; +use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; +use tokio::net::UnixStream; +use tracing::warn; + +/// Thin client for breadd's line-delimited JSON-RPC IPC socket. Connects fresh for +/// each emit rather than holding a persistent connection — presence changes are rare +/// (debounced, seconds-to-minutes apart), so there's no reason to keep a socket open +/// between them. +pub struct BreadClient { + socket_path: PathBuf, + event_prefix: String, +} + +impl BreadClient { + pub fn new(configured_path: &str, event_prefix: String) -> Self { + let socket_path = if configured_path.is_empty() { + default_socket_path() + } else { + PathBuf::from(configured_path) + }; + Self { + socket_path, + event_prefix, + } + } + + /// Emits `.` with the given JSON payload. Errors are logged + /// and swallowed by the caller's choice — a missing/unreachable bread daemon + /// shouldn't crash the presence loop. + pub async fn emit(&self, suffix: &str, data: serde_json::Value) -> Result<()> { + let event = format!("{}.{}", self.event_prefix, suffix); + let mut stream = UnixStream::connect(&self.socket_path) + .await + .with_context(|| format!("connecting to bread socket at {:?}", self.socket_path))?; + + let request = json!({ + "id": "crustd", + "method": "emit", + "params": { "event": event, "data": data }, + }); + let line = format!("{}\n", serde_json::to_string(&request)?); + stream + .write_all(line.as_bytes()) + .await + .context("writing emit request")?; + + let mut reader = BufReader::new(stream); + let mut response = String::new(); + reader + .read_line(&mut response) + .await + .context("reading emit response")?; + + if !response.contains("\"emitted\":true") { + warn!(response = %response.trim(), "bread did not confirm emit"); + } + + Ok(()) + } +} + +fn default_socket_path() -> PathBuf { + let runtime_dir = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".to_string()); + PathBuf::from(runtime_dir).join("bread").join("breadd.sock") +} diff --git a/src/camera.rs b/src/camera.rs new file mode 100644 index 0000000..d2af957 --- /dev/null +++ b/src/camera.rs @@ -0,0 +1,149 @@ +use std::path::{Path, PathBuf}; + +use anyhow::{Context, Result}; +use v4l::buffer::Type; +use v4l::io::mmap::Stream as MmapStream; +use v4l::io::traits::CaptureStream; +use v4l::video::Capture; +use v4l::FourCC; + +/// A single grayscale frame: raw luma bytes plus the dimensions they came from. +pub struct GrayFrame { + pub width: u32, + pub height: u32, + pub luma: Vec, +} + +impl GrayFrame { + /// Mean luma across the whole frame — used both to normalize the RGB motion + /// diff against global brightness changes, and as a cheap non-ML occupancy + /// signal on IR frames (something close to the sensor reflects a lot more IR + /// light back than an empty room, independent of whether a face is detected). + pub fn mean_luma(&self) -> f32 { + if self.luma.is_empty() { + return 0.0; + } + self.luma.iter().map(|&b| b as u64).sum::() as f32 / self.luma.len() as f32 + } +} + +/// Which physical sensor a device should be: used to auto-resolve a stable path +/// instead of trusting a possibly-renumbered `/dev/videoN` node. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum DeviceKind { + Rgb, + Ir, +} + +/// Resolves a configured device string to an actual path. +/// +/// A value of `"auto:rgb"` / `"auto:ir"` probes the stable `/dev/v4l/by-path/*` +/// symlinks and picks by capture capability (supports MJPG/YUYV color formats = +/// RGB sensor; GREY-only = IR sensor) rather than trusting `/dev/videoN` numbering, +/// which isn't stable across reboots or external camera plug events. Any other +/// value is used as a literal path, for explicit overrides. +pub fn resolve_device(configured: &str, want: DeviceKind) -> Result { + if configured != "auto:rgb" && configured != "auto:ir" { + return Ok(PathBuf::from(configured)); + } + + let by_path = Path::new("/dev/v4l/by-path"); + let entries = std::fs::read_dir(by_path) + .with_context(|| format!("listing {by_path:?} for camera auto-detection"))?; + + let mut seen = std::collections::HashSet::new(); + for entry in entries.flatten() { + let symlink_path = entry.path(); + let Ok(resolved) = std::fs::canonicalize(&symlink_path) else { + continue; + }; + if !seen.insert(resolved.clone()) { + continue; // by-path lists each physical device under multiple aliases + } + + let Ok(dev) = v4l::Device::with_path(&resolved) else { + continue; + }; + let Ok(formats) = Capture::enum_formats(&dev) else { + continue; + }; + + let has_color = formats + .iter() + .any(|f| f.fourcc == FourCC::new(b"MJPG") || f.fourcc == FourCC::new(b"YUYV")); + let has_grey = formats.iter().any(|f| f.fourcc == FourCC::new(b"GREY")); + + let matches = match want { + DeviceKind::Rgb => has_color, + DeviceKind::Ir => has_grey && !has_color, + }; + if matches { + return Ok(resolved); + } + } + + anyhow::bail!("no {want:?} camera found under {by_path:?}; set camera.rgb_device / camera.ir_device explicitly in crustd.toml") +} + +/// Grabs one YUYV frame from the RGB camera and returns just the luma (Y) plane. +/// +/// Opens the device, captures, and drops it before returning — nothing about this +/// camera is left streaming between polls. +pub fn grab_rgb_luma(device: &str, width: u32, height: u32) -> Result { + let mut dev = v4l::Device::with_path(device) + .with_context(|| format!("opening rgb camera {device}"))?; + + let mut fmt = Capture::format(&dev).context("reading current rgb format")?; + fmt.width = width; + fmt.height = height; + fmt.fourcc = FourCC::new(b"YUYV"); + Capture::set_format(&dev, &fmt).context("setting rgb format")?; + let fmt = Capture::format(&dev).context("reading confirmed rgb format")?; + + let mut stream = MmapStream::with_buffers(&mut dev, Type::VideoCapture, 2) + .context("starting rgb capture stream")?; + + // First frame after (re)starting a stream is often stale/partially exposed; take the second. + let _ = stream.next().context("priming rgb stream")?; + let (buf, _meta) = stream.next().context("capturing rgb frame")?; + + let mut luma = Vec::with_capacity((fmt.width * fmt.height) as usize); + for chunk in buf.chunks_exact(2) { + luma.push(chunk[0]); + } + + Ok(GrayFrame { + width: fmt.width, + height: fmt.height, + luma, + }) +} + +/// Grabs `count` frames from the IR camera in a single short burst and returns them. +/// +/// The device is opened once for the whole burst and dropped immediately after — +/// callers must not hold the IR camera open outside of this function, since that's +/// what keeps the IR illuminator from flashing continuously. +pub fn grab_ir_burst(device: &str, count: u32) -> Result> { + let mut dev = + v4l::Device::with_path(device).with_context(|| format!("opening ir camera {device}"))?; + + let fmt = Capture::format(&dev).context("reading ir format")?; + let mut stream = MmapStream::with_buffers(&mut dev, Type::VideoCapture, 2) + .context("starting ir capture stream")?; + + // Discard the first frame post-open the same way as the RGB path. + let _ = stream.next().context("priming ir stream")?; + + let mut frames = Vec::with_capacity(count as usize); + for _ in 0..count { + let (buf, _meta) = stream.next().context("capturing ir frame")?; + frames.push(GrayFrame { + width: fmt.width, + height: fmt.height, + luma: buf.to_vec(), + }); + } + + Ok(frames) +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9de2498 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,179 @@ +use std::path::PathBuf; + +use anyhow::Result; +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct Config { + pub camera: CameraConfig, + pub motion: MotionConfig, + pub presence: PresenceConfig, + pub bread: BreadConfig, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct CameraConfig { + /// Visible-light camera used for the always-on motion gate. Never opens the IR emitter. + pub rgb_device: String, + /// IR camera used only in short bursts for face detection/recognition. + pub ir_device: String, +} + +impl Default for CameraConfig { + fn default() -> Self { + Self { + // Auto-resolved by capture capability via /dev/v4l/by-path at startup — + // see camera::resolve_device. Set to a literal /dev/videoN to override. + rgb_device: "auto:rgb".to_string(), + ir_device: "auto:ir".to_string(), + } + } +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct MotionConfig { + /// Poll interval when nothing has moved recently. + pub idle_poll_ms: u64, + /// Poll interval right after motion was seen, before it settles back down. + pub active_poll_ms: u64, + /// Ceiling for backoff when the room has been still for a long time. + pub max_idle_poll_ms: u64, + /// RGB poll interval while presence is already confirmed. This is the retention + /// signal — typing, mouse movement, posture shifts — and it's cheap (no IR, no + /// inference), so it can run continuously without a power or annoyance cost. + pub present_poll_ms: u64, + /// How long RGB has to be continuously still while present before we bother + /// spending an IR burst to double-check someone's still there. A person actively + /// working is essentially never RGB-still for this long, so in normal use this + /// keeps the IR camera dark for the entire session. + pub present_stillness_timeout_ms: u64, + /// After an IR retention check comes back with no face, how soon to retry — much + /// faster than `present_stillness_timeout_ms` so a real departure is confirmed + /// (and presence released) within `release_frames` short retries instead of + /// waiting a full stillness timeout each time. A positive check at any point + /// resets back to the slow cadence. + pub present_retry_after_miss_ms: u64, + /// How long the compositor's seat (keyboard/mouse) must be idle, via + /// ext-idle-notify-v1, before Present-mode falls back to the camera-based + /// retention cascade at all. While input is active, no camera is opened — + /// typing/mousing is treated as sufficient proof of presence on its own. + pub input_idle_timeout_ms: u32, + /// Per-pixel luma delta (0-255) that counts as "changed". + pub diff_threshold: u8, + /// Minimum count of changed pixels (out of 320x180) to call it motion. + pub blob_min_pixels: usize, +} + +impl Default for MotionConfig { + fn default() -> Self { + Self { + idle_poll_ms: 2_000, + active_poll_ms: 250, + max_idle_poll_ms: 15_000, + present_poll_ms: 1_000, + present_stillness_timeout_ms: 45_000, + present_retry_after_miss_ms: 8_000, + input_idle_timeout_ms: 20_000, + diff_threshold: 24, + blob_min_pixels: 200, + } + } +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct PresenceConfig { + /// Path to the ONNX face-detection model used for the presence tier. + pub face_detect_model: String, + /// Consecutive positive IR bursts required before presence flips on. + pub confirm_frames: u32, + /// Consecutive negative IR bursts required before presence flips off. + pub release_frames: u32, + /// Minimum detector confidence to count a frame as "face seen". + pub min_confidence: f32, + /// Frames grabbed per IR burst (averaged/voted, then the camera is closed). + pub ir_burst_frames: u32, + /// Consecutive retention misses required before the recheck cadence escalates + /// from the slow stillness-timeout interval to the fast retry interval. Kept + /// above 1 so a single missed frontal-face check (person glanced down, turned to + /// talk to someone) gets a second slow-cadence check before anything urgent + /// happens, rather than immediately starting a fast countdown toward auto-lock. + /// + /// (An earlier version of this tried a "mean IR brightness = still occupied" + /// fallback signal instead, on the theory that a nearby person reflects + /// noticeably more IR than an empty room. Measured on real hardware, empty-room + /// and occupied-room mean luma overlapped too much to use — the frame is + /// dominated by background reflectance, not near-field subject reflectance. + /// Discarded rather than shipped; this grace-period approach doesn't depend on + /// that assumption.) + pub retention_grace_misses: u32, +} + +impl Default for PresenceConfig { + fn default() -> Self { + Self { + face_detect_model: "~/.local/share/crustd/models/ultraface-rfb-320.onnx".to_string(), + confirm_frames: 2, + release_frames: 3, + min_confidence: 0.7, + ir_burst_frames: 3, + retention_grace_misses: 2, + } + } +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct BreadConfig { + /// Empty = resolve $XDG_RUNTIME_DIR/bread/breadd.sock at runtime, matching breadd's default. + pub socket_path: String, + pub event_prefix: String, +} + +impl Default for BreadConfig { + fn default() -> Self { + Self { + socket_path: String::new(), + event_prefix: "bread.presence".to_string(), + } + } +} + +impl Default for Config { + fn default() -> Self { + Self { + camera: CameraConfig::default(), + motion: MotionConfig::default(), + presence: PresenceConfig::default(), + bread: BreadConfig::default(), + } + } +} + +impl Config { + pub fn load(path: &PathBuf) -> Result { + if !path.exists() { + return Ok(Self::default()); + } + let raw = std::fs::read_to_string(path)?; + Ok(toml::from_str(&raw)?) + } + + pub fn default_path() -> PathBuf { + directories::ProjectDirs::from("dev", "breadway", "crustd") + .map(|d| d.config_dir().join("crustd.toml")) + .unwrap_or_else(|| PathBuf::from("crustd.toml")) + } +} + +pub fn expand_home(path: &str) -> PathBuf { + if let Some(rest) = path.strip_prefix("~/") { + if let Some(home) = std::env::var_os("HOME") { + return PathBuf::from(home).join(rest); + } + } + PathBuf::from(path) +} diff --git a/src/idle.rs b/src/idle.rs new file mode 100644 index 0000000..1ec3dd4 --- /dev/null +++ b/src/idle.rs @@ -0,0 +1,126 @@ +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::mpsc; +use std::sync::Arc; + +use wayland_client::globals::{registry_queue_init, GlobalListContents}; +use wayland_client::protocol::{wl_registry, wl_seat}; +use wayland_client::protocol::wl_seat::WlSeat; +use wayland_client::{Connection, Dispatch, QueueHandle}; +use wayland_protocols::ext::idle_notify::v1::client::ext_idle_notification_v1::{ + self, ExtIdleNotificationV1, +}; +use wayland_protocols::ext::idle_notify::v1::client::ext_idle_notifier_v1::ExtIdleNotifierV1; + +/// Tracks whether the compositor considers the seat's input (keyboard/mouse/etc.) +/// idle, via the standard `ext-idle-notify-v1` protocol (the same one `hypridle` +/// itself relies on). Runs its own connection on a dedicated thread since the +/// wayland-client event loop is blocking. +pub struct IdleWatcher { + idle: Arc, +} + +impl IdleWatcher { + /// Returns `None` if the compositor doesn't support ext-idle-notify-v1 (or the + /// connection otherwise fails) — callers should treat that as "can't use this + /// signal" and fall back to the camera-only behavior rather than erroring out. + pub fn spawn(timeout_ms: u32) -> Option { + let idle = Arc::new(AtomicBool::new(false)); + let idle_for_thread = Arc::clone(&idle); + let (ready_tx, ready_rx) = mpsc::channel(); + + std::thread::Builder::new() + .name("crustd-idle-notify".into()) + .spawn(move || run(timeout_ms, idle_for_thread, ready_tx)) + .ok()?; + + ready_rx.recv().ok()?.then_some(Self { idle }) + } + + pub fn is_idle(&self) -> bool { + self.idle.load(Ordering::Relaxed) + } +} + +struct State { + idle: Arc, +} + +fn run(timeout_ms: u32, idle: Arc, ready_tx: mpsc::Sender) { + let Ok(conn) = Connection::connect_to_env() else { + let _ = ready_tx.send(false); + return; + }; + + let Ok((globals, mut queue)) = registry_queue_init::(&conn) else { + let _ = ready_tx.send(false); + return; + }; + let qh = queue.handle(); + + let seat = globals.bind::(&qh, 1..=8, ()); + let notifier = globals.bind::(&qh, 1..=1, ()); + + let (Ok(seat), Ok(notifier)) = (seat, notifier) else { + let _ = ready_tx.send(false); + return; + }; + + let mut state = State { idle }; + let _notification = notifier.get_idle_notification(timeout_ms, &seat, &qh, ()); + + let _ = ready_tx.send(true); + + loop { + if queue.blocking_dispatch(&mut state).is_err() { + // Compositor connection dropped; stick with the last known idle state + // rather than spinning a busy loop. + break; + } + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + _proxy: &ExtIdleNotificationV1, + event: ext_idle_notification_v1::Event, + _data: &(), + _conn: &Connection, + _qh: &QueueHandle, + ) { + match event { + ext_idle_notification_v1::Event::Idled => state.idle.store(true, Ordering::Relaxed), + ext_idle_notification_v1::Event::Resumed => state.idle.store(false, Ordering::Relaxed), + _ => {} + } + } +} + +// No-op dispatch impls for objects whose events we don't care about. +impl Dispatch for State { + fn event(_: &mut Self, _: &WlSeat, _: wl_seat::Event, _: &(), _: &Connection, _: &QueueHandle) {} +} + +impl Dispatch for State { + fn event( + _: &mut Self, + _: &ExtIdleNotifierV1, + _: ::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + } +} + +impl Dispatch for State { + fn event( + _: &mut Self, + _: &wl_registry::WlRegistry, + _: wl_registry::Event, + _: &GlobalListContents, + _: &Connection, + _: &QueueHandle, + ) { + } +} diff --git a/src/lid.rs b/src/lid.rs new file mode 100644 index 0000000..ad70221 --- /dev/null +++ b/src/lid.rs @@ -0,0 +1,28 @@ +use std::path::Path; + +/// Best-effort lid state via the ACPI button interface. Cameras obviously can't see +/// anything useful with the lid shut, so callers should skip capture entirely rather +/// than burn power opening devices against a blocked sensor. +/// +/// Returns `false` (assume open) if there's no ACPI lid button on this machine — +/// desktops and some laptops won't have one, and that's not an error condition. +pub fn is_closed() -> bool { + let Ok(entries) = std::fs::read_dir("/proc/acpi/button/lid") else { + return false; + }; + + for entry in entries.flatten() { + let state_path = entry.path().join("state"); + if let Some(state) = read_state(&state_path) { + if state.contains("closed") { + return true; + } + } + } + + false +} + +fn read_state(path: &Path) -> Option { + std::fs::read_to_string(path).ok() +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6e1df77 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,259 @@ +mod bread; +mod camera; +mod config; +mod idle; +mod lid; +mod motion; +mod presence; +mod vision; + +use std::time::{Duration, Instant}; + +use anyhow::{Context, Result}; +use tracing::{info, warn}; + +use bread::BreadClient; +use camera::DeviceKind; +use config::{Config, PresenceConfig}; +use idle::IdleWatcher; +use motion::MotionGate; +use presence::{PresenceState, PresenceTracker}; +use vision::{Backend, FaceDetector}; + +#[tokio::main] +async fn main() -> Result<()> { + tracing_subscriber::fmt() + .with_env_filter( + tracing_subscriber::EnvFilter::try_from_default_env() + .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("crustd=info")), + ) + .init(); + + let config_path = Config::default_path(); + let cfg = Config::load(&config_path)?; + info!(?config_path, "loaded config"); + + let model_path = config::expand_home(&cfg.presence.face_detect_model); + if !model_path.exists() { + anyhow::bail!( + "face detector model not found at {model_path:?}; place ultraface-rfb-320.onnx \ + there or point presence.face_detect_model at it in crustd.toml" + ); + } + + let mut detector = FaceDetector::load(&model_path, Backend::Cpu)?; + let mut motion_gate = MotionGate::new(); + let mut presence = PresenceTracker::new(&cfg.presence); + let bread = BreadClient::new(&cfg.bread.socket_path, cfg.bread.event_prefix.clone()); + + let rgb_device = camera::resolve_device(&cfg.camera.rgb_device, DeviceKind::Rgb) + .context("resolving rgb camera device")? + .to_string_lossy() + .into_owned(); + let ir_device = camera::resolve_device(&cfg.camera.ir_device, DeviceKind::Ir) + .context("resolving ir camera device")? + .to_string_lossy() + .into_owned(); + + let idle_watcher = IdleWatcher::spawn(cfg.motion.input_idle_timeout_ms); + if idle_watcher.is_none() { + warn!( + "compositor doesn't support ext-idle-notify-v1 (or connection failed); \ + falling back to camera-only retention, no compositor idle fast-path" + ); + } + + let mut idle_interval = cfg.motion.idle_poll_ms; + + // While present, RGB motion (typing, mouse, posture shifts) — or, when available, + // the compositor directly reporting active input — is the retention signal that + // resets this clock. Only once things have been still for a while do we spend an + // IR burst to double-check someone's actually still there. + let mut last_rgb_motion_at = Instant::now(); + + info!( + rgb_device, + ir_device, + compositor_idle_signal = idle_watcher.is_some(), + "crustd started; ir camera is opened only in short bursts, never streamed continuously" + ); + + let mut shutdown = std::pin::pin!(shutdown_signal()); + + loop { + let sleep_ms = if presence.state() == PresenceState::Present { + cfg.motion.present_poll_ms + } else { + idle_interval + }; + + tokio::select! { + _ = &mut shutdown => { + info!("shutting down"); + break; + } + _ = tokio::time::sleep(Duration::from_millis(sleep_ms)) => {} + } + + if lid::is_closed() { + // Nothing a camera can see with the lid shut; don't bother opening one. + tracing::trace!("lid closed, skipping this tick"); + continue; + } + + if presence.state() == PresenceState::Present { + if let Some(watcher) = &idle_watcher { + if !watcher.is_idle() { + // Compositor confirms the seat has active input right now — that's + // sufficient proof of presence on its own. No camera opened at all. + last_rgb_motion_at = Instant::now(); + continue; + } + } + } + + // Both states share the same cheap RGB capture from here — IR is never + // touched just to decide whether to look. + let rgb_device_owned = rgb_device.clone(); + let capture = tokio::task::spawn_blocking(move || camera::grab_rgb_luma(&rgb_device_owned, 320, 180)) + .await + .context("rgb capture task panicked"); + + let frame = match capture { + Ok(Ok(frame)) => frame, + Ok(Err(err)) => { + warn!(error = %err, "rgb capture failed"); + continue; + } + Err(err) => { + warn!(error = %err, "rgb capture task join error"); + continue; + } + }; + + let motion = motion_gate.observe(frame, &cfg.motion); + tracing::trace!(changed_pixels = motion.changed_pixels, "rgb motion sample"); + + if presence.state() == PresenceState::Present { + if motion.is_motion { + last_rgb_motion_at = Instant::now(); + continue; + } + + // RGB (and, per above, compositor input) has been still; only escalate to + // an IR retention check once it's been still long enough to matter. The + // first `retention_grace_misses` misses still use the slow stillness + // cadence — a single missed frontal-face check (glanced down, turned to + // talk to someone) shouldn't immediately start an urgent countdown toward + // auto-lock. Only after that grace period does it retry at the fast + // cadence, and any positive check resets back to the slow cadence. + let due_after = if presence.negative_streak() >= cfg.presence.retention_grace_misses { + cfg.motion.present_retry_after_miss_ms + } else { + cfg.motion.present_stillness_timeout_ms + }; + + if last_rgb_motion_at.elapsed() < Duration::from_millis(due_after) { + continue; + } + + match run_ir_check(&ir_device, &cfg.presence, &mut detector).await { + Ok(result) => { + let face_seen = result.max_confidence >= cfg.presence.min_confidence; + if face_seen { + last_rgb_motion_at = Instant::now(); + } + handle_observation(&mut presence, &bread, face_seen).await; + } + Err(err) => warn!(error = %err, "ir retention check failed"), + } + continue; + } + + // Absent: escalate to an IR acquisition burst as soon as RGB sees motion. + // Acquisition deliberately requires an actual frontal face match (not the + // looser occupancy signal) — a hand or mug near the sensor shouldn't count + // as someone arriving. IR camera stays closed and dark the rest of the time. + if motion.is_motion { + idle_interval = cfg.motion.active_poll_ms; + match run_ir_check(&ir_device, &cfg.presence, &mut detector).await { + Ok(result) => { + let face_seen = result.max_confidence >= cfg.presence.min_confidence; + if face_seen { + last_rgb_motion_at = Instant::now(); + } + handle_observation(&mut presence, &bread, face_seen).await; + } + Err(err) => warn!(error = %err, "ir burst check failed"), + } + } else { + idle_interval = (idle_interval * 3 / 2).min(cfg.motion.max_idle_poll_ms); + } + } + + Ok(()) +} + +struct IrCheckResult { + max_confidence: f32, + max_mean_luma: f32, +} + +/// Opens the IR camera for exactly one short burst, runs the tier-1 detector over +/// each frame, and closes it again before returning. +async fn run_ir_check(ir_device: &str, cfg: &PresenceConfig, detector: &mut FaceDetector) -> Result { + let device = ir_device.to_string(); + let burst_frames = cfg.ir_burst_frames; + + let frames = tokio::task::spawn_blocking(move || camera::grab_ir_burst(&device, burst_frames)) + .await + .context("ir capture task panicked")??; + + let mut max_confidence = 0.0f32; + let mut max_mean_luma = 0.0f32; + for frame in &frames { + let confidence = detector.max_face_confidence(frame)?; + max_confidence = max_confidence.max(confidence); + max_mean_luma = max_mean_luma.max(frame.mean_luma()); + } + + tracing::debug!( + max_confidence, + max_mean_luma, + threshold = cfg.min_confidence, + "ir burst result" + ); + + Ok(IrCheckResult { max_confidence, max_mean_luma }) +} + +async fn handle_observation(presence: &mut PresenceTracker, bread: &BreadClient, positive: bool) { + if let Some(new_state) = presence.observe(positive) { + info!(state = new_state.as_str(), "presence state changed"); + let data = serde_json::json!({ "state": new_state.as_str() }); + if let Err(err) = bread.emit("changed", data).await { + warn!(error = %err, "failed to emit presence event to bread"); + } + } +} + +async fn shutdown_signal() { + let ctrl_c = async { + let _ = tokio::signal::ctrl_c().await; + }; + + #[cfg(unix)] + let terminate = async { + use tokio::signal::unix::{signal, SignalKind}; + if let Ok(mut sig) = signal(SignalKind::terminate()) { + sig.recv().await; + } + }; + #[cfg(not(unix))] + let terminate = std::future::pending::<()>(); + + tokio::select! { + _ = ctrl_c => {}, + _ = terminate => {}, + } +} diff --git a/src/motion.rs b/src/motion.rs new file mode 100644 index 0000000..fb28fe5 --- /dev/null +++ b/src/motion.rs @@ -0,0 +1,49 @@ +use crate::camera::GrayFrame; +use crate::config::MotionConfig; + +/// Cheap frame-differencing gate over the RGB camera. This is the only thing that +/// runs continuously — it never touches the IR camera, so nothing flashes while +/// the room is empty or still. +pub struct MotionGate { + previous: Option, +} + +pub struct MotionResult { + pub changed_pixels: usize, + pub is_motion: bool, +} + +impl MotionGate { + pub fn new() -> Self { + Self { previous: None } + } + + pub fn observe(&mut self, frame: GrayFrame, cfg: &MotionConfig) -> MotionResult { + let changed_pixels = match &self.previous { + None => 0, + Some(prev) if prev.luma.len() != frame.luma.len() => 0, + Some(prev) => { + // Subtract the frame-wide brightness shift before thresholding, so a + // light turning on/off (which moves every pixel by roughly the same + // amount) doesn't register as motion — only localized change does. + let mean_shift = frame.mean_luma() - prev.mean_luma(); + prev.luma + .iter() + .zip(frame.luma.iter()) + .filter(|(&a, &b)| { + let adjusted = b as f32 - mean_shift; + (adjusted - a as f32).abs() >= cfg.diff_threshold as f32 + }) + .count() + } + }; + + let is_motion = changed_pixels >= cfg.blob_min_pixels; + self.previous = Some(frame); + + MotionResult { + changed_pixels, + is_motion, + } + } +} diff --git a/src/presence.rs b/src/presence.rs new file mode 100644 index 0000000..9e6d85c --- /dev/null +++ b/src/presence.rs @@ -0,0 +1,75 @@ +use crate::config::PresenceConfig; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PresenceState { + Absent, + Present, +} + +impl PresenceState { + pub fn as_str(&self) -> &'static str { + match self { + PresenceState::Absent => "absent", + PresenceState::Present => "present", + } + } +} + +/// Debounced presence state machine. Feed it one boolean per IR burst ("was a face +/// seen above threshold") and it reports state transitions only after `confirm_frames` +/// consecutive positives (to flip on) or `release_frames` consecutive negatives (to +/// flip off) — this is what keeps a single flickery frame from toggling the state. +pub struct PresenceTracker { + state: PresenceState, + positive_streak: u32, + negative_streak: u32, + confirm_frames: u32, + release_frames: u32, +} + +impl PresenceTracker { + pub fn new(cfg: &PresenceConfig) -> Self { + Self { + state: PresenceState::Absent, + positive_streak: 0, + negative_streak: 0, + confirm_frames: cfg.confirm_frames.max(1), + release_frames: cfg.release_frames.max(1), + } + } + + pub fn state(&self) -> PresenceState { + self.state + } + + /// Count of consecutive failed retention checks since presence was last + /// confirmed. Zero means the last check (if any) was positive, or none has run + /// yet — callers use this to decide whether to use the slow stillness-timeout + /// cadence or the fast retry-after-miss cadence for the next IR check. + pub fn negative_streak(&self) -> u32 { + self.negative_streak + } + + /// Returns `Some(new_state)` only when the debounced state actually changes. + pub fn observe(&mut self, face_seen: bool) -> Option { + if face_seen { + self.positive_streak += 1; + self.negative_streak = 0; + } else { + self.negative_streak += 1; + self.positive_streak = 0; + } + + match self.state { + PresenceState::Absent if self.positive_streak >= self.confirm_frames => { + self.state = PresenceState::Present; + Some(self.state) + } + PresenceState::Present if self.negative_streak >= self.release_frames => { + self.state = PresenceState::Absent; + Some(self.state) + } + _ => None, + } + } +} diff --git a/src/vision.rs b/src/vision.rs new file mode 100644 index 0000000..ea13697 --- /dev/null +++ b/src/vision.rs @@ -0,0 +1,110 @@ +use anyhow::Result; +use ort::session::builder::GraphOptimizationLevel; +use ort::session::Session; +use ort::value::Value; + +use crate::camera::GrayFrame; + +const MODEL_WIDTH: usize = 320; +const MODEL_HEIGHT: usize = 240; + +/// Which execution provider a `FaceDetector` was built against. +/// +/// `Npu` is intentionally unimplemented: this hardware (RyzenAI-npu6 / Krackan) has +/// no matching xclbin overlay in the installed Vitis AI SDK (it only ships Phoenix +/// overlays), so there's nothing for the VitisAI EP to load yet. The seam is here so +/// that dropping in a Krackan xclbin later is a config change, not a rewrite: swap +/// this match arm to call `SessionBuilder::with_execution_providers` with the VitisAI +/// EP once `vaip_config.json` points at a compatible overlay. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Backend { + Cpu, + Npu, +} + +/// Tier-1 presence face detector (UltraFace-RFB-320 class model). Runs only against +/// short IR bursts handed to it by the presence loop — it never touches the camera +/// itself. +pub struct FaceDetector { + session: Session, +} + +impl FaceDetector { + pub fn load(model_path: &std::path::Path, backend: Backend) -> Result { + if backend == Backend::Npu { + anyhow::bail!( + "NPU backend requested but no Krackan/Strix xclbin is available for the \ + VitisAI execution provider on this system (only Phoenix overlays are \ + installed under ryzenai-env). Falling back is the caller's job; this \ + constructor refuses rather than silently running on CPU under a false name." + ); + } + + let session = Session::builder() + .map_err(|e| anyhow::anyhow!("creating onnxruntime session builder: {e}"))? + .with_optimization_level(GraphOptimizationLevel::Level3) + .map_err(|e| anyhow::anyhow!("setting graph optimization level: {e}"))? + .with_intra_threads(1) + .map_err(|e| anyhow::anyhow!("setting intra-op thread count: {e}"))? + .commit_from_file(model_path) + .map_err(|e| anyhow::anyhow!("loading face detector model from {model_path:?}: {e}"))?; + + Ok(Self { session }) + } + + /// Resizes/normalizes the frame to the model's expected input and returns the + /// highest face-class probability across all anchor boxes. Callers decide the + /// confidence threshold; this just reports the peak score. + pub fn max_face_confidence(&mut self, frame: &GrayFrame) -> Result { + let tensor = preprocess(frame); + + let input = Value::from_array(([1usize, 3, MODEL_HEIGHT, MODEL_WIDTH], tensor)) + .map_err(|e| anyhow::anyhow!("building input tensor: {e}"))?; + + let outputs = self + .session + .run(ort::inputs!["input" => input]) + .map_err(|e| anyhow::anyhow!("running face detector session: {e}"))?; + + let scores = outputs["scores"] + .try_extract_tensor::() + .map_err(|e| anyhow::anyhow!("extracting scores output: {e}"))?; + + // scores is [1, N, 2]: column 0 = background prob, column 1 = face prob. + // The exported graph already applies softmax, so these are usable directly. + let (_shape, data) = scores; + let max_face_prob = data + .chunks_exact(2) + .map(|pair| pair[1]) + .fold(0.0f32, f32::max); + + Ok(max_face_prob) + } +} + +/// Nearest-neighbor stretch-resize to 320x240 + grayscale-replicated-to-RGB + +/// `(x - 127) / 128` normalization, matching the reference UltraFace preprocessing. +/// Nearest-neighbor is a deliberate v1 simplification (no extra image/resize +/// dependency) — a proper area-average downscale would be a bit more accurate but +/// isn't needed for a presence gate. +fn preprocess(frame: &GrayFrame) -> Vec { + let mut out = vec![0f32; 3 * MODEL_HEIGHT * MODEL_WIDTH]; + let plane_len = MODEL_HEIGHT * MODEL_WIDTH; + + for y in 0..MODEL_HEIGHT { + let src_y = y * frame.height as usize / MODEL_HEIGHT; + for x in 0..MODEL_WIDTH { + let src_x = x * frame.width as usize / MODEL_WIDTH; + let src_idx = src_y * frame.width as usize + src_x; + let luma = *frame.luma.get(src_idx).unwrap_or(&0) as f32; + let normalized = (luma - 127.0) / 128.0; + + let dst_idx = y * MODEL_WIDTH + x; + out[dst_idx] = normalized; // R + out[plane_len + dst_idx] = normalized; // G + out[2 * plane_len + dst_idx] = normalized; // B + } + } + + out +}