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:
@@ -213,12 +213,13 @@ pub fn start_manual(app: &AppHandle) -> CmdResult<CallId> {
|
||||
Ok(call_id)
|
||||
}
|
||||
|
||||
/// Starts recording a call that detection found (`app` is its display
|
||||
/// name, `root_pid` the process tree whose audio is the far end).
|
||||
pub fn start_detected(app: &AppHandle, name: &str, root_pid: u32) -> CmdResult<CallId> {
|
||||
/// Starts recording a call that detection found (`name` is its display
|
||||
/// name, `exe` and `root_pid` identify the call app, whose output device
|
||||
/// is recorded).
|
||||
pub fn start_detected(app: &AppHandle, name: &str, exe: &str, root_pid: u32) -> CmdResult<CallId> {
|
||||
let call_id = app
|
||||
.state::<AppState>()
|
||||
.start_detected_recording(name, root_pid)?;
|
||||
.start_detected_recording(name, exe, root_pid)?;
|
||||
on_started(app, call_id);
|
||||
Ok(call_id)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ enum Action {
|
||||
/// Record the detected call.
|
||||
Start {
|
||||
app: String,
|
||||
exe: String,
|
||||
root_pid: u32,
|
||||
},
|
||||
/// A manual recording already covers the call: only keep the detector
|
||||
@@ -67,7 +68,9 @@ enum Action {
|
||||
fn decide(event: Option<DetectorEvent>, manual_recording: bool) -> Action {
|
||||
match event {
|
||||
Some(DetectorEvent::CallStarted { .. }) if manual_recording => Action::Suppress,
|
||||
Some(DetectorEvent::CallStarted { app, root_pid, .. }) => Action::Start { app, root_pid },
|
||||
Some(DetectorEvent::CallStarted { exe, app, root_pid }) => {
|
||||
Action::Start { app, exe, root_pid }
|
||||
}
|
||||
Some(DetectorEvent::CallEnded) => Action::EndDetected,
|
||||
None => Action::Nothing,
|
||||
}
|
||||
@@ -85,14 +88,15 @@ fn poll(app: &AppHandle, last_sessions: &mut String) {
|
||||
}
|
||||
let event = state.detector_tick(Instant::now(), &sessions);
|
||||
if let Some(DetectorEvent::CallStarted { exe, root_pid, .. }) = &event {
|
||||
log::info!("call detected: {exe} (process tree {root_pid})");
|
||||
log::info!("call detected: {exe} (root pid {root_pid})");
|
||||
}
|
||||
match decide(event, state.manual_recording_running()) {
|
||||
Action::Start {
|
||||
app: name,
|
||||
exe,
|
||||
root_pid,
|
||||
} => {
|
||||
if let Err(e) = commands::start_detected(app, &name, root_pid) {
|
||||
if let Err(e) = commands::start_detected(app, &name, &exe, root_pid) {
|
||||
log::error!("recording the detected call failed: {e}");
|
||||
// Otherwise the detector would stay in the call and never
|
||||
// retry; suppressing waits for the app to release the mic.
|
||||
@@ -146,6 +150,7 @@ mod tests {
|
||||
decide(Some(started()), false),
|
||||
Action::Start {
|
||||
app: "Microsoft Teams".into(),
|
||||
exe: "ms-teams.exe".into(),
|
||||
root_pid: 100
|
||||
}
|
||||
);
|
||||
|
||||
@@ -43,6 +43,8 @@ pub fn run() {
|
||||
tauri_plugin_log::Builder::new()
|
||||
.targets(targets)
|
||||
.level(log::LevelFilter::Info)
|
||||
// flacenc logs per-encode statistics at Info.
|
||||
.level_for("flacenc", log::LevelFilter::Warn)
|
||||
.max_file_size(LOG_FILE_SIZE)
|
||||
.rotation_strategy(RotationStrategy::KeepSome(2))
|
||||
.timezone_strategy(TimezoneStrategy::UseLocal)
|
||||
|
||||
+94
-6
@@ -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())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user