Skip to content

Android screen streams send a key frame at least every 5 s through scrcpy's reset video #1601

Closed

Description

@V3RON

Part of #602.

Scope

After this PR an Android emulator's or a phone's stream sends a key frame at least every 5 seconds, also while the screen is still: the driver turns scrcpy's control channel on and sends reset video when no key frame came for 5 s.

If it goes wrong: Android streams fail to start (a control socket that hangs), or a still screen flickers every 5 s.

Technical spec

Commit 5e639b4.

Rows

  • Behaviours: B3, B4, B5
  • Interfaces: I4, I5
  • Existing code: X7, X8, X9, X13, X18, X14 (the Android screen manual's lines)

Facts

# Fact Source
F1 Measured on an API 35 emulator with the vendored scrcpy-server 5.0.1, control=true, 2026-11-16: a still screen sent 0 frames in 12 s; one byte 0x11 on the control socket gave a session packet, a config packet and a key packet within 0.1 s; 16 s of scrolling at the default interval sent no key packet, and with video_codec_options=i-frame-interval:int=5 one after about 10 s. a probe run in the spec session (Node, adb forward to localabstract:scrcpy_<scid>), output lines 14.0 --- RESET_VIDEO / 14.1 SESSION 324 x 720 / 14.1 CONFIG 32 / 14.1 KEY 7933
F2 The input module already runs a control-only server and reads and discards its control socket. src/drivers/android/input/device-input.ts:170-184, src/drivers/android/input/AGENTS.md
F3 scrcpy 5.0.1 parses control, power_on, clipboard_autosync and video_codec_options. v5.0.1:server/src/main/java/com/genymobile/scrcpy/Options.java:42,62,65,422-468
F4 The slow Android stream test reads frames through readScreenFrames. e2e/slow-android-stream.test.ts:57, e2e/helpers/screen-frames.ts:14

Modules touched

src/drivers/android/screen (session.ts, scrcpy-link.ts, their tests, the shared fixture test-session.ts, whose fake adb server sends a zero byte on every accepted socket today (src/drivers/android/screen/test-session.ts:131), and AGENTS.md), e2e/slow-android-stream.test.ts. Searches: control=false, connectScrcpySocket, ALIVE_AFTER_MS, SCRCPY_SERVER_VERSION.

Rules in play

  • ADR 0079 §5: Android's key-frame bound through reset video; power_on=false and clipboard_autosync=false keep "a stream changes no device setting" (src/drivers/android/screen/AGENTS.md), except a phone's existing stay-awake.
  • src/drivers/android/screen/AGENTS.md: a stream touches only its own scid; every adb command and connection goes through the target; close stays idempotent.

Tests

The seam is session.ts through session.test.ts, with a fake target, server and clock.

  • B3: the server starts with the control channel on, power_on=false, clipboard_autosync=false and i-frame-interval:int=2: the arguments; the control socket connected after the video's zero byte and before the video is read, not asked for a zero byte; a failed control connect; a phone's stay_awake; the control bytes discarded; the control socket ending before close.
  • B4: no key frame for 4 s sends reset video, leaving about 1 s for the emulator to answer it inside the 5 s promise: a still screen (reset at 4 s and 8 s); a key frame at 3 s (no reset at 4 s); a failed write; the session after a reset writes meta, description, key frame. B5's still phase counts key frames, not alive frames, since a 4 s reset leaves no 5 s silence. (decided in delivery, confirmed by the maintainer)
  • B5: a viewer of a still Android emulator gets a key frame at least every 5 s: measured from 15 s after the first key frame, a still home screen gives at least 4 key frames, no gap over 5.5 s (slow lane). A freshly booted emulator answers its first resets 2 to 5 s late, so a joiner in its first 15 s can wait up to about 9 s; the Android screen manual lists it as a Known gap. (decided in delivery, pending the maintainer)

Done when

  • pnpm test:changed passes, with the B3 and B4 cases in src/drivers/android/screen/session.test.ts.
  • Slow lane: scripts/slow-e2e.sh e2e/slow-android-stream.test.ts passes with the B5 case, on a real emulator, and its existing case still finds no server or jar left once the viewer goes.
  • src/drivers/android/screen/AGENTS.md names the control socket and the reset, drops the gap "Key frames come at scrcpy's default interval", and rewrites the rule line "scrcpy sends nothing for a still screen" to name the reset, keeping its alive frame rule.

Out of scope

  • The device input's own server: unchanged.

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 16, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 16, 2026
  3. self-assigned this
    on Nov 16, 2026
  4. V3RON commented on Nov 16, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: #1610 is built, audited and reviewed (round 1 on 09c3a0b, round 2 on 74bc0c7). Three blocking findings were fixed: the control-before-video order test, the false "within 15 s" start error, and copied values in the Android screen manual. It merged task/1600, which carries the iOS manual decision on #1600. The PR is ready in the #602 stack and labelled needs-hardware.

    Not done: Done when line 2, the slow-lane B5 case. Lane run 1 failed during lease setup (PROVISION_FAILED "Timed out waiting for device to boot") before any assertion. Run 2 was refused at 15.0 GiB free, where the lane needs 15.

    Findings: none open.

    Blocked on: a slow-lane run on a machine with room (/verify-hardware 1610). A boot timeout there again would need a look at the emulator, not this diff.

    Written by an agent.

  5. 6 remaining items

  6. self-assigned this
    on Nov 16, 2026
  7. V3RON commented on Nov 16, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: code, review (round 2 passed, 3 blocking fixed) and two hardware-fix runs on #1610 at 0395ac7. The reset fires after 4 s.

    Not done: the Android slow-lane line (B5 bound of 5.5 s between key frames, and no server or jar left).

    Findings: two lane runs on 2026-11-16 failed with the load average at 13 to 23, from tsc in another worktree and from Spotlight. Gaps were 7305/6419 ms and 8057/6547 ms; every other gap was 4.1 to 4.9 s. The hardware-fix run found no defect in the repo. The slow gaps are mostly the first one after the stream opens. If a quiet host still fails, look at the first reset.

    Blocked on: a slow-lane run on a quiet host (load under about 6): scripts/slow-e2e.sh e2e/slow-android-stream.test.ts, then a fix-check over 38e87bb..head. #1614 and #1617 sit above it in the stack.

    Written by an agent.

  8. added
    task:blocked
    and removed
    task:ready
    on Nov 16, 2026
  9. removed their assignment
    on Nov 16, 2026
  10. added
    task:ready
    and removed
    task:blocked
    on Nov 16, 2026
  11. self-assigned this
    on Nov 16, 2026
  12. added a commit that references this issue on Nov 16, 2026
    2ee1e5f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions