From 80776c65d8a8742c2dfd59fc6f9be4c4c61c720f Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 21 Aug 2024 09:40:58 -0400 Subject: [PATCH 1/2] Write a program that enumerates audio sinks on the device --- Cargo.lock | 171 ++++++++++++++++++ Cargo.toml | 2 +- gm-dash/server/Cargo.toml | 1 + .../server/src/bin/enumerate-audio-sinks.rs | 25 +++ gm-dash/server/src/main.rs | 3 - 5 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 gm-dash/server/src/bin/enumerate-audio-sinks.rs delete mode 100644 gm-dash/server/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 95e3947..c59b960 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,16 @@ dependencies = [ "libc", ] +[[package]] +name = "annotate-snippets" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccaf7e9dfbb6ab22c82e473cd1a8a7bd313c19a5b7e40970f3d89ef5a5c9e81e" +dependencies = [ + "unicode-width", + "yansi-term", +] + [[package]] name = "anstream" version = "0.6.5" @@ -404,6 +414,27 @@ dependencies = [ "rp-pico", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "annotate-snippets", + "bitflags 2.4.1", + "cexpr", + "clang-sys", + "itertools 0.12.0", + "lazy_static", + "lazycell", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.48", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -535,6 +566,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-expr" version = "0.15.5" @@ -596,6 +636,17 @@ dependencies = [ "phf_codegen 0.11.2", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.4.11" @@ -691,6 +742,15 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "cookie" version = "0.17.0" @@ -701,6 +761,15 @@ dependencies = [ "version_check 0.9.4", ] +[[package]] +name = "cookie-factory" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" +dependencies = [ + "futures", +] + [[package]] name = "cool_asserts" version = "2.0.3" @@ -1775,6 +1844,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "gloo-timers" version = "0.2.6" @@ -1808,6 +1883,9 @@ dependencies = [ [[package]] name = "gm-dash" version = "0.1.0" +dependencies = [ + "pipewire", +] [[package]] name = "gobject-sys" @@ -2446,6 +2524,12 @@ dependencies = [ "spin 0.5.2", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "lebe" version = "0.5.2" @@ -2490,12 +2574,50 @@ version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets 0.52.0", +] + [[package]] name = "libm" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libspa" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65f3a4b81b2a2d8c7f300643676202debd1b7c929dbf5c9bb89402ea11d19810" +dependencies = [ + "bitflags 2.4.1", + "cc", + "convert_case", + "cookie-factory", + "libc", + "libspa-sys", + "nix", + "nom", + "system-deps", +] + +[[package]] +name = "libspa-sys" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf0d9716420364790e85cbb9d3ac2c950bde16a7dd36f3209b7dfdfc4a24d01f" +dependencies = [ + "bindgen", + "cc", + "system-deps", +] + [[package]] name = "libsqlite3-sys" version = "0.27.0" @@ -3223,6 +3345,34 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pipewire" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08e645ba5c45109106d56610b3ee60eb13a6f2beb8b74f8dc8186cf261788dda" +dependencies = [ + "anyhow", + "bitflags 2.4.1", + "libc", + "libspa", + "libspa-sys", + "nix", + "once_cell", + "pipewire-sys", + "thiserror", +] + +[[package]] +name = "pipewire-sys" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "849e188f90b1dda88fe2bfe1ad31fe5f158af2c98f80fb5d13726c44f3f01112" +dependencies = [ + "bindgen", + "libspa-sys", + "system-deps", +] + [[package]] name = "pkcs1" version = "0.7.5" @@ -4090,6 +4240,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -4967,6 +5123,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "unicode_categories" version = "0.1.1" @@ -5466,6 +5628,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "yansi-term" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" +dependencies = [ + "winapi", +] + [[package]] name = "zerocopy" version = "0.7.31" diff --git a/Cargo.toml b/Cargo.toml index 292cbf6..96c65e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,5 +30,5 @@ members = [ "sgf", "timezone-testing", "tree", - "visions/server", "gm-dash", + "visions/server", "gm-dash/server", ] diff --git a/gm-dash/server/Cargo.toml b/gm-dash/server/Cargo.toml index dadb985..53a078a 100644 --- a/gm-dash/server/Cargo.toml +++ b/gm-dash/server/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +pipewire = "0.8.0" diff --git a/gm-dash/server/src/bin/enumerate-audio-sinks.rs b/gm-dash/server/src/bin/enumerate-audio-sinks.rs new file mode 100644 index 0000000..7ef8632 --- /dev/null +++ b/gm-dash/server/src/bin/enumerate-audio-sinks.rs @@ -0,0 +1,25 @@ +use pipewire::{context::Context, main_loop::MainLoop}; + +fn main() -> Result<(), Box> { + let mainloop = MainLoop::new(None)?; + let context = Context::new(&mainloop)?; + let core = context.connect(None)?; + let registry = core.get_registry()?; + + let _listener = registry + .add_listener_local() + .global(|global| { + if global.props.and_then(|p| p.get("media.class")) == Some("Audio/Sink"){ + println!( + "\t{:?} {:?}", + global.props.and_then(|p| p.get("node.description")), + global.props.and_then(|p| p.get("media.class")) + ); + } + }) + .register(); + + mainloop.run(); + + Ok(()) +} diff --git a/gm-dash/server/src/main.rs b/gm-dash/server/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/gm-dash/server/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} -- 2.44.1 From 6cae7dbb0ef3929b420a7266dc0c6739c231daa0 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 26 Aug 2024 10:41:17 -0400 Subject: [PATCH 2/2] Set up a basic server with a device listing endpoint --- Cargo.lock | 132 ++++++++++++++++++------------------- gm-dash/server/Cargo.toml | 4 ++ gm-dash/server/src/main.rs | 109 ++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 69 deletions(-) create mode 100644 gm-dash/server/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c59b960..6df3499 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -323,7 +323,7 @@ dependencies = [ "base64ct", "clap", "cool_asserts", - "serde 1.0.193", + "serde 1.0.209", "sha2", "sqlx", "thiserror", @@ -474,7 +474,7 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" dependencies = [ - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -608,7 +608,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", - "serde 1.0.193", + "serde 1.0.209", "wasm-bindgen", "windows-targets 0.48.5", ] @@ -622,7 +622,7 @@ dependencies = [ "chrono", "chrono-tz-build", "phf 0.11.2", - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -723,7 +723,7 @@ version = "0.1.0" dependencies = [ "config-derive", "cool_asserts", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "thiserror", ] @@ -972,7 +972,7 @@ dependencies = [ "libadwaita", "memorycache", "reqwest", - "serde 1.0.193", + "serde 1.0.209", "serde_derive", "serde_json", "tokio", @@ -1041,7 +1041,7 @@ checksum = "2517b0555262aeeda0d107a40ecfbbcf185921180ffb4acf316ebe0887467e26" dependencies = [ "generic-array 0.11.2", "num-traits", - "serde 1.0.193", + "serde 1.0.209", "typenum", ] @@ -1053,7 +1053,7 @@ checksum = "a0b0a86c5d31c93238ff4b694fa31f3acdf67440770dc314c57d90e433914397" dependencies = [ "generic-array 0.14.7", "num-traits", - "serde 1.0.193", + "serde 1.0.209", "typenum", ] @@ -1080,7 +1080,7 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" dependencies = [ - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -1119,7 +1119,7 @@ dependencies = [ "chrono", "chrono-tz", "dimensioned 0.7.0", - "serde 1.0.193", + "serde 1.0.209", "serde_derive", "serde_json", "tempfile", @@ -1274,7 +1274,7 @@ dependencies = [ "mime 0.3.17", "mime_guess 2.0.4", "pretty_env_logger", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "sha2", "tempdir", @@ -1475,7 +1475,7 @@ dependencies = [ "chrono-tz", "dimensioned 0.8.0", "emseries", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "tempfile", ] @@ -1875,7 +1875,7 @@ dependencies = [ "glib-build-tools 0.16.3", "gtk4", "libadwaita", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "tokio", ] @@ -1885,6 +1885,10 @@ name = "gm-dash" version = "0.1.0" dependencies = [ "pipewire", + "serde 1.0.209", + "serde_json", + "tokio", + "warp", ] [[package]] @@ -2097,9 +2101,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -2319,7 +2323,7 @@ name = "ifc" version = "0.1.0" dependencies = [ "chrono", - "serde 1.0.193", + "serde 1.0.209", "thiserror", ] @@ -2731,7 +2735,7 @@ version = "0.1.0" dependencies = [ "chrono", "futures", - "serde 1.0.193", + "serde 1.0.209", "serde_derive", "tokio", ] @@ -2810,13 +2814,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3091,7 +3096,7 @@ dependencies = [ "cool_asserts", "grid", "nary_tree", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "sgf", "thiserror", @@ -3851,7 +3856,7 @@ dependencies = [ "once_cell", "percent-encoding 2.3.1", "pin-project-lite", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "serde_urlencoded", "system-configuration", @@ -4019,15 +4024,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.5", -] - [[package]] name = "rusty-fork" version = "0.3.0" @@ -4154,18 +4150,18 @@ checksum = "34b623917345a631dc9608d5194cc206b3fe6c3554cd1c75b937e55e285254af" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -4174,13 +4170,14 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", + "memchr", "ryu", - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -4189,7 +4186,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -4201,7 +4198,7 @@ dependencies = [ "form_urlencoded", "itoa", "ryu", - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -4212,7 +4209,7 @@ dependencies = [ "cool_asserts", "nary_tree", "nom", - "serde 1.0.193", + "serde 1.0.209", "thiserror", "typeshare", "uuid 0.8.2", @@ -4415,7 +4412,7 @@ dependencies = [ "once_cell", "paste", "percent-encoding 2.3.1", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "sha2", "smallvec", @@ -4454,7 +4451,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "sha2", "sqlx-core", @@ -4497,7 +4494,7 @@ dependencies = [ "percent-encoding 2.3.1", "rand 0.8.5", "rsa", - "serde 1.0.193", + "serde 1.0.209", "sha1", "sha2", "smallvec", @@ -4535,7 +4532,7 @@ dependencies = [ "memchr", "once_cell", "rand 0.8.5", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "sha1", "sha2", @@ -4563,7 +4560,7 @@ dependencies = [ "libsqlite3-sys", "log 0.4.20", "percent-encoding 2.3.1", - "serde 1.0.193", + "serde 1.0.209", "sqlx-core", "tracing", "url 2.5.0", @@ -4755,7 +4752,7 @@ dependencies = [ "deranged", "itoa", "powerfmt", - "serde 1.0.193", + "serde 1.0.209", "time-core", "time-macros", ] @@ -4809,28 +4806,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.39.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.5", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -4860,9 +4856,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util", "log 0.4.20", @@ -4890,7 +4886,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" dependencies = [ - "serde 1.0.193", + "serde 1.0.209", "serde_spanned", "toml_datetime", "toml_edit 0.20.2", @@ -4902,7 +4898,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" dependencies = [ - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -4923,7 +4919,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap", - "serde 1.0.193", + "serde 1.0.209", "serde_spanned", "toml_datetime", "winnow", @@ -4985,14 +4981,14 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ "byteorder", "bytes", "data-encoding", - "http 0.2.11", + "http 1.0.0", "httparse", "log 0.4.20", "rand 0.8.5", @@ -5039,7 +5035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6" dependencies = [ "chrono", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "typeshare-annotation", ] @@ -5207,7 +5203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ "getrandom", - "serde 1.0.193", + "serde 1.0.209", ] [[package]] @@ -5261,7 +5257,7 @@ version = "0.1.0" dependencies = [ "authdb", "http 1.0.0", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "tokio", "warp", @@ -5308,9 +5304,9 @@ dependencies = [ [[package]] name = "warp" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e92e22e03ff1230c03a1a8ee37d2f89cd489e2e541b7550d6afad96faed169" +checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" dependencies = [ "bytes", "futures-channel", @@ -5324,13 +5320,11 @@ dependencies = [ "multer", "percent-encoding 2.3.1", "pin-project", - "rustls-pemfile", "scoped-tls", - "serde 1.0.193", + "serde 1.0.209", "serde_json", "serde_urlencoded", "tokio", - "tokio-stream", "tokio-tungstenite", "tokio-util", "tower-service", diff --git a/gm-dash/server/Cargo.toml b/gm-dash/server/Cargo.toml index 53a078a..f07ad89 100644 --- a/gm-dash/server/Cargo.toml +++ b/gm-dash/server/Cargo.toml @@ -7,3 +7,7 @@ edition = "2021" [dependencies] pipewire = "0.8.0" +serde = { version = "1.0.209", features = ["alloc", "derive"] } +serde_json = "1.0.127" +tokio = { version = "1.39.3", features = ["full"] } +warp = "0.3.7" diff --git a/gm-dash/server/src/main.rs b/gm-dash/server/src/main.rs new file mode 100644 index 0000000..c80aec8 --- /dev/null +++ b/gm-dash/server/src/main.rs @@ -0,0 +1,109 @@ +use pipewire::{context::Context, main_loop::MainLoop}; +use std::{ + net::{Ipv6Addr, SocketAddrV6}, + sync::{Arc, RwLock}, +}; +use tokio::task::spawn_blocking; +use warp::{serve, Filter}; + +struct State_ { + device_list: Vec, +} + +#[derive(Clone)] +struct State { + internal: Arc>, +} + +impl State { + fn new() -> State { + let internal = State_ { + device_list: vec![], + }; + State { + internal: Arc::new(RwLock::new(internal)), + } + } + + fn add_audio(&self, device: String) { + let mut st = self.internal.write().unwrap(); + (*st).device_list.push(device); + } + + fn audio_devices(&self) -> Vec { + let st = self.internal.read().unwrap(); + (*st).device_list.clone() + } +} + +impl Default for State { + fn default() -> State { + State::new() + } +} + +async fn server_main(state: State) { + let localhost: Ipv6Addr = "::1".parse().unwrap(); + let server_addr = SocketAddrV6::new(localhost, 3001, 0, 0); + + let root = warp::path!().map(|| "ok".to_string()); + let list_output_devices = warp::path!("output_devices").map({ + let state = state.clone(); + move || { + let devices = state.audio_devices(); + serde_json::to_string(&devices).unwrap() + } + }); + + let routes = root.or(list_output_devices); + + serve(routes).run(server_addr).await; +} + +fn handle_add_audio_device(state: State, props: &pipewire::spa::utils::dict::DictRef) +{ + if props.get("media.class") == Some("Audio/Sink") { + if let Some(device_name) = props.get("node.description") { + state.add_audio(device_name.to_owned()); + } + } +} + +fn pipewire_loop(state: State) -> Result<(), Box> { + let mainloop = MainLoop::new(None)?; + let context = Context::new(&mainloop)?; + let core = context.connect(None)?; + let registry = core.get_registry()?; + + let _listener = registry + .add_listener_local() + .global({ + let state = state.clone(); + move |global_data| { + if let Some(props) = global_data.props { + handle_add_audio_device(state.clone(), props); + } + } + }) + .register(); + + mainloop.run(); + + Ok(()) +} + +fn pipewire_main(state: State) { + pipewire_loop(state).expect("pipewire should not error"); +} + +#[tokio::main] +async fn main() { + let state = State::default(); + + spawn_blocking({ + let state = state.clone(); + move || pipewire_main(state) + }); + + server_main(state.clone()).await; +} -- 2.44.1