Skip to content

Forward-buffer window: 150-segment ceiling silently caps an "unbounded pre-buffer" host option (#102 follow-up) #207

Description

@fxndxs

What should the engine do?

Summary

LoadOptions.forwardBufferSegments (#102) made the loopback session's forward window configurable, but HLSVideoEngine.clampedForwardWindow caps it at 150 segments (~10 min at 4 s). A host that offers an explicit "buffer without limit" setting cannot honor it: any request above 150 clamps down, so a user who deliberately opted into pre-buffering the whole source for a flaky network (WAN/VPN streaming, commuting, trains/tunnels) still stalls once the connection drops for longer than ~10 minutes of content.

Proposal

Raise the ceiling from 150 to 2700 segments (~3 h at 4 s) — a pure sanity bound against accidental values that still covers a whole feature film. Hosts can then pass Int.max to mean "buffer the entire source". Floor (4) and nil default (10) stay unchanged, and 150 still passes through unchanged, so sessions that don't opt in are unaffected.

The cost profile stays the host's informed choice, as designed in #102: segments are disk-backed (mmap served, ~10 MB per 4K-HEVC segment — a fully cached 2 h film can occupy ~18 GB), and the producer front-loads the demux work. SegmentCache and HLSSegmentProducer take the window as plain arithmetic bounds (no fixed-size structures), so no other code change is needed; the backpressure/wedge machinery is untouched because the producer still paces against AVPlayer's fetch target plus the window.

If you'd rather keep 150 as the default ceiling, an alternative shape would be an explicit opt-in (e.g. forwardBufferSegments: .unbounded) — happy to rework the patch.

Patch

forward-window-ceiling.patch

Attached: git am-able patch against 5.20.4 (1abe7fa):

  • HLSVideoEngine.clampedForwardWindow: ceiling 150 → 2700, doc comment explains the whole-film rationale and disk math.
  • LoadOptions.forwardBufferSegments doc comment updated to match.
  • ForwardBufferWindowTests: ceiling tests updated (900/2700 pass through, 2701/Int.max clamp to 2700); floor and nil-default tests unchanged.

Motivating media or use case

Raise the clampedForwardWindow ceiling (currently 150 segments ≈ 10 min at 4 s) so a host's explicit "buffer without limit" option can actually pre-buffer a whole film — e.g. to 2700 segments (~3 h), with Int.max meaning "buffer the entire source". Floor (4) and the nil default (10) stay unchanged, and 150 still passes through, so sessions that don't opt in are unaffected.

Area

Performance

Host app / integration context

No response

Would you be willing to open a PR?

Maybe, with guidance

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions