Skip to main content

SectionReassembler

Struct SectionReassembler 

Source
pub struct SectionReassembler { /* private fields */ }
Expand description

Reassembles PSI/SI sections from TS packets on a single PID.

Feed each TS packet’s payload with feed. Complete sections are appended to an internal queue; drain them with pop_section.

Implementations§

Source§

impl SectionReassembler

Source

pub fn feed(&mut self, payload: &[u8], pusi: bool)

Feed a TS payload and whether its packet had PUSI set.

Extracts complete SI sections into the internal queue. A single call can produce zero, one, or several sections — a payload may concatenate multiple complete sections after the pointer_field (EN 300 468 §5.1.4; common on EMM PIDs). Drain with a while let Some(s) = r.pop_section() loop, not a single if let.

Examples found in repository?
examples/demux.rs (line 37)
27fn main() {
28    let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
29    println!(
30        "TS packet: pid=0x{:04X} pusi={} has_payload={}",
31        pkt.header.pid, pkt.header.pusi, pkt.header.has_payload
32    );
33
34    let mut reasm = SectionReassembler::default();
35
36    if let Some(payload) = pkt.payload {
37        reasm.feed(payload, pkt.header.pusi);
38    }
39
40    while let Some(section) = reasm.pop_section() {
41        println!(
42            "section: {} bytes, table_id=0x{:02X}",
43            section.len(),
44            section[0]
45        );
46        // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
47        if section.len() >= 5 {
48            let ts_id = u16::from_be_bytes([section[3], section[4]]);
49            println!("  transport_stream_id={}", ts_id);
50        }
51    }
52}
Source

pub fn pop_section(&mut self) -> Option<Bytes>

Pop one complete section. Returns None when the queue is empty.

Examples found in repository?
examples/demux.rs (line 40)
27fn main() {
28    let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
29    println!(
30        "TS packet: pid=0x{:04X} pusi={} has_payload={}",
31        pkt.header.pid, pkt.header.pusi, pkt.header.has_payload
32    );
33
34    let mut reasm = SectionReassembler::default();
35
36    if let Some(payload) = pkt.payload {
37        reasm.feed(payload, pkt.header.pusi);
38    }
39
40    while let Some(section) = reasm.pop_section() {
41        println!(
42            "section: {} bytes, table_id=0x{:02X}",
43            section.len(),
44            section[0]
45        );
46        // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
47        if section.len() >= 5 {
48            let ts_id = u16::from_be_bytes([section[3], section[4]]);
49            println!("  transport_stream_id={}", ts_id);
50        }
51    }
52}
Source

pub fn len(&self) -> usize

Number of bytes currently buffered (incomplete section).

Source

pub fn is_empty(&self) -> bool

True if no bytes are currently buffered.

Trait Implementations§

Source§

impl Default for SectionReassembler

Source§

fn default() -> SectionReassembler

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> 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.