Repository navigation
Conversation
srperens
left a comment
There was a problem hiding this comment.
Verdict: Comment. The mechanism is right and the MP4 and MPEG-TS paths ran in CI. The Matroska path has not run in this repo's CI: its three tests return early on Linux's GStreamer 1.24. The Windows job (GStreamer 1.26.10) would run them.
Requested changes
- Maintainer: add the
ci:windowslabel. The Windows job installs.github/workflows/ci.yml:565—$GSTREAMER_VERSION = "1.26.10", so the mkv tests get pastbackend/tests/live_recorder_test.rs:1618—if container == "mkv" && gst::version() < (1, 26, 0, 0) {. Until then, the only evidence forbackend/src/blocks/builtin/live_recorder/fragment_sink.rs:364—Format::Matroska => state.file_base?.checked_mul(1_000_000)?,is the author's macOS run.
Claims
| Claim | Verdict | Evidence |
|---|---|---|
| MP4 start is the decode time the file is moved back by | CONFIRMED |
backend/src/blocks/builtin/live_recorder/fragment_sink.rs:431 — state.file_base = mp4_boxes::fragment_start_ns(&bytes, &state.timescales);, set by the first fragment and reported in the same handle call |
| The callback runs without the sink's state lock | CONFIRMED |
backend/src/blocks/builtin/live_recorder/fragment_sink.rs:542 — callback(&self.obj(), index, &path, start); is reached only from report(), after every state guard has dropped (render, EOS, PausedToReady). The closure gets the sink as an argument and captures no element |
| Matroska cluster time is in 1 ms units | EXTERNAL |
Assumes matroskamux's default TimestampScale, which this block does not override |
Diagnosis. Taking the start from what the sink already moves each file back by is the right layer. It is the one value both muxers write into the file. Coverage is BOUNDED: MPEG-TS gets no start (stated), and audio-only Opus MKV is about 6 ms off after the first file (stated, out of scope).
Side effects worth knowing.
- The first MP4 file is now announced up to one fragment late. That is 1 s, from
backend/src/blocks/builtin/live_recorder/mod.rs:61—const FRAGMENT_DURATION: gst::ClockTime = gst::ClockTime::from_seconds(1);. The GUI starts its elapsed timer on that event (frontend/src/app/update.rs:854—.or_insert_with(instant::Instant::now);), so that timer now reads up to 1 s short. backend/src/blocks/builtin/live_recorder/utc.rs:20—static RUNNING_ZERO_UTC_NS: OnceLock<Mutex<HashMap<FlowId, RunAnchor>>> = OnceLock::new();keys onFlowId, which is right per CLAUDE.md. It is never pruned, so it keeps one small entry per flow ever recorded. It holds only aWeakRefto the clock. I raised the same point on #944.
Contract. RecorderFileChanged gains two optional fields, and the body flags this as an intentional change, as CLAUDE.md requires. openapi.json is updated, and API Contract Check is green.
Radius. SHARED: a strom-types event, both recorder blocks, the frontend, and API clients.
Overlaps. None own this decision. #1056, #1025 and #897 also edit openapi.json, a mechanical conflict for whichever lands second.
Tests & CI. At 8eb54d5, all 8 file_start_time tests print ok in Check (Linux), but the 3 mkv_* tests return before asserting anything, as the body says. Check (Linux), both Linux builds, WASM, API Contract and Static JS are green. macOS and Windows were skipped.
Confidence: HIGH
Reverts #578: a recorder's first part stamped by rule 2 (event) keeps the uncorrected event receipt time instead of being moved back by the file's trackStartOffsetMs. #569 acceptance run attempt 6 showed the correction over-corrects (SRT input part 0 came out about 1.1 s early against program). Follows @svensson00's product call on #569 (2026-10-26): options (a) and (b) of #579, not (c). AC 3 for input parts depends on Eyevinn/strom#1057 and stays tracked in #579. Spec §6 and ADR-011 Amendment 1 record the anchor and the verification plan. Part of #579 Part of #569 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@srperens could this one get a review when you have a moment? It has been green since 9 Oct. Open Live's start-time check for input recordings (Eyevinn/open-live#579) is blocked until it lands, and it touches the same Live Recorder block as #1107. |
8eb54d5 to
af44727
Compare
srperens
left a comment
There was a problem hiding this comment.
Area: Live Recorder file timeline (RecorderFileChanged start times)
Adds start_running_time_ns/start_utc_us, taken from the base the fragment sink already shifts each MP4/MKV file by. Right layer; approach unchanged since the review at 8eb54d5.
Since 8eb54d5: a rebase onto #1034's finish_file and #1107's MP4 index, with conflicts resolved. Reports are still queued before the file is finished (fragment_sink.rs:358, :330-333), and the index is built from already-shifted fragments, so the start is unaffected. No author reply to the earlier review.
Earlier findings:
- MKV untested in CI: fixed by CI, not this PR. Check (Linux) now runs GStreamer 1.28.2 (ci.yml:117), and all three
mkv_*file_start_timetests ran at this head. The body's "Linux CI has 1.24, run the Windows job" is stale. - GUI elapsed timer up to 1 s short: still open (inline).
- UTC anchor map never pruned: still open, minor (inline).
Neighbours: #690 asks for a flow-wide wall-clock/running-time mapping; utc.rs builds one privately for this block, and #1103 and #966 ask the same question. Whoever settles #690 should reuse or replace this anchor, not add a second. #1075 also edits live_recorder_test.rs (text conflict only).
Contract: the variant change is flagged as intentional, openapi.json is updated, API Contract Check is green. Checks: Linux, floor, WASM, builds green; macOS/Windows skipped.
| flow_id, | ||
| block_id, | ||
| filename, | ||
| .. |
There was a problem hiding this comment.
Still open from the last review: the elapsed timer starts on this event (or_insert_with(instant::Instant::now) just below). The first MP4 file is now announced at its first fragment, up to FRAGMENT_DURATION (1 s, live_recorder/mod.rs:61) after it opens, so the timer reads up to 1 s short. start_utc_us is now on the event, so the timer could start from that instead.
There was a problem hiding this comment.
Posted by Claude on behalf of Peter.
Fixed in b885a15. The timer now starts from start_utc_us when that is 0-5 s before the event arrives, so a late MP4 announcement no longer shortens it. It falls back to the arrival time when the field is absent (MPEG-TS) or the GUI and server clocks disagree by more than that. Covered by two unit tests in update.rs.
| /// out of step by that drift. One anchor keeps every recorder in the run on the | ||
| /// same mapping; only the absolute time drifts. | ||
| type RunAnchor = (gst::glib::WeakRef<gst::Clock>, gst::ClockTime, i128); | ||
| static RUNNING_ZERO_UTC_NS: OnceLock<Mutex<HashMap<FlowId, RunAnchor>>> = OnceLock::new(); |
There was a problem hiding this comment.
Keyed on FlowId, which matches CLAUDE.md. Still never pruned, though: one entry stays for every flow ever recorded, even after the flow is deleted. It is small and holds only a WeakRef to the clock. Minor, raised before with no reply.
There was a problem hiding this comment.
Posted by Claude on behalf of Peter.
Fixed in b885a15. Each entry now also holds a weak reference to the flow's pipeline, and entries whose pipeline is gone are dropped whenever a new anchor is taken. The clock reference could not serve for this because the system clock outlives every pipeline. The new test a_stopped_flow_leaves_no_anchor_behind fails with the pruning line removed.
srperens
left a comment
There was a problem hiding this comment.
Area: Live Recorder file timeline (RecorderFileChanged start times)
Adds start_running_time_ns/start_utc_us to RecorderFileChanged, taken from the base the fragment sink already moves each MP4/MKV file back by. The approach looks right. The first two commits are identical to af44727 in range-diff; this covers b885a15 and rechecks the whole PR.
b885a15 fixes the two open points:
- GUI timer starts from
start_utc_uswhen that falls 0-5 s before the event arrives, else from arrival (frontend/src/app/update.rs:2213-2223). Minor note inline. - UTC anchors are pruned. Each entry holds only a
WeakRefto the top-level pipeline (utc.rs:23-28, :77), so no reference cycle. Dead entries drop when the next anchor is taken (utc.rs:60);a_stopped_flow_leaves_no_anchor_behindcovers it and ran in Check (Linux).
Neighbours: #690, #1103 and #966 ask the same wall-clock to running-time question; whoever settles #690 should reuse or replace utc.rs, not add a second mapping. #1075 and #786 are text conflicts only.
Contract: the variant change is flagged as intentional, openapi.json is updated, API Contract Check is green. The anchor is keyed on FlowId.
Tests: Check (Linux) ran all 8 file_start_time tests, mkv included (GStreamer 1.28), and the new utc and recording_started_at unit tests. Linux, 1.22 floor, WASM and Static JS green; macOS and Windows skipped. Not built or run here.
| /// How far a file's start may lie before the event announcing it and still be | ||
| /// believed. The event trails the file by up to one MP4 fragment; a larger gap | ||
| /// means the GUI and the server disagree about the time of day. | ||
| const MAX_ANNOUNCE_LAG: std::time::Duration = std::time::Duration::from_secs(5); |
There was a problem hiding this comment.
Minor. The window is 5 s, but the event trails the file by about one fragment (FRAGMENT_DURATION = 1 s, live_recorder/mod.rs:61). So any browser-to-server clock skew of up to about 4 s, with the browser ahead, gets through silently, and the timer reads that much long. Before this change it was at most 1 s short. A native GUI on the server host is not affected. If isofmp4mux can make fragments longer than 1 s (a GOP longer than the fragment), 5 s may be needed; not verified. Fine for a display timer, but the doc comment could say that skew inside the window is not detected.
There was a problem hiding this comment.
From Claude on behalf of @wagenet. Agreed, and the fragment length was the open question here. FRAGMENT_DURATION is a minimum: the muxer is built with send-force-keyunit off (live_recorder/mod.rs:257), so a fragment ends at the first keyframe after 1 s. The event therefore trails the file by max(1 s, GOP). With a GOP over 5 s the check fails and the timer starts at arrival, as before this PR. Skew of up to about 4 s with a 1 s fragment still passes unnoticed. Fixed in b460800: the doc comments on MAX_ANNOUNCE_LAG and recording_started_at say both. I left the window at 5 s.
| .ok()?; | ||
| let zero_ns = match anchors.get(&flow_id) { | ||
| Some((anchor_clock, _, base, zero_ns)) | ||
| if *base == base_time && anchor_clock.upgrade().as_ref() == Some(&clock) => |
There was a problem hiding this comment.
Minor, and an edge case. A rerun reuses the entry when the base time and the clock both match. A flow with Monotonic and direct media timing uses the singleton clock (gst/pipeline/construction.rs:600) and base time 0 (construction.rs:661), so a later run reuses the first run's anchor, and its drift keeps growing across runs instead of being sampled again. Construction warns that this combination is unlikely to be useful (:651-655). Now that the entry holds the pipeline weakly, adding pipeline.upgrade() == top_level(element) to this guard would make it one anchor per run in that case too.
There was a problem hiding this comment.
From Claude on behalf of @wagenet. Confirmed: Monotonic with direct media timing gives the singleton clock and base time 0 on every run, so the old guard reused the first run's anchor. The guard now also requires the same pipeline (anchor_pipeline.upgrade() == top_level(element)), fixed in 9bd29f8. a_rerun_with_the_same_clock_and_base_time_takes_its_own_anchor builds two successive pipelines with base time 0 on the same clock; it fails at the anchor assertion with the pipeline condition removed.
b460800 to
c67d811
Compare
RecorderFileChanged gains start_running_time_ns (running time of the file's t=0) and start_utc_us (that running time on the wall clock), so files from separate recorders can be lined up. Both are optional; the Recorder leaves them None. The fragment sink already moves each MP4 and Matroska file back to start at zero. What it moves it back by is the start: isofmp4mux and matroskamux write running time into tfdt and cluster timestamps, whatever segment they put on their output (isofmp4mux's starts at 1000 h). The sink now reports a file once that is known, at its first fragment or cluster, which for the first MP4 file is up to a fragment after the init segment opened it. MPEG-TS files are reported at once without a start: a player starts them at their earliest PTS, which the sink would have to read from the PES headers. UTC uses one anchor per flow run (flow, clock and base time), so every recorder in the run maps running time the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
two_video_recorders_line_up ran a 5 s source, so the recorder that opens 1.3 s late got about 3.7 s of video with a split every 2 s. Its last fragment could then land alone after the split, where the sink keeps it in the current file rather than open a file for it, and the test saw one file where it wants several: 1 failure in 2 full runs. An 8 s source leaves two whole splits; 4 of 4 runs and the full suite pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first MP4 file is announced with its first fragment, up to one second after it opened, so the GUI's elapsed timer read that much short. Start it from start_utc_us when that lies within five seconds before now, and fall back to the arrival time otherwise (no start reported, or the GUI and server clocks disagree). The per-flow UTC anchor map kept an entry for every flow ever recorded. It now holds the flow's pipeline weakly and drops entries whose pipeline is gone each time a new anchor is taken. The clock cannot serve for this: the system clock outlives every pipeline. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The anchor entry was reused when the base time and clock matched. A flow with Monotonic clock and direct media timing has the singleton clock and base time 0 on every run, so a rerun kept the first run's anchor and its drift grew across runs. The entry now also has to belong to the same pipeline. The doc comment on MAX_ANNOUNCE_LAG says that clock skew inside the window is not detected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The muxer is built with send-force-keyunit off, so a fragment ends at the first keyframe after the fragment duration. With a GOP longer than the 5 s window the timer starts at arrival. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
c67d811 to
1c051e5
Compare
Written by Claude (Claude Code).
Replaces #1042, which closed with its base branch when #1034 merged. Same two commits, rebuilt on
main. #1042 replaced #944, which did this on the Recorder.Problem
Files from two recorders in one flow could not be lined up:
RecorderFileChangednamed a file but not where its timeline sits.Change
RecorderFileChangedgainsstart_running_time_ns(the running time of the file's t=0) andstart_utc_us(that time on the wall clock), both optional.tfdtand cluster timestamps, whatever their output segment says. isofmp4mux's segment starts at 1000 h, so converting through it gives nothing.two_video_recorders_line_upgets an 8 s source, so it always sees two whole splits.Evidence
live_recorder_test.rs, modulefile_start_time. Every sample in every file must be an input buffer atstart + file time, within 1 ms. Audio is matched on size too, and video on painted white frames.two_video_recorders_line_up(one starts 1.3 s late)..._00000.mp4: no start_running_time_nsone_track_files_map_to_their_inputsfirst_file_starts_at_the_earliest_trackAlso
a_rerun_on_another_clock_maps_to_utc_afreshandmpegts_files_are_reported_at_once_without_a_start.Re-run on this branch, each with the smallest revert of one behaviour; every one fails its test:
maps to running time 3600000000.169 ms, but the nearest input buffer is at 3483.140 msmaps to running time 47.000 ms, but the nearest input buffer is at 48.076 ms..._00000.mp4: no start_running_time_nsmpegts_files_are_reported_at_once_without_a_startrealtime: start_utc_us ... is 1790793245 s from nowfiles in one flow run map running time to UTC differently(spread 23 µs)Tests
Ran on this branch (macOS, GStreamer 1.28.6):
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace --no-fail-fast: 1482 passed, 0 failed, 12 ignored. All 8file_start_timetests executed.In CI only 5 of the 8 run. The three mkv tests return early before GStreamer 1.26, as #1034's mkv tests do, and Linux CI has 1.24. Could a maintainer run the Windows job?
Checked in a review run, not committed as tests: B-frame video (x264
bframes=2, mp4 and mkv), Opus alone and with H.264 (mp4 and mkv). All within 1 ms, except the limit below.For the reviewer
This changes an existing
StromEventvariant on purpose. JSON clients see new fields only, but a Rust pattern without..stops compiling. The two in this repo are updated.Out of scope
live_recorder_test.rsis now about 1900 lines. Movingfile_start_timeand the helpers it uses into a file of its own is a follow-up.🤖 Generated with Claude Code