pub struct UnitReassembler<F> { /* private fields */ }Expand description
Reassembles units of one format from the payloads of one PID’s packets.
Implementations§
Source§impl<F: Framing> UnitReassembler<F>
impl<F: Framing> UnitReassembler<F>
Sourcepub fn new(framing: F, options: UnitOptions) -> Self
pub fn new(framing: F, options: UnitOptions) -> Self
A reassembler for framing with the caller’s options.
Examples found in repository?
examples/demux.rs (lines 61-69)
45fn main() {
46 let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
47 println!(
48 "TS packet: pid=0x{:04X} pusi={} has_payload={}",
49 pkt.header.pid.value(),
50 pkt.header.pusi,
51 pkt.header.has_payload()
52 );
53 assert_eq!(pkt.header.pid, well_known::PAT);
54
55 let mut reasm = SectionReassembler::default();
56
57 if let Some(payload) = pkt.payload {
58 reasm.feed(payload, pkt.header.pusi);
59 }
60
61 let mut units = UnitReassembler::new(
62 PatFraming,
63 UnitOptions::new(
64 AfterContinuation::DiscardRest,
65 PointerCheck::Authoritative,
66 Duplicates::Any,
67 std::num::NonZeroUsize::new(1024).unwrap(),
68 ),
69 );
70
71 while let Some(section) = reasm.pop_section() {
72 let mut packets = Vec::new();
73 let count =
74 SectionPacketiser::new(well_known::PAT).packetise_into(&[§ion], &mut packets);
75 println!(
76 "re-packetised {count} PAT packet(s), section: {} bytes, table_id=0x{:02X}",
77 section.len(),
78 section[0]
79 );
80 // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
81 if section.len() >= 5 {
82 let ts_id = u16::from_be_bytes([section[3], section[4]]);
83 println!(" transport_stream_id={ts_id}");
84 }
85 if let Some(payload) = pkt.payload {
86 units.feed(payload, pkt.header.pusi, None);
87 if let Some(unit) = units.pop() {
88 println!(" unit reassembled: {} bytes", unit.len());
89 }
90 }
91 }
92}Sourcepub fn feed(
&mut self,
payload: &[u8],
pusi: bool,
continuity: Option<Continuity>,
) -> Fed
pub fn feed( &mut self, payload: &[u8], pusi: bool, continuity: Option<Continuity>, ) -> Fed
Feed one packet’s payload and its PUSI flag. With continuity, a legal
duplicate of the previous payload (same counter, identical bytes, no
discontinuity) is discarded.
Examples found in repository?
examples/demux.rs (line 86)
45fn main() {
46 let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
47 println!(
48 "TS packet: pid=0x{:04X} pusi={} has_payload={}",
49 pkt.header.pid.value(),
50 pkt.header.pusi,
51 pkt.header.has_payload()
52 );
53 assert_eq!(pkt.header.pid, well_known::PAT);
54
55 let mut reasm = SectionReassembler::default();
56
57 if let Some(payload) = pkt.payload {
58 reasm.feed(payload, pkt.header.pusi);
59 }
60
61 let mut units = UnitReassembler::new(
62 PatFraming,
63 UnitOptions::new(
64 AfterContinuation::DiscardRest,
65 PointerCheck::Authoritative,
66 Duplicates::Any,
67 std::num::NonZeroUsize::new(1024).unwrap(),
68 ),
69 );
70
71 while let Some(section) = reasm.pop_section() {
72 let mut packets = Vec::new();
73 let count =
74 SectionPacketiser::new(well_known::PAT).packetise_into(&[§ion], &mut packets);
75 println!(
76 "re-packetised {count} PAT packet(s), section: {} bytes, table_id=0x{:02X}",
77 section.len(),
78 section[0]
79 );
80 // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
81 if section.len() >= 5 {
82 let ts_id = u16::from_be_bytes([section[3], section[4]]);
83 println!(" transport_stream_id={ts_id}");
84 }
85 if let Some(payload) = pkt.payload {
86 units.feed(payload, pkt.header.pusi, None);
87 if let Some(unit) = units.pop() {
88 println!(" unit reassembled: {} bytes", unit.len());
89 }
90 }
91 }
92}Sourcepub fn pop(&mut self) -> Option<Bytes>
pub fn pop(&mut self) -> Option<Bytes>
The next complete unit.
Examples found in repository?
examples/demux.rs (line 87)
45fn main() {
46 let pkt = TsPacket::parse(&PAT_PACKET).expect("hardcoded packet must parse");
47 println!(
48 "TS packet: pid=0x{:04X} pusi={} has_payload={}",
49 pkt.header.pid.value(),
50 pkt.header.pusi,
51 pkt.header.has_payload()
52 );
53 assert_eq!(pkt.header.pid, well_known::PAT);
54
55 let mut reasm = SectionReassembler::default();
56
57 if let Some(payload) = pkt.payload {
58 reasm.feed(payload, pkt.header.pusi);
59 }
60
61 let mut units = UnitReassembler::new(
62 PatFraming,
63 UnitOptions::new(
64 AfterContinuation::DiscardRest,
65 PointerCheck::Authoritative,
66 Duplicates::Any,
67 std::num::NonZeroUsize::new(1024).unwrap(),
68 ),
69 );
70
71 while let Some(section) = reasm.pop_section() {
72 let mut packets = Vec::new();
73 let count =
74 SectionPacketiser::new(well_known::PAT).packetise_into(&[§ion], &mut packets);
75 println!(
76 "re-packetised {count} PAT packet(s), section: {} bytes, table_id=0x{:02X}",
77 section.len(),
78 section[0]
79 );
80 // The PAT section bytes: table_id=0x00, transport_stream_id at bytes 3-4.
81 if section.len() >= 5 {
82 let ts_id = u16::from_be_bytes([section[3], section[4]]);
83 println!(" transport_stream_id={ts_id}");
84 }
85 if let Some(payload) = pkt.payload {
86 units.feed(payload, pkt.header.pusi, None);
87 if let Some(unit) = units.pop() {
88 println!(" unit reassembled: {} bytes", unit.len());
89 }
90 }
91 }
92}Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forget the unit in progress and the sync state: nothing is accepted again until the next PUSI.
Sourcepub fn take_buffered(&mut self) -> Bytes
pub fn take_buffered(&mut self) -> Bytes
Take the bytes of the unit in progress, leaving the sync state alone.
Sourcepub fn drop_buffered(&mut self)
pub fn drop_buffered(&mut self)
Discard the bytes of the unit in progress, leaving the sync state alone.
Trait Implementations§
Auto Trait Implementations§
impl<F> Forget for UnitReassembler<F>
impl<F> Freeze for UnitReassembler<F>
impl<F> Move for UnitReassembler<F>
impl<F> RefUnwindSafe for UnitReassembler<F>where
F: RefUnwindSafe,
NonZero<usize>: RefUnwindSafe,
Atomic<usize>: RefUnwindSafe,
Atomic<*mut ()>: RefUnwindSafe,
impl<F> Send for UnitReassembler<F>
impl<F> Sync for UnitReassembler<F>
impl<F> Unpin for UnitReassembler<F>
impl<F> UnsafeUnpin for UnitReassembler<F>where
F: UnsafeUnpin,
NonZeroUsizeInner: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
*mut Shared: UnsafeUnpin,
PhantomData<Bytes>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl<F> UnwindSafe for UnitReassembler<F>where
F: UnwindSafe,
NonZero<usize>: UnwindSafe,
NonNull<u8>: UnwindSafe,
*mut Shared: UnwindSafe,
RawVecInner: UnwindSafe,
*const u8: UnwindSafe,
Align8<*mut ()>: UnwindSafe,
&'static Vtable: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more