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>
impl<'a> PacketEnvelope<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self>
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.
Sourcepub fn encode(
codec: EnvelopeCodec,
presentation_time: i64,
decode_time: i64,
keyframe: bool,
data: &[u8],
extra_data: &[u8],
) -> Result<Vec<u8>>
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]);Sourcepub fn codec(self) -> Option<EnvelopeCodec>
pub fn codec(self) -> Option<EnvelopeCodec>
The codec, when the header names one this module knows.
Sourcepub fn presentation_time(self) -> i64
pub fn presentation_time(self) -> i64
Presentation timestamp, in the stream’s own units.
Sourcepub fn decode_time(self) -> i64
pub fn decode_time(self) -> i64
Decode timestamp, in the stream’s own units.
Sourcepub fn is_keyframe(self) -> bool
pub fn is_keyframe(self) -> bool
Whether the keyframe flag is set.
Sourcepub fn flags(self) -> u32
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.
Sourcepub fn reserved(self) -> u64
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.
Sourcepub fn header_extension(self) -> &'a [u8] ⓘ
pub fn header_extension(self) -> &'a [u8] ⓘ
Header bytes beyond the version-0 fields. Empty for version 0.
Sourcepub fn extra_data(self) -> &'a [u8] ⓘ
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.
Sourcepub fn trailing_bytes(self) -> &'a [u8] ⓘ
pub fn trailing_bytes(self) -> &'a [u8] ⓘ
Bytes after the lengths the header declares.
Sourcepub fn is_known_version(self) -> bool
pub fn is_known_version(self) -> bool
Whether the header is exactly version 0, the version this module writes.