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
  • Not Send: Prevents accidental cross-thread use of FFI buffers

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.

Source

pub fn timestamp(&self) -> i64

Get the timestamp.

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

Get a zero-copy view of the audio data as 32-bit floats.

This returns a slice directly into the NDI SDK’s buffer. No allocation or memcpy is performed.

§Safety Guarantee

The slice length is computed once at construction time using checked arithmetic and validated against MAX_AUDIO_BYTES. This eliminates the possibility of integer overflow or unbounded slice creation. A validated empty (query/no-source) layout yields an empty slice.

Source

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

Get the zero-copy samples for a single channel.

This respects channel_stride_in_bytes, so it works for tightly packed and strided planar FLTP audio.

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.

This performs a single memcpy of the audio data and metadata, allowing the frame to outlive the NDI buffer and be sent across threads.

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.

This performs a single memcpy of the audio data and metadata, allowing the frame to outlive the NDI buffer and be sent across threads.

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> Freeze for AudioRef<'a, S>
where <S as FrameFree>::Instance: Freeze,

§

impl<'a, S> RefUnwindSafe for AudioRef<'a, S>

§

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

§

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

§

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

§

impl<'a, S> UnsafeUnpin for AudioRef<'a, S>

§

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.