nandi/jolt-nativepublic Fork 0
2ab40bf193b6a39bc8d1397cc36d17572bbf59cd
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

mod.rs · 47 lines · 1.2 KBRust Blame HistoryRaw
Lift freeq's AV media plane out of sleek 90f8b89 nandi 19d ago1use crate::traits::HostTrait;
2use device::{init_devices, Class, Device, Devices};
3mod device;
4mod stream;
5mod utils;
6
7#[inline]
8fn pipewire_available() -> bool {
9 let dir = std::env::var("PIPEWIRE_RUNTIME_DIR")
10 .or_else(|_| std::env::var("XDG_RUNTIME_DIR"))
11 .unwrap_or_default();
12 std::path::Path::new(&dir).join("pipewire-0").exists()
13}
14
15#[derive(Debug)]
16pub struct Host(Vec<Device>);
17
18impl Host {
19 pub fn new() -> Result<Self, crate::HostUnavailable> {
20 let devices = init_devices().ok_or(crate::HostUnavailable)?;
21 Ok(Host(devices))
22 }
23}
24
25impl HostTrait for Host {
26 type Devices = Devices;
27 type Device = Device;
28 fn is_available() -> bool {
29 pipewire_available()
30 }
31 fn devices(&self) -> Result<Self::Devices, crate::DevicesError> {
32 Ok(self.0.clone().into_iter())
33 }
34
35 fn default_input_device(&self) -> Option<Self::Device> {
36 self.0
37 .iter()
38 .find(|device| matches!(device.class(), Class::DefaultInput))
39 .cloned()
40 }
41 fn default_output_device(&self) -> Option<Self::Device> {
42 self.0
43 .iter()
44 .find(|device| matches!(device.class(), Class::DefaultOutput))
45 .cloned()
46 }
47}