pub struct RtpPacketizer { /* private fields */ }ingest and (crate features rtsp or webrtc) only.Expand description
Packetizes H.264 Annex-B access units into RFC 6184 RTP packets — the inverse
of H264Depacketizer, used for WebRTC/WHEP egress.
Each NAL unit that fits the MTU is sent as a single-NAL packet; larger NALs are split into FU-A fragments. The RTP marker bit is set on the last packet of each access unit so the receiver knows the frame is complete.
Implementations§
Source§impl RtpPacketizer
impl RtpPacketizer
Sourcepub fn new(payload_type: u8, ssrc: u32, mtu: usize) -> Self
pub fn new(payload_type: u8, ssrc: u32, mtu: usize) -> Self
An H.264 packetizer for payload_type/ssrc. mtu is the maximum UDP
payload (1200 is the WebRTC-safe default); the 12-byte RTP header is
subtracted.
Sourcepub fn new_h265(payload_type: u8, ssrc: u32, mtu: usize) -> Self
pub fn new_h265(payload_type: u8, ssrc: u32, mtu: usize) -> Self
An H.265 (HEVC) packetizer, emitting the RFC 7798 payload format
(2-byte NAL header, FU type 49). Counterpart to new.
Sourcepub fn packetize(&mut self, access_unit: &[u8], timestamp: u32) -> Vec<Vec<u8>>
pub fn packetize(&mut self, access_unit: &[u8], timestamp: u32) -> Vec<Vec<u8>>
Packetize one Annex-B access unit at timestamp (90 kHz) into RTP packets.
Each NAL that fits the MTU is sent as a single-NAL packet; larger NALs are fragmented (FU-A for H.264, FU for H.265). The marker bit is set on the last packet of the access unit.
Allocating variant; prefer packetize_into on the
egress hot path to recycle packet buffers across frames.
Sourcepub fn packetize_into(
&mut self,
access_unit: &[u8],
timestamp: u32,
out: &mut Vec<Vec<u8>>,
)
pub fn packetize_into( &mut self, access_unit: &[u8], timestamp: u32, out: &mut Vec<Vec<u8>>, )
Packetize into a caller-owned buffer, recycling the Vec<u8> allocations
it already holds from a previous frame.
The hot-path contract: pass the same out every frame. On entry the
previously-produced (already-sent) packet buffers are reclaimed as a free
pool and refilled in place, so steady-state egress performs no per-packet
heap allocation.
Sourcepub fn fragment_into(&self, access_unit: &[u8], out: &mut Vec<RtpFragment>)
pub fn fragment_into(&self, access_unit: &[u8], out: &mut Vec<RtpFragment>)
Split an access unit into viewer-independent RtpFragments (the packet
payloads + marker bits), without touching the sequence number — so the
same packetizer (or a throwaway template one) can fragment once and every
viewer stamps the result with stamp_into.
This produces exactly the payloads packetize_into would, in the same
order (both drive the shared for_each_nal_packet walker); only the
per-session RTP header is deferred to stamp_into. The caller passes the
same out each frame to
recycle the fragment buffers.
Sourcepub fn stamp_into(
&mut self,
frag: &RtpFragment,
timestamp: u32,
out: &mut Vec<u8>,
)
pub fn stamp_into( &mut self, frag: &RtpFragment, timestamp: u32, out: &mut Vec<u8>, )
Turn one shared RtpFragment into a complete RTP packet on this session’s
timeline: writes the 12-byte header (this packetizer’s PT/SSRC + its own
monotonic sequence) at timestamp, then the fragment payload. Advances the
sequence number. The per-viewer counterpart to fragment_into.
Trait Implementations§
Source§impl Clone for RtpPacketizer
impl Clone for RtpPacketizer
Source§fn clone(&self) -> RtpPacketizer
fn clone(&self) -> RtpPacketizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more