pub struct ScatterFrame<F: PacketFormat> { /* private fields */ }Expand description
A sendable compressed frame held in ordered blocks, without joining them.
The first block holds the complete 44-byte envelope header for H.264, HEVC or AAC, or the first four bytes for SpeedHQ. Opus has no header.
§Examples
use grafton_ndi::advanced::{
EnvelopeCodec, PacketEnvelope, ScatterFrame, VideoCodec, VideoPacketFormat,
};
let packet =
PacketEnvelope::encode(EnvelopeCodec::H264, 0, 0, true, &[0x65; 64], &[0x67; 8])?;
let (header, rest) = packet.split_at(44);
let frame = ScatterFrame::new(
VideoPacketFormat::new(VideoCodec::H264, 1280, 720)?,
vec![header.to_vec(), rest.to_vec()],
)?;
assert_eq!(frame.total_bytes(), packet.len());Implementations§
Source§impl<F: PacketFormat> ScatterFrame<F>
impl<F: PacketFormat> ScatterFrame<F>
Sourcepub fn timecode(&self) -> Timecode
pub fn timecode(&self) -> Timecode
The timecode: crate::Timecode::SYNTHESIZE on a frame built for
sending without an explicit timecode.
Sourcepub fn set_timecode(&mut self, timecode: Timecode)
pub fn set_timecode(&mut self, timecode: Timecode)
Replace the frame’s timecode.
Sourcepub fn metadata(&self) -> Option<&str>
pub fn metadata(&self) -> Option<&str>
The per-frame metadata, if any. Unreadable received text is omitted.
Sourcepub fn metadata_status(&self) -> FrameMetadataStatus
pub fn metadata_status(&self) -> FrameMetadataStatus
Cached metadata presence or the reason unreadable text was withheld.
Sourcepub fn set_metadata(
&mut self,
metadata: impl Into<String>,
) -> Result<(), Rejected<String>>
pub fn set_metadata( &mut self, metadata: impl Into<String>, ) -> Result<(), Rejected<String>>
Replace frame metadata. Use Self::clear_metadata to remove it.
Invalid replacement text leaves the existing metadata unchanged.
§Errors
Returns the unchanged text in crate::Rejected, with
crate::Error::InvalidCString for an interior NUL, or
crate::Error::InvalidFrame when the emitted C string would
exceed the metadata size cap. NulError retains only the prefix
through the first NUL; crate::Rejected::into_inner returns all text.
Sourcepub fn clear_metadata(&mut self)
pub fn clear_metadata(&mut self)
Remove the frame metadata.
Sourcepub fn new(
format: F,
blocks: Vec<Vec<u8>>,
) -> Result<Self, Rejected<Vec<Vec<u8>>>>
pub fn new( format: F, blocks: Vec<Vec<u8>>, ) -> Result<Self, Rejected<Vec<Vec<u8>>>>
Take ownership of one frame’s blocks, in order.
§Errors
Returns the original blocks with Error::InvalidFrame if the list is
empty or exceeds MAX_SCATTER_BLOCKS, a block is empty, the frame
exceeds MAX_PACKET_BYTES, or the packet is not sendable in this format.
Sourcepub fn blocks(&self) -> impl ExactSizeIterator<Item = &[u8]>
pub fn blocks(&self) -> impl ExactSizeIterator<Item = &[u8]>
The blocks, in order.
Sourcepub fn into_blocks(self) -> Vec<Vec<u8>>
pub fn into_blocks(self) -> Vec<Vec<u8>>
Recover each original block, preserving order, allocation and capacity. The SDK’s writes remain in those blocks.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
The combined size of the blocks, in bytes.
Sourcepub fn into_contiguous_copy(self) -> CompressedFrame<F>
pub fn into_contiguous_copy(self) -> CompressedFrame<F>
Join the blocks into one newly allocated contiguous frame.