pub struct AudioRef<'a, S: FrameFree<RawFrame = NDIlib_audio_frame_v3_t>> { /* private fields */ }Expand description
A zero-copy borrowed audio frame, generic over its free strategy S.
This type wraps an RAII Guard that owns the NDI frame buffer lifetime,
exposing a safe, zero-copy view of the audio data. The frame is automatically
freed when dropped, via whichever NDIlib_*_free_audio* call the strategy S
encodes.
The shared accessors and the Debug impl are written exactly once here; the
two public spellings are aliases that layer their differing format/owned/empty
policy on top:
AudioFrameRef<'rx>— frames captured from aReceiver(always concrete:format() -> AudioFormat,to_owned() -> AudioFrame).FrameSyncAudioRef<'fs>— frames captured from aFrameSync, which additionally model a validated empty query/no-source state (is_empty,Option-returningformat/to_owned).
Key characteristics:
- Zero allocations: References NDI SDK buffers directly
- Zero copies: No memcpy of audio samples
- RAII lifetime: Exactly one free per frame, enforced at compile time
- Receiver refs are
Send + Sync; FrameSync refs stay on their capture thread
Implementations§
Source§impl<'a, S: FrameFree<RawFrame = NDIlib_audio_frame_v3_t>> AudioRef<'a, S>
impl<'a, S: FrameFree<RawFrame = NDIlib_audio_frame_v3_t>> AudioRef<'a, S>
Sourcepub fn sample_rate(&self) -> i32
pub fn sample_rate(&self) -> i32
Get the sample rate in Hz.
Sourcepub fn num_channels(&self) -> i32
pub fn num_channels(&self) -> i32
Get the number of audio channels.
Sourcepub fn num_samples(&self) -> i32
pub fn num_samples(&self) -> i32
Get the number of samples per channel.
Sourcepub fn channel_stride_in_bytes(&self) -> i32
pub fn channel_stride_in_bytes(&self) -> i32
Get the channel stride in bytes.
Sourcepub fn data(&self) -> Option<&[f32]>
pub fn data(&self) -> Option<&[f32]>
Get a zero-copy slice when channels are tightly packed.
Returns None for multi-channel buffers with padding between channels.
Use channel_data or channels
for those buffers. An empty query/no-source frame returns Some(&[]).
Sourcepub fn channel_data(&self, channel: usize) -> Option<&[f32]>
pub fn channel_data(&self, channel: usize) -> Option<&[f32]>
Get the zero-copy samples for a single channel, excluding padding.
Sourcepub fn channels(&self) -> impl ExactSizeIterator<Item = &[f32]> + '_
pub fn channels(&self) -> impl ExactSizeIterator<Item = &[f32]> + '_
Iterate over channel slices without reading inter-channel padding. Empty query/no-source frames yield no channels.
Source§impl<'rx> AudioRef<'rx, AudioKind>
impl<'rx> AudioRef<'rx, AudioKind>
Sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Get the audio format (FourCC code).
This is guaranteed to be a valid, supported format since it’s validated during construction.
Sourcepub fn to_owned(&self) -> Result<AudioFrame>
pub fn to_owned(&self) -> Result<AudioFrame>
Convert this borrowed frame to an owned AudioFrame.
Copies channel samples into tightly packed planar storage and copies metadata, allowing the frame to outlive the SDK buffer. Padding is omitted.
Source§impl<'fs> AudioRef<'fs, FrameSyncAudioFree>
impl<'fs> AudioRef<'fs, FrameSyncAudioFree>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true for a valid query/no-source state with no sample buffer.
Sourcepub fn format(&self) -> Option<AudioFormat>
pub fn format(&self) -> Option<AudioFormat>
Get the audio format (FourCC code), or None for an empty query/no-source state.
Sourcepub fn to_owned(&self) -> Result<Option<AudioFrame>>
pub fn to_owned(&self) -> Result<Option<AudioFrame>>
Convert this borrowed frame to an owned AudioFrame.
Copies channel samples into tightly packed planar storage and copies metadata, allowing the frame to outlive the SDK buffer. Padding is omitted.
Returns Ok(None) for a valid query/no-source state with no sample
buffer to own.