32 lines
1.1 KiB
Rust
32 lines
1.1 KiB
Rust
use std::sync::mpsc::{Sender, Receiver};
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AudioError {
|
|
#[error("Failed to initialize audio backend: {0}")]
|
|
Init(String),
|
|
#[error("Audio device error: {0}")]
|
|
Device(String),
|
|
#[error("Stream error: {0}")]
|
|
Stream(String),
|
|
#[error("Audio buffer overflow/underflow")]
|
|
BufferError,
|
|
#[error("Other audio error: {0}")]
|
|
Other(String),
|
|
}
|
|
|
|
pub trait AudioBackend: Send + Sync {
|
|
/// Starts capturing raw PCM audio from the input device (microphone),
|
|
/// sending chunks of samples (e.g. `Vec<i16>`) to the provided Sender.
|
|
fn start_capture(&self, tx: Sender<Vec<i16>>, target_node: Option<String>) -> Result<(), AudioError>;
|
|
|
|
/// Starts playing back raw PCM audio to the output device (speaker),
|
|
/// reading mixed/incoming chunks of samples from the provided Receiver.
|
|
fn start_playback(&self, rx: Receiver<Vec<i16>>, target_node: Option<String>) -> Result<(), AudioError>;
|
|
|
|
/// Stops both capture and playback streams.
|
|
fn stop(&self) -> Result<(), AudioError>;
|
|
}
|
|
|
|
pub mod pipewire_impl;
|