pub struct AudioFrame { /* private fields */ }Expand description
Owned, tightly packed planar floating-point audio with a validated layout.
Channel samples are contiguous, with channels stored one after another. Conversion from borrowed SDK audio omits inter-channel padding. Cloning copies the samples, readable metadata and metadata status, including when received text was withheld.
Implementations§
Source§impl AudioFrame
impl AudioFrame
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Get the sample rate in Hz.
Sourcepub fn num_channels(&self) -> u32
pub fn num_channels(&self) -> u32
Get the number of audio channels.
Sourcepub fn num_samples(&self) -> u32
pub fn num_samples(&self) -> u32
Get the number of samples per channel.
Sourcepub fn timecode(&self) -> Timecode
pub fn timecode(&self) -> Timecode
Get the timecode.
A built frame starts with Timecode::SYNTHESIZE; a copy of a
received frame keeps the timecode it arrived with.
Sourcepub fn timestamp(&self) -> Option<ReceivedTimestamp>
pub fn timestamp(&self) -> Option<ReceivedTimestamp>
The source-dependent timestamp of the received frame.
A frame has one only when it was copied from a received frame that carries one; frames built for sending have none.
Sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Get the audio format.
It is a supported format, validated when the frame was constructed.
Sourcepub fn channel_stride_bytes(&self) -> usize
pub fn channel_stride_bytes(&self) -> usize
Get the distance between the starts of consecutive channels in bytes.
It is one channel’s samples, since an owned frame has no padding.
Sourcepub fn metadata(&self) -> Option<&str>
pub fn metadata(&self) -> Option<&str>
Get frame metadata as UTF-8 text, if present.
Empty metadata, Some(""), is distinct from none, None.
Unreadable received text returns None; use
Self::metadata_status to distinguish it from absent text.
Sourcepub fn metadata_status(&self) -> FrameMetadataStatus
pub fn metadata_status(&self) -> FrameMetadataStatus
The metadata’s presence or the reason unreadable received text was withheld. Querying the cached status allocates nothing.
Sourcepub fn channel_data(&self, channel: usize) -> Option<&[f32]>
pub fn channel_data(&self, channel: usize) -> Option<&[f32]>
Get one channel’s samples, or None for an invalid channel.
The slice borrows the frame’s samples without copying and excludes any padding between channels.
Samples for this channel are contiguous in the packed planar data.
Sourcepub fn channels(&self) -> AudioChannels<'_> ⓘ
pub fn channels(&self) -> AudioChannels<'_> ⓘ
Iterate over the channels’ samples, in channel order, without copying or reading padding between channels.
Sourcepub fn data(&self) -> &[f32]
pub fn data(&self) -> &[f32]
Get tightly packed planar audio as 32-bit floats. Each channel’s samples are contiguous; channels follow one another.
Sourcepub fn to_owned(&self) -> AudioFrame
pub fn to_owned(&self) -> AudioFrame
Copy this frame, its readable metadata and its metadata status into independent owned storage.
Sourcepub fn copy_into(&self, destination: &mut AudioFrame)
pub fn copy_into(&self, destination: &mut AudioFrame)
Copy samples, header, timestamp and metadata into a reusable owned frame. Existing sample and metadata capacity is reused when it is sufficient.
Source§impl AudioFrame
impl AudioFrame
Sourcepub fn from_interleaved(source: &InterleavedAudioF32<'_>) -> Self
pub fn from_interleaved(source: &InterleavedAudioF32<'_>) -> Self
Copy validated interleaved floating-point samples into packed planar audio.
This conversion needs no NDI runtime and allocates only the output
samples. It preserves the input’s timecode; metadata is absent and the
received timestamp is None. Use Self::set_metadata to attach metadata.
Sourcepub fn builder() -> AudioFrameBuilder
pub fn builder() -> AudioFrameBuilder
Create a builder for a frame to send.
Its defaults are 48 kHz stereo FLTP with 1024 samples per channel,
planar input, Timecode::SYNTHESIZE, no metadata and silent
samples.
Sourcepub fn set_timecode(&mut self, timecode: Timecode)
pub fn set_timecode(&mut self, timecode: Timecode)
Set the timecode without reallocating the samples.
Sourcepub fn into_data(self) -> Vec<f32>
pub fn into_data(self) -> Vec<f32>
Recover tightly packed planar samples, retaining their allocation and capacity.
Sourcepub fn swap_data(
&mut self,
data: Vec<f32>,
) -> Result<Vec<f32>, Rejected<Vec<f32>>>
pub fn swap_data( &mut self, data: Vec<f32>, ) -> Result<Vec<f32>, Rejected<Vec<f32>>>
Replace samples and return the previous vector for allocation reuse.
§Errors
Returns data unchanged with Error::InvalidFrame unless it has
exactly the validated sample count. The frame is unchanged.
Sourcepub fn data_mut(&mut self) -> &mut [f32]
pub fn data_mut(&mut self) -> &mut [f32]
Get mutable audio sample data without changing the validated layout.
Sourcepub fn replace_data(&mut self, data: Vec<f32>) -> Result<(), Rejected<Vec<f32>>>
pub fn replace_data(&mut self, data: Vec<f32>) -> Result<(), Rejected<Vec<f32>>>
Replace the owned audio data while preserving the validated layout.
§Errors
Returns data, unused, with Error::InvalidFrame if it is not
exactly the validated sample count. The frame is unchanged.
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.
Valid replacement text sets FrameMetadataStatus::Text, including
an empty string. Invalid replacement text leaves the existing metadata
and its status unchanged.
§Errors
Returns the unchanged text in Rejected. Its reason is
Error::InvalidCString if metadata contains an interior NUL
byte, or Error::InvalidFrame if the emitted C string would exceed
the metadata size cap.
The NulError retains only the prefix through the first NUL; use
Rejected::into_inner for the whole original string.
Sourcepub fn clear_metadata(&mut self)
pub fn clear_metadata(&mut self)
Remove frame metadata, setting FrameMetadataStatus::Absent and
retaining its allocation for later copies.
Sourcepub fn channel_data_mut(&mut self, channel: usize) -> Option<&mut [f32]>
pub fn channel_data_mut(&mut self, channel: usize) -> Option<&mut [f32]>
Get mutable samples for one channel without allocating.
Trait Implementations§
Source§impl AudioSource for AudioFrame
impl AudioSource for AudioFrame
Source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Source§fn num_channels(&self) -> u32
fn num_channels(&self) -> u32
Source§fn num_samples(&self) -> u32
fn num_samples(&self) -> u32
Source§fn timestamp(&self) -> Option<ReceivedTimestamp>
fn timestamp(&self) -> Option<ReceivedTimestamp>
Source§fn format(&self) -> AudioFormat
fn format(&self) -> AudioFormat
Source§fn channel_stride_bytes(&self) -> usize
fn channel_stride_bytes(&self) -> usize
Source§fn metadata(&self) -> Option<&str>
fn metadata(&self) -> Option<&str>
Self::metadata_status.