Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。
docs(media): record routing and quality boundaries
AAA6c4b7895ba12
diff --git a/docs/README.md b/docs/README.mdindex 306c0e83..8136fb76 100644--- a/docs/README.md+++ b/docs/README.md@@ -7,15 +7,15 @@- [Deployment](./deployment.md): minimal Node, HTTPS/WSS, coturn, firewall, secret, optional TURN/TLS, and network-verification procedure.- [Maintenance guide](./maintenance.md): Git workflow, context hygiene, document lifecycle, research policy, and automation.- [P2P WebRTC research](./research/webrtc-p2p-screen-sharing.md): evidence, bandwidth model, browser constraints, reference implementations, and feasibility assessment.-- [Peer-assisted media research](./research/peer-assisted-media.md): browser shared-encode limits, standard relay re-encoding, rejected custom encoded transport, deterministic sticky topology, and abandon gates.+- [Peer-assisted media research](./research/peer-assisted-media.md): browser shared-encode limits, standard relay re-encoding, deterministic sticky topology, runtime relay-capacity extension, and abandon gates.- [Low-server-cost media routes](./research/low-server-media-routes.md): traffic accounting, route screening, conditional native encoded-RTP relay, and automatic use of enabled SFU capacity as the final fallback.- [Advanced peer distribution](./research/advanced-peer-distribution.md): multi-tree/SVC, encoded-object relay, native RTP forwarding, FEC/network-coding, MoQ, and measurable go/no-go gates.-- [Native shared-encode sender](./research/native-shared-encode-sender.md): bounded libwebrtc encoder-proxy risk spike, Pion fallback, and hard failure gates.+- [Native shared-encode sender](./research/native-shared-encode-sender.md): bounded libwebrtc encoder-proxy risk spike, Draft PR #16's transport-only Pion fanout oracle, and hard failure gates.- [Realtime quality adaptation](./research/realtime-quality-adaptation.md): browser degradation policy, live profile changes, offline-encoding boundaries, and measurement gates.- [Agent context governance research](./research/agent-context-governance.md): official Codex, Claude Code, Hermes Agent, and GitHub practices adopted by this repository.- [ADR-0001](./adr/0001-p2p-first-media-topology.md): accepted P2P-first media topology and its consequences.- [ADR-0002](./adr/0002-persistent-protected-rooms.md): optional SQLite persistence, protected sequential room IDs, and room lifecycle.- [ADR-0004](./adr/0004-peer-assisted-media-experiment.md): proposed, experiment-only standard-WebRTC peer-assisted spike with hard fanout and failure gates.-- [ADR-0005](./adr/0005-automatic-hybrid-media-routing.md): proposed automatic P2P/peer/SFU preparation, commit, and rollback with a hard host-edge budget.+- [ADR-0005](./adr/0005-automatic-hybrid-media-routing.md): proposed, Draft-implemented automatic P2P/peer/SFU preparation, commit, failback, and rollback with a hard host-edge budget.Documentation and project memory are part of the product source of truth. Update them in the same change that alters the corresponding requirement or architecture.diff --git a/docs/adr/0005-automatic-hybrid-media-routing.md b/docs/adr/0005-automatic-hybrid-media-routing.mdindex 7e56583b..a9b87ad6 100644--- a/docs/adr/0005-automatic-hybrid-media-routing.md+++ b/docs/adr/0005-automatic-hybrid-media-routing.md@@ -1,6 +1,6 @@# ADR-0005: Automatic Hybrid Media Routing-- Status: Proposed - Experiment Only+- Status: Proposed - Draft Implementation, Experiment Only- Date: 2026-08-19## Context@@ -50,6 +50,37 @@ LiveKit endpoint/key/secret tuple. There is no user-facing topology selector andno process-wide `MEDIA_MODE` union. Without the tuple, the same controller endsat peer assistance and bounded waiting/failure.+## Draft Implementation Status++The current `feat/automatic-hybrid-routing` branch implements this controller+on top of Draft PR #13. It is not merged or deployed. Production remains on the+ordinary one-host-peer-per-viewer path.++The Draft keeps the LiveKit dependency dormant unless the complete URL, API key,+and API secret tuple is present together with `PEER_ASSISTED_MEDIA=true`. It+issues short-lived room-, role-, peer-, and publication-generation-bound grants,+and only allowlisted branch roots may subscribe. The server first retries a+failed edge through the deterministic peer topology; only an exhausted peer+route can request an SFU branch root.++Every viewer starts with zero relay capacity for each authenticated session. A+peer-assisted Web client explicitly advertises either zero or one downstream+edge; conservative UA-CH/user-agent detection reports mobile and iPad clients as+leaves and desktop-class browsers as one-child relays. The controller uses this+binary capability only for future admission and recovery. Withdrawing capacity+does not proactively migrate an otherwise healthy existing edge.++Targeted tests cover the revision controller, protocol authorization, relay+capacity, ordered client transitions, stale asynchronous work, server-restart+resynchronization, one-shot credential recovery, and peer failback. A corrected+Chrome 151/LiveKit 1.13.5 localhost run physically failed the same leaf through+peer recovery/reparent and a two-root SFU route. That leaf resumed frames and+hook-assisted 25 ms sampling saw a host edge peak of two. Failure report to+active took 1.481 seconds and to new render 2.257 seconds, so the sub-second gate+failed. The final repository check passes 253 tests, type checking, and both+builds; public transport/audio/load/browser checks remain pending, so this ADR+stays Proposed.+## State And WireThe server holds one room revision with a participant assignment for every@@ -83,6 +114,8 @@ publisher from being counted as one logical edge during commit or rollback.Minimal protocol additions:+- `relay-capacity { downstreamEdges: 0 | 1 }` from an authenticated+ peer-assisted viewer;- `route-update { revision, phase: "prepare" | "active", assignment }`;- `sfu-config { revision, url, token }`;- `route-ready { revision, phase: "prepare" | "active" }`;@@ -90,8 +123,10 @@ Minimal protocol additions:- `refresh-sfu { revision }`.Authentication carries only the current participant assignment and room-revision. Existing peer signaling keeps its connection generation and-assigned-edge authorization. The server+revision. An authenticated snapshot is the sole authority allowed to replace a+higher client revision after the signaling server restarts; the client first+retires media owned by the old revision. Existing peer signaling keeps its+connection generation and assigned-edge authorization. The serverderives the failed edge from the authenticated session, active revision, andconnection ID instead of accepting a client-supplied parent or arbitrary reason.Late, duplicate, or stale revision messages have no effect.@@ -124,16 +159,22 @@ Late, duplicate, or stale revision messages have no effect.route. A failure after commit creates a new rollback/failure revision; staleacknowledgements cannot revive the abandoned plan.+8. An active SFU transport may request one fresh short-lived grant. If that+ retry fails, or token issuance itself fails, the server creates a newer peer+ baseline revision and disables SFU for the rest of the current share. Stop or+ a new sharing generation clears that one-shot circuit breaker.+SFU fallback is sticky until the current share stops. A new sharing generationstarts from the cheapest available route. The first experiment does notcontinuously fail back during a live share, avoiding oscillation without addinga score or hysteresis framework.-Use make-before-break when a downstream slot is free. When both slots are in-use, strict fanout requires warm break-before-make: participants prepare the new-transport, then the host releases one media edge before publishing. Zero-interruption, no standby path, and a hard two-edge maximum cannot all be-guaranteed at once.+The Draft warms only an unpublishing/unsubscribed transport during prepare. Its+media transition is break-before-make: the host releases the replaced peer or+SFU media edge before activating the new one, and a viewer retires its SFU+subscriber before returning to peer media. This avoids depending on transient+overlap and preserves the hard two-edge host invariant, at the cost of a bounded+interruption that still needs measurement.## Triggers And Budgetsdiff --git a/docs/project-memory.md b/docs/project-memory.mdindex d555af43..587ea281 100644--- a/docs/project-memory.md+++ b/docs/project-memory.md@@ -10,7 +10,7 @@ Last updated: 2026-08-19- Server bandwidth cost is a primary constraint. The ordered media ladder is direct P2P, then measured peer assistance, then an enabled user-operated or central SFU fallback. Route selection and failure recovery must be automatic and viewer-transparent, while remaining deterministic, budget-driven, and small enough to reason about. This has always been the product intent; earlier text prohibiting silent migration was an incorrect interpretation and is superseded.- Host and relay-capable endpoints each have a target budget of at most two downstream media edges. Every P2P edge independently uses direct ICE or authenticated TURN fallback. With two edges, the long-term native/encoded-object path should reuse one compatible encoded output; the current browser experiment is stricter at one viewer child and re-encodes.- Packet or layer striping across two peer trees is a recorded candidate for reducing endpoint upload toward one full-stream bitrate. It requires a separate bounded experiment for multi-parent assembly, loss recovery, synchronization, churn, and sub-second latency; it is not part of the current full-stream two-chain implementation.-- Browser convenience does not override reachability, measurable performance, or honest resource accounting. Shared encoding reduces compute, not the last-hop copy required by every viewer.+- Browser convenience does not override reachability or honest resource accounting. Shared encoding reduces compute, not each viewer's last-hop copy.- Durable decisions, current snapshots, research, code, `AGENTS.md`, and `.codex/` belong in Git. Memory and status are rewritten in place rather than kept as transcripts.- Research current official sources and established implementations before material work. Apply Occam's razor and reject speculative protocols, services, scoring, and scale.@@ -22,9 +22,9 @@ Last updated: 2026-08-19- Keep the full-stream browser experiment bounded. If it needs a different media plane, mark that experiment failed and evaluate native RTP relay, encoded-object striping, SVC, or FEC in separate measured spikes rather than hiding the change inside ADR-0004.- Plan a separate native-sender ADR for TeamSpeak-style shared encoding regardless of the browser relay result. One compatible encoded output may feed at most two standard WebRTC packetizers to reduce host encode work, but each edge still consumes upload bandwidth. This work is not part of the current Draft and cannot rescue another failed browser-relay gate.- Keep user-operated mini-SFU deployment and central single-node SFU Draft PR #12 as optional infrastructure. When configured, the route controller may select them automatically as the last fallback; their fanout egress belongs to their operator and does not justify Redis or multi-node infrastructure.-- Add automatic routing only through a separate, measured controller contract. It must keep the host at no more than two media edges, prefer endpoint-carried traffic over central egress, and use discrete capacity/failure events instead of continuous multi-metric scoring. Cross-mode live migration, make-before-break overlap, and rollback semantics remain unimplemented and require an ADR before code.+- Keep automatic routing behind ADR-0005: discrete failures drive peer recovery and optional SFU fallback, host media uses break-before-make and never exceeds two active edges, and a binary per-session relay capability keeps detected mobile/iPad clients as leaves. Corrected local recovery passes functionally but misses the sub-second gate.- Prefer direct UDP, then TURN/UDP, with TURN/TCP as the required non-UDP fallback. Optional TURN/TLS uses TCP 5349 by default; TCP 443 needs a dedicated address or validated L4/SNI routing.-- Treat 1080p60 at 8 Mbps as a best-effort ceiling. Keep the deployed 1080p60 at 8 Mbps, 1080p30 at 5 Mbps, and 720p30 at 3 Mbps profiles switchable during sharing. `balanced` does not guarantee resolution-first behavior; measure actual browser tradeoffs.+- Treat 3/5/8 Mbps profiles as ceilings. Production users report severe degradation across all three; run one controlled 1/2/3-viewer capture before changing constants, then A/B clarity-first against `balanced`. Do not hide actual limits or add an automatic score/controller without evidence.- Do not add custom scene detection or dynamic-FPS control until WebRTC statistics and host resource measurements prove a material gap. Keep browser codec order until target hardware proves a more efficient common codec.- Keep room policy deployment-driven. Public and password-only deployments use random temporary rooms. A site password plus SQLite path enables sequential persistent rooms; stopping sharing leaves the room and viewer link available.@@ -32,17 +32,19 @@ Last updated: 2026-08-19- The repository is one npm package using Node.js 24, React, TypeScript, Vite, native WebRTC, `ws`, Zod, Vitest, and separate coturn. LAN/container listening defaults to all interfaces; bare-metal reverse-proxy deployment binds loopback and exposes `/healthz`.- Production commit `5b2fb005f6f7` is deployed at `https://share.bonfire.icu`. It provides live source and quality changes without rebuilding healthy peers, video-only pause, clearer connection states, and the standard one-host-`RTCPeerConnection`-per-viewer path. Production therefore still exceeds the two-edge host target above two viewers.-- Production supports the three quality profiles above with `contentHint = "motion"` and explicit `degradationPreference = "balanced"`. A real live quality/pause cycle remains unverified.-- Access remains deliberately small: optional site-wide `ACCESS_PASSWORD`, a 12-hour stateless HMAC HttpOnly `SameSite=Strict` cookie, internal host token, role-bound signaling, Origin/payload checks, and no accounts, JWTs, session map, or logout flow.+- Production supports the three profiles with `contentHint = "motion"` and `degradationPreference = "balanced"`; its real live quality/pause cycle remains unverified.+- Access stays small: optional `ACCESS_PASSWORD`, a 12-hour stateless HMAC HttpOnly `SameSite=Strict` cookie, internal host token, role-bound signaling, Origin/payload checks, and no accounts, JWTs, or session map.- With `ROOM_DATABASE_PATH` and the site password, built-in SQLite stores only auto-incremented room ID and host-token digest. Links persist and stopping sharing leaves viewers waiting. Production room ID `1` survived the `5b2fb005f6f7` deployment restart. Without the path, rooms remain random and temporary; public mode cannot use sequential rooms.- Production runs behind nginx with Node.js 24.19.0. Authenticated coturn 4.17.2 at `turn.bonfire.icu:3478` has verified public STUN, TURN/UDP, TURN/TCP, and relay-only traffic. TURN/TLS is intentionally disabled.- Draft PR #13 contains deterministic server/client peer-assisted assignment, standard remote-track relay, and synchronized 1080p60/1080p30/720p30 room profiles. It defaults off, is capped at eight viewers, re-encodes at every relay, and is neither merged nor deployed. Native shared encoding and custom encoded browser transport are not implemented.-- The tracked Chrome 151 harness passed short synthetic `1/3/5/8` runs: host active edges peaked at two, relay edges at one, every viewer kept increasing decoded frames through the measurement window, and the slowest first frame was about 1.05 seconds. A three-viewer first-level relay close recovered in about 5.32 seconds without exceeding host fanout. These are topology/control checks, not quality, load, or endurance proof; silent partitions remain unverified.+- The current automatic-routing Draft stacks on PR #13: peer recovery precedes an allowlisted SFU root; revisioned prepare/commit/abort is session-bound; active SFU failure gets one token refresh, then fails back and disables SFU for that share. LiveKit is dormant when unconfigured.+- Corrected Chrome 151/LiveKit 1.13.5 smoke physically failed one leaf through peer recovery/reparent and two-root SFU. Frames resumed; 472 hook-assisted 25 ms samples saw host edge peak two. Failure-to-render took 2.257 seconds. It is localhost, headless, synthetic 720p30 video only.+- Draft PR #16 (`5b09f0a`) proves one Pion RTP write fans equivalent data to two transports with independent SSRCs. It has no encoder and proves neither physical shared encode nor browser readiness.+- Chrome 151 short synthetic `1/3/5/8` runs kept host edges at two, relay edges at one, and all viewers decoding; a three-viewer relay close recovered in 5.32 seconds. This proves topology/control only, not quality, load, endurance, or silent partitions.- The peer-assisted authenticated snapshot and host-only update synchronize one bounded, non-persistent room profile. Online viewers receive changes; `ViewerRelay` uses the latest desired profile for current and future children, while `HostPeer` serializes sender setup, stream replacement, and last-wins profile updates. The ordinary P2P wire is unchanged. Real 1/3/5/8 quality, resource, and latency measurements remain pending.-- Chromium 151 kept the same relay peer, sender, and signaling generations while changing its sender ceilings from 8 Mbps/60 fps to 5 Mbps/30 fps and 3 Mbps/30 fps; the leaf continued decoding. The synthetic 640x360/30 source proves profile propagation and connection preservation only, not full-resolution quality or load.+- Chromium 151 kept relay/sender/signaling generations through 8 Mbps/60, 5 Mbps/30, and 3 Mbps/30 ceilings while the leaf decoded. Synthetic 640x360/30 proves control propagation, not full-resolution load.- Per-frame encode/decode diagnostics use adjacent non-overlapping `getStats()` deltas rather than connection-lifetime averages; first, empty, changed-stream, and reset intervals remain unknown and rebase.-- The recorded peer-assisted full check passes type checking, 13 Vitest files with 152 tests, and both client and server production builds. Production release `5b2fb005f6f7` separately passed 108 tests and deployment checks.-- Draft SFU PR #12 and ADR-0003 remain unmerged, undeployed, and independently reversible. There is no infrastructure blocker for the deployed Web baseline or bounded peer-assisted experiment.+- The automatic-route branch passes type checking, 19 Vitest files/253 tests, both builds, dependency audit, and repository hygiene. Production separately passed 108 tests and deployment checks.## Provisional Quality Targets@@ -57,7 +59,7 @@ These are measurement gates, not performance claims.- Sustainable viewer count by broadcaster and relay hardware, quality profile, network class, and media route; use instrumented 1/3/5/8 comparisons rather than a 1:8 claim.- Whether ADR-0004 passes fanout, re-encoding, depth-four latency, reparenting, silent-partition, and mobile-leaf gates.-- The smallest safe automatic route and migration contract for the ordered P2P, peer-assisted, and optional-SFU ladder, including its bounded overlap and rollback budget.+- Whether ADR-0005 can reduce or accept its corrected 2.257-second local interruption and pass public LiveKit UDP/ICE-TCP/TURN, rollback, reconnect, restart, egress, and browser-matrix gates.- Exact mobile lifecycle behavior and whether Windows per-application audio is required for the first release.- Project license and distribution model, which determines whether GPL/AGPL sources can move beyond study-only use.- Initial deployment regions and expected mainland China, Hong Kong, and overseas network mix.diff --git a/docs/research/advanced-peer-distribution.md b/docs/research/advanced-peer-distribution.mdindex 8ec6724e..428d2ba9 100644--- a/docs/research/advanced-peer-distribution.md+++ b/docs/research/advanced-peer-distribution.md@@ -3,7 +3,9 @@- Research date: 2026-08-19- Scope: at most eight trusted viewers, sub-second interactive media, endpointdownstream fanout at most two, and minimal central-server media egress-- Status: candidate routes and bounded spike gates; none is implemented+- Status: candidate routes and bounded spike gates; only the Pion RTP+ transport-fanout sub-oracle is implemented, with no advanced media route+ integrated into Screener## Terms@@ -47,7 +49,14 @@ independent downstream browser PeerConnections without decoding and encodingthe video again. Each downstream edge keeps its own SSRC, pacing, RTCP,DTLS-SRTP, ICE, and TURN behavior.-The first Go/Pion spike is video-only VP8 at 720p30 with one browser upstream+Draft PR [#16](https://github.com/TNTcraftHIM/Screener/pull/16) passes an earlier+in-process transport oracle: one Pion v4.2.18 `TrackLocalStaticRTP.WriteRTP`+call reaches two independent PeerConnections with preserved semantic payload,+sequence number, and timestamp plus binding-specific SSRCs. It contains no+encoder or browsers, so it is not evidence for one physical encode, end-to-end+compatibility, feedback arbitration, congestion control, or latency.++The next Go/Pion spike is video-only VP8 at 720p30 with one browser upstreamand two unchanged browser children. It must prove:- zero relay video-encoder calls and at least 40% lower relay CPU than browserdiff --git a/docs/research/low-server-media-routes.md b/docs/research/low-server-media-routes.mdindex 939f0ea5..953f8f8a 100644--- a/docs/research/low-server-media-routes.md+++ b/docs/research/low-server-media-routes.md@@ -3,8 +3,9 @@- Research date: 2026-08-19- Scope: one broadcaster, at most eight trusted viewers, low latency, and hostmedia fanout at most two-- Status: route screening for ADR-0004; only the standard browser relay is in- the current spike+- Status: route screening for ADR-0004/ADR-0005; automatic hybrid routing has a+ Draft implementation, while every non-browser data-plane candidate remains a+ separate experiment## Current Route Ladder@@ -22,15 +23,16 @@ The smallest current plan is:4. Only if browser relay re-encoding is the isolated failure should anotherexperiment add opt-in native volunteer encoded-RTP relays.5. Keep a user-operated mini-SFU and a centrally operated single-node SFU as- optional capacity. When configured, a later route controller uses that- capacity automatically only after cheaper endpoint-carried routes fail.+ optional capacity. The current ADR-0005 Draft controller uses that capacity+ automatically only after deterministic peer recovery is exhausted.They transfer fanout bandwidth to their operator; they do not make itdisappear.Any browser-spike failure other than isolated relay re-encoding closes thatbrowser-relay route. It does not cancel the separate native sender plan. Draft-SFU PR #12 remains unmerged and undeployed. The required automatic cross-mode-fallback is not implemented in the current spike and needs its own bounded ADR.+SFU PR #12 remains unmerged and undeployed. ADR-0005 now owns a separate Draft+implementation of the automatic cross-mode controller; it is also undeployed+and has not passed real LiveKit/browser network validation.## Traffic Conservation And The Impossible Triangle@@ -89,6 +91,15 @@ also needs a separate native shared encoder so its two WebRTC packetizers consumone encoded result. Pion's broadcast example demonstrates server-side RTPfanout, but it does not supply this end-user topology or product behavior.+Draft PR [#16](https://github.com/TNTcraftHIM/Screener/pull/16) has now passed+the narrower transport oracle: one Pion v4.2.18+`TrackLocalStaticRTP.WriteRTP` call fans a pre-packetized semantic payload to+two independent PeerConnections with binding-specific SSRCs. Because that+oracle contains no encoder, browsers, RTCP arbitration, or bandwidth-control+loop, it proves neither one physical encode nor a usable native relay. Its next+gate is browser-to-native-to-two-browser interoperability with bounded+RTCP/PLI, congestion, queues, throughput, and latency.+The native shared-encode sender is a planned independent phase. Native volunteerrelays remain conditional on measurements isolating relay re-encoding as thesole browser-spike failure. They must not rescue failures in deterministicdiff --git a/docs/research/native-shared-encode-sender.md b/docs/research/native-shared-encode-sender.mdindex 3b0ee11a..42f2f157 100644--- a/docs/research/native-shared-encode-sender.md+++ b/docs/research/native-shared-encode-sender.md@@ -3,7 +3,8 @@- Research date: 2026-08-19- Scope: one Windows game-capture sender, one encoded video stream, and at mosttwo independent standard WebRTC media edges-- Status: candidate risk spike; not implemented or accepted for production+- Status: Pion transport-fanout sub-oracle passed in Draft PR #16; physical+ shared encoding and browser end-to-end behavior remain unproven## Decision Input@@ -98,6 +99,25 @@ aggregation of both edge targets, encoder bitrate control, PLI handling, andbounded RTP/RTX queues. A Pion route must use the same minimum-edge rate rule andmust not invent a custom SRTP, ICE, or congestion protocol.+### Draft PR #16 Transport Oracle++[Draft PR #16](https://github.com/TNTcraftHIM/Screener/pull/16), branch+`spike/native-rtp-fanout-oracle` at commit `5b09f0a`, passes CI for one narrower+public-API question. With Pion WebRTC v4.2.18, one shared+`TrackLocalStaticRTP.WriteRTP` call reaches two independent PeerConnections.+Both receivers observe the same semantic payload, RTP sequence number, and+timestamp, while each binding receives its own transport SSRC and the caller's+packet is not mutated.++This is an in-process RTP transport-fanout oracle, not the shared-encode+acceptance gate above. It contains no physical encoder and therefore cannot+prove one encoder invocation per input frame. It also does not prove browser+interoperability, capture, decoding, RTCP/PLI aggregation, congestion-control+fairness, retransmission, pacing, sustained throughput, latency, or production+readiness. The next independent gate is one browser publisher through the+native relay to two unmodified browser viewers with bounded RTCP, PLI, queue,+and bandwidth-estimation behavior.+## Acceptance And Failure Gates- Two current unmodified browsers decode continuously.diff --git a/docs/research/peer-assisted-media.md b/docs/research/peer-assisted-media.mdindex c71b0404..7c0dd701 100644--- a/docs/research/peer-assisted-media.md+++ b/docs/research/peer-assisted-media.md@@ -2,7 +2,9 @@- Research date: 2026-08-19- Scope: one game-screen broadcaster, at most eight trusted viewers, host media fanout at most two-- Status: evidence for a bounded experiment; not a production topology decision+- Status: evidence for the bounded ADR-0004 experiment; the stacked ADR-0005+ Draft adds binary relay capability and automatic optional-SFU routing but is+ not a production topology decision## Conclusion@@ -24,8 +26,8 @@ does not hide it or claim shared encoding.The product preference is `direct P2P -> peer-assisted -> optional SFU`. DirectP2P remains the simplest path for one or two viewers. The experiment assigns thethird and later viewers to peers automatically. Deployment decides whether SFU-capacity exists; when it does, a later small route controller must use it as an-automatic last fallback without asking host or viewers to select a topology.+capacity exists; when it does, the current ADR-0005 Draft controller uses it as+an automatic last fallback without asking host or viewers to select a topology.## What Browsers Can Share@@ -260,9 +262,12 @@ slot:Peer assistance distributes traffic; it does not eliminate it. Relayeligibility must therefore be visible and voluntary in any production design.-This spike has no runtime capability flag: its desktop relay/mobile leaf matrix-is enforced only by controlled join order, so it must not be enabled for-arbitrary users.+The standalone ADR-0004 spike has no runtime capability flag and relies on+controlled join order. The stacked ADR-0005 Draft starts every viewer as a leaf,+then accepts an explicit per-session capacity of zero or one; its Web client+reports detected mobile/iPad clients as leaves and desktop-class browsers as+one-child relays. That conservative heuristic is still unverified on the real+mobile matrix and is not a substitute for a future voluntary relay policy.## Bounded Spike And Gatesdiff --git a/docs/research/realtime-quality-adaptation.md b/docs/research/realtime-quality-adaptation.mdindex 1f25438d..8cd246d7 100644--- a/docs/research/realtime-quality-adaptation.md+++ b/docs/research/realtime-quality-adaptation.md@@ -34,6 +34,36 @@ on 2024-05-22; the commit says it had already been disabled for several yearsand was not maintained. Current Chromium behavior must therefore not bedescribed as automatically detecting game motion and forcing a 720p cap.+## Production Degradation Report++On 2026-08-19 the deployed build was reported to deliver very low resolution,+bitrate, and frame rate across all three profiles. This is a user observation,+not yet an instrumented result. The highest-confidence explanation is the+combination of one independent peer connection, sender, encoder pipeline, and+upload copy per viewer with `balanced` adaptation: host CPU or uplink pressure+can grow per edge, and the browser may then reduce both dimensions. The current+peer-assisted and SFU drafts are not deployed, so relay re-encoding and LiveKit+cannot explain that production observation.++One controlled capture should classify the problem before changing constants:++1. Run the same high-motion scene for 60 to 90 seconds with one, two, then three+ viewers, plus one TURN/UDP case.+2. Compare capture settings/media-source, outbound and inbound resolution/FPS,+ actual and target bitrate, codec and encoder implementation, interval encode+ cost, selected path, and `qualityLimitationReason`.+3. Treat source-low as capture, outbound-low with `cpu` as encoder pressure,+ outbound-low with `bandwidth` as uplink/path pressure, and inbound-only loss+ or dropped/frozen frames as network or receiver pressure.+4. Export `chrome://webrtc-internals` only as sensitive local evidence; remove+ SDP, candidate addresses, and other identifiers before sharing or retaining.++Missing `scaleResolutionDownBy` is not itself a root cause for a single encoding+because its effective default is 1.0. Likewise, the current 3/5/8 Mbps values+are ceilings rather than targets. Raising them cannot repair CPU or bandwidth+limitation and should only follow evidence that the encoder is already pinned+to the ceiling while spare transport capacity remains.+## Why Offline Encoding Presets Do Not Transfer[Maruko Toolbox](https://github.com/wzxjohn/marukotoolbox) is an Apache-2.0@@ -80,6 +110,14 @@ resolution, frame rate, or bitrate.- Pausing the picture disables the existing video track, producing black videowithout closing the room or media connection. Audio remains enabled.+The next bounded A/B changes only degradation preference: keep `motion`, compare+the current `balanced` behavior with `maintain-resolution`, and expose the+result as a default clarity-first choice plus optional balanced/fluid choices.+It may trade frame rate for readability and is not a universal fix. The+advanced panel remains bounded to resolution ceiling, frame-rate ceiling,+bitrate ceiling, quality priority, and audio mode; it does not expose raw SDP or+codec internals.+A Chromium 151 loopback smoke with one host, three viewers, and a synthetic640x360/30 source kept the same relay peer, sender, and signaling generationswhile applying 8 Mbps/60 fps, 5 Mbps/30 fps, and 3 Mbps/30 fps sender ceilings.@@ -96,6 +134,8 @@ quality, CPU/GPU cost, public-network behavior, or sustained performance.power-efficient encoder.- No promise that all browsers honor `applyConstraints` or degradationpreference identically.+- No automatic composite quality score or periodic profile controller before+ the controlled production capture identifies a reproducible bottleneck.## Verification Gate@@ -125,10 +165,13 @@ profiles before adding an application-level adaptation controller.- [W3C MediaStreamTrack Content Hints](https://www.w3.org/TR/mst-content-hint/)- [W3C Screen Capture](https://www.w3.org/TR/screen-capture/)- [W3C WebRTC](https://www.w3.org/TR/webrtc/)+- [W3C WebRTC Statistics](https://www.w3.org/TR/webrtc-stats/)- [Chromium `motion` to libwebrtc `kFluid` bridge](https://chromium.googlesource.com/chromium/src/third_party/+/refs/heads/main/blink/renderer/modules/peerconnection/media_stream_video_webrtc_sink.cc)- [libwebrtc `motion`/`kFluid` sender classification](https://webrtc.googlesource.com/src/+/3b1eab8a69cb5078befb021c5492d3f204a7d6a2/pc/rtp_sender.cc)- [libwebrtc encoder content-type selection](https://webrtc.googlesource.com/src/+/9caef2a8b88f389af10cee841732c42a98d3d45d/media/engine/webrtc_video_engine.cc)- [libwebrtc conditional screen-share degradation mapping](https://webrtc.googlesource.com/src/+/refs/heads/main/video/video_stream_encoder.cc)+- [libwebrtc adaptation overview](https://webrtc.googlesource.com/src/+/HEAD/video/g3doc/adaptation.md)+- [libwebrtc per-send-stream encoder construction](https://webrtc.googlesource.com/src/+/refs/heads/main/video/video_send_stream_impl.cc)- [libwebrtc removal of the automatic animation-detection experiment, 2024-05-22](https://webrtc.googlesource.com/src/+/1d7d0e6e2c5002815853be251ce43fe88779ac85)- [LiveKit screen-share presets](https://github.com/livekit/client-sdk-js/blob/main/src/room/track/options.ts)- [LiveKit degradation defaults](https://github.com/livekit/client-sdk-js/blob/main/src/room/participant/publishUtils.ts)diff --git a/docs/status.md b/docs/status.mdindex c7296258..c0b3a33e 100644--- a/docs/status.md+++ b/docs/status.md@@ -8,10 +8,10 @@ The WebRTC proof of concept at `https://share.bonfire.icu` runs commit`5b2fb005f6f7` with live quality/source changes, video pause, protected SQLiterooms, sequential IDs, and reusable links.-Production still creates one host `RTCPeerConnection` per viewer. Draft PR #13-adds default-off, maximum-eight-viewer peer assistance: two sticky chains,-host capacity two, viewer capacity one, per-hop decode/re-encode, and synchronized-quality profiles. Draft SFU PR #12 is also unmerged and undeployed.+Production still creates one host peer connection per viewer. Draft PR #13 adds+default-off two-chain peer assistance with per-hop re-encoding; ADR-0005 adds+optional automatic SFU fallback. Corrected recovery passes functionally but+misses its sub-second gate; neither Draft is merged or deployed.## Current Snapshot@@ -19,54 +19,53 @@ quality profiles. Draft SFU PR #12 is also unmerged and undeployed.- Whole-site `ACCESS_PASSWORD` is optional. Protected sessions use a stateless 12-hour HMAC HttpOnly `SameSite=Strict` cookie; host authentication remains internal and signaling is role-bound.- Without `ROOM_DATABASE_PATH`, rooms are random and temporary. With both the database path and site password, room IDs start at `1`, links persist, and stopping a share leaves viewers waiting. SQLite stores only room ID and host-token digest.- Direct ICE is preferred independently per media edge. Authenticated TURN/UDP and TURN/TCP are required production fallbacks; TURN/TLS is optional.-- The required media priority has always been direct P2P, then peer assistance, then an enabled user-operated or central SFU fallback, with route allocation and recovery hidden from host and viewers. The current peer-assisted Draft already assigns the first two viewers to the host and later viewers to peers automatically. Cross-mode failure fallback and live migration are not implemented yet; they must preserve the host two-edge budget, minimize server egress, and use a small deterministic state machine rather than composite health scoring.-- Peer-assisted profile state is bounded, server-memory-only, and absent from the ordinary P2P wire. The host reasserts its choice after authentication; online viewers receive changes, and each relay applies the latest desired profile to its current or future child through serialized sender mutations.+- Hidden routing is `direct P2P -> peer-assisted -> optional SFU`. After bounded ICE recovery it tries peer reparenting before an allowlisted SFU root. Session-bound revisions prepare, commit break-before-make under two host edges, or abort. Active SFU gets one token refresh, then fails back for that share.+- A viewer starts as a leaf each session and explicitly advertises relay capacity zero or one; the Web client reports detected mobile/iPad clients as zero and desktop-class browsers as one. Withdrawal stops future assignment without moving a healthy edge. Browser relays remain one-child; the host remains two-child.+- Peer-assisted profile state is bounded, memory-only, absent from ordinary P2P wire, and applied to current and future relay children.## Verified Evidence-- Production passed 108 tests, both builds, public HTTPS/access/TURN checks, clean activation, and a database restart with room `1` retained.+- Production passed 108 tests, both builds, public HTTPS/access/TURN checks, clean activation, and a database restart retaining room `1`.- Draft PR #13 now provides `npm run benchmark:peer-assisted`; the full check passes type checking, 13 Vitest files with 152 tests, and both production builds.- A short Chrome 151 synthetic `1/3/5/8` benchmark passed every topology check: host active edges peaked at two, relay edges at one, every viewer kept increasing decoded frames through the measurement window, and the slowest first decoded frame was about 1.05 seconds. Closing a first-level relay in the three-viewer run recovered in about 5.32 seconds without exceeding host fanout two.- A separate live-profile smoke kept the same relay peer, sender, and signaling generations through 8 Mbps/60, 5 Mbps/30, and 3 Mbps/30 ceilings while its leaf kept decoding.-- Local WebRTC diagnostics derive per-frame encode/decode cost from adjacent non-overlapping `getStats()` samples. First, empty, changed-stream, and reset intervals stay unknown and rebase instead of publishing a misleading lifetime average.+- Corrected Chrome 151/LiveKit 1.13.5 synthetic 720p30 smoke physically failed the same leaf through peer recovery/reparent and a two-root SFU route. Its frames resumed; 472 hook-assisted 25 ms samples saw host edge peak two. Failure report to active took 1.481 seconds and to new render 2.257 seconds.+- The current Draft passes type checking, 19 Vitest files/253 tests, both production builds, dependency audit, and repository hygiene.+- Draft PR [#16](https://github.com/TNTcraftHIM/Screener/pull/16) passes CI for one Pion RTP write fanned to two transports. It has no encoder and proves neither physical encode nor browser E2E.+- Local diagnostics use adjacent non-overlapping `getStats()` deltas; empty, changed-stream, and reset intervals rebase instead of publishing lifetime averages.- Production HTTPS/WSS, access cookie, room/WebSocket authorization, certificate renewal, public STUN, and authenticated TURN/UDP and TURN/TCP relay-only bidirectional paths are verified. TURN/TLS is intentionally disabled.## Unverified Boundaries- The short harness uses synthetic headless capture and proves topology, controls, stats collection, and recovery only. Full-resolution 30-minute runs, relay CPU/GPU, generational quality, controlled loss/RTT, depth latency, and actual game-capture behavior remain unverified.-- Android Chrome and iOS Safari remain required leaves but are not verified for this topology. There is no runtime relay-capability bit; controlled join order is the only mobile-leaf enforcement, so arbitrary-user deployment is excluded.+- Android Chrome and iOS Safari remain unverified leaves. Runtime capability conservatively marks detected mobile/iPad clients as leaves; real UA/lifecycle behavior remains open.- The observed recovery starts from a page close immediately seen by the server. A silent partition can wait 30 to 60 seconds for heartbeat detection before the default 5-second grace; it remains unverified.- Real screen/game audio, heterogeneous machines and networks, mobile lifecycle behavior, the production live quality/pause cycle, room `1` stop-and-republish/link reuse, and sustained profile performance remain unverified.-- Browser relays do not provide shared encoding. Encoded Transform, DataChannel/WebCodecs media, custom congestion control, multiple trees, and network coding remain researched alternatives rather than current implementation. They may enter a separate bounded experiment only when measurements identify a specific bottleneck and show a plausible sub-second benefit.+- Production users report severe resolution/bitrate/FPS degradation across all profiles. A controlled 1/2/3-viewer and TURN sample must distinguish capture, per-edge CPU, bandwidth/path, and receiver limits before changing ceilings or codecs; clarity-first versus `balanced` is the first bounded A/B.+- Browser relays do not share encoding. Encoded objects, custom congestion control, multiple trees, and network coding remain separate measured candidates.- The long-term endpoint budget is at most two downstream edges for both the host and relay-capable viewers, with one compatible encoded output reused across both edges where a native media engine can prove it. The current browser spike remains host capacity two/viewer capacity one and performs a new encode at each relay. Packet/layer striping and multi-parent assembly are recorded, not implemented.+- The corrected smoke is localhost/headless/video-only; public transport, audio, shaping, load, mobile, endurance, and sub-25 ms overlap remain open.## Next Milestone-Complete ADR-0004 before UI polish: run full-resolution 30-minute `1/3/5/8`-matrices with network shaping and resource/quality/latency capture; exercise source,-profile, stop/restart, rebuild, reparent, signaling and silent-partition paths; and-verify Chrome/Edge relays with Android Chrome and iOS Safari leaves.+Finish ADR-0005 before UI polish: address the 2.257-second fallback, then+validate public transports, rollback, reconnect, controls, edge counts, egress,+and load.-In parallel, Proposed ADR-0005 defines the smallest automatic route controller-for `direct P2P -> peer-assisted -> optional SFU`. It must use explicit-budgets and discrete failure events, avoid continuous composite scoring, and-specify make-before-break or a bounded visible interruption before any live-migration is implemented. The current Draft still performs no automatic-cross-mode migration.+ADR-0004 still requires a full-resolution 30-minute `1/3/5/8` network,+resource, quality, latency, recovery, and browser/mobile-leaf matrix.For a disconnect immediately observed by the server, the gate retains thedefault 5-second grace followed by at most 3 seconds to restore a decodablepicture, about 8 seconds total. Silent partitions include their detection delay.-ADR-0004 gates fail closed for the current full-stream browser path. Native-shared encode and packet/layer striping are separate measured experiments, not-ways to relabel a failed browser-relay result.+ADR-0004 fails closed. Native shared encode and packet/layer striping remain+separate experiments, not ways to relabel a failed browser route.## Blockers And Decisions-Production peer assistance remains blocked on the matrix and ADR-0004 gates.-Automatic cross-mode routing, native shared encode, and multi-tree striping each-require their own bounded ADR/spike.+Peer assistance and automatic routing remain blocked on ADR-0004/0005 gates.+Native shared encode and multi-tree striping remain separate experiments.- Whole-system versus selected-game audio for the first release.- Initial deployment region and network cohort.diff --git "a/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md" "b/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"index 5620c1bc..12d16605 100644--- "a/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"+++ "b/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"@@ -135,6 +135,8 @@ Zod 在服务边界拒绝未知类型、超长字符串、非法 SDP/candidate浏览器可返回更低设置,界面以 `track.getSettings()` 显示实际结果。视频 track 保留 `contentHint = "motion"`;sender 尝试设置 `maxBitrate`、`maxFramerate` 与 `degradationPreference = "balanced"`。`balanced` 只允许浏览器在帧率和分辨率之间权衡,不保证清晰度优先;具体 Chromium、Firefox 与 Safari 行为仍需实测。不支持 sender 参数时只记录警告。+生产反馈显示三个档位都可能被降到难以阅读的分辨率、帧率和码率。下一质量迭代先在同一高动态场景对 1、2、3 名观看者做一次 60 至 90 秒采样,并对 `maintain-resolution` 与当前 `balanced` 做 A/B;默认目标是清晰优先,高级区再提供清晰、平衡和流畅三种偏好。不得只提高 ceiling 或强制 codec。只有实际/target bitrate 长期顶住 ceiling、网络仍有余量且画质仍不足时,才增加更高的可选码率上限。+PoC 不强制 codec,也不做 SDP munging。先通过 stats 记录实际协商 codec、`encoderImplementation` 和 `powerEfficientEncoder`,再依据目标机器测量决定是否优先 H.264。这样避免静态 codec 偏好意外触发软件编码。`audio: true` 只是请求。若 `getAudioTracks()` 为空,分享者界面必须显示“当前来源没有可共享音频”。纯 Web 首版接受浏览器提供的标签页或系统音频,不承诺仅捕获某个游戏进程。@@ -169,6 +171,8 @@ TURN/TLS 是可选能力,不是生产启动门槛。启用时默认使用 RFC每两秒在本地采集一次 `getStats()`。首版不上传原始统计,也不展示候选地址。+质量诊断必须能按顺序区分:捕获源设置、sender 实际参数、CPU 或带宽 `qualityLimitationReason`、selected candidate/TURN 路径、outbound 与 inbound 差异,以及接收端 dropped/freeze。每次成功调用 `setParameters()` 后读回并记录实际 `maxBitrate`、`maxFramerate`、`scaleResolutionDownBy` 与 degradation preference;参数拒绝不能只留在控制台。首轮使用浏览器 WebRTC internals 导出和一份脱敏 run manifest,不新增服务端遥测、综合评分器或自动调档状态机。+分享者逐观看者显示:- `connectionState` / `iceConnectionState`;@@ -185,14 +189,16 @@ TURN/TLS 是可选能力,不是生产启动门槛。启用时默认使用 RFC首屏就是工具,不做营销页。视觉采用中性深灰工作台,绿色表示 direct、琥珀色表示 relay/警告、红色表示失败,避免单一蓝紫色主题。- 全站 gate:仅在配置 `ACCESS_PASSWORD` 且 cookie 无效时显示一个密码输入窗口;验证后返回原目标路径。-- 分享者根页面:顶部房间状态;主区域为 16:9 本地预览;底部为开始/停止、质量档位和复制邀请;侧栏以紧凑列表显示配置范围内的观看者及统计。+- 分享者根页面:顶部房间状态;主区域保持稳定的 16:9 舞台。未发布、已停止或可恢复错误状态时,舞台内以同等尺寸和权重显示“开始分享”和“加入房间”,中间只用“或”与分隔线表达发送/接收;前者直接开始现有分享流程,后者直接进入 `/join`,不增加首页、向导或拓扑选择。直播时舞台显示本地预览,底部保留停止、暂停、质量档位和复制邀请。- `/join`:只输入正整数形式的数字房间码,成功后进入 `/r/{code}`。- `/r/{code}` 观看者:主区域最大化远端视频;顶部显示房间与连接状态;提供声音、全屏和重试控制,不要求额外邀请码或 viewer token。- 移动端:视频保持稳定宽高比,控制与状态移到视频下方,任何文字和按钮不得溢出或遮挡。-用户可见的非直播状态只使用“已停止分享”(分享端已结束当前发布)和“等待开始分享”(观看端等待发布)。房间寿命、媒体代次、换父和恢复等内部状态不得作为额外产品文案暴露。+两端默认只显示房间、媒体、核心连接状态和常用操作。一个不持久化的“显示连接详情”复选框按页展开信令、ICE/TURN、codec、RTT、丢包、编解码耗时及逐边统计;真实连接失败、音频缺失、持续画质受限和需要用户动作的告警始终可见,不能被该开关隐藏。分享者默认观看人数必须来自房间 roster,而不是只统计当前由 host 直连的媒体 child。++用户可见的非直播状态只使用“已停止分享”(分享端已结束当前发布)、“等待开始分享”(观看端等待发布)、“正在连接”与“正在恢复连接”。`room-closed` 显示“房间已关闭”或“房间已过期”,不得误写成“分享已结束”。房间寿命、媒体代次、换父和恢复等内部状态不得作为额外产品文案暴露。-按钮使用 `lucide-react` 图标并提供可访问名称和 tooltip。动态状态区域固定最小尺寸,避免连接状态变化导致布局跳动。+按钮使用 `lucide-react` 图标并提供可访问名称和 tooltip。动态状态区域固定最小尺寸,避免连接状态变化导致布局跳动。320、375 与 390 CSS px 下两个首屏动作仍须同排等宽、文字不溢出且触控高度至少 44 px;展开详情不遮挡视频或引入横向滚动。## 安全与故障边界diff --git "a/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md" "b/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"index db998ca1..381d910a 100644--- "a/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"+++ "b/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"@@ -12,6 +12,7 @@### P0 - 必须实现+- [ ] 首屏双入口:通过全站验证后,主工作区必须同等突出“开始分享”和“加入房间”两个主要动作,并用清楚的视觉分隔表达发送与接收;加入房间不能只藏在页头或次要链接中。点击后直接进入现有分享或房间码加入流程,不增加营销首页、模式向导或拓扑选择。- [ ] 简单房间:分享者获得纯数字房间码和 `/r/{code}` 链接;观看者也可在 `/join` 只输入房间码加入,链接不携带额外观看 token 或 fragment。启用持久受保护房间时,房间码从 `1` 开始自增;其他模式继续使用随机临时房间码防止枚举。- [ ] 免安装观看:桌面和手机观看者可直接通过浏览器链接进入、授权并播放,不依赖与分享端相同的桌面客户端。- [ ] 屏幕采集:分享者可主动选择显示器或应用窗口,开始、停止、临时暂停画面和切换分享来源。@@ -20,14 +21,16 @@- [ ] 分享端 fanout 硬上限:分享端任何时刻最多维护两条下游媒体边,包括加入、断线、换父和恢复过程。第三名及后续观看者由系统自动分配给通过验收的 peer-assisted 拓扑,必要时自动回退到部署已提供的可选 SFU;两者都不可用时才明确拒绝,不能隐藏地回退为分享端第三条连接。- [ ] P2P 优先:每条逻辑媒体边的 ICE 必须先尝试直接 UDP 路径,服务器不得默认中转可直连的媒体。一个或两个观看者优先直接连接分享端;更多观看者的 peer-assisted 行为须先通过 ADR-0004 的实验门槛。- [ ] NAT 兜底:每条 parent-child 边独立进行 ICE;生产环境必须提供 STUN、TURN/UDP 与 TURN/TCP candidates,通过优先级偏好直连和 UDP,同时允许无法使用 UDP 的网络选择 TCP,不能因为某条边的网络与其他边不同而静默失败。-- [ ] 质量档位:提供 1080p60(8 Mbps)、1080p30(5 Mbps)、720p30(3 Mbps)三档上限;分享期间可直接换档而不重新选择来源或重建健康连接。Peer-assisted 房间只允许这三个档位 ID,并把分享者当前选择同步给现有和后续 relay sender;普通 P2P 信令结构保持不变。保留 `contentHint = "motion"` 并显式设置 `degradationPreference = "balanced"`;该偏好允许浏览器在帧率和分辨率之间权衡,不保证清晰度优先,具体行为必须实测。自定义动态 FPS 或画面检测策略必须在统计证明有必要后再实现。+- [ ] 质量档位:提供 1080p60(8 Mbps)、1080p30(5 Mbps)、720p30(3 Mbps)三档上限;分享期间可直接换档而不重新选择来源或重建健康连接。Peer-assisted 房间只允许这三个档位 ID,并把分享者当前选择同步给现有和后续 relay sender;普通 P2P 信令结构保持不变。当前 `contentHint = "motion"` 与 `balanced` 只是测量基线;目标默认策略为可读性优先,并在高级设置中提供“清晰优先 / 平衡 / 流畅优先”。任何策略都只是浏览器偏好,必须显示实际结果和限制原因。自定义动态 FPS 或画面检测只在统计证明必要后实现。- [ ] 断线恢复:临时网络变化时尝试 ICE restart 和重连,并向用户显示当前连接状态。- [ ] 可观测性:采集候选类型、RTT、丢包、抖动、实际码率、帧率、编码耗时和质量受限原因。+- [ ] 渐进式诊断:分享者和观看者默认只看到房间、画面、核心状态和常用控制;候选路径、RTT、丢包、编解码器、编码耗时等技术详情由一个明确的“显示连接详情”开关展开。隐藏诊断不能隐藏失败原因、音频缺失、持续画质受限或需要用户操作的告警。- [ ] 访问控制:部署者可配置一个全站 `ACCESS_PASSWORD`;为空时网站公开,非空值必须为 1 至 128 个可见 ASCII 字符。配置时分享者和观看者都必须先登录。登录成功签发 12 小时、无服务端会话状态的 HttpOnly、`SameSite=Strict` cookie,建房 HTTP 和 WebSocket 都只使用该 cookie,不提供建房 Bearer 旁路;不引入账号、JWT、服务端 session Map 或 logout。- [ ] 持久受保护房间:`ROOM_DATABASE_PATH` 可选且必须与 `ACCESS_PASSWORD` 同时配置。两者都存在时,SQLite 只持久保存从 `1` 开始自增的房间 ID 与 host token 摘要;房间及链接不设过期时间,停止后分享端显示“已停止分享”,观看页显示“等待开始分享”。密码模式不配置数据库时仍使用临时房间;公开模式始终使用随机临时房间。### P1 - 重要功能+- [ ] 质量控制扩展:保留可立即理解的推荐档位作为默认入口,同时提供一个可选的高级设置区,让分享者在安全边界内实时调整分辨率、帧率、视频码率、质量优先级和音频模式而无需重选来源或重建健康连接。实际发送/接收质量持续明显低于所选上限时必须显示可解释的限制原因;在真实拥塞、编码器和接收端证据完成前,不把任一固定参数组合称为“完美平衡”。- [ ] Peer-assisted 媒体实验:分享端最多两个 child、每名 viewer 最多一个 child;信令服务只按深度和服务端加入序号确定性地形成两条 sticky 平衡链,不加入综合评分或主动重平衡。每个 viewer 将收到的标准 remote track 通过新的 `RTCPeerConnection` 转发,因此会逐跳解码和重编码;必须测量而不能称为 shared encode。服务端只在受房间数限制的内存状态中保存当前档位,不写入 SQLite;host 鉴权后先重报档位,在线 viewers 接收更新,后加入者从鉴权快照取得当前值。该功能在 ADR-0004 的实验门槛通过并由后续 ADR 正式接受前不得成为产品路径。- [ ] 原生 shared encode 分享端:后续独立的 Electron/原生分享端阶段必须保证一份兼容编码输出扇出到最多两套独立 WebRTC packetizer,并由单独 ADR 和测量约束。它降低分享端重复编码负载,但不消除每条出边各自的上传带宽。浏览器不保证跨 `RTCPeerConnection` 复用编码器,因此当前 Web spike 不实现、也不能宣称满足 shared encode 保证。- [ ] 原生 shared encode relay:具备原生 relay 能力的 audience 同样最多维护两条下游媒体边,并应让一份兼容编码输出供两条边复用。普通浏览器 audience 继续作为 leaf 或使用当前会逐跳重编码的实验路径,不伪称 shared encode。@@ -102,6 +105,7 @@### 质量和恢复+- Given 用户选择任一推荐档位或高级质量参数,When 接收端实际分辨率、帧率或码率持续显著低于该目标,Then 诊断数据能区分采集约束、发送编码、带宽/拥塞、TURN 路径和接收端限制;产品不得只改变档位标签却继续隐藏实际降级。- Given 受控 RTT/丢包测试条件,When 连续分享高动态游戏画面 30 分钟,Then 延迟、帧率与丢帧达到上述目标,且没有不可恢复的冻结。- Given 分享过程中切换 Wi-Fi/有线网络,When ICE 连接失败,Then 客户端触发 ICE restart,并在成功或超时后给出明确状态。- Given 浏览器未返回系统音轨,When 分享开始,Then 分享者在启播前看到“当前来源没有可共享音频”的提示。