Repository navigation
Description
Request: none
Problem
Every viewer of a device's screen starts its own capture on the worker (#593). Two people watching one device cost two capture programs on iOS (a second encoder) or two scrcpy servers on an Android emulator. Through a gateway each viewer also holds its own relay channel. A worker link carries at most 64 at once and the 65th waits, so many viewers crowd out agent-device calls to that worker.
A viewer that stops reading also slows its own capture to its pace, because nothing is ever dropped.
Who it is for
Operators and agents who watch the same device at once: a team following one agent's run, or a dashboard beside a person's console tab.
Outcome
- Any number of viewers of one device share one capture on its worker, whichever path they asked by (the device path or a lease path).
- A viewer that joins late sees a picture within 5 seconds, on a still screen too, on every platform: iOS simulator, iPhone, Android emulator and Android phone.
- A slow viewer misses frames instead of slowing the others.
- The capture stops when the last viewer leaves, or when the device stops or its lease ends, as today.
- A gateway sends one relayed stream per device (or per lease) to a worker, however many viewers it has.
How it works for the user
sequenceDiagram
participant A as Viewer A
participant B as Viewer B (joins later)
participant G as Gateway
participant W as Worker
participant D as Device capture
A->>G: GET /v1/stream/workers/w1/devices/d1
G->>W: relay /stream/devices/d1 (the only one)
W->>D: open the one capture
D-->>W: meta, parameter sets, key frame, deltas...
W-->>G: frames
G-->>A: frames
B->>G: GET the same device
Note over G: no second relay
G-->>B: headers (current size), meta, parameter sets
D-->>W: key frame (at most 5 s later)
G-->>B: key frame, then live frames
A-xG: A closes its tab
Note over G,W: B still watching, nothing stops
B-xG: B closes its tab
G-xW: relay ends, capture stops
Failure paths:
- The capture cannot start: every viewer that was waiting for it gets the same refusal (for example 503
STREAM_UNAVAILABLE). The next viewer tries a fresh capture. - The capture ends or fails mid-stream: every viewer's stream ends the same way. The console reopens a stream that ended with no reason, as today.
- A lease ends: every viewer gets the one last frame that says why, then the end.
- A viewer stops reading (a background tab, a slow link): it skips frames up to the next key frame. The others see no change.
What a person sees, before and after, with two console tabs on one leased simulator:
before: ps -ax | grep -c '[s]imlock-screen-capture' → 2
after: ps -ax | grep -c '[s]imlock-screen-capture' → 1
The second tab, opened on a still screen: today it shows a picture at once (its own capture). After this, it shows "starting" for at most 5 seconds, then the picture.
Examples
What a viewer that joins a running capture gets first (iOS or Android, H.264):
| The shared capture has sent so far | Today (own capture) | After |
|---|---|---|
| meta, parameter sets, key frame, 40 deltas | its own meta, parameter sets, key frame | meta, parameter sets, then nothing until the next key frame (≤ 5 s), then key frame and live |
| meta 494×720, …, meta 720×506 (a fold), parameter sets, key frame, deltas | its own capture at the current size | headers 720×506, meta 720×506, its parameter sets, the next key frame |
| nothing yet (still starting) | its own capture starting | waits for the same start as the first viewer, gets everything from meta on |
| an MJPEG capture (no H.264) | its own capture | meta, then the next picture: every MJPEG picture is whole |
| a lease end's last frame | — | the last frame, then the end |
What a viewer whose queue is full gets:
| Queued for it, then | After |
|---|---|
| deltas past the bound, a new delta arrives | queued deltas dropped, new deltas skipped until the next key frame |
| full, then a meta or parameter sets arrive | kept: they are never dropped |
| full, then the lease ends | the last frame is kept, then the end |
What could go wrong
- A viewer that joins on a still screen sees "starting" for up to 5 seconds instead of a picture at once. Likely, and by design.
- On Android a still screen restarts scrcpy's encoder every 4 seconds. If a device's encoder handles that badly, the picture could flicker or stall. Unlikely: the emulator check showed a clean new key frame within 0.1 s.
- A picture slightly softer while moving, because key frames come more often at the same bitrate. Mild.
- A bug in sharing would hit every viewer of a device at once, not only one.
- A viewer that joins a phone whose screen went dark (off its charger) sees no picture until the screen is on again. Rare.
Words used
- capture: the program on the worker that films one device's screen:
simlock-screen-capture(iOS simulator),simlock-device-capture(iPhone) or a scrcpy server (Android). - key frame: a whole picture a decoder can start from, e.g. tag
0x02. Every other picture (a delta, tag0x03) only says what changed since the frame before. - parameter sets: the decoder's setup (the
descriptionframe, tag0x01), sent once per encoder. A viewer needs it before its first key frame. - meta frame: the picture's codec and size (tag
0x05); a new one comes when the size changes. - reset video: scrcpy's control message 17, which restarts its encoder; a new session, parameter sets and a key frame follow within about 0.1 s (measured on an API 35 emulator).
- viewer queue: the frames read from the capture that one viewer has not taken yet.
Non-goals
- No viewer limit per device.
- No replay of the frames since the last key frame: a joiner waits for the next one.
- No on-demand key frame when a viewer joins; the 5-second bound is the only promise.
- No sharing between a device-path relay and a lease-path relay on a gateway: they are two relays to the worker, which still runs one capture.
- No change to the console or the frame envelope. The only HTTP change is one response header (I6).
- No wake of a phone that went dark mid-stream when a viewer joins.
Completion conditions
- Two viewers of one iOS simulator, one opened by its device path and one by its lease path, run one
simlock-screen-captureprocess on the worker. - Two viewers of one Android emulator run one scrcpy video server on it.
- A viewer that opens the stream of a still iOS simulator, a still Android emulator, while another viewer watches it, gets a key frame within 5 seconds.
- A viewer that stops reading for 30 seconds does not delay another viewer's frames, and gets a key frame once it reads again.
- Through a gateway, three viewers of one device hold one relay channel to the worker.
- The capture stops once the last viewer leaves, and when the lease ends every viewer gets the lease-end frame.
Open questions
none
Decisions
- ADR 0079 (PR docs(adr): propose 0079, one capture per device is shared and every capture sends a key frame every 5 s (#602) #1593) — One capture per device, shared on the worker and the gateway, with a key frame at least every 5 s: what is shared, what the gateway reads, the key-frame promise, what a slow viewer gets. Narrows ADR 0045 §5 and the stream rule that a gateway relays the body unread.
- ADR 0045 — A device's screen streams to operators: §5 already keys the shared capture by device; §4's ends stay.
- Maintainer: sharing on the worker and on the gateway.
- Maintainer: no limit on viewers per device.
- Maintainer: a late joiner waits for the next key frame, and every capture sends one at least every 5 s, still screens included.
- Decided in the session: a slow viewer drops frames up to its next key frame and is never cut off, because its queue is bounded (B7) and costs little.
- Decided in the session: the capture stops as soon as the last viewer leaves, as today, because the issue asks for it and the console reconnects within seconds anyway.
- Decided in the session, changed in delivery (confirmed by the maintainer): the Android driver sends reset video after 4 s with no key frame, so the emulator's answer lands inside the 5 s promise, and sets scrcpy's
i-frame-intervalto 2, because the emulator check showed scrcpy's interval counts frames at a nominal 60 fps and sends nothing on a still screen (0 frames in 12 s; no key frame in 16 s of scrolling at the default). - Decided in the session: iOS forces a key frame when 5 s of wall clock have passed since the last one, in the shared encode loop, because the encoder's own interval counts frames (
fps × 5), which is about 30 s on a still simulator, and its timestamps are a frame counter, so a duration limit would count frames too. - Decided in the session: a gateway shares a relay per worker and what the path names (a device, or the worker's lease id), because a gateway does not know a lease's device before the worker answers; the worker still runs one capture for both.
- Decided in the session: a shared relay is started with an abort controller of its own and the first viewer's tenant, because the first viewer leaving must not end it, and the worker's relay door serves any tenant as an operator.
- Maintainer: a gateway shares a relay only when the worker's answer says it sends a key frame at least every 5 s (I6); without it each viewer gets its own relay, as today, so a worker not yet updated never leaves a joiner on a blank screen.
- Maintainer: a phone that goes dark mid-stream (off its charger) is a known gap: a viewer that joins its capture waits with no picture until the screen is on again or the lease ends, where today its own capture would wake the phone.
- Decided in the session: the broadcast and the gateway read a meta frame's JSON (codec, size, fps) with the check a worker uses, because a joiner's headers must give the current size after a fold; a picture's bytes are never read.
- Decided in the session: a joiner's stream starts at a key frame: the server skips the pictures and
aliveframes before it and passes meta frames, parameter sets and the lease-end frame, so the console and other viewers need no change. - Decided in the session: a viewer queue holds at most 2 MiB (about 10 s at today's 1500 kbps), because that rides out a short stall without a drop and bounds a stuck viewer's memory.
Behaviours
| Id | Behaviour (invoker, action, what it sees) | Seam | Cases | Task |
|---|---|---|---|---|
| B1 | An iOS capture (simulator or iPhone) given frames writes a key frame at least every 5 s of frame time, still screen included; the first frame is still a key frame. | encodeLoop in vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift, through EncodeLoopTests.swift with fake frames |
idle-floor frames (5/s) for 12 s: key frames at 0 s, ≤ 5 s, ≤ 10 s; 30 frames/s for 12 s: the same; an encoder-chosen key frame at 3 s moves the next forced one to ≤ 8 s; a size change still gets meta, parameter sets and a key frame (existing test) | #1600 |
| B2 | A viewer of a still iOS simulator gets a key frame at least every 5 s. | slow lane, one simulator | still home screen for 15 s: ≥ 3 key frames, no gap over 5.5 s | #1600 |
| B3 | An Android stream starts its scrcpy server with the control channel on, power_on=false, clipboard_autosync=false and video_codec_options=i-frame-interval:int=2; the control socket is read and discarded. |
src/drivers/android/screen/session.ts, through session.test.ts with a fake target |
the server arguments (I4); the control socket is connected after the video socket's zero byte and before the video is read, and is not asked for a zero byte (a fake server that sends video only once both are accepted streams; one that sends no zero byte on the second socket does not hang); a failed control connect refuses the open; a phone keeps stay_awake=true, an emulator has none; the control socket's bytes are discarded; the control socket ending before close errors the body with the server's last output, as the video socket's end does |
#1601 |
| B4 | An Android stream with no key frame for 4 s sends reset video on the control socket, leaving about 1 s for the device to answer inside the 5 s promise (decided in delivery, confirmed by the maintainer); the new session's meta, parameter sets and key frame go out as a rotation's do today. | session.ts through session.test.ts with a fake clock and target |
still screen: one reset at 4 s, another at 8 s if none came; a key frame at 3 s: no reset at 4 s, next due at 7 s; a reset whose write fails errors the body; the session after a reset writes meta, description, key frame (existing envelope rule) | #1601 |
| B5 | A viewer of a still Android emulator gets a key frame at least every 5 s. | slow lane, one emulator | still home screen for 15 s: ≥ 3 key frames, no gap over 5.5 s | #1601 |
| B6 | Two or more viewers of one device on a worker, by the device path, a lease path or both, share one capture: one openScreen call; each gets 200 with the current meta in its headers, and a body that starts with the current meta frame, the current parameter sets, then frames from the next key frame. |
createWorkerStream (src/stream/create.ts) through create.test.ts with a fake ScreenOpener |
two device-path viewers; a device-path and a lease-path viewer; a second viewer while the first's open is still pending (one open, both answered from its meta); a joiner after a size change (headers and first meta give the new size); a joiner before any parameter sets; a joiner that gets a new meta frame and parameter sets before its first key frame (an Android reset): it gets both, then the key frame; a joiner waiting when the lease ends gets the lease-end frame; a later meta frame that fails the meta check errors every body with that check's message; an MJPEG capture (no wait for a key frame); a viewer refused by the device checks (agent on a device path, unknown device, not running) joins nothing | #1602 |
| B7 | A viewer that stops reading on a worker never delays the capture or another viewer: past 2 MiB queued it drops its queued frames and skips new ones up to the next key frame; meta, parameter sets and the lease-end frame are never dropped. | create.test.ts with a fake capture |
one viewer stalled while another reads 2,000 frames; the stalled one reads again and gets meta and parameter sets it missed, then a key frame; a full queue when the lease ends still ends with the lease-end frame; alive frames are dropped with deltas; an MJPEG viewer past the bound drops its queued pictures and takes the next one |
#1602 |
| B8 | On a worker the capture is closed once, when its last viewer leaves; a viewer that leaves while others watch closes nothing. | create.test.ts |
two viewers, the first leaves (no close), the second leaves (one close); a viewer with expiresAt reaches it (its stream ends, the capture goes on for the other); the last viewer's expiresAt passes (its body is cancelled, which leaves, and the capture closes once); every viewer leaves during the open (the open's signal aborts, what it attached is closed once); one leaves during the open and another stays (the open goes on) |
#1602 |
| B9 | A lease end or a device stop ends every viewer of the device the way it ends one today: each gets the lease-end frame when there is a reason, then the end; the reclaim waits for the one close. | create.test.ts |
lease end with three viewers (three bodies end with one ended frame each, one close); device.shutdown with two viewers (no frame); device.absence-detected on a leased device (device-lost frame once); a viewer that asks after the stop gets a fresh capture or DEVICE_NOT_RUNNING as today |
#1602 |
| B10 | A capture that fails to start refuses every viewer waiting for it with the same refusal; one that fails mid-stream errors every viewer's body; the next viewer starts a fresh capture. | create.test.ts |
start fails with ScreenUnavailableError (two viewers, 503 STREAM_UNAVAILABLE each, same message); start exceeds the start bound; mid-stream read error; silence bound passes (every body errors); the device stops during a shared start (DEVICE_STOPPED to each); after a failure a new viewer gets a new openScreen, also while an earlier viewer has not read its errored body |
#1602 |
| B11 | Two or more viewers of one device through a gateway share one relay to the worker per worker and target (a device, or the worker's lease id); a device-path and a lease-path viewer use one relay each. | createGatewayStream (src/stream/create.ts) through gateway-link.test.ts with a fake FleetPort |
three device-path viewers, one relay call; the lease's owner and an operator on one lease path, one call; a device-path and a lease-path viewer, two calls; an agent on a device path and an unknown worker are refused before joining (no call); a worker answer without simlock-stream-keyframe-ms (I6): two viewers one after the other get two relays, and two that came while the first head was awaited get two relays (the second started once that head arrived), each ended by its own viewer; a worker answer with it: shared; the gateway's own answer to its viewer carries no I6 |
#1603 |
| B12 | On a gateway a joiner, a slow viewer and the last viewer leaving behave as on a worker (B6–B8): the joiner gets headers from the relay's current meta, then meta, parameter sets and the next key frame; a slow viewer drops up to its next key frame; the relay's body is cancelled once, when its last viewer leaves; the first viewer leaving does not end it. | gateway-link.test.ts |
joiner after the relay's first key frame; joiner after a later meta frame; a stalled viewer while another reads; first viewer leaves, the second still gets frames; last leaves, the relay's request is aborted once; every viewer leaves while the relay still waits for the worker's head (its request is aborted once, nothing joins); the last viewer's expiresAt passes (the relay's request is aborted once) |
#1603 |
| B13 | A shared relay that is refused or fails refuses or ends every viewer waiting on it the same way; a body that breaks the frame envelope errors every viewer and ends the relay. | gateway-link.test.ts |
worker refusal 409 DEVICE_NOT_RUNNING to two viewers; WORKER_UNREACHABLE to two viewers; a relayed frame over MAX_FRAME_BYTES; a relayed frame of length 0; a relayed body whose first frame is not a meta frame; a later relayed meta frame that fails the meta check (each with I2's message to every viewer); the relay body ending (the lease-end frame then the end, to each) |
#1603 |
Stored state
| Id | What and where | Created, changed, deleted by | Listed or swept by | A restart mid-step leaves | Schema step | Task | Used by |
|---|---|---|---|---|---|---|---|
| S1 | A shared capture per device, in the worker's memory (src/stream/captures.ts): the capture slot, the broadcast (I1) and its viewers |
created by the first viewer that passes the device checks; a viewer joins or leaves, also while the open is pending (the start counts its waiters, and the last waiter leaving aborts the open); deleted when the broadcast's done settles (the last viewer left, or the source ended or failed) or the slot is stopped |
the lease end and the device events (stopOnDevice), as today |
nothing: the process is gone, the capture program ends when its stdin or socket closes, as today | none | #1602 | #1603 |
| S2 | A shared relay per worker and target, in the gateway's memory (src/stream/gateway-link.ts): the relayed response, its broadcast (I1), its abort controller |
created pending by the first viewer that passes the gateway's checks: its relay starts with an abort controller of its own, and viewers that come while its head is awaited wait on it as a group (the last waiter leaving aborts it); a head with I6: every waiter joins its broadcast and the entry stays for later viewers; a head without I6: the entry is deleted, the first waiter takes that relay as its own (its leaving then aborts it, as today), and every other waiter starts a relay of its own, unshared; deleted when the broadcast's done settles, or the relay is refused or fails (every waiter gets that answer) |
— | nothing: the relay channel closes with the process, and the worker's capture ends with it, as today | none | #1603 | — |
Interfaces
| Id | What | Shape and bounds | Errors and limits | Where | Task | Used by |
|---|---|---|---|---|---|---|
| I1 | The broadcast: one frame source shared by viewers. createBroadcast(source: CapturedStream): Broadcast; Broadcast.join(signal: AbortSignal): CapturedStream (its meta the current one; its close, its signal's abort and its body's cancel each leave, once); Broadcast.viewers: number; Broadcast.done: Promise<void>, settled once when the last viewer leaves (then the source is cancelled and closed) or the source ends or errors |
reads the source as fast as it delivers, whatever the viewers do; reads each meta frame's JSON with readScreenMeta (exported from framing.ts, the check a capture's first meta gets) and keeps it and the last parameter sets, never a picture's bytes; a joiner's body is the last meta frame, the last parameter sets (H.264 only), then every frame from the first key frame on, where before that key frame it skips 0x03, 0x04 and 0x06 and passes 0x01, 0x05 and 0x07 (MJPEG: no wait, every 0x03 is a whole picture); a viewer queue is bounded at MAX_VIEWER_QUEUE_BYTES = 2 MiB, past which it drops its queued 0x02/0x03/0x04/0x06 frames and skips new ones the way a joiner does (MJPEG: takes the next picture), keeping 0x01, 0x05, 0x07; the source's end ends every body after what is queued, its error errors every body with that error |
a frame the splitter (I2) refuses, or a later meta frame readScreenMeta refuses, errors every body with that message and settles done |
src/stream/broadcast.ts (new) |
#1602 | #1603 |
| I2 | The frame splitter: FrameSplitter.push(chunk: Uint8Array): Frame[], Frame = { tag: number; bytes: Uint8Array } (the whole frame, header included) |
reads the 4-byte length and the tag byte of every frame, and nothing else; a frame is at most MAX_FRAME_BYTES (8 MiB); the first frame must be a meta frame |
over the bound: The screen stream sent a frame of <n> bytes, over the 8388608 a frame may be; a length of 0: The screen stream's output is not a frame envelope; a first frame that is not meta: The screen stream does not begin with a meta frame; a later meta frame readScreenMeta refuses: its own messages (The screen capture's meta frame is not JSON, …names a codec this stream cannot carry: <codec>, …'s <name> is not a size a screen has: <value>) |
src/stream/framing.ts |
#1602 | #1603 |
| I3 | iOS key-frame bound: the encode loop forces a key frame when KEYFRAME_MAX_GAP_NANOS = 5 s of frame arrival time (frame.atNanos) have passed since the last key frame it wrote, whoever chose it |
the first frame stays forced; MaxKeyFrameInterval stays fps × 5 |
— | vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift |
#1600 | — |
| I4 | Android stream server arguments: control=false becomes control=true, plus power_on=false, clipboard_autosync=false, video_codec_options=i-frame-interval:int=2; the second socket of the scid is the control socket: connected right after the video socket's zero byte and before any video is read, because scrcpy sends no video until both are accepted; it gets no zero byte (scrcpy writes it on the first socket only), so connectScrcpySocket (scrcpy-link.ts) takes an option not to wait for one |
scrcpy v5.0.1 Options.java (control, power_on, clipboard_autosync, video_codec_options), v5.0.1:server/src/main/java/com/genymobile/scrcpy/device/DesktopConnection.java:66-88, v5.0.1:server/src/main/java/com/genymobile/scrcpy/Server.java:105-155 |
the control socket's connect shares the start budget (START_DEADLINE_MS); a connect that fails refuses the open as a video connect's failure does |
src/drivers/android/screen/session.ts, scrcpy-link.ts |
#1601 | — |
| I5 | Reset video: one byte 0x11 (scrcpy TYPE_RESET_VIDEO = 17) on the control socket, sent when RESET_VIDEO_AFTER_MS = 4,000 ms pass on the clock since the last key frame (or the session's start) |
the timer restarts on each key frame and after each reset | a failed write errors the body with The screen server's control socket failed: <reason> and closes the feed |
src/drivers/android/screen/session.ts |
#1601 | — |
| I6 | The key-frame promise header: a worker's stream answer carries simlock-stream-keyframe-ms: 5000, on both doors (local and relay); a gateway's answer to its viewer does not (the worker's StreamServiceOptions turn it on, the gateway's do not) |
the gateway shares a relay only when the header is exactly 5000; any other value or none is a worker that makes no promise; declared in STREAM_HEADERS for OpenAPI, optional, and described on the website's stream page |
none: without it the gateway relays per viewer, as today | src/stream/service.ts (streamResponse), src/stream/create.ts, src/stream/gateway-link.ts, src/stream/definition.ts:13-20 (STREAM_HEADERS), src/http/openapi.test.ts:405-410 (pins the 200's headers), website/src/content/docs/docs/using-devices/watching-the-screen.mdx |
#1603 | — |
Existing code
Commit 5e639b4.
Searches: beginOnDevice|stopOnDevice (4 files), openScreen (6), readScreenFeed (3), fleet.relay|relayPath (2), control=false|control=true (2: screen session.ts:256, input device-input.ts:180), MaxKeyFrameInterval|forceKeyframe (2 Swift files), awaitingKeyframe (1, ui/src/data/stream.ts), Each viewer is|#602|Two viewers in docs (5).
| Id | Code (path:line) | Today | With this feature | Handled by |
|---|---|---|---|---|
| X1 | src/stream/worker-link.ts:57-96 serve |
every request registers a slot and calls openScreen, and its viewer's abort releases its slot |
the first viewer opens; later viewers join the device's broadcast; a viewer's abort leaves it | B6, B8, #1602 |
| X2 | src/stream/captures.ts:47 running: Map<string, Set<Slot>> |
a set of slots per device, one per viewer | one slot per device, holding the shared capture (S1); stopOnDevice still stops it and waits for its close |
S1, B9, #1602 |
| X3 | src/stream/feed.ts:27-65 readScreenFeed |
one reader per capture, pull-based, with the start and silence bounds and the lease-end last frame | unchanged; its body is the broadcast's source, read by the broadcast alone | I1, B10, #1602 |
| X4 | src/stream/service.ts:123-156 endingAt |
wraps a viewer's body with its expiresAt deadline |
unchanged: it wraps a viewer's own body from join, so one viewer's deadline ends only that viewer |
B8, #1602 |
| X5 | src/stream/gateway-link.ts:53-62 serveDevice |
one fleet.relay per viewer, with the viewer's request.signal and tenant |
one relay per worker and target, with an abort controller of its own and the first viewer's tenant, once the answer carries I6; viewers join its broadcast | S2, B11, #1603 |
| X6 | src/stream/gateway-link.ts:151-160 fromResponse |
the body is relayed unread | a shared relay's body goes through the frame splitter (I2), which reads lengths and tags, and through the broadcast (I1), which reads meta frames' JSON; a picture's bytes are never read | I2, B13, #1603 |
| X7 | src/drivers/android/screen/session.ts:251-268 |
control=false, no codec options |
I4's arguments; a control socket; the reset timer (I5) | B3, B4, #1601 |
| X8 | src/drivers/android/screen/session.ts:376 started on the first key frame, ALIVE_AFTER_MS 5 s |
alive frames after 5 s of quiet |
unchanged; the reset timer runs beside it and a reset's key frame resets the alive timer as any frame does | B4, #1601 |
| X9 | src/drivers/android/screen/envelope.ts:30-73 |
a scrcpy session event writes a new meta frame, then the description before the next picture | unchanged: a reset's new session goes through it | B4, #1601 |
| X10 | vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift:223 forceKeyframe = !started, H264Encoder.swift:212 MaxKeyFrameInterval fps * 5, H264Encoder.swift:96-97 timestamps from a frame counter |
a key frame forced only first; the encoder's own interval counts frames | I3: also forced after 5 s of arrival time | B1, #1600 |
| X11 | vendor/screen-capture/Sources/simlock-device-capture/DeviceScreenSource.swift:648-655 keepAlive |
a still iPhone's last picture is fed every 200 ms | unchanged: it is what lets I3 fire on a still iPhone | B1, #1600 |
| X12 | ui/src/data/stream.ts:100-104, 184-190 |
the decoder starts with awaitingKeyframe = false, needs a description first |
unchanged: a joiner's body (I1) starts with a description and its first picture is a key frame | B6 |
| X13 | src/drivers/android/input/device-input.ts:180 |
the input's own control-only server per lease, its own scid | unchanged: the stream's control socket is another scid's | B3 |
| X14 | src/stream/AGENTS.md (Gateway: "relays the body unread"; Known gaps: "Each viewer is its own capture", "A frame skipped by a slow viewer is not dropped"), src/drivers/android/screen/AGENTS.md (rules "changes no device setting", "scrcpy sends nothing for a still screen"; gaps "Key frames come at scrcpy's default interval", "Two viewers of one lease"), src/drivers/ios/AGENTS.md ("Two viewers ask for two streams (#602)") |
describe one capture per viewer | the gaps go; the gateway rule says it reads lengths, tags and meta frames, never a picture; the Android rules name the control socket and the reset; a new Android gap: a phone that went dark mid-stream leaves a joiner with no picture | #1600, #1601, #1602, #1603 |
| X15 | website/src/content/docs/docs/using-devices/watching-the-screen.mdx:78 "Each viewer is a separate capture." |
says two tabs capture twice | viewers share one capture; a joiner can wait up to 5 s for its picture; a slow viewer skips frames; a phone that went dark off its charger shows no picture to a viewer that joins | #1602 |
| X16 | docs/internal/adr/0045-a-devices-screen-streams-to-operators-not-a-leases.md §5 |
"One capture per viewer, as today", left to #602 | narrowed by ADR 0079 | ADR 0079 |
| X17 | src/link/index.ts:32,125-139 OPEN_LIMIT = 64, the 65th openChannel waits |
each viewer through a gateway holds one | one per shared relay (S2) | B11, #1603 |
| X18 | src/drivers/android/screen/scrcpy-link.ts:93-100 connectScrcpySocket |
retries until the socket's first byte is 0 | an option skips the wait, for the control socket (I4) | B3, #1601 |
| X19 | src/drivers/android/screen/session.ts:152 #wakeIfOff at open |
a second viewer's own open wakes a dark phone | a joiner opens nothing, so a dark phone stays dark (Decisions) | X14, X15 |
Tasks
flowchart LR
A["#1600 iOS key frames"] --> D["#1603 gateway relay sharing"]
B["#1601 Android key frames"] --> D
C["#1602 worker capture sharing"] --> D
- iOS screen streams send a key frame at least every 5 s, still screens included #1600 iOS screen streams send a key frame at least every 5 s — a new decoder on an iOS simulator or iPhone gets a picture within 5 s, still screen included. Risk: a still simulator shows a new viewer its picture late, or the moving picture gets softer.
- Android screen streams send a key frame at least every 5 s through scrcpy's reset video #1601 Android screen streams send a key frame at least every 5 s — the same on an emulator or phone, through scrcpy's reset video. Risk: Android streams fail to start, or a still screen flickers every 5 s.
- Viewers of one device on a worker share one capture #1602 Viewers of one device on a worker share one capture — two tabs on one device run one capture program. Risk: every viewer of a device breaks at once, or a capture runs on with no viewer.
- Viewers through a gateway share one relayed stream per worker and target #1603 Viewers through a gateway share one relayed stream — many viewers hold one link channel to the worker. Risk: every gateway viewer breaks at once, or a relay stays open with no viewer.
Completion conditions:
- One
simlock-screen-capturefor two iOS viewers (device and lease path): Viewers of one device on a worker share one capture #1602 (B6). - One scrcpy video server for two Android viewers: Viewers of one device on a worker share one capture #1602 (B6).
- A key frame within 5 s for a joiner on a still iOS simulator and a still Android emulator: iOS screen streams send a key frame at least every 5 s, still screens included #1600 (B2), Android screen streams send a key frame at least every 5 s through scrcpy's reset video #1601 (B5), with Viewers of one device on a worker share one capture #1602 (B6).
- A stalled viewer does not delay another and gets a key frame when it reads again: Viewers of one device on a worker share one capture #1602 (B7).
- Three gateway viewers hold one relay channel: Viewers through a gateway share one relayed stream per worker and target #1603 (B11).
- The capture stops with the last viewer, and every viewer gets the lease-end frame: Viewers of one device on a worker share one capture #1602 (B8, B9).
Open work in the same area:
- feat(console): watch running device screens side by side #1256 (console: running screens side by side, open PR): adds viewers in the console, and benefits from sharing; it touches
ui/only, so no Depends on. - iOS Simulator screen stream: ROCKit invalid-connection fault storm and multi-second stalls #1583 (iOS ROCKit fault storm with two capture programs): sharing may remove its trigger; a bug, not a dependency.
- Shared helper: errorMessage for the error-message unwrap #1442 (shared
errorMessagehelper, another feature'stask:draft): rewrites one line ingateway-link.tsfromResponse(Viewers through a gateway share one relayed stream per worker and target #1603) and removeserrorMessagefromscrcpy-link.ts(Android screen streams send a key frame at least every 5 s through scrcpy's reset video #1601). No Depends on either way: it is a draft, and its change is one line per site, so whichever lands second merges main in. - iOS screen stream at --fps 60 delivers 55-57 distinct app frames/s while the simulator composites at 115+/s #1551 (iOS 60 fps frame pacing): the same encode loop as iOS screen streams send a key frame at least every 5 s, still screens included #1600 (
Lifecycle.swift); no PR is open, so no Depends on. Whichever lands second merges main in.
Written by an agent.
Activity
feat(stream): a leased simulator's or emulator's screen, streamed to …
V3RON commentedon Nov 16, 2026
Design posted: the business sections were rewritten from the spec session. Decisions, Behaviours B1–B13, Stored state S1–S2, Interfaces I1–I5 and Existing code X1–X17 were added. ADR 0079 is proposed in #1593.
Written by an agent.
V3RON commentedon Nov 16, 2026
Spec updated: the design was approved, ADR 0079 accepted (not yet implemented), and tasks #1600, #1601, #1602 and #1603 written; the Tasks section is filled and the T cells name them.
Written by an agent.
V3RON commentedon Nov 16, 2026
Delivery run
Merged: none. The stack #1593 → #1606 → #1610 → #1614 → #1617 is complete and ready, and it merges together once the slow lane passes.
Parked: #1600 — needs-hardware: #1606's slow-lane B2 case did not run (the disk was below the lane's 15 GiB), #1601 — needs-hardware: #1610's slow-lane B5 case failed once in emulator boot, before any assertion, then could not start at 15.0 GiB free
Waiting: #1602 (#1614) and #1603 (#1617) — on the stack; #1617's three device Completion conditions wait on #1606 and #1610
Decided: #1600 — iOS manual's "every 5 s" against documentation rule 7 → the manual states the rule without the period, #1602 — a viewer arriving after every viewer left during the open → a fresh capture
Also: #1608 (review inputs missed the feature for
feature/<N>-adrbranches) was opened and fixed on main by #1611. ADR 0079 still needs its flip to Accepted when the stack merges.To finish: free disk space, run
/verify-hardware 1606and/verify-hardware 1610, then/deliver 602.Written by an agent.
V3RON commentedon Nov 16, 2026
Delivery run
Merged: none (the stack #1593 → #1606 → #1610 → #1614 → #1617 stays open)
Parked: #1601 — Android slow lane fails under host load (load average 13 to 23); gaps 7305 and 8057 ms > 5.5 s, no repo defect found; needs a quiet-host run, then a fix-check
Waiting: #1602, #1603 — reviewed and in the stack, waiting on #1601
Written by an agent.
docs(adr): propose 0079, one capture per device is shared and every c…
github-actions commentedon Nov 16, 2026
Closing: all 4 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on
main. Flip its ADRs to Accepted if delivery has not.feat(stream): viewers of one device on a worker share one capture (#1614
feat(stream): viewers through a gateway share one relay (#1617)
V3RON commentedon Nov 16, 2026
Delivery run
Merged: #1593 (ADR 0079, now Accepted), #1606 (#1600), #1610 (#1601), #1614 (#1602), #1617 (#1603), as one stack into main (c382493)
Parked: none
Waiting: none
Decided: #1600 — the iOS manual's "every 5 s" against documentation rule 7 → the manual states the rule without the period, #1602 — a viewer arriving after every viewer left during the open → a fresh capture, #1601 — reset at 5 s plus about 1 s of emulator latency broke the 5 s promise → reset after 4 s (confirmed by the maintainer), #1601 — a fresh emulator answers its first resets 2 to 5 s late → the slow test measures from 15 s after the first key frame, and the Android manual lists it as a Known gap (pending the maintainer)
The slow lane ran with
SIMLOCK_SLOW_MIN_FREE_GIB=5at the maintainer's request. The run also opened #1608 (review inputs forfeature/<N>-adrbranches), which #1611 fixed.Written by an agent.