pub struct TsFixBuilder { /* private fields */ }Expand description
Builder for TsFix.
Each repair operation is opt-in via a dedicated method. Methods that correspond to later tasks are listed here for documentation purposes but will be implemented in subsequent releases — attempting to call them will cause a compile error until they ship.
§Forward-compat guarantee
Adding a new builder method in v0.2/v0.3 is an additive change. Callers who
construct TsFix::builder().build()? (with no additional methods) will
compile and behave identically across versions.
Implementations§
Source§impl TsFixBuilder
impl TsFixBuilder
Sourcepub fn build(self) -> Result<TsFix, Error>
pub fn build(self) -> Result<TsFix, Error>
Build the configured engine.
When no operations have been registered the engine is an identity pass-through: every packet is emitted unchanged.
The engine applies operations in the canonical ordering:
filter_pids → regen_psi → repair_continuity → restamp_pcr →
honor_pcr_discontinuity → stuffing. The build() method sorts ops by
this order regardless of the order in which builder methods were
called.
Sourcepub fn repair_continuity(self) -> Self
pub fn repair_continuity(self) -> Self
Enable continuity counter repair.
Renumbers the 4-bit continuity_counter per PID to a correct monotonic
sequence (mod 16), respecting the ISO/IEC 13818-1 §2.4.3.3 rule that the
counter increments only on payload-bearing packets.
Sourcepub fn filter_pids(self, cfg: PidFilter) -> Self
pub fn filter_pids(self, cfg: PidFilter) -> Self
Enable PID filtering / service extraction.
Two modes:
PidFilter::keep— pass only packets whose PID is in the supplied set. PAT PID 0x0000 is always implicitly included.PidFilter::service— observe the live PAT/PMT and keep exactly the PIDs that belong to the given program_number (PAT + PMT PID + PCR PID + all ES PIDs); everything else is dropped.
§Example — extract service 1 from a multi-program mux
use ts_fix::{TsFix, PidFilter};
let mut engine = TsFix::builder()
.filter_pids(PidFilter::service(1))
.build()
.unwrap();Sourcepub fn regen_psi(self) -> Self
pub fn regen_psi(self) -> Self
Enable PAT/PMT regeneration.
Rebuilds the Program Association Table (PAT) to be consistent with the
actual programs present in the stream output. This is particularly useful
after filter_pids to ensure the PAT lists only the
programs that survived the filter.
The engine observes PAT sections as packets pass through, collecting the program → PMT PID mappings. On flush (end of stream), it emits a freshly-generated PAT listing exactly the observed programs.
§Example — filter to one service, then regenerate PAT
use ts_fix::{TsFix, PidFilter};
let mut engine = TsFix::builder()
.filter_pids(PidFilter::service(1))
.regen_psi()
.build()
.unwrap();Sourcepub fn restamp_pcr(self, cfg: PcrRestamp) -> Self
pub fn restamp_pcr(self, cfg: PcrRestamp) -> Self
Enable PCR restamping.
Recomputes the 42-bit Program Clock Reference on the PCR PID using a timing model (ISO/IEC 13818-1 §2.4.3.5). Two modes:
PcrRestamp::interpolate— interpolate PCRs between observed anchors.PcrRestamp::from_bitrate— recompute from a fixed bitrate.
PCR values are written in-place via mpeg-ts editors; the adaptation field layout is preserved.
§Example — restore a plausible PCR timeline
use ts_fix::{TsFix, PcrRestamp};
let mut engine = TsFix::builder()
.restamp_pcr(PcrRestamp::interpolate())
.build()
.unwrap();Sourcepub fn honor_pcr_discontinuity(self) -> Self
pub fn honor_pcr_discontinuity(self) -> Self
Enable PCR-discontinuity honor mode (#562).
The alternative to restamp_pcr: leaves every
timestamp byte — including the PCR field itself — untouched, and
instead sets discontinuity_indicator (ISO/IEC 13818-1 §2.4.3.5) on
packets where a genuine, unflagged PCR break exists.
“Genuine, unflagged” means the PCR delta exceeds the ETSI TR 101 290
v1.4.1 §5.2.2 Table 5.0b indicator 2.3b
(PCR_discontinuity_indicator_error) threshold with
discontinuity_indicator == 0 — reused verbatim from
dvb_conformance::ConformanceMonitor, never re-derived here. A
packet that already carries discontinuity_indicator == 1 is a legal
break and is left alone.
§Example — flag genuine PCR defects without rewriting values
use ts_fix::TsFix;
let mut engine = TsFix::builder()
.honor_pcr_discontinuity()
.build()
.unwrap();Sourcepub fn stuffing(self, cfg: Stuffing) -> Self
pub fn stuffing(self, cfg: Stuffing) -> Self
Enable null packet stuffing or drop.
Two modes:
Stuffing::drop_nulls— strip all null packets (PID 0x1FFF) from the output.Stuffing::pad_to— insert null packets to reach a target packet rate (e.g.pad_to(2.0)doubles the output packet count).
§Example — drop all null packets
use ts_fix::{TsFix, Stuffing};
let mut engine = TsFix::builder()
.stuffing(Stuffing::drop_nulls())
.build()
.unwrap();