Skip to main content

Decoder

Struct Decoder 

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

An OpenH264 decoder.

Implementations§

Source§

impl Decoder

Source

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

Create a decoder with default settings and the built-in decoder.

This method is only available when compiling with the source feature.

§Errors

This should never error, but the underlying OpenH264 decoder has an error indication and since we don’t know their code that well we just can’t guarantee it.

Source

pub fn with_api_config( api: OpenH264API, config: DecoderConfig, ) -> Result<Self, Error>

Create a decoder with the provided API and configuration.

§Errors

Might fail if the provided encoder parameters had issues.

Source

pub fn decode(&mut self, packet: &[u8]) -> Result<Option<DecodedYUV<'_>>, Error>

Decodes a series of H.264 NAL packets and returns the latest picture.

This is a convenience wrapper around decode_with_options that uses default decoding options.

§Errors

The function returns an error if the bitstream was corrupted.

Source

pub fn decode_with_options( &mut self, packet: &[u8], options: DecodeOptions, ) -> Result<Option<DecodedYUV<'_>>, Error>

Decodes a series of H.264 NAL packets and returns the latest picture.

This function can be called with:

  • only the complete SPS / PPS header (usually the first some 30 bytes of a H.264 stream),
  • the headers and series of complete frames,
  • new frames after previous headers and frames were successfully decoded.

In each case, it will return Some(decoded) image in YUV format if an image was available, or None if more data needs to be provided. If options contains Flush (or if this is set as the decoder default), it will try to flush a frame no image was available.

In any case, it is probably a good idea to call Decoder::flush_remaining after you finished decoding all available NAL units.

§Errors
  • The function returns an error if the bitstream was corrupted.
  • Also, flushing best practices are somewhat hard to come by in OpenH264. You might get errors if you flushed when you shouldn’t have, although we cannot exactly tell you when that is. If you have more information on how to make this more robust, a PR would be greatly welcome.
Source

pub fn flush_remaining(&mut self) -> Result<Vec<DecodedYUV<'_>>, Error>

Flush and return all remaining frames in the buffer.

This function should be called after decoding all frames of a NAL stream.

§Errors

The function returns an error if the bitstream was corrupted.

Source

pub const unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI

Obtain the raw API for advanced use cases.

When resorting to this call, please consider filing an issue / PR.

§Safety

You must not set parameters the decoder relies on, we recommend checking the source.

§Example
use openh264::decoder::{DecoderConfig, Decoder};

let api = OpenH264API::from_source();
let config = DecoderConfig::default();
let mut decoder = Decoder::with_api_config(api, config)?;

unsafe {
    _ = decoder.raw_api();
}

Trait Implementations§

Source§

impl Drop for Decoder

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<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.