Files
AAA 1b9f5bd2a2 feat: add room interactions and media sharing improvements
## Problem and outcome / 问题与结果

This phase adds lightweight room interaction without making media depend on chat,
and adds Windows source-audio exclusion and optional SFU-only hosting at their
existing owners. It also corrects confirmed encoder/capture ownership and native
color-conversion defects. Host microphone commentary remains on the shared media
path; room voice and 4K are outside this phase.

## Release notes

### 中文

这是一次功能更新:Piik 加入了文字聊天与表情互动,并完善了 Windows 声音采集、画面颜色和自部署选项。

#### 新功能

- **边看边聊。** 在可移动、可缩放的聊天窗口中发送消息,或开启弹幕。停止分享后,房间中的朋友仍可继续聊天。
- **表情互动。** 点击沙发上的人物,给自己发表情,或把番茄等表情送给朋友;各端按同一事件显示动画。
- **排除应用声音。** Windows App 分享整个屏幕时,可排除一个应用及其子进程的声音,适合同时使用语音软件。所选应用退出后,来源声音停止,避免恢复为未过滤的系统声音。
- **可选的纯 SFU 模式。** 自部署管理员可让共享画面和声音统一通过媒体服务器转发。默认仍为优先 P2P;App 公网邀请保持纯 P2P。
- **Windows HDR 转 SDR。** 原生采集与缩略图自动将 HDR 来源转换为 SDR,沿用现有观看链路。

#### 修复与改进

- 修复原生颜色转换的范围与矩阵处理,避免已复现的暗部丢失、高光裁切和颜色偏差。
- 修复共享编码器切换时使用过期需求或过期帧信息的问题,保护正在观看的画面;修复换源后旧采集事件可能影响新来源的问题。
- 统一新控件、浮窗与来源选择文案,补充中英文使用说明。

#### 使用与升级

聊天与表情需要新版站点页面和 Server;声音排除需要新版页面与支持此能力的 Windows App。聊天只保留本页最近收到的消息,刷新后清空,不补发历史,且不提供端到端加密。

HDR 转换输出为 SDR,不代表端到端 HDR 或多声道支持。既有房主麦克风与立体声能力保留。

### English

This feature update brings text chat and reactions to Piik, alongside improvements to Windows audio capture, picture colors and self-hosting options.

#### New features

- **Chat while watching.** Send messages in a movable, resizable window, or enable on-screen chat. Friends can keep chatting after the host stops sharing.
- **Reactions.** Select a person on the sofa to react above yourself or send a tomato and other reactions to a friend. Participants animate the same shared event.
- **Exclude application audio.** When sharing a whole screen with Windows App, exclude one application and its child processes, useful when using a separate voice app. Source audio stops if the selected app exits, preventing a return to unfiltered system sound.
- **Optional SFU-only hosting.** Site operators can require shared video and audio to pass through the media server. P2P-first remains the default; App Public invite remains P2P-only.
- **Windows HDR-to-SDR conversion.** Native capture and source thumbnails automatically convert HDR sources to SDR for the existing viewing path.

#### Fixes and improvements

- Correct native color-conversion ranges and matrices, addressing reproduced crushed shadows, clipped highlights and color shifts.
- Correct stale demand and frame evidence during shared-encoder handoffs to protect the current picture. Prevent events from a replaced capture from affecting its successor.
- Align new controls, floating panels and source-picker copy, with updated Chinese and English guides.

#### Using this update

Chat and reactions require updated site pages and Server. Audio exclusion requires updated pages and a Windows App that supports the capability. Chat retains only recent messages received by the current page, clears on refresh and does not replay history. It is not end-to-end encrypted.

HDR conversion produces SDR; it does not add end-to-end HDR or surround sound. Existing host microphone commentary and stereo support remain available.

## Verification / 验证

- Web type checks, 78 test files / 1275 tests and production build: PASS.
- Go core tests, formatting/vet and target builds: PASS; Darwin cgo remains platform-limited on this Windows runner.
- Native build/check/color probes and synthetic HDR-to-SDR H.264/VP8 browser reception: PASS.
- Access/privacy gate, Native H.264 SFU-only media gate and local Auto/H.264 Host gate: PASS.
- Three real production pages: chat/reactions, stop/resume, idle-room join, host departure/return, offline draft recovery and invitation revocation: PASS.
- Synthetic parent/child process-audio exclusion and target lifetime: PASS; no raw audio retained.
- Windows candidate archive extraction and packaged Local startup/shutdown: PASS.
- Documentation and website build: PASS.
- [Candidate CI](https://github.com/TNTcraftHIM/Piik/actions/runs/36873766646) at
  `f26cd208d03bc0dcbe353f8cac217f993216b0a3`: Go core and race checks, Web tests,
  Server/container checks and Windows/macOS/Linux App packaging all PASS.
  Publication was skipped as intended.

The owner accepted the UI/model and bounded local walkthrough for phase closure.
Physical HDR/mixed displays, mobile keyboard,
real voice applications across output devices and macOS/Linux capture remain
unverified. Existing field reports without matched evidence are not claimed
resolved. The owner authorized v1.7.0 publication on 2026-10-02. The final
documentation-only commit records that authorization; product code matches
the verified candidate above.

## Impact / 影响

Authorized version: **v1.7.0**, matching the local release planner. Current wire
contracts remain Browser/server 23, Native control 9 and capture 7. Optional
capabilities gate new functionality; existing room/media authority remains owned
by the existing services. No new ports, message persistence, room voice or
automatic room creation on page visit. Updated README, guides, standards,
research evidence and TODO stay with the candidate phase.
2026-10-02 01:36:45 +08:00

5.7 KiB

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 build 20348+ and a successful exclusion probe. 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. Hardware low-latency mode stays on; the old fixed one-frame VBV override is removed so later bitrate increases are not trapped by the original buffer limit.

The build caches the pinned WebRTC SDK and matching official MSVC linker/runtime libraries under build/encoder-pool. 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.