Skip to main content

AudioRef

Struct AudioRef 

Source
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 a Receiver (always concrete: format() -> AudioFormat, to_owned() -> AudioFrame).
  • FrameSyncAudioRef<'fs> — frames captured from a FrameSync, which additionally model a validated empty query/no-source state (is_empty, Option-returning format/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>

Source

pub fn sample_rate(&self) -> i32

Get the sample rate in Hz.

Source

pub fn num_channels(&self) -> i32

Get the number of audio channels.

Source

pub fn num_samples(&self) -> i32

Get the number of samples per channel.

Source

pub fn timecode(&self) -> i64

Get the timecode in 100 ns units.

Source

pub fn timestamp(&self) -> i64

Get the receive timestamp in 100 ns units since the Unix epoch.

Source

pub fn channel_stride_in_bytes(&self) -> i32

Get the channel stride in bytes.

Source

pub fn metadata(&self) -> Option<&str>

Get frame metadata as UTF-8 text, if present.

Source

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(&[]).

Source

pub fn channel_data(&self, channel: usize) -> Option<&[f32]>

Get the zero-copy samples for a single channel, excluding padding.

Source

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>

Source

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.

Source

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>

Source

pub fn is_empty(&self) -> bool

Returns true for a valid query/no-source state with no sample buffer.

Source

pub fn format(&self) -> Option<AudioFormat>

Get the audio format (FourCC code), or None for an empty query/no-source state.

Source

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.

Trait Implementations§

Source§

impl<'a, S: FrameFree<RawFrame = NDIlib_audio_frame_v3_t>> Debug for AudioRef<'a, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, S> !Send for AudioRef<'a, S>

§

impl<'a, S> !Sync for AudioRef<'a, S>

§

impl<'a, S> Freeze for AudioRef<'a, S>
where <S as FrameFree>::Instance: Freeze,

§

impl<'a, S> RefUnwindSafe for AudioRef<'a, S>
where <S as FrameFree>::Instance: RefUnwindSafe,

§

impl<'a, S> Unpin for AudioRef<'a, S>
where <S as FrameFree>::Instance: Unpin,

§

impl<'a, S> UnsafeUnpin for AudioRef<'a, S>
where <S as FrameFree>::Instance: UnsafeUnpin,

§

impl<'a, S> UnwindSafe for AudioRef<'a, S>
where <S as FrameFree>::Instance: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.