pub struct Decoder { /* private fields */ }Expand description
An OpenH264 decoder.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new() -> Result<Self, Error>
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.
Sourcepub fn with_api_config(
api: OpenH264API,
config: DecoderConfig,
) -> Result<Self, Error>
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.
Sourcepub fn decode(&mut self, packet: &[u8]) -> Result<Option<DecodedYUV<'_>>, Error>
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.
Sourcepub fn decode_with_options(
&mut self,
packet: &[u8],
options: DecodeOptions,
) -> Result<Option<DecodedYUV<'_>>, Error>
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.
Sourcepub fn flush_remaining(&mut self) -> Result<Vec<DecodedYUV<'_>>, Error>
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.
Sourcepub const unsafe fn raw_api(&mut self) -> &mut DecoderRawAPI
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();
}