chore #14740: capture diagnostics logging

Add diagnostic logging (no behaviour change) to distinguish, from one
instrumented Windows test call, whether an auto-detected call records
nothing because the wrong process tree was targeted, packets arrive but
are flagged silent, or process loopback failed to start and the fallback
hit the wrong device:

- Log one line on every successful WASAPI stream open (initial and
  reopen): endpoint description (process tree pid + exe name for
  loopback, friendly name/id/role for device endpoints), rate and
  channels.
- output_source_with_fallback: Info line when the primary target starts
  OK; the existing fallback Warn line now also names DefaultRender
  explicitly.
- New CaptureStats (crates/audio/src/stats.rs), shared by the Windows
  and Linux capture loops: counts packets, frames, packets flagged
  silent, and the peak absolute sample value, reported every 10 s and
  once more when a stream stops. Plain counters updated inline on the
  audio thread; no locks, no extra threads.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-05 16:27:38 +01:00
co-authored by Claude Sonnet 5
parent c3254c3da0
commit 1420e56e77
6 changed files with 224 additions and 21 deletions
+9
View File
@@ -7,6 +7,7 @@
//! back to that monitor as well.
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Instant;
use libpulse_binding::def::BufferAttr;
use libpulse_binding::error::{Code, PAErr};
@@ -18,6 +19,7 @@ use recorder_core::capture::{
};
use crate::capture_thread::{CaptureThread, Ready};
use crate::stats::CaptureStats;
const APP_NAME: &str = "Gesprächsrekorder";
const DEFAULT_MONITOR: &str = "@DEFAULT_MONITOR@";
@@ -144,17 +146,24 @@ fn run(
let mut bytes = vec![0u8; CHUNK_BYTES];
let mut samples = vec![0f32; CHUNK_SAMPLES];
let mut stats = CaptureStats::new(Instant::now());
while !stop.load(Ordering::SeqCst) {
if let Err(err) = simple.read(&mut bytes) {
// Source gone (unplugged, server restart): stop delivering and
// report it; the recorder keeps the track aligned with silence.
log::warn!("PulseAudio capture '{stream_name}' ended: {err}");
stats.report_final(stream_name);
return Err(format!("PulseAudio: {err}"));
}
for (sample, raw) in samples.iter_mut().zip(bytes.as_chunks::<4>().0) {
*sample = f32::from_ne_bytes(*raw);
}
// PulseAudio reports no silence flag; every packet counts as not
// silent, which matches the actual samples just decoded above.
stats.record(CHUNK_SAMPLES, false, &samples);
stats.maybe_report(stream_name, Instant::now());
on_data(&samples);
}
stats.report_final(stream_name);
Ok(())
}