Add seek field to player

This commit is contained in:
Brahim Hadriche committed 2026-10-09 14:09:58 -04:00
1 parent 3bb7746d50
commit 810ef60770
16 files changed
+685 -52

No files matched your search

@@ -8,6 +8,7 @@
' 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).
' - InstantReplay from idle AND from any transport (scrub/scan/live), and the not-ready input drop.
' - External seek (ForceIdleSeek) from idle and from a transport: cursor on the target, clamped; replay chain dropped.
import "pkg:/components/VideoPlayerDev/TransportController.bs"
@@ -1066,18 +1067,158 @@ namespace Tests
m.assertEqual(t.liveOffsetMs, 0)
end function
' =========================================================================================
' EXTERNAL SEEK (ForceIdleSeek) — a seek from outside the brain, from any state: back to idle, the cursor
' on the target (clamped to the timeline), a seek intent.
' =========================================================================================
@describe("external seek")
@it("from idle: stays idle, moves the cursor + position to the target, and seeks keeping the play state")
function _()
m.t.ForceIdleSeek(150000, true)
m.assertEqual(m.t.transportMode, TransportController.Mode.Idle)
m.assertEqual(m.t.cursorMs, 150000)
m.assertEqual(m.t.positionMs, 150000)
intent = m.t.TakeVideoIntent()
m.assertEqual(intent.control, TransportController.Control.None)
m.assertTrue(intent.hasSeek)
m.assertEqual(intent.seekMs, 150000)
end function
@it("from a scrub: back to idle with the scratch cleared, and resumes at the target")
function _()
m.t.HandleKey(TransportController.Command.Left, true)
m.t.TakeVideoIntent()
m.t.ForceIdleSeek(150000, false)
m.assertEqual(m.t.transportMode, TransportController.Mode.Idle)
m.assertEqual(m.t.glyph, TransportController.Glyph.None)
m.assertEqual(m.t.scrubHeldDir, 0)
m.assertEqual(m.t.cursorMs, 150000)
intent = m.t.TakeVideoIntent()
m.assertEqual(intent.control, TransportController.Control.Resume)
m.assertEqual(intent.seekMs, 150000)
end function
@it("clamps a VOD target to [0, duration]")
function _()
m.t.ForceIdleSeek(500000, true)
m.assertEqual(m.t.cursorMs, 210000)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 210000)
m.t.ForceIdleSeek(-5000, true)
m.assertEqual(m.t.cursorMs, 0)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 0)
end function
@it("keeps the target when the duration is not known yet")
function _()
t = new TransportController.Controller()
t.SetContent(false, 2000, true)
t.ForceIdleSeek(150000, true)
m.assertEqual(t.cursorMs, 150000)
m.assertEqual(t.TakeVideoIntent().seekMs, 150000)
end function
@it("drops a pending InstantReplay: the next replay goes back from the external target")
function _()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertTrue(m.t.replayPending)
m.t.ForceIdleSeek(150000, true)
m.assertFalse(m.t.replayPending)
m.t.TakeVideoIntent()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 130000)
end function
' a live brain 5s behind its raw edge (learned latency): edge 300s, effective edge 295s, window 60s ->
' floor 240s. Tells the raw edge, the effective edge and the playhead apart.
function LiveLagging() as object
t = new TransportController.Controller()
t.SetContent(true, 0, false)
t.SetLiveDvrWindow(60000)
t.OnLiveEdge(300000)
t.OnPosition(295000)
t.OnPosition(295000) ' confirmed latency floor: 5s
t.OnReady()
return t
end function
@it("on live, moves the cursor to the target clamped to the floor and recomputes the offset")
function _()
t = m.LiveLagging()
m.assertEqual(t.LiveEdgeMs(), 295000)
t.ForceIdleSeek(270000, true)
m.assertEqual(t.cursorMs, 270000)
m.assertEqual(t.positionMs, 295000, "the live playhead stays the last real sample")
m.assertEqual(t.liveOffsetMs, 25000) ' (300 - 270) - 5 latency
m.assertFalse(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, 270000)
t.ForceIdleSeek(100000, true)
m.assertEqual(t.cursorMs, 240000)
m.assertEqual(t.TakeVideoIntent().seekMs, 240000)
end function
@it("on live, a target at or past the effective edge seeks to the edge, as a commit there does")
function _()
t = m.LiveLagging()
t.ForceIdleSeek(297000, true) ' between the effective (295s) and the raw (300s) edge
m.assertEqual(t.cursorMs, 295000)
m.assertTrue(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
t.ForceIdleSeek(295000, true)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
end function
@it("on live, the edge sentinel puts the cursor at the effective edge and seeks with the sentinel")
function _()
t = m.LiveLagging()
t.HandleCommand(TransportController.Command.Left)
t.ForceIdleSeek(TransportController.LIVE_EDGE_SEEK_MS, false)
m.assertEqual(t.transportMode, TransportController.Mode.Idle)
m.assertEqual(t.cursorMs, 295000)
m.assertTrue(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
end function
@it("before the seek lands, a scrub, a scan and a Replay start from the target (VOD)")
function _()
m.t.ForceIdleSeek(150000, true)
m.t.HandleCommand(TransportController.Command.Left)
m.assertEqual(m.t.cursorMs, 148000)
m.t.ForceIdleSeek(150000, true)
m.t.HandleCommand(TransportController.Command.Fwd)
m.t.Tick(TransportController.Timer.Scan)
m.assertTrue(m.t.cursorMs > 150000, "the scan runs on from the target")
m.t.ForceIdleSeek(150000, true)
m.t.TakeVideoIntent()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 130000)
end function
@it("before the seek lands, a live rewind and a Replay start from the target")
function _()
t = m.LiveLagging()
t.ForceIdleSeek(270000, true)
t.HandleCommand(TransportController.Command.Left)
m.assertEqual(t.transportMode, TransportController.Mode.LiveDvr)
m.assertEqual(t.cursorMs, 265000)
t.ForceIdleSeek(270000, true)
t.TakeVideoIntent()
t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(t.TakeVideoIntent().seekMs, 250000)
end function
' =========================================================================================
' SEEK-SETTLING FREEZE DEFER (INV-B12) — a transport entered while a play-through seek (commit /
' SponsorBlock skip / replay) is still in flight must NOT slam control=pause: that pause lands mid-seek
' external seek / replay) is still in flight must NOT slam control=pause: that pause lands mid-seek
' and wedges the device (the reported bif-over-black bug). Defer the freeze; the coordinator's
' EnforceTransportFreeze re-pauses once the seek reaches "playing". seekSettling models the in-flight seek.
' =========================================================================================
@describe("seek-settling freeze defer")
@it("a non-pause seek (SponsorBlock skip / commit / replay) marks seekSettling; pause+no-seek do not")
@it("a non-pause seek (external / commit / replay) marks seekSettling; pause+no-seek do not")
function _()
m.assertFalse(m.t.seekSettling)
m.t.ForceIdleSeek(120000, true) ' SponsorBlock skip, keep playing -> in flight
m.t.ForceIdleSeek(120000, true) ' an external seek, keep playing -> in flight
m.assertTrue(m.t.seekSettling)
m.t.MarkSeekSettled()
m.assertFalse(m.t.seekSettling)
@@ -1097,9 +1238,9 @@ namespace Tests
m.t.HandleCommand(TransportController.Command.Right)
m.assertEqual(m.t.transportMode, TransportController.Mode.Scrub) ' still enters scrub
m.assertInvalid(m.t.TakeVideoIntent()) ' but the FREEZE was deferred (no pause)
' the scrub still snaps + steps off the LAST KNOWN position (60000) — the seek to 120000 hasn't
' landed yet (that IS the "press Right immediately" race), so cursor = 60000 grid + 2000 step.
m.assertEqual(m.t.cursorMs, 62000)
' the scrub steps off the seek target, not the stale position (60000): the seek to 120000 hasn't
' landed yet (that IS the "press Right immediately" race), so cursor = 120000 + 2000 step.
m.assertEqual(m.t.cursorMs, 122000)
end function
@it("entering scan while a seek is settling DEFERS the freeze")
@@ -16,11 +16,13 @@ namespace Tests
' a fresh brain at rest (idle, ready) with realistic content facts. windowMs = the live DVR window
' (0 = unknown), the axis that decides the rewind floor.
function Fresh(isLive as boolean, windowMs = 0 as integer) as object
function Fresh(isLive as boolean, windowMs = 0 as integer, ready = true as boolean) as object
t = new TransportController.Controller()
t.SetContent(isLive, 2000, true)
t.SetLiveDvrWindow(windowMs)
t.OnReady()
if ready
t.OnReady()
end if
if isLive
t.OnLiveEdge(600000) ' clock-anchored live edge
else
@@ -71,11 +73,11 @@ namespace Tests
' reachable-state labels — each built by DRIVING the brain (only reachable states are tested). On live
' the same label reaches a live mode (left -> liveDvr step, fwd -> liveDvr ladder).
function Labels() as object
return ["idle", "scrub", "scrubHeld", "scan1", "scan2", "replay"]
return ["idle", "scrub", "scrubHeld", "scan1", "scan2", "replay", "committed", "notReady"]
end function
function Build(label as string, isLive as boolean, windowMs = 0 as integer) as object
t = m.Fresh(isLive, windowMs)
t = m.Fresh(isLive, windowMs, label <> "notReady")
if label = "scrub"
t.HandleKey(TransportController.Command.Left, true)
t.HandleKey(TransportController.Command.Left, false) ' release -> frozen, glyph cleared
@@ -88,6 +90,10 @@ namespace Tests
t.HandleCommand(TransportController.Command.Fwd)
else if label = "replay"
t.HandleCommand(TransportController.Command.Replay)
else if label = "committed"
' a scrub committed: its play-through seek is still settling.
t.HandleCommand(TransportController.Command.Left)
t.HandleCommand(TransportController.Command.Commit)
end if
return t
end function
@@ -141,14 +147,60 @@ namespace Tests
t.OnDuration(d)
m.AssertInv(t, label + tag + "+dur=" + d.ToStr())
end for
' an external seek from any state, to any target: back to idle on the clamped target, the replay
' chain and any armed timer dropped, the seek in flight.
for each target in [0, 120000, 599000, 900000, -5000, TransportController.LIVE_EDGE_SEEK_MS]
for each keepPlaying in [true, false]
t = m.Build(label, v.isLive, v.windowMs)
t.TakeTimerCmd()
expected = m.ExpectedExternalSeek(t, target)
t.ForceIdleSeek(target, keepPlaying)
where = label + tag + "+externalSeek=" + target.ToStr() + "/" + keepPlaying.ToStr()
m.AssertInv(t, where)
m.assertEqual(t.transportMode, TransportController.Mode.Idle, where)
m.assertFalse(t.replayPending, where)
m.assertTrue(t.seekSettling, where)
m.assertEqual(t.cursorMs, expected.cursorMs, where)
intent = t.TakeVideoIntent()
m.assertTrue(intent.hasSeek, where)
m.assertEqual(intent.seekMs, expected.seekMs, where)
if keepPlaying
m.assertEqual(intent.control, TransportController.Control.None, where)
else
m.assertEqual(intent.control, TransportController.Control.Resume, where)
end if
m.assertEqual(t.TakeTimerCmd().action, TransportController.TimerAction.Stop, where)
end for
end for
end for
end for
end function
' Where an external seek must land, from the brain's bounds before it: VOD clamps to [0, duration]; live
' clamps to the DVR floor, and at or past the effective edge goes to the edge (the sentinel).
function ExpectedExternalSeek(t as object, target as integer) as object
if t.isLive
if TransportController.IsLiveEdgeSentinelMs(target) or target >= t.LiveEdgeMs()
return { cursorMs: t.LiveEdgeMs(), seekMs: TransportController.LIVE_EDGE_SEEK_MS }
end if
floor = t.LiveFloorMs()
if target < floor
target = floor
end if
return { cursorMs: target, seekMs: target }
end if
if target < 0
target = 0
else if target > t.durationMs
target = t.durationMs
end if
return { cursorMs: target, seekMs: target }
end function
' ---------- seeded fuzz with shrink ----------
' a 16-bit LCG (ZX-Spectrum constants): s*25173 < 2^31 so it never overflows Integer; deterministic +
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 14 -> one input.
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 19 -> one input.
function Lcg(s as integer) as integer
return (s * 25173 + 13849) and 65535
end function
@@ -158,7 +210,7 @@ namespace Tests
s = seed
for i = 0 to n - 1
s = m.Lcg(s)
seq.Push(s mod 14)
seq.Push(s mod 19)
end for
return seq
end function
@@ -192,6 +244,16 @@ namespace Tests
t.OnLiveEdge(t.edgeMs + 50000) ' a big edge jump (long pause's catch-up)
else if tok = 13
t.ResolveLiveTail() ' the coordinator's tail-overtake resolution (no-op outside LiveDvr)
else if tok = 14
t.ForceIdleSeek(300000, true) ' an external seek keeping the play state (SponsorBlock skip, setSeek)
else if tok = 15
t.ForceIdleSeek(300000, false) ' an external seek out of a transport (setSeek resumes)
else if tok = 16
t.ForceIdleSeek(-5000, true) ' below the start / the DVR floor
else if tok = 17
t.ForceIdleSeek(900000, false) ' past the end / the edge
else if tok = 18
t.ForceIdleSeek(TransportController.LIVE_EDGE_SEEK_MS, true)
end if
end function
@@ -1,8 +1,11 @@
' Pins the test mock's node tree to the real component's. VideoPlayerDevMock.xml is a hand-mirrored copy of
' VideoPlayerDev.xml (same child ids so the coordinator's findNode()s resolve); silent drift between the two
' weakens every seam test built on the mock. This suite parses both XMLs from pkg and asserts:
' Pins the test mock's node tree and interface to the real component's. VideoPlayerDevMock.xml is a hand-mirrored
' copy of VideoPlayerDev.xml (same child ids so the coordinator's findNode()s resolve, same interface fields so
' the spec drives them as the outside world does); silent drift between the two weakens every seam test built on
' the mock. This suite parses both XMLs from pkg and asserts:
' - every real child id exists in the mock (minus the documented omissions) and vice versa;
' - same-id duration attributes (Timers/Animations) match.
' - same-id duration attributes (Timers/Animations) match;
' - every real interface field exists in the mock (minus the documented omissions) with the same type and
' alwaysNotify. The mock's extra fields (the Video fields it fakes, test probes) are its own.
' Element TYPES may differ (the mock substitutes simpler nodes with the same field surface, e.g. Label for
' ScrollingLabel), so type parity is intentionally not checked.
@@ -50,8 +53,58 @@ namespace Tests
end for
end function
' real interface fields the mock omits: profilesService is read only by the content-job paths the seam never
' runs; bindings + binding_done are the AutoBind include's plumbing, which TestSetup does by hand.
function MockFieldOmissions() as object
return { profilesService: true, bindings: true, binding_done: true }
end function
' Parse a component XML from pkg and index its <interface> fields: id -> { type, alwaysNotify }.
function FieldIndex(path as string) as object
text = ReadAsciiFile(path)
xml = CreateObject("roXMLElement")
parsed = (text <> "") and xml.Parse(text)
index = {}
if parsed
for each section in xml.GetChildElements()
if LCase(section.GetName()) = "interface"
for each field in section.GetChildElements()
if LCase(field.GetName()) = "field"
attrs = field.GetAttributes()
index[ValidString(attrs.id)] = { type: LCase(ValidString(attrs.type)), alwaysNotify: LCase(ValidString(attrs.alwaysNotify)) = "true" }
end if
end for
end if
end for
end if
return { parsed: parsed, index: index }
end function
@describe("mock parity")
@it("the mock declares every real interface field with the same type and alwaysNotify")
function _()
real = m.FieldIndex("pkg:/components/VideoPlayerDev/VideoPlayerDev.xml")
mock = m.FieldIndex("pkg:/components/VideoPlayerDev/tests/VideoPlayerDevMock.xml")
m.assertTrue(real.parsed, "VideoPlayerDev.xml read + parsed")
m.assertTrue(mock.parsed, "VideoPlayerDevMock.xml read + parsed")
m.assertTrue(real.index.Count() > 10, "real fields found (sanity: the walker isn't vacuous)")
omissions = m.MockFieldOmissions()
for each id in real.index
if not omissions.DoesExist(id)
m.assertTrue(mock.index.DoesExist(id), "mock is missing interface field '" + id + "' — mirror it (or add a documented omission)")
if mock.index.DoesExist(id)
m.assertEqual(mock.index[id].type, real.index[id].type, "type drift on field '" + id + "'")
m.assertEqual(mock.index[id].alwaysNotify, real.index[id].alwaysNotify, "alwaysNotify drift on field '" + id + "'")
end if
end if
end for
for each id in omissions
m.assertTrue(real.index.DoesExist(id), "stale field omission '" + id + "' — it left VideoPlayerDev.xml")
end for
end function
@it("the mock mirrors the real component's children (ids + timer/animation durations)")
function _()
real = m.ChildIndex("pkg:/components/VideoPlayerDev/VideoPlayerDev.xml")