Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed the `wasm-beep` and `audioworklet-beep` examples to `webaudio` and `audioworklet`.
- **ALSA**: Update `alsa` dependency to 0.12.
- **Linux**: `realtime` can now promote threads without requiring `realtime-dbus`.
- **PipeWire**: Set `node.rate` property so that `default.clock.allowed-rates` PipeWire config works.

### Deprecated

Expand Down
15 changes: 10 additions & 5 deletions src/host/pipewire/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
stream::{
DefaultDeviceMonitor, PwInitGuard, SUPPORTED_FORMATS, StreamCommand, StreamData,
},
utils::{DEVICE_ICON_NAME, METADATA_NAME, audio, clock, default, node},
utils::{DEVICE_ICON_NAME, METADATA_NAME, audio, clock, default},
},
},
iter::{SupportedInputConfigs, SupportedOutputConfigs},
Expand Down Expand Up @@ -174,7 +174,12 @@ impl Device {

// Group input and output nodes so PipeWire schedules them in the same quantum,
// preventing phase drift between simultaneous input/output streams.
properties.insert("node.group", format!("cpal-{}", std::process::id()));
properties.insert(
*pw::keys::NODE_GROUP,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one! I also prefer to re-use constants. Any chance there's more in src/host/pipewire/utils.rs where we could use some from *pw::keys instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed node module from utils and replaced with pw::keys.

  • METADATA_NAME is exposed in pipewire-sys but not in pipewire.
  • There is pw::keys::DEVICE_ICON but that one exposes icon-name, not icon_name
  • I couldn't find anything other than that.

format!("cpal-{}", std::process::id()),
);

properties.insert(*pw::keys::NODE_RATE, format!("1/{}", config.sample_rate));

if let BufferSize::Fixed(buffer_size) = config.buffer_size {
properties.insert(
Expand Down Expand Up @@ -989,7 +994,7 @@ pub fn init_devices(connect_automatically: Arc<AtomicBool>) -> Option<Vec<Device

let interface_type = match props.get(*pw::keys::DEVICE_API) {
Some("bluez5") => InterfaceType::Bluetooth,
_ => match props.get("device.bus") {
_ => match props.get(*pw::keys::DEVICE_BUS) {
Some("pci") => InterfaceType::Pci,
Some("usb") => InterfaceType::Usb,
Some("firewire") => InterfaceType::FireWire,
Expand All @@ -1008,7 +1013,7 @@ pub fn init_devices(connect_automatically: Arc<AtomicBool>) -> Option<Vec<Device
// "node.rate" = "1/<sample_rate>" — set by the driver, authoritative
// for the hardware clock rate.
let node_rate: Option<SampleRate> = props
.get(node::RATE)
.get(&pw::keys::NODE_RATE)
.and_then(parse_fraction)
.filter(|(_, den)| *den > 0)
.map(|(_, den)| den);
Expand All @@ -1019,7 +1024,7 @@ pub fn init_devices(connect_automatically: Arc<AtomicBool>) -> Option<Vec<Device
Option<FrameCount>,
Option<SampleRate>,
) = props
.get(node::LATENCY)
.get(&pw::keys::NODE_LATENCY)
.and_then(parse_fraction)
.filter(|(num, den)| *num > 0 && *den > 0)
.unzip();
Expand Down
5 changes: 0 additions & 5 deletions src/host/pipewire/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ pub mod clock {
pub const MAX_QUANTUM: &str = "clock.max-quantum";
}

pub mod node {
pub const RATE: &str = "node.rate";
pub const LATENCY: &str = "node.latency";
}

pub mod default {
pub const NAME: &str = "default";
pub const SINK: &str = "default.audio.sink";
Expand Down
Loading