Skip to content

iOS screen stream at --fps 60 drops frames that arrive slightly early #1717

Closed

Description

@V3RON

Split from #1551 (cause 2). Causes 1, 3 and 4 stay on #1551.

The problem

The encode loop at vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift:227 drops any frame that arrives less than one interval after the last frame sent. A frame that comes even slightly early is lost, and the next frame sent can be almost two intervals later. Both capture programs share this loop, so simulator and physical iPhone streams are both hit.

Reproduction

testAt60FpsASourceOfAtLeast60FramesASecondIsWrittenAt60FramesASecond in vendor/screen-capture/Tests/SimlockCaptureTests/EncodeLoopTests.swift, on branch bug/1551-repro (test only, no fix):

Source, --fps 60 Frames written Expected
100 a second for 2 s 100 120
90 a second for 2 s 90 120
60 a second, alternating 16.2 / 17.1 ms gaps, for 2 s 60 120
100 a second, a 1 s pause, then 100 a second 75 90

Fix

The grid from #1551: a deadline that moves one interval per frame sent, accepts a frame up to a quarter interval early, and never trails the clock by more than half an interval, so a pause doesn't end in a burst.

var deadline: UInt64 = 0
...
if started, frame.atNanos &+ intervalNanos / 4 < deadline { continue }
deadline = started ? max(deadline &+ intervalNanos, frame.atNanos &+ intervalNanos / 2) : frame.atNanos &+ intervalNanos

With it, the reproduction and all 11 tests in vendor/screen-capture pass.

Rejected: lowering the threshold to 0.75 of an interval (lets more than --fps through from a 100/s source); a grid with no catch-up clamp (bursts after a pause).

Measured on a real simulator

iPhone 17 Pro, iOS 26.5, Safari with a full-screen canvas redrawn on every requestAnimationFrame, --fps 60 --duration 20, builds alternating, host load under 10 on 10 cores:

Build Incoming fps Sent fps
before (3 runs) 58.0–58.4 36.6–37.9
after (4 runs) 57.6–58.5 57.7–58.5

All streams decode (unframed and checked with ffprobe). Without the fix, about 37% of a ~58/s source is dropped. With it, every frame that arrives is sent.

Not covered on hardware: a source faster than 60 a second (the iOS 26.4 Liquid Glass case in #1551). The unit test covers it, and the #1551 reporter measured 57–59 fps sent with this change, up from 50–52.

Written by an agent.

Activity

  1. added
    bug:ready
    on Nov 18, 2026
  2. self-assigned this
    on Nov 18, 2026
  3. V3RON commented on Nov 18, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1718 (#1717)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  4. added a commit that references this issue on Nov 19, 2026
    bc14ca0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions