From 60199cfa06610f16f86e5f8f4beffebbb05d3854 Mon Sep 17 00:00:00 2001 From: kieran Date: Fri, 15 Nov 2024 15:54:51 +0000 Subject: [PATCH] feat: overseer --- Cargo.lock | 2139 +++++++++++++++++++++++++++++++- Cargo.toml | 19 +- README.md | 10 +- config.toml | 12 - config.yaml | 42 + docker-compose.yml | 21 +- src/bin/zap_stream_core.rs | 48 +- src/egress/hls.rs | 316 +---- src/egress/http.rs | 8 +- src/egress/mod.rs | 25 +- src/egress/recorder.rs | 13 +- src/ingress/file.rs | 12 +- src/ingress/mod.rs | 42 +- src/ingress/srt.rs | 7 +- src/ingress/tcp.rs | 7 +- src/ingress/test.rs | 13 +- src/lib.rs | 3 +- src/mux/hls.rs | 302 +++++ src/mux/mod.rs | 2 + src/overseer/mod.rs | 209 ++++ src/overseer/webhook.rs | 42 + src/overseer/zap_stream/db.rs | 114 ++ src/overseer/zap_stream/mod.rs | 201 +++ src/pipeline/mod.rs | 2 +- src/pipeline/runner.rs | 96 +- src/settings.rs | 36 +- src/webhook.rs | 99 -- 27 files changed, 3262 insertions(+), 578 deletions(-) delete mode 100755 config.toml create mode 100755 config.yaml create mode 100644 src/mux/hls.rs create mode 100644 src/mux/mod.rs create mode 100644 src/overseer/mod.rs create mode 100644 src/overseer/webhook.rs create mode 100644 src/overseer/zap_stream/db.rs create mode 100644 src/overseer/zap_stream/mod.rs delete mode 100644 src/webhook.rs diff --git a/Cargo.lock b/Cargo.lock index 533305d..c8bcd19 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,16 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + [[package]] name = "aes" version = "0.8.4" @@ -61,6 +71,21 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.15" @@ -143,6 +168,28 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "async-trait" version = "0.1.77" @@ -151,7 +198,57 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", +] + +[[package]] +name = "async-utility" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a349201d80b4aa18d17a34a182bdd7f8ddf845e9e57d2ea130a12e10ef1e3a47" +dependencies = [ + "futures-util", + "gloo-timers", + "tokio", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-wsocket" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a107e3bdbe61e8e1e1341c57241b4b2d50501127b44bd2eff13b4635ab42d35a" +dependencies = [ + "async-utility", + "futures", + "futures-util", + "js-sys", + "thiserror 1.0.57", + "tokio", + "tokio-rustls 0.26.0", + "tokio-socks", + "tokio-tungstenite 0.24.0", + "url", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-destructor" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d919cb60ba95c87ba42777e9e246c4e8d658057299b437b7512531ce0a09a23" +dependencies = [ + "tracing", ] [[package]] @@ -160,6 +257,51 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.31", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 0.1.2", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -175,6 +317,16 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.21.7" @@ -187,6 +339,18 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bindgen" version = "0.69.5" @@ -202,9 +366,90 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", - "syn 2.0.52", + "syn 2.0.87", +] + +[[package]] +name = "bip39" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33415e24172c1b7d6066f6d999545375ab8e1d95421d6784bdfff9496f292387" +dependencies = [ + "bitcoin_hashes 0.13.0", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bitcoin" +version = "0.32.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "788902099d47c8682efe6a7afb01c8d58b9794ba66c06affd81c3d6b560743eb" +dependencies = [ + "base58ck", + "bech32", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", + "hex_lit", + "secp256k1", + "serde", +] + +[[package]] +name = "bitcoin-internals" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" + +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals 0.3.0", + "serde", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" +dependencies = [ + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.2", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.1", + "serde", ] [[package]] @@ -231,6 +476,21 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "bytemuck" version = "1.19.0" @@ -251,15 +511,27 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" [[package]] name = "bytes" -version = "1.5.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" + +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] [[package]] name = "cc" -version = "1.0.90" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +dependencies = [ + "shlex", +] [[package]] name = "cexpr" @@ -276,13 +548,49 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", "num-traits", + "serde", + "wasm-bindgen", + "windows-targets 0.52.4", ] [[package]] @@ -293,6 +601,7 @@ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", + "zeroize", ] [[package]] @@ -347,7 +656,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] [[package]] @@ -368,6 +677,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "config" version = "0.14.0" @@ -388,6 +706,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-random" version = "0.1.18" @@ -423,6 +747,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "core_maths" version = "0.1.0" @@ -441,6 +771,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.4.2" @@ -450,6 +795,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -469,6 +823,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core", "typenum", ] @@ -493,6 +848,17 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -513,6 +879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -526,11 +893,20 @@ dependencies = [ "const-random", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "either" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +dependencies = [ + "serde", +] [[package]] name = "encoding_rs" @@ -560,6 +936,44 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" + [[package]] name = "fdeflate" version = "0.3.6" @@ -569,6 +983,26 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "fedimint-tonic-lnd" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df03ca33b5116de3051c1e233fe341e23b04c4913c7b16042497924559bc2a2e" +dependencies = [ + "hex", + "http-body 0.4.6", + "hyper 0.14.31", + "hyper-rustls 0.24.2", + "prost", + "rustls 0.21.12", + "rustls-pemfile 1.0.4", + "tokio", + "tokio-stream", + "tonic", + "tonic-build", + "tower", +] + [[package]] name = "ffmpeg-rs-raw" version = "0.1.0" @@ -594,6 +1028,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.34" @@ -610,12 +1050,29 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin 0.9.8", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "fontconfig-parser" version = "0.5.7" @@ -645,7 +1102,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efe23d02309319171d00d794c9ff48d4f903c0e481375b1b04b017470838af04" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", "ttf-parser 0.21.1", ] @@ -688,6 +1145,28 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -702,7 +1181,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] [[package]] @@ -752,8 +1231,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -778,6 +1259,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "h2" version = "0.3.26" @@ -790,13 +1283,19 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.13.2" @@ -805,14 +1304,34 @@ checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashlink" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "headers" version = "0.3.9" @@ -855,6 +1374,36 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + [[package]] name = "hmac" version = "0.12.1" @@ -864,6 +1413,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -897,6 +1455,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.9.5" @@ -927,7 +1508,7 @@ dependencies = [ "futures-util", "h2", "http 0.2.12", - "http-body", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -939,6 +1520,111 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.31", + "rustls 0.21.12", + "tokio", + "tokio-rustls 0.24.1", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.5.0", + "hyper-util", + "rustls 0.23.16", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper 0.14.31", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + +[[package]] +name = "hyper-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.5.0", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -965,6 +1651,16 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.2.5" @@ -972,7 +1668,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", ] [[package]] @@ -981,9 +1677,28 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ + "block-padding", "generic-array", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + [[package]] name = "is-terminal" version = "0.4.12" @@ -1025,6 +1740,15 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "json5" version = "0.4.1" @@ -1042,7 +1766,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee7893dab2e44ae5f9d0173f26ff4aa327c10b01b06a72b52dd9405b628640d" dependencies = [ - "indexmap", + "indexmap 2.2.5", ] [[package]] @@ -1060,6 +1784,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "lazycell" @@ -1089,18 +1816,66 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lnurl-pay" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "536e7c782167a2d48346ca0b2677fad19eaef20f19a4ab868e4d5b96ca879def" +dependencies = [ + "bech32", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +dependencies = [ + "hashbrown 0.15.1", +] + [[package]] name = "m3u8-rs" version = "6.0.0" @@ -1111,6 +1886,22 @@ dependencies = [ "nom", ] +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.1" @@ -1169,13 +1960,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1192,10 +1984,28 @@ dependencies = [ "log", "memchr", "mime", - "spin", + "spin 0.9.8", "version_check", ] +[[package]] +name = "multimap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" + +[[package]] +name = "negentropy" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e664971378a3987224f7a0e10059782035e89899ae403718ee07de85bec42afe" + +[[package]] +name = "negentropy" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a88da9dd148bbcdce323dd6ac47d369b4769d4a3b78c6c52389b9269f77932" + [[package]] name = "nom" version = "7.1.3" @@ -1206,6 +2016,138 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nostr" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d" +dependencies = [ + "aes", + "async-trait", + "base64 0.22.1", + "bech32", + "bip39", + "bitcoin", + "cbc", + "chacha20", + "chacha20poly1305", + "getrandom", + "instant", + "js-sys", + "negentropy 0.3.1", + "negentropy 0.4.3", + "once_cell", + "reqwest", + "scrypt", + "serde", + "serde_json", + "unicode-normalization", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "nostr-database" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1859abebf78d7d9e945b20c8faaf710c9db905adeb148035b803ae45792dbebe" +dependencies = [ + "async-trait", + "lru", + "nostr", + "thiserror 1.0.57", + "tokio", + "tracing", +] + +[[package]] +name = "nostr-relay-pool" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e39cfcb30cab86b30ca9acba89f5ccb25a4142a5dc5fcfbf3edf34b204ddd7c7" +dependencies = [ + "async-utility", + "async-wsocket", + "atomic-destructor", + "negentropy 0.3.1", + "negentropy 0.4.3", + "nostr", + "nostr-database", + "thiserror 1.0.57", + "tokio", + "tokio-stream", + "tracing", +] + +[[package]] +name = "nostr-sdk" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4739ed15ff81a0e474d79b38c3eb481ff5f968c1865f38ba46852daf6f6495e" +dependencies = [ + "async-utility", + "atomic-destructor", + "lnurl-pay", + "nostr", + "nostr-database", + "nostr-relay-pool", + "nostr-zapper", + "nwc", + "thiserror 1.0.57", + "tokio", + "tracing", +] + +[[package]] +name = "nostr-zapper" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d9709ecf8050bbe4ecf0e5efda2f25b690bb1761fc504e05654621ba9e568a8" +dependencies = [ + "async-trait", + "nostr", + "thiserror 1.0.57", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[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-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -1213,16 +2155,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", + "libm", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "nwc" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "1b5f98bcaf232b3ec48e018792ca7bc2b90e7520d001a07b8218a9e76a03fda2" dependencies = [ - "hermit-abi", - "libc", + "async-trait", + "async-utility", + "nostr", + "nostr-relay-pool", + "nostr-zapper", + "thiserror 1.0.57", + "tracing", ] [[package]] @@ -1236,9 +2184,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "ordered-multimap" @@ -1250,6 +2204,52 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.4", +] + +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pathdiff" version = "0.2.1" @@ -1263,6 +2263,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest", + "hmac", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", ] [[package]] @@ -1278,7 +2288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.57", "ucd-trie", ] @@ -1302,7 +2312,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] [[package]] @@ -1316,6 +2326,16 @@ dependencies = [ "sha2", ] +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap 2.2.5", +] + [[package]] name = "pico-args" version = "0.5.0" @@ -1339,7 +2359,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] [[package]] @@ -1354,6 +2374,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.31" @@ -1373,6 +2414,17 @@ dependencies = [ "miniz_oxide 0.8.0", ] +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "portable-atomic" version = "1.9.0" @@ -1396,20 +2448,135 @@ dependencies = [ ] [[package]] -name = "proc-macro2" -version = "1.0.78" +name = "prettyplease" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn 2.0.87", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" +dependencies = [ + "bytes", + "heck", + "itertools 0.12.1", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.87", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" +dependencies = [ + "anyhow", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "prost-types" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" +dependencies = [ + "prost", +] + [[package]] name = "quick-error" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +[[package]] +name = "quinn" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.0.0", + "rustls 0.23.16", + "socket2", + "thiserror 2.0.3", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" +dependencies = [ + "bytes", + "getrandom", + "rand", + "ring", + "rustc-hash 2.0.0", + "rustls 0.23.16", + "rustls-pki-types", + "slab", + "thiserror 2.0.3", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.35" @@ -1449,6 +2616,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags 2.4.2", +] + [[package]] name = "regex" version = "1.10.3" @@ -1478,6 +2654,49 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.5.0", + "hyper-rustls 0.27.3", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.16", + "rustls-pemfile 2.2.0", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tokio-rustls 0.26.0", + "tokio-socks", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + [[package]] name = "resvg" version = "0.44.0" @@ -1504,6 +2723,21 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "ringbuf" version = "0.4.7" @@ -1532,6 +2766,26 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rust-ini" version = "0.19.0" @@ -1554,6 +2808,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.0" @@ -1563,6 +2823,99 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.23.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.8", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +dependencies = [ + "web-time", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "rustybuzz" version = "0.18.0" @@ -1587,12 +2940,70 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "scoped-tls" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scrypt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" +dependencies = [ + "password-hash", + "pbkdf2", + "salsa20", + "sha2", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "secp256k1" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "bitcoin_hashes 0.14.0", + "rand", + "secp256k1-sys", + "serde", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", +] + [[package]] name = "semver" version = "1.0.22" @@ -1616,7 +3027,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] [[package]] @@ -1625,6 +3036,7 @@ version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ + "indexmap 2.2.5", "itoa", "ryu", "serde", @@ -1690,6 +3102,16 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -1740,6 +3162,9 @@ name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -1751,11 +3176,238 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlformat" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" +dependencies = [ + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93334716a037193fac19df402f8571269c84a00852f6a7066b5d2616dcd64d3e" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d8060b456358185f7d50c55d9b5066ad956956fddec42ee2e8567134a8936e" +dependencies = [ + "atoi", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.14.5", + "hashlink", + "hex", + "indexmap 2.2.5", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror 1.0.57", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cac0692bcc9de3b073e8d747391827297e075c7710ff6276d9f7a1f3d58c6657" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 2.0.87", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 2.0.87", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags 2.4.2", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 1.0.57", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags 2.4.2", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 1.0.57", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5b2cf34a45953bfd3daaf3db0f7a7878ab9b7a6b91b422d24a7a9e4c857b680" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "tracing", + "url", +] [[package]] name = "srt-protocol" @@ -1781,7 +3433,7 @@ dependencies = [ "sha-1", "streaming-stats", "take-until", - "thiserror", + "thiserror 1.0.57", "url", ] @@ -1819,6 +3471,17 @@ dependencies = [ "float-cmp", ] +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "strsim" version = "0.11.1" @@ -1854,21 +3517,46 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "take-until" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb" +[[package]] +name = "tempfile" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -1884,7 +3572,16 @@ version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.57", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -1895,7 +3592,18 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -1950,30 +3658,72 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.36.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.16", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-socks" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" +dependencies = [ + "either", + "futures-util", + "thiserror 1.0.57", + "tokio", ] [[package]] @@ -1997,7 +3747,23 @@ dependencies = [ "futures-util", "log", "tokio", - "tungstenite", + "tungstenite 0.21.0", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" +dependencies = [ + "futures-util", + "log", + "rustls 0.23.16", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tungstenite 0.24.0", + "webpki-roots", ] [[package]] @@ -2041,13 +3807,82 @@ version = "0.22.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c12219811e0c1ba077867254e5ad62ee2c9c190b0d957110750ac0cda1ae96cd" dependencies = [ - "indexmap", + "indexmap 2.2.5", "serde", "serde_spanned", "toml_datetime", "winnow", ] +[[package]] +name = "tonic" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.21.7", + "bytes", + "h2", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.31", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "rustls 0.21.12", + "rustls-pemfile 1.0.4", + "tokio", + "tokio-rustls 0.24.1", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d021fc044c18582b9a2408cd0dd05b1596e3ecdb5c4df822bb0183545683889" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" version = "0.3.3" @@ -2062,9 +3897,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -2109,11 +3956,31 @@ dependencies = [ "log", "rand", "sha1", - "thiserror", + "thiserror 1.0.57", "url", "utf-8", ] +[[package]] +name = "tungstenite" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand", + "rustls 0.23.16", + "rustls-pki-types", + "sha1", + "thiserror 1.0.57", + "utf-8", +] + [[package]] name = "typenum" version = "1.17.0" @@ -2158,9 +4025,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] @@ -2189,6 +4056,28 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -2198,6 +4087,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -2281,7 +4171,7 @@ dependencies = [ "futures-util", "headers", "http 0.2.12", - "hyper", + "hyper 0.14.31", "log", "mime", "mime_guess", @@ -2293,7 +4183,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", - "tokio-tungstenite", + "tokio-tungstenite 0.21.0", "tokio-util", "tower-service", "tracing", @@ -2305,12 +4195,124 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.87", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "weezl" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "whoami" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" +dependencies = [ + "redox_syscall", + "wasite", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2342,6 +4344,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -2483,6 +4494,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "xmlwriter" version = "0.1.0" @@ -2504,8 +4525,10 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "chrono", "clap", "config", + "fedimint-tonic-lnd", "ffmpeg-rs-raw", "fontdue", "futures-util", @@ -2513,11 +4536,13 @@ dependencies = [ "libc", "log", "m3u8-rs", + "nostr-sdk", "pretty_env_logger", "rand", "resvg", "ringbuf", "serde", + "sqlx", "srt-tokio", "tiny-skia", "tokio", @@ -2545,9 +4570,15 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.87", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + [[package]] name = "zune-core" version = "0.4.12" diff --git a/Cargo.toml b/Cargo.toml index 327eba7..02e59b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,36 +8,43 @@ name = "zap-stream-core" path = "src/bin/zap_stream_core.rs" [features] -default = ["test-source"] +default = ["test-pattern"] srt = ["dep:srt-tokio"] -test-source = ["dep:resvg", "dep:usvg", "dep:tiny-skia", "dep:fontdue", "dep:ringbuf"] +zap-stream = ["dep:nostr-sdk", "dep:sqlx", "dep:fedimint-tonic-lnd", "dep:chrono"] +test-pattern = ["dep:resvg", "dep:usvg", "dep:tiny-skia", "dep:fontdue", "dep:ringbuf"] [dependencies] ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "0abe0c5229adeb64b013d1895c7eba3d917f05a4" } - tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"] } anyhow = { version = "^1.0.91", features = ["backtrace"] } pretty_env_logger = "0.5.0" - tokio-stream = "0.1.14" futures-util = "0.3.30" async-trait = "0.1.77" log = "0.4.21" uuid = { version = "1.8.0", features = ["v4", "serde"] } serde = { version = "1.0.197", features = ["derive"] } -config = { version = "0.14.0", features = ["toml"] } +config = { version = "0.14.0", features = ["yaml"] } url = "2.5.0" itertools = "0.13.0" rand = "0.8.5" clap = { version = "4.5.16", features = ["derive"] } warp = "0.3.7" libc = "0.2.162" +m3u8-rs = "6.0.0" +# test-pattern srt-tokio = { version = "0.4.3", optional = true } resvg = { version = "0.44.0", optional = true } usvg = { version = "0.44.0", optional = true } tiny-skia = { version = "0.11.4", optional = true } fontdue = { version = "0.9.2", optional = true } ringbuf = { version = "0.4.7", optional = true } -m3u8-rs = "6.0.0" + +# zap-stream +nostr-sdk = { version = "0.36.0", optional = true } +sqlx = { version = "0.8.2", optional = true, features = ["runtime-tokio", "migrate", "mysql", "chrono"] } +fedimint-tonic-lnd = { version = "0.2.0", optional = true, default-features = false, features = ["invoicesrpc", "versionrpc"] } +chrono = { version = "0.4.38", optional = true, features = ["serde"] } + diff --git a/README.md b/README.md index f1e96bc..c5aef74 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # zap.stream core -Pure rust zap.stream core streaming server +Rust zap.stream core streaming server + +![diagram](./zap.stream.svg) + +## Building + +By default, the `zap-stream` feature is not built which means that a `webhook` service +is required to control access to the service. -![diagram](./zap.stream.svg) \ No newline at end of file diff --git a/config.toml b/config.toml deleted file mode 100755 index 5ea5aac..0000000 --- a/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -# List of endpoints to listen on -# currently supporting srt/tcp -endpoints = [ - "srt://127.0.0.1:3333", - "tcp://127.0.0.1:3334" -] - -# Output directory for egress -output_dir = "./out" - -# Wehook system url (required) -webhook_url = "http://localhost:5873/api/v1/stream-core" \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100755 index 0000000..b47170a --- /dev/null +++ b/config.yaml @@ -0,0 +1,42 @@ +# List of endpoints to listen on +# currently supporting srt/tcp/file/test-pattern +# All the endpoints must be valid URI's +endpoints: + - "srt://127.0.0.1:3333" + - "tcp://127.0.0.1:3334" + - "test-pattern:" + +# Output directory for recording / hls +output_dir: "./out" + +# Overseer is the main control structure which controls access to the service +# +# ** ONLY 1 OVERSEER CAN BE CONFIGURED AT A TIME ** +# +# Supported overseers: +# static: +# egress-types: +# - hls +# - recorder +# webhook: +# url: +# zap-stream: +# private-key: "nsec1234" +# relays: +# - "wss://relay.com" +# lnd: +# address: +# cert: +# macaroon: +# database: +# +overseer: + zap-stream: + nsec: "nsec1wya428srvpu96n4h78gualaj7wqw4ecgatgja8d5ytdqrxw56r2se440y4" + relays: + - "ws://localhost:7766" + database: "mysql://root:root@localhost:3368/zap-stream?max_connections=2" + lnd: + address: "https://127.0.0.1:10001" + cert: "/home/kieran/.polar/networks/1/volumes/lnd/alice/tls.cert" + macaroon: "/home/kieran/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index f744275..3a1231c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,17 @@ name: zap-stream-core services: - app: - build: - context: . + db: + image: mariadb environment: - - "RUST_LOG=info" + - "MARIADB_ROOT_PASSWORD=root" + - "MARIADB_DATABASE=zap-stream" ports: - - "3333:3333" - - "3334:3334" - volumes: - - "./config.toml:/app/config.toml:ro" \ No newline at end of file + - "3368:3306" + #volumes: + #- "db:/var/lib/mysql" + relay: + image: scsibug/nostr-rs-relay + ports: + - "7766:8080" +volumes: + db: \ No newline at end of file diff --git a/src/bin/zap_stream_core.rs b/src/bin/zap_stream_core.rs index 63b5a0c..14951ae 100644 --- a/src/bin/zap_stream_core.rs +++ b/src/bin/zap_stream_core.rs @@ -8,26 +8,20 @@ use url::Url; use zap_stream_core::egress::http::listen_out_dir; #[cfg(feature = "srt")] use zap_stream_core::ingress::srt; -use zap_stream_core::ingress::{file, tcp, test}; +#[cfg(feature = "test-pattern")] +use zap_stream_core::ingress::test; + +use zap_stream_core::ingress::{file, tcp}; use zap_stream_core::settings::Settings; #[derive(Parser, Debug)] -struct Args { - /// Add file input at startup - #[arg(long)] - file: Option, - - /// Add input test pattern at startup - #[cfg(feature = "test-source")] - #[arg(long)] - test_pattern: bool, -} +struct Args {} #[tokio::main] async fn main() -> anyhow::Result<()> { pretty_env_logger::init(); - let args = Args::parse(); + let _args = Args::parse(); unsafe { //ffmpeg_sys_next::av_log_set_level(ffmpeg_sys_next::AV_LOG_DEBUG); @@ -35,20 +29,32 @@ async fn main() -> anyhow::Result<()> { } let builder = Config::builder() - .add_source(config::File::with_name("config.toml")) + .add_source(config::File::with_name("config.yaml")) .add_source(config::Environment::with_prefix("APP")) .build()?; let settings: Settings = builder.try_deserialize()?; + let overseer = settings.get_overseer().await?; let mut listeners = vec![]; for e in &settings.endpoints { let u: Url = e.parse()?; - let addr = format!("{}:{}", u.host_str().unwrap(), u.port().unwrap()); match u.scheme() { #[cfg(feature = "srt")] - "srt" => listeners.push(tokio::spawn(srt::listen(addr, settings.clone()))), - "tcp" => listeners.push(tokio::spawn(tcp::listen(addr, settings.clone()))), + "srt" => listeners.push(tokio::spawn(srt::listen( + u.host().unwrap().to_string(), + overseer.clone(), + ))), + "tcp" => listeners.push(tokio::spawn(tcp::listen( + u.host().unwrap().to_string(), + overseer.clone(), + ))), + "file" => listeners.push(tokio::spawn(file::listen( + u.path().parse()?, + overseer.clone(), + ))), + #[cfg(feature = "test-pattern")] + "test-pattern" => listeners.push(tokio::spawn(test::listen(overseer.clone()))), _ => { error!("Unknown endpoint config: {e}"); } @@ -56,17 +62,9 @@ async fn main() -> anyhow::Result<()> { } listeners.push(tokio::spawn(listen_out_dir( "0.0.0.0:8080".to_owned(), - settings.clone(), + settings.output_dir, ))); - if let Some(p) = args.file { - listeners.push(tokio::spawn(file::listen(p.parse()?, settings.clone()))); - } - #[cfg(feature = "test-source")] - if args.test_pattern { - listeners.push(tokio::spawn(test::listen(settings.clone()))); - } - for handle in listeners { if let Err(e) = handle.await { error!("{e}"); diff --git a/src/egress/hls.rs b/src/egress/hls.rs index 30045ee..0e63f8b 100644 --- a/src/egress/hls.rs +++ b/src/egress/hls.rs @@ -1,308 +1,24 @@ -use anyhow::{bail, Result}; -use ffmpeg_rs_raw::ffmpeg_sys_the_third::{ - av_free, av_opt_set, av_q2d, av_strdup, av_write_frame, avio_flush, avio_open, AVPacket, - AVIO_FLAG_WRITE, AV_PKT_FLAG_KEY, -}; -use ffmpeg_rs_raw::{cstr, Encoder, Muxer}; -use itertools::Itertools; -use log::{info, warn}; -use m3u8_rs::MediaSegment; +use anyhow::Result; +use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVPacket; use std::fmt::Display; -use std::fs::File; -use std::path::PathBuf; -use std::ptr; use uuid::Uuid; -use crate::egress::Egress; -use crate::variant::{StreamMapping, VariantStream}; +use crate::egress::{Egress, EgressResult}; +use crate::mux::HlsMuxer; -pub struct HlsEgress { - id: Uuid, +/// Alias the muxer directly +pub type HlsEgress = HlsMuxer; - /// All variant streams - variants: Vec, -} - -enum HlsVariantStream { - Video { - group: usize, - index: usize, - id: Uuid, - }, - Audio { - group: usize, - index: usize, - id: Uuid, - }, - Subtitle { - group: usize, - index: usize, - id: Uuid, - }, -} - -impl HlsVariantStream { - pub fn group(&self) -> usize { - match self { - HlsVariantStream::Video { group, .. } => *group, - HlsVariantStream::Audio { group, .. } => *group, - HlsVariantStream::Subtitle { group, .. } => *group, - } - } - - pub fn index(&self) -> usize { - match self { - HlsVariantStream::Video { index, .. } => *index, - HlsVariantStream::Audio { index, .. } => *index, - HlsVariantStream::Subtitle { index, .. } => *index, - } - } - - pub fn id(&self) -> &Uuid { - match self { - HlsVariantStream::Video { id, .. } => id, - HlsVariantStream::Audio { id, .. } => id, - HlsVariantStream::Subtitle { id, .. } => id, +impl Egress for HlsMuxer { + unsafe fn process_pkt( + &mut self, + packet: *mut AVPacket, + variant: &Uuid, + ) -> Result { + if let Some(ns) = self.mux_packet(packet, variant)? { + Ok(EgressResult::NewSegment(ns)) + } else { + Ok(EgressResult::None) } } } - -impl Display for HlsVariantStream { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - HlsVariantStream::Video { index, .. } => write!(f, "v:{}", index), - HlsVariantStream::Audio { index, .. } => write!(f, "a:{}", index), - HlsVariantStream::Subtitle { index, .. } => write!(f, "s:{}", index), - } - } -} - -struct HlsVariant { - /// Name of this variant (720p) - name: String, - /// MPEG-TS muxer for this variant - mux: Muxer, - /// List of streams ids in this variant - streams: Vec, - /// Segment length in seconds - segment_length: f32, - /// Current segment index - idx: u64, - /// Output directory (base) - out_dir: String, - /// List of segments to be included in the playlist - segments: Vec, -} - -struct SegmentInfo(u64, f32); - -impl SegmentInfo { - fn to_media_segment(&self) -> MediaSegment { - MediaSegment { - uri: HlsVariant::segment_name(self.0), - duration: self.1, - title: Some("no desc".to_string()), - ..MediaSegment::default() - } - } - - fn filename(&self) -> String { - HlsVariant::segment_name(self.0) - } -} - -impl HlsVariant { - pub fn new<'a>( - out_dir: &'a str, - segment_length: f32, - group: usize, - encoded_vars: impl Iterator, - ) -> Result { - let name = format!("stream_{}", group); - let first_seg = Self::map_segment_path(out_dir, &name, 1); - std::fs::create_dir_all(PathBuf::from(&first_seg).parent().unwrap())?; - - let mut mux = unsafe { - Muxer::builder() - .with_output_path(first_seg.as_str(), Some("mpegts"))? - .build()? - }; - let mut streams = Vec::new(); - for (var, enc) in encoded_vars { - match var { - VariantStream::Video(v) => unsafe { - let stream = mux.add_stream_encoder(enc)?; - streams.push(HlsVariantStream::Video { - group, - index: (*stream).index as usize, - id: v.id(), - }) - }, - VariantStream::Audio(a) => unsafe { - let stream = mux.add_stream_encoder(enc)?; - streams.push(HlsVariantStream::Audio { - group, - index: (*stream).index as usize, - id: a.id(), - }) - }, - VariantStream::Subtitle(s) => unsafe { - let stream = mux.add_stream_encoder(enc)?; - streams.push(HlsVariantStream::Subtitle { - group, - index: (*stream).index as usize, - id: s.id(), - }) - }, - _ => panic!("unsupported variant stream"), - } - } - unsafe { - mux.open(None)?; - } - Ok(Self { - name: name.clone(), - segment_length, - mux, - streams, - idx: 1, - segments: Vec::from([SegmentInfo(1, segment_length)]), - out_dir: out_dir.to_string(), - }) - } - - pub fn segment_name(idx: u64) -> String { - format!("{}.ts", idx) - } - - pub fn out_dir(&self) -> PathBuf { - PathBuf::from(&self.out_dir).join(&self.name) - } - - pub fn map_segment_path(out_dir: &str, name: &str, idx: u64) -> String { - PathBuf::from(out_dir) - .join(name) - .join(Self::segment_name(idx)) - .to_string_lossy() - .to_string() - } - - /// Mux a packet created by the encoder for this variant - pub unsafe fn mux_packet(&mut self, pkt: *mut AVPacket) -> Result<()> { - // time of this packet in seconds - let pkt_time = (*pkt).pts as f32 * av_q2d((*pkt).time_base) as f32; - // what segment this pkt should be in (index) - let pkt_seg = 1 + (pkt_time / self.segment_length).floor() as u64; - - let can_split = (*pkt).flags & AV_PKT_FLAG_KEY == AV_PKT_FLAG_KEY; - if pkt_seg != self.idx && can_split { - self.split_next_seg()?; - } - self.mux.write_packet(pkt) - } - - unsafe fn split_next_seg(&mut self) -> Result<()> { - self.idx += 1; - - // Manually reset muxer avio - let ctx = self.mux.context(); - av_write_frame(ctx, ptr::null_mut()); - avio_flush((*ctx).pb); - av_free((*ctx).url as *mut _); - - let next_seg_url = Self::map_segment_path(&*self.out_dir, &self.name, self.idx); - (*ctx).url = av_strdup(cstr!(next_seg_url.as_str())); - - let ret = avio_open(&mut (*ctx).pb, (*ctx).url, AVIO_FLAG_WRITE); - if ret < 0 { - bail!("Failed to re-alloc avio"); - } - - // tell muxer it needs to write headers again - av_opt_set( - (*ctx).priv_data, - cstr!("mpegts_flags"), - cstr!("resend_headers"), - 0, - ); - - info!("Writing segment {}", next_seg_url); - if let Err(e) = self.add_segment(self.idx, 2.0) { - warn!("Failed to update playlist: {}", e); - } - Ok(()) - } - - fn add_segment(&mut self, idx: u64, duration: f32) -> Result<()> { - self.segments.push(SegmentInfo(idx, duration)); - - const MAX_SEGMENTS: usize = 10; - - if self.segments.len() > MAX_SEGMENTS { - let n_drain = self.segments.len() - MAX_SEGMENTS; - let seg_dir = PathBuf::from(self.out_dir()); - for seg in self.segments.drain(..n_drain) { - // delete file - let seg_path = seg_dir.join(seg.filename()); - std::fs::remove_file(seg_path)?; - } - } - self.write_playlist() - } - - fn write_playlist(&mut self) -> Result<()> { - let mut pl = m3u8_rs::MediaPlaylist::default(); - pl.target_duration = self.segment_length as u64; - pl.segments = self.segments.iter().map(|s| s.to_media_segment()).collect(); - pl.version = Some(3); - pl.media_sequence = self.segments.first().map(|s| s.0).unwrap_or(0); - - let mut f_out = File::create(self.out_dir().join("live.m3u8"))?; - pl.write_to(&mut f_out)?; - Ok(()) - } - - pub fn to_mapping(&self) -> String { - format!( - "{},name:{}", - self.streams.iter().map(|j| j.to_string()).join(","), - self.name - ) - } -} - -impl HlsEgress { - pub fn new<'a>( - out_dir: &str, - segment_length: f32, - encoders: impl Iterator, - ) -> Result { - let id = Uuid::new_v4(); - let base = PathBuf::from(out_dir) - .join(id.to_string()) - .to_string_lossy() - .to_string(); - - let mut vars = Vec::new(); - for (k, group) in &encoders - .sorted_by(|a, b| a.0.group_id().cmp(&b.0.group_id())) - .chunk_by(|a| a.0.group_id()) - { - let var = HlsVariant::new(&base, segment_length, k, group)?; - vars.push(var); - } - - Ok(Self { id, variants: vars }) - } -} - -impl Egress for HlsEgress { - unsafe fn process_pkt(&mut self, packet: *mut AVPacket, variant: &Uuid) -> Result<()> { - for var in self.variants.iter_mut() { - if var.streams.iter().any(|s| s.id() == variant) { - var.mux_packet(packet)?; - } - } - Ok(()) - } -} diff --git a/src/egress/http.rs b/src/egress/http.rs index a1e2f19..10937fe 100644 --- a/src/egress/http.rs +++ b/src/egress/http.rs @@ -3,15 +3,11 @@ use std::net::SocketAddr; use anyhow::Error; use warp::{cors, Filter}; -use crate::settings::Settings; - -pub async fn listen_out_dir(addr: String, settings: Settings) -> Result<(), Error> { +pub async fn listen_out_dir(addr: String, dir: String) -> Result<(), Error> { let addr: SocketAddr = addr.parse()?; let cors = cors().allow_any_origin().allow_methods(vec!["GET"]); - let warp_out = warp::get() - .and(warp::fs::dir(settings.output_dir.clone())) - .with(cors); + let warp_out = warp::get().and(warp::fs::dir(dir)).with(cors); warp::serve(warp_out).run(addr).await; Ok(()) diff --git a/src/egress/mod.rs b/src/egress/mod.rs index 9ed1957..a503203 100644 --- a/src/egress/mod.rs +++ b/src/egress/mod.rs @@ -3,6 +3,7 @@ use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVPacket; use serde::{Deserialize, Serialize}; use std::collections::HashSet; use std::fmt::{Display, Formatter}; +use std::path::PathBuf; use uuid::Uuid; pub mod hls; @@ -31,5 +32,27 @@ impl Display for EgressConfig { } pub trait Egress { - unsafe fn process_pkt(&mut self, packet: *mut AVPacket, variant: &Uuid) -> Result<()>; + unsafe fn process_pkt(&mut self, packet: *mut AVPacket, variant: &Uuid) + -> Result; +} + +#[derive(Debug, Clone)] +pub enum EgressResult { + /// Nothing to report + None, + /// A new segment was created + NewSegment(NewSegment), +} + +/// Basic details of new segment created by a muxer +#[derive(Debug, Clone)] +pub struct NewSegment { + /// The id of the variant (video or audio) + pub variant: Uuid, + /// Segment index + pub idx: u64, + /// Duration in seconds + pub duration: f32, + /// Path on disk to the segment file + pub path: PathBuf, } diff --git a/src/egress/recorder.rs b/src/egress/recorder.rs index 8f7f7cd..5291008 100644 --- a/src/egress/recorder.rs +++ b/src/egress/recorder.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::PathBuf; use uuid::Uuid; -use crate::egress::{Egress, EgressConfig}; +use crate::egress::{Egress, EgressConfig, EgressResult}; pub struct RecorderEgress { id: Uuid, @@ -39,11 +39,14 @@ impl RecorderEgress { } impl Egress for RecorderEgress { - unsafe fn process_pkt(&mut self, packet: *mut AVPacket, variant: &Uuid) -> Result<()> { + unsafe fn process_pkt( + &mut self, + packet: *mut AVPacket, + variant: &Uuid, + ) -> Result { if self.config.variants.contains(variant) { - self.muxer.write_packet(packet) - } else { - Ok(()) + self.muxer.write_packet(packet)?; } + Ok(EgressResult::None) } } diff --git a/src/ingress/file.rs b/src/ingress/file.rs index 09bf0e9..69f0fbb 100644 --- a/src/ingress/file.rs +++ b/src/ingress/file.rs @@ -1,19 +1,21 @@ +use crate::ingress::{spawn_pipeline, ConnectionInfo}; +use crate::overseer::Overseer; +use crate::settings::Settings; use anyhow::Result; use log::info; use std::path::PathBuf; +use std::sync::Arc; -use crate::ingress::{spawn_pipeline, ConnectionInfo}; -use crate::settings::Settings; - -pub async fn listen(path: PathBuf, settings: Settings) -> Result<()> { +pub async fn listen(path: PathBuf, overseer: Arc) -> Result<()> { info!("Sending file {}", path.to_str().unwrap()); let info = ConnectionInfo { ip_addr: "127.0.0.1:6969".to_string(), endpoint: "file-input".to_owned(), + key: "".to_string(), }; let file = std::fs::File::open(path)?; - spawn_pipeline(info, settings, Box::new(file)); + spawn_pipeline(info, overseer.clone(), Box::new(file)).await; Ok(()) } diff --git a/src/ingress/mod.rs b/src/ingress/mod.rs index d35eb15..d2ce2d3 100644 --- a/src/ingress/mod.rs +++ b/src/ingress/mod.rs @@ -1,16 +1,18 @@ +use crate::overseer::Overseer; use crate::pipeline::runner::PipelineRunner; use crate::settings::Settings; -use crate::webhook::Webhook; use anyhow::Result; use log::{error, info}; use serde::{Deserialize, Serialize}; use std::io::Read; +use std::sync::Arc; +use tokio::runtime::Handle; pub mod file; #[cfg(feature = "srt")] pub mod srt; pub mod tcp; -#[cfg(feature = "test-source")] +#[cfg(feature = "test-pattern")] pub mod test; #[derive(Clone, Debug, Serialize, Deserialize)] @@ -20,29 +22,31 @@ pub struct ConnectionInfo { /// IP address of the connection pub ip_addr: String, + + /// Stream key + pub key: String, } -pub(crate) fn spawn_pipeline( +pub async fn spawn_pipeline( info: ConnectionInfo, - settings: Settings, + seer: Arc, reader: Box, ) { info!("New client connected: {}", &info.ip_addr); + let handle = Handle::current(); + let seer = seer.clone(); std::thread::spawn(move || unsafe { - if let Err(e) = spawn_pipeline_inner(info, settings, reader) { - error!("{}", e); - } + match PipelineRunner::new(handle, seer, info, reader) { + Ok(mut pl) => loop { + if let Err(e) = pl.run() { + error!("Pipeline run failed: {}", e); + break; + } + }, + Err(e) => { + error!("Failed to create PipelineRunner: {}", e); + return; + } + }; }); } - -unsafe fn spawn_pipeline_inner( - info: ConnectionInfo, - settings: Settings, - reader: Box, -) -> Result<()> { - let webhook = Webhook::new(settings.clone()); - let mut pl = PipelineRunner::new(info, webhook, reader)?; - loop { - pl.run()? - } -} diff --git a/src/ingress/srt.rs b/src/ingress/srt.rs index 3492880..774f845 100644 --- a/src/ingress/srt.rs +++ b/src/ingress/srt.rs @@ -1,14 +1,15 @@ use crate::ingress::{spawn_pipeline, ConnectionInfo}; +use crate::overseer::Overseer; use crate::pipeline::runner::PipelineRunner; use crate::settings::Settings; -use crate::webhook::Webhook; use anyhow::Result; use futures_util::{StreamExt, TryStreamExt}; use log::{error, info, warn}; use srt_tokio::{SrtListener, SrtSocket}; +use std::sync::Arc; use tokio::sync::mpsc::unbounded_channel; -pub async fn listen(listen_addr: String, settings: Settings) -> Result<()> { +pub async fn listen(listen_addr: String, overseer: Arc) -> Result<()> { let (_binding, mut packets) = SrtListener::builder().bind(listen_addr.clone()).await?; info!("SRT listening on: {}", listen_addr.clone()); @@ -18,7 +19,7 @@ pub async fn listen(listen_addr: String, settings: Settings) -> Result<()> { endpoint: listen_addr.clone(), ip_addr: socket.settings().remote.to_string(), }; - spawn_pipeline(info, settings.clone(), Box::new(socket)); + spawn_pipeline(info, overseer.clone(), Box::new(socket)).await; } Ok(()) } diff --git a/src/ingress/tcp.rs b/src/ingress/tcp.rs index 7622f3b..9c14670 100644 --- a/src/ingress/tcp.rs +++ b/src/ingress/tcp.rs @@ -1,11 +1,13 @@ use anyhow::Result; use log::info; +use std::sync::Arc; use tokio::net::TcpListener; use crate::ingress::{spawn_pipeline, ConnectionInfo}; +use crate::overseer::Overseer; use crate::settings::Settings; -pub async fn listen(addr: String, settings: Settings) -> Result<()> { +pub async fn listen(addr: String, overseer: Arc) -> Result<()> { let listener = TcpListener::bind(addr.clone()).await?; info!("TCP listening on: {}", addr.clone()); @@ -13,9 +15,10 @@ pub async fn listen(addr: String, settings: Settings) -> Result<()> { let info = ConnectionInfo { ip_addr: ip.to_string(), endpoint: addr.clone(), + key: "".to_string(), }; let socket = socket.into_std()?; - spawn_pipeline(info, settings.clone(), Box::new(socket)); + spawn_pipeline(info, overseer.clone(), Box::new(socket)).await; } Ok(()) } diff --git a/src/ingress/test.rs b/src/ingress/test.rs index 97affa7..bd3ad47 100644 --- a/src/ingress/test.rs +++ b/src/ingress/test.rs @@ -1,4 +1,5 @@ use crate::ingress::{spawn_pipeline, ConnectionInfo}; +use crate::overseer::Overseer; use crate::settings::Settings; use anyhow::Result; use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVCodecID::AV_CODEC_ID_H264; @@ -15,20 +16,20 @@ use log::info; use ringbuf::traits::{Observer, Split}; use ringbuf::{HeapCons, HeapRb}; use std::io::Read; -use std::ops::Add; +use std::sync::Arc; use std::time::{Duration, Instant}; use tiny_skia::Pixmap; -use warp::Buf; -pub async fn listen(settings: Settings) -> Result<()> { +pub async fn listen(overseer: Arc) -> Result<()> { info!("Test pattern enabled"); let info = ConnectionInfo { - endpoint: "test-source".to_string(), - ip_addr: "".to_string(), + endpoint: "test-pattern".to_string(), + ip_addr: "test-pattern".to_string(), + key: "test-pattern".to_string(), }; let src = TestPatternSrc::new()?; - spawn_pipeline(info, settings, Box::new(src)); + spawn_pipeline(info, overseer.clone(), Box::new(src)).await; Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index b90fc52..0c4a04b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ pub mod egress; pub mod ingress; +pub mod mux; +pub mod overseer; pub mod pipeline; pub mod settings; pub mod variant; -pub mod webhook; diff --git a/src/mux/hls.rs b/src/mux/hls.rs new file mode 100644 index 0000000..6ff87e5 --- /dev/null +++ b/src/mux/hls.rs @@ -0,0 +1,302 @@ +use crate::egress::{EgressResult, NewSegment}; +use crate::variant::{StreamMapping, VariantStream}; +use anyhow::{bail, Result}; +use ffmpeg_rs_raw::ffmpeg_sys_the_third::{ + av_free, av_opt_set, av_q2d, av_write_frame, avio_flush, avio_open, AVPacket, AVIO_FLAG_WRITE, + AV_PKT_FLAG_KEY, +}; +use ffmpeg_rs_raw::{cstr, Encoder, Muxer}; +use itertools::Itertools; +use log::{info, warn}; +use m3u8_rs::MediaSegment; +use std::fmt::Display; +use std::fs::File; +use std::path::PathBuf; +use std::ptr; +use uuid::Uuid; + +pub enum HlsVariantStream { + Video { + group: usize, + index: usize, + id: Uuid, + }, + Audio { + group: usize, + index: usize, + id: Uuid, + }, + Subtitle { + group: usize, + index: usize, + id: Uuid, + }, +} + +impl HlsVariantStream { + pub fn id(&self) -> &Uuid { + match self { + HlsVariantStream::Video { id, .. } => id, + HlsVariantStream::Audio { id, .. } => id, + HlsVariantStream::Subtitle { id, .. } => id, + } + } +} + +impl Display for HlsVariantStream { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + HlsVariantStream::Video { index, .. } => write!(f, "v:{}", index), + HlsVariantStream::Audio { index, .. } => write!(f, "a:{}", index), + HlsVariantStream::Subtitle { index, .. } => write!(f, "s:{}", index), + } + } +} + +pub struct HlsVariant { + /// Name of this variant (720p) + pub name: String, + /// MPEG-TS muxer for this variant + pub mux: Muxer, + /// List of streams ids in this variant + pub streams: Vec, + /// Segment length in seconds + pub segment_length: f32, + /// Current segment index + pub idx: u64, + /// Output directory (base) + pub out_dir: String, + /// List of segments to be included in the playlist + pub segments: Vec, +} + +struct SegmentInfo(u64, f32); + +impl SegmentInfo { + fn to_media_segment(&self) -> MediaSegment { + MediaSegment { + uri: HlsVariant::segment_name(self.0), + duration: self.1, + title: Some("no desc".to_string()), + ..MediaSegment::default() + } + } + + fn filename(&self) -> String { + HlsVariant::segment_name(self.0) + } +} + +impl HlsVariant { + pub fn new<'a>( + out_dir: &'a str, + segment_length: f32, + group: usize, + encoded_vars: impl Iterator, + ) -> Result { + let name = format!("stream_{}", group); + let first_seg = Self::map_segment_path(out_dir, &name, 1); + std::fs::create_dir_all(PathBuf::from(&first_seg).parent().unwrap())?; + + let mut mux = unsafe { + Muxer::builder() + .with_output_path(first_seg.as_str(), Some("mpegts"))? + .build()? + }; + let mut streams = Vec::new(); + for (var, enc) in encoded_vars { + match var { + VariantStream::Video(v) => unsafe { + let stream = mux.add_stream_encoder(enc)?; + streams.push(HlsVariantStream::Video { + group, + index: (*stream).index as usize, + id: v.id(), + }) + }, + VariantStream::Audio(a) => unsafe { + let stream = mux.add_stream_encoder(enc)?; + streams.push(HlsVariantStream::Audio { + group, + index: (*stream).index as usize, + id: a.id(), + }) + }, + VariantStream::Subtitle(s) => unsafe { + let stream = mux.add_stream_encoder(enc)?; + streams.push(HlsVariantStream::Subtitle { + group, + index: (*stream).index as usize, + id: s.id(), + }) + }, + _ => panic!("unsupported variant stream"), + } + } + unsafe { + mux.open(None)?; + } + Ok(Self { + name: name.clone(), + segment_length, + mux, + streams, + idx: 1, + segments: Vec::from([SegmentInfo(1, segment_length)]), + out_dir: out_dir.to_string(), + }) + } + + pub fn segment_name(idx: u64) -> String { + format!("{}.ts", idx) + } + + pub fn out_dir(&self) -> PathBuf { + PathBuf::from(&self.out_dir).join(&self.name) + } + + pub fn map_segment_path(out_dir: &str, name: &str, idx: u64) -> String { + PathBuf::from(out_dir) + .join(name) + .join(Self::segment_name(idx)) + .to_string_lossy() + .to_string() + } + + /// Mux a packet created by the encoder for this variant + pub unsafe fn mux_packet(&mut self, pkt: *mut AVPacket) -> Result> { + // time of this packet in seconds + let pkt_time = (*pkt).pts as f32 * av_q2d((*pkt).time_base) as f32; + // what segment this pkt should be in (index) + let pkt_seg = 1 + (pkt_time / self.segment_length).floor() as u64; + + let mut result = None; + let can_split = (*pkt).flags & AV_PKT_FLAG_KEY == AV_PKT_FLAG_KEY; + if pkt_seg != self.idx && can_split { + result = Some(self.split_next_seg()?); + } + self.mux.write_packet(pkt)?; + Ok(result) + } + + unsafe fn split_next_seg(&mut self) -> Result { + self.idx += 1; + + // Manually reset muxer avio + let ctx = self.mux.context(); + av_write_frame(ctx, ptr::null_mut()); + avio_flush((*ctx).pb); + av_free((*ctx).url as *mut _); + + let next_seg_url = Self::map_segment_path(&*self.out_dir, &self.name, self.idx); + (*ctx).url = cstr!(next_seg_url.as_str()); + + let ret = avio_open(&mut (*ctx).pb, (*ctx).url, AVIO_FLAG_WRITE); + if ret < 0 { + bail!("Failed to re-init avio"); + } + + // tell muxer it needs to write headers again + av_opt_set( + (*ctx).priv_data, + cstr!("events_flags"), + cstr!("resend_headers"), + 0, + ); + + // TODO: calc actual duration + let duration = 2.0; + info!("Writing segment {}", &next_seg_url); + if let Err(e) = self.add_segment(self.idx, duration) { + warn!("Failed to update playlist: {}", e); + } + + /// Get the video variant for this group + /// since this could actually be audio which would not be useful for + /// [Overseer] impl + let video_var = self + .streams + .iter() + .find(|a| matches!(*a, HlsVariantStream::Video { .. })) + .map_or(Default::default(), |v| v.id().clone()); + + Ok(NewSegment { + variant: video_var, + idx: self.idx - 1, // emit result of the previously completed segment, + duration, + path: PathBuf::from(next_seg_url), + }) + } + + fn add_segment(&mut self, idx: u64, duration: f32) -> Result<()> { + self.segments.push(SegmentInfo(idx, duration)); + + const MAX_SEGMENTS: usize = 10; + + if self.segments.len() > MAX_SEGMENTS { + let n_drain = self.segments.len() - MAX_SEGMENTS; + let seg_dir = PathBuf::from(self.out_dir()); + for seg in self.segments.drain(..n_drain) { + // delete file + let seg_path = seg_dir.join(seg.filename()); + std::fs::remove_file(seg_path)?; + } + } + self.write_playlist() + } + + fn write_playlist(&mut self) -> Result<()> { + let mut pl = m3u8_rs::MediaPlaylist::default(); + pl.target_duration = self.segment_length as u64; + pl.segments = self.segments.iter().map(|s| s.to_media_segment()).collect(); + pl.version = Some(3); + pl.media_sequence = self.segments.first().map(|s| s.0).unwrap_or(0); + + let mut f_out = File::create(self.out_dir().join("live.m3u8"))?; + pl.write_to(&mut f_out)?; + Ok(()) + } +} + +pub struct HlsMuxer { + variants: Vec, +} + +impl HlsMuxer { + pub fn new<'a>( + out_dir: &str, + segment_length: f32, + encoders: impl Iterator, + ) -> Result { + let id = Uuid::new_v4(); + let base = PathBuf::from(out_dir) + .join(id.to_string()) + .to_string_lossy() + .to_string(); + + let mut vars = Vec::new(); + for (k, group) in &encoders + .sorted_by(|a, b| a.0.group_id().cmp(&b.0.group_id())) + .chunk_by(|a| a.0.group_id()) + { + let var = HlsVariant::new(&base, segment_length, k, group)?; + vars.push(var); + } + + Ok(Self { variants: vars }) + } + + /// Mux an encoded packet from [Encoder] + pub unsafe fn mux_packet( + &mut self, + pkt: *mut AVPacket, + variant: &Uuid, + ) -> Result> { + for var in self.variants.iter_mut() { + if var.streams.iter().any(|s| s.id() == variant) { + return var.mux_packet(pkt); + } + } + bail!("Packet doesnt match any variants"); + } +} diff --git a/src/mux/mod.rs b/src/mux/mod.rs new file mode 100644 index 0000000..d6aeb80 --- /dev/null +++ b/src/mux/mod.rs @@ -0,0 +1,2 @@ +mod hls; +pub use hls::*; diff --git a/src/overseer/mod.rs b/src/overseer/mod.rs new file mode 100644 index 0000000..1e19264 --- /dev/null +++ b/src/overseer/mod.rs @@ -0,0 +1,209 @@ +use crate::egress::EgressConfig; +use crate::ingress::ConnectionInfo; +use crate::overseer::webhook::WebhookOverseer; +#[cfg(feature = "zap-stream")] +use crate::overseer::zap_stream::ZapStreamOverseer; +use crate::pipeline::{EgressType, PipelineConfig}; +use crate::settings::{OverseerConfig, Settings}; +use crate::variant::audio::AudioVariant; +use crate::variant::mapping::VariantMapping; +use crate::variant::video::VideoVariant; +use crate::variant::{StreamMapping, VariantStream}; +use anyhow::Result; +use async_trait::async_trait; +use chrono::Utc; +use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVPixelFormat::AV_PIX_FMT_YUV420P; +use std::cmp::PartialEq; +use std::path::PathBuf; +use std::sync::Arc; +use uuid::Uuid; + +mod webhook; +#[cfg(feature = "zap-stream")] +mod zap_stream; + +/// A copy of [ffmpeg_rs_raw::DemuxerInfo] without internal ptr +#[derive(PartialEq, Clone)] +pub struct IngressInfo { + pub bitrate: usize, + pub streams: Vec, +} + +/// A copy of [ffmpeg_rs_raw::StreamInfo] without ptr +#[derive(PartialEq, Clone)] +pub struct IngressStream { + pub index: usize, + pub stream_type: IngressStreamType, + pub codec: isize, + pub format: isize, + pub width: usize, + pub height: usize, + pub fps: f32, + pub sample_rate: usize, + pub language: String, +} + +#[derive(PartialEq, Eq, Clone)] +pub enum IngressStreamType { + Video, + Audio, + Subtitle, +} + +#[async_trait] +/// The control process that oversees streaming operations +pub trait Overseer: Send + Sync { + /// Set up a new streaming pipeline + async fn configure_pipeline( + &self, + connection: &ConnectionInfo, + stream_info: &IngressInfo, + ) -> Result; + + /// A new segment (HLS etc.) was generated for a stream variant + /// + /// This handler is usually used for distribution / billing + async fn new_segment( + &self, + pipeline: &Uuid, + variant_id: &Uuid, + index: u64, + duration: f32, + path: &PathBuf, + ) -> Result<()>; +} + +impl Settings { + pub async fn get_overseer(&self) -> Result> { + match &self.overseer { + OverseerConfig::Static { egress_types } => Ok(Arc::new(StaticOverseer::new( + &self.output_dir, + egress_types, + ))), + OverseerConfig::Webhook { url } => Ok(Arc::new(WebhookOverseer::new(&url))), + OverseerConfig::ZapStream { + nsec: private_key, + database, + lnd, + relays, + } => { + #[cfg(not(feature = "zap-stream"))] + panic!("zap.stream overseer is not enabled"); + + #[cfg(feature = "zap-stream")] + Ok(Arc::new( + ZapStreamOverseer::new(private_key, database, lnd, relays).await?, + )) + } + } + } +} + +pub(crate) fn get_default_variants(info: &IngressInfo) -> Result> { + let mut vars: Vec = vec![]; + if let Some(video_src) = info + .streams + .iter() + .find(|c| c.stream_type == IngressStreamType::Video) + { + vars.push(VariantStream::CopyVideo(VariantMapping { + id: Uuid::new_v4(), + src_index: video_src.index, + dst_index: 0, + group_id: 0, + })); + vars.push(VariantStream::Video(VideoVariant { + mapping: VariantMapping { + id: Uuid::new_v4(), + src_index: video_src.index, + dst_index: 1, + group_id: 1, + }, + width: 1280, + height: 720, + fps: video_src.fps, + bitrate: 3_000_000, + codec: 27, + profile: 100, + level: 51, + keyframe_interval: video_src.fps as u16 * 2, + pixel_format: AV_PIX_FMT_YUV420P as u32, + })); + } + + if let Some(audio_src) = info + .streams + .iter() + .find(|c| c.stream_type == IngressStreamType::Audio) + { + vars.push(VariantStream::CopyAudio(VariantMapping { + id: Uuid::new_v4(), + src_index: audio_src.index, + dst_index: 2, + group_id: 0, + })); + vars.push(VariantStream::Audio(AudioVariant { + mapping: VariantMapping { + id: Uuid::new_v4(), + src_index: audio_src.index, + dst_index: 3, + group_id: 1, + }, + bitrate: 192_000, + codec: 86018, + channels: 2, + sample_rate: 48_000, + sample_fmt: "fltp".to_owned(), + })); + } + + Ok(vars) +} +/// Simple static file output without any access controls +struct StaticOverseer {} + +impl StaticOverseer { + fn new(out_dir: &str, egress_types: &Vec) -> Self { + Self {} + } +} + +#[async_trait] +impl Overseer for StaticOverseer { + async fn configure_pipeline( + &self, + connection: &ConnectionInfo, + stream_info: &IngressInfo, + ) -> Result { + let vars = get_default_variants(stream_info)?; + let var_ids = vars.iter().map(|v| v.id()).collect(); + Ok(PipelineConfig { + id: Utc::now().timestamp() as u64, + variants: vars, + egress: vec![ + /*EgressType::Recorder(EgressConfig { + name: "REC".to_owned(), + out_dir: self.config.output_dir.clone(), + variants: var_ids, + }),*/ + EgressType::HLS(EgressConfig { + name: "HLS".to_owned(), + // TODO: this is temp, webhook should not need full config + out_dir: "out".to_string(), + variants: var_ids, + }), + ], + }) + } + + async fn new_segment( + &self, + pipeline: &Uuid, + variant_id: &Uuid, + index: u64, + duration: f32, + path: &PathBuf, + ) -> Result<()> { + todo!() + } +} diff --git a/src/overseer/webhook.rs b/src/overseer/webhook.rs new file mode 100644 index 0000000..ed7fc9d --- /dev/null +++ b/src/overseer/webhook.rs @@ -0,0 +1,42 @@ +use crate::ingress::ConnectionInfo; +use crate::overseer::{IngressInfo, Overseer}; +use crate::pipeline::PipelineConfig; +use anyhow::Result; +use async_trait::async_trait; +use std::path::PathBuf; +use uuid::Uuid; + +#[derive(Clone)] +pub struct WebhookOverseer { + url: String, +} + +impl WebhookOverseer { + pub fn new(url: &str) -> Self { + Self { + url: url.to_string(), + } + } +} + +#[async_trait] +impl Overseer for WebhookOverseer { + async fn configure_pipeline( + &self, + connection: &ConnectionInfo, + stream_info: &IngressInfo, + ) -> Result { + todo!() + } + + async fn new_segment( + &self, + pipeline: &Uuid, + variant_id: &Uuid, + index: u64, + duration: f32, + path: &PathBuf, + ) -> Result<()> { + todo!() + } +} diff --git a/src/overseer/zap_stream/db.rs b/src/overseer/zap_stream/db.rs new file mode 100644 index 0000000..f21fd3d --- /dev/null +++ b/src/overseer/zap_stream/db.rs @@ -0,0 +1,114 @@ +use anyhow::Result; +use chrono::{DateTime, Utc}; +use nostr_sdk::{Client, Event, EventBuilder, Kind, Tag}; +use sqlx::{FromRow, Type}; +use std::fmt::{Display, Formatter}; + +#[derive(Debug, Clone, FromRow)] +pub struct User { + pub id: u64, + pub pubkey: [u8; 32], + pub created: DateTime, + pub balance: i64, + pub tos_accepted: DateTime, + pub stream_key: String, + pub is_admin: bool, + pub is_blocked: bool, +} + +#[derive(Default, Debug, Clone, Type)] +#[repr(u8)] +pub enum UserStreamState { + #[default] + Unknown = 0, + Planned = 1, + Live = 2, + Ended = 3, +} + +impl Display for UserStreamState { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + UserStreamState::Unknown => write!(f, "unknown"), + UserStreamState::Planned => write!(f, "planned"), + UserStreamState::Live => write!(f, "live"), + UserStreamState::Ended => write!(f, "ended"), + } + } +} + +#[derive(Debug, Clone, Default, FromRow)] +pub struct UserStream { + pub id: u64, + pub user_id: u64, + pub starts: DateTime, + pub ends: Option>, + pub state: UserStreamState, + pub title: Option, + pub summary: Option, + pub image: Option, + pub thumb: Option, + pub tags: Option, + pub content_warning: Option, + pub goal: Option, + pub pinned: Option, + pub cost: u64, + pub duration: f32, + pub fee: Option, + pub event: Option, +} + +impl UserStream { + pub(crate) fn to_event_builder(&self) -> Result { + let mut tags = vec![ + Tag::parse(&["d".to_string(), self.id.to_string()])?, + Tag::parse(&["status".to_string(), self.state.to_string()])?, + Tag::parse(&["starts".to_string(), self.starts.timestamp().to_string()])?, + ]; + if let Some(ref ends) = self.ends { + tags.push(Tag::parse(&[ + "ends".to_string(), + ends.timestamp().to_string(), + ])?); + } + if let Some(ref title) = self.title { + tags.push(Tag::parse(&["title".to_string(), title.to_string()])?); + } + if let Some(ref summary) = self.summary { + tags.push(Tag::parse(&["summary".to_string(), summary.to_string()])?); + } + if let Some(ref image) = self.image { + tags.push(Tag::parse(&["image".to_string(), image.to_string()])?); + } + if let Some(ref thumb) = self.thumb { + tags.push(Tag::parse(&["thumb".to_string(), thumb.to_string()])?); + } + if let Some(ref content_warning) = self.content_warning { + tags.push(Tag::parse(&[ + "content_warning".to_string(), + content_warning.to_string(), + ])?); + } + if let Some(ref goal) = self.goal { + tags.push(Tag::parse(&["goal".to_string(), goal.to_string()])?); + } + if let Some(ref pinned) = self.pinned { + tags.push(Tag::parse(&["pinned".to_string(), pinned.to_string()])?); + } + if let Some(ref tags_csv) = self.tags { + for tag in tags_csv.split(',') { + tags.push(Tag::parse(&["t".to_string(), tag.to_string()])?); + } + } + Ok(EventBuilder::new(Kind::from(30_313), "", tags)) + } + + pub(super) async fn publish_stream_event(&self, client: &Client) -> Result { + let ev = self + .to_event_builder()? + .sign(&client.signer().await?) + .await?; + client.send_event(ev.clone()).await?; + Ok(ev) + } +} diff --git a/src/overseer/zap_stream/mod.rs b/src/overseer/zap_stream/mod.rs new file mode 100644 index 0000000..c500ab2 --- /dev/null +++ b/src/overseer/zap_stream/mod.rs @@ -0,0 +1,201 @@ +use crate::egress::hls::HlsEgress; +use crate::egress::EgressConfig; +use crate::ingress::ConnectionInfo; +use crate::overseer::zap_stream::db::{UserStream, UserStreamState}; +use crate::overseer::{get_default_variants, IngressInfo, Overseer}; +use crate::pipeline::{EgressType, PipelineConfig}; +use crate::settings::LndSettings; +use crate::variant::StreamMapping; +use anyhow::{anyhow, Result}; +use async_trait::async_trait; +use chrono::{DateTime, Utc}; +use fedimint_tonic_lnd::verrpc::VersionRequest; +use log::info; +use nostr_sdk::bitcoin::PrivateKey; +use nostr_sdk::{JsonUtil, Keys}; +use sqlx::{MySqlPool, Row}; +use std::env::temp_dir; +use std::fs::create_dir_all; +use std::path::PathBuf; +use std::str::FromStr; +use uuid::Uuid; + +mod db; + +/// zap.stream NIP-53 overseer +#[derive(Clone)] +pub struct ZapStreamOverseer { + db: MySqlPool, + lnd: fedimint_tonic_lnd::Client, + client: nostr_sdk::Client, + keys: Keys, +} + +impl ZapStreamOverseer { + pub async fn new( + private_key: &str, + db: &str, + lnd: &LndSettings, + relays: &Vec, + ) -> Result { + let db = MySqlPool::connect(db).await?; + + info!("Connected to database, running migrations"); + // automatically run migrations + sqlx::migrate!().run(&db).await?; + + let mut lnd = fedimint_tonic_lnd::connect( + lnd.address.clone(), + PathBuf::from(&lnd.cert), + PathBuf::from(&lnd.macaroon), + ) + .await?; + + let version = lnd + .versioner() + .get_version(VersionRequest::default()) + .await?; + info!("LND connected: v{}", version.into_inner().version); + + let keys = Keys::from_str(private_key)?; + let client = nostr_sdk::ClientBuilder::new().signer(keys.clone()).build(); + for r in relays { + client.add_relay(r).await?; + } + client.connect().await; + + Ok(Self { + db, + lnd, + client, + keys, + }) + } + + /// Find user by stream key, typical first lookup from ingress + async fn find_user_stream_key(&self, key: &str) -> Result> { + #[cfg(feature = "test-pattern")] + if key == "test-pattern" { + // use the 00 pubkey for test sources + return Ok(Some(self.upsert_user(&[0; 32]).await?)); + } + + Ok(sqlx::query("select id from user where stream_key = ?") + .bind(key) + .fetch_optional(&self.db) + .await? + .map(|r| r.try_get(0).unwrap())) + } + + async fn upsert_user(&self, pubkey: &[u8; 32]) -> Result { + let res = sqlx::query("insert ignore into user(pubkey) values(?) returning id") + .bind(pubkey.as_slice()) + .fetch_optional(&self.db) + .await?; + match res { + None => sqlx::query("select id from user where pubkey = ?") + .bind(pubkey.as_slice()) + .fetch_one(&self.db) + .await? + .try_get(0) + .map_err(anyhow::Error::new), + Some(res) => res.try_get(0).map_err(anyhow::Error::new), + } + } + + async fn create_stream(&self, user_stream: &UserStream) -> Result { + sqlx::query( + "insert into user_stream (user_id, state, starts) values (?, ?, ?) returning id", + ) + .bind(&user_stream.user_id) + .bind(&user_stream.state) + .bind(&user_stream.starts) + .fetch_one(&self.db) + .await? + .try_get(0) + .map_err(anyhow::Error::new) + } + + async fn update_stream(&self, user_stream: &UserStream) -> Result<()> { + sqlx::query( + "update user_stream set state = ?, starts = ?, ends = ?, title = ?, summary = ?, image = ?, thumb = ?, tags = ?, content_warning = ?, goal = ?, pinned = ?, fee = ?, event = ? where id = ?", + ) + .bind(&user_stream.state) + .bind(&user_stream.starts) + .bind(&user_stream.ends) + .bind(&user_stream.title) + .bind(&user_stream.summary) + .bind(&user_stream.image) + .bind(&user_stream.thumb) + .bind(&user_stream.tags) + .bind(&user_stream.content_warning) + .bind(&user_stream.goal) + .bind(&user_stream.pinned) + .bind(&user_stream.fee) + .bind(&user_stream.event) + .bind(&user_stream.id) + .execute(&self.db) + .await + .map_err(anyhow::Error::new)?; + Ok(()) + } +} + +#[async_trait] +impl Overseer for ZapStreamOverseer { + async fn configure_pipeline( + &self, + connection: &ConnectionInfo, + stream_info: &IngressInfo, + ) -> Result { + let uid = self + .find_user_stream_key(&connection.key) + .await? + .ok_or_else(|| anyhow::anyhow!("User not found"))?; + + let out_dir = temp_dir().join("zap-stream"); + create_dir_all(&out_dir)?; + + let variants = get_default_variants(&stream_info)?; + + let mut egress = vec![]; + egress.push(EgressType::HLS(EgressConfig { + name: "nip94-hls".to_string(), + out_dir: out_dir.to_string_lossy().to_string(), + variants: variants.iter().map(|v| v.id()).collect(), + })); + + // insert new stream record + let mut new_stream = UserStream { + id: 0, + user_id: uid, + starts: Utc::now(), + state: UserStreamState::Live, + ..Default::default() + }; + + let stream_id = self.create_stream(&new_stream).await?; + new_stream.id = stream_id; + + let stream_event = new_stream.publish_stream_event(&self.client).await?; + new_stream.event = Some(stream_event.as_json()); + self.update_stream(&new_stream).await?; + + Ok(PipelineConfig { + id: stream_id, + variants, + egress, + }) + } + + async fn new_segment( + &self, + pipeline: &Uuid, + variant_id: &Uuid, + index: u64, + duration: f32, + path: &PathBuf, + ) -> Result<()> { + todo!() + } +} diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 7f822b3..29dffaf 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -45,7 +45,7 @@ impl Display for EgressType { #[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct PipelineConfig { - pub id: Uuid, + pub id: u64, /// Transcoded/Copied stream config pub variants: Vec, /// Output muxers diff --git a/src/pipeline/runner.rs b/src/pipeline/runner.rs index 114bc2b..241a109 100644 --- a/src/pipeline/runner.rs +++ b/src/pipeline/runner.rs @@ -2,34 +2,41 @@ use std::collections::{HashMap, HashSet}; use std::io::Read; use std::mem::transmute; use std::ops::Sub; +use std::sync::Arc; use std::time::Instant; use crate::egress::hls::HlsEgress; use crate::egress::recorder::RecorderEgress; use crate::egress::Egress; use crate::ingress::ConnectionInfo; +use crate::overseer::{IngressInfo, IngressStream, IngressStreamType, Overseer}; use crate::pipeline::{EgressType, PipelineConfig}; use crate::variant::{StreamMapping, VariantStream}; -use crate::webhook::Webhook; -use anyhow::Result; +use anyhow::{bail, Result}; use ffmpeg_rs_raw::ffmpeg_sys_the_third::{ av_frame_free, av_get_sample_fmt, av_packet_free, av_rescale_q, }; use ffmpeg_rs_raw::{ - cstr, get_frame_from_hw, Decoder, Demuxer, DemuxerInfo, Encoder, Resample, Scaler, + cstr, get_frame_from_hw, Decoder, Demuxer, DemuxerInfo, Encoder, Resample, Scaler, StreamType, }; use itertools::Itertools; use log::{info, warn}; +use tokio::runtime::Handle; use uuid::Uuid; /// Pipeline runner is the main entry process for stream transcoding +/// /// Each client connection spawns a new [PipelineRunner] and it should be run in its own thread -/// using [ingress::spawn_pipeline] +/// using [crate::ingress::spawn_pipeline] pub struct PipelineRunner { + /// Async runtime handle + handle: Handle, + + /// Input stream connection info connection: ConnectionInfo, /// Configuration for this pipeline (variants, egress config etc.) - config: PipelineConfig, + config: Option, /// Singleton demuxer for this input demuxer: Demuxer, @@ -54,18 +61,24 @@ pub struct PipelineRunner { fps_counter_start: Instant, frame_ctr: u64, - webhook: Webhook, - info: Option, + /// Info about the input stream + info: Option, + + /// Overseer managing this pipeline + overseer: Arc, } impl PipelineRunner { pub fn new( + handle: Handle, + overseer: Arc, connection: ConnectionInfo, - webhook: Webhook, recv: Box, ) -> Result { Ok(Self { + handle, + overseer, connection, config: Default::default(), demuxer: Demuxer::new_custom_io(recv, None)?, @@ -77,7 +90,6 @@ impl PipelineRunner { fps_counter_start: Instant::now(), egress: Vec::new(), frame_ctr: 0, - webhook, info: None, }) } @@ -86,6 +98,12 @@ impl PipelineRunner { pub unsafe fn run(&mut self) -> Result<()> { self.setup()?; + let config = if let Some(ref config) = self.config { + config + } else { + bail!("Pipeline not configured, cannot run") + }; + // run transcoder pipeline let (mut pkt, stream) = self.demuxer.get_packet()?; let src_index = (*stream).index; @@ -106,8 +124,7 @@ impl PipelineRunner { (*frame).time_base = (*stream).time_base; // Get the variants which want this pkt - let pkt_vars = self - .config + let pkt_vars = config .variants .iter() .filter(|v| v.src_index() == src_index as usize); @@ -188,14 +205,49 @@ impl PipelineRunner { } let info = self.demuxer.probe_input()?; + + // convert to internal type + let i_info = IngressInfo { + bitrate: info.bitrate, + streams: info + .streams + .iter() + .map(|s| IngressStream { + index: s.index, + stream_type: match s.stream_type { + StreamType::Video => IngressStreamType::Video, + StreamType::Audio => IngressStreamType::Audio, + StreamType::Subtitle => IngressStreamType::Subtitle, + }, + codec: s.codec, + format: s.format, + width: s.width, + height: s.height, + fps: s.fps, + sample_rate: s.sample_rate, + language: s.language.clone(), + }) + .collect(), + }; + + let cfg = self.handle.block_on(async { + self.overseer + .configure_pipeline(&self.connection, &i_info) + .await + })?; + self.config = Some(cfg); + self.info = Some(i_info); + self.setup_pipeline(&info)?; - self.info = Some(info); Ok(()) } - unsafe fn setup_pipeline(&mut self, info: &DemuxerInfo) -> Result<()> { - let cfg = self.webhook.start(info); - self.config = cfg.clone(); + unsafe fn setup_pipeline(&mut self, demux_info: &DemuxerInfo) -> Result<()> { + let cfg = if let Some(ref cfg) = self.config { + cfg + } else { + bail!("Cannot setup pipeline without config"); + }; // src stream indexes let inputs: HashSet = cfg.variants.iter().map(|e| e.src_index()).collect(); @@ -205,7 +257,11 @@ impl PipelineRunner { // setup decoders for input_idx in inputs { - let stream = info.streams.iter().find(|f| f.index == input_idx).unwrap(); + let stream = demux_info + .streams + .iter() + .find(|f| f.index == input_idx) + .unwrap(); self.decoder.setup_decoder(stream, None)?; } @@ -219,7 +275,7 @@ impl PipelineRunner { VariantStream::Audio(a) => { let enc = a.try_into()?; let rs = Resample::new( - av_get_sample_fmt(cstr!(a.sample_fmt.as_bytes())), + av_get_sample_fmt(cstr!(a.sample_fmt.as_str())), a.sample_rate as _, a.channels as _, ); @@ -230,10 +286,10 @@ impl PipelineRunner { } } - // Setup copy streams + // TODO: Setup copy streams // Setup egress - for e in cfg.egress { + for e in &cfg.egress { match e { EgressType::HLS(ref c) => { let encoders = self.encoders.iter().filter_map(|(k, v)| { @@ -252,7 +308,7 @@ impl PipelineRunner { let encoders = self .encoders .iter() - .filter(|(k, v)| c.variants.contains(k)) + .filter(|(k, _v)| c.variants.contains(k)) .map(|(_, v)| v); let rec = RecorderEgress::new(c.clone(), encoders)?; self.egress.push(Box::new(rec)); diff --git a/src/settings.rs b/src/settings.rs index 370d620..f186319 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,3 +1,4 @@ +use crate::pipeline::EgressType; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -9,9 +10,38 @@ pub struct Settings { /// - rtmp://localhost:1935 pub endpoints: Vec, - /// Output directory for egress + /// Where to store output (static files) pub output_dir: String, - /// Webhook configuration URL - pub webhook_url: String, + /// Overseer service see [crate::overseer::Overseer] for more info + pub overseer: OverseerConfig, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum OverseerConfig { + /// Static output + Static { + /// Types of output + egress_types: Vec, + }, + /// Control system via external API + Webhook { + /// Webhook service URL + url: String, + }, + /// NIP-53 service (i.e. zap.stream backend) + ZapStream { + database: String, + lnd: LndSettings, + relays: Vec, + nsec: String, + }, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct LndSettings { + pub address: String, + pub cert: String, + pub macaroon: String, } diff --git a/src/webhook.rs b/src/webhook.rs deleted file mode 100644 index aa68684..0000000 --- a/src/webhook.rs +++ /dev/null @@ -1,99 +0,0 @@ -use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVPixelFormat::AV_PIX_FMT_YUV420P; -use ffmpeg_rs_raw::{DemuxerInfo, StreamType}; -use uuid::Uuid; - -use crate::egress::EgressConfig; -use crate::pipeline::{EgressType, PipelineConfig}; -use crate::settings::Settings; -use crate::variant::audio::AudioVariant; -use crate::variant::mapping::VariantMapping; -use crate::variant::video::VideoVariant; -use crate::variant::{StreamMapping, VariantStream}; - -#[derive(Clone)] -pub struct Webhook { - config: Settings, -} - -impl Webhook { - pub fn new(config: Settings) -> Self { - Self { config } - } - - pub fn start(&self, stream_info: &DemuxerInfo) -> PipelineConfig { - let mut vars: Vec = vec![]; - if let Some(video_src) = stream_info - .streams - .iter() - .find(|c| c.stream_type == StreamType::Video) - { - vars.push(VariantStream::CopyVideo(VariantMapping { - id: Uuid::new_v4(), - src_index: video_src.index, - dst_index: 0, - group_id: 0, - })); - vars.push(VariantStream::Video(VideoVariant { - mapping: VariantMapping { - id: Uuid::new_v4(), - src_index: video_src.index, - dst_index: 1, - group_id: 1, - }, - width: 1280, - height: 720, - fps: video_src.fps, - bitrate: 3_000_000, - codec: 27, - profile: 100, - level: 51, - keyframe_interval: video_src.fps as u16 * 2, - pixel_format: AV_PIX_FMT_YUV420P as u32, - })); - } - - if let Some(audio_src) = stream_info - .streams - .iter() - .find(|c| c.stream_type == StreamType::Audio) - { - vars.push(VariantStream::CopyAudio(VariantMapping { - id: Uuid::new_v4(), - src_index: audio_src.index, - dst_index: 2, - group_id: 0, - })); - vars.push(VariantStream::Audio(AudioVariant { - mapping: VariantMapping { - id: Uuid::new_v4(), - src_index: audio_src.index, - dst_index: 3, - group_id: 1, - }, - bitrate: 192_000, - codec: 86018, - channels: 2, - sample_rate: 48_000, - sample_fmt: "fltp".to_owned(), - })); - } - - let var_ids = vars.iter().map(|v| v.id()).collect(); - PipelineConfig { - id: Uuid::new_v4(), - variants: vars, - egress: vec![ - /*EgressType::Recorder(EgressConfig { - name: "REC".to_owned(), - out_dir: self.config.output_dir.clone(), - variants: var_ids, - }),*/ - EgressType::HLS(EgressConfig { - name: "HLS".to_owned(), - out_dir: self.config.output_dir.clone(), - variants: var_ids, - }), - ], - } - } -}