Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/recording/src/feeds/microphone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,31 @@ fn stream_config_with_latency(
let buffer_size_frames = desired_buffer_size_frames(config, device_name);

if let Some(frames) = buffer_size_frames {
stream_config.buffer_size = BufferSize::Fixed(frames);
if uses_pulse_backend(device_name) {
stream_config.buffer_size = BufferSize::Default;
} else {
stream_config.buffer_size = BufferSize::Fixed(frames);
}
}

(stream_config, buffer_size_frames)
}

#[cfg(target_os = "linux")]
fn uses_pulse_backend(device_name: Option<&str>) -> bool {
device_name
.map(|n| {
let lower = n.to_ascii_lowercase();
lower == "default" || lower == "pulse" || lower == "pipewire"
})
.unwrap_or(false)
}

#[cfg(not(target_os = "linux"))]
fn uses_pulse_backend(_device_name: Option<&str>) -> bool {
false
}

fn desired_buffer_size_frames(
config: &SupportedStreamConfig,
device_name: Option<&str>,
Expand Down
16 changes: 16 additions & 0 deletions crates/recording/src/sources/screen_capture/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,14 @@ fn select_system_audio_monitor() -> anyhow::Result<SelectedSystemAudioInput> {
return Ok(selected);
}

if !pactl_available() {
return Err(anyhow!(
"Linux system audio capture needs `pactl` to discover monitor sources, but it was not found on PATH. \
Install it (e.g. `apt install pulseaudio-utils`, `dnf install pulseaudio-utils`, `pacman -S libpulse`) and try again. \
Available cpal input devices: {available:?}."
));
}

Err(anyhow!(
"No PulseAudio/PipeWire monitor input was found for Linux system audio. \
Available input devices: {available:?}. Select a monitor source with --mic, or enable a monitor source in your audio server."
Expand Down Expand Up @@ -1029,6 +1037,14 @@ fn pactl_monitor_rank(name: &str) -> Option<u8> {
}
}

fn pactl_available() -> bool {
Command::new("pactl")
.arg("--version")
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}

fn pactl_default_source() -> Option<String> {
let output = Command::new("pactl")
.arg("get-default-source")
Expand Down