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

Windows Capture Process

This isolated Windows process provides native capture for Piik App. It enumerates local displays and visible top-level windows, binds each window to its PID and process creation time, and has independent modes for:

  • capability discovery (--probe);
  • process-tree inclusion/exclusion or default-device loopback PCM (--capture-audio); or
  • WGC/D3D11 screen/window video with adapter-bound Media Foundation H.264 or libvpx VP8 output (--capture-video --codec auto|h264|vp8).
  • bounded 320x180 BMP source previews (--preview), delivered once per target over the local control connection rather than the media route.

The video command receives the current product resolution, frame-rate, bitrate, and quality preference. A replacement process applies live changes while the Go session retains its Pion source and connections.

Sharing and source previews request borderless access by default when Windows exposes IsBorderRequired and GraphicsCaptureAccess (build 20348+, including Windows 11). The probe advertises API availability; the source-picker preference passes --show-capture-border when the Host wants the sharing border visible. One capture-local owner applies completed access without waiting for consent, and cancels pending access on retirement. Unsupported APIs, denial or failure retain ordinary capture; another capture session may still require a border. The property value is a preference, not proof that the border is invisible. Consumer Windows 10 through build 19045 lacks this API; the current WGC capture path keeps its system border there.

Video and audio run as separate bounded child processes. A source whose audio loopback cannot be initialized keeps video available and reports audio unavailable instead of failing the whole source. Process loopback is probed by activation rather than inferred from a Windows build number; display sources normally use the standard render-device loopback available on Windows 10 and later. The optional --capture-audio exclude <pid> <creation-time> mode requires a successful exclusion-mode probe, without an additional OS-version gate. Windows 10 isolation still needs physical verification; see the audio evidence. It captures all output devices except the selected process tree, and retires when that process exits. The screen-audio contract owns selection and failure behavior.

Auto measures delivered frame cadence through the target-profile encoding pipeline within a four-second selection budget; H.264 that sustains the target needs no software comparison. The selected codec remains fixed across profile and source changes. VP8 reads the existing NV12 surface through one staging texture and uses the same encoded-frame boundary. The process has no network fallback. The App consumes the selected process or system-audio stream through its native media edge when the capability probe reports support. Build to the stable project build/go-check directory for a bounded capability run:

npm run check:native

The checks include synthetic output-worker replacement and failure cases using WARP and a test codec, plus preview cleanup when WGC rejects a hidden test window. They do not capture a user screen or validate a physical encoder.

On a Windows machine with a physical D3D11 adapter, check SDR and HDR-to-SDR conversion:

powershell -NoProfile -File native/capture/windows/build.ps1 -OutputDirectory build/color-check -CheckColor

This sends synthetic RGB, full/limited-range BT.601/BT.709 NV12 and FP16 HDR bars through the production converters. It checks range/matrix, highlight detail, SDR/HDR replacement, white-level changes and retained-frame ownership without capturing the desktop. Decoded H.264/VP8, Browser reception and real HDR displays remain separate media acceptance; fidelity research records current evidence and limits.

The implementation follows Microsoft's MIT-licensed reference samples and official API contracts without copying their WIL framework. The retained MF fixture compiles the same encoder source with PIIK_H264_FIXTURE; there is not a second product MFT implementation. Shared local outputs use stock WebRTC source/encoder adaptation. H264 keeps native NV12 surfaces, while WebRTC VP8 reads back into I420. The existing capture and output mailboxes retain source/generation ownership; adapted sizes and timestamps cross the same media envelope. The encoder requests one temporal layer where supported and low-latency mode where writable; these optional properties do not replace the actual output and Auto cadence checks. VBV sizing stays with the encoder, allowing bitrate increases within the active profile.

The build caches the pinned WebRTC SDK and matching official MSVC linker/runtime libraries under build/encoder-pool. A newer installed MSVC keeps its own linker and runtime; older installations use that pinned minimum, following Microsoft's binary compatibility rule. The SDK supplies libvpx, replacing the separate source build. Only statically linked code and required notices enter the package, not the SDK/toolchain or another runtime service.