Decoder

Struct Decoder 

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

The main VP8/VP9 video decoder.

§Example

use std::num::NonZero;
use vpx_rs::{Decoder, DecoderConfig, Error, DecodedImageData};

// Initialize a new decoder
fn new_vp8_decoder(width: u32, height: u32,) -> Result<Decoder, Error> {
    // Prepare the configuration
    let config = DecoderConfig::new(
        vpx_rs::dec::CodecId::VP8,
        width,
        height,
    );
    // Instantiate the decoder
    Decoder::new(config)
}

// Passes a buffer to the decoder and extracts any completed frames
fn decode_vp8_buf(
    decoder: &mut Decoder,
    stream_data: &[u8],
) -> Result<(), Error> {
    for decoded_image in decoder.decode(stream_data)?.into_iter() {
        let (format, bit_depth) = match decoded_image.data() {
            DecodedImageData::Data8b(data) =>
                (format!("{:?}", data.format()), 8),
            DecodedImageData::Data16b(data) =>
                (format!("{:?}", data.format()), 16),
        };
        println!(
            "Decoded a {}x{} pixel image in {} format with bit depth {}",
            decoded_image.width(),
            decoded_image.height(),
            format,
            bit_depth,
        );
    }
    Ok(())
}

Implementations§

Source§

impl Decoder

Source

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

Constructs a new decoder for the given configuration. After successful construction, you can start sending bitstream buffers to the decoder by calling Decoder::decode().

Source

pub fn decode(&mut self, data: &[u8]) -> Result<DecodedImageIterator<'_>>

Submits data to be decoded by the decoder, yielding a number of decoded images as a result. Please note that even if you only send data for a single frame at a time, due to internal bitstream frame rendering, the decoder might produce any number of frames per decode call. You should retrieve all decoded images from the returned iterator before trying to push more data to the decoder. The images will always be returned to you in presentation order, so there’s no need to perform image reordering on your end.

Source

pub fn stream_info(&mut self) -> Option<StreamInfo>

Returns stream information for the decoder. This might not return stream information initially, especially before sending any data to the decoder.

Trait Implementations§

Source§

impl Debug for Decoder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Decoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Decoder

Source§

impl Sync for Decoder

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<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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.