Skip to main content

TsFixBuilder

Struct TsFixBuilder 

Source
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

Source

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.

Source

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.

Source

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();
Source

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();
Source

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:

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();
Source

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();
Source

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();

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.