fix #14740: record detected calls from the output device

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-06 10:49:02 +01:00
co-authored by Claude Opus 5.5
parent 1cb1033cbb
commit 5dfe1d9357
12 changed files with 397 additions and 346 deletions
+94 -6
View File
@@ -16,6 +16,7 @@ use std::thread;
use std::time::{Duration, Instant};
use chrono::{DateTime, Local};
use recorder_audio::RenderSession;
use recorder_core::accounts;
use recorder_core::call_view::{self, CallDetail, CallListItem};
use recorder_core::capture::{CaptureSource, OutputTarget};
@@ -255,12 +256,27 @@ impl AppState {
self.start_recording(MANUAL_APP, false, out)
}
/// Starts recording a detected call: the configured mic and the audio
/// of the call app's process tree (or, if that cannot be captured, the
/// default output).
pub fn start_detected_recording(&self, app: &str, root_pid: u32) -> Result<CallId, String> {
let out = recorder_audio::output_source_with_fallback(OutputTarget::Process { root_pid });
self.start_recording(app, true, out)
/// Starts recording a detected call (`app` is its display name, `exe`
/// and `root_pid` identify the call app): the configured mic and the
/// output device the call plays on (see [`detected_output_target`]).
pub fn start_detected_recording(
&self,
app: &str,
exe: &str,
root_pid: u32,
) -> Result<CallId, String> {
let sessions = recorder_audio::render_sessions();
log::info!(
"render sessions: [{}]",
recorder_audio::describe_render_sessions(&sessions)
);
let target = detected_output_target(
self.settings().output_device.as_deref(),
&sessions,
exe,
root_pid,
);
self.start_recording(app, true, recorder_audio::output_source(target))
}
/// Creates a call row and records the configured mic and `out` into
@@ -621,6 +637,37 @@ impl AppState {
}
}
/// The output a detected call is recorded from: the configured output
/// device, else the device on which the call app (`exe`, `root_pid`) has an
/// active render session, else the default communications device. Always
/// device loopback: new Teams plays call audio from a process outside the
/// ms-teams.exe tree, so loopback of that process tree recorded silence.
fn detected_output_target(
output_device: Option<&str>,
sessions: &[RenderSession],
exe: &str,
root_pid: u32,
) -> OutputTarget {
if let Some(id) = output_device {
log::info!("out track: configured output device {id}");
return OutputTarget::Device(id.to_string());
}
match recorder_audio::render_endpoint_for(sessions, exe, root_pid) {
Some(session) => {
log::info!(
"out track: call app playing on {} ({})",
session.device_name,
session.device_id
);
OutputTarget::Device(session.device_id.clone())
}
None => {
log::info!("out track: no render session of {exe} found, using communications default");
OutputTarget::DefaultRender
}
}
}
fn output_target(settings: &Settings) -> OutputTarget {
match &settings.output_device {
Some(id) => OutputTarget::Device(id.clone()),
@@ -1070,4 +1117,45 @@ mod tests {
assert_eq!(f.state.save_settings(valid.clone()), Ok(()));
assert_eq!(f.state.settings(), valid);
}
fn render_session(exe: &str, root_pid: u32, device: &str) -> RenderSession {
RenderSession {
exe: exe.to_string(),
pid: root_pid + 1,
root_pid,
active: true,
device_id: format!("id-{device}"),
device_name: device.to_string(),
}
}
#[test]
fn detected_calls_record_the_device_the_call_app_plays_on() {
let sessions = [
render_session("spotify.exe", 50, "Lautsprecher"),
render_session("ms-teams.exe", 100, "Headset"),
];
assert_eq!(
detected_output_target(None, &sessions, "ms-teams.exe", 100),
OutputTarget::Device("id-Headset".into())
);
}
#[test]
fn detected_calls_without_a_render_session_record_the_default_device() {
let sessions = [render_session("spotify.exe", 50, "Lautsprecher")];
assert_eq!(
detected_output_target(None, &sessions, "ms-teams.exe", 100),
OutputTarget::DefaultRender
);
}
#[test]
fn a_configured_output_device_wins_for_detected_calls() {
let sessions = [render_session("ms-teams.exe", 100, "Headset")];
assert_eq!(
detected_output_target(Some("id-Lautsprecher"), &sessions, "ms-teams.exe", 100),
OutputTarget::Device("id-Lautsprecher".into())
);
}
}