Files
piik/docs/research/native-sender.md
T
AAA 066e218d84 fix(media): improve connection recovery and capture compatibility (#498)
## Problem and outcome

Stale ICE and transport callbacks, interrupted media ownership, and optional encoder capabilities could break otherwise recoverable sharing sessions. This maintenance phase corrects those owners across Web, Native and embedded SFU, improves current-state diagnostics, and finishes the affected UI and documentation animation paths.

Android, QR invitations and App/Server headline presentation stay on their feature branch. This PR contains the accepted maintenance scope only.

## Release notes

**Play together. Your turn!**

Approved friends can play together with shared keyboard and mouse controls or optional gamepads.

**远程同乐,轮到你啦!**

获准的朋友可以共用键鼠,或使用可选手柄,一起玩本地多人游戏。

### English

This maintenance update improves connection recovery, capture compatibility and troubleshooting for existing Piik rooms.

- Keep ICE candidates and gathering completion tied to their current connection. Preserve Viewer route preferences through reconnection and retry newly available Peer opportunities after SFU fallback.
- Correct picture and voice ownership during restart, source replacement and connection retirement. Report failed picture dependencies while keeping room voice available.
- Separate capture and forwarding statistics and isolate pooled sender attachment failures.
- Improve Windows H.264 compatibility with optional encoder properties, retain safe capture failure codes, and keep shared sound volume usable without microphone support.
- Improve remote input continuity and mouse responsiveness after idle.
- Fix fullscreen handling in some mobile browsers, source-picker refresh, delayed chat confirmations, starred-site startup and local App requests. Refine control motion and reduced-motion behavior.
- Restore the mascot's face and shared animation lifecycle in the documentation header.
- Include current connection and playback state in diagnostic exports, update Zod to 4.6.6 and simplify shared lifecycle code.

Existing 2.x protocols, configuration and default quality settings are preserved.

### 中文

本次维护更新改善现有房间的连接恢复、采集兼容性和故障诊断。

- ICE 候选和收集结束事件跟随当前连接;重连保留观众线路偏好,SFU 兜底后出现新的可用 P2P 机会仍可尝试。
- 修正重启、换源和连接结束时的画面与语音生命周期;语音继续时,画面失败会明确反馈。
- 区分采集与转发统计,隔离编码池中单个输出连接的失败。
- 改善 Windows H.264 可选属性兼容性,保留有效的采集失败原因;没有麦克风能力时也能调整共享声音音量。
- 修复部分移动浏览器全屏、选源刷新、迟到聊天确认、收藏站点启动和本机 App 请求问题,打磨控件动效及减少动态效果行为。
- 修复文档导航 mascot 面部一直隐藏的问题,接回共用动画生命周期。
- 诊断导出补取当前连接与播放状态,升级 Zod 至 4.6.6,精简共用生命周期代码。

沿用现有 2.x 协议、配置和画质默认值。Android、二维码邀请及 App/Server 新增的 HEADLINE 展示留待后续版本。

## Verification

- `npm run check`: type-check, 98 test files / 1,765 tests, production Web build passed.
- `npm run check:go-core`: Go formatting, tests, vet, Windows/Linux builds passed; Darwin builds require the native CI runners.
- `npm run check:native`: current Windows capture compilation, fixtures and capability probe passed.
- `npm run build:website`, TypeScript and repository hygiene checks passed after the documentation-brand fix.
- Existing controlled media lifecycle and P2P/SFU voice acceptance covered the retained route/transport changes. Final local browser acceptance covered actual sharing and pause/resume, fullscreen, source refresh, voice/keyboard/settings, 320px to desktop layouts, both themes and all presentation modes. Documentation brand was reproduced broken, then verified on load, replay and reduced motion.
- Independent scoped reviews found no integration blocker.

## Impact

Patch release v2.4.1. Existing 2.x wire, configuration, authority, capacity and default quality contracts remain intact; no data migration. Source volume no longer depends on microphone availability. Zod 4.6.6 fixes GHSA-mrhx-c7xc-m3w5.

The device-specific Windows reports #495 and #452 remain under investigation; this PR improves compatibility and diagnostics without claiming those reports fully resolved. Physical macOS acceptance remains with its native runner/device checks.
2026-10-24 12:30:39 -04:00

8.8 KiB

Native Sender And Shared-Encode Evidence

  • Reviewed: 2026-08-27
  • Scope: Windows capture, one hardware H.264 encoder, bounded WebRTC fanout
  • Status: historical evidence; obsolete sender implementation deleted

Current product scope is owned by media quality. ADR-0006 records the retired canary stop line. Native App adoption and subsequent evidence are owned by ADR-0010 and Native App media.

Conclusion

A native sender can plausibly capture and encode once while serving bounded independent WebRTC transports. Shared encoding can reduce capture/encode work; it cannot remove each child's RTP, congestion, retransmission, encryption, and network copy.

The retained measurements prove:

  • Pion can fan one encoded source into two independent transport bindings;
  • one WebCodecs encoder object fed two Browser sessions in a bounded fixture;
  • one Windows Graphics Capture/Media Foundation H.264 path used an adapter- bound hardware MFT with matching process/LUID VideoEncode activity; and
  • the product helper delivered H.264 video and process-tree audio to one Chrome Viewer.

It does not prove two-Viewer product fanout, heterogeneous congestion feedback, loss/retransmission correctness, audio synchronization, reconnect isolation, public networks, endurance, packaging, update/signing, cross-platform behavior, or distribution licensing. These were the limits of the August 27 canary, before the later Native App integration.

Candidate Shape

The smallest measured Windows pipeline was:

opaque window target
  -> Windows Graphics Capture BGRA surface
  -> one D3D11 conversion to NV12
  -> one adapter-bound hardware Media Foundation H.264 encoder
  -> one generation-bound Go/Pion RTP source
  -> at most two independent PeerConnections

Each PeerConnection must keep independent ICE, DTLS-SRTP, SSRC/sequence/TWCC, pacing, RTCP, congestion, and retransmission state. PLI/FIR from any child may be coalesced into one shared SPS/PPS/IDR request, but a weak child's bitrate request cannot silently become a room-wide minimum policy. That canary required a third Viewer to wait under its then-current endpoint capacity; current placement is owned by routing and transport.

Local target identity, HWND/PID, process creation time, adapter/MFT identity, PCM, and hardware diagnostics never enter signaling. The helper revalidates the selected window/process before capture. There is no software, codec, monitor, or audio fallback hidden behind a hardware-only source choice.

Browser And Pion Fixtures

A stack of bounded fixtures established progressively narrower facts:

Gate Retained result Missing proof
One Pion RTP source, two bindings Equivalent payload reached two transport-local SSRCs. No encoder or Browser.
WebCodecs VP8, two Chrome receivers One encoder object produced 120 outputs; both decoded. Physical/hardware encoder identity.
12-second live bridge 360 inputs/outputs; both Viewers rendered 331 frames; queues remained bounded. Product rooms/capture/audio.
Pion GCC plus negotiated RTX Failed with unknown RTX SSRC. Valid shared congestion/retransmission composition.
No-RTX replay One leg recovered without disturbing the other. Accurate retransmission-specific loss accounting.
Two-leg stock GCC Both estimates happened to be 600 kbps; one shared reconfiguration and keyframe recovery succeeded. Heterogeneous estimates and product policy.

The stock-GCC/RTX composition remains no-go. Do not replace it with a custom pacer, congestion controller, interceptor fork, SRTP, or private transport. No-RTX replay remains research-only because it can distort RTP/RTCP loss accounting.

Hardware Encoder Evidence

WebCodecs

Chrome accepted H.264 Annex-B 1280x720@30 with prefer-hardware and produced 360/360 frames, but Browser-process GPU samples showed no attributed VideoEncode activity. The emitted SPS was 42041f, not the requested codec string. This proves usable chunks and in-band recovery units, not hardware selection or exact WebRTC fmtp compatibility. VP8 prefer-hardware was rejected on the same Windows system.

Media Foundation Fixture

One MSVC/D3D11 fixture selected the NVIDIA H.264 Encoder MFT on an RTX 4070 SUPER by exact DXGI LUID, required hardware enumeration, D3D11 awareness, low-latency mode, CBR readback, 3 Mbps, a 60-frame GOP, and forced keyframes.

Measure Retained result
Inputs / outputs 360 / 360
Recovery units 6 / 6 with Annex-B SPS, PPS, and IDR
Maximum in flight 1
Wall time 12.106 s
Input-to-output p95 11.575 ms
Process+adapter VideoEncode 45 samples; mean 2.949%, max 4.863%
Emitted profile 42c01f

The MFT was physically attributed by hardware-only activation, accepted device manager, exact process/LUID GPU engine, and output progress. Its 42c01f Constrained Baseline profile was absent from Pion's default exact mode-1 list, so the fixture correctly stopped before claiming transport interoperability. The later opt-in fixture registered that exact profile and proved one Browser loopback; it did not alter the wider stop line.

Product Helper Smoke

The Windows helper reuses the same encoder source with WGC capture and process-tree WASAPI loopback. One bounded run delivered 203 rendered 1280x720 frames and 500 Opus packets to a Chrome Viewer. The exact helper PID and adapter LUID matched nonzero VideoEncode. This is a one-Viewer functional proof, not a resource or product release claim.

Historical Canary Gates

The August 27 canary required the following evidence before product consideration. Later implementation and current acceptance are recorded in Native App media and verification status, rather than this retired checklist:

  1. current room/Host authorization and source-generation cleanup;
  2. exact emitted H.264 profile negotiation and unmodified Chrome, Edge, Firefox, and Safari decode/render;
  3. two independent transports with one physical encoder and compatible source, codec, cadence, and rate requests;
  4. correct PLI/FIR, NACK/RTX, TWCC, burst/sustained loss, and reconnect isolation;
  5. process audio, A/V synchronization, source switch, pause, and failure;
  6. bounded CPU/GPU, memory, latency, quality, upload, queues, and thermals under real games and public networks;
  7. evaluation packaging followed by installer, signing, update, and recovery; and
  8. project, dependency, H.264 patent, and distribution license decisions.

No native experiment may preserve an obsolete Piik wire, create another room/topology model, loosen endpoint capacity, or become production merely to make a diagnostic gate pass.

License Boundary

Pion is MIT and coder/websocket is ISC. The Windows APIs use installed hardware MFTs; vendor codec binaries are not redistributed. Direct NVENC would require a separate NVIDIA Video Codec SDK and redistribution review. H.264 patent and project licensing were unresolved at that canary boundary. Current distribution terms and packaged notices are owned by the repository license and dependency provenance. No proprietary or GPL/AGPL implementation code was copied.

Primary Sources