Skip to main content

PacketRef

Struct PacketRef 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§track_id: u32

The track ID of the track this packet belongs to.

§pts: Timestamp

The 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: Timestamp

The 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: Duration

The 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: Duration

The duration of decoded frames that should be trimmed from the start of the decoded buffer to remove encoder delay.

§trim_end: Duration

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

Source

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.

Source

pub const fn block_dur(&self) -> Duration

Get the duration of all decoded frames in the packet in TimeBase units.

Source

pub fn as_buf_reader(&self) -> BufReader<'_>

Get a BufReader to read the packet data buffer sequentially.

Trait Implementations§

Source§

impl<'a> Clone for PacketRef<'a>

Source§

fn clone(&self) -> PacketRef<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PacketRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Packet> for PacketRef<'a>

Source§

fn from(packet: &'a Packet) -> Self

Converts to this type from the input type.
Source§

impl<'a> Copy for PacketRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PacketRef<'a>

§

impl<'a> RefUnwindSafe for PacketRef<'a>

§

impl<'a> Send for PacketRef<'a>

§

impl<'a> Sync for PacketRef<'a>

§

impl<'a> Unpin for PacketRef<'a>

§

impl<'a> UnsafeUnpin for PacketRef<'a>

§

impl<'a> UnwindSafe for PacketRef<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.