pub mod record;
#[cfg(feature = "pipewire")]
mod pw;
#[cfg(feature = "pipewire")]
pub use pw::*;
pub use record::{LoopRecordManager, RecordManager, RecordingMode};
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AudioDevice {
pub id: u32,
pub name: String,
pub device_type: DeviceType,
pub channels: u32,
pub sample_rate: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum DeviceType {
Source,
Sink,
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct CaptureConfig {
pub sample_rate: u32,
pub channels: u32,
pub buffer_frames: u32,
pub device_id: Option<u32>,
}
impl Default for CaptureConfig {
fn default() -> Self {
Self {
sample_rate: 48000,
channels: 2,
buffer_frames: 1024,
device_id: None,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct OutputConfig {
pub sample_rate: u32,
pub channels: u32,
pub buffer_frames: u32,
pub device_id: Option<u32>,
}
impl Default for OutputConfig {
fn default() -> Self {
Self {
sample_rate: 48000,
channels: 2,
buffer_frames: 1024,
device_id: None,
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum CaptureEvent {
DeviceAdded(AudioDevice),
DeviceRemoved {
id: u32,
},
Overflow,
Underrun,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn capture_config_default() {
let cfg = CaptureConfig::default();
assert_eq!(cfg.sample_rate, 48000);
assert_eq!(cfg.channels, 2);
assert_eq!(cfg.buffer_frames, 1024);
assert!(cfg.device_id.is_none());
}
#[test]
fn output_config_default() {
let cfg = OutputConfig::default();
assert_eq!(cfg.sample_rate, 48000);
assert_eq!(cfg.channels, 2);
}
#[test]
fn device_type_equality() {
assert_eq!(DeviceType::Source, DeviceType::Source);
assert_ne!(DeviceType::Source, DeviceType::Sink);
}
#[test]
fn audio_device_serde() {
let dev = AudioDevice {
id: 42,
name: "Built-in Mic".into(),
device_type: DeviceType::Source,
channels: 2,
sample_rate: 48000,
};
let json = serde_json::to_string(&dev).unwrap();
let back: AudioDevice = serde_json::from_str(&json).unwrap();
assert_eq!(back.id, 42);
assert_eq!(back.name, "Built-in Mic");
}
}