#[non_exhaustive]pub struct PacketRef<'a> {
pub track_id: u32,
pub pts: Timestamp,
pub dts: Timestamp,
pub dur: Duration,
pub trim_start: Duration,
pub trim_end: Duration,
pub data: &'a [u8],
}Expand description
A non-owning equivalent to Packet.
PacketRef is the zero-copy, non-owning, equivalent of Packet. It is particularly useful when
packet data is already residing in an application-managed fixed buffer or when data is
passed in from external environments like C/C++ via FFI. This allows decoders to process
the data directly without forcing a heap allocation and deep copy.
See Packet for more details on the various timing and implementation details.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.track_id: u32The track ID of the track this packet belongs to.
pts: TimestampThe presentation timestamp (PTS) of the packet in TimeBase units.+
This is the time relative to the start of the media that the decoded packet should be presented to the user.
dts: TimestampThe decode timestamp (DTS) of the packet in TimeBase units.
This is the time relative to the start of the media that the packet should be decoded.
dur: DurationThe duration of all valid frames in the packet in TimeBase units.
This duration excludes any delay or padding frames that may be produced by the decoder. Generally, delay or padding frames should not be presented to the user.
trim_start: DurationThe duration of decoded frames that should be trimmed from the start of the decoded buffer to remove encoder delay.
trim_end: DurationThe duration of decoded frames that should be trimmed from the end of the decoded buffer to remove encoder padding.
data: &'a [u8]The packet data buffer.
Implementations§
Source§impl<'a> PacketRef<'a>
impl<'a> PacketRef<'a>
Sourcepub fn new(track_id: u32, pts: Timestamp, dur: Duration, data: &'a [u8]) -> Self
pub fn new(track_id: u32, pts: Timestamp, dur: Duration, data: &'a [u8]) -> Self
Create a new untrimmed PacketRef.
The data slice can be constructed directly from a fixed-size buffer, or from
raw FFI pointers (e.g., a C++ std::vector payload) using std::slice::from_raw_parts.
Sourcepub const fn block_dur(&self) -> Duration
pub const fn block_dur(&self) -> Duration
Get the duration of all decoded frames in the packet in TimeBase units.
Sourcepub fn as_buf_reader(&self) -> BufReader<'_>
pub fn as_buf_reader(&self) -> BufReader<'_>
Get a BufReader to read the packet data buffer sequentially.