Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ alsa = "0.6"
libc = "0.2"
parking_lot = "0.12"
jack = { version = "0.10", optional = true }
intmap = "2.0"
pipewire = { git = "https://gitlab.freedesktop.org/pipewire/pipewire-rs", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
Expand Down
41 changes: 38 additions & 3 deletions examples/beep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ struct Opt {
#[arg(short, long)]
#[allow(dead_code)]
jack: bool,
/// Use the Pipewire host
#[cfg(all(
any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
),
feature = "pipewire"
))]
#[allow(dead_code)]
pipewire: bool,
}

fn main() -> anyhow::Result<()> {
let opt = Opt::parse();

// Conditionally compile with jack if the feature is specified.
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features jack -- --jack
#[cfg(all(
any(
target_os = "linux",
Expand All @@ -40,8 +54,6 @@ fn main() -> anyhow::Result<()> {
),
feature = "jack"
))]
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features jack -- --jack
let host = if opt.jack {
cpal::host_from_id(cpal::available_hosts()
.into_iter()
Expand All @@ -53,14 +65,37 @@ fn main() -> anyhow::Result<()> {
cpal::default_host()
};

// Conditionally compile with PipeWire if the feature is specified.
#[cfg(all(
any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
),
feature = "pipewire"
))]
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features pipewire -- --pipewire
let host = if opt.pipewire {
cpal::host_from_id(cpal::available_hosts()
.into_iter()
.find(|id| *id == cpal::HostId::PipeWire)
.expect(
"make sure --features pipewire is specified. only works on OSes where PipeWire is available",
)).expect("PipeWire host unavailable")
} else {
cpal::default_host()
};

#[cfg(any(
not(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
)),
not(feature = "jack")
not(any(feature = "jack", feature = "pipewire"))
))]
let host = cpal::default_host();

Expand Down
5 changes: 5 additions & 0 deletions src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub(crate) mod jack;
pub(crate) mod null;
#[cfg(target_os = "android")]
pub(crate) mod oboe;
#[cfg(all(
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
feature = "pipewire"
))]
pub(crate) mod pipewire;
#[cfg(windows)]
pub(crate) mod wasapi;
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
Expand Down
Loading