fix(ios): keep the voice-processing graph up instead of rebuilding it
Build and test / test (macos-latest) (push) Canceled after 0s
Build and test / test (ubuntu-24.04) (push) Canceled after 0s
Build and test / test (windows-latest) (push) Canceled after 0s
Build and test / apple-client (push) Canceled after 0s

Joining voice on the voice-chat preset was unreliable: audio arrived after
several seconds of the route flipping back and forth, sometimes not at all, and
VoiceOver went quiet while it happened. Device logs show why. A graph with
voice processing enabled reports a successful start and is then torn down
within a second, roughly three times in four; every configuration without voice
processing — both microphone presets, and voice chat with processing off — comes
up first time and runs indefinitely.

With voice processing the input and output are one IO unit, and it only stays up
while the input is part of the render chain. The input node carried a tap and no
connection, which leaves it out of that chain. Route the input through a silent
mixer so it is genuinely rendered.

The rest of this is the amplifier rather than the cause, and each part of it
turned one failed start into a storm:

The stall watchdog rebuilt on every missed tick, without bound. That converted a
graph that could not start into endless session reconfiguration, which is what
the user heard and what hid the reason from the log. It now backs off after each
failed attempt and stops after four, logging VC_WATCHDOG exhausted, so a
transient freeze still recovers and a graph that will not start fails visibly.

Nothing waited for a graph to start before judging it dead. Enabling voice
processing rebuilds both halves of the IO, which posts a configuration change
and reads as not running for several hundred milliseconds, so the
configuration-change handler and the watchdog both tore down graphs that were
about to run. A settling window holds them off for two seconds.

A route change forced a full rebuild, and every rebuild moves the route, so one
notification produced the next. Route changes now take the non-forcing path,
which rebuilds a stopped graph and leaves a healthy one alone; the hardware test
it uses reads the input node's format, not AVAudioSession, whose reported rate
and channel count do not settle until after the graph has started.

The input side is built once per session instead of being added when voice is
joined, so joining and leaving voice set a stream id rather than replacing the
graph, and a mono voice-chat apply no longer clears a stereo capsule
configuration it never applied.

Every rebuild now logs its cause, and VC_START/VC_START_CHECK record whether the
graph survived its start. The first-attempt failure is not fixed and is recorded
in PROGRESS.md as a release gate: capture still comes up on a watchdog rebuild
rather than immediately.

The changed logic sits on AVAudioSession and AVAudioEngine, which the net10.0
test project cannot reference, so the behaviour is covered by the existing
source assertions; verification is on device.
This commit is contained in:
2026-09-25 20:56:31 +02:00
parent 1a0ff957ae
commit 01bae734b8
6 changed files with 229 additions and 135 deletions
-36
View File
@@ -1,36 +0,0 @@
namespace VoiceCat.Core;
/// Decides whether a reported audio-route change is a reason to rebuild the audio graph, or the
/// echo of the rebuild that produced it.
///
/// The distinction matters because reconfiguring a session moves the route, and moving the route
/// is reported back as a change. Taking a headset out of the route to force the speaker is
/// reported as a device becoming unavailable, and releasing the speaker is reported as one
/// becoming available: act on either and the rebuild answers its own echo, which is an endless
/// flip between two routes rather than one reconfiguration.
///
/// The rule is that only the hardware carrying audio decides. A graph must be rebuilt when that
/// changes, because the input format changes with it; when the route still matches the one the
/// live graph was built on, there is nothing to rebuild for.
///
/// Platform-agnostic on purpose: the caller supplies whatever stable route identity its OS
/// reports (on iOS, the UIDs of the current route's ports).
public sealed class AudioRouteWatcher
{
private readonly object gate = new();
private string built = "";
/// Records the route a graph has just been built on. Called after the session is configured,
/// so it describes the new route rather than the one it replaced.
public void Built(string signature) { lock (gate) built = signature ?? ""; }
/// Forgets the recorded route, for a session that has been released and has no route left.
public void Reset() { lock (gate) built = ""; }
/// Returns true when the reported route differs from the one the live graph was built on.
/// A graph built before anything was recorded is rebuilt, since nothing is known about it.
public bool ShouldRebuild(string signature)
{
lock (gate) return built.Length == 0 || built != (signature ?? "");
}
}