pub struct HlsOriginBuilder { /* private fields */ }std only.Expand description
Fluent builder for HlsOrigin (issue #873) — replaces the old
four-positional HlsOrigin::new (deleted; this crate is at 0.4.0
unpublished, so there is no compatibility burden), which could not
express “classic HLS, no low latency” at all since part_target_ms was a
mandatory positional argument.
let classic_ts = HlsOrigin::builder(Arc::clone(&trunk))
.target_duration_secs(6.0)
.window_segments(nz(4))
.container(Container::MpegTs)
// `.low_latency(..)` omitted entirely -> classic HLS.
.build()
.expect("both required fields were set");Implementations§
Source§impl HlsOriginBuilder
impl HlsOriginBuilder
Sourcepub fn target_duration_secs(self, target_duration_secs: f64) -> Self
pub fn target_duration_secs(self, target_duration_secs: f64) -> Self
#EXT-X-TARGETDURATION’s configured floor (RFC 8216bis §4.4.3.1) —
required; HlsOriginBuilder::build errors if this is never called.
The actually-rendered value is raised to the largest real segment
duration seen, if that ever exceeds this (see render_playlist).
Sourcepub fn window_segments(self, window_segments: NonZeroUsize) -> Self
pub fn window_segments(self, window_segments: NonZeroUsize) -> Self
How many closed segments this origin advertises in a rendered Media
Playlist — required; independent of
media_plane::trunk::TrunkConfig::segment_capacity (the Trunk’s
own retention bound): a caller may legitimately want a shorter
advertised window than the Trunk retains for other consumers (e.g. a
DVR SegmentEgress reading the same Trunk).
Sourcepub fn container(self, container: Container) -> Self
pub fn container(self, container: Container) -> Self
Which container this origin serves segments/parts as. Defaults to
Container::Fmp4 if never called, matching every pre-#873 caller’s
behaviour. Orthogonal to Self::low_latency — all four
{Fmp4, MpegTs} x {classic, low-latency} combinations are valid.
Sourcepub fn low_latency(self, part_target_ms: u32) -> Self
pub fn low_latency(self, part_target_ms: u32) -> Self
Opt into LL-HLS: part_target_ms becomes #EXT-X-PART-INF’s
PART-TARGET (milliseconds). Omit this call entirely for classic
HLS — no #EXT-X-PART/#EXT-X-PART-INF/#EXT-X-SERVER-CONTROL/
#EXT-X-PRELOAD-HINT tags are then rendered, regardless of
Self::container. This is what the old constructor’s mandatory
part_target_ms positional could not express.
Sourcepub fn media_sequence_offset(self, offset: u64) -> Self
pub fn media_sequence_offset(self, offset: u64) -> Self
Add offset to every Media Sequence Number this origin shows: the
playlist’s EXT-X-MEDIA-SEQUENCE, the numbers in segment/part URIs and
the _HLS_msn it answers to. Default 0.
A fresh Trunk restarts its segment numbers at 1; the offset is
the mechanism that keeps the Media Sequence Number a client sees
increasing across a replacement origin (RFC 8216bis §6.2.2: it MUST NOT
decrease). Pass previous.next_media_sequence() — not - 1: the number
the previous origin’s open segment was shown with is skipped too, as
its parts were already served (see HlsOrigin::next_media_sequence).
Sourcepub fn instance(self, token: u64) -> Self
pub fn instance(self, token: u64) -> Self
Override the per-origin HlsOrigin::instance token (default: a fresh
wall-clock-seeded one per build). For deterministic tests and for an
embedder that wants names stable across a rebuild it knows is the
same media.
Sourcepub fn build(self) -> Result<HlsOrigin, HlsOriginBuildError>
pub fn build(self) -> Result<HlsOrigin, HlsOriginBuildError>
Build the HlsOrigin, subscribing its one SegmentCursor
immediately (so the window starts empty but never misses a segment
published from this point on).
Errors, never silently defaults, if Self::target_duration_secs or
Self::window_segments was never called, for a zero
Self::low_latency part target, or for an offset that cannot hold
the u32 sequence range.
The advertised window is never shorter than three segments, whatever
Self::window_segments says (RFC 8216bis §6.2.2: a live Playlist
MUST NOT be shortened below three Target Durations). Part retention is
not checked here: the part ring’s capacity belongs to the Trunk
and is not observable from it; the playlist only advertises the parts
of a closed segment while all of them are still resident.