INV-D1 variants work on live

This commit is contained in:
Brahim Hadriche committed 2026-07-02 17:17:58 -04:00
1 parent f4ab86d368
commit 6eb47827bf
8 files changed
+349 -47

No files matched your search

@@ -101,11 +101,13 @@ namespace Tests
' =========================================================================================
@describe("TransportSafetyAction (total device-seam guard)")
@it("the guard decision is DEFINED and correct over the FULL axis cross-product (state x transport x live x eof)")
@it("the guard decision is DEFINED and correct over the FULL axis cross-product (state x transport x live x eof x floor)")
function _()
' the full Roku Video.state enum — including the ones the old guard ignored (none/paused/stopping/
' stopped) — crossed with the live and at-end axes. Only playing-under-a-transport ever acts, and it
' finishes (instead of freezing) exactly when VOD has both the device AND the cursor at the end.
' stopped) — crossed with the live, at-end and tail-floor axes. Only playing-under-a-transport ever
' acts: it finishes (instead of freezing) exactly when VOD has both the device AND the cursor at the
' end, and resolves forward (instead of freezing) exactly when a live playhead sits under the known
' floor + margin. Floors: -1 = unknown, 0 = known but safely below, 100000 = mid pos overtaken.
states = ["none", "buffering", "playing", "paused", "finished", "error", "stopping", "stopped"]
durationMs = 210000
endMs = 209000 ' within FINISH_EPSILON_MS of the duration
@@ -115,26 +117,30 @@ namespace Tests
for each isLive in [false, true]
for each posAtEnd in [false, true]
for each curAtEnd in [false, true]
if posAtEnd
posMs = endMs
else
posMs = midMs
end if
if curAtEnd
curMs = endMs
else
curMs = midMs
end if
expected = PlayerCoordinatorLogic.SafetyAction.None
if inT and s = "playing"
if not isLive and posAtEnd and curAtEnd
expected = PlayerCoordinatorLogic.SafetyAction.FinishEof
for each floorMs in [-1, 0, 100000]
if posAtEnd
posMs = endMs
else
expected = PlayerCoordinatorLogic.SafetyAction.Freeze
posMs = midMs
end if
end if
got = PlayerCoordinatorLogic.TransportSafetyAction(s, inT, isLive, posMs, curMs, durationMs)
m.assertEqual(got, expected, "state=" + s + " inT=" + inT.ToStr() + " live=" + isLive.ToStr() + " posEnd=" + posAtEnd.ToStr() + " curEnd=" + curAtEnd.ToStr())
if curAtEnd
curMs = endMs
else
curMs = midMs
end if
expected = PlayerCoordinatorLogic.SafetyAction.None
if inT and s = "playing"
if isLive and floorMs >= 0 and posMs < floorMs + TransportController.LIVE_TAIL_RESUME_MARGIN_MS
expected = PlayerCoordinatorLogic.SafetyAction.ResumeLiveTail
else if not isLive and posAtEnd and curAtEnd
expected = PlayerCoordinatorLogic.SafetyAction.FinishEof
else
expected = PlayerCoordinatorLogic.SafetyAction.Freeze
end if
end if
got = PlayerCoordinatorLogic.TransportSafetyAction(s, inT, isLive, posMs, curMs, durationMs, floorMs)
m.assertEqual(got, expected, "state=" + s + " inT=" + inT.ToStr() + " live=" + isLive.ToStr() + " posEnd=" + posAtEnd.ToStr() + " curEnd=" + curAtEnd.ToStr() + " floor=" + floorMs.ToStr())
end for
end for
end for
end for
@@ -145,22 +151,37 @@ namespace Tests
@it("an unmodeled / unexpected device state under a transport is a safe no-op, never an undefined freeze")
function _()
' the wedge's failure mode: a state the guard did not enumerate must NOT trigger a spurious freeze.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("buffering", true, false, 60000, 60000, 210000), PlayerCoordinatorLogic.SafetyAction.None)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("some_future_state", true, false, 60000, 60000, 210000), PlayerCoordinatorLogic.SafetyAction.None)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("buffering", true, false, 60000, 60000, 210000, -1), PlayerCoordinatorLogic.SafetyAction.None)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("some_future_state", true, false, 60000, 60000, 210000, -1), PlayerCoordinatorLogic.SafetyAction.None)
end function
@it("VOD playing at the end under a transport whose cursor is ALSO at the end -> FinishEof, not Freeze")
function _()
' both the device and the cursor within the 2s epsilon of duration -> finish.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.FinishEof)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 210000, -1), PlayerCoordinatorLogic.SafetyAction.FinishEof)
' cursor rewound away from the end -> the user is heading backwards: keep the freeze.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 100000, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 100000, 210000, -1), PlayerCoordinatorLogic.SafetyAction.Freeze)
' device not at the end -> freeze as usual.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 60000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
' LIVE has no EOF: always freeze.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 209000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 60000, 209500, 210000, -1), PlayerCoordinatorLogic.SafetyAction.Freeze)
' LIVE has no EOF: always freeze (above the tail).
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 209000, 209500, 210000, -1), PlayerCoordinatorLogic.SafetyAction.Freeze)
' unknown duration -> no EOF concept -> freeze.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 0), PlayerCoordinatorLogic.SafetyAction.Freeze)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 0, -1), PlayerCoordinatorLogic.SafetyAction.Freeze)
end function
@it("live: the sliding tail overtaking the frozen playhead -> ResumeLiveTail, not a doomed freeze")
function _()
' frozen 10s above a known floor -> inside the resume margin: resolve forward.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 446000, 441000, 0, 436000), PlayerCoordinatorLogic.SafetyAction.ResumeLiveTail)
' exactly AT floor + margin -> still holdable: keep the freeze.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 436000 + TransportController.LIVE_TAIL_RESUME_MARGIN_MS, 441000, 0, 436000), PlayerCoordinatorLogic.SafetyAction.Freeze)
' floor unknown (-1) -> no floor knowledge, plain freeze even at a tiny position.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 5000, 5000, 0, -1), PlayerCoordinatorLogic.SafetyAction.Freeze)
' VOD ignores the floor argument entirely.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 60000, 60000, 210000, 436000), PlayerCoordinatorLogic.SafetyAction.Freeze)
' not playing / not in a transport -> None regardless of the overtaken floor.
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("paused", true, true, 446000, 441000, 0, 436000), PlayerCoordinatorLogic.SafetyAction.None)
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", false, true, 446000, 441000, 0, 436000), PlayerCoordinatorLogic.SafetyAction.None)
end function
' =========================================================================================
@@ -1144,6 +1144,109 @@ namespace Tests
m.assertEqual(t.LiveFloorMs(), 0)
end function
' =========================================================================================
' LIVE TAIL RESOLUTION — the sliding floor overtaking the frozen playhead cannot be fought
' (the device force-resumes such a pause every manifest refresh): the transport resolves
' forward with a normal commit from a cursor floored above the tail.
' =========================================================================================
@describe("live tail resolution")
' the doom setup: playing deep in the window, frozen by a rewind step, then the edge (and with
' it the floor) slides toward the frozen playhead until it sits inside the trigger margin.
' edge 400->405s, window 300s -> floor 100->105s; frozen playhead at 120s.
function LiveTailOvertaken() as object
t = new TransportController.Controller()
t.SetContent(true, 0, false)
t.SetLiveDvrWindow(300000)
t.OnLiveEdge(400000)
t.OnPosition(400000)
t.OnPosition(400000) ' confirmed latency floor
t.OnReady()
t.OnPosition(120000) ' playing deep in the window (after a deep-rewind commit)
t.HandleCommand(TransportController.Command.Left) ' freeze; cursor steps to 115000
t.TakeVideoIntent() ' drain the freeze pause
t.OnLiveEdge(405000) ' floor 105000: the frozen 120000 playhead is inside the trigger margin
return t
end function
@it("SafetyFloorMs is -1 on VOD and on an unknown live window; the known floor otherwise")
function _()
m.assertEqual(m.t.SafetyFloorMs(), -1) ' VOD
m.assertEqual(m.Live().SafetyFloorMs(), -1) ' live, window unknown
t = m.LiveTailOvertaken()
m.assertEqual(t.SafetyFloorMs(), 105000) ' rides the edge (405000 - 300000)
end function
@it("ResolveLiveTail commits forward from the safe floor when the cursor sits at the tail")
function _()
t = m.LiveTailOvertaken()
m.assertEqual(t.cursorMs, 115000)
t.ResolveLiveTail()
m.assertEqual(t.transportMode, TransportController.Mode.Idle)
intent = t.TakeVideoIntent()
m.assertEqual(intent.control, TransportController.Control.Resume)
m.assertTrue(intent.hasSeek)
m.assertEqual(intent.seekMs, 165000) ' floor 105000 + 2x margin (a full margin above the trigger)
m.assertEqual(t.cursorMs, 165000)
m.assertEqual(t.commitSeq, 1)
m.assertEqual(t.liveOffsetMs, 240000) ' the bar keeps showing how far behind the resume is
m.assertFalse(t.atLiveEdge)
end function
@it("ResolveLiveTail keeps a cursor the user had already moved above the safe floor")
function _()
t = m.LiveTailOvertaken()
for i = 1 to 11 ' step the cursor up from 115000: +5s per press to 170000
t.HandleCommand(TransportController.Command.Right)
end for
m.assertEqual(t.cursorMs, 170000)
t.ResolveLiveTail()
m.assertEqual(t.TakeVideoIntent().seekMs, 170000) ' the user's target wins; only the floor is raised
end function
@it("ResolveLiveTail outside LiveDvr is a no-op (idle, and VOD transports)")
function _()
t = m.LiveWindowed()
t.ResolveLiveTail() ' idle
m.assertEqual(t.transportMode, TransportController.Mode.Idle)
m.assertInvalid(t.TakeVideoIntent())
m.assertEqual(t.cursorMs, 300000)
' a VOD scrub is not a live tail
m.t.HandleCommand(TransportController.Command.Left)
m.t.TakeVideoIntent() ' drain the freeze
m.t.ResolveLiveTail()
m.assertEqual(m.t.transportMode, TransportController.Mode.Scrub)
m.assertInvalid(m.t.TakeVideoIntent())
end function
' =========================================================================================
' LIVE-EDGE SENTINEL ECHO — the 999999s jump-to-edge seek echoes back through the
' single-precision position field as 999998976ms (24ms UNDER the constant): both ingest
' guards must drop it, or it poisons positionMs and (via the max rule) edgeMs.
' =========================================================================================
@describe("live edge sentinel echo")
@it("OnPosition drops the float32 sentinel echo — position, edge and cursor stay clean")
function _()
t = m.LiveWindowed()
t.OnPosition(999998976) ' Int(float32(999999.0s) * 1000): the echo as the device reports it
t.OnPosition(999999000) ' the exact constant
m.assertEqual(t.positionMs, 300000)
m.assertEqual(t.edgeMs, 300000)
m.assertEqual(t.cursorMs, 300000)
t.OnPosition(295000) ' a real sample still lands
m.assertEqual(t.positionMs, 295000)
end function
@it("OnLiveEdge drops the float32 sentinel echo")
function _()
t = m.LiveWindowed()
t.OnLiveEdge(999998976)
m.assertEqual(t.edgeMs, 300000)
t.OnLiveEdge(305000) ' the real heartbeat still lands
m.assertEqual(t.edgeMs, 305000)
end function
' =========================================================================================
' LIVE REWINDABILITY — a buffer-sized DVR window (the manifest's timeShiftBufferDepth) is not
' a rewind feature: the brain takes no live transport input and the bar drops its label.
@@ -145,7 +145,7 @@ namespace Tests
' ---------- 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 13 -> one input.
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 14 -> one input.
function Lcg(s as integer) as integer
return (s * 25173 + 13849) and 65535
end function
@@ -155,7 +155,7 @@ namespace Tests
s = seed
for i = 0 to n - 1
s = m.Lcg(s)
seq.Push(s mod 13)
seq.Push(s mod 14)
end for
return seq
end function
@@ -187,6 +187,8 @@ namespace Tests
t.Tick(TransportController.Timer.ReplayToast)
else if tok = 12
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)
end if
end function