Files
piik/docs/adr/0013-embedded-node-local-media.md
T
AAA 9925486cec feat(app): improve startup and media recovery (#478)
This compatible update improves quality recovery after congestion and stream changes, and lets an approved Site become the App's startup page. It also aligns responsive controls and external brand assets while preserving the in-page mascot and illustrations.

The existing media allocator, room graph and authorization owners remain in place. The scoped LiveKit demand-input patch is pinned and submitted upstream in livekit/livekit#5016; its removal condition is documented. No wire or storage version changes.

## Validation

- Web type-check, unit tests and production build; Go core/native acceptance and website build.
- Focused controlled recovery/relay/NAT evidence reused from this phase, plus final integrated lifecycle checks.
- Independent media and UI reviews; corrected the ready App button's stale passive styling.
- Repository hygiene, documentation links, responsive launcher/theme previews and package icon propagation.
- Physical macOS/Linux capture and unmatched reporter cases remain documented; controlled tests do not establish a public connection success rate.

## Release notes

### 中文

这是一次兼容 2.x 的功能与维护更新,重点改善网络波动后的画质恢复,并让常用站点的 App 启动流程更方便。

- **更快恢复画质:** 修复部分 App 分享与服务器中转线路在网络恢复后仍长时间保持低码率的问题;调整 Windows 原生编码,减少短暂波动造成的分辨率下降,并加快恢复。
- **更稳定的中继播放:** 修复原生中继在分辨率变化、画面数据不完整和换源时的恢复处理,以及延迟关键帧请求被丢失的问题。
- **启动时打开常用站点:** 可以为已授权站点加星,下次启动 App 时直接打开它;仍可通过网页 App 按钮或终端地址返回启动页管理授权和选择模式。
- **简化连接设置:** NAT 穿透增强在能力可用时自动启用;高级用户可通过 `PIIK_STUN_URLS` 指定 App 公网邀请使用的 STUN 服务。
- **界面与图标打磨:** 修正窄屏房间工具栏、昵称编辑和浮层排版,精简启动页说明,统一官网与应用的语言、深浅色控件,并更新 App 图标与网站 favicon。页面内的 mascot 和插画保持原有风格。
- **补充连接排查指引:** 更清楚地区分公网邀请服务、站点访问与媒体连接问题。

本次更新不改变 2.x 通信协议或数据库格式。浏览器采集在部分网络波动后仍可能恢复较慢;此次修复不代表所有网络和设备上的画质问题均已消除。

### English

This compatible 2.x feature and maintenance update improves quality recovery after network disturbances and makes it easier to launch the App with your usual Site.

- **Faster quality recovery:** Fixed cases where native App sharing or server-relayed media stayed at a low bitrate after bandwidth returned. Tuned Windows native encoding to reduce resolution drops during brief disturbances and recover sooner.
- **More reliable relay playback:** Fixed native relay recovery across resolution changes, incomplete frames and source replacement, and preserved delayed keyframe requests until they can be fulfilled.
- **Open your usual Site on startup:** Star an approved Site to open it when the App starts. The page's App button and the terminal's launcher address still provide access to approval management and room modes.
- **Simpler connection settings:** Available NAT traversal enhancement now activates automatically. Advanced users can set `PIIK_STUN_URLS` to choose the STUN services used by App public invitations.
- **Interface and icon polish:** Fixed narrow-screen room controls, nickname editing and overlays; simplified launcher guidance; aligned website language and theme controls with the App; and refreshed App icons and website favicons. In-page mascots and illustrations retain their existing appearance.
- **Clearer connection troubleshooting:** Updated guidance distinguishes public-invitation service failures, Site access and media connectivity.

This update preserves the 2.x communication protocols and database format. Browser capture can still recover slowly after some network disturbances; these fixes do not resolve every quality issue on every network or device.
2026-10-16 21:56:49 +08:00

7.4 KiB

ADR-0013: Embedded Node-Local Media

  • Status: Accepted; physical evidence and release boundaries are owned by status
  • Date: 2026-09-07

Context

The owner accepts one self-contained Piik process for the current STUN and SFU services, and one shared encoded-media model for capable Native P2P nodes and the SFU. Bundling or supervising coturn/LiveKit executables does not meet this requirement. The existing product uses coturn only as STUN, not TURN.

The encoding comparison and decode comparison establish real unused-layer cost and codec lifecycle costs, but not complete network/hardware acceptance. Mature simulcast implementations provide the starting model.

Decision

  1. Every parent, including Host and the SFU, owns only its direct children's media demands. Keep the existing single room authority, committed route graph and serial route operation. Media layer changes are not topology operations.
  2. Forward a suitable existing encoding. Derive a missing lower output at its direct parent and share that encoded output among compatible children. Do not create an encoder per child. A forwarding-only healthy relay creates no decoder/encoder group just to manufacture unused fallback layers.
  3. An already-needed encoding group uses a finite highest-demand envelope: produce the highest required output and its lower fallbacks, and stop upper outputs no child needs. This is not a promise of a single Host encode under all conditions. Representation settings come from the chosen media component within Host ceilings, not a new Piik quality score or arbitrary ladder.
  4. Each child receives only its selected output. Multiple active encodings do not imply sending every output to every child. Preserve the original input, source clock and unaffected siblings. Playback quality, cadence and recovery take priority over reducing the number of encoders.
  5. Mature media components own bandwidth estimation, rate allocation, pacing, loss recovery and safe switching. The shared group owns representation lifetime and reuse. Do not add a second congestion controller, fine-grained warm cache, whole-tree demand scanner or periodic topology rebalancer.
  6. The SFU remains one Host publication with one-to-many distribution. For a forwarding SFU, its upstream demand is the maximum required by its direct subscribers; Host combines that demand with its direct P2P children's demand. This requests the highest needed representation, not a sum of encoding counts or a room-wide minimum. The aggregate publication must fit its own upstream congestion budget; requested quality is not a delivery guarantee.
  7. Shared group code must be reusable by the SFU and Native paths. A future transcoding SFU reports its actual input requirements instead of blindly forwarding every downstream request. Do not require server transcoding or recursive subtree demand to ship a forwarding SFU.
  8. Embed library-level STUN, preserving Binding and the three NAT-survey destinations without enabling TURN allocations. Evaluate an embedded SFU library through a narrow adapter. inlivedev/sfu is a candidate, not an irrevocable selection or authorization for a deep fork.
  9. Pure Browser peers retain normal WebRTC capture/senders and can consume the same H264/VP8 output. No Browser encoded-passthrough promise, new codec family or application transport is introduced by this architecture.

For an SFU that forwards existing layers:

SFU upstream demand = max(SFU direct-subscriber demands)
Host output demand  = max(Host direct-P2P demands, SFU upstream demand)

Indirect P2P descendants are not included in either aggregate. Native parents handle their own derivation. Framework estimates must distinguish desired, available and actually delivered output so missing high input cannot be mistaken for a healthy high-quality path.

Consequences And Release Boundary

The Native integration uses one complete stock WebRTC encoding/adaptation pipeline per shared local output. Its source adapter, rate correction, resource feedback and input dropping share that output's lifetime; they are not cloned per consumer behind an encoder cache. The existing Pion/LiveKit transport owns the input bitrate budget and forwarding. Ordinary encoder adaptation preserves the unadapted capture/received original, source timeline and route identity. This refines the implementation boundary, not the direct-child demand model or an acceptance claim. The encoder-pool evidence shows why sharing the codec alone loses reuse or churns under independent drops.

Incompatible direct-child budgets own separate adaptive outputs. Equal effective requests within the same source generation, codec, preference and ceiling may share; dimensions alone are not a compatibility key. Rates update an owned pipeline in place, not by recreating it for every bitrate sample. Membership changes wait for independent recovery, retain existing transport identity and stop the last unused codec slot. The original input is not lowered by a derived group. Physical codec slots are bounded by endpoint admission, not by LiveKit's three spatial-layer labels; each connection sees original plus its assigned adaptive output. SFU publication retains its aggregate allocation separately. No ancestor lookup, extra upstream layer subscription or new congestion policy is introduced.

  • One media model can serve Native edges and embedded server forwarding without duplicating room authority. The adapter is not a second room policy.
  • Extra low encodes, decoder work, frame copies and publication upload remain real costs. A fixed set of layers does not solve bandwidth below its lowest layer or CPU overload; those cases need framework adaptation and verification.
  • An available lowest output owned by a live local rate-controlled codec uses the framework's non-pausing allocation policy at positive budgets; raw relay input and forwarding SFU outputs retain pausing. Cold codec preparation and existing estimation windows still impose transition cost, so eventual recovery does not establish low-bandwidth latency parity.
  • Replacing the external SFU changes Browser signaling/media integration and deployment. Cut over one coordinated current contract, delete replaced paths in that boundary, and preserve active-share/rollback rules from CONTRIBUTING.
  • Shared Pion/LiveKit media components implement this model; ADR-0007 retains the earlier production/runtime context and its unchanged Browser source/codec decisions. Status indexes published behavior and deployment evidence. Controlled implementation checks do not replace the remaining physical acceptance.
  • TODO owns remaining implementation and acceptance. Research owns measurements and library-selection evidence; no production switch is added merely because a probe passes.

References