Files
client/docs/evidence/appaudio-bridge.md
T
omar ceecbb790a docs: record source parity evidence and remaining acceptance gaps
Document accumulated interoperability findings and current source-backed design. Record build-specific visual results, matched acceleration policy, passing packaged behavior checks, and explicit native/ARM and strict visual acceptance limits. No complete 1:1 claim.
2026-11-01 19:47:52 +03:00

7.5 KiB
Raw Blame History

Selected-application audio bridge

The bridge uses the existing resolved teamspeach-core executable, never a renderer-provided executable, command line or PID. app-audio list returns observed audio sessions/streams, not installed applications. Each selected opaque identity must appear in the chooser's observed list and a fresh native enumeration; native capture revalidates its operating-system identity again.

Windows capture scope is process-tree: selecting overlapping trees (including two session entries with the same process ID) is rejected instead of double-mixing audio. Linux native adapters report audio-stream; distinct observed streams in one process remain separately selectable. The bridge does not infer support from a platform name. Unsupported native results remain explicit; there is no system-audio or microphone fallback. Entries belonging to Electron's main process or its observed descendants are filtered out. Process-tree lists must additionally establish the helper's host ancestry, and enclosing ancestors are excluded so their capture trees cannot include TeamsPeach.

Ownership and limits

  • CaptureController.onSelected issues a new, frame-bound, one-use application-audio grant; its capture-permission/gesture confirmation is required before starting audio. New video selection revokes the old session. Grants expire after 30 seconds.
  • Preload exposes listAppAudio, startAppAudio, stopAppAudio, ackAppAudio, and onAppAudio. Main validates the application top frame and every start/stop/ack payload. At most eight observed identities may be selected: this explicit resource bound limits simultaneously owned native processes/worklets; attempts above it return a chooser error rather than silently truncating selection.
  • Native PCM must be signed little-endian 16-bit, 48 kHz, stereo, exactly 960 frames/3,840 bytes per message with strictly increasing sequence numbers. Format changes, malformed lines, oversized frames and replayed sequence numbers stop capture.
  • At most four unacknowledged PCM messages cross Electron IPC. The bridge keeps draining native pipes and drops realtime frames when the receiver stalls. Each worklet independently caps its queue at four frames. Acknowledgements follow consumption, not mere receipt.
  • Each selected application has a separate worklet and gain. Their sum passes through a separate broadcast master gain into a MediaStreamAudioDestinationNode. Nothing connects this mixer to speaker output, microphone, voice transport or normal playback volume.
  • Renderer subscription precedes native activation, so initial frames cannot outrun the listener. Cancellation during module loading, fresh enumeration or helper activation cannot attach a late audio track. Release is idempotent and closes subscriptions, the mixed track and native stdin; main enforces a 250 ms child-termination grace period. Each worklet acknowledges its stop before its port/context closes, with a one-second failed-processor deadline. Processor-error listeners are removable EventTarget listeners. A closed message port cannot bypass context closure. Context/native-stop failure rejects explicit release and retains retryable ownership rather than reporting false cleanup success.
  • Unchecking/changing the selection requires stopping that capture and an explicit new preview. Source end, dialog cancellation, disconnect, navigation, renderer loss, application exit and window shutdown stop the session. No audio source is silently substituted.

Interfaces

listApplicationAudio() returns { supported, applications, scope, reason? } through the native bridge.

attachApplicationAudio(videoStream, { sessionId, applications: [opaqueId], gains: { [opaqueId]: 1 }, masterGain: 1, onError, signal }) returns { stream, release, setAppGain, setMasterGain }. Obtain sessionId from getCaptureSessionId(videoStream) after explicitly acquiring the selected video source. Gain range is 0–2; reset is 1. An empty application selection creates no audio context and starts no helper.

Evidence and reproduction

Focused tests live in test/appaudio-main.test.js, test/appaudio-renderer.test.mjs, and test/appaudio-worklet.test.mjs. They cover strict frames, bounded queues, cross-session acknowledgement rejection, process-tree overlap, fresh-identity loss, cancellation during enumeration/activation, late success, early subscription, gain isolation, source end and idempotent disposal.

node scripts/smoke-appaudio.mjs --core <debug-core.exe> --out <evidence-directory> uses Windows waveOut sources and refuses to spawn them unless TEAMSPEACH_TEST_ISOLATED_AUDIO_CONFIRMED=1 and TEAMSPEACH_TEST_ISOLATED_WAVEOUT_DEVICE_ID=<explicit isolated device> are provided. These values must follow actual confirmation of a nonphysical/isolated endpoint; never set them merely to bypass the guard. Default-output audible tones are forbidden. The harness always uses a dedicated invisible, non-focusable offscreen Electron window and disposable profile. Only its two owned source identities may be selected. No desktop pixels, private audio, microphone, server, normal profile, global key, native dialog or visible window is used. Its explicit generated canvas does not prove the OS source chooser or camera permissions.

Each run writes result.json containing measurements, native identities, final actual child count, offscreen/visibility state, failures and bounded diagnostics. Runtime success must be reported from that artifact, not inferred from this document or the unit tests. Linux and macOS runtime coverage is not established by the Windows fixture.

Observed results, 2026-10-24

The safe transport diagnostic command is node scripts/smoke-appaudio.mjs --synthetic-pcm --out smoke-out/appaudio-synthetic. It emits exact-contract synthetic PCM from child processes, opens no source audio device, uses silent (sinkId: { type: 'none' }) contexts, and labels its result as not native WASAPI/PulseAudio capture or native isolation proof.

Final observed result: C:/Users/Admin/Desktop/projects/TeamsPeach/smoke-out/appaudio-synthetic/result.json, ok: true. Decoded receiver RMS was 0.005092; selected 440 Hz was -59.91 dB versus unselected 997 Hz -94.21 dB. Master half gain changed 440 Hz by -6.15 dB. Muting only the 440 Hz application suppressed it by 36.51 dB while 997 Hz changed by only 0.01 dB. Gain reset and master mute passed. All 323 delivered PCM frames were consumed. Three actual AudioWorkletNode processorerror EventTarget-dispatch cycles ended with six worklet stop acknowledgements, five closed contexts, zero active helpers and zero in-flight frames. These cycles exercise the native node event path, not an intentionally crashed processor implementation.

The earlier zero-RMS failure is preserved at C:/Users/Admin/Desktop/projects/TeamsPeach/smoke-out/appaudio-bridge/result.json. Synthetic instrumentation isolated it to the test receiver, not the production mixer: PCM/worklet acknowledgements advanced and WebRTC packets arrived, but decoded samples stayed zero until a muted media element was attached and played. The fixture now starts muted remote playout; no production media-element workaround was added.

The native worker separately reported real WASAPI isolation evidence. The combined real-WASAPI → renderer → WebRTC run has not been re-proved after the receiver-fixture correction: a confirmed isolated endpoint is unavailable, and default-output tone reruns are prohibited. Synthetic success must not be combined with standalone native evidence into a claim of live combined proof.