Skip to main content

VideoFrame

Struct VideoFrame 

Source
pub struct VideoFrame { /* private fields */ }
Expand description

One timestamped video frame with retained storage and readiness semantics.

The admitted packed-image path retains the backing Image, which in turn retains its crate::Matrix storage and exact producer readiness. Cloning a frame shares that retained value; it does not copy pixels or manufacture a second completion event.

Implementations§

Source§

impl VideoFrame

Source

pub fn to_matrix(&self, config: &VideoMatrixConfig) -> Result<Matrix>

Convenience form of to_matrix for one frame.

§Errors

Returns the same errors as to_matrix.

Source§

impl VideoFrame

Source

pub fn new_from_image( image: Image, timing: VideoFrameTiming, color: VideoColorInfo, ) -> Result<Self>

Attach single-frame timing and color semantics to a packed image.

Batched image layouts are accepted only when their batch extent is one. Zero-width and zero-height Images remain useful for shape propagation but are not valid produced video frames.

§Errors

Returns an error when image has a batch extent other than one or a zero spatial extent.

Source

pub fn upload_planes( format: VideoPixelFormat, planes: Vec<Vec<u8>>, width: usize, height: usize, timing: VideoFrameTiming, color: VideoColorInfo, ) -> Result<Self>

Upload tightly packed plane bytes into device-resident planar storage.

planes must match the format’s plane count and each plane’s tightly packed width * height u8 extent. width and height are the visible luma extent. The returned frame carries the same timing and color metadata the caller supplies; this is the host-to-device staging step for native frame operations and oa::video::to_matrix. For P010, each sample occupies a little-endian 16-bit lane with its 10 bits in the high end. Its luma row has width * 2 bytes and its interleaved CbCr row has width.div_ceil(2) * 4 bytes.

§Errors

Returns an error for a zero extent, a wrong plane count, mismatched plane sizes, a bit depth that has no admitted storage, or a storage allocation or upload failure.

This variant uploads on this thread’s default engine. An engine initialization failure is returned before the upload starts.

Source

pub fn upload_planes_on( engine: &Engine, format: VideoPixelFormat, planes: Vec<Vec<u8>>, width: usize, height: usize, timing: VideoFrameTiming, color: VideoColorInfo, ) -> Result<Self>

Upload tightly packed planes to device-resident planar frame storage on a particular engine.

This is the upload_planes contract evaluated on engine instead of this thread’s default engine.

§Errors

Returns the same errors as upload_planes.

Source

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

Stage a host-planar frame into device-resident planar storage.

A device-planar frame is returned unchanged. A tightly packed YUV420 host frame uploads as three Yuv420Planar8 planes with its timing and color metadata preserved. Packed images, textures, and native decoder frames have no upload route in this checkpoint.

Returns an error for an ineligible backing or an upload failure.

This variant uploads on this thread’s default engine. An engine initialization failure is returned before the upload starts.

Source

pub fn upload_on(&self, engine: &Engine) -> Result<VideoFrame>

Stage a host-planar frame into device-resident planar storage on a particular engine.

This is the upload contract evaluated on engine instead of this thread’s default engine.

§Errors

Returns an error for an ineligible backing or an upload failure.

Source

pub fn new_from_yuv420p( bytes: Vec<u8>, width: usize, height: usize, timing: VideoFrameTiming, color: VideoColorInfo, ) -> Result<Self>

Attach frame semantics to tightly packed planar 8-bit YUV 4:2:0 bytes.

Planes are stored as full-resolution Y followed by quarter-resolution U and V. The owned Vec allocation is retained without copying pixels; cloning the frame shares that allocation. Width and height must both be non-zero and even.

§Errors

Returns an error for invalid 4:2:0 geometry, arithmetic overflow, or a byte count other than width * height * 3 / 2.

Source

pub fn new_from_yuv420p10( bytes: Vec<u16>, width: usize, height: usize, timing: VideoFrameTiming, color: VideoColorInfo, ) -> Result<Self>

Attach frame semantics to tightly packed planar 10-bit YUV 4:2:0 samples.

Samples are little-endian u16 lanes with the ten significant bits right-justified (yuv420p10le layout). Geometry and plane order match new_from_yuv420p.

§Errors

Returns an error for invalid 4:2:0 geometry, arithmetic overflow, or a sample count other than width * height * 3 / 2.

Source

pub fn width(&self) -> usize

Return the visible frame width.

Source

pub fn height(&self) -> usize

Return the visible frame height.

Source

pub const fn timing(&self) -> VideoFrameTiming

Return the presentation timing.

Source

pub const fn color_info(&self) -> VideoColorInfo

Return the retained source color metadata.

Source

pub const fn as_image(&self) -> Option<&Image>

Borrow the packed Image backing when this frame has one.

Future native multi-plane decoder output will return None rather than pretending that a Vulkan image or several planes are one dense Image.

Source

pub const fn as_texture(&self) -> Option<&Texture>

Borrow the retained render Texture when this frame has one.

Texture backing remains semantically distinct from packed Image and planar codec output. Its Matrix producer readiness remains attached to the retained Texture.

Source

pub fn as_yuv420p(&self) -> Option<&[u8]>

Borrow tightly packed planar 8-bit YUV 4:2:0 bytes when present.

Source

pub fn as_yuv420p10(&self) -> Option<&[u16]>

Borrow tightly packed planar 10-bit YUV 4:2:0 samples when present.

Samples are stored little-endian in u16 lanes with the ten significant bits right-justified, matching FFmpeg’s yuv420p10le.

Source

pub const fn native_format(&self) -> Option<VideoPixelFormat>

Return the native decoded-plane format when this frame retains one.

Source

pub fn pixel_format(&self) -> Option<VideoPixelFormat>

Return the frame’s plane format when it has a planar or native backing.

Source

pub fn planes(&self) -> Option<&[Matrix]>

Borrow the frame’s device plane matrices when it has a device-planar backing, in the format’s plane order.

The matrices are U8 planes shaped [plane_height, plane_width] in tightly packed row order; NV12 carries the chroma pair plane second. Returns None for packed, texture, native-decoded, and host-planar frames.

Source

pub const fn ready_event(&self) -> Option<&Event>

Return the exact producer completion when the frame carries one.

Native decode and render-target adapters retain their producer event. The current native decoder waits before publishing, while a render target may still be in flight. Consumers must honor this dependency.

Source

pub fn mark_consumed(&self, event: &Event) -> Result<()>

Retain a native decoded or render-target frame until a GPU consumer completes.

Multiple consumers may register events from the same Engine; the latest timeline point controls slot reuse. Dropping every frame clone declares immediate reuse only when no consumer event was registered.

§Errors

Returns an error for unsupported backing, a foreign or out-of-order event, or a frame whose producer slot is no longer active.

Source

pub fn into_image(self) -> Option<Image>

Consume the frame and return its packed Image backing when present.

Source

pub fn into_texture(self) -> Option<Texture>

Consume the frame and return its render Texture backing when present.

Trait Implementations§

Source§

impl Clone for VideoFrame

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

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.