Skip to main content

AudioFrameRef

Struct AudioFrameRef 

Source
pub struct AudioFrameRef<'rx> { /* private fields */ }
Expand description

A zero-copy audio frame captured from a Receiver.

Borrows its receiver and frees the SDK buffer when dropped. It can be moved or shared with scoped worker threads (Send + Sync). Converting with to_owned copies the active samples into an owned frame. No samples are copied by capture itself. For padded channels, data() returns None; use channel_data() or channels() to read initialized samples. Every captured audio frame has at least one channel and one sample per channel. See crate::FrameSyncAudioRef for clock-driven capture.

Implementations§

Source§

impl<'a> AudioFrameRef<'a>

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.

FrameSync output without a source timecode carries Timecode::SYNTHESIZE.

Source

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

The source-dependent timestamp of the received frame.

It is None when the SDK does not know it. FrameSync and AV-sync audio also treat their zero marker as unknown; that marker alone does not identify synthesized silence.

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.

It includes any padding between channels.

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.

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]>

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.

Source

pub fn to_owned(&self) -> AudioFrame

Copy this borrowed frame into 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. Allocates one sample buffer, and one metadata string when present. Withheld metadata keeps its status without retaining its text. Self::copy_into makes the same copy into an existing frame, reusing its allocations.

The copy cannot fail: capture validated everything it relies on.

Source

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

Copy this borrowed frame into destination, reusing its allocations.

destination ends up exactly as Self::to_owned would have returned it, whatever it held before: the channels’ samples packed back to back without inter-channel padding, format, sample rate, channel and sample counts, timecode, timestamp and metadata.

Its sample buffer is reused when its capacity holds the packed samples, and otherwise replaced by one allocation of exactly that size. Its metadata string is reused when its capacity holds the new text and its terminator; otherwise it grows once. With sufficient sample and metadata capacity, subsequent copies allocate nothing, including when sources alternate between absent and present metadata. A copy without text retains its allocation.

The copy makes no SDK call. It runs wherever this reference may be used: a receiver frame can be copied on a scoped worker thread, while a synchronizer frame stays on its capture thread. The destination is an ordinary owned frame either way.

Trait Implementations§

Source§

impl<'a> AudioSource for AudioFrameRef<'a>

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<'a> Debug for AudioFrameRef<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'rx> Freeze for AudioFrameRef<'rx>

§

impl<'rx> RefUnwindSafe for AudioFrameRef<'rx>

§

impl<'rx> Send for AudioFrameRef<'rx>

§

impl<'rx> Sync for AudioFrameRef<'rx>

§

impl<'rx> Unpin for AudioFrameRef<'rx>

§

impl<'rx> UnsafeUnpin for AudioFrameRef<'rx>

§

impl<'rx> UnwindSafe for AudioFrameRef<'rx>

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 = !

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.