Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder: Send {
    // Required methods
    fn encoding(&self) -> Encoding;
    fn decode(&mut self, packet: &Packet) -> Result<Option<Frame>>;
    fn flush(&mut self) -> Result<Vec<Frame>>;
    fn reset(&mut self) -> Result<()>;
    fn is_hardware(&self) -> bool;
}
Expand description

Something that turns packets into frames.

Decoders are stateful and are not Sync: one belongs to one thread, which is how every platform decoder works anyway. They are Send so that thread need not be the one that opened the file.

Required Methods§

Source

fn encoding(&self) -> Encoding

What this decodes.

Source

fn decode(&mut self, packet: &Packet) -> Result<Option<Frame>>

Feeds one packet in.

Returns None when the decoder has taken the packet but has no picture yet, which is normal: B-frames mean output lags input by a frame or more, and a hardware decoder may hold several.

Source

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

Everything still held inside, at the end of a stream.

Skipping this loses the last few frames of every file — the ones the decoder was holding for reordering.

Source

fn reset(&mut self) -> Result<()>

Throws away all state, for a seek.

Source

fn is_hardware(&self) -> bool

Whether the pictures come from silicon dedicated to the job.

Worth surfacing: it is the difference between a laptop playing 4K for an afternoon and one playing it until the battery runs out.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§