From 0ba7f5beecdf0b0632470b1bba8892c4f903d180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Sun, 9 Nov 2025 15:07:54 +0100 Subject: [PATCH 1/3] Fix repeat_n() clippy lint --- src/backends/alsa/stream.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backends/alsa/stream.rs b/src/backends/alsa/stream.rs index ac649c1..663114d 100644 --- a/src/backends/alsa/stream.rs +++ b/src/backends/alsa/stream.rs @@ -49,14 +49,14 @@ impl AlsaStream { let mut poll_descriptors = { let mut buf = vec![rx.as_pollfd()]; let num_descriptors = device.pcm.count(); - buf.extend( - std::iter::repeat(libc::pollfd { + buf.extend(std::iter::repeat_n( + libc::pollfd { fd: 0, events: 0, revents: 0, - }) - .take(num_descriptors), - ); + }, + num_descriptors, + )); buf }; let (hwp, _, io) = device.apply_config(&stream_config)?; @@ -70,7 +70,7 @@ impl AlsaStream { let stream_config = StreamConfig { samplerate, channels: ChannelMap32::default() - .with_indices(std::iter::repeat(1).take(num_channels)), + .with_indices(std::iter::repeat_n(1, num_channels)), buffer_size_range: (Some(period_size), Some(period_size)), exclusive: false, }; From 0f9805e9d270b6b03a24aaef33504dba4fc10d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Sun, 9 Nov 2025 15:08:07 +0100 Subject: [PATCH 2/3] Add docstrings for 2 non-interleaved methods Tweaked copy&paste from their interleaved counterparts --- src/audio_buffer.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/audio_buffer.rs b/src/audio_buffer.rs index 6872350..3d4031b 100644 --- a/src/audio_buffer.rs +++ b/src/audio_buffer.rs @@ -351,6 +351,8 @@ where Some(Self { storage }) } + /// Create an audio buffer reference from non-interleaved data. This does *not* copy the data, + /// but creates a view over it, so that it can be accessed as any other audio buffer. pub fn from_noninterleaved(data: &'a [T], channels: usize) -> Option { let buffer_size = data.len() / channels; let storage = ArrayView2::from_shape((channels, buffer_size), data).ok()?; @@ -373,6 +375,12 @@ impl<'a, T: 'a> AudioMut<'a, T> { Some(Self { storage }) } + /// Create an audio buffer mutable reference from interleaved data. This does *not* copy the + /// data, but creates a view over it, so that it can be accessed as any other audio buffer. + /// + /// Writes to the resulting buffer directly map to the provided slice, and asking an + /// interleaved view out of the resulting buffer (with [`AudioBufferBase::as_interleaved`]) + /// means the same slice is returned. pub fn from_noninterleaved_mut(data: &'a mut [T], channels: usize) -> Option { let buffer_size = data.len() / channels; let storage = ArrayViewMut2::from_shape((channels, buffer_size), data).ok()?; From 9be0d1f6ac0ce31aaf4331a008d9298162e4b483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Sun, 9 Nov 2025 15:29:01 +0100 Subject: [PATCH 3/3] Add docs for public PipeWire backend items --- src/backends/pipewire/device.rs | 8 ++++++++ src/backends/pipewire/driver.rs | 3 +++ src/backends/pipewire/error.rs | 5 +++++ src/backends/pipewire/mod.rs | 7 +++++++ src/backends/pipewire/stream.rs | 3 +++ 5 files changed, 26 insertions(+) diff --git a/src/backends/pipewire/device.rs b/src/backends/pipewire/device.rs index b8646fb..d9ef53b 100644 --- a/src/backends/pipewire/device.rs +++ b/src/backends/pipewire/device.rs @@ -1,3 +1,5 @@ +//! PipeWire device abstraction. + use super::stream::StreamHandle; use crate::backends::pipewire::error::PipewireError; use crate::{ @@ -12,15 +14,21 @@ use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::rc::Rc; +/// A device (like a sound card) in PipeWire. pub struct PipewireDevice { pub(super) target_node: Option, + /// Additive flags describing the device (input/output/...) pub device_type: DeviceType, + /// Serial number of the device node in the PipeWire graph. pub object_serial: Option, + /// Name to be used for the next created stream. pub stream_name: Cow<'static, str>, + /// Properties for the next created stream. pub stream_properties: HashMap, Vec>, } impl PipewireDevice { + /// Get PipeWire properties of the PipeWire device node. pub fn properties(&self) -> Result, PipewireError> { let Some(node_id) = self.target_node else { return Ok(None); diff --git a/src/backends/pipewire/driver.rs b/src/backends/pipewire/driver.rs index a980420..38f8410 100644 --- a/src/backends/pipewire/driver.rs +++ b/src/backends/pipewire/driver.rs @@ -1,3 +1,5 @@ +//! PipeWire driver abstraction. + use super::error::PipewireError; use crate::backends::pipewire::device::PipewireDevice; use crate::backends::pipewire::utils; @@ -6,6 +8,7 @@ use std::borrow::Cow; use std::collections::HashMap; use std::marker::PhantomData; +/// The Interflow PipeWire backend driver. pub struct PipewireDriver { __init: PhantomData<()>, } diff --git a/src/backends/pipewire/error.rs b/src/backends/pipewire/error.rs index 174ab04..c46c197 100644 --- a/src/backends/pipewire/error.rs +++ b/src/backends/pipewire/error.rs @@ -1,9 +1,14 @@ +//! PipeWire errors. + use thiserror::Error; +/// PipeWire error. #[derive(Debug, Error)] pub enum PipewireError { + /// Error originating in the PipeWire backend. #[error("Pipewire error: {0}")] BackendError(#[from] pipewire::Error), + /// Error creating a pipewire stream (SPA pod serialization problem). #[error("Cannot create Pipewire stream: {0}")] GenError(#[from] libspa::pod::serialize::GenError), } diff --git a/src/backends/pipewire/mod.rs b/src/backends/pipewire/mod.rs index f571420..12d0c5b 100644 --- a/src/backends/pipewire/mod.rs +++ b/src/backends/pipewire/mod.rs @@ -1,3 +1,10 @@ +//! # PipeWire backend +//! +//! PipeWire is a modern multimedia server for Linux systems, designed to handle both audio and +//! video streams. It provides low-latency performance and advanced routing capabilities while +//! maintaining compatibility with older APIs like ALSA and PulseAudio, making it a flexible and +//! future-oriented backend. + pub mod device; pub mod driver; pub mod error; diff --git a/src/backends/pipewire/stream.rs b/src/backends/pipewire/stream.rs index 4fac9f2..37a14bc 100644 --- a/src/backends/pipewire/stream.rs +++ b/src/backends/pipewire/stream.rs @@ -1,3 +1,5 @@ +//! PipeWire streams. + use crate::audio_buffer::{AudioMut, AudioRef}; use crate::backends::pipewire::error::PipewireError; use crate::channel_map::Bitset; @@ -124,6 +126,7 @@ impl StreamInner { } } +/// PipeWire stream handle. pub struct StreamHandle { commands: rtrb::Producer>, handle: JoinHandle>,