Skip to main content

VideoRef

Struct VideoRef 

Source
pub struct VideoRef<'a, S: FrameFree<RawFrame = NDIlib_video_frame_v2_t>> { /* private fields */ }
Expand description

A zero-copy borrowed video 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 video data. The frame is automatically freed when dropped, via whichever NDIlib_*_free_video* call the strategy S encodes.

The two public spellings are type aliases over this one core, so every accessor and the Debug impl are written exactly once:

Key characteristics:

  • Zero allocations: References NDI SDK buffers directly
  • Zero copies: No memcpy of pixel data
  • RAII lifetime: Exactly one free per frame, enforced at compile time
  • Not Send: Prevents accidental cross-thread use of FFI buffers

§Lifetime

The lifetime parameter 'a ties this frame to the owner (a Receiver or a FrameSync) that created it. The borrow checker ensures the owner cannot be dropped while any frame references are alive, preventing use-after-free at compile time with zero runtime cost. The underlying NDI buffer is freed when the frame ref is dropped.

§Performance

For a 1920×1080 BGRA frame, this eliminates ~8.3 MB of memcpy compared to the owned VideoFrame. At 60 fps, this saves ~475 MB/s of memory bandwidth.

Implementations§

Source§

impl<'a, S: FrameFree<RawFrame = NDIlib_video_frame_v2_t>> VideoRef<'a, S>

Source

pub fn width(&self) -> i32

Get the frame width in pixels.

Source

pub fn height(&self) -> i32

Get the frame height in pixels.

Source

pub fn pixel_format(&self) -> PixelFormat

Get the pixel format (FourCC code).

This is guaranteed to be a valid, supported format since it’s validated during construction.

Source

pub fn frame_rate_n(&self) -> i32

Get the frame rate numerator.

Source

pub fn frame_rate_d(&self) -> i32

Get the frame rate denominator.

Source

pub fn picture_aspect_ratio(&self) -> f32

Get the picture aspect ratio.

Source

pub fn scan_type(&self) -> ScanType

Get the scan type (progressive, interlaced, etc.).

This is guaranteed to be valid since it is checked during construction.

Source

pub fn timecode(&self) -> i64

Get the timecode.

Source

pub fn timestamp(&self) -> i64

Get the timestamp.

Source

pub fn line_stride_or_size(&self) -> LineStrideOrSize

Get the line stride or data size.

This returns the cached, validated value computed at construction time.

Source

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

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

Source

pub fn data(&self) -> &[u8]

Get a zero-copy view of the frame data.

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

For planar 4:2:0 formats (YV12/I420/NV12), this returns the full buffer including Y and UV planes.

§Safety Guarantee

The slice length is computed once at construction time using checked arithmetic and validated against MAX_VIDEO_BYTES. This eliminates the possibility of integer overflow or unbounded slice creation.

Source

pub fn to_owned(&self) -> Result<VideoFrame>

Convert this borrowed frame to an owned VideoFrame.

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

Trait Implementations§

Source§

impl<'a, S: FrameFree<RawFrame = NDIlib_video_frame_v2_t>> Debug for VideoRef<'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 VideoRef<'a, S>
where <S as FrameFree>::Instance: Freeze,

§

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

§

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

§

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

§

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

§

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

§

impl<'a, S> UnwindSafe for VideoRef<'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.