pub struct SectionPacketiser { /* private fields */ }Expand description
Packetises PSI/SI sections into 188-byte TS packets.
This is the byte-exact inverse of
SectionReassembler::feed: packets
produced here, when fed back through the reassembler, yield the same
sections in order.
ISO/IEC 13818-1:2007 §2.4.4 (private/specs-verified/mpeg/mpeg-ts/tables/h222_0/psi_section.md).
Implementations§
Source§impl SectionPacketiser
impl SectionPacketiser
Sourcepub fn new(pid: Pid) -> Self
pub fn new(pid: Pid) -> Self
Start a packetiser for pid with continuity_counter = 0.
Examples found in repository?
examples/demux.rs (line 74)
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 with_continuity(pid: Pid, cc: ContinuityCounter) -> Self
pub fn with_continuity(pid: Pid, cc: ContinuityCounter) -> Self
Start at a specific continuity_counter — for resuming a stream.
Sourcepub fn continuity_counter(&self) -> ContinuityCounter
pub fn continuity_counter(&self) -> ContinuityCounter
The continuity_counter for the next emitted packet.
Sourcepub fn packetise_into(
&mut self,
sections: &[&[u8]],
out: &mut Vec<[u8; 188]>,
) -> usize
pub fn packetise_into( &mut self, sections: &[&[u8]], out: &mut Vec<[u8; 188]>, ) -> usize
Packetise a batch of complete sections into 188-byte TS packets,
appended to out (cleared first).
Returns the number of packets appended.
Examples found in repository?
examples/demux.rs (line 74)
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}Auto Trait Implementations§
impl Forget for SectionPacketiser
impl Freeze for SectionPacketiser
impl Move for SectionPacketiser
impl RefUnwindSafe for SectionPacketiser
impl Send for SectionPacketiser
impl Sync for SectionPacketiser
impl Unpin for SectionPacketiser
impl UnsafeUnpin for SectionPacketiser
impl UnwindSafe for SectionPacketiser
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