pub struct TsResync { /* private fields */ }Expand description
Stateful TS byte-stream resynchroniser (ISO/IEC 13818-1 §2.4.3.2).
Recovers 188-byte MPEG-TS packet alignment from an arbitrary byte stream that may start mid-packet or contain junk, and detects 204-byte Reed-Solomon-coded packets (stripping the 16 parity bytes).
Feed raw bytes with feed; each call returns a Vec of
aligned 188-byte TS packets. Bytes are buffered across calls so that
packet boundaries may span call boundaries freely.
Lock is declared after LOCK_CONFIRMATIONS consecutive sync bytes are
found at the candidate stride (188 or 204). On sync loss the resynchroniser
re-scans from the byte after the lost position.
§Stats
stats returns cumulative counters (packets emitted,
resyncs, dropped bytes).
Implementations§
Source§impl TsResync
impl TsResync
Sourcepub fn feed(&mut self, data: &[u8]) -> Vec<[u8; 188]>
pub fn feed(&mut self, data: &[u8]) -> Vec<[u8; 188]>
Feed data and emit every newly-aligned 188-byte TS packet.
For a 204-byte stream the 16 Reed-Solomon parity bytes are stripped; only the 188-byte TS payload is returned. Bytes that cannot yet form a complete packet (or fall before lock) are buffered for the next call.
Sourcepub fn feed_into(&mut self, data: &[u8], emitted: &mut Vec<[u8; 188]>) -> usize
pub fn feed_into(&mut self, data: &[u8], emitted: &mut Vec<[u8; 188]>) -> usize
feed appending to a caller-owned out (not cleared),
so a steady-state caller that reuses one Vec allocates nothing per
call (audit r01-O4). The output capacity is reserved once from the
buffered byte count instead of growing by doubling.
Returns the number of packets appended.
Sourcepub fn stride(&self) -> Option<PacketStride>
pub fn stride(&self) -> Option<PacketStride>
Detected packet stride, or None before the stream has locked.
Sourcepub fn stats(&self) -> ResyncStats
pub fn stats(&self) -> ResyncStats
Accumulated statistics.