Skip to main content

Decoder

Struct Decoder 

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

Safe AV1 decoder instance

This is the main entry point for decoding AV1 video. It wraps the internal rav1d decoder with a safe, type-safe interface.

§Example

use rav1d_safe::src::managed::Decoder;

let mut decoder = Decoder::new()?;
let obu_data = b"...";

if let Some(frame) = decoder.decode(obu_data)? {
    println!("Decoded {}x{}", frame.width(), frame.height());
}

Implementations§

Source§

impl Decoder

Source

pub fn new() -> Result<Self>

Create a new decoder with default settings

Source

pub fn with_settings(settings: Settings) -> Result<Self>

Create a decoder with custom settings

Source

pub fn set_stop(&mut self, stop: Option<Arc<dyn Stop>>)

Set (or clear with None) a cooperative cancellation token (issue #412).

While set, the decode loop polls the token at sbrow boundaries and aborts the in-flight frame with Error::Cancelled if it fires — so a server can bound a slow decode of a crafted-but-legal stream without abandoning the worker thread. Pass any Arc<dyn Stop> (a deadline, a flag, an Unstoppable no-op); None (the default) disables checking at zero cost. The token applies to subsequent decode / get_frame / flush calls and may be swapped between them.

Both decode paths honor the token: the single-threaded loop (threads = 1, the default) checks it per sbrow, and tile-threaded workers (threads > 1) check it per task and abort the frame through the same error path the internal flush uses. Granularity is one superblock row, so a cancel lands within a few milliseconds even on a large frame, not at the next frame boundary.

let mut decoder = Decoder::new()?;
decoder.set_stop(Some(Arc::new(Unstoppable)));
Source

pub fn decode(&mut self, data: &[u8]) -> Result<Option<Frame>>

Decode AV1 OBU data from a byte slice

Returns Ok(None) if more data is needed (the decoder is waiting for more input). Returns Ok(Some(frame)) when a frame is successfully decoded.

§Example
let mut decoder = Decoder::new()?;
let data = b"..."; // AV1 OBU data

match decoder.decode(data)? {
    Some(frame) => {
        println!("Got frame: {}x{}", frame.width(), frame.height());
    }
    None => {
        println!("Need more data");
    }
}
Source

pub fn get_frame(&mut self) -> Result<Option<Frame>>

Try to get a decoded frame without sending new data.

After calling decode(), the decoder may have buffered additional frames (e.g. from a raw OBU stream containing multiple temporal units). Call this in a loop until it returns Ok(None) to drain them.

Source

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

Flush the decoder and return all remaining frames

This should be called after all input data has been fed to the decoder to retrieve any buffered frames. It is a drain, then a reset: every frame the decoder still owes for data already passed to decode() — temporal units not yet parsed from the last chunk, and frames in flight on frame-threading workers — is returned, in output order, and only then is the decoder reset so it is ready for a new stream.

On an error the decoder is still reset, and the error is returned; frames drained before it are dropped with it.

Trait Implementations§

Source§

impl Drop for Decoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> To for T
where T: ?Sized,

Source§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
Source§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
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.