Fix CI: recordings keep to 60 fps, the battery has room for its time left
Deploy to the handset / build-and-deploy (push) Successful in 2m3s
CI / test (push) Successful in 3m5s

- Recorder: a 12 ms gap let through 83 frames a second. Frames now come due every 60th of a
  second, with room for a 60 Hz screen's jitter.
- Battery: the handset change shrank it to 76 px everywhere, too narrow for the time left. It is
  104 px again, and 76 only on a compact panel.
- Tests: recording is timed from its first frame, the failed launch doesn't depend on the apps
  installed, and the scene test waits for notices and clocks to settle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 23:20:00 -08:00
1 parent 4e6a8005dd
commit d1d1bb398c
6 files changed
+63 -14

No files matched your search

+39 -10
View File
@@ -36,8 +36,9 @@ pub(all) struct Recording {
/// itself; a host with a frame recorder keeps its own).
mut pending : Bytes
mut sent : Int
/// When the last frame was taken, and the pointer position drawn into it.
mut last_grab : UInt64
/// When the next frame is due (monotonic microseconds), and the pointer position drawn into the
/// last one.
mut due_us : UInt64
mut grab_px : Int
mut grab_py : Int
/// A drawn frame not recorded yet (too soon after the last one, or the queue was full).
@@ -47,11 +48,39 @@ pub(all) struct Recording {
mut frames : Int
}
///| Frames a second recorded at most, and the gap that makes.
///| Frames a second recorded at most.
let rec_fps : Int = 60
///| How early a frame may come, in microseconds: a screen's frames at 60 Hz jitter by a few ms.
let rec_early_us : UInt64 = 4667UL
///| When the next frame is due after one taken at `now` (microseconds) that was itself due at `due`:
/// a 60th of a second on. One taken early doesn't bring the next forward, so the average stays
/// within `rec_fps`; one taken late starts the count over, so a stall isn't made up in a burst.
fn rec_next_due(due : UInt64, now : UInt64) -> UInt64 {
(if due > now { due } else { now }) + 1000000UL / rec_fps.to_uint64()
}
///|
let rec_gap_ms : UInt64 = 12UL
test "recording takes at most 60 frames a second, and all of a jittery 60 Hz screen's" {
let run = fn(times : Array[UInt64]) {
let mut due = 0UL
let mut n = 0
for t in times {
if t + rec_early_us >= due {
due = rec_next_due(due, t)
n = n + 1
}
}
n
}
// A changed picture every 5 ms for ten seconds.
let n = run(Array::makei(2000, i => 1000000UL + i.to_uint64() * 5000UL))
assert_true(n >= 595 && n <= 601)
// A 60 Hz screen, every other frame 3 ms late: none is dropped.
let jittery = Array::makei(600, i => 1000000UL + i.to_uint64() * 16667UL + (if i % 2 == 1 { 3000UL } else { 0UL }))
assert_eq(run(jittery), 600)
}
///| Screen recording done by the host that draws the screen: `grab` copies a rectangle of the
/// screen (with the pointer at a screen position when asked) into the host's queue, stamped with
@@ -191,7 +220,7 @@ fn ChandraCompositor::start_recording(self : ChandraCompositor, r : @scene.Rect)
header_sent: 0,
pending: Bytes::from_array([]),
sent: 0,
last_grab: 0UL,
due_us: 0UL,
grab_px: -1,
grab_py: -1,
dirty: true,
@@ -218,7 +247,7 @@ fn ChandraCompositor::end_recording(self : ChandraCompositor, error : String?) -
if streaming && error is None {
// One more frame with the time now, so the last picture lasts until the stop.
rec.dirty = true
rec.last_grab = 0UL
rec.due_us = 0UL
self.take_recording_frame(rec, @sys.monotonic_ms())
match self.frame_recorder {
Some(host) =>
@@ -379,11 +408,11 @@ pub fn ChandraCompositor::recording_frame_drawn(self : ChandraCompositor) -> Uni
}
}
///| Take the screen's current frame into the recording, unless the last one was taken less than
/// a 60th of a second ago or the previous frame is still going out (it stays `dirty` then, and
///| Take the screen's current frame into the recording, unless it would make more than
/// `rec_fps` a second or the previous frame is still going out (it stays `dirty` then, and
/// `recording_tick` takes it as soon as it can).
fn ChandraCompositor::take_recording_frame(self : ChandraCompositor, rec : Recording, now : UInt64) -> Unit {
if rec.last_grab > 0UL && now - rec.last_grab < rec_gap_ms {
if now * 1000UL + rec_early_us < rec.due_us {
return
}
let px = self.ptr_x.to_int()
@@ -413,7 +442,7 @@ fn ChandraCompositor::take_recording_frame(self : ChandraCompositor, rec : Recor
}
if taken {
rec.dirty = false
rec.last_grab = now
rec.due_us = rec_next_due(rec.due_us, now * 1000UL)
rec.grab_px = px
rec.grab_py = py
rec.frames = rec.frames + 1