Skip to main content

PacketEnvelope

Struct PacketEnvelope 

Source
pub struct PacketEnvelope<'a> { /* private fields */ }
Expand description

A bounds-checked view of a packet envelope: its header, codec payload and codec configuration data. encode builds one.

Parsing keeps what it does not understand. Flags, the reserved field and header bytes added by a later envelope version are all readable, so a received packet can be inspected or stored without loss.

Implementations§

Source§

impl<'a> PacketEnvelope<'a>

Source

pub fn parse(bytes: &'a [u8]) -> Result<Self>

Parse bytes as one packet envelope.

§Errors

Error::InvalidFrame when the slice is shorter than a header, longer than MAX_PACKET_BYTES, or shorter than the lengths its header declares.

Source

pub fn encode( codec: EnvelopeCodec, presentation_time: i64, decode_time: i64, keyframe: bool, data: &[u8], extra_data: &[u8], ) -> Result<Vec<u8>>

Build a version-0 packet envelope around one codec payload.

presentation_time and decode_time are in the stream’s own units. keyframe marks a video keyframe; AAC has no other kind of packet, so an AAC envelope carries the flag whatever keyframe says. extra_data is the codec configuration (parameter sets for H.264 and HEVC, the AudioSpecificConfig for AAC); video keyframes and every AAC packet need it to be sendable.

§Errors

Error::InvalidFrame when data is empty or the packet would exceed MAX_PACKET_BYTES.

§Examples
use grafton_ndi::advanced::{EnvelopeCodec, PacketEnvelope};

let packet = PacketEnvelope::encode(EnvelopeCodec::H264, 0, 0, true, &[0x65, 0x88], &[0x67, 0x42])?;
let view = PacketEnvelope::parse(&packet)?;
assert!(view.is_keyframe());
assert_eq!(view.data(), [0x65, 0x88]);
assert_eq!(view.extra_data(), [0x67, 0x42]);
Source

pub fn codec(self) -> Option<EnvelopeCodec>

The codec, when the header names one this module knows.

Source

pub fn fourcc(self) -> FourCc

The codec’s FourCC exactly as the header carries it.

Source

pub fn presentation_time(self) -> i64

Presentation timestamp, in the stream’s own units.

Source

pub fn decode_time(self) -> i64

Decode timestamp, in the stream’s own units.

Source

pub fn is_keyframe(self) -> bool

Whether the keyframe flag is set.

Source

pub fn flags(self) -> u32

The header’s flags field, every bit as the packet carries it, including bits this module does not interpret. is_keyframe reads the one it does.

Source

pub fn reserved(self) -> u64

The header’s reserved field.

The field belongs to the SDK, which overwrites it in every packet it sends. Its value says nothing about whether a packet can be sent.

Source

pub fn header_extension(self) -> &'a [u8] ⓘ

Header bytes beyond the version-0 fields. Empty for version 0.

Source

pub fn data(self) -> &'a [u8] ⓘ

The codec payload.

Source

pub fn extra_data(self) -> &'a [u8] ⓘ

Codec configuration data (parameter sets, or the AAC configuration), which follows the payload. Empty when the packet carries none.

Source

pub fn trailing_bytes(self) -> &'a [u8] ⓘ

Bytes after the lengths the header declares.

Source

pub fn is_known_version(self) -> bool

Whether the header is exactly version 0, the version this module writes.

Trait Implementations§

Source§

impl<'a> Clone for PacketEnvelope<'a>

Source§

fn clone(&self) -> Self

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<'a> Copy for PacketEnvelope<'a>

Source§

impl Debug for PacketEnvelope<'_>

Source§

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

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

impl<'a> Eq for PacketEnvelope<'a>

Source§

impl<'a> Hash for PacketEnvelope<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for PacketEnvelope<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for PacketEnvelope<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PacketEnvelope<'a>

§

impl<'a> RefUnwindSafe for PacketEnvelope<'a>

§

impl<'a> Send for PacketEnvelope<'a>

§

impl<'a> Sync for PacketEnvelope<'a>

§

impl<'a> Unpin for PacketEnvelope<'a>

§

impl<'a> UnsafeUnpin for PacketEnvelope<'a>

§

impl<'a> UnwindSafe for PacketEnvelope<'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<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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.