Skip to content

Commit c9d19d2

Browse files
authored
Fix all but the last lint (mostly adds PipeWire backend docstrings) (#114)
## Description A kind of follow-up to #107. This fixes all but but one clippy lints (at least for me on Linux with `--all-features`), most of the work was adding basic docs to the pipewire backend The last remaining lint is of unused field in DuplexCallback::resample_config. I assume this is somewhat WIP, also per #29 (same as in #107). ## Type of Change - [x] Documentation update - [x] Code cleanup or refactor ## How Has This Been Tested? Compiles. :) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - ~Wherever possible, I have added tests that prove my fix is effective or that my feature works.~ - [x] New and existing unit tests pass locally with my changes - [x] I have checked my code and corrected any misspellings
2 parents bf23996 + 9be0d1f commit c9d19d2

7 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/audio_buffer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ where
351351
Some(Self { storage })
352352
}
353353

354+
/// Create an audio buffer reference from non-interleaved data. This does *not* copy the data,
355+
/// but creates a view over it, so that it can be accessed as any other audio buffer.
354356
pub fn from_noninterleaved(data: &'a [T], channels: usize) -> Option<Self> {
355357
let buffer_size = data.len() / channels;
356358
let storage = ArrayView2::from_shape((channels, buffer_size), data).ok()?;
@@ -373,6 +375,12 @@ impl<'a, T: 'a> AudioMut<'a, T> {
373375
Some(Self { storage })
374376
}
375377

378+
/// Create an audio buffer mutable reference from interleaved data. This does *not* copy the
379+
/// data, but creates a view over it, so that it can be accessed as any other audio buffer.
380+
///
381+
/// Writes to the resulting buffer directly map to the provided slice, and asking an
382+
/// interleaved view out of the resulting buffer (with [`AudioBufferBase::as_interleaved`])
383+
/// means the same slice is returned.
376384
pub fn from_noninterleaved_mut(data: &'a mut [T], channels: usize) -> Option<Self> {
377385
let buffer_size = data.len() / channels;
378386
let storage = ArrayViewMut2::from_shape((channels, buffer_size), data).ok()?;

src/backends/alsa/stream.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ impl<Callback: 'static + Send> AlsaStream<Callback> {
4949
let mut poll_descriptors = {
5050
let mut buf = vec![rx.as_pollfd()];
5151
let num_descriptors = device.pcm.count();
52-
buf.extend(
53-
std::iter::repeat(libc::pollfd {
52+
buf.extend(std::iter::repeat_n(
53+
libc::pollfd {
5454
fd: 0,
5555
events: 0,
5656
revents: 0,
57-
})
58-
.take(num_descriptors),
59-
);
57+
},
58+
num_descriptors,
59+
));
6060
buf
6161
};
6262
let (hwp, _, io) = device.apply_config(&stream_config)?;
@@ -70,7 +70,7 @@ impl<Callback: 'static + Send> AlsaStream<Callback> {
7070
let stream_config = StreamConfig {
7171
samplerate,
7272
channels: ChannelMap32::default()
73-
.with_indices(std::iter::repeat(1).take(num_channels)),
73+
.with_indices(std::iter::repeat_n(1, num_channels)),
7474
buffer_size_range: (Some(period_size), Some(period_size)),
7575
exclusive: false,
7676
};

src/backends/pipewire/device.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! PipeWire device abstraction.
2+
13
use super::stream::StreamHandle;
24
use crate::backends::pipewire::error::PipewireError;
35
use crate::{
@@ -12,15 +14,21 @@ use std::cell::{Cell, RefCell};
1214
use std::collections::HashMap;
1315
use std::rc::Rc;
1416

17+
/// A device (like a sound card) in PipeWire.
1518
pub struct PipewireDevice {
1619
pub(super) target_node: Option<u32>,
20+
/// Additive flags describing the device (input/output/...)
1721
pub device_type: DeviceType,
22+
/// Serial number of the device node in the PipeWire graph.
1823
pub object_serial: Option<String>,
24+
/// Name to be used for the next created stream.
1925
pub stream_name: Cow<'static, str>,
26+
/// Properties for the next created stream.
2027
pub stream_properties: HashMap<Vec<u8>, Vec<u8>>,
2128
}
2229

2330
impl PipewireDevice {
31+
/// Get PipeWire properties of the PipeWire device node.
2432
pub fn properties(&self) -> Result<Option<Properties>, PipewireError> {
2533
let Some(node_id) = self.target_node else {
2634
return Ok(None);

src/backends/pipewire/driver.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! PipeWire driver abstraction.
2+
13
use super::error::PipewireError;
24
use crate::backends::pipewire::device::PipewireDevice;
35
use crate::backends::pipewire::utils;
@@ -6,6 +8,7 @@ use std::borrow::Cow;
68
use std::collections::HashMap;
79
use std::marker::PhantomData;
810

11+
/// The Interflow PipeWire backend driver.
912
pub struct PipewireDriver {
1013
__init: PhantomData<()>,
1114
}

src/backends/pipewire/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
//! PipeWire errors.
2+
13
use thiserror::Error;
24

5+
/// PipeWire error.
36
#[derive(Debug, Error)]
47
pub enum PipewireError {
8+
/// Error originating in the PipeWire backend.
59
#[error("Pipewire error: {0}")]
610
BackendError(#[from] pipewire::Error),
11+
/// Error creating a pipewire stream (SPA pod serialization problem).
712
#[error("Cannot create Pipewire stream: {0}")]
813
GenError(#[from] libspa::pod::serialize::GenError),
914
}

src/backends/pipewire/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! # PipeWire backend
2+
//!
3+
//! PipeWire is a modern multimedia server for Linux systems, designed to handle both audio and
4+
//! video streams. It provides low-latency performance and advanced routing capabilities while
5+
//! maintaining compatibility with older APIs like ALSA and PulseAudio, making it a flexible and
6+
//! future-oriented backend.
7+
18
pub mod device;
29
pub mod driver;
310
pub mod error;

src/backends/pipewire/stream.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! PipeWire streams.
2+
13
use crate::audio_buffer::{AudioMut, AudioRef};
24
use crate::backends::pipewire::error::PipewireError;
35
use crate::channel_map::Bitset;
@@ -124,6 +126,7 @@ impl<Callback: AudioInputCallback> StreamInner<Callback> {
124126
}
125127
}
126128

129+
/// PipeWire stream handle.
127130
pub struct StreamHandle<Callback> {
128131
commands: rtrb::Producer<StreamCommands<Callback>>,
129132
handle: JoinHandle<Result<(), PipewireError>>,

0 commit comments

Comments
 (0)