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
feat(audio): record Windows communications default output device
Louis Beaumont217e457f09a3
diff --git a/Cargo.lock b/Cargo.lockindex 7009da5e4..fca074851 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -6552,6 +6552,7 @@ dependencies = ["webrtc-vad","which 7.0.3","whisper-rs",+ "windows 0.58.0",][[package]]diff --git a/apps/screenpipe-app-tauri/components/rewind/hooks/use-frame-loading.ts b/apps/screenpipe-app-tauri/components/rewind/hooks/use-frame-loading.tsindex f96702761..95159b4ab 100644--- a/apps/screenpipe-app-tauri/components/rewind/hooks/use-frame-loading.ts+++ b/apps/screenpipe-app-tauri/components/rewind/hooks/use-frame-loading.ts@@ -461,34 +461,44 @@ export function useFrameLoading(opts: {}, [adjacentFrames, debouncedFrame?.filePath, getVideoUrl]);// Update rendered dimensions on resize (needed for TextOverlay positioning)+ // Debounce via rAF to avoid stale intermediate values from rapid+ // ResizeObserver callbacks during layout stabilizationuseEffect(() => {+ let rafId: number | null = null;const updateDimensions = () => {- if (containerRef.current && naturalDimensions) {- const containerRect = containerRef.current.getBoundingClientRect();- const containerAspect = containerRect.width / containerRect.height;- const imageAspect = naturalDimensions.width / naturalDimensions.height;- let renderedWidth: number, renderedHeight: number;- if (containerAspect > imageAspect) {- renderedHeight = containerRect.height;- renderedWidth = containerRect.height * imageAspect;- } else {- renderedWidth = containerRect.width;- renderedHeight = containerRect.width / imageAspect;+ if (rafId !== null) cancelAnimationFrame(rafId);+ rafId = requestAnimationFrame(() => {+ rafId = null;+ if (containerRef.current && naturalDimensions) {+ const containerRect = containerRef.current.getBoundingClientRect();+ const containerAspect = containerRect.width / containerRect.height;+ const imageAspect = naturalDimensions.width / naturalDimensions.height;+ let renderedWidth: number, renderedHeight: number;+ if (containerAspect > imageAspect) {+ renderedHeight = containerRect.height;+ renderedWidth = containerRect.height * imageAspect;+ } else {+ renderedWidth = containerRect.width;+ renderedHeight = containerRect.width / imageAspect;+ }+ setRenderedImageInfo({+ width: renderedWidth,+ height: renderedHeight,+ offsetX: (containerRect.width - renderedWidth) / 2,+ offsetY: (containerRect.height - renderedHeight) / 2,+ });}- setRenderedImageInfo({- width: renderedWidth,- height: renderedHeight,- offsetX: (containerRect.width - renderedWidth) / 2,- offsetY: (containerRect.height - renderedHeight) / 2,- });- }+ });};updateDimensions();const el = containerRef.current;if (!el) return;const observer = new ResizeObserver(updateDimensions);observer.observe(el);- return () => observer.disconnect();+ return () => {+ observer.disconnect();+ if (rafId !== null) cancelAnimationFrame(rafId);+ };}, [naturalDimensions]);return {diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsxindex 9f3963311..32c83bf1d 100644--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx@@ -1375,12 +1375,11 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {currentIndex={currentIndex}onFrameChange={(index) => {pausePlayback();- let snapped = snapToDevice(index);- snapped = snapToApp(snapped);- snapped = snapToFiltered(snapped);- setCurrentIndex(snapped);- if (frames[snapped]) {- setCurrentFrame(frames[snapped]);+ // Use clicked index directly — don't snap, since the+ // user explicitly clicked this specific thumbnail+ setCurrentIndex(index);+ if (frames[index]) {+ setCurrentFrame(frames[index]);}}}fetchNextDayData={fetchNextDayData}diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex d0ca9b68b..92055be54 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -9329,7 +9329,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.2.116"+version = "2.2.123"dependencies = ["anyhow","arboard",@@ -9478,6 +9478,7 @@ dependencies = ["webrtc-vad","which 7.0.3","whisper-rs",+ "windows 0.58.0",][[package]]diff --git a/crates/screenpipe-audio/Cargo.toml b/crates/screenpipe-audio/Cargo.tomlindex 953de966c..fcefc3f39 100644--- a/crates/screenpipe-audio/Cargo.toml+++ b/crates/screenpipe-audio/Cargo.toml@@ -90,6 +90,17 @@ rand = "0.9.0"libpulse-binding = { version = "2.28", optional = true }libpulse-simple-binding = { version = "2.28", optional = true }+# Windows COM API for querying the "Default Communications Device" role.+# MS Teams/Zoom route audio to the eCommunications endpoint, which may+# differ from the multimedia/console default that cpal returns.+[target.'cfg(target_os = "windows")'.dependencies]+windows = { version = "0.58", features = [+ "Win32_Media_Audio",+ "Win32_System_Com",+ "Win32_Devices_FunctionDiscovery",+ "Win32_UI_Shell_PropertiesSystem",+] }+[target.'cfg(all(target_os = "windows", target_arch = "x86_64"))'.dependencies]ort = { version = "=2.0.0-rc.6", features = ["download-binaries",diff --git a/crates/screenpipe-audio/src/audio_manager/device_monitor.rs b/crates/screenpipe-audio/src/audio_manager/device_monitor.rsindex b777a6987..e4c4f4686 100644--- a/crates/screenpipe-audio/src/audio_manager/device_monitor.rs+++ b/crates/screenpipe-audio/src/audio_manager/device_monitor.rs@@ -17,6 +17,9 @@ use crate::{device::device_manager::DeviceManager,};+#[cfg(target_os = "windows")]+use crate::core::device::default_communications_output_device;+/// Check if a device name is a legacy per-display output device name/// (e.g., "Display 1 (output)", "Display 3 (output)") that should be/// migrated to the canonical "System Audio (output)" name.@@ -35,6 +38,9 @@ lazy_static::lazy_static! {struct SystemDefaultTracker {last_input: Option<String>,last_output: Option<String>,+ /// Windows only: the eCommunications default output (e.g. USB headset for Teams/Zoom)+ #[cfg(target_os = "windows")]+ last_communications_output: Option<String>,}impl SystemDefaultTracker {@@ -42,6 +48,8 @@ impl SystemDefaultTracker {Self {last_input: None,last_output: None,+ #[cfg(target_os = "windows")]+ last_communications_output: None,}}@@ -68,6 +76,21 @@ impl SystemDefaultTracker {None}}++ /// Windows: check if the eCommunications default output changed.+ /// Returns Some(name) when the communications device differs from the+ /// multimedia default AND has changed since last check.+ #[cfg(target_os = "windows")]+ fn check_communications_output_changed(&mut self) -> Option<String> {+ let current = default_communications_output_device().map(|d| d.to_string());+ if current != self.last_communications_output {+ let changed = current.clone();+ self.last_communications_output = current;+ changed+ } else {+ None+ }+ }}pub async fn start_device_monitor(@@ -93,6 +116,8 @@ pub async fn start_device_monitor(// Initialize tracker with current defaultslet _ = default_tracker.check_input_changed();let _ = default_tracker.check_output_changed().await;+ #[cfg(target_os = "windows")]+ let _ = default_tracker.check_communications_output_changed();// One-time flag: on first loop iteration, verify running devices match// system defaults. Handles the case where the app restarts while a USB@@ -232,6 +257,33 @@ pub async fn start_device_monitor(}}}++ // Windows: also start the eCommunications output device if it+ // differs from the multimedia default. MS Teams/Zoom route call+ // audio to this endpoint (often a USB headset) while the+ // multimedia default might be a monitor or speakers.+ #[cfg(target_os = "windows")]+ if let Some(comm_device) = default_communications_output_device() {+ let comm_name = comm_device.to_string();+ let current = audio_manager.enabled_devices().await;+ if !current.contains(&comm_name) {+ match audio_manager.start_device(&comm_device).await {+ Ok(()) => {+ info!(+ "[DEVICE_RECOVERY] initial sync: started communications output: {}",+ comm_name+ );+ default_tracker.last_communications_output = Some(comm_name);+ }+ Err(e) => {+ warn!(+ "[DEVICE_RECOVERY] initial sync: failed to start communications output {}: {}",+ comm_name, e+ );+ }+ }+ }+ }}// Check if system default input changed@@ -308,10 +360,17 @@ pub async fn start_device_monitor(// Only stop old output devices if the new one started successfullyif new_started {+ // Don't stop the communications output device during swap+ #[cfg(target_os = "windows")]+ let comm_name = default_tracker.last_communications_output.clone();for device_name in audio_manager.enabled_devices().await.iter() {if *device_name == new_default_output {continue; // don't stop the one we just started}+ #[cfg(target_os = "windows")]+ if comm_name.as_deref() == Some(device_name.as_str()) {+ continue; // don't stop the communications device+ }if let Ok(device) = parse_audio_device(device_name) {if device.device_type == DeviceType::Output {info!(@@ -325,6 +384,46 @@ pub async fn start_device_monitor(}}+ // Windows: check if the eCommunications output device changed.+ // This captures call audio from Teams/Zoom/etc. that routes to+ // the communications endpoint (often a USB headset).+ #[cfg(target_os = "windows")]+ {+ let old_comm = default_tracker.last_communications_output.clone();+ if let Some(new_comm_output) = default_tracker.check_communications_output_changed() {+ info!(+ "[DEVICE_RECOVERY] communications output changed to: {}",+ new_comm_output+ );++ // Stop the previous communications device if it's not the multimedia default+ if let Some(ref old_name) = old_comm {+ if default_tracker.last_output.as_deref() != Some(old_name.as_str()) {+ let _ = audio_manager.stop_device(old_name).await;+ }+ }++ // Start the new communications device+ if let Ok(new_device) = parse_audio_device(&new_comm_output) {+ failed_devices.remove(&new_comm_output);+ match audio_manager.start_device(&new_device).await {+ Ok(()) => {+ info!(+ "[DEVICE_RECOVERY] started new communications output: {}",+ new_comm_output+ );+ }+ Err(e) => {+ warn!(+ "[DEVICE_RECOVERY] failed to start communications output {}: {}",+ new_comm_output, e+ );+ }+ }+ }+ }+ }+// Ensure an input device is actually running.// Handles the case where the input device was lost after a// server restart or device reconnection (e.g. AirPods).diff --git a/crates/screenpipe-audio/src/core/device.rs b/crates/screenpipe-audio/src/core/device.rsindex c72a44f2e..369daaa3b 100644--- a/crates/screenpipe-audio/src/core/device.rs+++ b/crates/screenpipe-audio/src/core/device.rs@@ -574,3 +574,87 @@ pub async fn default_output_device() -> Result<AudioDevice> {Ok(AudioDevice::new(device.name()?, DeviceType::Output))}}++/// Returns the Windows "Default Communications Device" (output) if it differs+/// from the multimedia/console default. MS Teams, Zoom, etc. route call audio+/// to the eCommunications endpoint, which is often a USB headset while the+/// multimedia default is a monitor or speakers.+///+/// Returns `None` if:+/// - Not on Windows+/// - The communications and multimedia defaults are the same device+/// - Any COM/API error occurs (fail-open: don't block startup)+#[cfg(target_os = "windows")]+pub fn default_communications_output_device() -> Option<AudioDevice> {+ match unsafe { windows_com_audio::get_communications_output_name() } {+ Ok(Some(name)) => Some(AudioDevice::new(name, DeviceType::Output)),+ Ok(None) => None,+ Err(e) => {+ tracing::debug!(+ "failed to query Windows communications output device: {}",+ e+ );+ None+ }+ }+}++#[cfg(target_os = "windows")]+mod windows_com_audio {+ use anyhow::{anyhow, Result};++ /// Query the Windows eCommunications default output endpoint.+ /// Returns the friendly name if it differs from the eConsole default,+ /// or None if they are the same device.+ pub unsafe fn get_communications_output_name() -> Result<Option<String>> {+ use windows::Win32::Media::Audio::{+ eCommunications, eConsole, eRender, IMMDeviceEnumerator, MMDeviceEnumerator,+ };+ use windows::Win32::System::Com::{+ CoCreateInstance, CoInitializeEx, CoTaskMemFree, CLSCTX_ALL, COINIT_MULTITHREADED,+ };+ use windows::Win32::Devices::FunctionDiscovery::PKEY_Device_FriendlyName;++ // COM init (idempotent per thread — returns S_FALSE if already initialized)+ let _ = CoInitializeEx(None, COINIT_MULTITHREADED);++ let enumerator: IMMDeviceEnumerator =+ CoCreateInstance(&MMDeviceEnumerator, None, CLSCTX_ALL)?;++ // Get both default endpoints+ let comm = enumerator+ .GetDefaultAudioEndpoint(eRender, eCommunications)+ .map_err(|e| anyhow!("no communications output endpoint: {}", e))?;+ let console = enumerator+ .GetDefaultAudioEndpoint(eRender, eConsole)+ .map_err(|e| anyhow!("no console output endpoint: {}", e))?;++ // Compare endpoint IDs — if identical, the user's communications and+ // multimedia defaults point to the same physical device.+ let comm_id = comm.GetId()?;+ let console_id = console.GetId()?;++ let comm_id_str = comm_id.to_string()?;+ let console_id_str = console_id.to_string()?;++ CoTaskMemFree(Some(comm_id.as_ptr() as _));+ CoTaskMemFree(Some(console_id.as_ptr() as _));++ if comm_id_str == console_id_str {+ return Ok(None); // same device, nothing extra to record+ }++ // They differ — get the friendly name of the communications device+ // STGM_READ = 0+ let store = comm.OpenPropertyStore(0)?;+ let prop = store.GetValue(&PKEY_Device_FriendlyName)?;++ // windows-core 0.58 PROPVARIANT implements Display via BSTR conversion+ let name = prop.to_string();+ if name.is_empty() {+ return Err(anyhow!("device friendly name is empty"));+ }++ Ok(Some(name))+ }+}