Skip to main content

VideoDecoder

Struct VideoDecoder 

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

Stateful hardware decoder for one demuxed video stream.

The Experimental codec paths accept progressive H.264 Baseline/Main/High, H.265 Main, AV1 Main 8-bit 4:2:0 without film grain, or VP9 Profile 0 8-bit 4:2:0. AVC and HEVC access units contain one complete slice per picture; admitted AV1 and VP9 access units may contain hidden and show-existing pictures. Host-planar and retained native output are synchronous; Vulkan handles and queue ownership remain private.

Implementations§

Source§

impl VideoDecoder

Source

pub fn new(engine: &Engine, info: VideoContainerInfo) -> Result<Self>

Create a decoder for the selected track described by info.

§Errors

Returns an error unless the track is representable as progressive H.264 Baseline/Main/High, H.265 Main, AV1 Main 8-bit 4:2:0 without film grain, or VP9 Profile 0 8-bit 4:2:0 and the selected Engine admits the qualified Vulkan path.

Source

pub fn decode(&mut self, packet: &VideoPacket) -> Result<Option<VideoFrame>>

Decode one demuxed access unit and emit the next display-order frame when ready.

Packets enter in decode order. The decoder retains up to the SPS reorder depth and returns None while no display-order frame is safe to emit. Call flush at end of stream to retrieve the delayed tail.

§Errors

Returns an error after close, for a packet from another track, when the first packet after create/flush is not random access, for unsupported bitstream shapes, or when Vulkan submission, status, or readback fails.

Source

pub fn decode_native( &mut self, packet: &VideoPacket, ) -> Result<Option<VideoFrame>>

Decode one access unit while retaining its native multi-plane output.

This path omits the decoder-to-host pixel copy. It currently waits for the exact decode submission and verifies its result status before publishing the frame; asynchronous delivery is a later checkpoint. The returned frame retains its decoder image slot. Register every GPU consumer through VideoFrame::mark_consumed before dropping the last frame clone.

A decode sequence uses either host-planar decode or native output until flush establishes a new random-access boundary.

§Errors

Returns the same stream, capability, and state errors as decode, plus FailedPrecondition when output modes are mixed before a flush and ResourceExhausted while every recyclable DPB slot remains retained by native frames or consumer completions.

Source

pub fn read_native_yuv420p(&mut self, frame: &VideoFrame) -> Result<Vec<u8>>

Read one retained native frame as tightly packed planar 8-bit YUV 4:2:0.

The exact frame slot is copied; this does not observe the decoder’s newest slot by accident. The synchronous operation waits for producer readiness, performs explicit decode/compute queue-family ownership transfers, restores the image to its codec layout, and registers the final submission as a consumer completion before reading host bytes.

§Errors

Returns an error after close, for a non-native frame, for a frame produced by another decoder, for an unsupported native format, or when submission, synchronization, or readback fails.

Source

pub fn read_native_yuv420p10(&mut self, frame: &VideoFrame) -> Result<Vec<u16>>

Read a retained native frame into packed 10-bit yuv420p10le samples.

Samples are little-endian u16 lanes with the significant bits right-justified. The same synchronization contract as read_native_yuv420p applies.

§Errors

Returns an error after close, for a non-native frame, for an 8-bit frame, or when submission, synchronization, or readback fails.

Source

pub fn native_frame_texture(&mut self, frame: &VideoFrame) -> Result<Texture>

Convert one retained native frame into a packed RGBA8 Texture.

The plane pack and color conversion execute on the device; no decoded samples cross to the host. The frame’s color metadata selects the Y’CbCr matrix and component range with the same Unspecified fallback as crate::video::to_matrix (BT.709, limited range). The decoder slot is released once the conversion submission completes; the returned texture is an independent image-backed value with its own producer event.

§Errors

Returns an error after close, for a non-native frame, for a frame produced by another decoder, for an unsupported native format, for a Compatibility-profile build without the conversion kernel, or when submission or synchronization fails.

Source

pub fn stage_native_planes(&self, frame: &VideoFrame) -> Result<VideoFrame>

Copy an already-decoded I420, NV12, or P010 frame into device plane buffers.

The output supports VideoFrame::to_matrix. I420 and NV12 also support native geometry and luma operations. The copy can be recorded inside Engine::capture. The plan retains the decoder image layer and restores its ownership on each replay.

§Errors

Returns an error for closed or mismatched decoders, unsupported formats, or failure to allocate or record the planes.

Source

pub fn record_to_planes( &self, packets: &[VideoPacket], ) -> Result<Vec<VideoFrame>>

Record a self-contained packet sequence into an active execution capture.

Packets enter in decode order, beginning with a random-access access unit. H.264 requires an IDR with SPS/PPS, HEVC an IRAP with VPS/SPS/PPS, AV1 a key picture with its sequence header, and VP9 a key picture. The returned device-planar frames follow presentation order. Hidden pictures update decode state and show-existing pictures reuse their reconstructed image. No packet pixels cross the host.

The plan owns its compressed bytes and decode session. This decoder’s live packet position and pending frames are unaffected.

§Errors

Returns an error outside capture, after close, for an empty sequence, for packets from another track or with changing codec parameters, or when the decoder cannot plan the sequence.

Source

pub fn flush(&mut self) -> Result<Vec<VideoFrame>>

Reset stream sequencing at a seek boundary.

Return every delayed frame in presentation order and require the next packet to be random access. A second flush returns an empty vector.

Source

pub fn close(&mut self)

Close the decoder and release its session resources.

Source

pub const fn is_open(&self) -> bool

Return whether the decoder still accepts packets.

Source

pub fn info(&self) -> Option<VideoContainerInfo>

Return the selected stream metadata while open.

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<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, 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.