#![forbid(unsafe_code)]
use crate::{CaptureError, Select};
use mediaway_common::{AudioFrame, Rational, SampleFormat, StreamInfo};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DesktopAudioSource {
Loopback {
select: Select,
},
ProcessLoopback {
process_id: u32,
tree_scope: ProcessTreeScope,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ProcessTreeScope {
ProcessOnly,
IncludeChildren,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DesktopAudioCaptureConfig {
pub source: DesktopAudioSource,
pub time_base: Rational,
pub sample_format: SampleFormat,
}
impl DesktopAudioCaptureConfig {
#[must_use]
pub const fn loopback(time_base: Rational) -> Self {
Self {
source: DesktopAudioSource::Loopback {
select: Select::Default,
},
time_base,
sample_format: SampleFormat::F32,
}
}
#[must_use]
pub const fn process_loopback(
process_id: u32,
tree_scope: ProcessTreeScope,
time_base: Rational,
) -> Self {
Self {
source: DesktopAudioSource::ProcessLoopback {
process_id,
tree_scope,
},
time_base,
sample_format: SampleFormat::F32,
}
}
}
pub trait DesktopAudioCapture {
fn stream_info(&self) -> &StreamInfo;
fn poll_frame(&mut self) -> Result<Option<AudioFrame>, CaptureError>;
fn close(&mut self) -> Result<(), CaptureError>;
}