Repository navigation
ABR: the lookahead fetch is bounded by the stall guard like every active fetch - #209
Merged
Merged
Conversation
… active fetch pipe_abr_down_collapse (device): the link collapsed from 40 Mbps to 500 kbps while the ABR controller sat on rung 20000. Segment 11 (5.4 MB) then took 86.8 s and froze the picture for ~84 s, because hls_prefetch_same_encoder's same-encoder lookahead called hls_demux_segment(..., ReserveDeadlineState::new(None, false), None) — no stall guard at all — while the ordinary branch two lines above always armed one via arm_active_stall_guard. Both requests read the SAME active cursor at the SAME rung, but only one of them was ever able to observe the terminal-reserve boundary. Fix: hls_demux_segment now takes one required, role-typed SegmentAcquisition instead of the independently-optional (ReserveDeadlineState, Option<StallGuard>) pair that let "no reserve deadline AND no stall guard" compile at all. The Active role is opaque and buildable only through SegmentAcquisition::active, which performs the existing arm_active_stall_guard evaluation from live inputs (buffer reserve, at_floor, the shared terminal-hold flag) — so no active-cursor fetch, ordinary or lookahead, can skip it. Active vs Fixed is derived from hls_demux's own adaptive Option, not chosen per call site. Candidate warm-up/repeatable fetches move to a Candidate role that still carries no StallGuard, unchanged behaviorally. hls_prefetch_same_encoder's StallAbort is no longer swallowed by requeue-and-Ok(None) or allowed to escape via `?`: it is routed through hls_stall_abort_outcome, the same reducer the ordinary branch's StallAbort handling was extracted into, so both paths log, requeue exactly once, and hand back an abandoned round identically. The `prefetched` slot gained the abandoned-flag it was missing to carry that through. Regression test (red on old code, green after): drives the production read_cb callback under the ordinary policy and under the lookahead's actual policy against an identical terminal-hold-with-bytes-remaining condition; pre-fix the lookahead policy (hard-coded None) reads straight through the hold, post-fix it is built via SegmentAcquisition::active — the same constructor hls_prefetch_same_encoder now calls — and aborts identically. Also adds a unit test that the Active constructor preserves arm_active_stall_guard's unarmed exclusions (unknown/zero reserve, already-held clock). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hat the test drives
Round-2 review found the first fix incomplete on both must-fixes.
Must-fix 1 — the bypass was still representable. `SegmentAcquisition` and
`ActiveAcquisition` lived in `ff` itself, so anything in that one module could
still build `ActiveAcquisition { stall: None, .. }` by hand, or call the
private `SegmentAcquisition::Fixed`/`fixed()` shortcut, without ever running
`arm_active_stall_guard`. Moved both into a new child module
(`ff_acquisition.rs`, included the same way the `ff_*_tests.rs` files are)
whose payload lives in a private inner `Policy` enum `ff` cannot name — the
only way `ff` can produce a `SegmentAcquisition` at all now is this module's
`pub(super)` surface (`for_cursor`, `candidate`, `stall`, `into_parts`, and a
`#[cfg(test)]` `for_test`). There is no longer a `fixed()`: non-adaptive is
`for_cursor(None)`. `for_cursor` also stopped taking a caller-supplied
`at_floor: Option<bool>` — it now takes the authoritative adaptive context
itself (`Option<&abr::Controller>`, exactly what `hls_demux`'s own `adaptive`
holds) and reads the live buffer reserve and rebuffering hold itself, inside
the call, so a caller cannot hand it stale or fabricated inputs. Both the
ordinary fetch and the lookahead call this one constructor with the same
context.
Must-fix 2 — the regression test built its own `SegmentAcquisition` and drove
a hand-built `AvioState`/`read_cb` directly, so it could not see whether
`hls_prefetch_same_encoder`'s actual control flow ever reached that
construction. Split the lookahead into `hls_prefetch_same_encoder_with`, a
generic inner fn taking the demux call as an `FnOnce(&Segment, &mut
SegmentClock, SegmentAcquisition) -> Result<HlsSegmentOutput, HlsExit>`, and
a thin `hls_prefetch_same_encoder` wrapper that closes over the real
`hls_demux_segment`. The new test drives the inner fn with a fake demux that
records whether the acquisition it received was armed and returns
`HlsExit::StallAbort` on demand, then asserts the shared reducer's outcome:
`fetch_abandoned=true`, zero AUs, the segment requeued exactly once — never
`Ok(None)`. Proved as a real regression test: reverting the constructor call
to `for_cursor(None)` (the old unconditional-`None` bypass) turned it RED
(`left: Some(false), right: Some(true)`); reverting the `StallAbort` handling
to the old push_front+`Ok(None)` swallow also turned it RED (`a StallAbort
must still produce a round, never Ok(None)`); both are GREEN again restored.
Also adds `for_cursor_with_no_controller_is_unarmed` and renames the existing
constructor calls in the two prior tests from `active` to the `#[cfg(test)]`
`for_test` escape hatch the sealing now requires.
Small: the `for_cursor` doc corrected a wrong claim from round 1 — FFmpeg's
probe reads DO go through the guarded AVIO `read_cb`, so probing is covered;
the actually-uncovered legs are the HTTP open/connect+headers leg and the
`NotReady` wait inside `hls_demux_segment`, both of which precede any AVIO
read, plus a transport read already blocked when a hold transition arrives.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On the TV,
pipe_abr_down_collapsefailed onmain(28da566). It was 1 of 23 ABR cases; the other 22 passed. The link drops from 40 Mbps to 500 kbps while the controller is on rung 20000. Segment 11 (5.4 MB) then took 86.8 s, and the picture froze for 84.5 s (vgap=84522ms). Playback climbed 32 s where the case needs 45 s.The current-rung abort rule,
StallGuard, never fired: the log has noabr: stall abortline. The segment was fetched by the same-encoder lookahead that #89 added.hls_prefetch_same_encodercalledhls_demux_segment(…, ReserveDeadlineState::new(None, false), None), which meant no stall guard at all. On any error it also requeued the segment and returnedOk(None), so an abort would have been swallowed too. The ordinary fetch, a few lines above, always armed the guard for the same cursor.What
hls_demux_segmentused to take two independently optional arguments, and passing "neither" compiled. It now takes oneSegmentAcquisition. The type lives in a child module (ff_acquisition.rs) whose inner enum is private, soffcannot build one by hand.for_cursor(Option<&abr::Controller>)is the only constructor. It reads the live reserve, floor status and hold flag itself, and arms the guard through the existingarm_active_stall_guard.candidate(deadline), behaviour unchanged. All four callers are migrated.StallAborthandling was extracted intohls_stall_abort_outcome, and the lookahead now goes through it as well. Both paths requeue once, feed nothing, leave the timeline alone, and record the sample as.abandoned().hls_prefetch_same_encoder_with) is driven with a fake demux. The test went red under both reverts: making the lookahead unguarded again, and swallowing the abort again.read_cb-level test covers the abort itself.NotReadywait, and it does not wake a read that is already blocked when a hold starts. The ordinary fetch has always had these gaps, and they did not cause this failure.Verification
On the TV, with the final build deployed and verified by md5 before the run:
pipe_abr*21/0 andpipe_auto_*2/0.pipe_abr_down_collapse:abr: stall abort seq=11 … reserve=5626ms … cause=terminal_reserve. The freeze drops from 84.5 s to 5.8 s, and playback reaches pos=111 s.down_staircaseanddown_outrunstill pass.Committed tree:
make checkon 4b40837:test result: ok. 4199 passed; 0 failed,ok. 4250 passed; 0 failed,ok. 101 passed; 0 failed.--no-default-features: clean.This change touches no FFI or linkage. The doc-claim audit found one false claim, a test's own doc comment, and it is fixed here.
🤖 Generated with Claude Code