Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。
fix(media): preserve browser screen capture semantics (#229)
AAA0121b3a912a3
diff --git a/docs/project-memory.md b/docs/project-memory.mdindex 95421d43..b2f6ef4a 100644--- a/docs/project-memory.md+++ b/docs/project-memory.md@@ -18,7 +18,7 @@ Last updated: 2026-08-24- Ordinary peer ICE is STUN-only, and current LiveKit media is UDP-only. Credentials, room secrets, candidate details, and diagnostic data remain private and narrowly scoped. A future strict-firewall transport requires separate evidence and must remain inside LiveKit rather than becoming another Screener route candidate.- Browser peers use existing periodic WebRTC/LiveKit stats to maintain one exact-route decoded-progress timestamp. New frames or route/connection changes reset it; a non-paused deadline reports the edge once. Track availability, bitrate, FPS, resolution, freeze, RTT, jitter, loss, sender stats, and SFU layer describe only the current path: they remain framework or diagnostic inputs and cannot prove another parent would be better.- Browser capture requests available share audio by default on initial capture and source switch, with an explicit video-only warning when no audio track is returned. Its screen-audio control offers live-switchable 64/128/256 kbps sender ceilings and defaults to 128. The last-wins quality wire owns desired state; each endpoint serially applies and reads back current Host/relay/SFU audio senders, exposes local failures, and gives future senders the latest desired value. Opus remains fixed, and without an applied-ack wire the Host does not claim room-wide atomic convergence. These are configuration ceilings, not fidelity claims.-- The accepted Browser display-video behavior leaves `contentHint` unset so Chromium retains its screen-capture classification; returned audio tracks keep `contentHint = "music"`. Current v10 source and production still set video `motion` until the source change is integrated and deployed. The final Browser video codec remains undecided; v10 defaults to VP8 and retains the pre-share diagnostic selector, fixed for each share, until controlled game-load evidence supports one codec and the selector/wire can then be removed atomically. Actual codec/profile/encoder stats remain diagnostic only.+- Browser display video leaves `contentHint` unset in current source so Chromium retains its screen-capture classification; returned audio tracks keep `contentHint = "music"`. Production still sets video `motion` until this source change is deployed. The final Browser video codec remains undecided; v10 defaults to VP8 and retains the pre-share diagnostic selector, fixed for each share, until controlled game-load evidence supports one codec and the selector/wire can then be removed atomically. Actual codec/profile/encoder stats remain diagnostic only.- Recommended quality remains exactly `1080p60`, `1080p30`, and `720p30`, with the middle `1080p30` as the accepted default. `480p` means only an advanced `854x480` resolution choice whose FPS and bitrate remain independently selected; it is not a fourth recommended profile.- Two distribution artifacts are accepted only after the current feature, NAT, and real-network ledger is complete. A public-server one-click deployment package installs the current application plus STUN/SFU and proxy components on a user-owned server. A Windows/macOS/Linux local package runs the Host, application server, and local state on the broadcaster's machine without source, Node, or any external Screener/network service; it keeps workable direct P2P but reports the reachability loss imposed by public ingress, TLS, gateway, NAT, or firewall limits rather than promising universal connectivity.- Current UI, presence, route labels, and diagnostics describe observed state only; they do not create route authority.@@ -39,7 +39,7 @@ Last updated: 2026-08-24## Current Priority-1. Remove the Browser video `contentHint`, run focused capture/encode verification, and keep the final codec decision open until controlled game-load evidence is sufficient.+1. Deploy and physically validate the no-video-hint Browser source change, and keep the final codec decision open until controlled game-load evidence is sufficient.2. Diagnose screen audio and invitation UI, then finish background/mobile/network evidence at their stated boundaries; Native/executable, distribution, and repository-wide simplification remain later phases.## Working Rulesdiff --git a/docs/research/browser-background-capture.md b/docs/research/browser-background-capture.mdindex 82f2576e..8189c557 100644--- a/docs/research/browser-background-capture.md+++ b/docs/research/browser-background-capture.md@@ -49,13 +49,13 @@ main `2726edde9b87f31fd76e749de47972ef817a9bd5`. The current path does not claimimplement a page-keepalive mechanism, and deployment health supplies nophysical background-capture evidence.-- `src/client/media/quality.ts` obtains one `getDisplayMedia()` stream, applies- ideal/max capture constraints, currently marks video as `motion`, and applies sender- bitrate, frame-rate, and degradation ceilings. Explicit sharing pause and- authoritative reconnect re-pause change capture tracks' `enabled` state;- neither manufactures foreground activity.-- The accepted source change removes that video hint; production retains it- until a later deployment. Audio `contentHint = "music"` remains unchanged.+- Current `src/client/media/quality.ts` obtains one `getDisplayMedia()` stream,+ applies ideal/max capture constraints, leaves the video hint unset, and+ applies sender bitrate, frame-rate, and degradation ceilings. Production+ still marks video as `motion` until the source change is deployed. Explicit+ sharing pause and authoritative reconnect re-pause change capture tracks'+ `enabled` state; neither manufactures foreground activity. Audio+ `contentHint = "music"` remains unchanged.- `src/client/pages/HostPage.tsx` pauses the existing local preview video whenthe Host document is hidden or unfocused and resumes that preview when it isvisible and focused. This does not stop, mute, disable, or replace the capturediff --git a/docs/research/realtime-quality-adaptation.md b/docs/research/realtime-quality-adaptation.mdindex 57a591e5..aed8ae10 100644--- a/docs/research/realtime-quality-adaptation.md+++ b/docs/research/realtime-quality-adaptation.md@@ -706,10 +706,10 @@ guarantees the emitted resolution, frame rate, or bitrate.- A live profile change uses `track.applyConstraints()` and updates everycurrent sender with `RTCRtpSender.setParameters()`. It does not reopen thesource picker or renegotiate healthy peer connections.-- Current v10 source and production set video `contentHint = "motion"`; the- accepted source change removes that assignment so display capture retains- browser screen semantics. Recommended profiles and the advanced initial value- use `balanced`, with explicit `maintain-resolution` and+- Current v10 source leaves the video hint unset so display capture retains+ browser screen semantics; production still sets `contentHint = "motion"`+ until deployment. Recommended profiles and the advanced initial value use+ `balanced`, with explicit `maintain-resolution` and`maintain-framerate` choices. None promises an emitted resolution or rate.- `maxBitrate` and `maxFramerate` are ceilings. They are neither minimums nortarget guarantees, and the project does not use SDP bitrate hacks.diff --git a/docs/session-handoff.md b/docs/session-handoff.mdindex 84c9183f..1dc2cf61 100644--- a/docs/session-handoff.md+++ b/docs/session-handoff.md@@ -45,9 +45,10 @@ Current high-signal boundary:open/password/disabled code entry. Neither source nor production uses SQLite;exact rollback artifacts are owned by deployment.- Browser display video must leave `contentHint` unset; audio keeps `music`.- The final Browser video codec is not decided. Current source and production- remain v10, default VP8, with the diagnostic selector fixed for each share;- heterogeneous-network and SFU media evidence remains open.+ Current source implements that behavior; production still sets video `motion`.+ The final Browser video codec is not decided. Both remain v10, default VP8,+ with the diagnostic selector fixed for each share; heterogeneous-network and+ SFU media evidence remains open.- Ordinary browser ICE owns direct reachability. Do not build port prediction,guessed candidates, NAT classification, TCP probes, quality scores, orquality-driven reparenting. Current-path quality is diagnostic; a healthydiff --git a/docs/status.md b/docs/status.mdindex d2233fa8..4182ae4a 100644--- a/docs/status.md+++ b/docs/status.md@@ -12,6 +12,7 @@ This is the current execution index. Git history owns completed timelines; [veri- Production admits one Host plus 20 Viewers, applies endpoint capacity `2`, rejects stale Browser and executable-sender wires before room authority, and runs the one-controller exact-candidate route model with one staged total deadline. Rooms use random free four-digit codes, a 24-hour dormant lease, restart loss, local Host creation preferences, independent Viewer grants, and `open | password | disabled` code entry. LiveKit remains dedicated with `room.auto_create: false`, `max_participants: 21`, and global admission `1` publication ingress / `20` subscription egress.- Production media ports are STUN-only UDP 3478 and LiveKit UDP 7882; coturn TCP/TLS and relay ranges are disabled. The public Web ingress remains TCP 80/443; Node 8787 and LiveKit control/signaling 7880 are internal-only. These deployment facts do not close the real heterogeneous-network, SFU, mobile, or endurance evidence boundaries.- SFU subscribers reconcile Host screen publications across connect, activation, participant arrival, track publication, and reconnect. LiveKit runs at `warn`/Pion `error`, and the Screener unit waits boundedly for the same-host LiveKit control listener before startup. Postflight left the LiveKit namespace empty, so physical direct, peer-relay, and SFU behavior remains an open current-release gate.+- Production sets video `contentHint = "motion"` and audio `contentHint = "music"`; the no-video-hint source change is not deployed.## Current Source@@ -19,14 +20,14 @@ This is the current execution index. Git history owns completed timelines; [veri- Current source implements one Host plus up to `20` Viewers, one steady outbound media-copy cap for every non-server endpoint (default `2`, static `1/2/3`), and the process-memory room model with random four-digit codes, a default 24-hour dormant lease, exact-Host resume, restart loss, local Host preference replay, independent token invitations, `open | password | disabled` code entry, and no SQLite runtime.- One event-driven controller owns the committed graph and at most one room-serial child operation. It uses one deterministic candidate list/cursor and one total direct-then-SFU deadline; exact admission and physical resources remain charged through drain, and the pending candidate commits only after an exact-generation decoded-frame proof. A short-lived 100 ms stats observer proves only that candidate inside the existing deadline, while the 2-second sampler remains responsible for active-path diagnostics and decoded-frame stalls. Healthy edges remain sticky and current-path quality does not authorize reparenting.- Ordinary peer ICE is STUN-only and the only application fallback is the dedicated LiveKit SFU over UDP. SFU generations use explicit no-default ingress/egress capacities, exact `reserved | committed | draining` accounting, delete-plus-absence release, one Host publication, and exact Viewer subscription handles. No Screener TURN, ICE/TCP, media TCP, or TLS-relayed media route exists.-- Current source implements live 64/128/256 kbps audio-ceiling mutation for current and future Host/relay/SFU senders. Browser sharing defaults to VP8; `automatic | H.264 | VP8` is a temporary pre-share-only diagnostic input and remains fixed for the share lifetime. Ordinary Pause/Resume changes the existing tracks and Host SFU publication under the exact current Host session and `shareGeneration`.+- Current source leaves video `contentHint` unset and keeps audio `contentHint = "music"`. It implements live 64/128/256 kbps audio-ceiling mutation for current and future Host/relay/SFU senders. Browser sharing defaults to VP8; `automatic | H.264 | VP8` is a temporary pre-share-only diagnostic input and remains fixed for the share lifetime. Ordinary Pause/Resume changes the existing tracks and Host SFU publication under the exact current Host session and `shareGeneration`.- Current source implements typed first-frame Viewer presentation and recovery, Chinese user-facing route/access failures, privacy-safe failed-page export, authenticated Host-only on-demand route snapshots, neutral `ROOM_ACCESS_DENIED` room-code admission, and responsive entry controls.- Recommended quality remains exactly `1080p60`, `1080p30`, and `720p30`; current source defaults to `1080p30`. Advanced resolution adds `480p` as `854x480` without adding a fourth preset, and advanced FPS and bitrate remain independent.- Exact v10 runtime source `fdd5a4a529ff297f41c05ea3388bf484d76afe8f` passed 610 Web tests in 45 files, TypeScript typecheck, client/server production builds, the access/privacy gate, the 257-test SFU admission gate, production-dependency audit, and repository hygiene. Its one-Host/20-Viewer Chrome 151 loopback decoded every Viewer, propagated the selected VP8 settings, kept Host and relay fanout within cap `2`, captured all four current-child timing distributions, and observed no SFU publication. This is source, state-machine, build, privacy, and direct-loopback evidence, not public-network, SFU, mobile, physical audio/codec, H.264 performance, or Host-background evidence.## Current Milestone-1. Remove the Browser video `contentHint` and verify the resulting capture/encode behavior. The final Browser codec remains undecided; current source and production remain v10, default VP8, with the pre-share diagnostic selector fixed for each share.+1. Deploy and physically validate the no-video-hint Browser source change. The final Browser codec remains undecided; source and production remain v10, default VP8, with the pre-share diagnostic selector fixed for each share.2. Diagnose the reported screen-audio `1 kbps` readout and validate live audio ceilings, then refine the Host invitation controls without changing grant semantics implicitly.3. Reproduce the Host background/minimized report under controlled conditions while recording the actual negotiated codec.4. Finish representative ICE/STUN/SFU acceptance including mobile networks. Browser port prediction, NAT classification, TCP probing, fake page keepalive, and quality-driven reparenting remain outside the accepted model.@@ -42,6 +43,6 @@ This is the current execution index. Git history owns completed timelines; [veri## Current HoldThere is no active P0/P1 source or deployment hold. Current source and production run the postflight-clean-Browser v10 contract while the no-video-hint source change and final codec evidence remain pending. Audio, heterogeneous-network, SFU,+Browser v10 contract while the no-video-hint deployment and final codec evidence remain pending. Audio, heterogeneous-network, SFU,background, and mobile evidence remains open. Native/executable work and broad repository cleanupremain outside the current evidence boundary.diff --git a/docs/todo.md b/docs/todo.mdindex ce2c316c..61e2c56d 100644--- a/docs/todo.md+++ b/docs/todo.md@@ -6,7 +6,7 @@ Only items in **Now** are executable after their stated decision gate. A branch## Now-1. **Remove the Browser video content hint.** Stop assigning any video `contentHint` so display capture keeps the browser's screen semantics; retain audio `contentHint = "music"`. Verify the focused quality helper and a real `getDisplayMedia()` encode sample. This source-only change does not alter the v10 wire or decide the final codec.+1. **Deploy and physically validate the no-video-hint source.** Current source leaves video `contentHint` unset and retains audio `contentHint = "music"`; production still sets video `motion`. Deploy the source-only v10 change, then confirm real `getDisplayMedia()` capture and outbound stats on the production path. This does not decide the final codec.2. **Diagnose and physically validate live screen audio.** First reproduce the Host diagnostic remaining at `1 kbps` after switching the shared source, and distinguish stale/reset statistics from an actual RTP bitrate problem. The app already requests audio and supplies system/window audio hints; record the selected surface, returned audio track, sender/receiver counters, and audible result because the browser owns the picker and may still return video only. Then switch the 64/128/256 kbps ceilings across direct, browser-relay, and SFU paths, create a new edge, and switch source while checking route continuity and A/V synchronization. Do not infer fidelity or room-wide atomic convergence from configuration alone.3. **Redesign the Host invitation controls.** Replace the current raw-link-heavy block with a compact copy-first layout while preserving the accepted copy-link, copy-room-code, code-entry policy, rotate, and revoke actions. Keep the credential out of logs and request URLs; changing the copied credential length is blocked on the explicit product decision below.4. **Diagnose desktop Host background/minimized performance.** On the same machine, dynamic scene, direct Viewer, browser, and fresh share, compare foreground, occluded, minimized, and hidden states while recording the actual negotiated codec. Correlate capture settings/FPS, frames captured/encoded/sent/decoded, bitrate, `qualityLimitationReason`, encode time, browser/game CPU and GPU, and the existing local-preview pause boundary. Treat browser scheduling/throttling and codec effects as hypotheses until measured. Do not spoof page activity, add keepalive timers, or misuse Wake Lock; if current Chrome/Edge cannot preserve the accepted Host behavior through standard Web APIs, record that capability boundary before considering the packaged/native Host.diff --git a/docs/verification-status.md b/docs/verification-status.mdindex ffec6e9b..35ec41f6 100644--- a/docs/verification-status.md+++ b/docs/verification-status.md@@ -23,7 +23,7 @@ Capacity and routing entries below describe the exact tested source or release o- Chrome 151 synthetic `1/3/5/8` and 720p30 runs preserved bounded fanout and decoding. A `9461e20`-era three-Viewer rerun kept Host2/Browser Viewer1, decoded every Viewer, and recovered a hard first-level relay departure in 5,380 ms; it did not exercise quality-triggered MBB. Sixteen-Viewer cap2/cap3 loopbacks decoded all Viewers and a ten-second follow-up recorded guarded sender and aggregate Chromium CPU evidence, but resolution/FPS remained low and the ordinary-PC data cannot rank caps, select product policy, or prove sustainable heterogeneous-network quality. See [peer-assisted media](./research/peer-assisted-media.md).- Chrome 151 with local LiveKit 1.13.5/client 2.22.0 proved one SFU/UDP root after `q,f` -> `q,h`: decoded frames advanced 3 -> 23, rendered frames reached 26, Host used one edge, and leaves were clean. This is functional evidence only. See [low-server media routes](./research/low-server-media-routes.md).- Host A+B and authenticated P2P Viewer C evidence is sanitized, generation-bound, diagnostic-only, and closed for stale or ambiguous reports. Production can expose a Host-local current SFU `h` snapshot and clears it on publisher identity changes; raw media metadata is not retained. See [realtime quality adaptation](./research/realtime-quality-adaptation.md).-- Fresh Chrome 151 tab-capture probes identified two separate Browser boundaries. Removing video `contentHint = "motion"` changed VP8 from 14.93 fps at 428x208 to 29.73 fps at 1904x928 under the same 5 Mbps balanced setup. No-hint AMD H.264 remained about 14--16 fps with hundreds of outer rate-limiter drops, while the same MFT reached 29.93 fps under diagnostic Desktop SW BRC; OpenH264 was slower. The page cannot enable that Chromium field trial or select an adapter/MFT. No-hint VP8 used libvpx software and held about 30 fps in one- and two-sender loopback on the test machine, but the process CPU totals include capture and local decode and are not real-game or weaker-device evidence. The accepted change is therefore only to leave video hint unset; the final Browser codec remains undecided. See [realtime quality adaptation](./research/realtime-quality-adaptation.md), [Native H.264](./research/native-h264-hardware-decision.md), and [Native shared encode](./research/native-shared-encode-sender.md).+- Fresh Chrome 151 tab-capture probes identified two separate Browser boundaries. Removing video `contentHint = "motion"` changed VP8 from 14.93 fps at 428x208 to 29.73 fps at 1904x928 under the same 5 Mbps balanced setup. No-hint AMD H.264 remained about 14--16 fps with hundreds of outer rate-limiter drops, while the same MFT reached 29.93 fps under diagnostic Desktop SW BRC; OpenH264 was slower. The page cannot enable that Chromium field trial or select an adapter/MFT. No-hint VP8 used libvpx software and held about 30 fps in one- and two-sender loopback on the test machine, but the process CPU totals include capture and local decode and are not real-game or weaker-device evidence. Current source now leaves the video hint unset; production still sets `motion`. The final Browser codec remains undecided. See [realtime quality adaptation](./research/realtime-quality-adaptation.md), [Native H.264](./research/native-h264-hardware-decision.md), and [Native shared encode](./research/native-shared-encode-sender.md).- Native Windows 11 process audio is source-only and default-off. A retained run isolated the target by about 4018x and delivered 495 Opus packets to one Viewer; package download, game sync, Windows 10, and other routes remain open. See [ADR-0008](./adr/0008-window-scoped-audio-capture.md).## Open Proof Boundariesdiff --git a/src/client/media/quality.ts b/src/client/media/quality.tsindex cb87139e..c9e2a30c 100644--- a/src/client/media/quality.ts+++ b/src/client/media/quality.ts@@ -212,7 +212,6 @@ export async function captureDisplay(stream.getTracks().forEach((track) => track.stop());throw new Error("浏览器没有返回可分享的视频轨道");}- videoTrack.contentHint = "motion";for (const audioTrack of stream.getAudioTracks()) {audioTrack.contentHint = "music";}diff --git a/tests/quality.test.ts b/tests/quality.test.tsindex 011cfb8e..9cf66ca1 100644--- a/tests/quality.test.ts+++ b/tests/quality.test.ts@@ -96,7 +96,7 @@ describe("realtime quality controls", () => {systemAudio: "include",windowAudio: "window",});- expect(videoTrack.contentHint).toBe("motion");+ expect(videoTrack.contentHint).toBe("");expect(audioTrack.contentHint).toBe("music");});