Verify recorder identity once and retain original native process handles

This commit is contained in:
NINI
2026-10-07 01:22:46 +09:00
parent 1bb7ca68da
commit 160b595e2f
5 changed files with 28 additions and 18 deletions
+6 -1
View File
@@ -142,7 +142,7 @@ function StartAudio([string]$Name,[int]$Seconds) {
if (Test-Path -LiteralPath $readyPath) { Remove-Item -LiteralPath $readyPath }
$args=@('-NoProfile','-File',(Join-Path $PSScriptRoot 'record-native-audio.ps1'),'-OutputPath',(Join-Path $EvidenceDir "$Name.wav"),'-Seconds',"$Seconds",'-Serial',$Serial)
$process=Start-Process pwsh -ArgumentList ($args | ForEach-Object {'"'+$_+'"'}) -WindowStyle Hidden -RedirectStandardOutput (Join-Path $EvidenceDir "$Name.stdout") -RedirectStandardError (Join-Path $EvidenceDir "$Name.stderr") -PassThru
$recorders.Add(@{name=$Name;process=$process;seconds=$Seconds;startedUtc=[DateTime]::UtcNow})
$recorders.Add(@{name=$Name;process=$process;seconds=$Seconds;nativeProcess=$null;startedUtc=[DateTime]::UtcNow})
$readyPath=Join-Path $EvidenceDir "$Name.wav.ready.json"
$ready=$false
for ($attempt=0; $attempt -lt 120; $attempt++) {
@@ -151,6 +151,11 @@ function StartAudio([string]$Name,[int]$Seconds) {
Start-Sleep -Milliseconds 100
}
Check "audio-ready-$Name" $ready 'Recorder reported actual Recording started before interaction'
$readyRecord=Get-Content -LiteralPath $readyPath -Raw|ConvertFrom-Json
$native=Get-Process -Id $readyRecord.recorderPid -ErrorAction Stop
Check "audio-native-identity-$Name" ($native.ProcessName-eq'scrcpy'-and$native.StartTime.ToUniversalTime()-ge$recorders[-1].startedUtc-and$native.StartTime.ToUniversalTime()-le([DateTime]$readyRecord.readyUtc).ToUniversalTime()) 'Own scrcpy created in this recording window; retain Process object rather than recycled PID lookup'
$native.Handle|Out-Null # Retain this native process handle through its exit, even if Windows reuses its PID.
$recorders[-1].nativeProcess=$native
for ($attempt=0; $attempt -lt 20; $attempt++) {
Adb @('shell','cmd','audio','set-volume','3','15') | Out-Null
$route=Adb @('shell','dumpsys','audio')