INV-D1 variants work on live
This commit is contained in:
1 parent
f4ab86d368
commit
6eb47827bf
8 files changed
+349
-47
No files matched your search
@@ -22,6 +22,7 @@ namespace PlayerCoordinatorLogic
|
||||
None = 0
|
||||
Freeze = 1 ' the video is advancing under a transport -> the coordinator must re-pause it
|
||||
FinishEof = 2 ' VOD played to the end under a transport also sitting at the end -> finish, don't re-pause forever
|
||||
ResumeLiveTail = 3 ' live: the sliding DVR tail overtook the frozen playhead -> resolve forward, a re-pause cannot stick
|
||||
end enum
|
||||
|
||||
' The buttons in the row above the trackbar, in focus order (the index). The COUNT is owned by ButtonRow
|
||||
@@ -79,16 +80,26 @@ namespace PlayerCoordinatorLogic
|
||||
' Only a video actively PLAYING under a transport must be re-paused. Every other state is already
|
||||
' not-advancing or owned elsewhere: buffering = a seek/rebuffer the bif covers; paused = the desired frozen
|
||||
' state; none/stopping/stopped = teardown; finished/error = handled in their own OnVideoState branches.
|
||||
' EXCEPTION: VOD playing at the very end while the transport cursor is ALSO at the end — the device refuses
|
||||
' EXCEPTION (VOD): playing at the very end while the transport cursor is ALSO at the end — the device refuses
|
||||
' to stay paused at EOF (the freeze would loop forever), and the user is at the end anyway: finish instead.
|
||||
' A cursor rewound away from the end keeps the freeze (the user is heading backwards).
|
||||
function TransportSafetyAction(deviceState as string, inTransport as boolean, isLive as boolean, positionMs as integer, cursorMs as integer, durationMs as integer) as integer
|
||||
' EXCEPTION (live): the sliding DVR tail overtaking the frozen playhead — the device force-resumes such a
|
||||
' pause on every manifest refresh (from ~10s above the advertised floor), so a re-pause cannot stick and the
|
||||
' freeze would loop forever; resolve forward instead. liveFloorMs is the availability floor (edge − window),
|
||||
' or -1 when the window is unknown (no floor knowledge -> plain freeze).
|
||||
function TransportSafetyAction(deviceState as string, inTransport as boolean, isLive as boolean, positionMs as integer, cursorMs as integer, durationMs as integer, liveFloorMs as integer) as integer
|
||||
if not inTransport or deviceState <> VideoState.Playing
|
||||
return SafetyAction.None
|
||||
end if
|
||||
if isLive
|
||||
if liveFloorMs >= 0 and positionMs < liveFloorMs + TransportController.LIVE_TAIL_RESUME_MARGIN_MS
|
||||
return SafetyAction.ResumeLiveTail
|
||||
end if
|
||||
return SafetyAction.Freeze
|
||||
end if
|
||||
atEof = durationMs > 0 and positionMs >= durationMs - TransportController.FINISH_EPSILON_MS
|
||||
cursorAtEof = cursorMs >= durationMs - TransportController.FINISH_EPSILON_MS
|
||||
if not isLive and atEof and cursorAtEof
|
||||
if atEof and cursorAtEof
|
||||
return SafetyAction.FinishEof
|
||||
end if
|
||||
return SafetyAction.Freeze
|
||||
|
||||
@@ -68,6 +68,15 @@ namespace TransportController
|
||||
const SCAN_LEVEL_MAX = 3
|
||||
const LIVE_DVR_STEP_MS = 5000
|
||||
const LIVE_EDGE_SEEK_MS = 999999000 ' seek target that means "jump to the live edge"
|
||||
' Video.position is single-precision, so the 999999s sentinel echoes back as 999998.976s and
|
||||
' Int(position * 1000) lands 24ms UNDER the constant. Sentinel checks take this slack — nothing
|
||||
' legitimate on the window timeline gets near 11.5 days.
|
||||
const LIVE_EDGE_SENTINEL_SLACK_MS = 100000
|
||||
' The device will not hold a pause this close to the sliding DVR tail: it force-resumes ~1/s
|
||||
' (each manifest refresh), starting ~10s ABOVE the advertised floor (measured on device). The
|
||||
' tail resolution resumes at least this far above the floor so the resumed playhead isn't
|
||||
' immediately overtaken again.
|
||||
const LIVE_TAIL_RESUME_MARGIN_MS = 30000
|
||||
' Live scan base scales with DVR window length: base = effectiveEdge / DIVISOR, floored at the storyboard
|
||||
' interval so short DVRs are unchanged. 4000 -> ~10.8s base on a 12h DVR -> L3 ~65s/tick.
|
||||
const LIVE_SCAN_BASE_DIVISOR = 4000
|
||||
@@ -89,6 +98,13 @@ namespace TransportController
|
||||
' back on every burst reads as flicker. User actions (rewind/seek/commit) keep the tight band.
|
||||
const LIVE_EDGE_ATEDGE_LEAVE_MS = 6000
|
||||
|
||||
' Whether a device-reported ms value is the live-edge seek sentinel echoing back through the
|
||||
' single-precision position/duration fields (see LIVE_EDGE_SENTINEL_SLACK_MS): such values are
|
||||
' seek plumbing, not positions.
|
||||
function IsLiveEdgeSentinelMs(ms as integer) as boolean
|
||||
return ms >= TransportController.LIVE_EDGE_SEEK_MS - TransportController.LIVE_EDGE_SENTINEL_SLACK_MS
|
||||
end function
|
||||
|
||||
' The transport state machine.
|
||||
class Controller
|
||||
' ---- content facts (set once at contentReady) ----
|
||||
@@ -200,6 +216,16 @@ namespace TransportController
|
||||
return floor
|
||||
end function
|
||||
|
||||
' The floor for the coordinator's tail-overtake safety decision: the availability floor when
|
||||
' the window is known, -1 when it is not (without floor knowledge the safety verdict stays a
|
||||
' plain freeze).
|
||||
function SafetyFloorMs() as integer
|
||||
if not m.isLive or m.dvrWindowMs <= 0
|
||||
return -1
|
||||
end if
|
||||
return m.LiveFloorMs()
|
||||
end function
|
||||
|
||||
' Storyboards arrive late (the native Video.thumbnailTiles field populates after the manifest loads),
|
||||
' so the coordinator updates the scrub step + bif gate here without the live-edge / replay resets that
|
||||
' SetContent does for new content.
|
||||
@@ -224,7 +250,7 @@ namespace TransportController
|
||||
' Last real Video position. While idle the cursor tracks it; while a transport is active the machine owns
|
||||
' the cursor. Drops the live-edge seek sentinel echo (see OnDuration).
|
||||
function OnPosition(ms as integer) as void
|
||||
if m.isLive and ms >= TransportController.LIVE_EDGE_SEEK_MS
|
||||
if m.isLive and TransportController.IsLiveEdgeSentinelMs(ms)
|
||||
return
|
||||
end if
|
||||
m.positionMs = ms
|
||||
@@ -275,7 +301,7 @@ namespace TransportController
|
||||
' at the manifest's availabilityStartTime and pushed ~1/s. Advances through pauses, rebuffers and
|
||||
' startup — the offset/badge math needs no event-pattern heuristics on top.
|
||||
function OnLiveEdge(ms as integer) as void
|
||||
if not m.isLive or ms <= 0 or ms >= TransportController.LIVE_EDGE_SEEK_MS
|
||||
if not m.isLive or ms <= 0 or TransportController.IsLiveEdgeSentinelMs(ms)
|
||||
return
|
||||
end if
|
||||
m.edgeMs = ms
|
||||
@@ -522,6 +548,24 @@ namespace TransportController
|
||||
m.commitSeq = m.commitSeq + 1
|
||||
end function
|
||||
|
||||
' The sliding DVR tail overtook the frozen playhead (SafetyAction.ResumeLiveTail): the device
|
||||
' force-resumes such a pause on every manifest refresh, so freezing again just loops. Resolve
|
||||
' the transport forward instead — a normal commit, with the cursor floored above the tail
|
||||
' (what the stock player does when paused live content expires). The resume parks a FULL margin
|
||||
' above the trigger threshold: parked exactly on it, the floor advancing through the resume's
|
||||
' rebuffer leaves the playhead hovering at the boundary and the very next rewind press would
|
||||
' trip the trigger again and eat itself.
|
||||
function ResolveLiveTail() as void
|
||||
if m.transportMode <> TransportController.Mode.LiveDvr
|
||||
return ' only a frozen live transport has a tail to resolve
|
||||
end if
|
||||
floorSafe = m.LiveFloorMs() + 2 * TransportController.LIVE_TAIL_RESUME_MARGIN_MS
|
||||
if m.cursorMs < floorSafe
|
||||
m.cursorMs = m.Clamp(floorSafe, 0, m.LiveEdgeMs())
|
||||
end if
|
||||
m.Commit()
|
||||
end function
|
||||
|
||||
' The EFFECTIVE live edge: raw edge minus the latency baseline (where the offset reads 0 / "● LIVE").
|
||||
' Forward commit + cursor clamp use THIS so the offset-hits-0 point and the auto-commit point COINCIDE —
|
||||
' no dead-zone seeking forward past the visible edge.
|
||||
|
||||
@@ -17,6 +17,11 @@ import "pkg:/source/utils/RemoteKeys.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
' Per-content ceiling on INV-D1 heal / tail-resolve telemetry: a pathological loop otherwise emits one
|
||||
' error per second for as long as it runs. Occurrences keep counting past the cap (each message carries
|
||||
' its ordinal) and a capped heal loop's true total rides out in one summary event when the content ends.
|
||||
const INV_D1_TELEMETRY_CAP = 3
|
||||
|
||||
' Coordinator for the custom video player. extends Video, enableUI=false.
|
||||
'
|
||||
' Owns the focused Video node + key router, the Chrome-group fade, PiP resize, and lifecycle plumbing. All
|
||||
@@ -59,6 +64,8 @@ function Initialize()
|
||||
m.errorDialogNode = invalid
|
||||
m.ignoreNextFinished = false ' a retry replay -> swallow the next "finished" edge
|
||||
m.videoPlayedSuccessfully = false ' true once the stream has actually played (gates error-retry)
|
||||
m.healCount = 0 ' INV-D1 heals this content (telemetry stops at INV_D1_TELEMETRY_CAP; total goes out in the close summary)
|
||||
m.tailResolveCount = 0 ' live tail resolutions this content (telemetry capped the same way)
|
||||
|
||||
m.chromeMode = ChromeMode.Hidden
|
||||
m.liveBadgeHoldActive = false ' the "● LIVE" reveal hold is running
|
||||
@@ -312,7 +319,7 @@ end function
|
||||
|
||||
' Apply a seek (ms). The live "jump to edge" sentinel maps to the live-end seek the OS understands.
|
||||
function ApplySeek(seekMs as integer) as void
|
||||
if seekMs >= TransportController.LIVE_EDGE_SEEK_MS
|
||||
if TransportController.IsLiveEdgeSentinelMs(seekMs)
|
||||
m.top.seek = 999999
|
||||
return
|
||||
end if
|
||||
@@ -776,21 +783,41 @@ end function
|
||||
' event). Re-pausing yields state=paused -> OnPosition stops -> no loop.
|
||||
function EnforceTransportFreeze(source as string) as void
|
||||
inTransport = (m.transport.transportMode <> TransportController.Mode.Idle)
|
||||
action = PlayerCoordinatorLogic.TransportSafetyAction(m.top.state, inTransport, m.transport.isLive, Int(m.top.position * 1000), m.transport.cursorMs, m.transport.durationMs)
|
||||
action = PlayerCoordinatorLogic.TransportSafetyAction(m.top.state, inTransport, m.transport.isLive, Int(m.top.position * 1000), m.transport.cursorMs, m.transport.durationMs, m.transport.SafetyFloorMs())
|
||||
if action = PlayerCoordinatorLogic.SafetyAction.Freeze
|
||||
m.top.control = VideoControl.Pause
|
||||
' the play-through seek that opened this transport has landed, so clear autoplayAfterSeek; a later
|
||||
' seek-complete must not silently un-freeze the video behind the transport.
|
||||
m.top.autoplayAfterSeek = false
|
||||
m.healCount += 1
|
||||
' Position detail rides in the message; the fingerprint pins grouping (heal + mode + trigger) so it
|
||||
' stays a handful of issues instead of fragmenting on the per-event posMs/cursorMs values.
|
||||
healInfo = `INV-D1 heal: re-pause under active transport. src=${source} mode=${m.transport.transportMode} isLive=${m.transport.isLive} state=${m.top.state} posMs=${Int(m.top.position * 1000)} cursorMs=${m.transport.cursorMs} edgeMs=${m.transport.edgeMs}`
|
||||
' floorMs=-1 marks an unknown-window live stream — the one shape the tail resolution cannot cover.
|
||||
healInfo = `INV-D1 heal: re-pause under active transport. src=${source} mode=${m.transport.transportMode} isLive=${m.transport.isLive} state=${m.top.state} posMs=${Int(m.top.position * 1000)} cursorMs=${m.transport.cursorMs} edgeMs=${m.transport.edgeMs} floorMs=${m.transport.SafetyFloorMs()} heal=${m.healCount}`
|
||||
LogErrorNoTelemetry(healInfo)
|
||||
LogTelemetryEvent({
|
||||
level: "error"
|
||||
message: healInfo
|
||||
fingerprint: ["INV-D1 heal", m.transport.transportMode, source]
|
||||
})
|
||||
if m.healCount <= INV_D1_TELEMETRY_CAP
|
||||
LogTelemetryEvent({
|
||||
level: "error"
|
||||
message: healInfo
|
||||
fingerprint: ["INV-D1 heal", m.transport.transportMode, source]
|
||||
})
|
||||
end if
|
||||
else if action = PlayerCoordinatorLogic.SafetyAction.ResumeLiveTail
|
||||
' the tail overtook the frozen playhead: resolve forward (ResolveLiveTail), don't heal. Telemetered
|
||||
' at info level so the field shows the resolution working — resolve>1 on one content means the
|
||||
' resumed playhead was overtaken AGAIN, i.e. LIVE_TAIL_RESUME_MARGIN_MS is too small.
|
||||
m.tailResolveCount += 1
|
||||
resolveInfo = `INV-D1 tail-resolve: resume forward. src=${source} posMs=${Int(m.top.position * 1000)} cursorMs=${m.transport.cursorMs} floorMs=${m.transport.SafetyFloorMs()} edgeMs=${m.transport.edgeMs} resolve=${m.tailResolveCount}`
|
||||
LogInfo(resolveInfo)
|
||||
if m.tailResolveCount <= INV_D1_TELEMETRY_CAP
|
||||
LogTelemetryEvent({
|
||||
level: "info"
|
||||
message: resolveInfo
|
||||
fingerprint: ["INV-D1 tail-resolve", source]
|
||||
})
|
||||
end if
|
||||
m.transport.ResolveLiveTail()
|
||||
ApplyTransport()
|
||||
else if action = PlayerCoordinatorLogic.SafetyAction.FinishEof
|
||||
' content played to the end under a transport sitting at the end: finishing is what "at the end"
|
||||
' means, and the alternative (re-pausing at EOF) loops against the device forever.
|
||||
@@ -801,6 +828,19 @@ function EnforceTransportFreeze(source as string) as void
|
||||
end if
|
||||
end function
|
||||
|
||||
' A heal loop that ran past the telemetry cap still reports its true size: one tally event when the
|
||||
' content ends (close or content switch). Loop size is the discriminator between a singleton heal and a
|
||||
' fight the player lost for minutes — the capped per-event stream can no longer show it.
|
||||
function SendHealSummary() as void
|
||||
if m.healCount > INV_D1_TELEMETRY_CAP
|
||||
LogTelemetryEvent({
|
||||
level: "error"
|
||||
message: `INV-D1 heal: ${m.healCount} heals over one content (${m.healCount - INV_D1_TELEMETRY_CAP} past the telemetry cap)`
|
||||
fingerprint: ["INV-D1 heal suppressed"]
|
||||
})
|
||||
end if
|
||||
end function
|
||||
|
||||
' The Video node reached state=error. ErrorDialogController decides retry-vs-dialog; the coordinator applies
|
||||
' (replay the next URL, or show the scene-level TimedDialog).
|
||||
function OnVideoError() as void
|
||||
@@ -880,7 +920,7 @@ function OnDuration(event as object) as void
|
||||
m.transport.OnDuration(durMs) ' the brain ignores this on live (the edge comes from the clock)
|
||||
' a live stream WITHOUT the manifest anchor in its metadata: anchor the clock off each duration report
|
||||
' instead (duration freezes during pause, so each report re-anchors; between reports the clock projects).
|
||||
if m.transport.isLive and m.liveAstSeconds <= 0 and durMs > 0 and durMs < TransportController.LIVE_EDGE_SEEK_MS
|
||||
if m.transport.isLive and m.liveAstSeconds <= 0 and durMs > 0 and not TransportController.IsLiveEdgeSentinelMs(durMs)
|
||||
m.liveFallbackEdgeMs = durMs
|
||||
m.liveFallbackAtSeconds = NowSeconds()
|
||||
PushLiveEdge()
|
||||
@@ -1120,6 +1160,9 @@ function OnVideoContentJobDone(event as object) as void
|
||||
' fill them in for VOD.
|
||||
isLive = content <> invalid and content.Live = true
|
||||
m.transport.SetContent(isLive, 2000, false)
|
||||
SendHealSummary() ' the previous content's capped heal tally, if any
|
||||
m.healCount = 0
|
||||
m.tailResolveCount = 0
|
||||
' live floor: how far back the DVR window reaches (0 = unknown -> the brain keeps the [0, edge] clamp).
|
||||
' The generated DASH anchors t=0 to the window start, so floor = edge - window as the session outlives it.
|
||||
' The same window decides rewindability: a buffer-sized window means no live trickplay at all.
|
||||
@@ -1511,6 +1554,7 @@ function OnClose() as void
|
||||
end if
|
||||
m.onCloseCalled = true
|
||||
m.top.previousPlayer = invalid
|
||||
SendHealSummary()
|
||||
|
||||
' A closed player must not react to anything anymore. The onCloseCalled guards already make the handlers
|
||||
' no-ops; unobserving stops the traffic at the source — late device edges from the async stop, a stray
|
||||
|
||||
@@ -76,6 +76,14 @@ function TestSetup() as void
|
||||
m.webServer = m.top.webServer
|
||||
m.innertube = m.top.innertube
|
||||
|
||||
' OnNodeReady re-registers the device-field observers; unobserve-first for the same reason as the
|
||||
' nudge counter above — stacked observers fire a handler once per prior TestSetup on every write,
|
||||
' and OnPosition's latency learning reads two identical fires as a CONFIRMED min-gap, poisoning
|
||||
' LiveEdgeMs for any live test that runs after another test in the suite.
|
||||
for each deviceField in ["state", "position", "duration", "close", "thumbnailTiles", "control"]
|
||||
m.top.unobserveField(deviceField)
|
||||
end for
|
||||
|
||||
OnNodeReady()
|
||||
end function
|
||||
|
||||
@@ -175,6 +183,7 @@ function TestSnapshot() as object
|
||||
return {
|
||||
transportMode: m.transport.transportMode
|
||||
seekSettling: m.transport.seekSettling
|
||||
brainEdgeMs: m.transport.edgeMs
|
||||
onCloseCalled: m.onCloseCalled = true
|
||||
control: m.top.control
|
||||
autoplay: m.top.autoplayAfterSeek
|
||||
|
||||
@@ -86,6 +86,58 @@ namespace Tests
|
||||
end for
|
||||
end function
|
||||
|
||||
' The one live case where the re-freeze must NOT happen: the sliding DVR tail overtook the frozen
|
||||
' playhead, and the device force-resumes such a pause on every manifest refresh (verified on device) —
|
||||
' re-pausing loops 1/s forever. The coordinator resolves forward instead: a commit from a cursor
|
||||
' floored a margin above the tail.
|
||||
@it("a live playhead the sliding tail overtook resolves forward (commit), not a re-pause loop")
|
||||
function _()
|
||||
' 12h stream at the edge, 4h window -> floor = 8h. Park the playhead 5s above the floor (a deep
|
||||
' rewind), then freeze: the frozen position sits inside the tail margin the device cannot hold.
|
||||
m.top.callFunc("TestSetLive", 43200000)
|
||||
m.top.position = 28805.0 ' fires the REAL OnPosition -> brain playhead 28805000ms
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, true) ' freeze; the cursor clamps at the floor
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, false)
|
||||
mid = m.Snap()
|
||||
m.assertEqual(mid.transportMode, TransportController.Mode.LiveDvr)
|
||||
m.assertEqual(mid.control, VideoControl.Pause)
|
||||
|
||||
' the device force-resumes the doomed pause (what the real player does each manifest refresh).
|
||||
m.top.callFunc("TestSetState", VideoState.Playing)
|
||||
snap = m.Snap()
|
||||
m.assertEqual(snap.transportMode, TransportController.Mode.Idle, "the transport resolved instead of fighting")
|
||||
m.assertEqual(snap.control, VideoControl.Resume, "resumed forward, not re-paused")
|
||||
m.assertEqual(Int(m.top.seek * 1000), 28860000, "the resume parks a full margin above the trigger (28800s + 60s)")
|
||||
' the resolution telemeters at info level (never as a heal) with its per-content ordinal.
|
||||
sent = m.global.telemetry.LogEvent
|
||||
m.assertEqual(sent.level, "info")
|
||||
m.assertTrue(sent.message.InStr("INV-D1 tail-resolve") = 0, "got: " + sent.message)
|
||||
m.assertTrue(sent.message.InStr("resolve=1") > 0)
|
||||
end function
|
||||
|
||||
@it("heal telemetry stops at the cap while the occurrences keep counting")
|
||||
function _()
|
||||
' a frozen VOD scrub the device keeps flipping to playing: 5 heals, but only 3 events may leave.
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, true)
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, false)
|
||||
for i = 1 to 5
|
||||
m.top.callFunc("TestSetState", VideoState.Playing)
|
||||
end for
|
||||
sent = m.global.telemetry.LogEvent
|
||||
m.assertTrue(sent.message.InStr("heal=3") > 0, "telemetry must stop at the 3rd heal; last sent: " + sent.message)
|
||||
end function
|
||||
|
||||
@it("a sentinel-valued duration report cannot anchor the live-edge fallback clock")
|
||||
function _()
|
||||
m.top.callFunc("TestSetLive", 300000)
|
||||
' the 999999s live seek echoing back through the single-precision duration field.
|
||||
m.top.duration = 999998.976
|
||||
m.assertEqual(m.Snap().brainEdgeMs, 300000, "the sentinel echo must not move the edge")
|
||||
' a real duration report anchors the fallback and re-feeds the edge.
|
||||
m.top.duration = 400.0
|
||||
m.assertEqual(m.Snap().brainEdgeMs, 400000)
|
||||
end function
|
||||
|
||||
' An external resume (the linked phone via Lounge) under an active transport must TAKE OVER: VPD never
|
||||
' resumes under a transport itself, so a resume here is the phone's. It cancels the scrub and plays.
|
||||
@it("an external Lounge resume under a transport takes over: cancels the scrub and lets it play")
|
||||
@@ -341,7 +393,7 @@ namespace Tests
|
||||
classified[name] = "axis"
|
||||
end for
|
||||
' flags / scratch — one-shot latches and counters with a single consuming path.
|
||||
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastExitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive"]
|
||||
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastExitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive", "healCount", "tailResolveCount"]
|
||||
classified[name] = "flag"
|
||||
end for
|
||||
' NOT coordinator state — node-scope + test-environment entries, pinned EXPLICITLY (no hidden
|
||||
@@ -422,7 +474,8 @@ namespace Tests
|
||||
' FinishEof -> OnPlaybackFinished -> ClosePlayer -> the queue sets player.close -> OnClose drops
|
||||
' m.sponsorblock — then OnPosition continues to `m.sponsorblock.OnPosition()` and derefs the dropped
|
||||
' controller. (`m.sponsorblock` is a field, so the invalid deref is &hf3, not &hec.) The OLD code crashes
|
||||
' here; the onCloseCalled re-check after EnforceTransportFreeze bails. Kept LAST: OnClose detaches the node.
|
||||
' here; the onCloseCalled re-check after EnforceTransportFreeze bails. Kept at the END with the other
|
||||
' closing test: OnClose detaches the node.
|
||||
@it("a finish during a position tick must not deref the dropped sponsorblock (the OnPosition ERR_RO3 crash)")
|
||||
function _()
|
||||
m.top.callFunc("TestWireQueueClose") ' the stub queue now closes the player on closePlayer, as the real one does
|
||||
@@ -446,6 +499,21 @@ namespace Tests
|
||||
m.assertTrue(m.Snap().onCloseCalled, "the finish closed the player from within the position tick")
|
||||
end function
|
||||
|
||||
' Also at the end (closes the player): a heal loop that ran past the telemetry cap reports its
|
||||
' true size in one tally event when the content ends.
|
||||
@it("the close summary carries a capped heal loop's true size")
|
||||
function _()
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, true)
|
||||
m.top.callFunc("TestKey", RemoteKeys.Left, false)
|
||||
for i = 1 to 5
|
||||
m.top.callFunc("TestSetState", VideoState.Playing)
|
||||
end for
|
||||
m.top.close = true
|
||||
summary = m.global.telemetry.LogEvent
|
||||
m.assertTrue(summary.message.InStr("5 heals") > 0, "got: " + summary.message)
|
||||
m.assertTrue(summary.message.InStr("2 past the telemetry cap") > 0, "got: " + summary.message)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user