Files
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.
066e218d84 · 2026-10-24 12:30:39 -04:00
History
..

Encoder Pool Feasibility Probe

Explicit Windows experiment, not a product dependency or CI job. Two real libwebrtc VideoStreamEncoders consume one synthetic 640x360 source through independent stock VideoAdapters. It does not capture the desktop or open ports. Research and evidence own conclusions.

Use Shiguredo m152.7977.0.2 Windows x64 SDK (WebRTC commit 6f37672d358475cd17544121a12494da454d85fb), matching its headers and static library: download. ZIP SHA-256: 3250ee091eb745b9885482d92db352e6bcd5426940021ff90a095747d84d2137. Keep the extracted SDK, official compiler dependencies and executable under ignored build/encoder-pool; preserve the SDK's notices. Do not ship this SDK as part of Piik based on this probe.

With CMake and Visual Studio 2022 x64 tools available:

cmake -S native/probes/encoder-pool -B build/encoder-pool/probe -A x64 `
  -DWEBRTC_SDK="$PWD/build/encoder-pool/webrtc"
cmake --build build/encoder-pool/probe --config Release -j 2
& ./build/encoder-pool/probe/Release/encoder-pool-probe.exe
& ./build/encoder-pool/probe/Release/encoder-pool-probe.exe --pooled
& ./build/encoder-pool/probe/Release/encoder-pool-probe.exe --pooled --group-adjuster

The tested older compiler was MSVC 14.42; linking requires the newer official 14.44 libraries/linker used by the SDK. On such a machine pass MSVC_CRT_DIR to CMake and /p:LinkToolPath=<official tools directory> to MSBuild after --. Do not supply substitute STL implementations or alter global tool settings.

The full trace takes about 51 seconds: healthy, 100 kbps weak B, release to 2 Mbps, one omitted B input, then independent B retirement. --healthy-only omits the weak/release phases. JSONL reports real encoding calls, both WebRTC decoders, raw libvpx hashes without history-dependent postprocessing, dimensions, first transition times, group lifetime and resource observations. integrity checks nonzero decoding, error counts, shared-payload comparisons and retirement; it is not an automatic performance/parity verdict.

--no-adjuster is a diagnostic ablation only. --group-adjuster instead keeps WebRTC's actual adjustment algorithm once per physical codec; it must not run alongside per-VSE correction. --unsafe-skip removes dependency protection as a negative control and should fail integrity with group adjustment and a skipped input. This cache arm is guarded single-source realtime VP8/L1T1 with synchronous codecs; no H264 cache, physical overload or public-network claim follows.

--realtime removes per-input encoder-queue drains. --latency-probe requires that mode and inserts a bounded pixel-proportional 45 ms codec delay, then releases it; it is not a CPU/GPU stress test. --shared-pipeline --realtime --latency-probe is a separate control with one full stock VSE feeding both decoders, not two VSEs borrowing its encoder. Do not combine it with pool or adjuster flags. Source and codec work remain bounded; use a 95-second process deadline for these approximately 70-second traces. The shared-pipeline B resource metrics repeat the common pipeline, while its decoded counters are independent.

Hardware H264 Pipeline

The separate --h264 arm wraps the existing Windows MFT LiveEncoder in a WebRTC encoder adapter. It requires --shared-pipeline --healthy-only --export PATH; one complete stock VSE supplies two output callbacks. It does not test two independent controllers borrowing an H264 encoder. Run it alone, with a 30-second process deadline and no concurrent capture/codec workload:

& ./build/encoder-pool/probe/Release/encoder-pool-probe.exe `
  --h264 --shared-pipeline --healthy-only --realtime `
  --export build/encoder-pool/h264-input.jsonl

This is synthetic I420 upload to NV12/MFT, not WGC capture or zero-copy input. The pinned SDK has no H264 decoder, so this arm records payload equality and encoded dimensions with decoded counters at zero. Validate the exported AUs separately in Chrome. The existing scripts/encoded-group-decode.mjs accepts PIIK_ENCODED_CODEC=avc1.42c033 and PIIK_ENCODED_OUTPUT pointing to two arrays of {Index, Width, Height, PTS, Recovery, Data} frames (nanosecond PTS, base64 Annex-B data). A repeated export in those two arrays proves decoding of that bitstream, not two Pion transports or weak-budget/resource adaptation.

Healthy Relay Chain

Export the first 180 real AUs from sender A for the opt-in Go forwarding check:

& ./build/encoder-pool/probe/Release/encoder-pool-probe.exe `
  --pooled --group-adjuster --healthy-only --export build/encoder-pool/chain-input.jsonl
go test -c -o build/embedded-media/mediaedge.test.exe ./internal/app/mediaedge
$env:PIIK_POOL_CHAIN_FIXTURE = "$PWD/build/encoder-pool/chain-input.jsonl"
$env:PIIK_NATIVE_CAPTURE = "$PWD/build/go-check/piik-capture.exe"
$env:PIIK_POOL_CHAIN_OUTPUT = "$PWD/build/encoder-pool/chain-result.json"
& ./build/embedded-media/mediaedge.test.exe `
  '-test.run=^TestRelayChainEncodedFixture$' '-test.v' '-test.timeout=30s'

The real capture executable must already be built, so Native relay capability remains enabled while checking that healthy forwarding does not start it. This replays encoded video through two Native receivers and three leaves, checking recovery-first, contiguous, hash-identical AUs and closure. No frame payload is committed. Optional output contains only the synthetic trace's summary. It is not a live encoder/BWE integration or an internet/NAT test.