Skip to main content

BorrowedAudioFrame

Struct BorrowedAudioFrame 

Source
pub struct BorrowedAudioFrame<'buf> { /* private fields */ }
Expand description

Validated planar floating-point audio borrowed from application storage.

Samples and optional NUL-terminated metadata are borrowed for the frame’s lifetime. Synchronous sending and crate::audio_conversion::AudioConverter use the original channel stride without copying samples or allocating. Inspect channels with Self::channel_data or Self::channels; those slices exclude inter-channel padding.

Implementations§

Source§

impl<'buf> BorrowedAudioFrame<'buf>

Source

pub fn builder( data: &'buf [f32], sample_rate: u32, num_channels: u32, num_samples: u32, ) -> BorrowedAudioFrameBuilder<'buf>

Configure a borrowed planar frame with explicit sample rate and shape.

Defaults to tightly packed channels, Timecode::SYNTHESIZE and no metadata. A larger input slice is permitted; only the checked frame extent is retained. All validation occurs in the builder’s build.

use grafton_ndi::{AudioSource, BorrowedAudioFrame};
let samples = [1.0, 2.0, 99.0, 3.0, 4.0];
let frame = BorrowedAudioFrame::builder(&samples, 48_000, 2, 2)
    .channel_stride_bytes(12)
    .build()?;
let source: &dyn AudioSource = &frame;
assert_eq!(source.channels().collect::<Vec<_>>(), [&[1.0, 2.0][..], &[3.0, 4.0][..]]);
assert!(source.data().is_none());
Source

pub fn with_timecode(self, timecode: Timecode) -> Self

Return this frame with the supplied timecode; no samples are copied.

Source§

impl<'buf> BorrowedAudioFrame<'buf>

Source

pub fn sample_rate(&self) -> u32

Get the sample rate in Hz.

Source

pub fn num_channels(&self) -> u32

Get the number of audio channels.

Source

pub fn num_samples(&self) -> u32

Get the number of samples per channel.

Source

pub fn timecode(&self) -> Timecode

Get the timecode.

Source

pub fn timestamp(&self) -> Option<ReceivedTimestamp>

The source-dependent timestamp of the received frame.

Application input has no received timestamp.

Source

pub fn format(&self) -> AudioFormat

Get the audio format.

It is a supported format, validated when the frame was constructed.

Source

pub fn channel_stride_bytes(&self) -> usize

Get the distance between the starts of consecutive channels in bytes.

Includes any configured inter-channel padding.

Source

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.

Source

pub fn metadata_status(&self) -> FrameMetadataStatus

The metadata’s presence or the reason unreadable received text was withheld. Querying the cached status allocates nothing.

Source

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.

Borrows the caller’s active samples without reading padding.

Source

pub fn channels(&self) -> AudioChannels<'_> ⓘ

Iterate over the channels’ samples, in channel order, without copying or reading padding between channels.

Source

pub fn data(&self) -> Option<&[f32]>

Contiguous active samples, or None when padding separates channels.

Source

pub fn to_owned(&self) -> AudioFrame

Copy initialized samples and metadata into a new tightly packed frame. The returned frame retains no borrow; padding is omitted.

Source

pub fn copy_into(&self, destination: &mut AudioFrame)

Copy into an existing packed frame, reusing its sample and metadata allocations when their capacity and lengths permit. A copy without metadata retains the destination’s text allocation.

Trait Implementations§

Source§

impl<'buf> AudioSource for BorrowedAudioFrame<'buf>

Source§

fn sample_rate(&self) -> u32

Sample rate in Hz.
Source§

fn num_channels(&self) -> u32

Number of channels.
Source§

fn num_samples(&self) -> u32

Number of active samples per channel.
Source§

fn timecode(&self) -> Timecode

Frame timecode, or the sender’s synthesis sentinel.
Source§

fn timestamp(&self) -> Option<ReceivedTimestamp>

Source-dependent timestamp supplied by the SDK for a captured frame.
Source§

fn format(&self) -> AudioFormat

Validated planar floating-point audio format.
Source§

fn channel_stride_bytes(&self) -> usize

Distance in bytes between consecutive channel starts.
Source§

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

UTF-8 metadata; an explicit empty string differs from no metadata. Unreadable received text is withheld; inspect Self::metadata_status.
Source§

fn metadata_status(&self) -> FrameMetadataStatus

Whether per-frame metadata is absent, readable, or withheld as unreadable.
Source§

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

One channel’s initialized samples, excluding any inter-channel padding.
Source§

fn channels(&self) -> AudioChannels<'_> ⓘ

Iterate initialized channel samples without allocating or reading padding.
Source§

fn data(&self) -> Option<&[f32]>

Contiguous samples, or None when padding separates channels.
Source§

fn to_owned(&self) -> AudioFrame

Copy samples and readable metadata into a new owned, tightly packed planar frame. Withheld metadata keeps its status without its text. Allocates sample storage and, when present, readable metadata storage.
Source§

fn copy_into(&self, destination: &mut AudioFrame)

Copy into an owned destination, reusing sample and metadata allocations when their capacities permit. Padding is omitted. Absent source metadata clears the destination text while retaining its allocation.
Source§

impl<'buf> Clone for BorrowedAudioFrame<'buf>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'buf> Copy for BorrowedAudioFrame<'buf>

Source§

impl<'buf> Debug for BorrowedAudioFrame<'buf>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'buf> Freeze for BorrowedAudioFrame<'buf>

§

impl<'buf> RefUnwindSafe for BorrowedAudioFrame<'buf>

§

impl<'buf> Send for BorrowedAudioFrame<'buf>

§

impl<'buf> Sync for BorrowedAudioFrame<'buf>

§

impl<'buf> Unpin for BorrowedAudioFrame<'buf>

§

impl<'buf> UnsafeUnpin for BorrowedAudioFrame<'buf>

§

impl<'buf> UnwindSafe for BorrowedAudioFrame<'buf>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.