Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<R: Read> { /* private fields */ }
Expand description

A streaming YUV4MPEG2 decoder.

Owns one reusable frame buffer sized at header parse time. Decoder::read_frame fills it and returns borrowed plane slices.

Implementations§

Source§

impl<R: Read> Decoder<R>

Source

pub fn new(reader: R) -> Result<Self, Error>

Reads and parses the stream header with the default Limits.

Source

pub fn with_limits(reader: R, limits: Limits) -> Result<Self, Error>

Reads and parses the stream header, enforcing limits before the frame buffer is allocated.

EOF while reading the stream header is Error::EndOfStream. A wrong magic or malformed parameter is Error::Parse.

Source

pub fn width(&self) -> usize

Frame width in luma samples.

Source

pub fn height(&self) -> usize

Frame height in luma samples.

Source

pub fn framerate(&self) -> Ratio

Frame rate. Defaults to 25:1 when the F tag is absent. The default stays out of Decoder::raw_params.

Source

pub fn pixel_aspect(&self) -> Ratio

Pixel (sample) aspect ratio, where 0:0 means unknown.

Source

pub fn interlace(&self) -> Interlace

Interlacing mode, Interlace::Unknown when the I tag is absent.

Source

pub fn colorspace(&self) -> Colorspace

The stream colorspace, plain 4:2:0 8-bit when the C tag is absent.

Source

pub fn raw_params(&self) -> &[u8] ⓘ

Stream header parameter bytes after the "YUV4MPEG2 " prefix, verbatim, LF excluded. Feed to EncoderBuilder::raw_params for a byte-exact re-encode.

Source

pub fn plane_sizes(&self) -> [usize; 3]

Per-plane byte sizes [Y, U, V]. Chroma entries are 0 for mono.

Source

pub fn read_frame(&mut self) -> Result<FrameRef<'_>, Error>

Borrows the next frame. Planes point into the decoder’s reusable internal buffer, so each call reuses the same storage. The counting-allocator test tests/zero_alloc.rs pins the decode loop at zero heap allocations.

Returns Error::EndOfStream at a clean end (EOF exactly where the next FRAME magic would start) and Error::Truncated when EOF falls inside a frame header or payload.

Source

pub fn frame_bytes(&self) -> usize

The frame byte count implied by the header (sum of plane sizes).

Trait Implementations§

Source§

impl<R: Read> Debug for Decoder<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Decoder<R>
where BufReader<R>: Freeze,

§

impl<R> RefUnwindSafe for Decoder<R>

§

impl<R> Send for Decoder<R>
where BufReader<R>: Send,

§

impl<R> Sync for Decoder<R>
where BufReader<R>: Sync,

§

impl<R> Unpin for Decoder<R>
where BufReader<R>: Unpin,

§

impl<R> UnsafeUnpin for Decoder<R>

§

impl<R> UnwindSafe for Decoder<R>

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