Skip to main content

PcrTracker

Struct PcrTracker 

Source
pub struct PcrTracker {
    pub max_jitter_27mhz: u32,
    /* private fields */
}
Expand description

Per-PCR-PID PCR recovery + discontinuity detector.

Construct one per PCR_PID and call [observe] for every TS packet on that PID. Packets without a PCR are silently ignored (the tracker still reads them for the discontinuity_indicator flag, since §2.4.3.5 allows the indicator to be set in packets prior to the one carrying the new PCR).

The tracker keeps the last PCR + byte-offset to compute the instantaneous bitrate, and the previous pair so a fresh sample can have its jitter computed without a second sample arriving.

Fields§

§max_jitter_27mhz: u32

Threshold (in 27 MHz ticks) beyond which an unsignalled jump is reported as a discontinuity. Defaults to 100 ms × 27000 = 2 700 000 ticks. The spec says ±500 ns is the spec tolerance; real-world re-mux jitter is far higher (tens of milliseconds) so we use a window large enough to ignore schedule wobble but small enough to catch a clean time-base reset.

Implementations§

Source§

impl PcrTracker

Source

pub const DEFAULT_MAX_JITTER_27MHZ: u32 = 2_700_000

Default jitter window: 100 ms.

At 27 MHz that’s 2 700 000 ticks. Comfortably above the ±500 ns spec PCR tolerance but tight enough that a clean re-mux time-base reset (which jumps by seconds or hours) fires the discontinuity path.

Source

pub fn new() -> Self

Build a tracker with the default jitter window.

Source

pub fn with_jitter_window(max_jitter_27mhz: u32) -> Self

Build a tracker with a custom jitter window (27 MHz ticks).

Source

pub fn observe( &mut self, af: &AdaptationField<'_>, byte_offset: u64, ) -> Option<PcrEvent>

Observe one packet’s adaptation field.

byte_offset is the position of this packet’s first byte in the contiguous TS stream. It only needs to be monotonic; the tracker uses differences, not absolute values. Typical callers pass bytes_read - 188.

Returns None when the packet had no PCR and no pending discontinuity to commit.

Source

pub fn last_pcr(&self) -> Option<Pcr>

Most recent PCR sample, if any.

Source

pub fn reset(&mut self)

Discard accumulated state — useful after the demuxer independently detects an EOF + restart (e.g. an HLS discontinuity boundary between two segments).

Trait Implementations§

Source§

impl Clone for PcrTracker

Source§

fn clone(&self) -> PcrTracker

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PcrTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PcrTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.