YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(audio): insulate WASAPI capture threads from process priority drop (#4935)
Ezra Ellette8c1a21f44ed2
diff --git a/Cargo.lock b/Cargo.lockindex 5aa416a13..43126d486 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1792,7 +1792,7 @@ dependencies = [[[package]]name = "cpal"version = "0.15.3"-source = "git+https://github.com/screenpipe/cpal.git?rev=c7a610aee5c6037c9c69dc5bf7f2a850da8d8b12#c7a610aee5c6037c9c69dc5bf7f2a850da8d8b12"+source = "git+https://github.com/EzraEllette/cpal.git?rev=93647b9b5de39d6d4fd9f0a8224fbc0921e1e6bd#93647b9b5de39d6d4fd9f0a8224fbc0921e1e6bd"dependencies = ["alsa","cidre 0.15.1 (git+https://github.com/yury/cidre.git?rev=8481f3f0dc7dd39bb5be80d9424bfac0cad3801a)",diff --git a/crates/screenpipe-audio/Cargo.toml b/crates/screenpipe-audio/Cargo.tomlindex 3167dc488..fb255e7f5 100644--- a/crates/screenpipe-audio/Cargo.toml+++ b/crates/screenpipe-audio/Cargo.toml@@ -19,7 +19,7 @@ oasgen = { workspace = true }# Cross-platform audio capture. Tracks screenpipe/cpal main, which carries# the Windows WASAPI AEC and macOS VoiceProcessingIO patches.-cpal = { git = "https://github.com/screenpipe/cpal.git", rev = "c7a610aee5c6037c9c69dc5bf7f2a850da8d8b12" }+cpal = { git = "https://github.com/screenpipe/cpal.git", rev = "e7edfa174466e87a467d1a58e3a4aec233ff8a21" }# Wav encodinghound = { workspace = true }diff --git a/crates/screenpipe-audio/src/core/process_tap/windows.rs b/crates/screenpipe-audio/src/core/process_tap/windows.rsindex 60c60eb22..f7cc63bc5 100644--- a/crates/screenpipe-audio/src/core/process_tap/windows.rs+++ b/crates/screenpipe-audio/src/core/process_tap/windows.rs@@ -54,7 +54,10 @@ use windows::Win32::System::Com::{CoCreateInstance, CoInitializeEx, CoUninitialize, IAgileObject, IAgileObject_Impl, CLSCTX_ALL,COINIT_MULTITHREADED,};-use windows::Win32::System::Threading::{CreateEventW, WaitForSingleObject};+use windows::Win32::System::Threading::{+ CreateEventW, GetCurrentThread, SetThreadPriority, WaitForSingleObject,+ THREAD_PRIORITY_TIME_CRITICAL,+};use crate::core::stream::AudioStreamConfig;use crate::utils::audio::audio_to_mono;@@ -332,6 +335,13 @@ fn run_capture_loop(is_disconnected: Arc<AtomicBool>,label: &str,) {+ // Insulates this capture thread from the process's BELOW_NORMAL priority+ // class (and foreground contention generally) the same way cpal's WASAPI+ // backend does for its own capture threads.+ unsafe {+ let _ = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);+ }+while !is_disconnected.load(Ordering::Relaxed) {let wait = unsafe { WaitForSingleObject(capture.sample_ready.0, CAPTURE_WAIT_MS) };if wait == WAIT_TIMEOUT {