Skip to main content

Decoder

Struct Decoder 

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

A VA-API H.264 or H.265 decoder. Built once, fed Annex-B access units, emits NV12.

§Examples

use kodecs_vaapi::decode::{Config, Decoder};

let mut decoder = Decoder::new(Config::new())?;
let mut pictures = Vec::new();

for (index, access_unit) in access_units.iter().enumerate() {
    pictures.extend(decoder.decode(access_unit, index as u64)?);
}

// Output trails input, so the tail of the stream only arrives here.
pictures.extend(decoder.flush()?);

Implementations§

Source§

impl Decoder

Source

pub fn new(config: Config) -> Result<Self>

Opens Config::device, or the first render node that decodes Config::codec, and checks that the driver exposes a decode entrypoint for it.

The VA config, context, and surface pool are built later, from the first SPS, since their profile and size come from the stream. This still fails early enough for a caller to fall back to another decoder when libva is missing, the node cannot be opened, or the driver does not decode the codec. A named node is never swapped for another.

Source

pub fn decode( &mut self, access_unit: &[u8], timestamp: u64, ) -> Result<Vec<Frame>>

Decodes one Annex-B access unit, returning the pictures that came due, in output order.

timestamp is opaque and travels with the picture coded in this access unit, so it survives DPB reordering. Parameter sets are read from the stream, so an access unit carrying only an SPS and a PPS decodes to no frames.

Source

pub fn decode_exported( &mut self, access_unit: &[u8], timestamp: u64, ) -> Result<Vec<ExportedFrame>>

Decodes one Annex-B access unit, leaving the pictures that came due on the GPU.

The same decode as Decoder::decode, differing only in what the caller gets back: a DRM PRIME descriptor for each picture’s surface instead of a copy of its pixels. For a consumer that draws on the GPU that is the whole picture never touching system memory.

An exported surface stays out of the recycling pool until the ExportedFrame drops, since the next picture would otherwise be decoded over pixels the consumer still holds a descriptor for. A consumer that lets each picture go once it has drawn it therefore costs no allocation per picture; one that holds on to pictures costs one surface per picture held.

A consumer that turns out to want bytes after all is not stuck: the surface travels with the descriptor, and ExportedFrame::download reads it back.

Source

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

Returns every picture still held in the DPB, in output order.

The DPB lets a picture out only when a later one needs it to (C.4.5.3 for H.264, C.5.2 for H.265), so a stream that simply stops leaves its tail sitting there. This releases that tail and empties the DPB, so a second call returns nothing.

The parsed parameter sets survive, and nothing here waits for an IDR: a stream picked up part way through decodes against an empty DPB, which gives distorted pictures until its next IDR rather than an error.

Source

pub fn flush_exported(&mut self) -> Result<Vec<ExportedFrame>>

Decoder::flush for a caller taking its pictures on the GPU.

Auto Trait Implementations§

§

impl !Freeze for Decoder

§

impl !RefUnwindSafe for Decoder

§

impl !Send for Decoder

§

impl !Sync for Decoder

§

impl !UnwindSafe for Decoder

§

impl Forget for Decoder

§

impl Move for Decoder

§

impl Unpin for Decoder
where *const u8 is !null: Unpin, Arc<Sps>: Unpin, Arc<Pps>: Unpin, Arc<PooledSurface>: Unpin, Arc<Display>: Unpin, InternalBitFlags: Unpin, Arc<FreeList>: Unpin, Rc<Context>: Unpin, *const LeafNode<u8, Arc<Vps>> is !null: Unpin, Box<(u8, Arc<Vps>)>: Unpin, *const LeafNode<u8, Arc<Sps>> is !null: Unpin, Box<(u8, Arc<Sps>)>: Unpin, *const LeafNode<u8, (Arc<[u8]>, Arc<Pps>)> is !null: Unpin, Box<(u8, (Arc<[u8]>, Arc<Pps>))>: Unpin, Rc<RefCell<PictureData>>: Unpin, Arc<Sps>: Unpin,

§

impl UnsafeUnpin for Decoder
where *const u8 is !null: UnsafeUnpin, PhantomData<Option<Arc<Sps>>>: UnsafeUnpin, PhantomData<Option<StoredPps>>: UnsafeUnpin, *const ArcInner<Sps> is !null: UnsafeUnpin, PhantomData<ArcInner<Sps>>: UnsafeUnpin, PhantomData<DpbEntry<Handle>>: UnsafeUnpin, *const ArcInner<Display> is !null: UnsafeUnpin, PhantomData<ArcInner<Display>>: UnsafeUnpin, InternalBitFlags: UnsafeUnpin, *const ArcInner<FreeList> is !null: UnsafeUnpin, PhantomData<ArcInner<FreeList>>: UnsafeUnpin, *const RcInner<Context> is !null: UnsafeUnpin, PhantomData<RcInner<Context>>: UnsafeUnpin, PhantomData<Handle>: UnsafeUnpin, *const LeafNode<u8, Arc<Vps>> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(u8, Arc<Vps>)>>: UnsafeUnpin, *const LeafNode<u8, Arc<Sps>> is !null: UnsafeUnpin, PhantomData<Box<(u8, Arc<Sps>)>>: UnsafeUnpin, *const LeafNode<u8, (Arc<[u8]>, Arc<Pps>)> is !null: UnsafeUnpin, PhantomData<Box<(u8, (Arc<[u8]>, Arc<Pps>))>>: UnsafeUnpin, PhantomData<DpbEntry<Handle>>: UnsafeUnpin, *const ArcInner<Sps> is !null: UnsafeUnpin, PhantomData<ArcInner<Sps>>: UnsafeUnpin,

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