fix #14740: attribute teams helper processes, queue end-of-call prompts
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,23 +5,25 @@
|
||||
//! process (`IAudioSessionControl2::GetProcessId`) and is active while one
|
||||
//! of its streams runs, i.e. while the app actually records the mic. The
|
||||
//! process's exe comes from `QueryFullProcessImageNameW`; its `root_pid` is
|
||||
//! the top of its same-exe parent chain in a ToolHelp snapshot (see
|
||||
//! [`crate::process_tree`]), which is the tree application loopback records.
|
||||
//! the top of its same-exe parent chain in a ToolHelp snapshot, which is the
|
||||
//! tree application loopback records. Teams helper processes are reported
|
||||
//! as their Teams ancestor (see [`crate::process_tree`]).
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use recorder_core::detect::MicSession;
|
||||
use wasapi::{deinitialize, initialize_mta, DeviceEnumerator, Direction, SessionState};
|
||||
use windows::core::PWSTR;
|
||||
use windows::Win32::Foundation::{CloseHandle, HANDLE};
|
||||
use windows::Win32::Foundation::{CloseHandle, FILETIME, HANDLE};
|
||||
use windows::Win32::System::Diagnostics::ToolHelp::{
|
||||
CreateToolhelp32Snapshot, Process32FirstW, Process32NextW, PROCESSENTRY32W, TH32CS_SNAPPROCESS,
|
||||
};
|
||||
use windows::Win32::System::Threading::{
|
||||
OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32, PROCESS_QUERY_LIMITED_INFORMATION,
|
||||
GetProcessTimes, OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,
|
||||
PROCESS_QUERY_LIMITED_INFORMATION,
|
||||
};
|
||||
|
||||
use crate::process_tree::{root_pid, ProcessTable};
|
||||
use crate::process_tree::{attribute, ProcessTable};
|
||||
|
||||
/// Sessions on every active capture endpoint, one entry per session.
|
||||
///
|
||||
@@ -52,10 +54,11 @@ fn enumerate() -> Vec<MicSession> {
|
||||
raw.into_iter()
|
||||
.filter_map(|(pid, active)| {
|
||||
let exe = image_name(pid)?;
|
||||
let (exe, root_pid) = attribute(&table, pid, &exe, creation_time);
|
||||
Some(MicSession {
|
||||
exe,
|
||||
pid,
|
||||
root_pid: root_pid(&table, pid),
|
||||
root_pid,
|
||||
active,
|
||||
})
|
||||
})
|
||||
@@ -121,6 +124,26 @@ fn image_name(pid: u32) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// When `pid` was created (FILETIME ticks), or `None` if the process cannot
|
||||
/// be opened.
|
||||
fn creation_time(pid: u32) -> Option<u64> {
|
||||
// SAFETY: plain Win32 calls; the handle is closed below and the
|
||||
// FILETIMEs outlive the call that fills them.
|
||||
unsafe {
|
||||
let handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid).ok()?;
|
||||
let (mut created, mut exited, mut kernel, mut user) = (
|
||||
FILETIME::default(),
|
||||
FILETIME::default(),
|
||||
FILETIME::default(),
|
||||
FILETIME::default(),
|
||||
);
|
||||
let result = GetProcessTimes(handle, &mut created, &mut exited, &mut kernel, &mut user);
|
||||
close(handle);
|
||||
result.ok()?;
|
||||
Some((u64::from(created.dwHighDateTime) << 32) | u64::from(created.dwLowDateTime))
|
||||
}
|
||||
}
|
||||
|
||||
/// pid -> (parent pid, exe) of every process, from one ToolHelp snapshot.
|
||||
/// Empty if the snapshot fails, which makes every session its own root.
|
||||
fn process_table() -> ProcessTable {
|
||||
|
||||
Reference in New Issue
Block a user