#[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
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
impl Surface
Sourcepub fn rgba(rgba: &[u8], size: Size) -> Result<Self, Error>
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.
Sourcepub fn resize(&self, size: Size, config: &Config) -> Result<Surface, Error>
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.
Sourcepub fn into_i420(self) -> Result<I420, Error>
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.
Sourcepub fn to_rgba(&self, config: &Config) -> Result<Rgba, Error>
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.
Sourcepub fn color(&self) -> Option<Color>
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.
Sourcepub fn to_i420(&self) -> Result<Cow<'_, I420>, Error>
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.