Scrubbing accelerates on long videos

This commit is contained in:
Brahim Hadriche committed 2026-07-08 09:16:46 -04:00
1 parent bcd88e0ad4
commit fb331507e5
6 files changed
+139 -9

No files matched your search

@@ -15,8 +15,8 @@ import "pkg:/components/VideoPlayerDev/TransportController.bs"
namespace PlayerInvariants
' Snapshot keys: transportMode, glyph, scanLevel, scanDir, scrubHeldDir, cursorMs, positionMs, durationMs,
' edgeMs, liveOffsetMs, atLiveEdge, isLive, replayPending.
' Snapshot keys: transportMode, glyph, scanLevel, scanDir, scrubHeldDir, scrubHoldTicks, scrubStepMs,
' storyboardStepMs, cursorMs, positionMs, durationMs, edgeMs, liveOffsetMs, atLiveEdge, isLive, replayPending.
function CheckBrain(s as object) as object
hi = s.durationMs
if s.isLive
@@ -57,6 +57,18 @@ namespace PlayerInvariants
return Fail("INV-B6")
end if
' INV-B9 — the hold-accel scratch is bounded: the tick count never goes negative and the per-tick
' step stays within [storyboardStepMs, the duration-scaled cap] (same formula the brain ramps to).
if s.scrubHoldTicks < 0
return Fail("INV-B9")
end if
if s.scrubStepMs < s.storyboardStepMs
return Fail("INV-B9")
end if
if s.scrubStepMs > TransportController.ScrubHoldCapMs(s.durationMs, s.storyboardStepMs)
return Fail("INV-B9")
end if
' INV-B4 — the glyph is legal for the current mode.
if not GlyphOkForMode(s.transportMode, s.glyph)
return Fail("INV-B4")
@@ -94,7 +106,7 @@ namespace PlayerInvariants
' The brain INV ids this module enforces — the meta-test pins this set against the VideoPlayerDev README so a
' catalog row can't be added without an implementation (or vice-versa).
function BrainIds() as object
return ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8"]
return ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8", "INV-B9"]
end function
end namespace
@@ -2,7 +2,8 @@
' No SceneGraph node, no Video node, no device clock: the suite seeds content, pushes commands, and
' fires timers by calling Tick() directly (the controller publishes the schedule; here we are the clock).
' Every behavior is asserted, including the input x mode matrix (not just each mode's happy path):
' - scrub enter/step/hold/commit/cancel; scan ladder/wrap/flip/cadence/clamp/commit.
' - scrub enter/step/hold (with the duration-scaled acceleration ramp)/commit/cancel; scan
' ladder/wrap/flip/cadence/clamp/commit.
' - LIVE: Left/Right = +/-5s frozen step (scrubRepeat); Rev/Fwd = 3-level scan LADDER (scan timer) climbing
' L1->2->3->1, reverse clamps at the DVR floor, forward auto-resumes at the edge; offset counts up frozen.
' - LIVE step<->ladder sub-mode transitions clear the other sub-mode's scratch (no stale-tick bleed).
@@ -117,6 +118,57 @@ namespace Tests
m.assertEqual(m.t.cursorMs, 66000)
end function
@it("hold acceleration: flat through the ramp delay, then the step grows to the duration-scaled cap")
function _()
' 10h VOD: 36000000ms is exactly representable in single precision, so Sqr is exact and the
' cap is deterministic: 61 * Sqr(36000000) = 61 * 6000 = 366000ms per tick.
m.t.OnDuration(36000000)
m.t.HandleKey(TransportController.Command.Right, true) ' keydown -> 62000
' the first RAMP_DELAY ticks step the flat grid (the fine-adjust window).
for i = 1 to TransportController.SCRUB_HOLD_RAMP_DELAY_TICKS
m.t.Tick(TransportController.Timer.ScrubRepeat)
end for
m.assertEqual(m.t.cursorMs, 62000 + TransportController.SCRUB_HOLD_RAMP_DELAY_TICKS * 2000)
m.assertEqual(m.t.scrubStepMs, 2000)
' the next tick starts the ramp: the step grows, monotonically, never past the cap.
prev = m.t.scrubStepMs
for i = 1 to 150
m.t.Tick(TransportController.Timer.ScrubRepeat)
m.assertTrue(m.t.scrubStepMs >= prev, "the hold step must never shrink mid-hold")
m.assertTrue(m.t.scrubStepMs <= 366000, "the hold step must never exceed the cap")
prev = m.t.scrubStepMs
end for
m.assertEqual(m.t.scrubStepMs, 366000) ' saturated at the cap
end function
@it("hold acceleration: releasing and re-pressing restarts the ramp at the flat grid step")
function _()
m.t.OnDuration(36000000)
m.t.HandleKey(TransportController.Command.Right, true)
for i = 1 to 30 ' well into the ramp
m.t.Tick(TransportController.Timer.ScrubRepeat)
end for
m.assertTrue(m.t.scrubStepMs > 2000)
m.t.HandleKey(TransportController.Command.Right, false) ' release
before = m.t.cursorMs
m.t.HandleKey(TransportController.Command.Right, true) ' fresh press
m.assertEqual(m.t.scrubStepMs, 2000) ' ramp restarted
m.assertEqual(m.t.cursorMs, before + 2000) ' the fresh press steps the flat grid
end function
@it("hold acceleration: an unknown duration never accelerates (the cap floors at the grid step)")
function _()
t = new TransportController.Controller()
t.SetContent(false, 2000, true)
t.OnPosition(0)
t.OnReady() ' duration never learned
t.HandleKey(TransportController.Command.Right, true)
for i = 1 to 50
t.Tick(TransportController.Timer.ScrubRepeat)
end for
m.assertEqual(t.scrubStepMs, 2000)
end function
@it("keyUp stops the hold-repeat and clears the glyph")
function _()
m.t.HandleKey(TransportController.Command.Right, true)
@@ -49,6 +49,9 @@ namespace Tests
scanLevel: t.scanLevel
scanDir: t.scanDir
scrubHeldDir: t.scrubHeldDir
scrubHoldTicks: t.scrubHoldTicks
scrubStepMs: t.scrubStepMs
storyboardStepMs: t.storyboardStepMs
cursorMs: t.cursorMs
positionMs: t.positionMs
durationMs: t.durationMs
@@ -238,7 +241,8 @@ namespace Tests
function _()
good = {
transportMode: TransportController.Mode.Idle, glyph: TransportController.Glyph.None
scanLevel: 0, scanDir: 0, scrubHeldDir: 0, cursorMs: 1000, positionMs: 1000
scanLevel: 0, scanDir: 0, scrubHeldDir: 0, scrubHoldTicks: 0, scrubStepMs: 2000
storyboardStepMs: 2000, cursorMs: 1000, positionMs: 1000
durationMs: 600000, edgeMs: 0, liveOffsetMs: 0, atLiveEdge: true, isLive: false, replayPending: false
}
m.assertTrue(PlayerInvariants.CheckBrain(good).ok, "good snapshot should pass")
@@ -250,6 +254,9 @@ namespace Tests
m.assertEqual(m.Break(good, "scanDir", 2).failed, "INV-B5")
m.assertEqual(m.Break(good, "scanLevel", 1).failed, "INV-B5") ' level>=1 but mode=idle
m.assertEqual(m.Break(good, "scrubHeldDir", 5).failed, "INV-B8")
m.assertEqual(m.Break(good, "scrubHoldTicks", -1).failed, "INV-B9")
m.assertEqual(m.Break(good, "scrubStepMs", 1000).failed, "INV-B9") ' below the storyboard step
m.assertEqual(m.Break(good, "scrubStepMs", 99999999).failed, "INV-B9") ' above the duration cap
' INV-B6 needs BOTH held scratch non-zero.
bleed = {}
@@ -259,7 +266,7 @@ namespace Tests
m.assertEqual(PlayerInvariants.CheckBrain(bleed).failed, "INV-B6")
' the catalogued id set is pinned (the VideoPlayerDev README must match BrainIds).
m.assertEqual(PlayerInvariants.BrainIds(), ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8"])
m.assertEqual(PlayerInvariants.BrainIds(), ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8", "INV-B9"])
end function
' ---------- meta: the model accounts for EVERY mutable brain field (no unmodeled axis) ----------
@@ -275,7 +282,7 @@ namespace Tests
' FSM AXES — discrete state the exhaustive matrix enumerates + the invariants constrain.
axes = ["transportMode", "glyph", "scanLevel", "scanDir", "scrubHeldDir", "atLiveEdge", "isLive", "ready", "hasStoryboards", "replayPending", "seekSettling"]
' CONTINUOUS — equivalence-classed by the guard predicates (cursor/edge/duration compares), not enumerated.
continuous = ["cursorMs", "positionMs", "durationMs", "edgeMs", "liveOffsetMs", "storyboardStepMs", "replayTargetMs", "dvrWindowMs", "liveMinGapMs", "liveMinCandidateMs"]
continuous = ["cursorMs", "positionMs", "durationMs", "edgeMs", "liveOffsetMs", "storyboardStepMs", "scrubHoldTicks", "scrubStepMs", "replayTargetMs", "dvrWindowMs", "liveMinGapMs", "liveMinCandidateMs"]
' OUTPUT / IO scratch — drained by the coordinator, not state the FSM branches on.
io = ["videoIntent", "intentSeq", "commitSeq", "finishSeq", "timerCmdAction", "timerCmdId", "timerCmdDelayMs", "timerCmdRepeat"]