Skip to main content

Surface

Enum Surface 

Source
#[non_exhaustive]
pub enum Surface { Cuda(Frame), Vulkan(Frame), DmaBuf(DmaBuf), I420(I420), }
Expand description

Where a frame’s pixels currently live.

Decoders and capture sources hand these out; encoders and renderers consume them. Match to take a zero-copy fast path for the representation you can use, and fall back to into_i420 for representations that permit CPU readback. Surface::Vulkan intentionally refuses that fallback:

ⓘ
match surface {
    #[cfg(any(target_os = "macos", target_os = "ios"))]
    Surface::PixelBuffer(buffer) => draw_metal(buffer),
    other => upload(other.into_i420()?),
}

Variants are platform-gated, and the enum is #[non_exhaustive] so new representations stay additive: write that other arm and your code keeps building everywhere.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Cuda(Frame)

GPU buffer (Linux CUDA NV12). Produced by the NVDEC decoder or the GPU color converter, and scaled on the GPU into the NVENC encoder’s input.

§

Vulkan(Frame)

External Vulkan RGBA8 / BGRA8 image with explicit GPU synchronization.

§

DmaBuf(DmaBuf)

Linux DMA-BUF, exported on access and retained until the last clone drops.

§

I420(I420)

CPU-resident planar I420.

Implementations§

Source§

impl Surface

Source

pub fn width(&self) -> u32

The frame width in pixels.

Source

pub fn height(&self) -> u32

The frame height in pixels.

Source

pub fn rgba(rgba: &[u8], size: Size) -> Result<Self, Error>

Convert tightly-packed RGBA (width * height * 4 bytes, no row padding) to a CPU I420 surface in Color::infer’s color space for size, limited range. The result reports it via I420::color, and an encoder writes it into the bitstream, so the pixels and their label cannot disagree.

The bring-your-own-pixels entry point: wrap the result in a Frame to encode it. A capture source or decoder hands you a surface directly, often a GPU one, so don’t route those through here.

Source

pub fn resize(&self, size: Size, config: &Config) -> Result<Surface, Error>

A copy scaled to size. GPU-backed surfaces stay on the GPU. The pixel half of Frame::resize, which is what you usually want since it carries the timestamp across too.

A GPU scaler that a driver refuses falls back to downloading and scaling on the CPU where the surface permits readback. External Vulkan surfaces fail instead because their contract forbids CPU pixel access.

The result keeps the source’s color. An unlabelled source means what Color::infer guesses for its own size, so the result is labelled with that: scaling across 576 lines would otherwise change the guess without changing the samples.

Source

pub fn into_i420(self) -> Result<I420, Error>

The pixels as tightly-packed I420 (YUV 4:2:0): Y (width * height bytes), then U, then V (width/2 * height/2 each), no row padding.

Free for Surface::I420; downloads native GPU surfaces that permit readback, so it is the universal arm of a match on every other platform. A external Vulkan surface returns Error::Unsupported because its contract deliberately exposes no CPU pixel path.

Source

pub fn to_rgba(&self, config: &Config) -> Result<Rgba, Error>

Convert to owned, tightly packed RGBA8 pixels on the CPU.

Native GPU surfaces that permit readback are downloaded first; CPU I420 is converted directly. External Vulkan surfaces return Error::Unsupported. The conversion honors color and otherwise falls back to Color::infer.

Source

pub fn color(&self) -> Option<Color>

The color space these samples are in, when it is known rather than guessed. A decoded frame carries its stream’s; None for pixels that merely passed through without anything naming their space, a camera’s raw YUYV among them.

Worth reading before encoding pixels you resized or decoded: they keep their source’s space, which need not match what an encoder sized for them would infer. Pass this to encode::Config::color to keep the label honest; the encoder refuses a frame that disagrees with it.

Source

pub fn to_i420(&self) -> Result<Cow<'_, I420>, Error>

A CPU I420 view, downloading a GPU frame only if necessary.

Borrowed for Surface::I420, owned for a GPU surface that permits readback, and unsupported for external Vulkan. The borrowing counterpart to into_i420, for a caller that cannot give up the surface: a publisher’s preview frame is shared with every rendition’s encoder, so its Arc never has a refcount of one and no consuming exit is reachable from it.

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more