diff --git a/Cargo.lock b/Cargo.lock index aecc77a..a245284 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -41,13 +41,19 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] +[[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" @@ -59,30 +65,29 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -98,9 +103,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -108,9 +113,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "assert_matches" @@ -137,25 +142,25 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "async-trait" -version = "0.1.72" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "atomic_refcell" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d6dc922a2792b006573f60b2648076355daeae5ce9cb59507e5908c9625d31" +checksum = "76f2bfe491d41d45507b8431da8274f7feeca64a49e86d980eed2937ec2ff020" [[package]] name = "autocfg" @@ -210,9 +215,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -231,9 +236,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" [[package]] name = "bitflags" @@ -243,9 +248,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "block-buffer" @@ -258,9 +263,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byte-slice-cast" @@ -270,15 +275,15 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "c_linked_list" @@ -288,9 +293,9 @@ checksum = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" [[package]] name = "cc" -version = "1.0.81" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] @@ -306,9 +311,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b40ccee03b5175c18cde8f37e7d2a33bcef6f8ec8f7cc0d81090d1bb380949c9" +checksum = "03915af431787e6ffdcc74c645077518c6b6e01f80b761e0fbbfa288536311b3" dependencies = [ "smallvec", "target-lexicon", @@ -322,15 +327,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.24" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ + "android-tzdata", "iana-time-zone", - "num-integer", "num-traits", "serde", - "winapi 0.3.9", + "windows-targets", ] [[package]] @@ -345,45 +350,43 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.19" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.19" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", "clap_lex", - "once_cell", "strsim", ] [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "colorchoice" @@ -524,9 +527,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ "darling_core", "darling_macro", @@ -534,27 +537,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "darling_macro" -version = "0.20.1" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -570,9 +573,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" dependencies = [ "serde", ] @@ -635,9 +638,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] @@ -677,9 +680,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" dependencies = [ "errno-dragonfly", "libc", @@ -698,9 +701,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fcm-push-listener" @@ -708,7 +711,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51e1e9327cb6abc9da64951727a3cf534ae7101e529382dac7f5d350bccdba42" dependencies = [ - "base64 0.21.2", + "base64 0.21.4", "ece", "log", "prost 0.11.9", @@ -730,9 +733,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" dependencies = [ "crc32fast", "miniz_oxide", @@ -837,7 +840,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -923,9 +926,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "gio" @@ -965,7 +968,7 @@ version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c316afb01ce8067c5eaab1fc4f2cd47dc21ce7b6296358605e2ffab23ccbd19" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "futures-channel", "futures-core", "futures-executor", @@ -993,7 +996,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -1019,9 +1022,9 @@ dependencies = [ [[package]] name = "gstreamer" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cdb86791dc39a5443f7d08cf3e7ae9c88a94991aba620d177cb5804838201f" +checksum = "b369a1eb2f7db49920d3d590bd988c5fb56dbf2347e1efb60307fe953546ee5d" dependencies = [ "cfg-if", "futures-channel", @@ -1043,9 +1046,9 @@ dependencies = [ [[package]] name = "gstreamer-app" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6da0a8e5671d836ac70741dff0a3e7688ec9ac7ab8dc62c3135dece85df63d4" +checksum = "343376fe0a5b39e7e46fb0fed6a1ead4206ea34584c153130d0f20e51a480b80" dependencies = [ "futures-core", "futures-sink", @@ -1058,9 +1061,9 @@ dependencies = [ [[package]] name = "gstreamer-app-sys" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb093f39bd9b3d0c4ef8f1c4d46028d35bce033f9bda1a0449e21ef17349e03" +checksum = "aea07f07a3f17278e6998390ecaea127e476f0af0360c2d83d96e6d3a97fb75e" dependencies = [ "glib-sys", "gstreamer-base-sys", @@ -1085,9 +1088,9 @@ dependencies = [ [[package]] name = "gstreamer-base-sys" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b9c029583ed61fa5258076a42df91732dc7f5582044ea7ee66a721641e6af4" +checksum = "f4ca701f9078fe115b29b24c80910b577f9cb5b039182f050dbadf5933594b64" dependencies = [ "glib-sys", "gobject-sys", @@ -1169,9 +1172,9 @@ dependencies = [ [[package]] name = "gstreamer-rtsp-sys" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58434d020872f1297f29dfed7ff0d3078652828d4ab40ac6a6f28a77125bc3b0" +checksum = "e09d36a75071fe66ca48c6d9db30e2d03c006d0341aae1a5067ec0c016d780da" dependencies = [ "gio-sys", "glib-sys", @@ -1184,9 +1187,9 @@ dependencies = [ [[package]] name = "gstreamer-sdp" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44947e1d02e706baadfc0a8d25fed276948df86eb98fce434c8bc2172e83c3fa" +checksum = "87946f9c6fabb44a73fb0b3b3d611c7d4468f741dd8e4f9a3d54e1ab2a6a8b36" dependencies = [ "glib", "gstreamer", @@ -1207,9 +1210,9 @@ dependencies = [ [[package]] name = "gstreamer-sys" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a70e3a99118bcd1221f8a62d7a905bae5e5cc2cda678bb46bf3cd36e0f899d33" +checksum = "f86bf9de67a6ab7af67ac11588f4939e984a936030437219f269fe969d79ad8c" dependencies = [ "glib-sys", "gobject-sys", @@ -1219,9 +1222,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -1247,9 +1250,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" [[package]] name = "hdrhistogram" @@ -1272,9 +1275,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -1306,6 +1309,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "http" version = "0.2.9" @@ -1336,9 +1348,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humantime" @@ -1363,7 +1375,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -1397,9 +1409,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1453,19 +1465,19 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.1", ] [[package]] name = "indoc" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" [[package]] name = "inout" @@ -1534,15 +1546,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" [[package]] name = "lock_api" @@ -1556,9 +1568,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "matchers" @@ -1571,9 +1583,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "md5" @@ -1583,9 +1595,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "mime" @@ -1664,7 +1676,8 @@ name = "neolink" version = "0.6.2" dependencies = [ "anyhow", - "base64 0.21.2", + "async-stream", + "base64 0.21.4", "byte-slice-cast", "clap", "console-subscriber", @@ -1803,9 +1816,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -1818,11 +1831,11 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.52" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -1839,7 +1852,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -1850,9 +1863,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.87" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", @@ -1912,39 +1925,39 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "petgraph" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 1.9.3", + "indexmap 2.0.2", ] [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1987,7 +2000,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit 0.19.14", + "toml_edit 0.19.15", ] [[package]] @@ -2016,9 +2029,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" dependencies = [ "unicode-ident", ] @@ -2088,7 +2101,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -2123,16 +2136,16 @@ dependencies = [ "regex", "serde", "tokio", - "toml 0.7.6", + "toml 0.7.8", "validator", "validator_derive", ] [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -2198,14 +2211,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.4", - "regex-syntax 0.7.4", + "regex-automata 0.3.9", + "regex-syntax 0.7.5", ] [[package]] @@ -2219,13 +2232,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.4" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -2236,9 +2249,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "requestty" @@ -2268,11 +2281,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64 0.21.2", + "base64 0.21.4", "bytes", "encoding_rs", "futures-core", @@ -2293,6 +2306,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -2330,7 +2344,7 @@ dependencies = [ "log", "rustls-native-certs", "rustls-pemfile", - "rustls-webpki 0.100.1", + "rustls-webpki 0.100.3", "thiserror", "tokio", "tokio-rustls 0.24.1", @@ -2344,11 +2358,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.6" +version = "0.38.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" +checksum = "f25469e9ae0f3d0047ca8b93fc56843f38e6774f0914a107ff8b41be8be8e0b7" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "errno", "libc", "linux-raw-sys", @@ -2369,13 +2383,13 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki 0.101.2", + "rustls-webpki 0.101.6", "sct", ] @@ -2397,14 +2411,14 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.4", ] [[package]] name = "rustls-webpki" -version = "0.100.1" +version = "0.100.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3" dependencies = [ "ring", "untrusted", @@ -2412,9 +2426,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.2" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ "ring", "untrusted", @@ -2482,29 +2496,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.181" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.181" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "serde_json" -version = "1.0.104" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -2557,14 +2571,14 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -2573,9 +2587,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] @@ -2618,24 +2632,24 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smawk" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" +checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "socket2" @@ -2647,6 +2661,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "socket2" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "spin" version = "0.5.2" @@ -2670,9 +2694,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -2687,9 +2711,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -2715,15 +2739,36 @@ dependencies = [ ] [[package]] -name = "system-deps" -version = "6.1.1" +name = "system-configuration" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30c2de8a4d8f4b823d634affc9cd2a74ec98c53a756f317e529a48046cbf71f3" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "system-deps" +version = "6.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94af52f9402f94aac4948a2518b43359be8d9ce6cd9efc1c4de3b2f7b7e897d6" dependencies = [ "cfg-expr", "heck", "pkg-config", - "toml 0.7.6", + "toml 0.8.2", "version-compare", ] @@ -2735,9 +2780,9 @@ checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" [[package]] name = "tempfile" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", @@ -2748,9 +2793,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -2768,22 +2813,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -2818,9 +2863,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.25" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "itoa", @@ -2833,15 +2878,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -2863,11 +2908,10 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -2876,7 +2920,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.4", "tokio-macros", "tracing", "windows-sys", @@ -2900,7 +2944,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -2930,7 +2974,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.6", + "rustls 0.21.7", "tokio", ] @@ -2948,9 +2992,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -2966,14 +3010,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.19.14", + "toml_edit 0.19.15", ] [[package]] @@ -2999,11 +3043,11 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.14" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde", "serde_spanned", "toml_datetime", @@ -3016,7 +3060,7 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde", "serde_spanned", "toml_datetime", @@ -3032,7 +3076,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.21.2", + "base64 0.21.4", "bytes", "h2", "http", @@ -3102,7 +3146,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -3138,9 +3182,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" @@ -3150,9 +3194,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-linebreak" @@ -3177,9 +3221,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -3195,9 +3239,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -3212,9 +3256,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.3.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom", "rand", @@ -3223,13 +3267,13 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.3.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f67b459f42af2e6e1ee213cb9da4dbd022d3320788c3fb3e1b893093f1e45da" +checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -3333,15 +3377,15 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ "cfg-if", "js-sys", @@ -3367,7 +3411,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3390,9 +3434,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e" +checksum = "07ecc0cd7cac091bf682ec5efa18b1cff79d617b84181f38b3951dbe135f607f" dependencies = [ "ring", "untrusted", @@ -3409,13 +3453,14 @@ dependencies = [ [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] @@ -3442,9 +3487,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi 0.3.9", ] @@ -3475,9 +3520,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -3490,51 +3535,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.3" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46aab759304e4d7b2075a9aecba26228bb073ee8c50db796b2c72c676b5d807" +checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" dependencies = [ "memchr", ] @@ -3557,9 +3602,9 @@ checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956" [[package]] name = "xml-rs" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47430998a7b5d499ccee752b41567bc3afc57e1327dc855b1a2aa44ce29b5fa1" +checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "yaserde" diff --git a/Cargo.toml b/Cargo.toml index 736d99c..919d21e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ [dependencies] anyhow = "1.0.70" +async-stream = "0.3.5" base64 = "0.21.2" byte-slice-cast = "1.2.2" clap = { version = "4.2.2", features = ["derive", "cargo"] } diff --git a/src/common/streamthread.rs b/src/common/streamthread.rs index 79fe553..04f2151 100644 --- a/src/common/streamthread.rs +++ b/src/common/streamthread.rs @@ -316,6 +316,7 @@ impl StreamInstance { impl StreamData { async fn new(name: StreamKind, instance: NeoInstance, strict: bool) -> Result { + const BUFFER_DURATION: Duration = Duration::from_secs(15); let (vid, _) = broadcast::(100); let (aud, _) = broadcast::(100); let (vid_history, _) = watch::>(VecDeque::new()); @@ -420,6 +421,7 @@ impl StreamData { let vid_history = vid_history.clone(); let aud_history = aud_history.clone(); let watchdog_tx = watchdog_tx.clone(); + log::debug!("Running Stream Instance Task"); Box::pin(async move { // use std::io::Write; @@ -514,6 +516,7 @@ impl StreamData { match data { BcMedia::Iframe(BcMediaIframe{data, microseconds, ..}) => { prev_ts = Duration::from_micros(microseconds as u64); + log::debug!("IFrame: {prev_ts:?}"); let d = StampedData{ keyframe: true, data: Arc::new(data), @@ -521,7 +524,7 @@ impl StreamData { }; let _ = vid_tx.send(d.clone()); vid_history.send_modify(|history| { - let drop_time = d.ts.saturating_sub(Duration::from_secs(5)); + let drop_time = d.ts.saturating_sub(BUFFER_DURATION); history.push_back(d); while history.front().is_some_and(|di| di.ts < drop_time) { history.pop_front(); @@ -533,6 +536,7 @@ impl StreamData { }, BcMedia::Pframe(BcMediaPframe{data, microseconds,..}) if recieved_iframe => { prev_ts = Duration::from_micros(microseconds as u64); + log::debug!("PFrame: {prev_ts:?}"); // log::debug!("data: {data:02X?}"); let d = StampedData{ keyframe: false, @@ -541,7 +545,7 @@ impl StreamData { }; let _ = vid_tx.send(d.clone()); vid_history.send_modify(|history| { - let drop_time = d.ts.saturating_sub(Duration::from_secs(5)); + let drop_time = d.ts.saturating_sub(BUFFER_DURATION); history.push_back(d); while history.front().is_some_and(|di| di.ts < drop_time) { history.pop_front(); @@ -550,6 +554,7 @@ impl StreamData { log::trace!("Sent Vid Frame"); } BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) if recieved_iframe => { + log::debug!("Audio: {prev_ts:?}"); let d = StampedData{ keyframe: aud_keyframe, data: Arc::new(data), @@ -558,7 +563,7 @@ impl StreamData { aud_keyframe = false; let _ = aud_tx.send(d.clone())?; aud_history.send_modify(|history| { - let drop_time = d.ts.saturating_sub(Duration::from_secs(5)); + let drop_time = d.ts.saturating_sub(BUFFER_DURATION); history.push_back(d); while history.front().is_some_and(|di| di.ts < drop_time) { history.pop_front(); diff --git a/src/rtsp/factory.rs b/src/rtsp/factory.rs new file mode 100644 index 0000000..338da5c --- /dev/null +++ b/src/rtsp/factory.rs @@ -0,0 +1,408 @@ +use anyhow::{anyhow, Context, Result}; +use gstreamer::{prelude::*, Bin, Caps, Element, ElementFactory, GhostPad}; +use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType}; +use log::*; +use tokio::sync::mpsc::{channel as mpsc, Receiver as MpscReceiver}; + +use crate::{ + common::{AudFormat, StreamConfig, VidFormat}, + rtsp::gst::NeoMediaFactory, + AnyResult, +}; + +pub(super) struct ClientSourceData { + pub(super) app: AppSrc, +} + +pub(super) struct ClientData { + pub(super) vid: Option, + pub(super) aud: Option, +} + +pub(super) async fn make_dummy_factory(use_splash: bool) -> AnyResult { + NeoMediaFactory::new_with_callback(move |element| { + clear_bin(&element)?; + if !use_splash { + Ok(None) + } else { + build_unknown(&element)?; + Ok(Some(element)) + } + }) + .await +} + +pub(super) async fn make_factory( + stream_config: &StreamConfig, +) -> AnyResult<(NeoMediaFactory, MpscReceiver)> { + let (client_tx, client_rx) = mpsc(100); + let factory = { + let stream_config = stream_config.clone(); + + NeoMediaFactory::new_with_callback(move |element| { + clear_bin(&element)?; + let vid = match stream_config.vid_format { + VidFormat::None => { + build_unknown(&element)?; + AnyResult::Ok(None) + } + VidFormat::H264 => { + let app = build_h264(&element, &stream_config)?; + app.set_callbacks( + AppSrcCallbacks::builder() + .seek_data(move |_, _seek_pos| true) + .build(), + ); + AnyResult::Ok(Some(app)) + } + VidFormat::H265 => { + let app = build_h265(&element, &stream_config)?; + + app.set_callbacks( + AppSrcCallbacks::builder() + .seek_data(move |_, _seek_pos| true) + .build(), + ); + AnyResult::Ok(Some(app)) + } + }?; + let aud = if matches!(stream_config.vid_format, VidFormat::None) { + None + } else { + match stream_config.aud_format { + AudFormat::None => AnyResult::Ok(None), + AudFormat::Aac => { + let app = build_aac(&element, &stream_config)?; + app.set_callbacks( + AppSrcCallbacks::builder() + .seek_data(move |_, _seek_pos| true) + .build(), + ); + AnyResult::Ok(Some(app)) + } + AudFormat::Adpcm(block_size) => { + let app = build_adpcm(&element, block_size, &stream_config)?; + app.set_callbacks( + AppSrcCallbacks::builder() + .seek_data(move |_, _seek_pos| true) + .build(), + ); + AnyResult::Ok(Some(app)) + } + }? + }; + + client_tx.blocking_send(ClientData { + vid: vid.map(|app| ClientSourceData { app }), + aud: aud.map(|app| ClientSourceData { app }), + })?; + Ok(Some(element)) + }) + .await + }?; + + Ok((factory, client_rx)) +} + +fn clear_bin(bin: &Element) -> Result<()> { + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + // Clear the autogenerated ones + log::debug!("Clearing old elements"); + for element in bin.iterate_elements().into_iter().flatten() { + bin.remove(&element)?; + } + + Ok(()) +} + +fn build_unknown(bin: &Element) -> Result<()> { + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + log::debug!("Building Unknown Pipeline"); + let source = make_element("videotestsrc", "testvidsrc")?; + source.set_property_from_str("pattern", "snow"); + source.set_property("num-buffers", 500i32); // Send buffers then EOS + let queue = make_queue("queue0", 1024 * 1024 * 4)?; + + let overlay = make_element("textoverlay", "overlay")?; + overlay.set_property("text", "Stream not Ready"); + overlay.set_property_from_str("valignment", "top"); + overlay.set_property_from_str("halignment", "left"); + overlay.set_property("font-desc", "Sans, 16"); + let encoder = make_element("jpegenc", "encoder")?; + let payload = make_element("rtpjpegpay", "pay0")?; + + bin.add_many([&source, &queue, &overlay, &encoder, &payload])?; + source.link_filtered( + &queue, + &Caps::builder("video/x-raw") + .field("format", "YUY2") + .field("width", 896i32) + .field("height", 512i32) + .field("framerate", gstreamer::Fraction::new(25, 1)) + .build(), + )?; + Element::link_many([&queue, &overlay, &encoder, &payload])?; + + Ok(()) +} + +fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result { + let buffer_size = buffer_size(stream_config.bitrate); + log::debug!("buffer_size: {buffer_size}"); + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + log::debug!("Building H264 Pipeline"); + let source = make_element("appsrc", "vidsrc")? + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast to appsrc."))?; + + source.set_is_live(true); + source.set_block(false); + source.set_min_latency(0); + source.set_property("emit-signals", false); + source.set_max_bytes(buffer_size as u64); + source.set_do_timestamp(true); + source.set_stream_type(AppStreamType::Seekable); + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast back"))?; + let queue = make_queue("source_queue", buffer_size)?; + let parser = make_element("h264parse", "parser")?; + parser.set_property("config-interval", -1i32); // Send SPS and PPS every Iframe to imporove joining frame late + let payload = make_element("rtph264pay", "pay0")?; + bin.add_many([&source, &queue, &parser, &payload])?; + Element::link_many([&source, &queue, &parser, &payload])?; + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot convert appsrc"))?; + Ok(source) +} + +fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result { + let buffer_size = buffer_size(stream_config.bitrate); + log::debug!("buffer_size: {buffer_size}"); + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + log::debug!("Building H265 Pipeline"); + let source = make_element("appsrc", "vidsrc")? + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast to appsrc."))?; + source.set_is_live(true); + source.set_block(false); + source.set_min_latency(0); + source.set_property("emit-signals", false); + source.set_max_bytes(buffer_size as u64); + source.set_do_timestamp(true); + source.set_stream_type(AppStreamType::Seekable); + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast back"))?; + let queue = make_queue("source_queue", buffer_size)?; + let parser = make_element("h265parse", "parser")?; + let payload = make_element("rtph265pay", "pay0")?; + bin.add_many([&source, &queue, &parser, &payload])?; + Element::link_many([&source, &queue, &parser, &payload])?; + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot convert appsrc"))?; + Ok(source) +} + +fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result { + let buffer_size = buffer_size(stream_config.bitrate); + log::debug!("buffer_size: {buffer_size}"); + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + log::debug!("Building Aac pipeline"); + let source = make_element("appsrc", "audsrc")? + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast to appsrc."))?; + + source.set_is_live(true); + source.set_block(false); + source.set_min_latency(0); + source.set_property("emit-signals", false); + source.set_max_bytes(buffer_size as u64); + source.set_do_timestamp(true); + source.set_stream_type(AppStreamType::Seekable); + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast back"))?; + + let queue = make_queue("audqueue", buffer_size)?; + let parser = make_element("aacparse", "audparser")?; + let decoder = match make_element("faad", "auddecoder_faad") { + Ok(ele) => Ok(ele), + Err(_) => make_element("avdec_aac", "auddecoder_avdec_aac"), + }?; + let encoder = make_element("audioconvert", "audencoder")?; + let payload = make_element("rtpL16pay", "pay1")?; + + bin.add_many([&source, &queue, &parser, &decoder, &encoder, &payload])?; + Element::link_many([&source, &queue, &parser, &decoder, &encoder, &payload])?; + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot convert appsrc"))?; + Ok(source) +} + +fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result { + let buffer_size = buffer_size(stream_config.bitrate); + log::debug!("buffer_size: {buffer_size}"); + let bin = bin + .clone() + .dynamic_cast::() + .map_err(|_| anyhow!("Media source's element should be a bin"))?; + log::debug!("Building Adpcm pipeline"); + // Original command line + // caps=audio/x-adpcm,layout=dvi,block_align={},channels=1,rate=8000 + // ! queue silent=true max-size-bytes=10485760 min-threshold-bytes=1024 + // ! adpcmdec + // ! audioconvert + // ! rtpL16pay name=pay1 + + let source = make_element("appsrc", "audsrc")? + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast to appsrc."))?; + source.set_is_live(true); + source.set_block(false); + source.set_min_latency(0); + source.set_property("emit-signals", false); + source.set_max_bytes(buffer_size as u64); + source.set_do_timestamp(true); + source.set_stream_type(AppStreamType::Seekable); + + source.set_caps(Some( + &Caps::builder("audio/x-adpcm") + .field("layout", "div") + .field("block_align", block_size as i32) + .field("channels", 1i32) + .field("rate", 8000i32) + .build(), + )); + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot cast back"))?; + + let queue = make_queue("audqueue", buffer_size)?; + let decoder = make_element("decodebin", "auddecoder")?; + let encoder = make_element("audioconvert", "audencoder")?; + let payload = make_element("rtpL16pay", "pay1")?; + + bin.add_many([&source, &queue, &decoder, &encoder, &payload])?; + Element::link_many([&source, &queue, &decoder])?; + Element::link_many([&encoder, &payload])?; + decoder.connect_pad_added(move |_element, pad| { + debug!("Linking encoder to decoder: {:?}", pad.caps()); + let sink_pad = encoder + .static_pad("sink") + .expect("Encoder is missing its pad"); + pad.link(&sink_pad) + .expect("Failed to link ADPCM decoder to encoder"); + }); + + let source = source + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot convert appsrc"))?; + Ok(source) +} + +// Convenice funcion to make an element or provide a message +// about what plugin is missing +fn make_element(kind: &str, name: &str) -> AnyResult { + ElementFactory::make_with_name(kind, Some(name)).with_context(|| { + let plugin = match kind { + "appsrc" => "app (gst-plugins-base)", + "audioconvert" => "audioconvert (gst-plugins-base)", + "adpcmdec" => "Required for audio", + "h264parse" => "videoparsersbad (gst-plugins-bad)", + "h265parse" => "videoparsersbad (gst-plugins-bad)", + "rtph264pay" => "rtp (gst-plugins-good)", + "rtph265pay" => "rtp (gst-plugins-good)", + "rtpjitterbuffer" => "rtp (gst-plugins-good)", + "aacparse" => "audioparsers (gst-plugins-good)", + "rtpL16pay" => "rtp (gst-plugins-good)", + "x264enc" => "x264 (gst-plugins-ugly)", + "x265enc" => "x265 (gst-plugins-bad)", + "avdec_h264" => "libav (gst-libav)", + "avdec_h265" => "libav (gst-libav)", + "videotestsrc" => "videotestsrc (gst-plugins-base)", + "imagefreeze" => "imagefreeze (gst-plugins-good)", + "audiotestsrc" => "audiotestsrc (gst-plugins-base)", + "decodebin" => "playback (gst-plugins-good)", + _ => "Unknown", + }; + format!( + "Missing required gstreamer plugin `{}` for `{}` element", + plugin, kind + ) + }) +} +fn make_queue(name: &str, buffer_size: u32) -> AnyResult { + let queue = make_element("queue", &format!("queue1_{}", name))?; + queue.set_property("max-size-bytes", buffer_size); + queue.set_property("max-size-buffers", 0u32); + queue.set_property("max-size-time", 0u64); + // queue.set_property( + // "max-size-time", + // std::convert::TryInto::::try_into(tokio::time::Duration::from_secs(5).as_nanos()) + // .unwrap_or(0), + // ); + + let queue2 = make_element("queue2", &format!("queue2_{}", name))?; + queue2.set_property("max-size-bytes", buffer_size * 2u32 / 3u32); + queue.set_property("max-size-buffers", 0u32); + queue.set_property("max-size-time", 0u64); + // queue2.set_property( + // "max-size-time", + // std::convert::TryInto::::try_into(tokio::time::Duration::from_secs(5).as_nanos()) + // .unwrap_or(0), + // ); + queue2.set_property("use-buffering", false); + + let bin = gstreamer::Bin::builder().name(name).build(); + bin.add_many([&queue, &queue2])?; + Element::link_many([&queue, &queue2])?; + + let pad = queue + .static_pad("sink") + .expect("Failed to get a static pad from queue."); + let ghost_pad = GhostPad::builder_with_target(&pad).unwrap().build(); + ghost_pad.set_active(true)?; + bin.add_pad(&ghost_pad)?; + + let pad = queue2 + .static_pad("src") + .expect("Failed to get a static pad from queue2."); + let ghost_pad = GhostPad::builder_with_target(&pad).unwrap().build(); + ghost_pad.set_active(true)?; + bin.add_pad(&ghost_pad)?; + + let bin = bin + .dynamic_cast::() + .map_err(|_| anyhow!("Cannot convert bin"))?; + Ok(bin) +} + +fn buffer_size(bitrate: u32) -> u32 { + std::cmp::max(bitrate * 15u32 / 8u32, 4u32 * 1024u32 * 1024u32) +} diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 3543ba1..013ec00 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -53,34 +53,28 @@ // - `"none"`: Resends the last iframe the camera. This does not reencode at all. **Most use cases should use this one as it has the least effort on the cpu and gives what you would expect** // use anyhow::{anyhow, Context, Result}; -use gstreamer::{prelude::*, Bin, Caps, ClockTime, Element, ElementFactory, GhostPad}; -use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType}; use gstreamer_rtsp_server::prelude::*; use log::*; use neolink_core::bc_protocol::StreamKind; use std::collections::{HashMap, HashSet}; use std::sync::Arc; use tokio::{ - sync::{ - broadcast::channel as broadcast, - mpsc::{channel as mpsc, Receiver as MpscReceiver, Sender as MpscSender}, - watch::channel as watch, - }, + sync::watch::channel as watch, task::JoinSet, - time::{interval, sleep, Duration, Instant}, + time::{interval, Duration}, }; use tokio_stream::wrappers::IntervalStream; -use tokio_stream::{wrappers::BroadcastStream, Stream, StreamExt}; +use tokio_stream::StreamExt; use tokio_util::sync::CancellationToken; mod cmdline; +mod factory; mod gst; +mod stream; -use crate::common::{Permit, UseCounter}; -use crate::{ - common::{AudFormat, NeoInstance, NeoReactor, StreamConfig, StreamInstance, VidFormat}, - rtsp::gst::NeoMediaFactory, -}; +use crate::common::{NeoInstance, NeoReactor}; +use factory::*; +use stream::*; use super::config::UserConfig; pub(crate) use cmdline::Opt; @@ -338,16 +332,7 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { }; // Create the dummy factory - let dummy_factory = NeoMediaFactory::new_with_callback(move |element| { - clear_bin(&element)?; - if !use_splash { - Ok(None) - } else { - build_unknown(&element)?; - Ok(Some(element)) - } - }) - .await?; + let dummy_factory = make_dummy_factory(use_splash).await?; dummy_factory.add_permitted_roles(&permitted_users); let mut supported_streams_1 = supported_streams.clone(); let mut supported_streams_2 = supported_streams.clone(); @@ -464,1178 +449,3 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { Ok(()) } - -#[derive(Clone, Debug)] -enum StreamData { - Media { data: Arc>, ts: Duration }, - Seek { ts: Duration, reply: MpscSender<()> }, - Enough { ts: Instant }, - Need { ts: Instant }, -} - -struct ClientSourceData { - app: AppSrc, - msg: MpscReceiver, -} - -struct ClientData { - vid: Option, - aud: Option, -} - -/// This handles the stream itself by creating the factory and pushing messages into it -async fn stream_main( - mut stream_instance: StreamInstance, - camera: NeoInstance, - rtsp: &NeoRtspServer, - users: &HashSet, - paths: &[String], -) -> Result<()> { - let mut camera_config = camera.config().await?.clone(); - let name = camera_config.borrow().name.clone(); - - let mut curr_pause; - loop { - log::debug!("{}: Activating Stream", &name); - stream_instance.activate().await?; - - // Wait for a valid stream format to be detected - log::debug!("{}: Waiting for Valid Stream", &name); - stream_instance - .config - .wait_for(|config| { - log::debug!("{:?}", config); - config.vid_ready() - }) - .await?; - log::debug!("{}: Waiting for Valid Audio", &name); - // After vid give it 1s to look for audio - // Ignore timeout but check err - if let Ok(v) = tokio::time::timeout( - Duration::from_secs(1), - stream_instance.config.wait_for(|config| { - log::debug!("{:?}", config); - config.aud_ready() - }), - ) - .await - { - v?; - } - - curr_pause = camera_config.borrow().pause.clone(); - - let last_stream_config = stream_instance.config.borrow().clone(); - let mut thread_stream_config = stream_instance.config.clone(); - - let mut set = JoinSet::>::new(); - log::debug!("{}: Creating Client Counters", &name); - // Handles the on off of the stream with the client pause - let client_counter = UseCounter::new().await; - let client_count = client_counter.create_deactivated().await?; - - if curr_pause.on_disconnect && curr_pause.on_motion { - log::debug!("{}: Enabling Client&Motion Pause", &name); - // Take over activation - let mut client_activator = stream_instance.activator_handle().await; - client_activator.deactivate().await?; // Start deactivated - stream_instance.deactivate().await?; - // Get client counter - let client_count = client_counter.create_deactivated().await?; - - // Get motion counter - let mut motion = camera.motion().await?; - let delta = Duration::from_secs_f64(curr_pause.motion_timeout); - - let thread_name = name.clone(); - set.spawn(async move { - loop { - // Wait for motion to start - motion.wait_for(|md| matches!(md, crate::common::MdState::Start(_))).await?; - tokio::select! { - v = client_count.aquired_users() => { - v?; - }, - v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { - v?; - // Motion has stopped go back - continue; - } - } - log::debug!("{}: Activating Client&Motion", thread_name); - client_activator.activate().await?; - tokio::select! { - v = client_count.dropped_users() => { - v?; - }, - v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { - v?; - } - } - // Deactivate time - log::debug!("{}: Pausing Client&Motion", thread_name); - client_activator.deactivate().await?; - } - }); - - // Push notfications - let mut pn = camera.push_notifications().await?; - let mut curr_pn = None; - let mut client_activator = stream_instance.activator_handle().await; - client_activator.deactivate().await?; - let thread_name = name.clone(); - set.spawn(async move { - loop { - curr_pn = pn - .wait_for(|pn| pn != &curr_pn && pn.is_some()) - .await? - .clone(); - log::info!("{}: Enabling Push Notification", thread_name); - client_activator.activate().await?; - tokio::select! { - v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => { - v?; - // If another PN during wait then go back to wait more - continue; - } - _ = sleep(Duration::from_secs(30)) => {} - } - log::info!("{}: Pausing Push Notification", thread_name); - client_activator.deactivate().await?; - } - }); - } else if curr_pause.on_disconnect { - log::debug!("{}: Enabling Client Pause", &name); - // Take over activation - let mut client_activator = stream_instance.activator_handle().await; - client_activator.deactivate().await?; - stream_instance.deactivate().await?; - let client_count = client_counter.create_deactivated().await?; - let thread_name = name.clone(); - set.spawn(async move { - loop { - client_count.aquired_users().await?; - log::info!("{}: Activating Client", thread_name); - client_activator.activate().await?; - - client_count.dropped_users().await?; - log::info!("{}: Pausing Client", thread_name); - client_activator.deactivate().await?; - } - }); - } else if curr_pause.on_motion { - // Handles on motion pausing - log::debug!("{}: Activating Motion Pause", &name); - // Take over activation - let mut client_activator = stream_instance.activator_handle().await; - client_activator.deactivate().await?; - stream_instance.deactivate().await?; - - let mut motion = camera.motion().await?; - let delta = Duration::from_secs_f64(curr_pause.motion_timeout); - - let thread_name = name.clone(); - set.spawn(async move { - loop { - motion - .wait_for(|md| matches!(md, crate::common::MdState::Start(_))) - .await?; - log::info!("{}: Enabling Motion", thread_name); - client_activator.activate().await?; - - motion - .wait_for( - |md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta), - ) - .await?; - log::info!("{}: Pausing Motion", thread_name); - client_activator.deactivate().await?; - } - }); - - // Push notfications - let mut pn = camera.push_notifications().await?; - let mut curr_pn = None; - let mut client_activator = stream_instance.activator_handle().await; - client_activator.deactivate().await?; - let thread_name = name.clone(); - set.spawn(async move { - loop { - curr_pn = pn - .wait_for(|pn| pn != &curr_pn && pn.is_some()) - .await? - .clone(); - log::info!("{}: Enabling Push Notification", thread_name); - client_activator.activate().await?; - tokio::select! { - v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => { - v?; - // If another PN during wait then go back to wait more - continue; - } - _ = sleep(Duration::from_secs(30)) => {} - } - log::info!("{}: Pausing Push Notification", thread_name); - client_activator.deactivate().await?; - } - }); - } - - // This thread jsut keeps it active for 5s after an initial start to build the buffer - let mut init_activator = stream_instance.activator_handle().await; - set.spawn(async move { - init_activator.activate().await?; - sleep(Duration::from_secs(5)).await; - init_activator.deactivate().await?; - AnyResult::Ok(()) - }); - - // Task to just report the number of clients for debug purposes - let counter = client_counter.create_deactivated().await?; - let mut cur_count = 0; - let thread_name = name.clone(); - set.spawn(async move { - loop { - cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?; - log::debug!("{thread_name}: Number of rtsp clients: {cur_count}"); - } - }); - - // This runs the actual stream. - // The select will restart if the stream's config updates - log::debug!("{}: Stream Activated", &name); - break tokio::select! { - v = thread_stream_config.wait_for(|new_conf| new_conf != &last_stream_config) => { - let v = v?; - // If stream config changes we reload the stream - log::info!("{}: Stream Configuration Changed. Reloading Streams", &name); - log::trace!(" From {:?} to {:?}", last_stream_config, v.clone()); - continue; - }, - v = camera_config.wait_for(|new_conf| new_conf.pause != curr_pause ) => { - v?; - // If pause config changes restart - log::info!("{}: Pause Configuration Changed. Reloading Streams", &name); - continue; - }, - v = stream_run(&name, &stream_instance, rtsp, &last_stream_config, users, paths, client_count) => v, - }; - } -} - -async fn stream_run( - name: &str, - stream_instance: &StreamInstance, - rtsp: &NeoRtspServer, - stream_config: &StreamConfig, - users: &HashSet, - paths: &[String], - client_count: Permit, -) -> AnyResult<()> { - let vidstream = stream_instance.vid.resubscribe(); - let audstream = stream_instance.aud.resubscribe(); - let vid_history = stream_instance.vid_history.clone(); - let aud_history = stream_instance.aud_history.clone(); - - // Finally ready to create the factory and connect the stream - let mounts = rtsp - .mount_points() - .ok_or(anyhow!("RTSP server lacks mount point"))?; - // Create the factory - let (factory, mut client_rx) = make_factory(stream_config).await?; - - factory.add_permitted_roles(users); - - for path in paths.iter() { - log::debug!("Path: {}", path); - mounts.add_factory(path, factory.clone()); - } - log::info!("{}: Avaliable at {}", name, paths.join(", ")); - - let stream_cancel = CancellationToken::new(); - let drop_guard = stream_cancel.clone().drop_guard(); - let mut set = JoinSet::new(); - // Wait for new media client data to come in from the factory - while let Some(mut client_data) = client_rx.recv().await { - log::trace!("New media"); - // New media created - let (vid, mut vid_seek) = client_data - .vid - .take() - .map_or((None, None), |data| (Some(data.app), Some(data.msg))); - let (aud, mut aud_seek) = client_data - .aud - .take() - .map_or((None, None), |data| (Some(data.app), Some(data.msg))); - - // This is the data that gets sent to gstreamer thread - // It represents the combination of the camera stream and the appsrc seek messages - let (aud_data_tx, aud_data_rx) = broadcast(100); - let (vid_data_tx, vid_data_rx) = broadcast(100); - - // This thread takes the video data from the cam and passed it into the stream - let mut vidstream = BroadcastStream::new(vidstream.resubscribe()); - let thread_vid_data_tx = vid_data_tx.clone(); - let thread_stream_cancel = stream_cancel.clone(); - let thread_vid_history = vid_history.clone(); - set.spawn(async move { - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), - v = async { - // Send Initial - let mut found_key_frame = false; - { - let borrowed = thread_vid_history.borrow(); - let last_ts = borrowed.back().map(|lf| lf.ts); - for data in borrowed.iter() { - if data.keyframe || found_key_frame { - found_key_frame = true; - thread_vid_data_tx.send( - StreamData::Media { - data: data.data.clone(), - ts: last_ts.unwrap() - } - )?; - } - } - } - - // Send new - let mut hold_buffer = vec![]; - let mut last_hold = None; - loop { - let timeout = sleep(Duration::from_millis(1000/25)); - let r = tokio::select!{ - v = vidstream.next() => { - if let Some(data) = v { - if let Ok(data) = data { - if !data.keyframe { - hold_buffer.push(data); - } else { - // Send all held pframes - last_hold = Some(data.clone()); - for held in hold_buffer.drain(..) { - thread_vid_data_tx.send( - StreamData::Media { - data: held.data, - ts: held.ts - } - )?; - } - // Send the new keyframe - thread_vid_data_tx.send( - StreamData::Media { - data: data.data, - ts: data.ts - } - )?; - } - - } - } - AnyResult::Ok(()) - } - _ = timeout, if last_hold.is_some() => { - log::debug!("Send Skip"); - let data = last_hold.clone().unwrap(); - thread_vid_data_tx.send( - StreamData::Media { - data: data.data, - ts: data.ts - } - )?; - AnyResult::Ok(()) - } - }; - if r.is_err() { - break r; - } - }?; - AnyResult::Ok(()) - } => v - }; - log::trace!("Stream Vid Media End {r:?}"); - AnyResult::Ok(()) - }); - - // This thread takes the audio data from the cam and passed it into the stream - let mut audstream = BroadcastStream::new(audstream.resubscribe()); - let thread_stream_cancel = stream_cancel.clone(); - let thread_aud_data_tx = aud_data_tx.clone(); - let thread_aud_history = aud_history.clone(); - set.spawn(async move { - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), - v = async { - // Send Initial - { - let mut found_key_frame = false; - let borrowed = thread_aud_history.borrow(); - let last_ts = borrowed.back().map(|lf| lf.ts); - for data in borrowed.iter() { - if data.keyframe || found_key_frame { - found_key_frame = true; - thread_aud_data_tx.send( - StreamData::Media { - data: data.data.clone(), - ts: last_ts.unwrap() - } - )?; - } - } - } - // Send new - while let Some(data) = audstream.next().await { - if let Ok(data) = data { - thread_aud_data_tx.send( - StreamData::Media { - data: data.data, - ts: data.ts - } - )?; - } - // Ignore broadcast lag errors - } - AnyResult::Ok(()) - } => v, - }; - log::trace!("Stream Aud Media End: {r:?}"); - AnyResult::Ok(()) - }); - - // This thread takes the seek data for the vid and passed it into the stream - let thread_stream_cancel = stream_cancel.clone(); - let thread_vid_history = vid_history.clone(); - set.spawn(async move { - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), - v = async { - if let Some(vid_seek) = vid_seek.as_mut() { - while let Some(data) = vid_seek.recv().await { - let seek_ts = if let StreamData::Seek{ts, ..} = &data { - Some(*ts) - } else { - None - }; - // Send seek - vid_data_tx.send(data)?; - // Send initial buffer - if let Some(_seek_ts) = seek_ts { - // Send Initial - { - let mut found_key_frame = false; - let borrowed = thread_vid_history.borrow(); - let last_ts = borrowed.back().map(|lf| lf.ts); - for data in borrowed.iter() { - if data.keyframe || found_key_frame { - found_key_frame = true; - vid_data_tx.send( - StreamData::Media { - data: data.data.clone(), - ts: last_ts.unwrap() - } - )?; - } - } - } - } - } - } - AnyResult::Ok(()) - } => v, - }; - log::trace!("Stream Vid Seek End: {r:?}"); - r - }); - - // This thread takes the seek data for the aud and passed it into the stream - let thread_stream_cancel = stream_cancel.clone(); - let thread_aud_history = aud_history.clone(); - set.spawn(async move { - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), - v = async { - if let Some(aud_seek) = aud_seek.as_mut() { - while let Some(data) = aud_seek.recv().await { - let seek_ts = if let StreamData::Seek{ts, ..} = &data { - Some(*ts) - } else { - None - }; - aud_data_tx.send(data)?; - // Send initial buffer - if let Some(_seek_ts) = seek_ts { - // Send Initial - { - let mut found_key_frame = false; - let borrowed = thread_aud_history.borrow(); - let last_ts = borrowed.back().map(|lf| lf.ts); - for data in borrowed.iter() { - if data.keyframe || found_key_frame { - found_key_frame = true; - aud_data_tx.send( - StreamData::Media { - data: data.data.clone(), - ts: last_ts.unwrap() - } - )?; - } - } - } - } - } - } - AnyResult::Ok(()) - } => v - }; - log::trace!("Stream Aud Seek End: {r:?}"); - r - }); - - // Handles sending the video data into gstreamer - let thread_stream_cancel = stream_cancel.clone(); - let vid_data_rx = BroadcastStream::new(vid_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged - let thread_vid = vid.clone(); - let mut thread_client_count = client_count.subscribe(); - set.spawn(async move { - thread_client_count.activate().await?; - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => { - AnyResult::Ok(()) - }, - v = handle_data(thread_vid.as_ref(), vid_data_rx) => { - v - }, - }; - drop(thread_client_count); - thread_vid.map(|appsrc| appsrc.end_of_stream()); - log::debug!("Vid Thread End: {:?}", r); - r - }); - - // Handles the audio data into gstreamer - let thread_stream_cancel = stream_cancel.clone(); - let aud_data_rx = BroadcastStream::new(aud_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged - let thread_aud = aud.clone(); - set.spawn(async move { - let r = tokio::select! { - _ = thread_stream_cancel.cancelled() => { - AnyResult::Ok(()) - }, - v = handle_data(thread_aud.as_ref(), aud_data_rx) => { - v - }, - }; - thread_aud.map(|appsrc| appsrc.end_of_stream()); - log::debug!("Aud Thread End: {:?}", r); - r - }); - } - // At this point the factory has been destroyed - // Cancel any remaining threads that are trying to send data - // Although it should be finished already when the appsrcs are dropped - stream_cancel.cancel(); - drop(drop_guard); - while set.join_next().await.is_some() {} - log::trace!("Stream done"); - AnyResult::Ok(()) -} - -async fn make_factory( - stream_config: &StreamConfig, -) -> AnyResult<(NeoMediaFactory, MpscReceiver)> { - let (client_tx, client_rx) = mpsc(100); - let factory = { - let stream_config = stream_config.clone(); - let handle = tokio::runtime::Handle::current(); - NeoMediaFactory::new_with_callback(move |element| { - clear_bin(&element)?; - let (vid_seek_tx, vid_seek_rx) = mpsc(10); - let (aud_seek_tx, aud_seek_rx) = mpsc(10); - let vid_enough_tx = vid_seek_tx.clone(); - let vid_need_tx = vid_seek_tx.clone(); - let need_handle = handle.clone(); - let enough_handle = handle.clone(); - let vid = match stream_config.vid_format { - VidFormat::None => { - build_unknown(&element)?; - AnyResult::Ok(None) - } - VidFormat::H264 => { - let app = build_h264(&element, &stream_config)?; - app.set_callbacks( - AppSrcCallbacks::builder() - .seek_data(move |_, seek_pos| { - log::debug!("seek_pos: {seek_pos:?}"); - let (reply_tx, mut reply_rx) = mpsc(1); - vid_seek_tx - .blocking_send(StreamData::Seek { - ts: Duration::from_micros(seek_pos), - reply: reply_tx, - }) - .is_ok() - && reply_rx.blocking_recv().is_some() - }) - .enough_data(move |_| { - log::debug!("enough_data:"); - let ts = Instant::now(); - let vid_enough_tx = vid_enough_tx.clone(); - // Need and enough are fired when we - // call push_buffer which is inside an - // async context so blocking_send is forbiddon - enough_handle.spawn(async move { - let _ = vid_enough_tx.send(StreamData::Enough { ts }).await; - }); - }) - .need_data(move |_, _| { - log::debug!("need_data:"); - let vid_need_tx = vid_need_tx.clone(); - let ts = Instant::now(); - // Need and enough are fired when we - // call push_buffer which is inside an - // async context so blocking_send is forbiddon - need_handle.spawn(async move { - let _ = vid_need_tx.send(StreamData::Need { ts }).await; - }); - }) - .build(), - ); - AnyResult::Ok(Some(app)) - } - VidFormat::H265 => { - let app = build_h265(&element, &stream_config)?; - - app.set_callbacks( - AppSrcCallbacks::builder() - .seek_data(move |_, seek_pos| { - log::debug!("seek_pos: {seek_pos:?}"); - let (reply_tx, mut reply_rx) = mpsc(1); - vid_seek_tx - .blocking_send(StreamData::Seek { - ts: Duration::from_micros(seek_pos), - reply: reply_tx, - }) - .is_ok() - && reply_rx.blocking_recv().is_some() - }) - .enough_data(move |_| { - log::debug!("enough_data:"); - let vid_enough_tx = vid_enough_tx.clone(); - let ts = Instant::now(); - // Need and enough are fired when we - // call push_buffer which is inside an - // async context so blocking_send is forbiddon - enough_handle.spawn(async move { - vid_enough_tx.send(StreamData::Enough { ts }).await - }); - }) - .need_data(move |_, _| { - log::debug!("need_data:"); - let vid_need_tx = vid_need_tx.clone(); - let ts = Instant::now(); - // Need and enough are fired when we - // call push_buffer which is inside an - // async context so blocking_send is forbiddon - need_handle.spawn(async move { - let _ = vid_need_tx.send(StreamData::Need { ts }).await; - }); - }) - .build(), - ); - AnyResult::Ok(Some(app)) - } - }?; - let aud = if matches!(stream_config.vid_format, VidFormat::None) { - None - } else { - match stream_config.aud_format { - AudFormat::None => AnyResult::Ok(None), - AudFormat::Aac => { - let app = build_aac(&element, &stream_config)?; - app.set_callbacks( - AppSrcCallbacks::builder() - .seek_data(move |_, seek_pos| { - log::trace!("seek_pos: {seek_pos:?}"); - let (reply_tx, mut reply_rx) = mpsc(1); - aud_seek_tx - .blocking_send(StreamData::Seek { - ts: Duration::from_micros(seek_pos), - reply: reply_tx, - }) - .is_ok() - && reply_rx.blocking_recv().is_some() - }) - .build(), - ); - AnyResult::Ok(Some(app)) - } - AudFormat::Adpcm(block_size) => { - let app = build_adpcm(&element, block_size, &stream_config)?; - app.set_callbacks( - AppSrcCallbacks::builder() - .seek_data(move |_, seek_pos| { - log::trace!("seek_pos: {seek_pos:?}"); - let (reply_tx, mut reply_rx) = mpsc(1); - aud_seek_tx - .blocking_send(StreamData::Seek { - ts: Duration::from_micros(seek_pos), - reply: reply_tx, - }) - .is_ok() - && reply_rx.blocking_recv().is_some() - }) - .build(), - ); - AnyResult::Ok(Some(app)) - } - }? - }; - - client_tx.blocking_send(ClientData { - vid: match (vid, vid_seek_rx) { - (Some(app), msg) => Some(ClientSourceData { app, msg }), - _ => None, - }, - aud: match (aud, aud_seek_rx) { - (Some(app), msg) => Some(ClientSourceData { app, msg }), - _ => None, - }, - })?; - Ok(Some(element)) - }) - .await - }?; - - Ok((factory, client_rx)) -} - -async fn handle_data> + Unpin, E>( - app: Option<&AppSrc>, - mut data_rx: T, -) -> Result<()> { - if let Some(app) = app { - let mut start_rt: Option = None; - let mut start_ft: Option = None; - let mut rt: Duration = Duration::ZERO; - let appsrc = app.clone(); - - let (tx, mut rx) = mpsc(150); - let thread_appsrc = appsrc.clone(); - tokio::task::spawn(async move { - while let Some(buf) = rx.recv().await { - log::debug!("Send Frame"); - thread_appsrc - .push_buffer(buf) - .map(|_| ()) - .map_err(|_| anyhow!("Could not push buffer to appsrc"))?; - } - AnyResult::Ok(()) - }); - - let mut last_need: Option = None; - let mut last_enough: Option = None; - while let Some(Ok(data)) = data_rx.next().await { - check_live(app)?; // Stop if appsrc is dropped - // Cache the last runtime - // Check for buffer over full - // for >15s - if let (Some(rlast_enough), Some(rlast_need)) = (last_enough, last_need) { - if rlast_need > rlast_enough { - last_enough = None; - last_need = None; - } - } - if let Some(rlast_enough) = last_enough { - if rlast_enough.elapsed() > Duration::from_secs(15) { - let _ = app.end_of_stream(); - log::debug!( - "Client has not used any stream data for over 15s disconnecting the client" - ); - return Ok(()); - } - } - match data { - StreamData::Seek { ts: _, reply } => { - let _ = reply.send(()).await; - } - StreamData::Media { data, ts: ft_i } => { - log::trace!("Frame recieved with ts: {ft_i:?}"); - // Update rt - if let Some(rt_i) = get_runtime(app) { - log::debug!("Appsrc runtime: {:?}", rt_i); - rt = rt_i; - } - - if start_rt.is_none() { - start_rt = Some(rt); - } - if let Some(i_start_ft) = start_ft { - // Have we gone back in time? - if ft_i < i_start_ft { - start_rt = Some(rt); - start_ft = Some(ft_i); - } - } else { - start_ft = Some(ft_i); - } - let mut ts = (ft_i - start_ft.unwrap()) + start_rt.unwrap(); - - // Sync ft to rt if > 1500ms difference - const MAX_DELTA_T: Duration = Duration::from_millis(200); - let delta_t = if rt > ts { rt - ts } else { ts - rt }; - if delta_t > MAX_DELTA_T { - log::debug!("delta_t > MAX_DELTA_T = {delta_t:?} > {MAX_DELTA_T:?}"); - ts = rt; - start_rt = Some(rt); - start_ft = Some(ft_i); - } - - let buf = { - let mut gst_buf = gstreamer::Buffer::with_size(data.len()).unwrap(); - { - let gst_buf_mut = gst_buf.get_mut().unwrap(); - log::debug!("Setting PTS: {ts:?}, Runtime: {ts:?}"); - let time = ClockTime::from_useconds(ts.as_micros() as u64); - gst_buf_mut.set_dts(time); - gst_buf_mut.set_pts(time); - let mut gst_buf_data = gst_buf_mut.map_writable().unwrap(); - gst_buf_data.copy_from_slice(data.as_slice()); - } - gst_buf - }; - - tx.send(buf).await?; - } - StreamData::Enough { ts: when } => last_enough = Some(when), - StreamData::Need { ts: when } => last_need = Some(when), - } - } - } - Ok(()) -} - -fn check_live(app: &AppSrc) -> Result<()> { - app.pads() - .iter() - .all(|pad| pad.is_linked()) - .then_some(()) - .ok_or(anyhow!("App source is closed")) -} - -fn get_runtime(app: &AppSrc) -> Option { - if let Some(clock) = app.clock() { - if let Some(time) = clock.time() { - log::debug!("time: {time:?}"); - if let Some(base_time) = app.base_time() { - log::debug!("base_time: {base_time:?}"); - let runtime = time.saturating_sub(base_time); - log::debug!("runtime: {runtime:?}"); - return Some(Duration::from_micros(runtime.useconds())); - } - } - } - None -} - -fn clear_bin(bin: &Element) -> Result<()> { - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - // Clear the autogenerated ones - log::debug!("Clearing old elements"); - for element in bin.iterate_elements().into_iter().flatten() { - bin.remove(&element)?; - } - - Ok(()) -} - -fn build_unknown(bin: &Element) -> Result<()> { - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - log::debug!("Building Unknown Pipeline"); - let source = make_element("videotestsrc", "testvidsrc")?; - source.set_property_from_str("pattern", "snow"); - source.set_property("num-buffers", 500i32); // Send buffers then EOS - let queue = make_queue("queue0", 1024 * 1024 * 4)?; - - let overlay = make_element("textoverlay", "overlay")?; - overlay.set_property("text", "Stream not Ready"); - overlay.set_property_from_str("valignment", "top"); - overlay.set_property_from_str("halignment", "left"); - overlay.set_property("font-desc", "Sans, 16"); - let encoder = make_element("jpegenc", "encoder")?; - let payload = make_element("rtpjpegpay", "pay0")?; - - bin.add_many([&source, &queue, &overlay, &encoder, &payload])?; - source.link_filtered( - &queue, - &Caps::builder("video/x-raw") - .field("format", "YUY2") - .field("width", 896i32) - .field("height", 512i32) - .field("framerate", gstreamer::Fraction::new(25, 1)) - .build(), - )?; - Element::link_many([&queue, &overlay, &encoder, &payload])?; - - Ok(()) -} - -fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result { - let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - log::debug!("Building H264 Pipeline"); - let source = make_element("appsrc", "vidsrc")? - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast to appsrc."))?; - - source.set_is_live(true); - source.set_block(false); - source.set_min_latency(0); - source.set_property("emit-signals", false); - source.set_max_bytes(buffer_size as u64); - source.set_do_timestamp(false); - source.set_stream_type(AppStreamType::Seekable); - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast back"))?; - let queue = make_queue("source_queue", buffer_size)?; - let parser = make_element("h264parse", "parser")?; - parser.set_property("config-interval", -1i32); // Send SPS and PPS every Iframe to imporove joining frame late - let payload = make_element("rtph264pay", "pay0")?; - bin.add_many([&source, &queue, &parser, &payload])?; - Element::link_many([&source, &queue, &parser, &payload])?; - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot convert appsrc"))?; - Ok(source) -} - -fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result { - let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - log::debug!("Building H265 Pipeline"); - let source = make_element("appsrc", "vidsrc")? - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast to appsrc."))?; - source.set_is_live(true); - source.set_block(false); - source.set_min_latency(0); - source.set_property("emit-signals", false); - source.set_max_bytes(buffer_size as u64); - source.set_do_timestamp(false); - source.set_stream_type(AppStreamType::Seekable); - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast back"))?; - let queue = make_queue("source_queue", buffer_size)?; - let parser = make_element("h265parse", "parser")?; - let payload = make_element("rtph265pay", "pay0")?; - bin.add_many([&source, &queue, &parser, &payload])?; - Element::link_many([&source, &queue, &parser, &payload])?; - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot convert appsrc"))?; - Ok(source) -} - -fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result { - let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - log::debug!("Building Aac pipeline"); - let source = make_element("appsrc", "audsrc")? - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast to appsrc."))?; - - source.set_is_live(true); - source.set_block(false); - source.set_min_latency(0); - source.set_property("emit-signals", false); - source.set_max_bytes(buffer_size as u64); - source.set_do_timestamp(false); - source.set_stream_type(AppStreamType::Seekable); - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast back"))?; - - let queue = make_queue("audqueue", buffer_size)?; - let parser = make_element("aacparse", "audparser")?; - let decoder = match make_element("faad", "auddecoder_faad") { - Ok(ele) => Ok(ele), - Err(_) => make_element("avdec_aac", "auddecoder_avdec_aac"), - }?; - let encoder = make_element("audioconvert", "audencoder")?; - let payload = make_element("rtpL16pay", "pay1")?; - - bin.add_many([&source, &queue, &parser, &decoder, &encoder, &payload])?; - Element::link_many([&source, &queue, &parser, &decoder, &encoder, &payload])?; - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot convert appsrc"))?; - Ok(source) -} - -fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result { - let buffer_size = buffer_size(stream_config.bitrate); - log::debug!("buffer_size: {buffer_size}"); - let bin = bin - .clone() - .dynamic_cast::() - .map_err(|_| anyhow!("Media source's element should be a bin"))?; - log::debug!("Building Adpcm pipeline"); - // Original command line - // caps=audio/x-adpcm,layout=dvi,block_align={},channels=1,rate=8000 - // ! queue silent=true max-size-bytes=10485760 min-threshold-bytes=1024 - // ! adpcmdec - // ! audioconvert - // ! rtpL16pay name=pay1 - - let source = make_element("appsrc", "audsrc")? - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast to appsrc."))?; - source.set_is_live(true); - source.set_block(false); - source.set_min_latency(0); - source.set_property("emit-signals", false); - source.set_max_bytes(buffer_size as u64); - source.set_do_timestamp(false); - source.set_stream_type(AppStreamType::Seekable); - - source.set_caps(Some( - &Caps::builder("audio/x-adpcm") - .field("layout", "div") - .field("block_align", block_size as i32) - .field("channels", 1i32) - .field("rate", 8000i32) - .build(), - )); - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot cast back"))?; - - let queue = make_queue("audqueue", buffer_size)?; - let decoder = make_element("decodebin", "auddecoder")?; - let encoder = make_element("audioconvert", "audencoder")?; - let payload = make_element("rtpL16pay", "pay1")?; - - bin.add_many([&source, &queue, &decoder, &encoder, &payload])?; - Element::link_many([&source, &queue, &decoder])?; - Element::link_many([&encoder, &payload])?; - decoder.connect_pad_added(move |_element, pad| { - debug!("Linking encoder to decoder: {:?}", pad.caps()); - let sink_pad = encoder - .static_pad("sink") - .expect("Encoder is missing its pad"); - pad.link(&sink_pad) - .expect("Failed to link ADPCM decoder to encoder"); - }); - - let source = source - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot convert appsrc"))?; - Ok(source) -} - -// Convenice funcion to make an element or provide a message -// about what plugin is missing -fn make_element(kind: &str, name: &str) -> AnyResult { - ElementFactory::make_with_name(kind, Some(name)).with_context(|| { - let plugin = match kind { - "appsrc" => "app (gst-plugins-base)", - "audioconvert" => "audioconvert (gst-plugins-base)", - "adpcmdec" => "Required for audio", - "h264parse" => "videoparsersbad (gst-plugins-bad)", - "h265parse" => "videoparsersbad (gst-plugins-bad)", - "rtph264pay" => "rtp (gst-plugins-good)", - "rtph265pay" => "rtp (gst-plugins-good)", - "rtpjitterbuffer" => "rtp (gst-plugins-good)", - "aacparse" => "audioparsers (gst-plugins-good)", - "rtpL16pay" => "rtp (gst-plugins-good)", - "x264enc" => "x264 (gst-plugins-ugly)", - "x265enc" => "x265 (gst-plugins-bad)", - "avdec_h264" => "libav (gst-libav)", - "avdec_h265" => "libav (gst-libav)", - "videotestsrc" => "videotestsrc (gst-plugins-base)", - "imagefreeze" => "imagefreeze (gst-plugins-good)", - "audiotestsrc" => "audiotestsrc (gst-plugins-base)", - "decodebin" => "playback (gst-plugins-good)", - _ => "Unknown", - }; - format!( - "Missing required gstreamer plugin `{}` for `{}` element", - plugin, kind - ) - }) -} -fn make_queue(name: &str, buffer_size: u32) -> AnyResult { - let queue = make_element("queue", &format!("queue1_{}", name))?; - queue.set_property("max-size-bytes", buffer_size); - queue.set_property("max-size-buffers", 0u32); - queue.set_property("max-size-time", 0u64); - // queue.set_property( - // "max-size-time", - // std::convert::TryInto::::try_into(tokio::time::Duration::from_secs(5).as_nanos()) - // .unwrap_or(0), - // ); - - let queue2 = make_element("queue2", &format!("queue2_{}", name))?; - queue2.set_property("max-size-bytes", buffer_size * 2u32 / 3u32); - queue.set_property("max-size-buffers", 0u32); - queue.set_property("max-size-time", 0u64); - // queue2.set_property( - // "max-size-time", - // std::convert::TryInto::::try_into(tokio::time::Duration::from_secs(5).as_nanos()) - // .unwrap_or(0), - // ); - queue2.set_property("use-buffering", false); - - let bin = gstreamer::Bin::builder().name(name).build(); - bin.add_many([&queue, &queue2])?; - Element::link_many([&queue, &queue2])?; - - let pad = queue - .static_pad("sink") - .expect("Failed to get a static pad from queue."); - let ghost_pad = GhostPad::builder_with_target(&pad).unwrap().build(); - ghost_pad.set_active(true)?; - bin.add_pad(&ghost_pad)?; - - let pad = queue2 - .static_pad("src") - .expect("Failed to get a static pad from queue2."); - let ghost_pad = GhostPad::builder_with_target(&pad).unwrap().build(); - ghost_pad.set_active(true)?; - bin.add_pad(&ghost_pad)?; - - let bin = bin - .dynamic_cast::() - .map_err(|_| anyhow!("Cannot convert bin"))?; - Ok(bin) -} - -fn buffer_size(bitrate: u32) -> u32 { - std::cmp::max(bitrate * 15u32 / 8u32, 4u32 * 1024u32 * 1024u32) -} diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs new file mode 100644 index 0000000..c7799fa --- /dev/null +++ b/src/rtsp/stream.rs @@ -0,0 +1,612 @@ +use anyhow::{anyhow, Result}; +use gstreamer::{prelude::*, ClockTime}; +use gstreamer_app::AppSrc; +use gstreamer_rtsp_server::prelude::*; +use std::collections::HashSet; +use tokio::{ + sync::broadcast::channel as broadcast, + task::JoinSet, + time::{sleep, sleep_until, Duration, Instant}, +}; +use tokio_stream::{wrappers::BroadcastStream, Stream, StreamExt}; +use tokio_util::sync::CancellationToken; + +use crate::common::{Permit, StampedData, UseCounter}; +use crate::{ + common::{NeoInstance, StreamConfig, StreamInstance}, + AnyResult, +}; + +use super::{factory::*, gst::NeoRtspServer}; + +/// This handles the stream by activating and deacivating it as required +pub(super) async fn stream_main( + mut stream_instance: StreamInstance, + camera: NeoInstance, + rtsp: &NeoRtspServer, + users: &HashSet, + paths: &[String], +) -> Result<()> { + let mut camera_config = camera.config().await?.clone(); + let name = camera_config.borrow().name.clone(); + + let mut curr_pause; + loop { + log::debug!("{}: Activating Stream", &name); + stream_instance.activate().await?; + + // Wait for a valid stream format to be detected + log::debug!("{}: Waiting for Valid Stream", &name); + stream_instance + .config + .wait_for(|config| { + log::debug!("{:?}", config); + config.vid_ready() + }) + .await?; + log::debug!("{}: Waiting for Valid Audio", &name); + // After vid give it 1s to look for audio + // Ignore timeout but check err + if let Ok(v) = tokio::time::timeout( + Duration::from_secs(1), + stream_instance.config.wait_for(|config| { + log::debug!("{:?}", config); + config.aud_ready() + }), + ) + .await + { + v?; + } + + curr_pause = camera_config.borrow().pause.clone(); + + let last_stream_config = stream_instance.config.borrow().clone(); + let mut thread_stream_config = stream_instance.config.clone(); + + let mut set = JoinSet::>::new(); + log::debug!("{}: Creating Client Counters", &name); + // Handles the on off of the stream with the client pause + let client_counter = UseCounter::new().await; + let client_count = client_counter.create_deactivated().await?; + + if curr_pause.on_disconnect && curr_pause.on_motion { + log::debug!("{}: Enabling Client&Motion Pause", &name); + // Take over activation + let mut client_activator = stream_instance.activator_handle().await; + client_activator.deactivate().await?; // Start deactivated + stream_instance.deactivate().await?; + // Get client counter + let client_count = client_counter.create_deactivated().await?; + + // Get motion counter + let mut motion = camera.motion().await?; + let delta = Duration::from_secs_f64(curr_pause.motion_timeout); + + let thread_name = name.clone(); + set.spawn(async move { + loop { + // Wait for motion to start + motion.wait_for(|md| matches!(md, crate::common::MdState::Start(_))).await?; + tokio::select! { + v = client_count.aquired_users() => { + v?; + }, + v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { + v?; + // Motion has stopped go back + continue; + } + } + log::debug!("{}: Activating Client&Motion", thread_name); + client_activator.activate().await?; + tokio::select! { + v = client_count.dropped_users() => { + v?; + }, + v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { + v?; + } + } + // Deactivate time + log::debug!("{}: Pausing Client&Motion", thread_name); + client_activator.deactivate().await?; + } + }); + + // Push notfications + let mut pn = camera.push_notifications().await?; + let mut curr_pn = None; + let mut client_activator = stream_instance.activator_handle().await; + client_activator.deactivate().await?; + let thread_name = name.clone(); + set.spawn(async move { + loop { + curr_pn = pn + .wait_for(|pn| pn != &curr_pn && pn.is_some()) + .await? + .clone(); + log::info!("{}: Enabling Push Notification", thread_name); + client_activator.activate().await?; + tokio::select! { + v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => { + v?; + // If another PN during wait then go back to wait more + continue; + } + _ = sleep(Duration::from_secs(30)) => {} + } + log::info!("{}: Pausing Push Notification", thread_name); + client_activator.deactivate().await?; + } + }); + } else if curr_pause.on_disconnect { + log::debug!("{}: Enabling Client Pause", &name); + // Take over activation + let mut client_activator = stream_instance.activator_handle().await; + client_activator.deactivate().await?; + stream_instance.deactivate().await?; + let client_count = client_counter.create_deactivated().await?; + let thread_name = name.clone(); + set.spawn(async move { + loop { + client_count.aquired_users().await?; + log::info!("{}: Activating Client", thread_name); + client_activator.activate().await?; + + client_count.dropped_users().await?; + log::info!("{}: Pausing Client", thread_name); + client_activator.deactivate().await?; + } + }); + } else if curr_pause.on_motion { + // Handles on motion pausing + log::debug!("{}: Activating Motion Pause", &name); + // Take over activation + let mut client_activator = stream_instance.activator_handle().await; + client_activator.deactivate().await?; + stream_instance.deactivate().await?; + + let mut motion = camera.motion().await?; + let delta = Duration::from_secs_f64(curr_pause.motion_timeout); + + let thread_name = name.clone(); + set.spawn(async move { + loop { + motion + .wait_for(|md| matches!(md, crate::common::MdState::Start(_))) + .await?; + log::info!("{}: Enabling Motion", thread_name); + client_activator.activate().await?; + + motion + .wait_for( + |md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta), + ) + .await?; + log::info!("{}: Pausing Motion", thread_name); + client_activator.deactivate().await?; + } + }); + + // Push notfications + let mut pn = camera.push_notifications().await?; + let mut curr_pn = None; + let mut client_activator = stream_instance.activator_handle().await; + client_activator.deactivate().await?; + let thread_name = name.clone(); + set.spawn(async move { + loop { + curr_pn = pn + .wait_for(|pn| pn != &curr_pn && pn.is_some()) + .await? + .clone(); + log::info!("{}: Enabling Push Notification", thread_name); + client_activator.activate().await?; + tokio::select! { + v = pn.wait_for(|pn| pn != &curr_pn && pn.is_some()) => { + v?; + // If another PN during wait then go back to wait more + continue; + } + _ = sleep(Duration::from_secs(30)) => {} + } + log::info!("{}: Pausing Push Notification", thread_name); + client_activator.deactivate().await?; + } + }); + } + + // This thread jsut keeps it active for 5s after an initial start to build the buffer + let mut init_activator = stream_instance.activator_handle().await; + set.spawn(async move { + init_activator.activate().await?; + sleep(Duration::from_secs(5)).await; + init_activator.deactivate().await?; + AnyResult::Ok(()) + }); + + // Task to just report the number of clients for debug purposes + let counter = client_counter.create_deactivated().await?; + let mut cur_count = 0; + let thread_name = name.clone(); + set.spawn(async move { + loop { + cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?; + log::debug!("{thread_name}: Number of rtsp clients: {cur_count}"); + } + }); + + // This runs the actual stream. + // The select will restart if the stream's config updates + log::debug!("{}: Stream Activated", &name); + break tokio::select! { + v = thread_stream_config.wait_for(|new_conf| new_conf != &last_stream_config) => { + let v = v?; + // If stream config changes we reload the stream + log::info!("{}: Stream Configuration Changed. Reloading Streams", &name); + log::trace!(" From {:?} to {:?}", last_stream_config, v.clone()); + continue; + }, + v = camera_config.wait_for(|new_conf| new_conf.pause != curr_pause ) => { + v?; + // If pause config changes restart + log::info!("{}: Pause Configuration Changed. Reloading Streams", &name); + continue; + }, + v = stream_run(&name, &stream_instance, rtsp, &last_stream_config, users, paths, client_count) => v, + }; + } +} + +/// This handles the stream itself by creating the factory and pushing messages into it +async fn stream_run( + name: &str, + stream_instance: &StreamInstance, + rtsp: &NeoRtspServer, + stream_config: &StreamConfig, + users: &HashSet, + paths: &[String], + client_count: Permit, +) -> AnyResult<()> { + let vidstream = stream_instance.vid.resubscribe(); + let audstream = stream_instance.aud.resubscribe(); + let vid_history = stream_instance.vid_history.clone(); + let aud_history = stream_instance.aud_history.clone(); + + // Finally ready to create the factory and connect the stream + let mounts = rtsp + .mount_points() + .ok_or(anyhow!("RTSP server lacks mount point"))?; + // Create the factory + let (factory, mut client_rx) = make_factory(stream_config).await?; + + factory.add_permitted_roles(users); + + for path in paths.iter() { + log::debug!("Path: {}", path); + mounts.add_factory(path, factory.clone()); + } + log::info!("{}: Avaliable at {}", name, paths.join(", ")); + + let stream_cancel = CancellationToken::new(); + let drop_guard = stream_cancel.clone().drop_guard(); + let mut set = JoinSet::new(); + // Wait for new media client data to come in from the factory + while let Some(mut client_data) = client_rx.recv().await { + log::debug!("New media"); + // New media created + let vid = client_data.vid.take().map(|data| data.app); + let aud = client_data.aud.take().map(|data| data.app); + + // This is the data that gets sent to gstreamer thread + // It represents the combination of the camera stream and the appsrc seek messages + let (aud_data_tx, aud_data_rx) = broadcast(100); + let (vid_data_tx, vid_data_rx) = broadcast(100); + + // This thread takes the video data from the cam and passed it into the stream + let mut vidstream = BroadcastStream::new(vidstream.resubscribe()); + let thread_vid_data_tx = vid_data_tx.clone(); + let thread_stream_cancel = stream_cancel.clone(); + let thread_vid_history = vid_history.clone(); + set.spawn(async move { + let r = tokio::select! { + _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), + v = async { + // Send Initial + for data in thread_vid_history.borrow().iter() { + thread_vid_data_tx.send( + data.clone() + )?; + } + + // Send new + while let Some(frame) = vidstream.next().await { + if let Ok(data) = frame { + thread_vid_data_tx.send( + data + )?; + } + }; + AnyResult::Ok(()) + } => v, + }; + log::trace!("Stream Vid Media End {r:?}"); + AnyResult::Ok(()) + }); + + // This thread takes the audio data from the cam and passed it into the stream + let mut audstream = BroadcastStream::new(audstream.resubscribe()); + let thread_stream_cancel = stream_cancel.clone(); + let thread_aud_data_tx = aud_data_tx.clone(); + let thread_aud_history = aud_history.clone(); + set.spawn(async move { + let r = tokio::select! { + _ = thread_stream_cancel.cancelled() => AnyResult::Ok(()), + v = async { + // Send Initial + for data in thread_aud_history.borrow().iter() { + thread_aud_data_tx.send( + data.clone() + )?; + } + + // Send new + while let Some(frame) = audstream.next().await { + if let Ok(data) = frame { + thread_aud_data_tx.send( + data + )?; + } + }; + AnyResult::Ok(()) + } => v, + }; + log::trace!("Stream Aud Media End: {r:?}"); + AnyResult::Ok(()) + }); + + // Handles sending the video data into gstreamer + let thread_stream_cancel = stream_cancel.clone(); + let vid_data_rx = BroadcastStream::new(vid_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged + let thread_vid = vid.clone(); + let mut thread_client_count = client_count.subscribe(); + if let Some(thread_vid) = thread_vid { + set.spawn(async move { + thread_client_count.activate().await?; + let r = tokio::select! { + _ = thread_stream_cancel.cancelled() => { + AnyResult::Ok(()) + }, + v = send_to_appsrc( + repeat_keyframe( + frametime_stream( + hold_stream( + wait_for_keyframe( + vid_data_rx, + ) + ) + ), + Duration::from_secs(1) + ), &thread_vid) => { + v + }, + }; + drop(thread_client_count); + let _ = thread_vid.end_of_stream(); + log::debug!("Vid Thread End: {:?}", r); + r + }); + } + + // Handles the audio data into gstreamer + let thread_stream_cancel = stream_cancel.clone(); + let aud_data_rx = BroadcastStream::new(aud_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged + let thread_aud = aud.clone(); + if let Some(thread_aud) = thread_aud { + set.spawn(async move { + let r = tokio::select! { + _ = thread_stream_cancel.cancelled() => { + AnyResult::Ok(()) + }, + v = send_to_appsrc( + frametime_stream( + hold_stream( + wait_for_keyframe( + aud_data_rx + ) + ) + ), &thread_aud) => { + v + }, + }; + let _ = thread_aud.end_of_stream(); + log::debug!("Aud Thread End: {:?}", r); + r + }); + } + } + log::debug!("Cleaning up streams"); + // At this point the factory has been destroyed + // Cancel any remaining threads that are trying to send data + // Although it should be finished already when the appsrcs are dropped + stream_cancel.cancel(); + drop(drop_guard); + while set.join_next().await.is_some() {} + log::trace!("Stream done"); + AnyResult::Ok(()) +} + +fn check_live(app: &AppSrc) -> Result<()> { + // log::debug!("Checking Live: {:?}", app.bus()); + app.bus().map(|_| ()).ok_or(anyhow!("App source is closed")) +} + +fn get_runtime(app: &AppSrc) -> Option { + if let Some(clock) = app.clock() { + if let Some(time) = clock.time() { + // log::debug!("time: {time:?}"); + if let Some(base_time) = app.base_time() { + // log::debug!("base_time: {base_time:?}"); + let runtime = time.saturating_sub(base_time); + // log::debug!("runtime: {runtime:?}"); + return Some(Duration::from_micros(runtime.useconds())); + } + } + } + None +} + +// This ensures we start at a keyframe +fn wait_for_keyframe> + Unpin>( + mut stream: T, +) -> impl Stream> + Unpin { + Box::pin(async_stream::stream! { + let mut found_key = false; + while let Some(frame) = stream.next().await { + if let Ok(frame) = frame { + if frame.keyframe || found_key { + found_key = true; + yield Ok(frame); + } + } + } + }) +} + +// Take a stream of stamped data and release them +// in waves when a new key frame is found +// this ensure that the last frame sent is always an IFrame +fn hold_stream> + Unpin>( + mut stream: T, +) -> impl Stream> + Unpin { + Box::pin(async_stream::stream! { + let mut held_frames = vec![]; + while let Some(frame) = stream.next().await { + if let Ok(frame) = frame { + if frame.keyframe { + // Release + log::debug!("Yielding: {}", held_frames.len()); + for held_frame in held_frames.drain(..) { + yield Ok(held_frame); + } + log::debug!("Yielded"); + yield Ok(frame); + } else { + // Hold + held_frames.push(frame); + } + } + } + }) +} + +// Take a stream of stamped data pause until +// it is time to display it +fn frametime_stream> + Unpin>( + mut stream: T, +) -> impl Stream> + Unpin { + Box::pin(async_stream::stream! { + const MIN_FPS_DELTA: Duration = Duration::from_millis(1000/5); + let mut last_release = Instant::now(); + let mut cached_prev_ts = None; + while let Some(frame) = stream.next().await { + if let Ok(frame) = frame { + let curr_ts = frame.ts; + let mut prev_ts = cached_prev_ts.unwrap_or(curr_ts); + + // Check if we have gone backwards + if curr_ts < prev_ts { + // If we have reset things + prev_ts = curr_ts; + } + + let delta_ts = std::cmp::min(curr_ts - prev_ts, MIN_FPS_DELTA); + log::debug!("curr_ts: {curr_ts:?}, {prev_ts:?} delta_ts: {delta_ts:?}"); + + sleep_until(last_release + delta_ts).await; + last_release = Instant::now(); + cached_prev_ts = Some(curr_ts); + + yield Ok(frame); + } + } + }) +} + +// This will take a stream and if there is a notibable lack of data +// then it will repeat the last keyframe (if there have been no) +// pframes in between +fn repeat_keyframe> + Unpin>( + mut stream: T, + fallback_time: Duration, +) -> impl Stream> + Unpin { + Box::pin(async_stream::stream! { + while let Some(frame) = stream.next().await { + if let Ok(frame) = frame { + if frame.keyframe { + log::debug!("Key Frame"); + let repeater = frame.clone(); + yield Ok(frame); + + // Wait for either timeout or a new frame + loop { + tokio::select!{ + v = stream.next() => { + if let Some(frame) = v { + if let Ok(frame) = frame { + log::debug!("Key Frame: Resume"); + yield Ok(frame); + break; + } + } else { + break; + } + }, + _ = sleep(fallback_time) => { + log::debug!("Inserting Skip Frame"); + yield Ok(repeater.clone()); + } + } + } + } else { + // P frames go through as-is + yield Ok(frame); + } + } + } + }) +} + +/// Takes a stream and sends it to an appsrc +async fn send_to_appsrc> + Unpin>( + mut stream: T, + appsrc: &AppSrc, +) -> AnyResult<()> { + let mut rt = Duration::ZERO; + while let Some(Ok(data)) = stream.next().await { + check_live(appsrc)?; // Stop if appsrc is dropped + if let Some(rt_i) = get_runtime(appsrc) { + rt = rt_i; + } + let buf = { + let mut gst_buf = gstreamer::Buffer::with_size(data.data.len()).unwrap(); + { + let gst_buf_mut = gst_buf.get_mut().unwrap(); + // log::debug!("Setting PTS: {ts:?}, Runtime: {ts:?}"); + let time = ClockTime::from_useconds(rt.as_micros() as u64); + gst_buf_mut.set_dts(time); + gst_buf_mut.set_pts(time); + let mut gst_buf_data = gst_buf_mut.map_writable().unwrap(); + gst_buf_data.copy_from_slice(data.data.as_slice()); + } + gst_buf + }; + + appsrc + .push_buffer(buf) + .map(|_| ()) + .map_err(|_| anyhow!("Could not push buffer to appsrc"))?; + } + Ok(()) +}